diff --git a/src/main/groovy/com/github/spotbugs/snom/internal/SpotBugsTaskFactory.java b/src/main/groovy/com/github/spotbugs/snom/internal/SpotBugsTaskFactory.java index 8d26fe88..75d8272c 100644 --- a/src/main/groovy/com/github/spotbugs/snom/internal/SpotBugsTaskFactory.java +++ b/src/main/groovy/com/github/spotbugs/snom/internal/SpotBugsTaskFactory.java @@ -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; @@ -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") @@ -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() diff --git a/src/test/java/com/github/spotbugs/snom/internal/SpotBugsTaskFactoryTest.java b/src/test/java/com/github/spotbugs/snom/internal/SpotBugsTaskFactoryTest.java new file mode 100644 index 00000000..b9009d8c --- /dev/null +++ b/src/test/java/com/github/spotbugs/snom/internal/SpotBugsTaskFactoryTest.java @@ -0,0 +1,28 @@ +/* + * Copyright 2021 SpotBugs team + * + *

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 + * + *

http://www.apache.org/licenses/LICENSE-2.0 + * + *

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")); + } +}