Skip to content

Commit

Permalink
User's preference for -T can be stored as mvnd.threads in ~/.m2/mvnd.…
Browse files Browse the repository at this point in the history
…properties #132
  • Loading branch information
ppalaga committed Oct 31, 2020
1 parent 52da011 commit fcce52c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 15 deletions.
33 changes: 21 additions & 12 deletions client/src/main/java/org/jboss/fuse/mvnd/client/ClientLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand All @@ -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;
Expand All @@ -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;
}

/**
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,7 @@ public ExecutionResult execute(ClientOutput output, List<String> argv) {

static void setDefaultArgs(List<String> 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");
Expand Down
11 changes: 11 additions & 0 deletions common/src/main/java/org/jboss/fuse/mvnd/common/Environment.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit fcce52c

Please sign in to comment.