args,
String workingDir,
diff --git a/daemon/src/main/java/org/apache/maven/cli/DaemonMavenCling.java b/daemon/src/main/java/org/apache/maven/cli/DaemonMavenCling.java
index aded3ca44..d2debc275 100644
--- a/daemon/src/main/java/org/apache/maven/cli/DaemonMavenCling.java
+++ b/daemon/src/main/java/org/apache/maven/cli/DaemonMavenCling.java
@@ -33,7 +33,30 @@
import org.codehaus.plexus.classworlds.realm.ClassRealm;
import org.mvndaemon.mvnd.cli.EnvHelper;
+/**
+ * The main Daemon entry point: it shares lifecycle with daemon invoker (subclass of resident invoker) that keeps Maven
+ * resident, as long as this class is used. Once not needed, proper shut down using {@link #close()} method
+ * is required.
+ *
+ * While daemon invoker is stateful (keeps Maven object graph), daemon parser is stateless and reusable, no need to
+ * create instance per incoming call.
+ */
public class DaemonMavenCling implements DaemonCli {
+ private final DaemonMavenParser parser;
+ private final DaemonMavenInvoker invoker;
+
+ public DaemonMavenCling() {
+ this.parser = new DaemonMavenParser();
+ this.invoker = new DaemonMavenInvoker(ProtoLookup.builder()
+ .addMapping(
+ ClassWorld.class, ((ClassRealm) Thread.currentThread().getContextClassLoader()).getWorld())
+ .build());
+ }
+
+ @Override
+ public void close() {
+ invoker.close();
+ }
@Override
public int main(
@@ -49,24 +72,17 @@ public int main(
EnvHelper.environment(workingDir, env);
System.setProperty("maven.multiModuleProjectDirectory", projectDir);
- try (DaemonMavenInvoker invoker = new DaemonMavenInvoker(ProtoLookup.builder()
- .addMapping(
- ClassWorld.class, ((ClassRealm) Thread.currentThread().getContextClassLoader()).getWorld())
- .addMapping(BuildEventListener.class, buildEventListener)
- .build())) {
- DaemonMavenParser parser = new DaemonMavenParser();
- return invoker.invoke(parser.parse(ParserRequest.builder(
- "mvnd", "Maven Daemon", args, new ProtoLogger(), new DaemonMessageBuilderFactory())
- .cwd(Paths.get(workingDir))
- .in(in)
- .out(out)
- .err(err)
- .lookup(ProtoLookup.builder()
- .addMapping(Environment.class, () -> env)
- .addMapping(BuildEventListener.class, buildEventListener)
- .build())
- .build()));
- }
+ return invoker.invoke(parser.parse(ParserRequest.builder(
+ "mvnd", "Maven Daemon", args, new ProtoLogger(), new DaemonMessageBuilderFactory())
+ .cwd(Paths.get(workingDir))
+ .in(in)
+ .out(out)
+ .err(err)
+ .lookup(ProtoLookup.builder()
+ .addMapping(Environment.class, () -> env)
+ .addMapping(BuildEventListener.class, buildEventListener)
+ .build())
+ .build()));
}
/**
diff --git a/daemon/src/main/java/org/apache/maven/cli/DaemonMavenInvoker.java b/daemon/src/main/java/org/apache/maven/cli/DaemonMavenInvoker.java
index a13f463d2..d2a19c188 100644
--- a/daemon/src/main/java/org/apache/maven/cli/DaemonMavenInvoker.java
+++ b/daemon/src/main/java/org/apache/maven/cli/DaemonMavenInvoker.java
@@ -44,9 +44,19 @@ public DaemonMavenInvoker(ProtoLookup protoLookup) {
super(protoLookup);
}
- @Override
- protected void configureLogging(LocalContext context) throws Exception {
- super.configureLogging(context);
+ // TODO: this is a hack, and fixes issue in DefaultResidentMavenInvoker that does not copy TCCL
+ private ClassLoader tccl;
+
+ protected int doInvoke(LocalContext context) throws Exception {
+ try {
+ if (tccl != null) {
+ context.currentThreadContextClassLoader = tccl;
+ Thread.currentThread().setContextClassLoader(context.currentThreadContextClassLoader);
+ }
+ return super.doInvoke(context);
+ } finally {
+ this.tccl = context.currentThreadContextClassLoader;
+ }
}
@Override
@@ -85,7 +95,7 @@ private PrintStream printStream(OutputStream outputStream) {
@Override
protected org.apache.maven.logging.BuildEventListener doDetermineBuildEventListener(LocalContext context) {
- return protoLookup.lookup(BuildEventListener.class);
+ return context.invokerRequest.lookup().lookup(BuildEventListener.class);
}
@Override
diff --git a/daemon/src/main/java/org/mvndaemon/mvnd/daemon/Server.java b/daemon/src/main/java/org/mvndaemon/mvnd/daemon/Server.java
index 290ca27af..b8e00634e 100644
--- a/daemon/src/main/java/org/mvndaemon/mvnd/daemon/Server.java
+++ b/daemon/src/main/java/org/mvndaemon/mvnd/daemon/Server.java
@@ -187,7 +187,11 @@ public void close() {
try {
registry.close();
} finally {
- socket.close();
+ try {
+ socket.close();
+ } finally {
+ cli.close();
+ }
}
}
}
From a08cd297292e9bf89a7193d225e7cf9d359a51cc Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Fri, 8 Nov 2024 16:49:53 +0100
Subject: [PATCH 4/9] Bump org.apache.maven.plugins:maven-site-plugin from
3.20.0 to 3.21.0 (#1180)
Bumps [org.apache.maven.plugins:maven-site-plugin](https://github.com/apache/maven-site-plugin) from 3.20.0 to 3.21.0.
- [Release notes](https://github.com/apache/maven-site-plugin/releases)
- [Commits](https://github.com/apache/maven-site-plugin/compare/maven-site-plugin-3.20.0...maven-site-plugin-3.21.0)
---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-site-plugin
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot]
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index fcb9a11f7..62cdb9fa0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -500,7 +500,7 @@
org.apache.maven.plugins
maven-site-plugin
- 3.20.0
+ 3.21.0
org.apache.maven.plugins
From 32cf0ef04a2cfa706b703bd2b5d02ec1667441bb Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Fri, 8 Nov 2024 16:50:09 +0100
Subject: [PATCH 5/9] Bump testcontainers.version from 1.20.2 to 1.20.3 (#1182)
Bumps `testcontainers.version` from 1.20.2 to 1.20.3.
Updates `org.testcontainers:testcontainers` from 1.20.2 to 1.20.3
- [Release notes](https://github.com/testcontainers/testcontainers-java/releases)
- [Changelog](https://github.com/testcontainers/testcontainers-java/blob/main/CHANGELOG.md)
- [Commits](https://github.com/testcontainers/testcontainers-java/compare/1.20.2...1.20.3)
Updates `org.testcontainers:junit-jupiter` from 1.20.2 to 1.20.3
- [Release notes](https://github.com/testcontainers/testcontainers-java/releases)
- [Changelog](https://github.com/testcontainers/testcontainers-java/blob/main/CHANGELOG.md)
- [Commits](https://github.com/testcontainers/testcontainers-java/compare/1.20.2...1.20.3)
---
updated-dependencies:
- dependency-name: org.testcontainers:testcontainers
dependency-type: direct:development
update-type: version-update:semver-patch
- dependency-name: org.testcontainers:junit-jupiter
dependency-type: direct:development
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot]
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 62cdb9fa0..fc1d106fe 100644
--- a/pom.xml
+++ b/pom.xml
@@ -106,7 +106,7 @@
1.3
2.29.0.Final
1.0.2
- 1.20.2
+ 1.20.3
1.4.20
From e03959b12c898dd54e809adf708a7d780b7e3707 Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Fri, 8 Nov 2024 16:50:26 +0100
Subject: [PATCH 6/9] Bump maven.plugin-tools.version from 3.15.0 to 3.15.1
(#1184)
Bumps `maven.plugin-tools.version` from 3.15.0 to 3.15.1.
Updates `org.apache.maven.plugin-tools:maven-plugin-annotations` from 3.15.0 to 3.15.1
- [Release notes](https://github.com/apache/maven-plugin-tools/releases)
- [Commits](https://github.com/apache/maven-plugin-tools/compare/maven-plugin-tools-3.15.0...maven-plugin-tools-3.15.1)
Updates `org.apache.maven.plugins:maven-plugin-plugin` from 3.15.0 to 3.15.1
- [Release notes](https://github.com/apache/maven-plugin-tools/releases)
- [Commits](https://github.com/apache/maven-plugin-tools/compare/maven-plugin-tools-3.15.0...maven-plugin-tools-3.15.1)
---
updated-dependencies:
- dependency-name: org.apache.maven.plugin-tools:maven-plugin-annotations
dependency-type: direct:production
update-type: version-update:semver-patch
- dependency-name: org.apache.maven.plugins:maven-plugin-plugin
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot]
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index fc1d106fe..da542bff8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -90,7 +90,7 @@
2.0.2
2.0.16
0.9.0.M3
- 3.15.0
+ 3.15.1
4.0.2
4.0.4
2.0.1
From 31c765e0d43e72d4ccc3a17608b02619d7aabced Mon Sep 17 00:00:00 2001
From: Guillaume Nodet
Date: Thu, 7 Nov 2024 18:47:11 +0100
Subject: [PATCH 7/9] Use Maven 4 model
---
.../org/mvndaemon/mvnd/it/MvndTestUtil.java | 17 +++++++++--------
.../mvndaemon/mvnd/it/SingleModuleNativeIT.java | 10 +++++-----
.../org/mvndaemon/mvnd/it/SingleModuleTest.java | 8 ++++----
3 files changed, 18 insertions(+), 17 deletions(-)
diff --git a/integration-tests/src/test/java/org/mvndaemon/mvnd/it/MvndTestUtil.java b/integration-tests/src/test/java/org/mvndaemon/mvnd/it/MvndTestUtil.java
index 05e9f5376..6e523d5fb 100644
--- a/integration-tests/src/test/java/org/mvndaemon/mvnd/it/MvndTestUtil.java
+++ b/integration-tests/src/test/java/org/mvndaemon/mvnd/it/MvndTestUtil.java
@@ -18,34 +18,35 @@
*/
package org.mvndaemon.mvnd.it;
+import javax.xml.stream.XMLStreamException;
+
import java.io.IOException;
import java.io.Reader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
-import java.util.Properties;
+import java.util.Map;
-import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
-import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+import org.apache.maven.model.v4.MavenStaxReader;
public class MvndTestUtil {
private MvndTestUtil() {}
- public static Properties properties(Path pomXmlPath) {
+ public static Map properties(Path pomXmlPath) {
try (Reader runtimeReader = Files.newBufferedReader(pomXmlPath, StandardCharsets.UTF_8)) {
- final MavenXpp3Reader rxppReader = new MavenXpp3Reader();
+ final MavenStaxReader rxppReader = new MavenStaxReader();
return rxppReader.read(runtimeReader).getProperties();
- } catch (IOException | XmlPullParserException e) {
+ } catch (IOException | XMLStreamException e) {
throw new RuntimeException("Could not read or parse " + pomXmlPath);
}
}
public static String version(Path pomXmlPath) {
try (Reader runtimeReader = Files.newBufferedReader(pomXmlPath, StandardCharsets.UTF_8)) {
- final MavenXpp3Reader rxppReader = new MavenXpp3Reader();
+ final MavenStaxReader rxppReader = new MavenStaxReader();
return rxppReader.read(runtimeReader).getVersion();
- } catch (IOException | XmlPullParserException e) {
+ } catch (IOException | XMLStreamException e) {
throw new RuntimeException("Could not read or parse " + pomXmlPath);
}
}
diff --git a/integration-tests/src/test/java/org/mvndaemon/mvnd/it/SingleModuleNativeIT.java b/integration-tests/src/test/java/org/mvndaemon/mvnd/it/SingleModuleNativeIT.java
index fa98b88cf..c4ddfab41 100644
--- a/integration-tests/src/test/java/org/mvndaemon/mvnd/it/SingleModuleNativeIT.java
+++ b/integration-tests/src/test/java/org/mvndaemon/mvnd/it/SingleModuleNativeIT.java
@@ -24,7 +24,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
-import java.util.Properties;
+import java.util.Map;
import java.util.stream.Collectors;
import org.assertj.core.api.Assertions;
@@ -59,7 +59,7 @@ void cleanInstall() throws IOException, InterruptedException {
final TestClientOutput o = new TestClientOutput();
client.execute(o, "clean", "install", "-e", "-B").assertSuccess();
- final Properties props =
+ final Map props =
MvndTestUtil.properties(parameters.multiModuleProjectDirectory().resolve("pom.xml"));
final List messages = o.getMessages().stream()
@@ -87,14 +87,14 @@ void cleanInstall() throws IOException, InterruptedException {
Assertions.assertThat(installedJar).exists();
}
- protected void assertJVM(TestClientOutput o, Properties props) {
+ protected void assertJVM(TestClientOutput o, Map props) {
/* implemented in the subclass */
}
- String mojoStartedLogMessage(Properties props, String pluginArtifactId, String mojo, String executionId) {
+ String mojoStartedLogMessage(Map props, String pluginArtifactId, String mojo, String executionId) {
return "\\Q--- "
+ pluginArtifactId.replace("maven-", "").replace("-plugin", "")
- + ":" + props.getProperty(pluginArtifactId + ".version") + ":" + mojo + " ("
+ + ":" + props.get(pluginArtifactId + ".version") + ":" + mojo + " ("
+ executionId + ") @ single-module ---\\E";
}
}
diff --git a/integration-tests/src/test/java/org/mvndaemon/mvnd/it/SingleModuleTest.java b/integration-tests/src/test/java/org/mvndaemon/mvnd/it/SingleModuleTest.java
index d2b66cacf..a678353c1 100644
--- a/integration-tests/src/test/java/org/mvndaemon/mvnd/it/SingleModuleTest.java
+++ b/integration-tests/src/test/java/org/mvndaemon/mvnd/it/SingleModuleTest.java
@@ -19,7 +19,7 @@
package org.mvndaemon.mvnd.it;
import java.util.List;
-import java.util.Properties;
+import java.util.Map;
import java.util.stream.Collectors;
import org.assertj.core.api.Assertions;
@@ -31,7 +31,7 @@
@MvndTest(projectDir = "src/test/projects/single-module")
class SingleModuleTest extends SingleModuleNativeIT {
- protected void assertJVM(TestClientOutput o, Properties props) {
+ protected void assertJVM(TestClientOutput o, Map props) {
final List filteredMessages = o.getMessages().stream()
.filter(m -> m.getType() == Message.MOJO_STARTED)
.map(Object::toString)
@@ -48,14 +48,14 @@ protected void assertJVM(TestClientOutput o, Properties props) {
mojoStarted(props, "maven-install-plugin", "install", "default-install")));
}
- String mojoStarted(Properties props, String pluginArtifactId, String mojo, String executionId) {
+ String mojoStarted(Map props, String pluginArtifactId, String mojo, String executionId) {
return "\\Q"
+ Message.mojoStarted(
"single-module",
"org.apache.maven.plugins",
pluginArtifactId,
pluginArtifactId.replace("maven-", "").replace("-plugin", ""),
- props.getProperty(pluginArtifactId + ".version"),
+ props.get(pluginArtifactId + ".version"),
mojo,
executionId)
.toString()
From f191c652f531073951ebc39d6f400ebc4ff381a8 Mon Sep 17 00:00:00 2001
From: Guillaume Nodet
Date: Thu, 7 Nov 2024 19:10:14 +0100
Subject: [PATCH 8/9] Restore ModelCacheFactory
---
daemon/pom.xml | 5 ++++
.../maven/project/SnapshotModelCache.java | 9 ++++++--
.../project/SnapshotModelCacheFactory.java | 23 ++++++++-----------
pom.xml | 5 ++++
4 files changed, 27 insertions(+), 15 deletions(-)
diff --git a/daemon/pom.xml b/daemon/pom.xml
index 7c07b30dc..959e14705 100644
--- a/daemon/pom.xml
+++ b/daemon/pom.xml
@@ -33,6 +33,7 @@
+ full
@@ -60,6 +61,10 @@
org.apache.maven
maven-cli
+
+ org.apache.maven
+ maven-api-di
+
org.codehaus.plexus
plexus-interactivity-api
diff --git a/daemon/src/main/java/org/apache/maven/project/SnapshotModelCache.java b/daemon/src/main/java/org/apache/maven/project/SnapshotModelCache.java
index e27bf76e8..0ab483af4 100644
--- a/daemon/src/main/java/org/apache/maven/project/SnapshotModelCache.java
+++ b/daemon/src/main/java/org/apache/maven/project/SnapshotModelCache.java
@@ -21,8 +21,8 @@
import java.util.Objects;
import java.util.function.Supplier;
-import org.apache.maven.building.Source;
-import org.apache.maven.model.building.ModelCache;
+import org.apache.maven.api.services.Source;
+import org.apache.maven.api.services.model.ModelCache;
public class SnapshotModelCache implements ModelCache {
@@ -44,6 +44,11 @@ public T computeIfAbsent(Source path, String tag, Supplier data) {
return reactorCache.computeIfAbsent(path, tag, data);
}
+ @Override
+ public void clear() {
+ reactorCache.clear();
+ }
+
private ModelCache getDelegate(String version) {
return version.contains("SNAPSHOT") || version.contains("${") ? reactorCache : globalCache;
}
diff --git a/daemon/src/main/java/org/apache/maven/project/SnapshotModelCacheFactory.java b/daemon/src/main/java/org/apache/maven/project/SnapshotModelCacheFactory.java
index fe285af69..d276439f7 100644
--- a/daemon/src/main/java/org/apache/maven/project/SnapshotModelCacheFactory.java
+++ b/daemon/src/main/java/org/apache/maven/project/SnapshotModelCacheFactory.java
@@ -18,16 +18,13 @@
*/
package org.apache.maven.project;
-import javax.inject.Inject;
-import javax.inject.Named;
-import javax.inject.Singleton;
-
-import org.apache.maven.model.building.ModelCache;
-import org.apache.maven.repository.internal.DefaultModelCacheFactory;
-import org.apache.maven.repository.internal.ModelCacheFactory;
-import org.eclipse.aether.DefaultRepositorySystemSession;
-import org.eclipse.aether.RepositorySystemSession;
-import org.eclipse.sisu.Priority;
+import org.apache.maven.api.di.Inject;
+import org.apache.maven.api.di.Named;
+import org.apache.maven.api.di.Priority;
+import org.apache.maven.api.di.Singleton;
+import org.apache.maven.api.services.model.ModelCache;
+import org.apache.maven.api.services.model.ModelCacheFactory;
+import org.apache.maven.internal.impl.model.DefaultModelCacheFactory;
import static org.mvndaemon.mvnd.common.Environment.MVND_NO_MODEL_CACHE;
@@ -42,14 +39,14 @@ public class SnapshotModelCacheFactory implements ModelCacheFactory {
@Inject
public SnapshotModelCacheFactory(DefaultModelCacheFactory factory) {
this.factory = factory;
- this.globalCache = factory.createCache(new DefaultRepositorySystemSession());
+ this.globalCache = factory.newInstance();
}
@Override
- public ModelCache createCache(RepositorySystemSession session) {
+ public ModelCache newInstance() {
boolean noModelCache =
Boolean.parseBoolean(MVND_NO_MODEL_CACHE.asOptional().orElse(MVND_NO_MODEL_CACHE.getDefault()));
- ModelCache reactorCache = factory.createCache(session);
+ ModelCache reactorCache = factory.newInstance();
ModelCache globalCache = noModelCache ? reactorCache : this.globalCache;
return new SnapshotModelCache(globalCache, reactorCache);
}
diff --git a/pom.xml b/pom.xml
index da542bff8..f95870a13 100644
--- a/pom.xml
+++ b/pom.xml
@@ -178,6 +178,11 @@
maven-cli
${maven.version}
+
+ org.apache.maven
+ maven-api-di
+ ${maven.version}
+
org.apache.maven
maven-jline
From c0591868523d53a730c04553f587dba4582330cc Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Fri, 8 Nov 2024 15:51:09 +0000
Subject: [PATCH 9/9] Bump com.thoughtworks.xstream:xstream from 1.4.20 to
1.4.21
Bumps [com.thoughtworks.xstream:xstream](https://github.com/x-stream/xstream) from 1.4.20 to 1.4.21.
- [Release notes](https://github.com/x-stream/xstream/releases)
- [Commits](https://github.com/x-stream/xstream/commits)
---
updated-dependencies:
- dependency-name: com.thoughtworks.xstream:xstream
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot]
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index f95870a13..8be2d3d74 100644
--- a/pom.xml
+++ b/pom.xml
@@ -107,7 +107,7 @@
2.29.0.Final
1.0.2
1.20.3
- 1.4.20
+ 1.4.21