Skip to content

Commit a18cb37

Browse files
committed
Polish "Use 'switch' instead of 'if'"
See gh-40985
1 parent 2c5934d commit a18cb37

File tree

1 file changed

+20
-23
lines changed

1 file changed

+20
-23
lines changed

buildSrc/src/main/java/org/springframework/boot/build/classpath/CheckClasspathForProhibitedDependencies.java

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.boot.build.classpath;
1818

19+
import java.util.Set;
1920
import java.util.TreeSet;
2021
import java.util.stream.Collectors;
2122

@@ -35,6 +36,11 @@
3536
*/
3637
public class CheckClasspathForProhibitedDependencies extends DefaultTask {
3738

39+
private static final Set<String> PROHIBITED_GROUPS = Set.of("org.codehaus.groovy", "org.eclipse.jetty.toolchain",
40+
"commons-logging", "org.apache.geronimo.specs", "com.sun.activation");
41+
42+
private static final Set<String> PERMITTED_JAVAX_GROUPS = Set.of("javax.batch", "javax.cache", "javax.money");
43+
3844
private Configuration classpath;
3945

4046
public CheckClasspathForProhibitedDependencies() {
@@ -69,29 +75,20 @@ public void checkForProhibitedDependencies() {
6975
}
7076

7177
private boolean prohibited(ModuleVersionIdentifier id) {
72-
String group = id.getGroup();
73-
switch (group) {
74-
case "javax.batch", "javax.cache", "javax.money" -> {
75-
return false;
76-
}
77-
case "commons-logging", "org.codehaus.groovy", "org.eclipse.jetty.toolchain",
78-
"org.apache.geronimo.specs" -> {
79-
return true;
80-
}
81-
}
82-
if (group.startsWith("javax")) {
83-
return true;
84-
}
85-
if (group.equals("org.slf4j") && id.getName().equals("jcl-over-slf4j")) {
86-
return true;
87-
}
88-
if (group.startsWith("org.jboss.spec")) {
89-
return true;
90-
}
91-
if (group.equals("org.apache.geronimo.specs")) {
92-
return true;
93-
}
94-
return group.equals("com.sun.activation");
78+
return PROHIBITED_GROUPS.contains(id.getGroup()) || prohibitedJavax(id) || prohibitedSlf4j(id)
79+
|| prohibitedJbossSpec(id);
80+
}
81+
82+
private boolean prohibitedSlf4j(ModuleVersionIdentifier id) {
83+
return id.getGroup().equals("org.slf4j") && id.getName().equals("jcl-over-slf4j");
84+
}
85+
86+
private boolean prohibitedJbossSpec(ModuleVersionIdentifier id) {
87+
return id.getGroup().startsWith("org.jboss.spec");
88+
}
89+
90+
private boolean prohibitedJavax(ModuleVersionIdentifier id) {
91+
return id.getGroup().startsWith("javax.") && !PERMITTED_JAVAX_GROUPS.contains(id.getGroup());
9592
}
9693

9794
}

0 commit comments

Comments
 (0)