Attempt at moving mvn as first class citizen in mvnd distribution, #392 (#769)

This commit is contained in:
Guillaume Nodet
2023-01-24 10:50:40 +01:00
committed by GitHub
parent b2bd0aaae5
commit 4f90d558b2
18 changed files with 88 additions and 103 deletions

View File

@@ -339,7 +339,7 @@ public class DaemonConnector {
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"))) {
List<String> args = new ArrayList<>();
// executable
final String java = Os.current().isUnixLike() ? "bin/java" : "bin\\java.exe";
@@ -358,10 +358,10 @@ public class DaemonConnector {
}
}
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/");
}
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/");
}
args.add("-classpath");
args.add(mvndCommonPath + File.pathSeparator + mvndAgentPath);
@@ -419,8 +419,8 @@ public class DaemonConnector {
}
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());

View File

@@ -120,10 +120,10 @@ public class DaemonParameters {
private String mvndHomeFromExecutable() {
Optional<String> cmd = ProcessHandle.current().info().command();
if (Environment.isNative() && cmd.isPresent()) {
final Path mvndH = Paths.get(cmd.get()).getParent().getParent();
final Path mvndH = Paths.get(cmd.get()).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-daemon-" + BuildProperties.getInstance().getVersion() + ".jar");
if (Files.exists(mvndDaemonLib)) {
return mvndH.toString();
}
@@ -238,7 +238,8 @@ public class DaemonParameters {
public Path logbackConfigurationPath() {
return property(Environment.MVND_LOGBACK)
.orDefault(() -> mvndHome().resolve("conf/logback.xml").toString())
.orDefault(() ->
mvndHome().resolve("conf/logging/logback-mvnd.xml").toString())
.orFail()
.asPath();
}

View File

@@ -31,7 +31,7 @@ public class MavenDaemon {
final Path mvndHome = Environment.MVND_HOME.asPath();
URL[] classpath = Stream.concat(
/* jars */
Stream.of("mvn/lib/ext", "mvn/lib", "mvn/boot")
Stream.of("lib/ext", "lib", "boot")
.map(mvndHome::resolve)
.flatMap((Path p) -> {
try {
@@ -46,7 +46,7 @@ public class MavenDaemon {
})
.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 -> {

View File

@@ -192,7 +192,7 @@ exec "$JAVACMD" \
$MAVEN_DEBUG_OPTS \
-classpath "${CLASSWORLDS_JAR}" \
"-Dlogback.configurationFile=${MAVEN_HOME}/conf/logging/logback.xml" \
"-Dclassworlds.conf=${MAVEN_HOME}/bin/m2.conf" \
"-Dclassworlds.conf=${MAVEN_HOME}/bin/mvn.conf" \
"-Dmaven.home=${MAVEN_HOME}" \
"-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
${CLASSWORLDS_LAUNCHER} "$@"

View File

@@ -173,7 +173,7 @@ set CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
%MAVEN_DEBUG_OPTS% ^
-classpath %CLASSWORLDS_JAR% ^
"-Dlogback.configurationFile=%MAVEN_HOME%\conf\logging\logback.xml" ^
"-Dclassworlds.conf=%MAVEN_HOME%\bin\m2.conf" ^
"-Dclassworlds.conf=%MAVEN_HOME%\bin\mvn.conf" ^
"-Dmaven.home=%MAVEN_HOME%" ^
"-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^
%CLASSWORLDS_LAUNCHER% %MAVEN_CMD_LINE_ARGS%

View File

@@ -161,7 +161,7 @@ for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do s
:endReadAdditionalConfig
for %%i in ("%MVND_HOME%"\mvn\boot\plexus-classworlds-*) do set CLASSWORLDS_JAR="%%i"
for %%i in ("%MVND_HOME%"\boot\plexus-classworlds-*) do set CLASSWORLDS_JAR="%%i"
set CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
"%JAVACMD%" ^
@@ -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%

View File

@@ -16,9 +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 default ${maven.conf}/logging/logback-client.xml
set logback.configurationFile.fallback default ${maven.conf}/logging/logback.xml
[plexus.core]

View File

@@ -101,7 +101,7 @@ if [ ! -x "$JAVACMD" ] ; then
exit 1
fi
CLASSWORLDS_JAR=`echo "${MVND_HOME}"/mvn/boot/plexus-classworlds-*.jar`
CLASSWORLDS_JAR=`echo "${MVND_HOME}"/boot/plexus-classworlds-*.jar`
CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
# For Cygwin, switch paths to Windows format before running java
@@ -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} "$@"

View File

@@ -17,71 +17,53 @@
-->
<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 to="/lib">
<artifact id="ch.qos.logback:logback-classic">
<exclusion id="*:*"/>
</artifact>
<artifact id="ch.qos.logback:logback-core">
<exclusion id="*:*"/>
</artifact>
</artifactSet>
<artifactSet to="/mvn/lib/ext">
<exclusion id="org.slf4j:slf4j-api"/>
<artifactSet to="/lib">
<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-agent:${project.version}"/>
<artifact id="org.apache.maven.daemon:mvnd-helper-agent:${project.version}"/>
<artifact id="org.apache.maven.daemon:mvnd-common:${project.version}">
<exclusion id="*:*"/>
</artifact>
<artifact id="org.apache.maven.daemon:mvnd-agent:${project.version}">
<exclusion id="*:*"/>
</artifact>
<artifact id="org.apache.maven.daemon:mvnd-helper-agent:${project.version}">
<exclusion id="*:*"/>
</artifact>
<artifact id="org.apache.maven.daemon:mvnd-native:${project.version}">
<exclusion id="*:*"/>
</artifact>
<artifact id="ch.qos.logback:logback-classic">
<exclusion id="*:*"/>
</artifact>
<artifact id="org.codehaus.plexus:plexus-interactivity-api">
<exclusion id="*:*"/>
</artifact>
<artifact id="org.jline:jline-terminal">
<exclusion id="*:*"/>
</artifact>
<artifact id="org.jline:jline-terminal-jansi">
<exclusion id="*:*"/>
</artifact>
</artifactSet>
<fileSet to="/">

View File

@@ -21,10 +21,8 @@ package org.mvndaemon.mvnd.it;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@@ -33,6 +31,8 @@ import java.util.stream.Stream;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertNotNull;
public class DistroIT {
/**
@@ -40,20 +40,16 @@ 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));
Assertions.assertFalse(mavenLibs.isEmpty());
final List<Avc> mvndJars = streamJars(mavenHome, "mvn/lib/ext").collect(Collectors.toList());
Assertions.assertFalse(mvndJars.isEmpty());
final List<Avc> dups = mvndJars.stream()
.filter(avc -> mavenLibs.stream().anyMatch(mvnAvc -> mvnAvc.sameArtifactId(avc)))
String property = System.getProperty("mvnd.home");
assertNotNull(property, "mvnd.home must be defined");
final Path mavenHome = Paths.get(property);
List<Avc> avcs = listJars(mavenHome);
Map<String, List<Avc>> avcsByArtifactId = avcs.stream().collect(Collectors.groupingBy(Avc::getArtifactId));
List<List<Avc>> duplicateJars = avcsByArtifactId.values().stream()
.filter(list -> list.size() > 1)
.collect(Collectors.toList());
final String msg = mavenHome.resolve("mvn/lib/ext") + " contains duplicates available in "
+ mavenHome.resolve("mvn/lib") + " or " + mavenHome.resolve("mvn/boot");
Assertions.assertEquals(new ArrayList<Avc>(), dups, msg);
Assertions.assertTrue(duplicateJars.isEmpty(), mavenHome + " contains duplicates jars" + duplicateJars);
}
@Test
@@ -69,21 +65,17 @@ public class DistroIT {
Assertions.assertEquals(classifier, avc.classifier, "classifier in " + jarName);
}
private static Stream<Avc> streamJars(Path mavenHome, String... dirs) {
return Stream.of(dirs)
.map(mavenHome::resolve)
.flatMap((Path p) -> {
try {
return Files.list(p);
} catch (java.io.IOException e) {
throw new RuntimeException("Could not list " + p, e);
}
})
.filter(p -> p.getFileName().toString().endsWith(".jar"))
.filter(Files::isRegularFile)
.map(Path::getFileName)
.map(Path::toString)
.map(Avc::of);
private static List<Avc> listJars(Path mavenHome) {
try (Stream<Path> stream = Files.walk(mavenHome)) {
return stream.filter(p -> p.getFileName().toString().endsWith(".jar"))
.filter(Files::isRegularFile)
.map(Path::getFileName)
.map(Path::toString)
.map(Avc::of)
.collect(Collectors.toList());
} catch (java.io.IOException e) {
throw new RuntimeException("Could not list " + mavenHome, e);
}
}
static class Avc implements Comparable<Avc> {
@@ -113,6 +105,10 @@ public class DistroIT {
this.jarName = jarName;
}
public String getArtifactId() {
return artifactId;
}
@Override
public String toString() {
return jarName;

View File

@@ -52,7 +52,7 @@ public class MavenConfNativeIT {
"-DforceStdout",
"--raw-streams")
.assertSuccess();
String conf = parameters.mvndHome().resolve("mvn/conf").toString();
String conf = parameters.mvndHome().resolve("conf").toString();
assertTrue(
o.getMessages().stream().anyMatch(m -> m.toString().contains(conf)), "Output should contain " + conf);
}

View File

@@ -120,6 +120,11 @@
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>${logback.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>