diff --git a/client/src/main/java/org/jboss/fuse/mvnd/client/ClientLayout.java b/client/src/main/java/org/jboss/fuse/mvnd/client/ClientLayout.java index e822968ce..004409b68 100644 --- a/client/src/main/java/org/jboss/fuse/mvnd/client/ClientLayout.java +++ b/client/src/main/java/org/jboss/fuse/mvnd/client/ClientLayout.java @@ -41,7 +41,7 @@ public class ClientLayout extends Layout { private final int idleTimeoutMs; private final int keepAliveMs; private final int maxLostKeepAlive; - private final int minThreads; + private final String threads; public static ClientLayout getEnvInstance() { if (ENV_INSTANCE == null) { @@ -87,11 +87,20 @@ public static ClientLayout getEnvInstance() { .orLocalProperty(mvndProperties, mvndPropertiesPath) .orDefault(() -> Integer.toString(Environment.DEFAULT_MAX_LOST_KEEP_ALIVE)) .asInt(); - final int minThreads = Environment.MVND_MIN_THREADS + final String threads = Environment.MVND_THREADS .systemProperty() .orLocalProperty(mvndProperties, mvndPropertiesPath) - .orDefault(() -> Integer.toString(Environment.DEFAULT_MIN_THREADS)) - .asInt(); + .orDefault(() -> { + final int minThreads = Environment.MVND_MIN_THREADS + .systemProperty() + .orLocalProperty(mvndProperties, mvndPropertiesPath) + .orDefault(() -> Integer.toString(Environment.DEFAULT_MIN_THREADS)) + .asInt(); + return String + .valueOf(Math.max(Runtime.getRuntime().availableProcessors() - 1, minThreads)); + }) + .asString(); + ENV_INSTANCE = new ClientLayout( mvndPropertiesPath, mvndHome, @@ -101,14 +110,14 @@ public static ClientLayout getEnvInstance() { findLocalRepo(), null, Environment.findLogbackConfigurationPath(mvndProperties, mvndPropertiesPath, mvndHome), - idleTimeoutMs, keepAliveMs, maxLostKeepAlive, minThreads); + idleTimeoutMs, keepAliveMs, maxLostKeepAlive, threads); } return ENV_INSTANCE; } public ClientLayout(Path mvndPropertiesPath, Path mavenHome, Path userDir, Path multiModuleProjectDirectory, Path javaHome, Path localMavenRepository, Path settings, Path logbackConfigurationPath, int idleTimeoutMs, int keepAliveMs, - int maxLostKeepAlive, int minThreads) { + int maxLostKeepAlive, String threads) { super(mvndPropertiesPath, mavenHome, userDir, multiModuleProjectDirectory); this.localMavenRepository = localMavenRepository; this.settings = settings; @@ -117,7 +126,7 @@ public ClientLayout(Path mvndPropertiesPath, Path mavenHome, Path userDir, Path this.idleTimeoutMs = idleTimeoutMs; this.keepAliveMs = keepAliveMs; this.maxLostKeepAlive = maxLostKeepAlive; - this.minThreads = minThreads; + this.threads = threads; } /** @@ -127,7 +136,7 @@ public ClientLayout(Path mvndPropertiesPath, Path mavenHome, Path userDir, Path public ClientLayout cd(Path newUserDir) { return new ClientLayout(mvndPropertiesPath, mavenHome, newUserDir, multiModuleProjectDirectory, javaHome, localMavenRepository, settings, logbackConfigurationPath, idleTimeoutMs, keepAliveMs, maxLostKeepAlive, - minThreads); + threads); } /** @@ -166,11 +175,11 @@ public int getMaxLostKeepAlive() { } /** - * @return the minimum number of threads to use when constructing the default {@code -T} parameter for the daemon. - * This value is ignored if the user passes his own `-T` or `--threads`. + * @return the number of threads (same syntax as Maven's {@code -T}/{@code --threads} option) to pass to the daemon + * unless the user passes his own `-T` or `--threads`. */ - public int getMinThreads() { - return minThreads; + public String getThreads() { + return threads; } static Path findLocalRepo() { diff --git a/client/src/main/java/org/jboss/fuse/mvnd/client/DefaultClient.java b/client/src/main/java/org/jboss/fuse/mvnd/client/DefaultClient.java index 71de913aa..cfb0a5387 100644 --- a/client/src/main/java/org/jboss/fuse/mvnd/client/DefaultClient.java +++ b/client/src/main/java/org/jboss/fuse/mvnd/client/DefaultClient.java @@ -257,8 +257,7 @@ public ExecutionResult execute(ClientOutput output, List argv) { static void setDefaultArgs(List args, ClientLayout layout) { if (args.stream().noneMatch(arg -> arg.startsWith("-T") || arg.equals("--threads"))) { - final int threads = Math.max(Runtime.getRuntime().availableProcessors() - 1, layout.getMinThreads()); - args.add("-T" + threads); + args.add("-T" + layout.getThreads()); } if (args.stream().noneMatch(arg -> arg.startsWith("-b") || arg.equals("--builder"))) { args.add("-bsmart"); diff --git a/common/src/main/java/org/jboss/fuse/mvnd/common/Environment.java b/common/src/main/java/org/jboss/fuse/mvnd/common/Environment.java index e5f79753c..d2715d35e 100644 --- a/common/src/main/java/org/jboss/fuse/mvnd/common/Environment.java +++ b/common/src/main/java/org/jboss/fuse/mvnd/common/Environment.java @@ -45,7 +45,18 @@ public enum Environment { DAEMON_IDLE_TIMEOUT_MS("daemon.idleTimeoutMs", null), DAEMON_KEEP_ALIVE_MS("daemon.keepAliveMs", null), DAEMON_MAX_LOST_KEEP_ALIVE("daemon.maxLostKeepAlive", null), + /** + * The minimum number of threads to use when constructing the default {@code -T} parameter for the daemon. + * This value is ignored if the user passes @{@code-T}, @{@code --threads} or {@code -Dmvnd.threads} on the command + * line or if he sets {@code mvnd.threads} in {@code ~/.m2/mvnd.properties}. + */ MVND_MIN_THREADS("mvnd.minThreads", null), + /** + * The number of threads to pass to the daemon; same syntax as Maven's {@code -T}/{@code --threads} option. Ignored + * if the user passes @{@code-T}, @{@code --threads} or {@code -Dmvnd.threads} on the command + * line. + */ + MVND_THREADS("mvnd.threads", null), DAEMON_UID("daemon.uid", null); public static final int DEFAULT_IDLE_TIMEOUT = (int) TimeUnit.HOURS.toMillis(3); diff --git a/integration-tests/src/test/java/org/jboss/fuse/mvnd/junit/TestLayout.java b/integration-tests/src/test/java/org/jboss/fuse/mvnd/junit/TestLayout.java index 0d98c5f93..01f7656de 100644 --- a/integration-tests/src/test/java/org/jboss/fuse/mvnd/junit/TestLayout.java +++ b/integration-tests/src/test/java/org/jboss/fuse/mvnd/junit/TestLayout.java @@ -26,7 +26,8 @@ public TestLayout(Path testDir, Path mvndPropertiesPath, Path mavenHome, Path us Path javaHome, Path localMavenRepository, Path settings, Path logbackConfigurationPath, int idleTimeout, int keepAlive, int maxLostKeepAlive) { super(mvndPropertiesPath, mavenHome, userDir, multiModuleProjectDirectory, javaHome, localMavenRepository, - settings, logbackConfigurationPath, idleTimeout, keepAlive, maxLostKeepAlive, TEST_MIN_THREADS); + settings, logbackConfigurationPath, idleTimeout, keepAlive, maxLostKeepAlive, + String.valueOf(Math.max(Runtime.getRuntime().availableProcessors() - 1, TEST_MIN_THREADS))); this.testDir = testDir; }