diff --git a/client/src/main/java/org/jboss/fuse/mvnd/client/DaemonClientConnection.java b/client/src/main/java/org/jboss/fuse/mvnd/client/DaemonClientConnection.java index bf1328131..50e3b2735 100644 --- a/client/src/main/java/org/jboss/fuse/mvnd/client/DaemonClientConnection.java +++ b/client/src/main/java/org/jboss/fuse/mvnd/client/DaemonClientConnection.java @@ -66,10 +66,6 @@ public DaemonClientConnection(DaemonConnection connection, DaemonInfo daemon, this.parameters = parameters; } - public DaemonInfo getDaemon() { - return daemon; - } - public void dispatch(Message message) throws DaemonException.ConnectException { LOG.debug("thread {}: dispatching {}", Thread.currentThread().getId(), message.getClass()); try { diff --git a/client/src/main/java/org/jboss/fuse/mvnd/client/DaemonParameters.java b/client/src/main/java/org/jboss/fuse/mvnd/client/DaemonParameters.java index b4a3b26e8..8cf0dcc61 100644 --- a/client/src/main/java/org/jboss/fuse/mvnd/client/DaemonParameters.java +++ b/client/src/main/java/org/jboss/fuse/mvnd/client/DaemonParameters.java @@ -24,6 +24,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Optional; @@ -55,10 +56,14 @@ public class DaemonParameters { protected final Map mvndProperties = new ConcurrentHashMap<>(); protected final Function provider = path -> mvndProperties.computeIfAbsent(path, p -> loadProperties(path)); - protected final Properties properties; + private final Map properties; - public DaemonParameters(Properties properties) { - this.properties = properties; + public DaemonParameters() { + this.properties = Collections.emptyMap(); + } + + protected DaemonParameters(PropertiesBuilder propertiesBuilder) { + this.properties = propertiesBuilder.build(); } public List getDaemonOpts() { @@ -239,10 +244,9 @@ public Path mavenRepoLocal() { * @return a new {@link DaemonParameters} with {@code userDir} set to the given {@code newUserDir} */ public DaemonParameters cd(Path newUserDir) { - Properties properties = new Properties(); - properties.putAll(this.properties); - properties.put(Environment.USER_DIR.getProperty(), newUserDir.toString()); - return new DaemonParameters(properties); + return new DaemonParameters(new PropertiesBuilder() + .putAll(this.properties) + .put(Environment.USER_DIR, newUserDir)); } public int keepAliveMs() { @@ -282,7 +286,7 @@ public EnvValue property(Environment env) { protected EnvValue value(Environment env) { return new EnvValue(env, new ValueSource( description -> description.append("value: ").append(env.getProperty()), - () -> properties.getProperty(env.getProperty()))); + () -> properties.get(env.getProperty()))); } public static EnvValue systemProperty(Environment env) { @@ -354,6 +358,30 @@ private static Properties loadProperties(Path path) { return result; } + public static class PropertiesBuilder { + private Map properties = new LinkedHashMap<>(); + + public PropertiesBuilder put(Environment envKey, Object value) { + if (value == null) { + properties.remove(envKey.getProperty()); + } else { + properties.put(envKey.getProperty(), value.toString()); + } + return this; + } + + public PropertiesBuilder putAll(Map props) { + properties.putAll(props); + return this; + } + + public Map build() { + Map props = properties; + properties = null; + return Collections.unmodifiableMap(props); + } + } + /** * A source of an environment value with a description capability. */ 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 bcf7a3d74..3dd276f76 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 @@ -22,8 +22,6 @@ import java.time.ZoneId; import java.util.ArrayList; import java.util.List; -import java.util.Properties; -import java.util.function.Supplier; import org.fusesource.jansi.Ansi; import org.jboss.fuse.mvnd.common.BuildProperties; import org.jboss.fuse.mvnd.common.DaemonInfo; @@ -48,7 +46,7 @@ public class DefaultClient implements Client { private static final Logger LOGGER = LoggerFactory.getLogger(DefaultClient.class); - private final Supplier lazyParameters; + private final DaemonParameters parameters; public static void main(String[] argv) throws Exception { final List args = new ArrayList<>(argv.length); @@ -69,12 +67,12 @@ public static void main(String[] argv) throws Exception { } try (TerminalOutput output = new TerminalOutput(logFile)) { - new DefaultClient(() -> new DaemonParameters(new Properties())).execute(output, args); + new DefaultClient(new DaemonParameters()).execute(output, args); } } - public DefaultClient(Supplier lazyParameters) { - this.lazyParameters = lazyParameters; + public DefaultClient(DaemonParameters parameters) { + this.parameters = parameters; } @Override @@ -144,7 +142,6 @@ public ExecutionResult execute(ClientOutput output, List argv) { */ } - final DaemonParameters parameters = lazyParameters.get(); try (DaemonRegistry registry = new DaemonRegistry(parameters.registry())) { boolean status = args.remove("--status"); if (status) { diff --git a/integration-tests/src/test/java/org/jboss/fuse/mvnd/it/InteractiveTest.java b/integration-tests/src/test/java/org/jboss/fuse/mvnd/it/InteractiveTest.java index b2b11ca64..c06e0abe7 100644 --- a/integration-tests/src/test/java/org/jboss/fuse/mvnd/it/InteractiveTest.java +++ b/integration-tests/src/test/java/org/jboss/fuse/mvnd/it/InteractiveTest.java @@ -16,9 +16,7 @@ package org.jboss.fuse.mvnd.it; import java.io.IOException; - import javax.inject.Inject; - import org.jboss.fuse.mvnd.client.Client; import org.jboss.fuse.mvnd.client.DaemonParameters; import org.jboss.fuse.mvnd.common.logging.ClientOutput; diff --git a/integration-tests/src/test/java/org/jboss/fuse/mvnd/junit/MvndTestExtension.java b/integration-tests/src/test/java/org/jboss/fuse/mvnd/junit/MvndTestExtension.java index c9592e5ce..fbdb2b90b 100644 --- a/integration-tests/src/test/java/org/jboss/fuse/mvnd/junit/MvndTestExtension.java +++ b/integration-tests/src/test/java/org/jboss/fuse/mvnd/junit/MvndTestExtension.java @@ -121,7 +121,7 @@ Client newClient(boolean isNative, DaemonParameters parameters, long timeoutMs) } return new NativeTestClient(parameters, mvndNativeExecutablePath, timeoutMs); } else { - return new DefaultClient(() -> parameters); + return new DefaultClient(parameters); } } @@ -193,7 +193,7 @@ public static MvndResource create(String className, String rawProjectDir, boolea final Path mvndPropertiesPath = testDir.resolve("mvnd.properties"); final Path localMavenRepository = deleteDir(testDir.resolve("local-maven-repo")); final Path settingsPath = createSettings(testDir.resolve("settings.xml")); - final Path logback = Paths.get("src/test/resources/logback.xml").toAbsolutePath(); + final Path logback = Paths.get("src/test/resources/logback/logback.xml").toAbsolutePath(); final Path home = deleteDir(testDir.resolve("home")); final TestParameters parameters = new TestParameters( testDir, diff --git a/integration-tests/src/test/java/org/jboss/fuse/mvnd/junit/TestParameters.java b/integration-tests/src/test/java/org/jboss/fuse/mvnd/junit/TestParameters.java index 0ce27c461..0b0663f58 100644 --- a/integration-tests/src/test/java/org/jboss/fuse/mvnd/junit/TestParameters.java +++ b/integration-tests/src/test/java/org/jboss/fuse/mvnd/junit/TestParameters.java @@ -16,7 +16,6 @@ package org.jboss.fuse.mvnd.junit; import java.nio.file.Path; -import java.util.Properties; import org.jboss.fuse.mvnd.client.DaemonParameters; import org.jboss.fuse.mvnd.common.Environment; @@ -28,27 +27,21 @@ public TestParameters(Path testDir, Path mvndPropertiesPath, Path mavenHome, Pat Path multiModuleProjectDirectory, Path javaHome, Path localMavenRepository, Path settings, Path logbackConfigurationPath, int idleTimeout, int keepAlive, int maxLostKeepAlive) { - super(new Properties()); + super(new PropertiesBuilder().put(Environment.MVND_PROPERTIES_PATH, mvndPropertiesPath) + .put(Environment.MVND_HOME, mavenHome) + .put(Environment.USER_HOME, userHome) + .put(Environment.USER_DIR, userDir) + .put(Environment.MAVEN_MULTIMODULE_PROJECT_DIRECTORY, multiModuleProjectDirectory) + .put(Environment.JAVA_HOME, javaHome) + .put(Environment.MAVEN_REPO_LOCAL, localMavenRepository) + .put(Environment.MAVEN_SETTINGS, settings) + .put(Environment.LOGBACK_CONFIGURATION_FILE, logbackConfigurationPath) + .put(Environment.DAEMON_IDLE_TIMEOUT_MS, idleTimeout) + .put(Environment.DAEMON_KEEP_ALIVE_MS, keepAlive) + .put(Environment.DAEMON_MAX_LOST_KEEP_ALIVE, maxLostKeepAlive) + .put(Environment.MVND_MIN_THREADS, TEST_MIN_THREADS)); this.testDir = testDir; - put(Environment.MVND_PROPERTIES_PATH, mvndPropertiesPath); - put(Environment.MVND_HOME, mavenHome); - put(Environment.USER_HOME, userHome); - put(Environment.USER_DIR, userDir); - put(Environment.MAVEN_MULTIMODULE_PROJECT_DIRECTORY, multiModuleProjectDirectory); - put(Environment.JAVA_HOME, javaHome); - put(Environment.MAVEN_REPO_LOCAL, localMavenRepository); - put(Environment.MAVEN_SETTINGS, settings); - put(Environment.LOGBACK_CONFIGURATION_FILE, logbackConfigurationPath); - put(Environment.DAEMON_IDLE_TIMEOUT_MS, idleTimeout); - put(Environment.DAEMON_KEEP_ALIVE_MS, keepAlive); - put(Environment.DAEMON_MAX_LOST_KEEP_ALIVE, maxLostKeepAlive); - put(Environment.MVND_MIN_THREADS, TEST_MIN_THREADS); - } - private void put(Environment env, Object value) { - if (value != null) { - this.properties.put(env.getProperty(), value.toString()); - } } public Path getTestDir() { diff --git a/integration-tests/src/test/resources/logback.xml b/integration-tests/src/test/resources/logback/logback.xml similarity index 100% rename from integration-tests/src/test/resources/logback.xml rename to integration-tests/src/test/resources/logback/logback.xml