Skip to content

Commit

Permalink
Clean the names of properties, fixes apache#221
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Nov 16, 2020
1 parent 1ac4844 commit bcf23d1
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 47 deletions.
Expand Up @@ -127,9 +127,9 @@ private DaemonClientConnection connectNoDaemon() {
properties.put(Environment.USER_DIR.getProperty(), parameters.userDir().toString());
properties.put(Environment.USER_HOME.getProperty(), parameters.userHome().toString());
properties.put(Environment.MVND_HOME.getProperty(), parameters.mvndHome().toString());
properties.put(Environment.DAEMON_UID.getProperty(), daemon);
properties.put(Environment.MVND_UID.getProperty(), daemon);
properties.put(Environment.MVND_DAEMON_STORAGE.getProperty(), parameters.daemonStorage().toString());
properties.put(Environment.DAEMON_REGISTRY.getProperty(), parameters.registry().toString());
properties.put(Environment.MVND_REGISTRY.getProperty(), parameters.registry().toString());
properties.putAll(parameters.getDaemonOptsMap());
Environment.setProperties(properties);
AtomicReference<Throwable> throwable = new AtomicReference<>();
Expand Down Expand Up @@ -305,7 +305,7 @@ private Process startDaemon(String uid) {
final String classpath = mvndHome.resolve(mvndCommonPath).toString();
args.add(classpath);
// debug options
if (parameters.property(Environment.DAEMON_DEBUG).asBoolean()) {
if (parameters.property(Environment.MVND_DEBUG).asBoolean()) {
args.add("-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8000");
}
// jvm args
Expand All @@ -330,9 +330,9 @@ private Process startDaemon(String uid) {
args.add(Environment.MVND_HOME.asCommandLineProperty(mvndHome.toString()));
args.add(Environment.LOGBACK_CONFIGURATION_FILE
.asCommandLineProperty(parameters.logbackConfigurationPath().toString()));
args.add(Environment.DAEMON_UID.asCommandLineProperty(uid));
args.add(Environment.MVND_UID.asCommandLineProperty(uid));
args.add(Environment.MVND_DAEMON_STORAGE.asCommandLineProperty(parameters.daemonStorage().toString()));
args.add(Environment.DAEMON_REGISTRY.asCommandLineProperty(parameters.registry().toString()));
args.add(Environment.MVND_REGISTRY.asCommandLineProperty(parameters.registry().toString()));
args.addAll(parameters.getDaemonCommandLineProperties());
args.add(MavenDaemon.class.getName());
command = String.join(" ", args);
Expand Down
Expand Up @@ -209,15 +209,15 @@ public Path logbackConfigurationPath() {
}

public String minHeapSize() {
return property(Environment.DAEMON_MIN_HEAP_SIZE).asString();
return property(Environment.MVND_MIN_HEAP_SIZE).asString();
}

public String maxHeapSize() {
return property(Environment.DAEMON_MAX_HEAP_SIZE).asString();
return property(Environment.MVND_MAX_HEAP_SIZE).asString();
}

public String jvmArgs() {
return property(Environment.DAEMON_JVM_ARGS).asString();
return property(Environment.MVND_JVM_ARGS).asString();
}

/**
Expand Down Expand Up @@ -273,11 +273,11 @@ public DaemonParameters cd(Path newUserDir) {
}

public Duration keepAlive() {
return property(Environment.DAEMON_KEEP_ALIVE).orFail().asDuration();
return property(Environment.MVND_KEEP_ALIVE).orFail().asDuration();
}

public int maxLostKeepAlive() {
return property(Environment.DAEMON_MAX_LOST_KEEP_ALIVE).orFail().asInt();
return property(Environment.MVND_MAX_LOST_KEEP_ALIVE).orFail().asInt();
}

public boolean noBuffering() {
Expand Down Expand Up @@ -337,10 +337,10 @@ public static EnvValue fromValueSource(Environment env, ValueSource valueSource)
}

private String defaultValue(Environment env) {
if (env == Environment.DAEMON_EXT_CLASSPATH) {
if (env == Environment.MVND_EXT_CLASSPATH) {
List<String> cp = parseExtClasspath(userHome());
return String.join(",", cp);
} else if (env == Environment.DAEMON_CORE_EXTENSIONS) {
} else if (env == Environment.MVND_CORE_EXTENSIONS) {
try {
List<String> extensions = readCoreExtensionsDescriptor(multiModuleProjectDirectory()).stream()
.map(e -> e.getGroupId() + ":" + e.getArtifactId() + ":" + e.getVersion())
Expand Down
80 changes: 60 additions & 20 deletions common/src/main/java/org/mvndaemon/mvnd/common/Environment.java
Expand Up @@ -26,28 +26,41 @@
/**
* Collects system properties and environment variables used by mvnd client or server.
*
* Duration properties such as {@link #DAEMON_IDLE_TIMEOUT}, {@link #DAEMON_KEEP_ALIVE},
* {@link #DAEMON_EXPIRATION_CHECK_DELAY} or {@link #MVND_LOG_PURGE_PERIOD} are expressed
* Duration properties such as {@link #MVND_IDLE_TIMEOUT}, {@link #MVND_KEEP_ALIVE},
* {@link #MVND_EXPIRATION_CHECK_DELAY} or {@link #MVND_LOG_PURGE_PERIOD} are expressed
* in a human readable format such as {@code 2h30m}, {@code 600ms} or {@code 10 seconds}.
* The available units are <i>d/day/days</i>, <i>h/hour/hours</i>, <i>m/min/minute/minutes</i>,
* <i>s/sec/second/seconds</i> and <i>ms/millis/msec/milliseconds</i>.
*/
public enum Environment {

//
// Log properties
//

/**
* The location of the logback configuration file
*/
LOGBACK_CONFIGURATION_FILE("logback.configurationFile", null, null, false),

//
// System properties
//
/** java home directory */
JAVA_HOME("java.home", "JAVA_HOME", null, false),
/** mvnd home directory */
MVND_HOME("mvnd.home", "MVND_HOME", null, false),
/** user home directory */
USER_HOME("user.home", null, null, false),
/** user current dir */
USER_DIR("user.dir", null, null, false),

//
// Maven properties
//
/** path to the maven local repository */
MAVEN_REPO_LOCAL("maven.repo.local", null, null, false),
/** location of the maven settings file */
MAVEN_SETTINGS("maven.settings", null, null, false) {
@Override
public boolean hasCommandLineProperty(Collection<String> args) {
Expand All @@ -59,12 +72,25 @@ public String asCommandLineProperty(String value) {
return "--settings=" + value;
}
},
/** root directory of a multi module project */
MAVEN_MULTIMODULE_PROJECT_DIRECTORY("maven.multiModuleProjectDirectory", null, null, false),

//
// mvnd properties
//
MVND_PROPERTIES_PATH("mvnd.properties.path", "MVND_PROPERTIES_PATH", null, false),
MVND_DAEMON_STORAGE("mvnd.daemon.storage", null, null, false),

/**
* Location of the user supplied mvnd properties
*/
MVND_PROPERTIES_PATH("mvnd.propertiesPath", "MVND_PROPERTIES_PATH", null, false),
/**
* Directory where mvnd stores its files (the registry and the daemon logs).
*/
MVND_DAEMON_STORAGE("mvnd.daemonStorage", null, null, false),
/**
* The path to the daemon registry, defaults to <code>${mvnd.daemonStorage}/registry.bin</code>
*/
MVND_REGISTRY("mvnd.registry", null, null, false),
/**
* Property that can be set to avoid buffering the output and display events continuously, closer to the usual maven
* display. Passing {@code -B} or {@code --batch-mode} on the command line enables this too for the given build.
Expand All @@ -75,18 +101,32 @@ public String asCommandLineProperty(String value) {
*/
MVND_ROLLING_WINDOW_SIZE("mvnd.rollingWindowSize", null, "0", false),
/**
* The automatic log purge period
* The automatic log purge period.
*/
MVND_LOG_PURGE_PERIOD("mvnd.logPurgePeriod", null, "7d", false),
/**
* The path to the daemon registry
* Property to disable using a daemon (usefull for debugging, and only available in non native mode).
*/
DAEMON_REGISTRY("daemon.registry", null, null, false),
MVND_NO_DAEMON("mvnd.noDaemon", "MVND_NO_DAEMON", "false", true),
DAEMON_DEBUG("daemon.debug", null, false, true),
DAEMON_IDLE_TIMEOUT("daemon.idleTimeout", null, "3 hours", true),
DAEMON_KEEP_ALIVE("daemon.keepAlive", null, "1 sec", true),
DAEMON_MAX_LOST_KEEP_ALIVE("daemon.maxLostKeepAlive", null, 3, false),
/**
* Property to launch the daemon in debug mode with the following JVM argument
* <code>-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8000</code>
*/
MVND_DEBUG("mvnd.debug", null, false, true),
/**
* Duration after which an usused daemon will shut down.
*/
MVND_IDLE_TIMEOUT("mvnd.idleTimeout", null, "3 hours", true),
/**
* Time after which a daemon will send a keep-alive message to the client if the current build
* has produced no output.
*/
MVND_KEEP_ALIVE("mvnd.keepAlive", null, "1 sec", true),
/**
* The maximum number of keep alive message that can be lost before the client considers the daemon
* as having had a failure.
*/
MVND_MAX_LOST_KEEP_ALIVE("mvnd.maxLostKeepAlive", null, 3, false),
/**
* 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
Expand Down Expand Up @@ -128,39 +168,39 @@ public String asCommandLineProperty(String value) {
/**
* Internal system property set by the client when starting the daemon to identify its id
*/
DAEMON_UID("daemon.uid", null, null, false),
MVND_UID("mvnd.uid", null, null, false),
/**
* Internal option to specify the maven extension classpath
*/
DAEMON_EXT_CLASSPATH("daemon.ext.classpath", null, null, true),
MVND_EXT_CLASSPATH("mvnd.extClasspath", null, null, true),
/**
* Internal option to specify the list of maven extension to register
*/
DAEMON_CORE_EXTENSIONS("daemon.core.extensions", null, null, true),
MVND_CORE_EXTENSIONS("mvnd.coreExtensions", null, null, true),
/**
* JVM options for the daemon
*/
DAEMON_MIN_HEAP_SIZE("daemon.minHeapSize", null, "128M", true),
MVND_MIN_HEAP_SIZE("mvnd.minHeapSize", null, "128M", true),
/**
* JVM options for the daemon
*/
DAEMON_MAX_HEAP_SIZE("daemon.maxHeapSize", null, "2G", true),
MVND_MAX_HEAP_SIZE("mvnd.maxHeapSize", null, "2G", true),
/**
* Additional JVM args for the daemon
*/
DAEMON_JVM_ARGS("daemon.jvmArgs", null, "", true),
MVND_JVM_ARGS("mvnd.jvmArgs", null, "", true),
/**
* JVM options for the daemon
*/
DAEMON_ENABLE_ASSERTIONS("daemon.enableAssertions", null, false, true),
MVND_ENABLE_ASSERTIONS("mvnd.enableAssertions", null, false, true),
/**
* Interval to check if the daemon should expire
*/
DAEMON_EXPIRATION_CHECK_DELAY("daemon.expirationCheckDelay", null, "10 seconds", true),
MVND_EXPIRATION_CHECK_DELAY("mvnd.expirationCheckDelay", null, "10 seconds", true),
/**
* Period after which idle daemons will shut down
*/
DAEMON_DUPLICATE_DAEMON_GRACE_PERIOD("daemon.duplicateDaemonGracePeriod", null, "10 seconds", true),
MVND_DUPLICATE_DAEMON_GRACE_PERIOD("mvnd.duplicateDaemonGracePeriod", null, "10 seconds", true),
;

static Properties properties = System.getProperties();
Expand Down
4 changes: 2 additions & 2 deletions daemon/src/main/java/org/apache/maven/cli/DaemonMavenCli.java
Expand Up @@ -424,14 +424,14 @@ void container()
}

List<File> extClassPath = Stream
.of(Environment.DAEMON_EXT_CLASSPATH.asString().split(","))
.of(Environment.MVND_EXT_CLASSPATH.asString().split(","))
.map(File::new)
.collect(Collectors.toList());

CoreExtensionEntry coreEntry = CoreExtensionEntry.discoverFrom(coreRealm);

List<CoreExtension> extensions = Stream
.of(Environment.DAEMON_CORE_EXTENSIONS.asString().split(","))
.of(Environment.MVND_CORE_EXTENSIONS.asString().split(","))
.filter(s -> s != null && !s.isEmpty())
.map(s -> {
String[] parts = s.split(":");
Expand Down
Expand Up @@ -54,7 +54,7 @@ public static DaemonExpirationStrategy master() {
return any(
any(gcTrashing(), lowHeapSpace(), lowNonHeap()),
all(compatible(), duplicateGracePeriod(), notMostRecentlyUsed()),
idleTimeout(Environment.DAEMON_IDLE_TIMEOUT.asDuration()),
idleTimeout(Environment.MVND_IDLE_TIMEOUT.asDuration()),
all(duplicateGracePeriod(), notMostRecentlyUsed(), lowMemory(0.05)),
registryUnavailable());
}
Expand Down Expand Up @@ -83,7 +83,7 @@ static DaemonExpirationStrategy lowMemory(double minFreeMemoryPercentage) {
}

static DaemonExpirationStrategy duplicateGracePeriod() {
return idleTimeout(Environment.DAEMON_DUPLICATE_DAEMON_GRACE_PERIOD.asDuration());
return idleTimeout(Environment.MVND_DUPLICATE_DAEMON_GRACE_PERIOD.asDuration());
}

static DaemonExpirationStrategy idleTimeout(Duration timeout) {
Expand Down
8 changes: 4 additions & 4 deletions daemon/src/main/java/org/mvndaemon/mvnd/daemon/Server.java
Expand Up @@ -105,11 +105,11 @@ public Server() throws IOException {
} catch (Throwable t) {
LOGGER.warn("Unable to ignore INT and TSTP signals", t);
}
this.uid = Environment.DAEMON_UID.asString();
this.uid = Environment.MVND_UID.asString();
this.noDaemon = Environment.MVND_NO_DAEMON.asBoolean();
try {
cli = new DaemonMavenCli();
registry = new DaemonRegistry(Environment.DAEMON_REGISTRY.asPath());
registry = new DaemonRegistry(Environment.MVND_REGISTRY.asPath());
socket = ServerSocketChannel.open().bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0));
executor = Executors.newScheduledThreadPool(1);
strategy = DaemonExpiration.master();
Expand Down Expand Up @@ -184,7 +184,7 @@ public void clearCache(String clazzName, String fieldName) {

public void run() {
try {
Duration expirationCheckDelay = Environment.DAEMON_EXPIRATION_CHECK_DELAY.asDuration();
Duration expirationCheckDelay = Environment.MVND_EXPIRATION_CHECK_DELAY.asDuration();
executor.scheduleAtFixedRate(this::expirationCheck,
expirationCheckDelay.toMillis(), expirationCheckDelay.toMillis(), TimeUnit.MILLISECONDS);
LOGGER.info("Daemon started");
Expand Down Expand Up @@ -424,7 +424,7 @@ private void cancelNow() {
private void handle(DaemonConnection connection, BuildRequest buildRequest) {
updateState(Busy);
try {
Duration keepAlive = Environment.DAEMON_KEEP_ALIVE.asDuration();
Duration keepAlive = Environment.MVND_KEEP_ALIVE.asDuration();

LOGGER.info("Executing request");

Expand Down
Expand Up @@ -49,7 +49,7 @@ void version() throws IOException, InterruptedException {
client.execute(o, "-v").assertSuccess();
Assertions.assertThat(registry.getAll().size()).isEqualTo(1);
DaemonInfo daemon = registry.getAll().iterator().next();
assertTrue(daemon.getOptions().contains("daemon.core.extensions=io.takari.aether:takari-local-repository:0.11.3"));
assertTrue(daemon.getOptions().contains("mvnd.coreExtensions=io.takari.aether:takari-local-repository:0.11.3"));

registry.awaitIdle(daemon.getUid());

Expand Down
Expand Up @@ -205,9 +205,9 @@ public static MvndResource create(String className, String rawProjectDir, boolea
Paths.get(System.getProperty("java.home")).toAbsolutePath().normalize(),
localMavenRepository, settingsPath,
logback,
TimeUtils.toDuration(Environment.DAEMON_IDLE_TIMEOUT.getDef()),
TimeUtils.toDuration(Environment.DAEMON_KEEP_ALIVE.getDef()),
Integer.parseInt(Environment.DAEMON_MAX_LOST_KEEP_ALIVE.getDef()));
TimeUtils.toDuration(Environment.MVND_IDLE_TIMEOUT.getDef()),
TimeUtils.toDuration(Environment.MVND_KEEP_ALIVE.getDef()),
Integer.parseInt(Environment.MVND_MAX_LOST_KEEP_ALIVE.getDef()));
final TestRegistry registry = new TestRegistry(parameters.registry());

return new MvndResource(parameters, registry, isNative, timeoutMs);
Expand Down
Expand Up @@ -38,9 +38,9 @@ public TestParameters(Path testDir, Path mvndPropertiesPath, Path mavenHome, Pat
.put(Environment.MAVEN_REPO_LOCAL, localMavenRepository)
.put(Environment.MAVEN_SETTINGS, settings)
.put(Environment.LOGBACK_CONFIGURATION_FILE, logbackConfigurationPath)
.put(Environment.DAEMON_IDLE_TIMEOUT, TimeUtils.printDuration(idleTimeout))
.put(Environment.DAEMON_KEEP_ALIVE, TimeUtils.printDuration(keepAlive))
.put(Environment.DAEMON_MAX_LOST_KEEP_ALIVE, maxLostKeepAlive)
.put(Environment.MVND_IDLE_TIMEOUT, TimeUtils.printDuration(idleTimeout))
.put(Environment.MVND_KEEP_ALIVE, TimeUtils.printDuration(keepAlive))
.put(Environment.MVND_MAX_LOST_KEEP_ALIVE, maxLostKeepAlive)
.put(Environment.MVND_MIN_THREADS, TEST_MIN_THREADS));
this.testDir = testDir;

Expand Down

0 comments on commit bcf23d1

Please sign in to comment.