You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by GitBox <gi...@apache.org> on 2019/01/08 20:29:09 UTC

[GitHub] asfgit closed pull request #194: MNG-6530 - Test + System property to disable global model cache

asfgit closed pull request #194: MNG-6530 - Test + System property to disable global model cache
URL: https://github.com/apache/maven/pull/194
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

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 35a4e9f596..a4020406cc 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 @@
     implements ProjectBuilder
 {
 
+    public static final String DISABLE_GLOBAL_MODEL_CACHE_SYSTEM_PROPERTY =
+            "maven.defaultProjectBuilder.disableGlobalModelCache";
+
     @Requirement
     private Logger logger;
 
@@ -115,14 +118,21 @@
     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.getBoolean( 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 ProjectBuildingResult build( Artifact artifact, boolean allowStubModel, P
         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 @@ private ModelSource createStubModelSource( Artifact artifact )
 
         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 );
 
@@ -951,11 +962,11 @@ private String findProfilesXml( ModelBuildingResult result, Map<File, Boolean> p
 
         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 18f22bd297..c472e470d7 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
@@ -28,6 +28,9 @@
 import org.apache.maven.execution.MavenSession;
 import org.apache.maven.model.building.FileModelSource;
 import org.apache.maven.model.building.ModelSource;
+import org.apache.maven.shared.utils.io.FileUtils;
+
+import com.google.common.io.Files;
 
 public class ProjectBuilderTest
     extends AbstractCoreMavenComponentTestCase
@@ -126,4 +129,42 @@ public void testDontResolveDependencies()
         assertEquals( 0, mavenProject.getArtifacts().size() );
     }
 
+    public void testReadModifiedPoms() throws Exception {
+        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" ) );
+        }
+        finally
+        {
+            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 );
+        }
+    }
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services