From fc683e0096385d1a9a6cd0065162a2748da904bc Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Mon, 9 Jan 2023 15:55:40 +0100 Subject: [PATCH] Attempt at moving mvn as first class citizen in mvnd distribution, #392 We may need to revisit the logging configuration to be closer to maven if needed. --- .../mvnd/client/DaemonConnector.java | 10 +-- .../mvnd/client/DaemonParameters.java | 6 +- .../mvndaemon/mvnd/common/MavenDaemon.java | 4 +- dist/src/main/distro/{mvn => }/bin/mvn | 4 +- dist/src/main/distro/{mvn => }/bin/mvn.cmd | 4 +- .../distro/{mvn/bin/m2.conf => bin/mvn.conf} | 0 dist/src/main/distro/{mvn => }/bin/mvnDebug | 0 .../main/distro/{mvn => }/bin/mvnDebug.cmd | 0 dist/src/main/distro/bin/mvnd.cmd | 2 +- .../main/distro/bin/{m2.conf => mvnd.conf} | 6 +- dist/src/main/distro/bin/mvnd.sh | 2 +- .../logback.xml => conf/logback-mvnd.xml} | 19 +++--- dist/src/main/distro/conf/logback.xml | 19 +++--- dist/src/main/provisio/maven-distro.xml | 64 ++++--------------- .../java/org/mvndaemon/mvnd/it/DistroIT.java | 9 ++- 15 files changed, 53 insertions(+), 96 deletions(-) rename dist/src/main/distro/{mvn => }/bin/mvn (97%) rename dist/src/main/distro/{mvn => }/bin/mvn.cmd (94%) rename dist/src/main/distro/{mvn/bin/m2.conf => bin/mvn.conf} (100%) rename dist/src/main/distro/{mvn => }/bin/mvnDebug (100%) rename dist/src/main/distro/{mvn => }/bin/mvnDebug.cmd (100%) rename dist/src/main/distro/bin/{m2.conf => mvnd.conf} (86%) rename dist/src/main/distro/{mvn/conf/logging/logback.xml => conf/logback-mvnd.xml} (75%) diff --git a/client/src/main/java/org/mvndaemon/mvnd/client/DaemonConnector.java b/client/src/main/java/org/mvndaemon/mvnd/client/DaemonConnector.java index cd5f416d2..c00e48d87 100644 --- a/client/src/main/java/org/mvndaemon/mvnd/client/DaemonConnector.java +++ b/client/src/main/java/org/mvndaemon/mvnd/client/DaemonConnector.java @@ -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 jarPaths = Files.newDirectoryStream(mvndHome.resolve("mvn/lib/ext"))) { + try (DirectoryStream jarPaths = Files.newDirectoryStream(mvndHome.resolve("lib/mvnd"))) { List args = new ArrayList<>(); // executable final String java = Os.current().isUnixLike() ? "bin/java" : "bin\\java.exe"; @@ -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); @@ -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()); diff --git a/client/src/main/java/org/mvndaemon/mvnd/client/DaemonParameters.java b/client/src/main/java/org/mvndaemon/mvnd/client/DaemonParameters.java index e6c6a4ecf..e0afa36ce 100644 --- a/client/src/main/java/org/mvndaemon/mvnd/client/DaemonParameters.java +++ b/client/src/main/java/org/mvndaemon/mvnd/client/DaemonParameters.java @@ -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(); } @@ -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(); } diff --git a/common/src/main/java/org/mvndaemon/mvnd/common/MavenDaemon.java b/common/src/main/java/org/mvndaemon/mvnd/common/MavenDaemon.java index cf4bb1336..20c84bad0 100644 --- a/common/src/main/java/org/mvndaemon/mvnd/common/MavenDaemon.java +++ b/common/src/main/java/org/mvndaemon/mvnd/common/MavenDaemon.java @@ -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 { @@ -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 -> { diff --git a/dist/src/main/distro/mvn/bin/mvn b/dist/src/main/distro/bin/mvn similarity index 97% rename from dist/src/main/distro/mvn/bin/mvn rename to dist/src/main/distro/bin/mvn index 97363a1e4..30ccb3a64 100755 --- a/dist/src/main/distro/mvn/bin/mvn +++ b/dist/src/main/distro/bin/mvn @@ -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} "$@" diff --git a/dist/src/main/distro/mvn/bin/mvn.cmd b/dist/src/main/distro/bin/mvn.cmd similarity index 94% rename from dist/src/main/distro/mvn/bin/mvn.cmd rename to dist/src/main/distro/bin/mvn.cmd index 17cb1cb76..177b3209f 100644 --- a/dist/src/main/distro/mvn/bin/mvn.cmd +++ b/dist/src/main/distro/bin/mvn.cmd @@ -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% diff --git a/dist/src/main/distro/mvn/bin/m2.conf b/dist/src/main/distro/bin/mvn.conf similarity index 100% rename from dist/src/main/distro/mvn/bin/m2.conf rename to dist/src/main/distro/bin/mvn.conf diff --git a/dist/src/main/distro/mvn/bin/mvnDebug b/dist/src/main/distro/bin/mvnDebug similarity index 100% rename from dist/src/main/distro/mvn/bin/mvnDebug rename to dist/src/main/distro/bin/mvnDebug diff --git a/dist/src/main/distro/mvn/bin/mvnDebug.cmd b/dist/src/main/distro/bin/mvnDebug.cmd similarity index 100% rename from dist/src/main/distro/mvn/bin/mvnDebug.cmd rename to dist/src/main/distro/bin/mvnDebug.cmd diff --git a/dist/src/main/distro/bin/mvnd.cmd b/dist/src/main/distro/bin/mvnd.cmd index 62d29d490..3e1a0d674 100644 --- a/dist/src/main/distro/bin/mvnd.cmd +++ b/dist/src/main/distro/bin/mvnd.cmd @@ -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% diff --git a/dist/src/main/distro/bin/m2.conf b/dist/src/main/distro/bin/mvnd.conf similarity index 86% rename from dist/src/main/distro/bin/m2.conf rename to dist/src/main/distro/bin/mvnd.conf index 1f7aa818b..0ae0bb2ee 100644 --- a/dist/src/main/distro/bin/m2.conf +++ b/dist/src/main/distro/bin/mvnd.conf @@ -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 diff --git a/dist/src/main/distro/bin/mvnd.sh b/dist/src/main/distro/bin/mvnd.sh index df821112e..b52b7843e 100755 --- a/dist/src/main/distro/bin/mvnd.sh +++ b/dist/src/main/distro/bin/mvnd.sh @@ -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} "$@" diff --git a/dist/src/main/distro/mvn/conf/logging/logback.xml b/dist/src/main/distro/conf/logback-mvnd.xml similarity index 75% rename from dist/src/main/distro/mvn/conf/logging/logback.xml rename to dist/src/main/distro/conf/logback-mvnd.xml index 1628306d0..3fa5f26da 100644 --- a/dist/src/main/distro/mvn/conf/logging/logback.xml +++ b/dist/src/main/distro/conf/logback-mvnd.xml @@ -1,6 +1,6 @@ - + + ${mvnd.daemonStorage}/daemon-${mvnd.id}.log + + %d{HH:mm:ss.SSS} %.-1level %msg%n + + + + + + @@ -36,7 +42,4 @@ - - - diff --git a/dist/src/main/distro/conf/logback.xml b/dist/src/main/distro/conf/logback.xml index 3fa5f26da..1628306d0 100644 --- a/dist/src/main/distro/conf/logback.xml +++ b/dist/src/main/distro/conf/logback.xml @@ -1,6 +1,6 @@ + @@ -42,4 +36,7 @@ + + + diff --git a/dist/src/main/provisio/maven-distro.xml b/dist/src/main/provisio/maven-distro.xml index 145e2f883..da1918471 100644 --- a/dist/src/main/provisio/maven-distro.xml +++ b/dist/src/main/provisio/maven-distro.xml @@ -17,71 +17,29 @@ --> - + + excludes="conf/logging/*,lib/maven-slf4j-provider*,lib/plexus-utils-3.*" /> - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + diff --git a/integration-tests/src/test/java/org/mvndaemon/mvnd/it/DistroIT.java b/integration-tests/src/test/java/org/mvndaemon/mvnd/it/DistroIT.java index 1044673d8..79995ad12 100644 --- a/integration-tests/src/test/java/org/mvndaemon/mvnd/it/DistroIT.java +++ b/integration-tests/src/test/java/org/mvndaemon/mvnd/it/DistroIT.java @@ -41,18 +41,17 @@ public class DistroIT { @Test void noDuplicateJars() { final Path mavenHome = Paths.get(System.getProperty("mvnd.home")); - Set mavenLibs = - streamJars(mavenHome, "mvn/lib", "mvn/boot").collect(Collectors.toCollection(TreeSet::new)); + Set mavenLibs = streamJars(mavenHome, "lib", "boot").collect(Collectors.toCollection(TreeSet::new)); Assertions.assertFalse(mavenLibs.isEmpty()); - final List mvndJars = streamJars(mavenHome, "mvn/lib/ext").collect(Collectors.toList()); + final List mvndJars = streamJars(mavenHome, "lib/ext", "lib/mvnd").collect(Collectors.toList()); Assertions.assertFalse(mvndJars.isEmpty()); final List 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(), dups, msg); }