You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sl...@apache.org on 2018/11/29 19:23:22 UTC
[maven] 02/02: [MNG-6530] System property to disable global model
cache
This is an automated email from the ASF dual-hosted git repository.
slachiewicz pushed a commit to branch MNG-6311-regression
in repository https://gitbox.apache.org/repos/asf/maven.git
commit 417531622a731fd60617101cf7c34e2b9d979fb2
Author: Mickael Istria <mi...@redhat.com>
AuthorDate: Thu Nov 29 10:26:31 2018 +0100
[MNG-6530] System property to disable global model cache
The global model cache introduced in MNG-6311 causes severe regressions
in case of pom files changing during application lifetime.
This patch adds a system property
`defaultProjectBuilder.disableGlobalModelCache` that disables this
global model cache when set to true, ensure pom modifications are
honored.
---
.../maven/project/DefaultProjectBuilder.java | 23 ++++++++----
.../apache/maven/project/ProjectBuilderTest.java | 42 ++++++++++++----------
2 files changed, 41 insertions(+), 24 deletions(-)
diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java
index a659046..96429ef 100644
--- a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java
+++ b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java
@@ -81,6 +81,9 @@ public class DefaultProjectBuilder
implements ProjectBuilder
{
+ public static final String DISABLE_GLOBAL_MODEL_CACHE_SYSTEM_PROPERTY =
+ "defaultProjectBuilder.disableGlobalModelCache";
+
@Requirement
private Logger logger;
@@ -115,14 +118,21 @@ public class DefaultProjectBuilder
public ProjectBuildingResult build( File pomFile, ProjectBuildingRequest request )
throws ProjectBuildingException
{
- return build( pomFile, new FileModelSource( pomFile ), new InternalConfig( request, null ) );
+ return build( pomFile, new FileModelSource( pomFile ),
+ new InternalConfig( request, null, useGlobalModelCache() ? getModelCache() : null ) );
+ }
+
+ private boolean useGlobalModelCache()
+ {
+ return !Boolean.parseBoolean( System.getProperty( DISABLE_GLOBAL_MODEL_CACHE_SYSTEM_PROPERTY ) );
}
@Override
public ProjectBuildingResult build( ModelSource modelSource, ProjectBuildingRequest request )
throws ProjectBuildingException
{
- return build( null, modelSource, new InternalConfig( request, null ) );
+ return build( null, modelSource,
+ new InternalConfig( request, null, useGlobalModelCache() ? getModelCache() : null ) );
}
private ProjectBuildingResult build( File pomFile, ModelSource modelSource, InternalConfig config )
@@ -293,7 +303,7 @@ public class DefaultProjectBuilder
org.eclipse.aether.artifact.Artifact pomArtifact = RepositoryUtils.toArtifact( artifact );
pomArtifact = ArtifactDescriptorUtils.toPomArtifact( pomArtifact );
- InternalConfig config = new InternalConfig( request, null );
+ InternalConfig config = new InternalConfig( request, null, useGlobalModelCache() ? getModelCache() : null );
boolean localProject;
@@ -355,7 +365,8 @@ public class DefaultProjectBuilder
ReactorModelPool modelPool = new ReactorModelPool();
- InternalConfig config = new InternalConfig( request, modelPool );
+ InternalConfig config = new InternalConfig( request, modelPool,
+ useGlobalModelCache() ? getModelCache() : new ReactorModelCache() );
Map<String, MavenProject> projectIndex = new HashMap<>( 256 );
@@ -944,11 +955,11 @@ public class DefaultProjectBuilder
private final ReactorModelCache modelCache;
- InternalConfig( ProjectBuildingRequest request, ReactorModelPool modelPool )
+ InternalConfig( ProjectBuildingRequest request, ReactorModelPool modelPool, ReactorModelCache modelCache )
{
this.request = request;
this.modelPool = modelPool;
- this.modelCache = getModelCache();
+ this.modelCache = modelCache;
session =
LegacyLocalRepositoryManager.overlay( request.getLocalRepository(), request.getRepositorySession(),
repoSystem );
diff --git a/maven-core/src/test/java/org/apache/maven/project/ProjectBuilderTest.java b/maven-core/src/test/java/org/apache/maven/project/ProjectBuilderTest.java
index 0d68a42..ef9a540 100644
--- a/maven-core/src/test/java/org/apache/maven/project/ProjectBuilderTest.java
+++ b/maven-core/src/test/java/org/apache/maven/project/ProjectBuilderTest.java
@@ -90,28 +90,34 @@ public class ProjectBuilderTest
}
public void testReadModifiedPoms() throws Exception {
- // TODO a similar test should be created to test the dependency management (basically all usages
- // of DefaultModelBuilder.getCache() are affected by MNG-6530
+ String initialValue = System.setProperty(DefaultProjectBuilder.DISABLE_GLOBAL_MODEL_CACHE_SYSTEM_PROPERTY, Boolean.toString(true));
+ // TODO a similar test should be created to test the dependency management (basically all usages
+ // of DefaultModelBuilder.getCache() are affected by MNG-6530
File tempDir = Files.createTempDir();
FileUtils.copyDirectoryStructure(new File( "src/test/resources/projects/grandchild-check"), tempDir);
try {
- MavenSession mavenSession = createMavenSession( null );
- ProjectBuildingRequest configuration = new DefaultProjectBuildingRequest();
- configuration.setRepositorySession( mavenSession.getRepositorySession() );
- org.apache.maven.project.ProjectBuilder projectBuilder = lookup( org.apache.maven.project.ProjectBuilder.class );
- File child = new File(tempDir, "child/pom.xml");
- // build project once
- projectBuilder.build(child, configuration);
- // modify parent
- File parent = new File(tempDir, "pom.xml");
- String parentContent = FileUtils.fileRead(parent);
- parentContent = parentContent.replaceAll("<packaging>pom</packaging>", "<packaging>pom</packaging><properties><addedProperty>addedValue</addedProperty></properties>");
- FileUtils.fileWrite(parent, "UTF-8", parentContent);
- // re-build pom with modified parent
- ProjectBuildingResult result = projectBuilder.build(child, configuration);
- assertTrue(result.getProject().getProperties().containsKey("addedProperty"));
+ MavenSession mavenSession = createMavenSession( null );
+ ProjectBuildingRequest configuration = new DefaultProjectBuildingRequest();
+ configuration.setRepositorySession( mavenSession.getRepositorySession() );
+ org.apache.maven.project.ProjectBuilder projectBuilder = lookup( org.apache.maven.project.ProjectBuilder.class );
+ File child = new File(tempDir, "child/pom.xml");
+ // build project once
+ projectBuilder.build(child, configuration);
+ // modify parent
+ File parent = new File(tempDir, "pom.xml");
+ String parentContent = FileUtils.fileRead(parent);
+ parentContent = parentContent.replaceAll("<packaging>pom</packaging>", "<packaging>pom</packaging><properties><addedProperty>addedValue</addedProperty></properties>");
+ FileUtils.fileWrite(parent, "UTF-8", parentContent);
+ // re-build pom with modified parent
+ ProjectBuildingResult result = projectBuilder.build(child, configuration);
+ assertTrue(result.getProject().getProperties().containsKey("addedProperty"));
} finally {
- FileUtils.deleteDirectory(tempDir);
+ if (initialValue == null) {
+ System.clearProperty(DefaultProjectBuilder.DISABLE_GLOBAL_MODEL_CACHE_SYSTEM_PROPERTY);
+ } else {
+ System.setProperty(DefaultProjectBuilder.DISABLE_GLOBAL_MODEL_CACHE_SYSTEM_PROPERTY, initialValue);
+ }
+ FileUtils.deleteDirectory(tempDir);
}
}
}