diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java index 047f675fd4..d5fd812158 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java @@ -48,7 +48,6 @@ import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.Option; import org.apache.commons.cli.ParseException; import org.apache.commons.cli.UnrecognizedOptionException; -import org.apache.commons.lang3.math.NumberUtils; import org.apache.maven.BuildAbort; import org.apache.maven.InternalErrorException; import org.apache.maven.Maven; @@ -1422,43 +1421,30 @@ public class MavenCli { } int calculateDegreeOfConcurrency(String threadConfiguration) { - if (threadConfiguration.endsWith("C")) { - threadConfiguration = threadConfiguration.substring(0, threadConfiguration.length() - 1); + try { + if (threadConfiguration.endsWith("C")) { + String str = threadConfiguration.substring(0, threadConfiguration.length() - 1); + float coreMultiplier = Float.parseFloat(str); - if (!NumberUtils.isParsable(threadConfiguration)) { - throw new IllegalArgumentException("Invalid threads core multiplier value: '" + threadConfiguration - + "C'. Supported are int and float values ending with C."); - } + if (coreMultiplier <= 0.0f) { + throw new IllegalArgumentException("Invalid threads core multiplier value: '" + threadConfiguration + + "'. Value must be positive."); + } - float coreMultiplier = Float.parseFloat(threadConfiguration); - - if (coreMultiplier <= 0.0f) { - throw new IllegalArgumentException("Invalid threads core multiplier value: '" + threadConfiguration - + "C'. Value must be positive."); - } - - int procs = Runtime.getRuntime().availableProcessors(); - int threads = (int) (coreMultiplier * procs); - return threads == 0 ? 1 : threads; - } else { - if (!NumberUtils.isParsable(threadConfiguration)) { - throw new IllegalArgumentException( - "Invalid threads value: '" + threadConfiguration + "'. Supported are int values."); - } - - try { + int procs = Runtime.getRuntime().availableProcessors(); + int threads = (int) (coreMultiplier * procs); + return threads == 0 ? 1 : threads; + } else { int threads = Integer.parseInt(threadConfiguration); - if (threads <= 0) { throw new IllegalArgumentException( "Invalid threads value: '" + threadConfiguration + "'. Value must be positive."); } - return threads; - } catch (NumberFormatException e) { - throw new IllegalArgumentException( - "Invalid threads value: '" + threadConfiguration + "'. Supported are integer values."); } + } catch (NumberFormatException e) { + throw new IllegalArgumentException("Invalid threads value: '" + threadConfiguration + + "'. Supported are int and float values ending with C."); } } diff --git a/maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java b/maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java index 54e937b31d..3dba909e67 100644 --- a/maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java +++ b/maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java @@ -158,7 +158,6 @@ public class MavenCliTest { int cpus = Runtime.getRuntime().availableProcessors(); assertEquals((int) (cpus * 2.2), cli.calculateDegreeOfConcurrency("2.2C")); assertEquals(1, cli.calculateDegreeOfConcurrency("0.0001C")); - assertThrows(IllegalArgumentException.class, () -> cli.calculateDegreeOfConcurrency("2.C")); assertThrows(IllegalArgumentException.class, () -> cli.calculateDegreeOfConcurrency("-2.2C")); assertThrows(IllegalArgumentException.class, () -> cli.calculateDegreeOfConcurrency("0C")); }