Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #1188

Merged
merged 2 commits into from
Nov 8, 2024
Merged

Fixes #1188

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions daemon/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<properties>
<!-- If using release, sun.misc is not reachable (see SignalHelper) -->
<!-- <maven.compiler.release />-->
<maven.compiler.proc>full</maven.compiler.proc>
</properties>

<dependencies>
Expand Down Expand Up @@ -60,6 +61,10 @@
<groupId>org.apache.maven</groupId>
<artifactId>maven-cli</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-api-di</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-interactivity-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -44,6 +44,11 @@ public <T> T computeIfAbsent(Source path, String tag, Supplier<T> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> 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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, String> props =
MvndTestUtil.properties(parameters.multiModuleProjectDirectory().resolve("pom.xml"));

final List<String> messages = o.getMessages().stream()
Expand Down Expand Up @@ -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<String, String> props) {
/* implemented in the subclass */
}

String mojoStartedLogMessage(Properties props, String pluginArtifactId, String mojo, String executionId) {
String mojoStartedLogMessage(Map<String, String> 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";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String, String> props) {
final List<String> filteredMessages = o.getMessages().stream()
.filter(m -> m.getType() == Message.MOJO_STARTED)
.map(Object::toString)
Expand All @@ -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<String, String> 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()
Expand Down
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@
<artifactId>maven-cli</artifactId>
<version>${maven.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-api-di</artifactId>
<version>${maven.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-jline</artifactId>
Expand Down