mirror of https://github.com/apache/maven.git
[MNG-8433] Use the switch expressions syntax (#1983)
Signed-off-by: crazyhzm <crazyhzm@apache.org> --- https://issues.apache.org/jira/browse/MNG-8433
This commit is contained in:
parent
cd36684ade
commit
99777ace02
|
@ -119,25 +119,19 @@ public class ComparableVersion implements Comparable<ComparableVersion> {
|
|||
return (value == 0) ? 0 : 1; // 1.0 == 1, 1.1 > 1
|
||||
}
|
||||
|
||||
switch (item.getType()) {
|
||||
case INT_ITEM:
|
||||
return switch (item.getType()) {
|
||||
case INT_ITEM -> {
|
||||
int itemValue = ((IntItem) item).value;
|
||||
return Integer.compare(value, itemValue);
|
||||
case LONG_ITEM:
|
||||
case BIGINTEGER_ITEM:
|
||||
return -1;
|
||||
yield Integer.compare(value, itemValue);
|
||||
}
|
||||
case LONG_ITEM, BIGINTEGER_ITEM -> -1;
|
||||
case STRING_ITEM -> 1;
|
||||
case COMBINATION_ITEM -> 1; // 1.1 > 1-sp
|
||||
|
||||
case STRING_ITEM:
|
||||
return 1;
|
||||
case COMBINATION_ITEM:
|
||||
return 1; // 1.1 > 1-sp
|
||||
case LIST_ITEM -> 1; // 1.1 > 1-1
|
||||
|
||||
case LIST_ITEM:
|
||||
return 1; // 1.1 > 1-1
|
||||
|
||||
default:
|
||||
throw new IllegalStateException("invalid item: " + item.getClass());
|
||||
}
|
||||
default -> throw new IllegalStateException("invalid item: " + item.getClass());
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -191,26 +185,20 @@ public class ComparableVersion implements Comparable<ComparableVersion> {
|
|||
return (value == 0) ? 0 : 1; // 1.0 == 1, 1.1 > 1
|
||||
}
|
||||
|
||||
switch (item.getType()) {
|
||||
case INT_ITEM:
|
||||
return 1;
|
||||
case LONG_ITEM:
|
||||
return switch (item.getType()) {
|
||||
case INT_ITEM -> 1;
|
||||
case LONG_ITEM -> {
|
||||
long itemValue = ((LongItem) item).value;
|
||||
return Long.compare(value, itemValue);
|
||||
case BIGINTEGER_ITEM:
|
||||
return -1;
|
||||
yield Long.compare(value, itemValue);
|
||||
}
|
||||
case BIGINTEGER_ITEM -> -1;
|
||||
case STRING_ITEM -> 1;
|
||||
case COMBINATION_ITEM -> 1; // 1.1 > 1-sp
|
||||
|
||||
case STRING_ITEM:
|
||||
return 1;
|
||||
case COMBINATION_ITEM:
|
||||
return 1; // 1.1 > 1-sp
|
||||
case LIST_ITEM -> 1; // 1.1 > 1-1
|
||||
|
||||
case LIST_ITEM:
|
||||
return 1; // 1.1 > 1-1
|
||||
|
||||
default:
|
||||
throw new IllegalStateException("invalid item: " + item.getClass());
|
||||
}
|
||||
default -> throw new IllegalStateException("invalid item: " + item.getClass());
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -264,25 +252,16 @@ public class ComparableVersion implements Comparable<ComparableVersion> {
|
|||
return BigInteger.ZERO.equals(value) ? 0 : 1; // 1.0 == 1, 1.1 > 1
|
||||
}
|
||||
|
||||
switch (item.getType()) {
|
||||
case INT_ITEM:
|
||||
case LONG_ITEM:
|
||||
return 1;
|
||||
return switch (item.getType()) {
|
||||
case INT_ITEM, LONG_ITEM -> 1;
|
||||
case BIGINTEGER_ITEM -> value.compareTo(((BigIntegerItem) item).value);
|
||||
case STRING_ITEM -> 1;
|
||||
case COMBINATION_ITEM -> 1; // 1.1 > 1-sp
|
||||
|
||||
case BIGINTEGER_ITEM:
|
||||
return value.compareTo(((BigIntegerItem) item).value);
|
||||
case LIST_ITEM -> 1; // 1.1 > 1-1
|
||||
|
||||
case STRING_ITEM:
|
||||
return 1;
|
||||
case COMBINATION_ITEM:
|
||||
return 1; // 1.1 > 1-sp
|
||||
|
||||
case LIST_ITEM:
|
||||
return 1; // 1.1 > 1-1
|
||||
|
||||
default:
|
||||
throw new IllegalStateException("invalid item: " + item.getClass());
|
||||
}
|
||||
default -> throw new IllegalStateException("invalid item: " + item.getClass());
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -101,14 +101,11 @@ public final class MetadataBridge extends AbstractMetadata implements MergeableM
|
|||
|
||||
public Nature getNature() {
|
||||
if (metadata instanceof RepositoryMetadata) {
|
||||
switch (((RepositoryMetadata) metadata).getNature()) {
|
||||
case RepositoryMetadata.RELEASE_OR_SNAPSHOT:
|
||||
return Nature.RELEASE_OR_SNAPSHOT;
|
||||
case RepositoryMetadata.SNAPSHOT:
|
||||
return Nature.SNAPSHOT;
|
||||
default:
|
||||
return Nature.RELEASE;
|
||||
}
|
||||
return switch (((RepositoryMetadata) metadata).getNature()) {
|
||||
case RepositoryMetadata.RELEASE_OR_SNAPSHOT -> Nature.RELEASE_OR_SNAPSHOT;
|
||||
case RepositoryMetadata.SNAPSHOT -> Nature.SNAPSHOT;
|
||||
default -> Nature.RELEASE;
|
||||
};
|
||||
} else {
|
||||
return Nature.RELEASE;
|
||||
}
|
||||
|
|
|
@ -1461,15 +1461,13 @@ public class DefaultModelValidator implements ModelValidator {
|
|||
}
|
||||
|
||||
private boolean isValidProfileId(String id) {
|
||||
switch (id.charAt(0)) { // avoid first character that has special CLI meaning in "mvn -P xxx"
|
||||
case '+': // activate
|
||||
case '-': // deactivate
|
||||
case '!': // deactivate
|
||||
case '?': // optional
|
||||
return false;
|
||||
default:
|
||||
}
|
||||
return true;
|
||||
return switch (id.charAt(0)) { // avoid first character that has special CLI meaning in "mvn -P xxx"
|
||||
// +: activate
|
||||
// -, !: deactivate
|
||||
// ?: optional
|
||||
case '+', '-', '!', '?' -> false;
|
||||
default -> true;
|
||||
};
|
||||
}
|
||||
|
||||
@SuppressWarnings("checkstyle:parameternumber")
|
||||
|
|
|
@ -174,36 +174,23 @@ public class Os {
|
|||
|| actualOsName.contains("ce"));
|
||||
isNT = !is9x;
|
||||
}
|
||||
switch (family) {
|
||||
case FAMILY_WINDOWS:
|
||||
return isWindows;
|
||||
case FAMILY_WIN9X:
|
||||
return isWindows && is9x;
|
||||
case FAMILY_NT:
|
||||
return isWindows && isNT;
|
||||
case FAMILY_OS2:
|
||||
return actualOsName.contains(FAMILY_OS2);
|
||||
case FAMILY_NETWARE:
|
||||
return actualOsName.contains(FAMILY_NETWARE);
|
||||
case FAMILY_DOS:
|
||||
return File.pathSeparatorChar == ';' && !isFamily(FAMILY_NETWARE, actualOsName) && !isWindows;
|
||||
case FAMILY_MAC:
|
||||
return actualOsName.contains(FAMILY_MAC) || actualOsName.contains(DARWIN);
|
||||
case FAMILY_TANDEM:
|
||||
return actualOsName.contains("nonstop_kernel");
|
||||
case FAMILY_UNIX:
|
||||
return File.pathSeparatorChar == ':'
|
||||
&& !isFamily(FAMILY_OPENVMS, actualOsName)
|
||||
&& (!isFamily(FAMILY_MAC, actualOsName) || actualOsName.endsWith("x"));
|
||||
case FAMILY_ZOS:
|
||||
return actualOsName.contains(FAMILY_ZOS) || actualOsName.contains(FAMILY_OS390);
|
||||
case FAMILY_OS400:
|
||||
return actualOsName.contains(FAMILY_OS400);
|
||||
case FAMILY_OPENVMS:
|
||||
return actualOsName.contains(FAMILY_OPENVMS);
|
||||
default:
|
||||
return actualOsName.contains(family.toLowerCase(Locale.US));
|
||||
}
|
||||
return switch (family) {
|
||||
case FAMILY_WINDOWS -> isWindows;
|
||||
case FAMILY_WIN9X -> isWindows && is9x;
|
||||
case FAMILY_NT -> isWindows && isNT;
|
||||
case FAMILY_OS2 -> actualOsName.contains(FAMILY_OS2);
|
||||
case FAMILY_NETWARE -> actualOsName.contains(FAMILY_NETWARE);
|
||||
case FAMILY_DOS -> File.pathSeparatorChar == ';' && !isFamily(FAMILY_NETWARE, actualOsName) && !isWindows;
|
||||
case FAMILY_MAC -> actualOsName.contains(FAMILY_MAC) || actualOsName.contains(DARWIN);
|
||||
case FAMILY_TANDEM -> actualOsName.contains("nonstop_kernel");
|
||||
case FAMILY_UNIX -> File.pathSeparatorChar == ':'
|
||||
&& !isFamily(FAMILY_OPENVMS, actualOsName)
|
||||
&& (!isFamily(FAMILY_MAC, actualOsName) || actualOsName.endsWith("x"));
|
||||
case FAMILY_ZOS -> actualOsName.contains(FAMILY_ZOS) || actualOsName.contains(FAMILY_OS390);
|
||||
case FAMILY_OS400 -> actualOsName.contains(FAMILY_OS400);
|
||||
case FAMILY_OPENVMS -> actualOsName.contains(FAMILY_OPENVMS);
|
||||
default -> actualOsName.contains(family.toLowerCase(Locale.US));
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -95,13 +95,11 @@ class DefaultModelBuilderTest {
|
|||
@Override
|
||||
public ModelSource resolveModel(org.apache.maven.model.Dependency dependency)
|
||||
throws UnresolvableModelException {
|
||||
switch (dependency.getManagementKey()) {
|
||||
case BASE1_ID:
|
||||
return new StringModelSource(BASE1);
|
||||
case BASE2_ID:
|
||||
return new StringModelSource(BASE2);
|
||||
}
|
||||
return null;
|
||||
return switch (dependency.getManagementKey()) {
|
||||
case BASE1_ID -> new StringModelSource(BASE1);
|
||||
case BASE2_ID -> new StringModelSource(BASE2);
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -183,18 +181,12 @@ class DefaultModelBuilderTest {
|
|||
request.setModelResolver(new BaseModelResolver() {
|
||||
public ModelSource resolveModel(org.apache.maven.model.Dependency dependency)
|
||||
throws UnresolvableModelException {
|
||||
switch (dependency.getManagementKey()) {
|
||||
case "test:import:pom":
|
||||
return new FileModelSource(new File(getClass()
|
||||
.getResource("/poms/depmgmt/import.xml")
|
||||
.getFile()));
|
||||
default:
|
||||
throw new UnresolvableModelException(
|
||||
"Cannot resolve",
|
||||
dependency.getGroupId(),
|
||||
dependency.getArtifactId(),
|
||||
dependency.getVersion());
|
||||
if (dependency.getManagementKey().equals("test:import:pom")) {
|
||||
return new FileModelSource(new File(
|
||||
getClass().getResource("/poms/depmgmt/import.xml").getFile()));
|
||||
}
|
||||
throw new UnresolvableModelException(
|
||||
"Cannot resolve", dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion());
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -224,18 +216,12 @@ class DefaultModelBuilderTest {
|
|||
request.setModelResolver(new BaseModelResolver() {
|
||||
public ModelSource resolveModel(org.apache.maven.model.Dependency dependency)
|
||||
throws UnresolvableModelException {
|
||||
switch (dependency.getManagementKey()) {
|
||||
case "test:import:pom":
|
||||
return new FileModelSource(new File(getClass()
|
||||
.getResource("/poms/depmgmt/import.xml")
|
||||
.getFile()));
|
||||
default:
|
||||
throw new UnresolvableModelException(
|
||||
"Cannot resolve",
|
||||
dependency.getGroupId(),
|
||||
dependency.getArtifactId(),
|
||||
dependency.getVersion());
|
||||
if (dependency.getManagementKey().equals("test:import:pom")) {
|
||||
return new FileModelSource(new File(
|
||||
getClass().getResource("/poms/depmgmt/import.xml").getFile()));
|
||||
}
|
||||
throw new UnresolvableModelException(
|
||||
"Cannot resolve", dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion());
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -265,22 +251,18 @@ class DefaultModelBuilderTest {
|
|||
request.setModelResolver(new BaseModelResolver() {
|
||||
public ModelSource resolveModel(org.apache.maven.model.Dependency dependency)
|
||||
throws UnresolvableModelException {
|
||||
switch (dependency.getManagementKey()) {
|
||||
case "test:import:pom":
|
||||
return new FileModelSource(new File(getClass()
|
||||
.getResource("/poms/depmgmt/import.xml")
|
||||
.getFile()));
|
||||
case "test:other:pom":
|
||||
return new FileModelSource(new File(getClass()
|
||||
.getResource("/poms/depmgmt/other-import.xml")
|
||||
.getFile()));
|
||||
default:
|
||||
throw new UnresolvableModelException(
|
||||
"Cannot resolve",
|
||||
dependency.getGroupId(),
|
||||
dependency.getArtifactId(),
|
||||
dependency.getVersion());
|
||||
}
|
||||
return switch (dependency.getManagementKey()) {
|
||||
case "test:import:pom" -> new FileModelSource(new File(
|
||||
getClass().getResource("/poms/depmgmt/import.xml").getFile()));
|
||||
case "test:other:pom" -> new FileModelSource(new File(getClass()
|
||||
.getResource("/poms/depmgmt/other-import.xml")
|
||||
.getFile()));
|
||||
default -> throw new UnresolvableModelException(
|
||||
"Cannot resolve",
|
||||
dependency.getGroupId(),
|
||||
dependency.getArtifactId(),
|
||||
dependency.getVersion());
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -313,22 +295,19 @@ class DefaultModelBuilderTest {
|
|||
request.setModelResolver(new BaseModelResolver() {
|
||||
public ModelSource resolveModel(org.apache.maven.model.Dependency dependency)
|
||||
throws UnresolvableModelException {
|
||||
switch (dependency.getManagementKey()) {
|
||||
case "org.junit:bom:pom":
|
||||
return new FileModelSource(new File(getClass()
|
||||
.getResource("/poms/depmgmt/junit-" + dependency.getVersion() + ".xml")
|
||||
.getFile()));
|
||||
case "test:other:pom":
|
||||
return new FileModelSource(new File(getClass()
|
||||
.getResource("/poms/depmgmt/distant-import.xml")
|
||||
.getFile()));
|
||||
default:
|
||||
throw new UnresolvableModelException(
|
||||
"Cannot resolve",
|
||||
dependency.getGroupId(),
|
||||
dependency.getArtifactId(),
|
||||
dependency.getVersion());
|
||||
}
|
||||
return switch (dependency.getManagementKey()) {
|
||||
case "org.junit:bom:pom" -> new FileModelSource(new File(getClass()
|
||||
.getResource("/poms/depmgmt/junit-" + dependency.getVersion() + ".xml")
|
||||
.getFile()));
|
||||
case "test:other:pom" -> new FileModelSource(new File(getClass()
|
||||
.getResource("/poms/depmgmt/distant-import.xml")
|
||||
.getFile()));
|
||||
default -> throw new UnresolvableModelException(
|
||||
"Cannot resolve",
|
||||
dependency.getGroupId(),
|
||||
dependency.getArtifactId(),
|
||||
dependency.getVersion());
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -363,22 +342,19 @@ class DefaultModelBuilderTest {
|
|||
request.setModelResolver(new BaseModelResolver() {
|
||||
public ModelSource resolveModel(org.apache.maven.model.Dependency dependency)
|
||||
throws UnresolvableModelException {
|
||||
switch (dependency.getManagementKey()) {
|
||||
case "org.junit:bom:pom":
|
||||
return new FileModelSource(new File(getClass()
|
||||
.getResource("/poms/depmgmt/junit-" + dependency.getVersion() + ".xml")
|
||||
.getFile()));
|
||||
case "test:other:pom":
|
||||
return new FileModelSource(new File(getClass()
|
||||
.getResource("/poms/depmgmt/distant-import.xml")
|
||||
.getFile()));
|
||||
default:
|
||||
throw new UnresolvableModelException(
|
||||
"Cannot resolve",
|
||||
dependency.getGroupId(),
|
||||
dependency.getArtifactId(),
|
||||
dependency.getVersion());
|
||||
}
|
||||
return switch (dependency.getManagementKey()) {
|
||||
case "org.junit:bom:pom" -> new FileModelSource(new File(getClass()
|
||||
.getResource("/poms/depmgmt/junit-" + dependency.getVersion() + ".xml")
|
||||
.getFile()));
|
||||
case "test:other:pom" -> new FileModelSource(new File(getClass()
|
||||
.getResource("/poms/depmgmt/distant-import.xml")
|
||||
.getFile()));
|
||||
default -> throw new UnresolvableModelException(
|
||||
"Cannot resolve",
|
||||
dependency.getGroupId(),
|
||||
dependency.getArtifactId(),
|
||||
dependency.getVersion());
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -82,15 +82,12 @@ public class ArtifactDescriptorUtils {
|
|||
}
|
||||
|
||||
public static String toRepositoryChecksumPolicy(final String artifactRepositoryPolicy) {
|
||||
switch (artifactRepositoryPolicy) {
|
||||
case RepositoryPolicy.CHECKSUM_POLICY_FAIL:
|
||||
return RepositoryPolicy.CHECKSUM_POLICY_FAIL;
|
||||
case RepositoryPolicy.CHECKSUM_POLICY_IGNORE:
|
||||
return RepositoryPolicy.CHECKSUM_POLICY_IGNORE;
|
||||
case RepositoryPolicy.CHECKSUM_POLICY_WARN:
|
||||
return RepositoryPolicy.CHECKSUM_POLICY_WARN;
|
||||
default:
|
||||
throw new IllegalArgumentException("unknown repository checksum policy: " + artifactRepositoryPolicy);
|
||||
}
|
||||
return switch (artifactRepositoryPolicy) {
|
||||
case RepositoryPolicy.CHECKSUM_POLICY_FAIL -> RepositoryPolicy.CHECKSUM_POLICY_FAIL;
|
||||
case RepositoryPolicy.CHECKSUM_POLICY_IGNORE -> RepositoryPolicy.CHECKSUM_POLICY_IGNORE;
|
||||
case RepositoryPolicy.CHECKSUM_POLICY_WARN -> RepositoryPolicy.CHECKSUM_POLICY_WARN;
|
||||
default -> throw new IllegalArgumentException(
|
||||
"unknown repository checksum policy: " + artifactRepositoryPolicy);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -198,20 +198,12 @@ public final class UserPropertiesArtifactRelocationSource implements MavenArtifa
|
|||
private static Artifact parseArtifact(String coords) {
|
||||
Artifact s;
|
||||
String[] parts = coords.split(":");
|
||||
switch (parts.length) {
|
||||
case 3:
|
||||
s = new DefaultArtifact(parts[0], parts[1], "*", "*", parts[2]);
|
||||
break;
|
||||
case 4:
|
||||
s = new DefaultArtifact(parts[0], parts[1], "*", parts[2], parts[3]);
|
||||
break;
|
||||
case 5:
|
||||
s = new DefaultArtifact(parts[0], parts[1], parts[2], parts[3], parts[4]);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Bad artifact coordinates " + coords
|
||||
+ ", expected format is <groupId>:<artifactId>[:<extension>[:<classifier>]]:<version>");
|
||||
}
|
||||
s = switch (parts.length) {
|
||||
case 3 -> new DefaultArtifact(parts[0], parts[1], "*", "*", parts[2]);
|
||||
case 4 -> new DefaultArtifact(parts[0], parts[1], "*", parts[2], parts[3]);
|
||||
case 5 -> new DefaultArtifact(parts[0], parts[1], parts[2], parts[3], parts[4]);
|
||||
default -> throw new IllegalArgumentException("Bad artifact coordinates " + coords
|
||||
+ ", expected format is <groupId>:<artifactId>[:<extension>[:<classifier>]]:<version>");};
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,20 +28,12 @@ import org.apache.maven.cling.logging.BaseSlf4jConfiguration;
|
|||
public class Log4j2Configuration extends BaseSlf4jConfiguration {
|
||||
@Override
|
||||
public void setRootLoggerLevel(Level level) {
|
||||
String value;
|
||||
switch (level) {
|
||||
case DEBUG:
|
||||
value = "debug";
|
||||
break;
|
||||
|
||||
case INFO:
|
||||
value = "info";
|
||||
break;
|
||||
|
||||
default:
|
||||
value = "error";
|
||||
break;
|
||||
}
|
||||
String value =
|
||||
switch (level) {
|
||||
case DEBUG -> "debug";
|
||||
case INFO -> "info";
|
||||
default -> "error";
|
||||
};
|
||||
System.setProperty("maven.logging.root.level", value);
|
||||
}
|
||||
|
||||
|
|
|
@ -30,20 +30,12 @@ import org.slf4j.LoggerFactory;
|
|||
public class LogbackConfiguration extends BaseSlf4jConfiguration {
|
||||
@Override
|
||||
public void setRootLoggerLevel(Level level) {
|
||||
ch.qos.logback.classic.Level value;
|
||||
switch (level) {
|
||||
case DEBUG:
|
||||
value = ch.qos.logback.classic.Level.DEBUG;
|
||||
break;
|
||||
|
||||
case INFO:
|
||||
value = ch.qos.logback.classic.Level.INFO;
|
||||
break;
|
||||
|
||||
default:
|
||||
value = ch.qos.logback.classic.Level.ERROR;
|
||||
break;
|
||||
}
|
||||
ch.qos.logback.classic.Level value =
|
||||
switch (level) {
|
||||
case DEBUG -> ch.qos.logback.classic.Level.DEBUG;
|
||||
case INFO -> ch.qos.logback.classic.Level.INFO;
|
||||
default -> ch.qos.logback.classic.Level.ERROR;
|
||||
};
|
||||
((ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME)).setLevel(value);
|
||||
}
|
||||
|
||||
|
|
|
@ -31,20 +31,12 @@ import org.slf4j.LoggerFactory;
|
|||
public class MavenSimpleConfiguration extends BaseSlf4jConfiguration {
|
||||
@Override
|
||||
public void setRootLoggerLevel(Level level) {
|
||||
String value;
|
||||
switch (level) {
|
||||
case DEBUG:
|
||||
value = "debug";
|
||||
break;
|
||||
|
||||
case INFO:
|
||||
value = "info";
|
||||
break;
|
||||
|
||||
default:
|
||||
value = "error";
|
||||
break;
|
||||
}
|
||||
String value =
|
||||
switch (level) {
|
||||
case DEBUG -> "debug";
|
||||
case INFO -> "info";
|
||||
default -> "error";
|
||||
};
|
||||
System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", value);
|
||||
}
|
||||
|
||||
|
|
|
@ -122,14 +122,11 @@ class Xpp3DomNodeIterator implements NodeIterator {
|
|||
return false;
|
||||
}
|
||||
if (test instanceof NodeTypeTest) {
|
||||
switch (((NodeTypeTest) test).getNodeType()) {
|
||||
case Compiler.NODE_TYPE_NODE:
|
||||
return true;
|
||||
case Compiler.NODE_TYPE_TEXT:
|
||||
return node.getValue() != null;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return switch (((NodeTypeTest) test).getNodeType()) {
|
||||
case Compiler.NODE_TYPE_NODE -> true;
|
||||
case Compiler.NODE_TYPE_TEXT -> node.getValue() != null;
|
||||
default -> false;
|
||||
};
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -1534,15 +1534,13 @@ public class DefaultModelValidator implements ModelValidator {
|
|||
}
|
||||
|
||||
private boolean isValidProfileId(String id) {
|
||||
switch (id.charAt(0)) { // avoid first character that has special CLI meaning in "mvn -P xxx"
|
||||
case '+': // activate
|
||||
case '-': // deactivate
|
||||
case '!': // deactivate
|
||||
case '?': // optional
|
||||
return false;
|
||||
default:
|
||||
}
|
||||
return true;
|
||||
return switch (id.charAt(0)) { // avoid first character that has special CLI meaning in "mvn -P xxx"
|
||||
// +: activate
|
||||
// -, !: deactivate
|
||||
// ?: optional
|
||||
case '+', '-', '!', '?' -> false;
|
||||
default -> true;
|
||||
};
|
||||
}
|
||||
|
||||
@SuppressWarnings("checkstyle:parameternumber")
|
||||
|
|
|
@ -175,36 +175,23 @@ public class Os {
|
|||
|| actualOsName.contains("ce"));
|
||||
isNT = !is9x;
|
||||
}
|
||||
switch (family) {
|
||||
case FAMILY_WINDOWS:
|
||||
return isWindows;
|
||||
case FAMILY_WIN9X:
|
||||
return isWindows && is9x;
|
||||
case FAMILY_NT:
|
||||
return isWindows && isNT;
|
||||
case FAMILY_OS2:
|
||||
return actualOsName.contains(FAMILY_OS2);
|
||||
case FAMILY_NETWARE:
|
||||
return actualOsName.contains(FAMILY_NETWARE);
|
||||
case FAMILY_DOS:
|
||||
return PATH_SEP.equals(";") && !isFamily(FAMILY_NETWARE, actualOsName) && !isWindows;
|
||||
case FAMILY_MAC:
|
||||
return actualOsName.contains(FAMILY_MAC) || actualOsName.contains(DARWIN);
|
||||
case FAMILY_TANDEM:
|
||||
return actualOsName.contains("nonstop_kernel");
|
||||
case FAMILY_UNIX:
|
||||
return PATH_SEP.equals(":")
|
||||
&& !isFamily(FAMILY_OPENVMS, actualOsName)
|
||||
&& (!isFamily(FAMILY_MAC, actualOsName) || actualOsName.endsWith("x"));
|
||||
case FAMILY_ZOS:
|
||||
return actualOsName.contains(FAMILY_ZOS) || actualOsName.contains(FAMILY_OS390);
|
||||
case FAMILY_OS400:
|
||||
return actualOsName.contains(FAMILY_OS400);
|
||||
case FAMILY_OPENVMS:
|
||||
return actualOsName.contains(FAMILY_OPENVMS);
|
||||
default:
|
||||
return actualOsName.contains(family.toLowerCase(Locale.US));
|
||||
}
|
||||
return switch (family) {
|
||||
case FAMILY_WINDOWS -> isWindows;
|
||||
case FAMILY_WIN9X -> isWindows && is9x;
|
||||
case FAMILY_NT -> isWindows && isNT;
|
||||
case FAMILY_OS2 -> actualOsName.contains(FAMILY_OS2);
|
||||
case FAMILY_NETWARE -> actualOsName.contains(FAMILY_NETWARE);
|
||||
case FAMILY_DOS -> PATH_SEP.equals(";") && !isFamily(FAMILY_NETWARE, actualOsName) && !isWindows;
|
||||
case FAMILY_MAC -> actualOsName.contains(FAMILY_MAC) || actualOsName.contains(DARWIN);
|
||||
case FAMILY_TANDEM -> actualOsName.contains("nonstop_kernel");
|
||||
case FAMILY_UNIX -> PATH_SEP.equals(":")
|
||||
&& !isFamily(FAMILY_OPENVMS, actualOsName)
|
||||
&& (!isFamily(FAMILY_MAC, actualOsName) || actualOsName.endsWith("x"));
|
||||
case FAMILY_ZOS -> actualOsName.contains(FAMILY_ZOS) || actualOsName.contains(FAMILY_OS390);
|
||||
case FAMILY_OS400 -> actualOsName.contains(FAMILY_OS400);
|
||||
case FAMILY_OPENVMS -> actualOsName.contains(FAMILY_OPENVMS);
|
||||
default -> actualOsName.contains(family.toLowerCase(Locale.US));
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -80,15 +80,12 @@ public class ArtifactDescriptorUtils {
|
|||
}
|
||||
|
||||
public static String toRepositoryChecksumPolicy(final String artifactRepositoryPolicy) {
|
||||
switch (artifactRepositoryPolicy) {
|
||||
case RepositoryPolicy.CHECKSUM_POLICY_FAIL:
|
||||
return RepositoryPolicy.CHECKSUM_POLICY_FAIL;
|
||||
case RepositoryPolicy.CHECKSUM_POLICY_IGNORE:
|
||||
return RepositoryPolicy.CHECKSUM_POLICY_IGNORE;
|
||||
case RepositoryPolicy.CHECKSUM_POLICY_WARN:
|
||||
return RepositoryPolicy.CHECKSUM_POLICY_WARN;
|
||||
default:
|
||||
throw new IllegalArgumentException("unknown repository checksum policy: " + artifactRepositoryPolicy);
|
||||
}
|
||||
return switch (artifactRepositoryPolicy) {
|
||||
case RepositoryPolicy.CHECKSUM_POLICY_FAIL -> RepositoryPolicy.CHECKSUM_POLICY_FAIL;
|
||||
case RepositoryPolicy.CHECKSUM_POLICY_IGNORE -> RepositoryPolicy.CHECKSUM_POLICY_IGNORE;
|
||||
case RepositoryPolicy.CHECKSUM_POLICY_WARN -> RepositoryPolicy.CHECKSUM_POLICY_WARN;
|
||||
default -> throw new IllegalArgumentException(
|
||||
"unknown repository checksum policy: " + artifactRepositoryPolicy);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -194,20 +194,12 @@ public final class UserPropertiesArtifactRelocationSource implements MavenArtifa
|
|||
private static Artifact parseArtifact(String coords) {
|
||||
Artifact s;
|
||||
String[] parts = coords.split(":");
|
||||
switch (parts.length) {
|
||||
case 3:
|
||||
s = new DefaultArtifact(parts[0], parts[1], "*", "*", parts[2]);
|
||||
break;
|
||||
case 4:
|
||||
s = new DefaultArtifact(parts[0], parts[1], "*", parts[2], parts[3]);
|
||||
break;
|
||||
case 5:
|
||||
s = new DefaultArtifact(parts[0], parts[1], parts[2], parts[3], parts[4]);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Bad artifact coordinates " + coords
|
||||
+ ", expected format is <groupId>:<artifactId>[:<extension>[:<classifier>]]:<version>");
|
||||
}
|
||||
s = switch (parts.length) {
|
||||
case 3 -> new DefaultArtifact(parts[0], parts[1], "*", "*", parts[2]);
|
||||
case 4 -> new DefaultArtifact(parts[0], parts[1], "*", parts[2], parts[3]);
|
||||
case 5 -> new DefaultArtifact(parts[0], parts[1], parts[2], parts[3], parts[4]);
|
||||
default -> throw new IllegalArgumentException("Bad artifact coordinates " + coords
|
||||
+ ", expected format is <groupId>:<artifactId>[:<extension>[:<classifier>]]:<version>");};
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -442,20 +442,14 @@ public class MavenBaseLogger extends LegacyAbstractLogger {
|
|||
}
|
||||
|
||||
protected String renderLevel(int levelInt) {
|
||||
switch (levelInt) {
|
||||
case LOG_LEVEL_TRACE:
|
||||
return "TRACE";
|
||||
case LOG_LEVEL_DEBUG:
|
||||
return ("DEBUG");
|
||||
case LOG_LEVEL_INFO:
|
||||
return "INFO";
|
||||
case LOG_LEVEL_WARN:
|
||||
return "WARN";
|
||||
case LOG_LEVEL_ERROR:
|
||||
return "ERROR";
|
||||
default:
|
||||
throw new IllegalStateException("Unrecognized level [" + levelInt + "]");
|
||||
}
|
||||
return switch (levelInt) {
|
||||
case LOG_LEVEL_TRACE -> "TRACE";
|
||||
case LOG_LEVEL_DEBUG -> ("DEBUG");
|
||||
case LOG_LEVEL_INFO -> "INFO";
|
||||
case LOG_LEVEL_WARN -> "WARN";
|
||||
case LOG_LEVEL_ERROR -> "ERROR";
|
||||
default -> throw new IllegalStateException("Unrecognized level [" + levelInt + "]");
|
||||
};
|
||||
}
|
||||
|
||||
public void log(LoggingEvent event) {
|
||||
|
|
|
@ -58,19 +58,13 @@ public class MavenSimpleLogger extends MavenBaseLogger {
|
|||
warnRenderedLevel = builder().warning("WARNING").build();
|
||||
errorRenderedLevel = builder().error("ERROR").build();
|
||||
}
|
||||
switch (level) {
|
||||
case LOG_LEVEL_TRACE:
|
||||
return traceRenderedLevel;
|
||||
case LOG_LEVEL_DEBUG:
|
||||
return debugRenderedLevel;
|
||||
case LOG_LEVEL_INFO:
|
||||
return infoRenderedLevel;
|
||||
case LOG_LEVEL_WARN:
|
||||
return warnRenderedLevel;
|
||||
case LOG_LEVEL_ERROR:
|
||||
default:
|
||||
return errorRenderedLevel;
|
||||
}
|
||||
return switch (level) {
|
||||
case LOG_LEVEL_TRACE -> traceRenderedLevel;
|
||||
case LOG_LEVEL_DEBUG -> debugRenderedLevel;
|
||||
case LOG_LEVEL_INFO -> infoRenderedLevel;
|
||||
case LOG_LEVEL_WARN -> warnRenderedLevel;
|
||||
default -> errorRenderedLevel;
|
||||
};
|
||||
}
|
||||
|
||||
protected void write(StringBuilder buf, Throwable t) {
|
||||
|
|
|
@ -59,17 +59,10 @@ class OutputChoice {
|
|||
}
|
||||
|
||||
PrintStream getTargetPrintStream() {
|
||||
switch (outputChoiceType) {
|
||||
case SYS_OUT:
|
||||
return System.out;
|
||||
case SYS_ERR:
|
||||
return System.err;
|
||||
case CACHED_SYS_ERR:
|
||||
case CACHED_SYS_OUT:
|
||||
case FILE:
|
||||
return targetPrintStream;
|
||||
default:
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
return switch (outputChoiceType) {
|
||||
case SYS_OUT -> System.out;
|
||||
case SYS_ERR -> System.err;
|
||||
case CACHED_SYS_ERR, CACHED_SYS_OUT, FILE -> targetPrintStream;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -84,17 +84,15 @@ class ImmutableCollections {
|
|||
} else if (collection instanceof AbstractImmutableList) {
|
||||
return (List<E>) collection;
|
||||
} else {
|
||||
switch (collection.size()) {
|
||||
case 0:
|
||||
return emptyList();
|
||||
case 1:
|
||||
return singletonList(collection.iterator().next());
|
||||
case 2:
|
||||
return switch (collection.size()) {
|
||||
case 0 -> emptyList();
|
||||
case 1 -> singletonList(collection.iterator().next());
|
||||
case 2 -> {
|
||||
Iterator<E> it = collection.iterator();
|
||||
return new List2<>(it.next(), it.next());
|
||||
default:
|
||||
return new ListN<>(collection);
|
||||
}
|
||||
yield new List2<>(it.next(), it.next());
|
||||
}
|
||||
default -> new ListN<>(collection);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -113,15 +111,14 @@ class ImmutableCollections {
|
|||
} else if (map instanceof AbstractImmutableMap) {
|
||||
return map;
|
||||
} else {
|
||||
switch (map.size()) {
|
||||
case 0:
|
||||
return emptyMap();
|
||||
case 1:
|
||||
return switch (map.size()) {
|
||||
case 0 -> emptyMap();
|
||||
case 1 -> {
|
||||
Map.Entry<K, V> entry = map.entrySet().iterator().next();
|
||||
return singletonMap(entry.getKey(), entry.getValue());
|
||||
default:
|
||||
return new MapN<>(map);
|
||||
}
|
||||
yield singletonMap(entry.getKey(), entry.getValue());
|
||||
}
|
||||
default -> new MapN<>(map);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue