Skip to content

Commit

Permalink
Attempt at moving mvn as first class citizen in mvnd distribution, ap…
Browse files Browse the repository at this point in the history
…ache#392

We may need to revisit the logging configuration to be closer to maven if needed.
  • Loading branch information
gnodet committed Jan 23, 2023
1 parent a2a5854 commit fc683e0
Show file tree
Hide file tree
Showing 15 changed files with 53 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ private Process startDaemonProcess(String daemonId, ClientOutput output) {
final Path mvndHome = parameters.mvndHome();
final Path workingDir = parameters.userDir();
String command = "";
try (DirectoryStream<Path> jarPaths = Files.newDirectoryStream(mvndHome.resolve("mvn/lib/ext"))) {
try (DirectoryStream<Path> jarPaths = Files.newDirectoryStream(mvndHome.resolve("lib/mvnd"))) {
List<String> args = new ArrayList<>();
// executable
final String java = Os.current().isUnixLike() ? "bin/java" : "bin\\java.exe";
Expand All @@ -347,10 +347,10 @@ private Process startDaemonProcess(String daemonId, ClientOutput output) {
}
}
if (mvndCommonPath == null) {
throw new IllegalStateException("Could not find mvnd-common jar in mvn/lib/ext/");
throw new IllegalStateException("Could not find mvnd-common jar in lib/mvnd/");
}
if (mvndAgentPath == null) {
throw new IllegalStateException("Could not find mvnd-agent jar in mvn/lib/ext/");
throw new IllegalStateException("Could not find mvnd-agent jar in lib/mvnd/");
}
args.add("-classpath");
args.add(mvndCommonPath + File.pathSeparator + mvndAgentPath);
Expand Down Expand Up @@ -408,8 +408,8 @@ private Process startDaemonProcess(String daemonId, ClientOutput output) {
}

Environment.MVND_HOME.addSystemProperty(args, mvndHome.toString());
args.add("-Dmaven.home=" + mvndHome.resolve("mvn"));
args.add("-Dmaven.conf=" + mvndHome.resolve("mvn/conf"));
args.add("-Dmaven.home=" + mvndHome);
args.add("-Dmaven.conf=" + mvndHome.resolve("conf"));

Environment.MVND_JAVA_HOME.addSystemProperty(
args, parameters.javaHome().toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ private String mvndHomeFromExecutable() {
if (Environment.isNative() && cmd.isPresent()) {
final Path mvndH = Paths.get(cmd.get()).getParent().getParent();
if (mvndH != null) {
final Path mvndDaemonLib = mvndH.resolve("mvn/lib/ext/mvnd-daemon-"
+ BuildProperties.getInstance().getVersion() + ".jar");
final Path mvndDaemonLib = mvndH.resolve(
"lib/mvnd/mvnd-daemon-" + BuildProperties.getInstance().getVersion() + ".jar");
if (Files.exists(mvndDaemonLib)) {
return mvndH.toString();
}
Expand Down Expand Up @@ -238,7 +238,7 @@ public Path multiModuleProjectDirectory(Path projectDir) {

public Path logbackConfigurationPath() {
return property(Environment.MVND_LOGBACK)
.orDefault(() -> mvndHome().resolve("conf/logback.xml").toString())
.orDefault(() -> mvndHome().resolve("conf/logback-mvnd.xml").toString())
.orFail()
.asPath();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static void main(String[] args) throws Exception {
final Path mvndHome = Environment.MVND_HOME.asPath();
URL[] classpath = Stream.concat(
/* jars */
Stream.of("mvn/lib/ext", "mvn/lib", "mvn/boot")
Stream.of("lib/mvnd", "lib/ext", "lib", "boot")
.map(mvndHome::resolve)
.flatMap((Path p) -> {
try {
Expand All @@ -46,7 +46,7 @@ public static void main(String[] args) throws Exception {
})
.filter(Files::isRegularFile),
/* resources */
Stream.of(mvndHome.resolve("mvn/conf"), mvndHome.resolve("mvn/conf/logging")))
Stream.of(mvndHome.resolve("conf"), mvndHome.resolve("conf/logging")))
.map(Path::normalize)
.map(Path::toUri)
.map(uri -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ exec "$JAVACMD" \
$MAVEN_OPTS \
$MAVEN_DEBUG_OPTS \
-classpath "${CLASSWORLDS_JAR}" \
"-Dlogback.configurationFile=${MAVEN_HOME}/conf/logging/logback.xml" \
"-Dclassworlds.conf=${MAVEN_HOME}/bin/m2.conf" \
"-Dlogback.configurationFile=${MAVEN_HOME}/conf/logback.xml" \
"-Dclassworlds.conf=${MAVEN_HOME}/bin/mvn.conf" \
"-Dmaven.home=${MAVEN_HOME}" \
"-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
${CLASSWORLDS_LAUNCHER} "$@"
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ set CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
%MAVEN_OPTS% ^
%MAVEN_DEBUG_OPTS% ^
-classpath %CLASSWORLDS_JAR% ^
"-Dlogback.configurationFile=%MAVEN_HOME%\conf\logging\logback.xml" ^
"-Dclassworlds.conf=%MAVEN_HOME%\bin\m2.conf" ^
"-Dlogback.configurationFile=%MAVEN_HOME%\conf\logback.xml" ^
"-Dclassworlds.conf=%MAVEN_HOME%\bin\mvn.conf" ^
"-Dmaven.home=%MAVEN_HOME%" ^
"-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^
%CLASSWORLDS_LAUNCHER% %MAVEN_CMD_LINE_ARGS%
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion dist/src/main/distro/bin/mvnd.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ set CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
%MAVEN_OPTS% ^
%MAVEN_DEBUG_OPTS% ^
-classpath %CLASSWORLDS_JAR% ^
"-Dclassworlds.conf=%MVND_HOME%\bin\m2.conf"
"-Dclassworlds.conf=%MVND_HOME%\bin\mvnd.conf"
"-Dmvnd.home=%MVND_HOME%" ^
"-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^
%CLASSWORLDS_LAUNCHER% %MAVEN_CMD_LINE_ARGS%
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
# under the License.
main is org.mvndaemon.mvnd.client.DefaultClient from plexus.core

set maven.home default ${mvnd.home}/mvn
set maven.home default ${mvnd.home}
set maven.conf default ${maven.home}/conf
set logback.configurationFile default ${mvnd.home}/conf/logback-client.xml
set logback.configurationFile.fallback default ${maven.conf}/logging/logback.xml
set logback.configurationFile default ${maven.conf}/logback-client.xml
set logback.configurationFile.fallback default ${maven.conf}/logback.xml

[plexus.core]
load ${maven.conf}/logging
Expand Down
2 changes: 1 addition & 1 deletion dist/src/main/distro/bin/mvnd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ exec "$JAVACMD" \
$MAVEN_OPTS \
$MAVEN_DEBUG_OPTS \
-classpath "${CLASSWORLDS_JAR}" \
"-Dclassworlds.conf=${MVND_HOME}/bin/m2.conf" \
"-Dclassworlds.conf=${MVND_HOME}/bin/mvnd.conf" \
"-Dmvnd.home=${MVND_HOME}" \
"-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
${CLASSWORLDS_LAUNCHER} "$@"
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!--
Copyright 2020 the original author or authors.
Copyright 2019 the original author or authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -25,18 +25,21 @@
<configuration>
<contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator" />

<!--
| write project-specific build log messages to ${project.build.directory}/build.log files
-->
<appender name="CONSOLE" class="org.mvndaemon.mvnd.logging.internal.SimpleAppender" />
<appender name="DAEMON" class="ch.qos.logback.core.FileAppender">
<file>${mvnd.daemonStorage}/daemon-${mvnd.id}.log</file>
<encoder>
<pattern>%d{HH:mm:ss.SSS} %.-1level %msg%n</pattern>
</encoder>
</appender>

<logger name="org.mvndaemon.mvnd.daemon" level="DEBUG" additivity="false">
<appender-ref ref="DAEMON" />
</logger>

<logger name="Sisu" level="INFO" />

<!-- suppress annoying @threadSafe and checksum failure warning messages -->
<logger name="org.apache.maven.lifecycle.internal.builder.BuilderCommon" level="ERROR" />
<logger name="org.eclipse.aether.internal.impl.WarnChecksumPolicy" level="ERROR" />

<root level="${consoleLevel:-info}">
<appender-ref ref="CONSOLE" />
</root>
</configuration>
19 changes: 8 additions & 11 deletions dist/src/main/distro/conf/logback.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!--
Copyright 2019 the original author or authors.
Copyright 2020 the original author or authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -25,21 +25,18 @@
<configuration>
<contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator" />

<appender name="DAEMON" class="ch.qos.logback.core.FileAppender">
<file>${mvnd.daemonStorage}/daemon-${mvnd.id}.log</file>
<encoder>
<pattern>%d{HH:mm:ss.SSS} %.-1level %msg%n</pattern>
</encoder>
</appender>

<logger name="org.mvndaemon.mvnd.daemon" level="DEBUG" additivity="false">
<appender-ref ref="DAEMON" />
</logger>
<!--
| write project-specific build log messages to ${project.build.directory}/build.log files
-->
<appender name="CONSOLE" class="org.mvndaemon.mvnd.logging.internal.SimpleAppender" />

<logger name="Sisu" level="INFO" />

<!-- suppress annoying @threadSafe and checksum failure warning messages -->
<logger name="org.apache.maven.lifecycle.internal.builder.BuilderCommon" level="ERROR" />
<logger name="org.eclipse.aether.internal.impl.WarnChecksumPolicy" level="ERROR" />

<root level="${consoleLevel:-info}">
<appender-ref ref="CONSOLE" />
</root>
</configuration>
64 changes: 11 additions & 53 deletions dist/src/main/provisio/maven-distro.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,71 +17,29 @@
-->
<assembly>

<artifactSet to="/mvn">
<artifactSet to="/">
<artifact id="org.apache.maven:apache-maven:tar.gz:bin">
<unpack useRoot="false"
excludes="conf/logging/*,lib/maven-slf4j-provider*,bin/mvn*,lib/jansi-*.jar,lib/jansi-native/*,lib/plexus-utils-3.*"/>
excludes="conf/logging/*,lib/maven-slf4j-provider*,lib/plexus-utils-3.*" />
</artifact>
</artifactSet>

<artifactSet to="/mvn/lib">
<exclusion id="javax.annotation:javax.annotation-api"/>
<exclusion id="org.codehaus.plexus:plexus-utils"/>
<artifact id="org.apache.maven.resolver:maven-resolver-api"/>
<artifact id="org.apache.maven.resolver:maven-resolver-impl"/>
<artifact id="org.apache.maven.resolver:maven-resolver-spi"/>
<artifact id="org.apache.maven.resolver:maven-resolver-util"/>
<artifact id="org.apache.maven.resolver:maven-resolver-connector-basic"/>
<artifact id="org.apache.maven.resolver:maven-resolver-transport-wagon"/>
</artifactSet>

<artifactSet to="/mvn/lib/ext">
<exclusion id="org.slf4j:slf4j-api"/>
<artifactSet to="/lib/mvnd">
<artifact id="org.apache.maven.daemon:mvnd-daemon:${project.version}">
<exclusion id="org.codehaus.plexus:plexus-classworlds"/>
<exclusion id="org.codehaus.plexus:plexus-utils"/>
<exclusion id="*:cdi-api"/>
<exclusion id="*:commons-cli"/>
<exclusion id="*:commons-io"/>
<exclusion id="*:commons-lang3"/>
<exclusion id="*:guava"/>
<exclusion id="*:guice"/>
<exclusion id="*:javax.inject"/>
<exclusion id="*:jcl-over-slf4j"/>
<exclusion id="*:jul-to-slf4j"/>
<exclusion id="*:jsr250-api"/>
<exclusion id="*:log4j-over-slf4j"/>
<exclusion id="*:maven-artifact"/>
<exclusion id="*:maven-builder-support"/>
<exclusion id="*:maven-core"/>
<exclusion id="*:maven-embedder"/>
<exclusion id="*:maven-model"/>
<exclusion id="*:maven-model-builder"/>
<exclusion id="*:maven-plugin-api"/>
<exclusion id="*:maven-repository-metadata"/>
<exclusion id="*:maven-resolver-api"/>
<exclusion id="*:maven-resolver-impl"/>
<exclusion id="*:maven-resolver-provider"/>
<exclusion id="*:maven-resolver-spi"/>
<exclusion id="*:maven-resolver-util"/>
<exclusion id="*:maven-settings"/>
<exclusion id="*:maven-settings-builder"/>
<exclusion id="*:maven-shared-utils"/>
<exclusion id="*:org.eclipse.sisu.inject"/>
<exclusion id="*:org.eclipse.sisu.plexus"/>
<exclusion id="*:plexus-cipher"/>
<exclusion id="*:plexus-component-annotations"/>
<exclusion id="*:plexus-interpolation"/>
<exclusion id="*:plexus-sec-dispatcher"/>
<exclusion id="*:plexus-utils"/>
<exclusion id="*:plexus-container-default"/>
<exclusion id="*:slf4j-api"/>
<exclusion id="*:*"/>
</artifact>
<artifact id="org.apache.maven.daemon:mvnd-client:${project.version}">
<exclusion id="*:*"/>
</artifact>
<artifact id="org.apache.maven.daemon:mvnd-common:${project.version}">
<exclusion id="*:*"/>
</artifact>
<artifact id="org.apache.maven.daemon:mvnd-agent:${project.version}"/>
<artifact id="org.apache.maven.daemon:mvnd-helper-agent:${project.version}"/>
<artifact id="org.apache.maven.daemon:mvnd-native:${project.version}"/>
<artifact id="ch.qos.logback:logback-classic">
<exclusion id="org.slf4j:slf4j-api"/>
</artifact>
</artifactSet>

<fileSet to="/">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,17 @@ public class DistroIT {
@Test
void noDuplicateJars() {
final Path mavenHome = Paths.get(System.getProperty("mvnd.home"));
Set<Avc> mavenLibs =
streamJars(mavenHome, "mvn/lib", "mvn/boot").collect(Collectors.toCollection(TreeSet::new));
Set<Avc> mavenLibs = streamJars(mavenHome, "lib", "boot").collect(Collectors.toCollection(TreeSet::new));
Assertions.assertFalse(mavenLibs.isEmpty());
final List<Avc> mvndJars = streamJars(mavenHome, "mvn/lib/ext").collect(Collectors.toList());
final List<Avc> mvndJars = streamJars(mavenHome, "lib/ext", "lib/mvnd").collect(Collectors.toList());
Assertions.assertFalse(mvndJars.isEmpty());

final List<Avc> dups = mvndJars.stream()
.filter(avc -> mavenLibs.stream().anyMatch(mvnAvc -> mvnAvc.sameArtifactId(avc)))
.collect(Collectors.toList());

final String msg = mavenHome.resolve("mvn/lib/ext") + " contains duplicates available in "
+ mavenHome.resolve("mvn/lib") + " or " + mavenHome.resolve("mvn/boot");
final String msg = mavenHome.resolve("lib/ext") + " contains duplicates available in "
+ mavenHome.resolve("lib") + " or " + mavenHome.resolve("boot");
Assertions.assertEquals(new ArrayList<Avc>(), dups, msg);
}

Expand Down

0 comments on commit fc683e0

Please sign in to comment.