Skip to content

Commit

Permalink
fix: replace deprecated GUtil API
Browse files Browse the repository at this point in the history
  • Loading branch information
KengoTODA committed Nov 17, 2021
1 parent 4ab0c8c commit 81ca2f7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.gradle.api.plugins.JavaPluginExtension;
import org.gradle.api.tasks.SourceSetContainer;
import org.gradle.api.tasks.compile.JavaCompile;
import org.gradle.util.GUtil;
import org.gradle.util.GradleVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -80,6 +79,15 @@ private void generateForJava(Project project) {
});
}

static String toLowerCamelCase(String head, String tail) {
if (tail == null || tail.isEmpty()) {
return head;
}
StringBuilder builder = new StringBuilder(head.length() + tail.length());
builder.append(head).append(Character.toUpperCase(tail.charAt(0))).append(tail.substring(1));
return builder.toString();
}

private void generateForAndroid(Project project) {

@SuppressWarnings("rawtypes")
Expand All @@ -98,8 +106,7 @@ private void generateForAndroid(Project project) {
}
variants.all(
(BaseVariant variant) -> {
String spotbugsTaskName =
GUtil.toLowerCamelCase("spotbugs " + variant.getName());
String spotbugsTaskName = toLowerCamelCase("spotbugs", variant.getName());
log.debug("Creating SpotBugsTask for {}", variant.getName());
project
.getTasks()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2021 SpotBugs team
*
* <p>Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of the License at
*
* <p>http://www.apache.org/licenses/LICENSE-2.0
*
* <p>Unless required by applicable law or agreed to in writing, software distributed under the
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.spotbugs.snom.internal;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;

class SpotBugsTaskFactoryTest {
@Test
void toLowerCamelCase() {
assertEquals("spotbugs", SpotBugsTaskFactory.toLowerCamelCase("spotbugs", null));
assertEquals("spotbugs", SpotBugsTaskFactory.toLowerCamelCase("spotbugs", ""));
assertEquals("spotbugsMain", SpotBugsTaskFactory.toLowerCamelCase("spotbugs", "main"));
assertEquals("spotbugsMainCode", SpotBugsTaskFactory.toLowerCamelCase("spotbugs", "mainCode"));
}
}

0 comments on commit 81ca2f7

Please sign in to comment.