You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2021/02/12 12:32:46 UTC

[maven] branch MNG-7063 created (now 6d8c24d)

This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a change to branch MNG-7063
in repository https://gitbox.apache.org/repos/asf/maven.git.


      at 6d8c24d  Fix failing integration tests

This branch includes the following new commits:

     new 7f517ed  Make sure ITs can still be used to verify older Maven versions
     new 1f22b55  Merge branch 'master' of https://gitbox.apache.org/repos/asf/maven
     new fd978e1  Use stock junit 5 parameterized tests
     new 9905ee3  Use JUnit 5 extension
     new 6b99829  Remove condition which is always true
     new e30f2c8  Make sure ModelCacheTag.FILEMODEL is always and only used in readModel()
     new 6247800  Break the readModel method into smaller methods
     new d28ca06  Move the ModelCacheTag usage to the ModelCache interface
     new d0873d0  Break the importDependencyManagement method into smaller methods
     new 5e8c509  Do not use a "persistent" cache which is the root cause MNG-6530
     new 00c7f3d  Avoid calling getParentPomFile twice
     new db7ad74  Avoid code duplication
     new 335c08e  Avoid useless anonymous classes
     new 107463b  Fix indentation
     new a1fa200  Use local variables
     new e0cd91f  Reuse existing methods to avoid code duplication
     new 788187a  Simplify readParent()
     new 5f51e81  Remove unneeded @SupressWarnings
     new 59ba25b  RAW models are not queried by GAV anymore, so no need to store them that way
     new a692419  Reuse the original request
     new f8abfb7  Extract FileToRawModelMerger
     new 6d8c24d  Fix failing integration tests

The 22 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[maven] 19/22: RAW models are not queried by GAV anymore, so no need to store them that way

Posted by rf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a commit to branch MNG-7063
in repository https://gitbox.apache.org/repos/asf/maven.git

commit 59ba25bc6af402901ce2c827398eb06e7965becb
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Mon Nov 30 14:00:02 2020 +0100

    RAW models are not queried by GAV anymore, so no need to store them that way
---
 .../main/java/org/apache/maven/model/building/DefaultModelBuilder.java   | 1 -
 1 file changed, 1 deletion(-)

diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
index d8292f5..83fe686 100644
--- a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
+++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
@@ -773,7 +773,6 @@ public class DefaultModelBuilder
         String version = getVersion( rawModel );
 
         ModelData modelData = new ModelData( modelSource, rawModel, groupId, artifactId, version );
-        intoCache( request.getModelCache(), groupId, artifactId, version, ModelCacheTag.RAW, modelData );
         intoCache( request.getModelCache(), modelSource, ModelCacheTag.RAW, modelData );
 
         return rawModel;


[maven] 20/22: Reuse the original request

Posted by rf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a commit to branch MNG-7063
in repository https://gitbox.apache.org/repos/asf/maven.git

commit a6924197432a2b14275c00123f09689d6bfc2ace
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Mon Nov 30 14:05:11 2020 +0100

    Reuse the original request
---
 .../apache/maven/model/building/DefaultModelBuilder.java   | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
index 83fe686..5edc249 100644
--- a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
+++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
@@ -1417,18 +1417,14 @@ public class DefaultModelBuilder
                 return null;
             }
 
-            ModelBuildingRequest importRequest = new DefaultModelBuildingRequest();
-            importRequest.setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL );
-            importRequest.setModelCache( request.getModelCache() );
-            importRequest.setSystemProperties( request.getSystemProperties() );
-            importRequest.setUserProperties( request.getUserProperties() );
-            importRequest.setLocationTracking( request.isLocationTracking() );
-            importRequest.setModelSource( importSource );
-            importRequest.setModelResolver( modelResolver.newCopy() );
-
             final ModelBuildingResult importResult;
             try
             {
+                ModelBuildingRequest importRequest = new DefaultModelBuildingRequest( request )
+                        .setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL )
+                        .setModelSource( importSource )
+                        .setModelResolver( modelResolver.newCopy() );
+
                 importResult = build( importRequest, importIds );
             }
             catch ( ModelBuildingException e )


[maven] 22/22: Fix failing integration tests

Posted by rf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a commit to branch MNG-7063
in repository https://gitbox.apache.org/repos/asf/maven.git

commit 6d8c24d61c1dfa29c7c2cef074487550da9ce9e7
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Tue Jan 19 16:29:38 2021 +0100

    Fix failing integration tests
---
 .../main/java/org/apache/maven/model/building/DefaultModelBuilder.java   | 1 +
 1 file changed, 1 insertion(+)

diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
index 675958f..afde52a 100644
--- a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
+++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
@@ -1415,6 +1415,7 @@ public class DefaultModelBuilder
             try
             {
                 ModelBuildingRequest importRequest = new DefaultModelBuildingRequest( request )
+                        .setTwoPhaseBuilding( false )
                         .setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL )
                         .setModelSource( importSource )
                         .setModelResolver( modelResolver.newCopy() );


[maven] 14/22: Fix indentation

Posted by rf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a commit to branch MNG-7063
in repository https://gitbox.apache.org/repos/asf/maven.git

commit 107463b42732ae825b40cc5f7b075c234c3b8ce3
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Mon Nov 30 10:54:43 2020 +0100

    Fix indentation
    
    # Conflicts:
    #	maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
---
 .../main/java/org/apache/maven/model/building/DefaultModelBuilder.java  | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
index bdf2d93..1e86fce 100644
--- a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
+++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
@@ -723,7 +723,7 @@ public class DefaultModelBuilder
         ModelData cachedData = fromCache( request.getModelCache(), modelSource, ModelCacheTag.RAW );
         if ( cachedData != null )
         {
-          return cachedData.getModel();
+            return cachedData.getModel();
         }
 
         Model rawModel;


[maven] 21/22: Extract FileToRawModelMerger

Posted by rf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a commit to branch MNG-7063
in repository https://gitbox.apache.org/repos/asf/maven.git

commit f8abfb7f5a2ef77ee097b948c7531e9378caf32c
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Mon Nov 30 14:19:58 2020 +0100

    Extract FileToRawModelMerger
    
    # Conflicts:
    #	maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
---
 .../maven/model/building/DefaultModelBuilder.java  | 158 -----------------
 .../maven/model/building/FileToRawModelMerger.java | 190 +++++++++++++++++++++
 .../model/building/FileToRawModelMergerTest.java   |   1 -
 3 files changed, 190 insertions(+), 159 deletions(-)

diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
index 5edc249..675958f 100644
--- a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
+++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
@@ -51,21 +51,15 @@ import org.apache.maven.building.Source;
 import org.apache.maven.feature.Features;
 import org.apache.maven.model.Activation;
 import org.apache.maven.model.Build;
-import org.apache.maven.model.BuildBase;
-import org.apache.maven.model.CiManagement;
 import org.apache.maven.model.Dependency;
 import org.apache.maven.model.DependencyManagement;
 import org.apache.maven.model.InputLocation;
 import org.apache.maven.model.InputSource;
 import org.apache.maven.model.Model;
-import org.apache.maven.model.ModelBase;
 import org.apache.maven.model.Parent;
 import org.apache.maven.model.Plugin;
-import org.apache.maven.model.PluginContainer;
 import org.apache.maven.model.PluginManagement;
 import org.apache.maven.model.Profile;
-import org.apache.maven.model.ReportPlugin;
-import org.apache.maven.model.Reporting;
 import org.apache.maven.model.Repository;
 import org.apache.maven.model.building.ModelProblem.Severity;
 import org.apache.maven.model.building.ModelProblem.Version;
@@ -1533,158 +1527,6 @@ public class DefaultModelBuilder
     }
 
     /**
-     * As long as Maven controls the BuildPomXMLFilter, the entities that need merging are known.
-     * All others can simply be copied from source to target to restore the locationTracker
-     *
-     * @author Robert Scholte
-     * @since 4.0.0
-     */
-    class FileToRawModelMerger extends ModelMerger
-    {
-        @Override
-        protected void mergeBuild_Extensions( Build target, Build source, boolean sourceDominant,
-                                              Map<Object, Object> context )
-        {
-            // don't merge
-        }
-
-
-        @Override
-        protected void mergeBuildBase_Resources( BuildBase target, BuildBase source, boolean sourceDominant,
-                                                 Map<Object, Object> context )
-        {
-            // don't merge
-        }
-
-        @Override
-        protected void mergeBuildBase_TestResources( BuildBase target, BuildBase source, boolean sourceDominant,
-                                                     Map<Object, Object> context )
-        {
-            // don't merge
-        }
-
-        @Override
-        protected void mergeCiManagement_Notifiers( CiManagement target, CiManagement source, boolean sourceDominant,
-                                                    Map<Object, Object> context )
-        {
-            // don't merge
-        }
-
-        @Override
-        protected void mergeDependencyManagement_Dependencies( DependencyManagement target, DependencyManagement source,
-                                                               boolean sourceDominant, Map<Object, Object> context )
-        {
-            Iterator<Dependency> sourceIterator = source.getDependencies().iterator();
-            target.getDependencies().stream().forEach( t -> mergeDependency( t, sourceIterator.next(), sourceDominant,
-                                                                             context ) );
-        }
-
-        @Override
-        protected void mergeDependency_Exclusions( Dependency target, Dependency source, boolean sourceDominant,
-                                                   Map<Object, Object> context )
-        {
-            // don't merge
-        }
-
-        @Override
-        protected void mergeModel_Contributors( Model target, Model source, boolean sourceDominant,
-                                                Map<Object, Object> context )
-        {
-            // don't merge
-        }
-
-        @Override
-        protected void mergeModel_Developers( Model target, Model source, boolean sourceDominant,
-                                              Map<Object, Object> context )
-        {
-            // don't merge
-        }
-
-        @Override
-        protected void mergeModel_Licenses( Model target, Model source, boolean sourceDominant,
-                                            Map<Object, Object> context )
-        {
-            // don't merge
-        }
-
-        @Override
-        protected void mergeModel_MailingLists( Model target, Model source, boolean sourceDominant,
-                                                Map<Object, Object> context )
-        {
-            // don't merge
-        }
-
-        @Override
-        protected void mergeModel_Profiles( Model target, Model source, boolean sourceDominant,
-                                            Map<Object, Object> context )
-        {
-            Iterator<Profile> sourceIterator = source.getProfiles().iterator();
-            target.getProfiles().stream().forEach( t -> mergeProfile( t, sourceIterator.next(), sourceDominant,
-                                                                      context ) );
-        }
-
-        @Override
-        protected void mergeModelBase_Dependencies( ModelBase target, ModelBase source, boolean sourceDominant,
-                                                    Map<Object, Object> context )
-        {
-            Iterator<Dependency> sourceIterator = source.getDependencies().iterator();
-            target.getDependencies().stream().forEach( t -> mergeDependency( t, sourceIterator.next(), sourceDominant,
-                                                                             context ) );
-        }
-
-        @Override
-        protected void mergeModelBase_PluginRepositories( ModelBase target, ModelBase source, boolean sourceDominant,
-                                                          Map<Object, Object> context )
-        {
-            target.setPluginRepositories( source.getPluginRepositories() );
-        }
-
-        @Override
-        protected void mergeModelBase_Repositories( ModelBase target, ModelBase source, boolean sourceDominant,
-                                                    Map<Object, Object> context )
-        {
-            // don't merge
-        }
-
-        @Override
-        protected void mergePlugin_Dependencies( Plugin target, Plugin source, boolean sourceDominant,
-                                                 Map<Object, Object> context )
-        {
-            Iterator<Dependency> sourceIterator = source.getDependencies().iterator();
-            target.getDependencies().stream().forEach( t -> mergeDependency( t, sourceIterator.next(), sourceDominant,
-                                                                             context ) );
-        }
-
-        @Override
-        protected void mergePlugin_Executions( Plugin target, Plugin source, boolean sourceDominant,
-                                               Map<Object, Object> context )
-        {
-            // don't merge
-        }
-
-        @Override
-        protected void mergeReporting_Plugins( Reporting target, Reporting source, boolean sourceDominant,
-                                               Map<Object, Object> context )
-        {
-            // don't merge
-        }
-
-        @Override
-        protected void mergeReportPlugin_ReportSets( ReportPlugin target, ReportPlugin source, boolean sourceDominant,
-                                                     Map<Object, Object> context )
-        {
-            // don't merge
-        }
-
-        @Override
-        protected void mergePluginContainer_Plugins( PluginContainer target, PluginContainer source,
-                                                     boolean sourceDominant, Map<Object, Object> context )
-        {
-            // don't merge
-        }
-    }
-
-    /**
      * Builds up the transformer context.
      * After the buildplan is ready, the build()-method returns the immutable context useful during distribution.
      * This is an inner class, as it must be able to call readRawModel()
diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/FileToRawModelMerger.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/FileToRawModelMerger.java
new file mode 100644
index 0000000..f697d77
--- /dev/null
+++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/FileToRawModelMerger.java
@@ -0,0 +1,190 @@
+package org.apache.maven.model.building;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.maven.model.Build;
+import org.apache.maven.model.BuildBase;
+import org.apache.maven.model.CiManagement;
+import org.apache.maven.model.Dependency;
+import org.apache.maven.model.DependencyManagement;
+import org.apache.maven.model.Model;
+import org.apache.maven.model.ModelBase;
+import org.apache.maven.model.Plugin;
+import org.apache.maven.model.PluginContainer;
+import org.apache.maven.model.Profile;
+import org.apache.maven.model.ReportPlugin;
+import org.apache.maven.model.Reporting;
+import org.apache.maven.model.merge.ModelMerger;
+
+/**
+ * As long as Maven controls the BuildPomXMLFilter, the entities that need merging are known.
+ * All others can simply be copied from source to target to restore the locationTracker
+ *
+ * @author Robert Scholte
+ * @since 4.0.0
+ */
+class FileToRawModelMerger extends ModelMerger
+{
+
+    @Override
+    protected void mergeBuild_Extensions( Build target, Build source, boolean sourceDominant,
+                                          Map<Object, Object> context )
+    {
+        // don't merge
+    }
+
+
+    @Override
+    protected void mergeBuildBase_Resources( BuildBase target, BuildBase source, boolean sourceDominant,
+                                             Map<Object, Object> context )
+    {
+        // don't merge
+    }
+
+    @Override
+    protected void mergeBuildBase_TestResources( BuildBase target, BuildBase source, boolean sourceDominant,
+                                                 Map<Object, Object> context )
+    {
+        // don't merge
+    }
+
+    @Override
+    protected void mergeCiManagement_Notifiers( CiManagement target, CiManagement source, boolean sourceDominant,
+                                                Map<Object, Object> context )
+    {
+        // don't merge
+    }
+
+    @Override
+    protected void mergeDependencyManagement_Dependencies( DependencyManagement target, DependencyManagement source,
+                                                           boolean sourceDominant, Map<Object, Object> context )
+    {
+        Iterator<Dependency> sourceIterator = source.getDependencies().iterator();
+        target.getDependencies().stream().forEach( t -> mergeDependency( t, sourceIterator.next(), sourceDominant,
+                                                                         context ) );
+    }
+
+    @Override
+    protected void mergeDependency_Exclusions( Dependency target, Dependency source, boolean sourceDominant,
+                                               Map<Object, Object> context )
+    {
+        // don't merge
+    }
+
+    @Override
+    protected void mergeModel_Contributors( Model target, Model source, boolean sourceDominant,
+                                            Map<Object, Object> context )
+    {
+        // don't merge
+    }
+
+    @Override
+    protected void mergeModel_Developers( Model target, Model source, boolean sourceDominant,
+                                          Map<Object, Object> context )
+    {
+        // don't merge
+    }
+
+    @Override
+    protected void mergeModel_Licenses( Model target, Model source, boolean sourceDominant,
+                                        Map<Object, Object> context )
+    {
+        // don't merge
+    }
+
+    @Override
+    protected void mergeModel_MailingLists( Model target, Model source, boolean sourceDominant,
+                                            Map<Object, Object> context )
+    {
+        // don't merge
+    }
+
+    @Override
+    protected void mergeModel_Profiles( Model target, Model source, boolean sourceDominant,
+                                        Map<Object, Object> context )
+    {
+        Iterator<Profile> sourceIterator = source.getProfiles().iterator();
+        target.getProfiles().stream().forEach( t -> mergeProfile( t, sourceIterator.next(), sourceDominant,
+                                                                  context ) );
+    }
+
+    @Override
+    protected void mergeModelBase_Dependencies( ModelBase target, ModelBase source, boolean sourceDominant,
+                                                Map<Object, Object> context )
+    {
+        Iterator<Dependency> sourceIterator = source.getDependencies().iterator();
+        target.getDependencies().stream().forEach( t -> mergeDependency( t, sourceIterator.next(), sourceDominant,
+                                                                         context ) );
+    }
+
+    @Override
+    protected void mergeModelBase_PluginRepositories( ModelBase target, ModelBase source, boolean sourceDominant,
+                                                      Map<Object, Object> context )
+    {
+        target.setPluginRepositories( source.getPluginRepositories() );
+    }
+
+    @Override
+    protected void mergeModelBase_Repositories( ModelBase target, ModelBase source, boolean sourceDominant,
+                                                Map<Object, Object> context )
+    {
+        // don't merge
+    }
+
+    @Override
+    protected void mergePlugin_Dependencies( Plugin target, Plugin source, boolean sourceDominant,
+                                             Map<Object, Object> context )
+    {
+        Iterator<Dependency> sourceIterator = source.getDependencies().iterator();
+        target.getDependencies().stream().forEach( t -> mergeDependency( t, sourceIterator.next(), sourceDominant,
+                                                                         context ) );
+    }
+
+    @Override
+    protected void mergePlugin_Executions( Plugin target, Plugin source, boolean sourceDominant,
+                                           Map<Object, Object> context )
+    {
+        // don't merge
+    }
+
+    @Override
+    protected void mergeReporting_Plugins( Reporting target, Reporting source, boolean sourceDominant,
+                                           Map<Object, Object> context )
+    {
+        // don't merge
+    }
+
+    @Override
+    protected void mergeReportPlugin_ReportSets( ReportPlugin target, ReportPlugin source, boolean sourceDominant,
+                                                 Map<Object, Object> context )
+    {
+        // don't merge
+    }
+
+    @Override
+    protected void mergePluginContainer_Plugins( PluginContainer target, PluginContainer source,
+                                                 boolean sourceDominant, Map<Object, Object> context )
+    {
+        // don't merge
+    }
+}
diff --git a/maven-model-builder/src/test/java/org/apache/maven/model/building/FileToRawModelMergerTest.java b/maven-model-builder/src/test/java/org/apache/maven/model/building/FileToRawModelMergerTest.java
index 9d53014..286664c 100644
--- a/maven-model-builder/src/test/java/org/apache/maven/model/building/FileToRawModelMergerTest.java
+++ b/maven-model-builder/src/test/java/org/apache/maven/model/building/FileToRawModelMergerTest.java
@@ -26,7 +26,6 @@ import java.util.List;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
-import org.apache.maven.model.building.DefaultModelBuilder.FileToRawModelMerger;
 import org.apache.maven.model.merge.ModelMerger;
 import org.junit.jupiter.api.Test;
 


[maven] 06/22: Make sure ModelCacheTag.FILEMODEL is always and only used in readModel()

Posted by rf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a commit to branch MNG-7063
in repository https://gitbox.apache.org/repos/asf/maven.git

commit e30f2c8e5549a5480561d636c24b252628fd03fe
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Sat Nov 28 21:54:29 2020 +0100

    Make sure ModelCacheTag.FILEMODEL is always and only used in readModel()
    
    # Conflicts:
    #	maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
---
 .../maven/model/building/DefaultModelBuilder.java  | 27 +---------------------
 1 file changed, 1 insertion(+), 26 deletions(-)

diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
index ebe0336..9417619 100644
--- a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
+++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
@@ -592,7 +592,7 @@ public class DefaultModelBuilder
         throws ModelBuildingException
     {
         ModelSource modelSource = request.getModelSource();
-        Model model = getModelFromCache( modelSource, request.getModelCache() );
+        Model model = fromCache( request.getModelCache(), modelSource, ModelCacheTag.FILE );
         if ( model != null )
         {
             return model;
@@ -780,31 +780,6 @@ public class DefaultModelBuilder
         return rawModel;
     }
 
-    private Model getModelFromCache( Source source, ModelCache cache )
-    {
-        Model model;
-        if ( source instanceof ArtifactModelSource )
-        {
-            ArtifactModelSource artifactModelSource = ( ArtifactModelSource ) source;
-            ModelData modelData = fromCache( cache, artifactModelSource.getGroupId(),
-                                            artifactModelSource.getArtifactId(),
-                                            artifactModelSource.getVersion(), ModelCacheTag.RAW );
-            if ( modelData != null )
-            {
-                model = modelData.getModel();
-            }
-            else
-            {
-                model = null;
-            }
-        }
-        else
-        {
-            model = fromCache( cache, source, ModelCacheTag.FILE );
-        }
-        return model;
-    }
-
     private String getGroupId( Model model )
     {
         String groupId = model.getGroupId();


[maven] 07/22: Break the readModel method into smaller methods

Posted by rf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a commit to branch MNG-7063
in repository https://gitbox.apache.org/repos/asf/maven.git

commit 6247800eff9c8bbd00063dae42cd101720714ff2
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Sat Nov 28 22:01:50 2020 +0100

    Break the readModel method into smaller methods
    
    # Conflicts:
    #	maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
---
 .../maven/model/building/DefaultModelBuilder.java  | 37 ++++++++++++++--------
 1 file changed, 23 insertions(+), 14 deletions(-)

diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
index 9417619..f66ae86 100644
--- a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
+++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
@@ -586,18 +586,38 @@ public class DefaultModelBuilder
         }
     }
 
-    @SuppressWarnings( "checkstyle:methodlength" )
     private Model readFileModel( ModelBuildingRequest request,
                                  DefaultModelProblemCollector problems )
         throws ModelBuildingException
     {
         ModelSource modelSource = request.getModelSource();
         Model model = fromCache( request.getModelCache(), modelSource, ModelCacheTag.FILE );
-        if ( model != null )
+        if ( model == null )
         {
-            return model;
+            model = doReadFileModel( modelSource, request, problems );
+
+            intoCache( request.getModelCache(), modelSource, ModelCacheTag.FILE, model );
+        }
+
+        if ( modelSource instanceof FileModelSource )
+        {
+            if ( request.getTransformerContextBuilder() instanceof DefaultTransformerContextBuilder )
+            {
+                DefaultTransformerContextBuilder contextBuilder =
+                        (DefaultTransformerContextBuilder) request.getTransformerContextBuilder();
+                contextBuilder.putSource( getGroupId( model ), model.getArtifactId(), modelSource );
+            }
         }
 
+        return model;
+    }
+
+    @SuppressWarnings( "checkstyle:methodlength" )
+    private Model doReadFileModel( ModelSource modelSource, ModelBuildingRequest request,
+                                 DefaultModelProblemCollector problems )
+            throws ModelBuildingException
+    {
+        Model model;
         problems.setSource( modelSource.getLocation() );
         try
         {
@@ -700,17 +720,6 @@ public class DefaultModelBuilder
             throw problems.newModelBuildingException();
         }
 
-        intoCache( request.getModelCache(), modelSource, ModelCacheTag.FILE, model );
-        if ( modelSource instanceof FileModelSource )
-        {
-            if ( request.getTransformerContextBuilder() instanceof DefaultTransformerContextBuilder )
-            {
-                DefaultTransformerContextBuilder contextBuilder =
-                        (DefaultTransformerContextBuilder) request.getTransformerContextBuilder();
-                contextBuilder.putSource( getGroupId( model ), model.getArtifactId(), modelSource );
-            }
-        }
-
         return model;
     }
 


[maven] 05/22: Remove condition which is always true

Posted by rf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a commit to branch MNG-7063
in repository https://gitbox.apache.org/repos/asf/maven.git

commit 6b99829addaa11c47dcbadc3aebee6a08dae9297
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Wed Nov 25 14:45:54 2020 +0100

    Remove condition which is always true
---
 .../main/java/org/apache/maven/model/building/DefaultModelBuilder.java  | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
index 7233cf5..ebe0336 100644
--- a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
+++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
@@ -388,7 +388,7 @@ public class DefaultModelBuilder
 
         List<Model> lineage = new ArrayList<>();
 
-        for ( ModelData currentData = resultData; currentData != null; )
+        for ( ModelData currentData = resultData; ; )
         {
             String modelId = currentData.getId();
             result.addModelId( modelId );


[maven] 13/22: Avoid useless anonymous classes

Posted by rf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a commit to branch MNG-7063
in repository https://gitbox.apache.org/repos/asf/maven.git

commit 335c08e5b232b3206131a580690e9d20709fc8bd
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Mon Nov 30 10:54:35 2020 +0100

    Avoid useless anonymous classes
    
    # Conflicts:
    #	maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
---
 .../maven/model/building/DefaultModelBuilder.java  | 44 ++++------------------
 .../building/DefaultModelBuildingRequest.java      |  1 +
 2 files changed, 9 insertions(+), 36 deletions(-)

diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
index 83e69b0..bdf2d93 100644
--- a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
+++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
@@ -1076,14 +1076,8 @@ public class DefaultModelBuilder
                 return null;
             }
 
-            ModelBuildingRequest candidateBuildRequest = new FilterModelBuildingRequest( request )
-            {
-                  @Override
-                public ModelSource getModelSource()
-                {
-                    return candidateSource;
-                }
-            };
+            ModelBuildingRequest candidateBuildRequest = new DefaultModelBuildingRequest( request )
+                .setModelSource( candidateSource );
 
             candidateModel = readRawModel( candidateBuildRequest, problems );
         }
@@ -1273,25 +1267,10 @@ public class DefaultModelBuilder
         }
 
         int validationLevel = Math.min( request.getValidationLevel(), ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0 );
-        ModelBuildingRequest lenientRequest = new FilterModelBuildingRequest( request )
-        {
-            @Override
-            public int getValidationLevel()
-            {
-                return validationLevel;
-            }
-
-            @Override
-            public ModelSource getModelSource()
-            {
-                return modelSource;
-            }
-            @Override
-            public Model getFileModel()
-            {
-                return null;
-            }
-        };
+        ModelBuildingRequest lenientRequest = new DefaultModelBuildingRequest( request )
+                .setValidationLevel( validationLevel )
+                .setFileModel( null )
+                .setModelSource( modelSource );
 
         Model parentModel = readRawModel( lenientRequest, problems );
 
@@ -1824,15 +1803,8 @@ public class DefaultModelBuilder
                     {
                         try
                         {
-                            ModelBuildingRequest gaBuildingRequest = new FilterModelBuildingRequest( request )
-                            {
-                                @Override
-                                public ModelSource getModelSource()
-                                {
-                                    return (ModelSource) source;
-                                }
-
-                            };
+                            ModelBuildingRequest gaBuildingRequest = new DefaultModelBuildingRequest( request )
+                                .setModelSource( (ModelSource) source );
                             return readRawModel( gaBuildingRequest, problems );
                         }
                         catch ( ModelBuildingException e )
diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuildingRequest.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuildingRequest.java
index a012786..379b5e7 100644
--- a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuildingRequest.java
+++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuildingRequest.java
@@ -102,6 +102,7 @@ public class DefaultModelBuildingRequest
         setModelResolver( request.getModelResolver() );
         setModelBuildingListener( request.getModelBuildingListener() );
         setModelCache( request.getModelCache() );
+        setWorkspaceModelResolver( request.getWorkspaceModelResolver() );
         setTransformerContextBuilder( request.getTransformerContextBuilder() );
     }
 


[maven] 03/22: Use stock junit 5 parameterized tests

Posted by rf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a commit to branch MNG-7063
in repository https://gitbox.apache.org/repos/asf/maven.git

commit fd978e17fab1800cfc9ffb655af61305294d1b0c
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Mon Jan 18 11:46:19 2021 +0100

    Use stock junit 5 parameterized tests
---
 .../maven/graph/DefaultGraphBuilderTest.java       |  51 +++---
 .../main/java/org/apache/maven/test/Parameter.java |  32 ----
 .../java/org/apache/maven/test/Parameterized.java  |  37 -----
 .../apache/maven/test/ParameterizedExtension.java  | 182 ---------------------
 .../java/org/apache/maven/test/Parameters.java     |  35 ----
 .../src/main/java/org/apache/maven/test/Test.java  |  34 ----
 .../maven/xml/sax/ext/CommentRenormalizerTest.java |  31 +---
 7 files changed, 29 insertions(+), 373 deletions(-)

diff --git a/maven-core/src/test/java/org/apache/maven/graph/DefaultGraphBuilderTest.java b/maven-core/src/test/java/org/apache/maven/graph/DefaultGraphBuilderTest.java
index d2f29e2..4a8f9c0 100644
--- a/maven-core/src/test/java/org/apache/maven/graph/DefaultGraphBuilderTest.java
+++ b/maven-core/src/test/java/org/apache/maven/graph/DefaultGraphBuilderTest.java
@@ -37,12 +37,11 @@ import org.apache.maven.project.collector.MultiModuleCollectionStrategy;
 import org.apache.maven.project.collector.PomlessCollectionStrategy;
 import org.apache.maven.project.collector.ProjectsSelector;
 import org.apache.maven.project.collector.RequestPomCollectionStrategy;
-import org.apache.maven.test.Parameter;
-import org.apache.maven.test.Parameterized;
-import org.apache.maven.test.Parameters;
-import org.apache.maven.test.Test;
 import org.codehaus.plexus.util.StringUtils;
 import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
 
 import java.io.File;
 import java.util.ArrayList;
@@ -60,11 +59,12 @@ import static org.apache.maven.execution.MavenExecutionRequest.REACTOR_MAKE_DOWN
 import static org.apache.maven.execution.MavenExecutionRequest.REACTOR_MAKE_UPSTREAM;
 import static org.apache.maven.graph.DefaultGraphBuilderTest.ScenarioBuilder.scenario;
 import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.mockito.ArgumentMatchers.*;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.anyList;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
-@Parameterized
 public class DefaultGraphBuilderTest
 {
     /*
@@ -103,26 +103,9 @@ public class DefaultGraphBuilderTest
 
     private Map<String, MavenProject> artifactIdProjectMap;
 
-    // Parameters for the test
-    @Parameter( 0 )
-    private String parameterDescription;
-    @Parameter( 1 )
-    private List<String> parameterSelectedProjects;
-    @Parameter( 2 )
-    private List<String> parameterExcludedProjects;
-    @Parameter( 3 )
-    private String parameterResumeFrom;
-    @Parameter( 4 )
-    private String parameterMakeBehavior;
-    @Parameter( 5 )
-    private List<String> parameterExpectedResult;
-    @Parameter( 6 )
-    private File parameterRequestedPom;
-
-    @Parameters(name = "{index}. {0}")
-    public static Collection<Object[]> parameters()
+    public static Stream<Arguments> parameters()
     {
-        return asList(
+        return Stream.of(
                 scenario( "Full reactor in order" )
                         .expectResult( PARENT_MODULE, MODULE_C, MODULE_C_1, MODULE_A, MODULE_B, MODULE_C_2, INDEPENDENT_MODULE ),
                 scenario( "Selected project" )
@@ -198,8 +181,16 @@ public class DefaultGraphBuilderTest
         );
     }
 
-    @Test
-    public void testGetReactorProjects()
+    @ParameterizedTest
+    @MethodSource("parameters")
+    public void testGetReactorProjects(
+            String parameterDescription,
+            List<String> parameterSelectedProjects,
+            List<String> parameterExcludedProjects,
+            String parameterResumeFrom,
+            String parameterMakeBehavior,
+            List<String> parameterExpectedResult,
+            File parameterRequestedPom)
     {
         // Given
         List<String> selectedProjects = parameterSelectedProjects.stream().map( p -> ":" + p ).collect( Collectors.toList() );
@@ -350,11 +341,11 @@ public class DefaultGraphBuilderTest
             return this;
         }
 
-        public Object[] expectResult( String... expectedReactorProjects )
+        public Arguments expectResult( String... expectedReactorProjects )
         {
-            return new Object[] {
+            return Arguments.arguments(
                     description, selectedProjects, excludedProjects, resumeFrom, makeBehavior, asList( expectedReactorProjects ), requestedPom
-            };
+            );
         }
     }
 }
\ No newline at end of file
diff --git a/maven-test-support/src/main/java/org/apache/maven/test/Parameter.java b/maven-test-support/src/main/java/org/apache/maven/test/Parameter.java
deleted file mode 100644
index f5164c5..0000000
--- a/maven-test-support/src/main/java/org/apache/maven/test/Parameter.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package org.apache.maven.test;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-
-/**
- * Parameter
- */
-@Retention( RetentionPolicy.RUNTIME )
-public @interface Parameter
-{
-    int value() default 0;
-}
diff --git a/maven-test-support/src/main/java/org/apache/maven/test/Parameterized.java b/maven-test-support/src/main/java/org/apache/maven/test/Parameterized.java
deleted file mode 100644
index a15fbaf..0000000
--- a/maven-test-support/src/main/java/org/apache/maven/test/Parameterized.java
+++ /dev/null
@@ -1,37 +0,0 @@
-package org.apache.maven.test;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-import org.junit.jupiter.api.extension.ExtendWith;
-
-/**
- * Parameterized
- */
-@Target( { ElementType.ANNOTATION_TYPE, ElementType.TYPE } )
-@Retention( RetentionPolicy.RUNTIME )
-@ExtendWith( ParameterizedExtension.class )
-public @interface Parameterized
-{
-}
diff --git a/maven-test-support/src/main/java/org/apache/maven/test/ParameterizedExtension.java b/maven-test-support/src/main/java/org/apache/maven/test/ParameterizedExtension.java
deleted file mode 100644
index 5741db4..0000000
--- a/maven-test-support/src/main/java/org/apache/maven/test/ParameterizedExtension.java
+++ /dev/null
@@ -1,182 +0,0 @@
-package org.apache.maven.test;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.util.Arrays;
-import java.util.Comparator;
-import java.util.List;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
-import org.junit.jupiter.api.extension.Extension;
-import org.junit.jupiter.api.extension.ExtensionContext;
-import org.junit.jupiter.api.extension.TestInstancePostProcessor;
-import org.junit.jupiter.api.extension.TestInstantiationException;
-import org.junit.jupiter.api.extension.TestTemplateInvocationContext;
-import org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider;
-import org.junit.jupiter.params.converter.DefaultArgumentConverter;
-import org.junit.jupiter.params.provider.Arguments;
-import org.junit.platform.commons.util.CollectionUtils;
-import org.junit.platform.commons.util.ReflectionUtils;
-
-import static org.junit.jupiter.params.provider.Arguments.arguments;
-import static org.junit.platform.commons.util.AnnotationUtils.isAnnotated;
-
-/**
- * ParameterizedExtension
- */
-public class ParameterizedExtension implements TestTemplateInvocationContextProvider
-{
-
-    @Override
-    public boolean supportsTestTemplate( ExtensionContext context )
-    {
-        return context.getTestMethod()
-                .map( m -> isAnnotated( m, Test.class ) )
-                .orElse( false );
-    }
-
-    @Override
-    public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContexts(
-            ExtensionContext extensionContext )
-    {
-        Class<?> testClass = extensionContext.getRequiredTestClass();
-        try
-        {
-            List<Method> parameters = getParametersMethods( testClass );
-            if ( parameters.size() != 1 )
-            {
-                throw new IllegalStateException(
-                        "Class " + testClass.getName() + " should provide a single method annotated with @"
-                                                + Parameters.class.getSimpleName() );
-            }
-            Object params = parameters.iterator().next().invoke( null );
-            return CollectionUtils.toStream( params )
-                    .map( ParameterizedExtension::toArguments )
-                    .map( Arguments::get )
-                    .map( ParameterizedTemplate::new );
-        }
-        catch ( Exception e )
-        {
-            throw new IllegalStateException( "Unable to generate test templates for class " + testClass.getName(), e );
-        }
-    }
-
-    private List<Method> getParametersMethods( Class<?> testClass )
-    {
-        List<Method> parameters = Stream.of( testClass.getDeclaredMethods() )
-                .filter( m -> Modifier.isStatic( m.getModifiers() ) )
-                .filter( m -> m.getAnnotation( Parameters.class ) != null )
-                .collect( Collectors.toList() );
-        if ( parameters.isEmpty() && testClass != null )
-        {
-            return getParametersMethods( testClass.getSuperclass() );
-        }
-        else
-        {
-            return parameters;
-        }
-    }
-
-    private static Arguments toArguments( Object item )
-    {
-        // Nothing to do except cast.
-        if ( item instanceof Arguments )
-        {
-            return ( Arguments ) item;
-        }
-        // Pass all multidimensional arrays "as is", in contrast to Object[].
-        // See https://github.com/junit-team/junit5/issues/1665
-        if ( ReflectionUtils.isMultidimensionalArray( item ) )
-        {
-            return arguments( item );
-        }
-        // Special treatment for one-dimensional reference arrays.
-        // See https://github.com/junit-team/junit5/issues/1665
-        if ( item instanceof Object[] )
-        {
-            return arguments( ( Object[] ) item );
-        }
-        // Pass everything else "as is".
-        return arguments( item );
-    }
-
-    /**
-     * ParameterizedTemplate
-     */
-    public static class ParameterizedTemplate implements TestTemplateInvocationContext
-    {
-
-        private final Object[] params;
-
-        public ParameterizedTemplate( Object[] params )
-        {
-            this.params = params;
-        }
-
-        @Override
-        public String getDisplayName( int invocationIndex )
-        {
-            return "[" + invocationIndex + "] "
-                   + Stream.of( params ).map( Object::toString ).collect( Collectors.joining( ", " ) );
-        }
-
-        @Override
-        public List<Extension> getAdditionalExtensions()
-        {
-            return Arrays.asList(
-                    ( TestInstancePostProcessor ) this::postProcessTestInstance );
-        }
-
-        protected void postProcessTestInstance( Object testInstance, ExtensionContext context ) throws Exception
-        {
-            Class<?> clazz = testInstance.getClass();
-            List<Field> fields = hierarchy( clazz )
-                    .map( Class::getDeclaredFields )
-                    .flatMap( Stream::of )
-                    .filter( f -> isAnnotated( f, Parameter.class ) )
-                    .sorted( Comparator.comparing( f -> ( Integer ) f.getAnnotation( Parameter.class ).value() ) )
-                    .collect( Collectors.toList() );
-            if ( params.length != fields.size() )
-            {
-                throw new TestInstantiationException(
-                        "Expected " + fields.size() + " parameters bug got " + params.length + " when instantiating "
-                                                     + clazz.getName() );
-            }
-            for ( int i = 0; i < fields.size(); i++ )
-            {
-                Field f = fields.get( i );
-                f.setAccessible( true );
-                f.set( testInstance, DefaultArgumentConverter.INSTANCE.convert( params[i], f.getType() ) );
-            }
-        }
-
-        protected Stream<Class<?>> hierarchy( Class<?> clazz )
-        {
-            Class<?> superclass = clazz.getSuperclass();
-            return Stream.concat( Stream.of( clazz ), superclass != null ? hierarchy( superclass ) : Stream.empty() );
-        }
-
-    }
-
-}
diff --git a/maven-test-support/src/main/java/org/apache/maven/test/Parameters.java b/maven-test-support/src/main/java/org/apache/maven/test/Parameters.java
deleted file mode 100644
index b643a3a..0000000
--- a/maven-test-support/src/main/java/org/apache/maven/test/Parameters.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package org.apache.maven.test;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Parameters
- */
-@Retention( RetentionPolicy.RUNTIME )
-@Target( ElementType.METHOD )
-public @interface Parameters
-{
-    String name() default "{index}";
-}
diff --git a/maven-test-support/src/main/java/org/apache/maven/test/Test.java b/maven-test-support/src/main/java/org/apache/maven/test/Test.java
deleted file mode 100644
index 5b542b6..0000000
--- a/maven-test-support/src/main/java/org/apache/maven/test/Test.java
+++ /dev/null
@@ -1,34 +0,0 @@
-package org.apache.maven.test;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-
-import org.junit.jupiter.api.TestTemplate;
-
-/**
- * Test
- */
-@Retention( RetentionPolicy.RUNTIME )
-@TestTemplate
-public @interface Test
-{
-}
diff --git a/maven-xml/src/test/java/org/apache/maven/xml/sax/ext/CommentRenormalizerTest.java b/maven-xml/src/test/java/org/apache/maven/xml/sax/ext/CommentRenormalizerTest.java
index dad847e..fba3521 100644
--- a/maven-xml/src/test/java/org/apache/maven/xml/sax/ext/CommentRenormalizerTest.java
+++ b/maven-xml/src/test/java/org/apache/maven/xml/sax/ext/CommentRenormalizerTest.java
@@ -22,34 +22,18 @@ package org.apache.maven.xml.sax.ext;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 
-import java.util.Arrays;
-import java.util.Collection;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
 
-import org.apache.maven.test.Parameter;
-import org.apache.maven.test.Parameterized;
-import org.apache.maven.test.Parameters;
-import org.apache.maven.test.Test;
 import org.xml.sax.ext.LexicalHandler;
 
-@Parameterized
 public class CommentRenormalizerTest
 {
     private LexicalHandler lexicalHandler = mock( LexicalHandler.class );
 
-    @Parameter
-    private String lineSeparator;
-
-    @Parameters
-    public static Collection<Object[]> data() {
-        return Arrays.asList(new Object[][] {
-                 { "\n" },
-                 { "\r\n" },
-                 { "\r" }
-           });
-    }
-
-    @Test
-    public void singleLine()
+    @ParameterizedTest
+    @ValueSource(strings = {"\n", "\r\n", "\r" })
+    public void singleLine(String lineSeparator)
         throws Exception
     {
         CommentRenormalizer commentRenormalizer = new CommentRenormalizer( lexicalHandler, lineSeparator );
@@ -61,8 +45,9 @@ public class CommentRenormalizerTest
         verify( lexicalHandler ).comment( ch, 0, ch.length );
     }
 
-    @Test
-    public void multiLine()
+    @ParameterizedTest
+    @ValueSource(strings = {"\n", "\r\n", "\r" })
+    public void multiLine(String lineSeparator)
         throws Exception
     {
         CommentRenormalizer commentRenormalizer = new CommentRenormalizer( lexicalHandler, lineSeparator );


[maven] 09/22: Break the importDependencyManagement method into smaller methods

Posted by rf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a commit to branch MNG-7063
in repository https://gitbox.apache.org/repos/asf/maven.git

commit d0873d0a02910c18a5f9b3c551414efcd0939ffa
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Thu Nov 26 17:57:21 2020 +0100

    Break the importDependencyManagement method into smaller methods
---
 .../maven/model/building/DefaultModelBuilder.java  | 261 +++++++++++----------
 1 file changed, 141 insertions(+), 120 deletions(-)

diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
index bc94607..9d4a419 100644
--- a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
+++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
@@ -1342,7 +1342,6 @@ public class DefaultModelBuilder
         return superPomProvider.getSuperModel( "4.0.0" ).clone();
     }
 
-    @SuppressWarnings( "checkstyle:methodlength" )
     private void importDependencyManagement( Model model, ModelBuildingRequest request,
                                              DefaultModelProblemCollector problems, Collection<String> importIds )
     {
@@ -1357,11 +1356,6 @@ public class DefaultModelBuilder
 
         importIds.add( importing );
 
-        final WorkspaceModelResolver workspaceResolver = request.getWorkspaceModelResolver();
-        final ModelResolver modelResolver = request.getModelResolver();
-
-        ModelBuildingRequest importRequest = null;
-
         List<DependencyManagement> importMgmts = null;
 
         for ( Iterator<Dependency> it = depMgmt.getDependencies().iterator(); it.hasNext(); )
@@ -1375,153 +1369,180 @@ public class DefaultModelBuilder
 
             it.remove();
 
-            String groupId = dependency.getGroupId();
-            String artifactId = dependency.getArtifactId();
-            String version = dependency.getVersion();
+            DependencyManagement importMgmt = loadDependencyManagement( model, request, problems,
+                                                                        dependency, importIds );
 
-            if ( groupId == null || groupId.length() <= 0 )
+            if ( importMgmt != null )
             {
-                problems.add( new ModelProblemCollectorRequest( Severity.ERROR, Version.BASE )
+                if ( importMgmts == null )
+                {
+                    importMgmts = new ArrayList<>();
+                }
+
+                importMgmts.add( importMgmt );
+            }
+        }
+
+        importIds.remove( importing );
+
+        dependencyManagementImporter.importManagement( model, importMgmts, request, problems );
+    }
+
+    private DependencyManagement loadDependencyManagement( Model model, ModelBuildingRequest request,
+                                                           DefaultModelProblemCollector problems,
+                                                           Dependency dependency,
+                                                           Collection<String> importIds )
+    {
+        String groupId = dependency.getGroupId();
+        String artifactId = dependency.getArtifactId();
+        String version = dependency.getVersion();
+
+        if ( groupId == null || groupId.length() <= 0 )
+        {
+            problems.add( new ModelProblemCollectorRequest( Severity.ERROR, Version.BASE )
                     .setMessage( "'dependencyManagement.dependencies.dependency.groupId' for "
                                      + dependency.getManagementKey() + " is missing." )
                     .setLocation( dependency.getLocation( "" ) ) );
-                continue;
-            }
-            if ( artifactId == null || artifactId.length() <= 0 )
-            {
-                problems.add( new ModelProblemCollectorRequest( Severity.ERROR, Version.BASE )
+            return null;
+        }
+        if ( artifactId == null || artifactId.length() <= 0 )
+        {
+            problems.add( new ModelProblemCollectorRequest( Severity.ERROR, Version.BASE )
                     .setMessage( "'dependencyManagement.dependencies.dependency.artifactId' for "
                                      + dependency.getManagementKey() + " is missing." )
                     .setLocation( dependency.getLocation( "" ) ) );
-                continue;
-            }
-            if ( version == null || version.length() <= 0 )
-            {
-                problems.add( new ModelProblemCollectorRequest( Severity.ERROR, Version.BASE )
+            return null;
+        }
+        if ( version == null || version.length() <= 0 )
+        {
+            problems.add( new ModelProblemCollectorRequest( Severity.ERROR, Version.BASE )
                     .setMessage( "'dependencyManagement.dependencies.dependency.version' for "
                                      + dependency.getManagementKey() + " is missing." )
                     .setLocation( dependency.getLocation( "" ) ) );
-                continue;
-            }
+            return null;
+        }
 
-            String imported = groupId + ':' + artifactId + ':' + version;
+        String imported = groupId + ':' + artifactId + ':' + version;
 
-            if ( importIds.contains( imported ) )
+        if ( importIds.contains( imported ) )
+        {
+            String message = "The dependencies of type=pom and with scope=import form a cycle: ";
+            for ( String modelId : importIds )
             {
-                String message = "The dependencies of type=pom and with scope=import form a cycle: ";
-                for ( String modelId : importIds )
-                {
-                    message += modelId + " -> ";
-                }
-                message += imported;
-                problems.add( new ModelProblemCollectorRequest( Severity.ERROR, Version.BASE ).setMessage( message ) );
-
-                continue;
+                message += modelId + " -> ";
             }
+            message += imported;
+            problems.add( new ModelProblemCollectorRequest( Severity.ERROR, Version.BASE ).setMessage( message ) );
 
-            DependencyManagement importMgmt = fromCache( request.getModelCache(), groupId, artifactId, version,
-                                                        ModelCacheTag.IMPORT );
+            return null;
+        }
 
-            if ( importMgmt == null )
+        DependencyManagement importMgmt = fromCache( request.getModelCache(), groupId, artifactId, version,
+                                                    ModelCacheTag.IMPORT );
+        if ( importMgmt == null )
+        {
+            importMgmt = doLoadDependencyManagement( model, request, problems, dependency,
+                                                     groupId, artifactId, version, importIds );
+            if ( importMgmt != null )
             {
-                if ( workspaceResolver == null && modelResolver == null )
-                {
-                    throw new NullPointerException( String.format(
-                        "request.workspaceModelResolver and request.modelResolver cannot be null"
-                        + " (parent POM %s and POM %s)",
-                        ModelProblemUtils.toId( groupId, artifactId, version ),
-                        ModelProblemUtils.toSourceHint( model ) ) );
-                }
-
-                Model importModel = null;
-                if ( workspaceResolver != null )
-                {
-                    try
-                    {
-                        importModel = workspaceResolver.resolveEffectiveModel( groupId, artifactId, version );
-                    }
-                    catch ( UnresolvableModelException e )
-                    {
-                        problems.add( new ModelProblemCollectorRequest( Severity.FATAL, Version.BASE )
-                            .setMessage( e.getMessage() ).setException( e ) );
-                        continue;
-                    }
-                }
-
-                // no workspace resolver or workspace resolver returned null (i.e. model not in workspace)
-                if ( importModel == null )
-                {
-                    final ModelSource importSource;
-                    try
-                    {
-                        importSource = modelResolver.resolveModel( dependency );
-                    }
-                    catch ( UnresolvableModelException e )
-                    {
-                        StringBuilder buffer = new StringBuilder( 256 );
-                        buffer.append( "Non-resolvable import POM" );
-                        if ( !containsCoordinates( e.getMessage(), groupId, artifactId, version ) )
-                        {
-                            buffer.append( ' ' ).append( ModelProblemUtils.toId( groupId, artifactId, version ) );
-                        }
-                        buffer.append( ": " ).append( e.getMessage() );
-
-                        problems.add( new ModelProblemCollectorRequest( Severity.ERROR, Version.BASE )
-                            .setMessage( buffer.toString() ).setLocation( dependency.getLocation( "" ) )
-                            .setException( e ) );
-                        continue;
-                    }
-
-                    if ( importRequest == null )
-                    {
-                        importRequest = new DefaultModelBuildingRequest();
-                        importRequest.setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL );
-                        importRequest.setModelCache( request.getModelCache() );
-                        importRequest.setSystemProperties( request.getSystemProperties() );
-                        importRequest.setUserProperties( request.getUserProperties() );
-                        importRequest.setLocationTracking( request.isLocationTracking() );
-                    }
-
-                    importRequest.setModelSource( importSource );
-                    importRequest.setModelResolver( modelResolver.newCopy() );
-
-                    final ModelBuildingResult importResult;
-                    try
-                    {
-                        importResult = build( importRequest, importIds );
-                    }
-                    catch ( ModelBuildingException e )
-                    {
-                        problems.addAll( e.getProblems() );
-                        continue;
-                    }
+                intoCache( request.getModelCache(), groupId, artifactId, version, ModelCacheTag.IMPORT, importMgmt );
+            }
+        }
 
-                    problems.addAll( importResult.getProblems() );
+        return importMgmt;
+    }
 
-                    importModel = importResult.getEffectiveModel();
-                }
+    @SuppressWarnings( "checkstyle:parameternumber" )
+    private DependencyManagement doLoadDependencyManagement( Model model, ModelBuildingRequest request,
+                                                             DefaultModelProblemCollector problems,
+                                                             Dependency dependency,
+                                                             String groupId,
+                                                             String artifactId,
+                                                             String version,
+                                                             Collection<String> importIds )
+    {
+        DependencyManagement importMgmt;
+        final WorkspaceModelResolver workspaceResolver = request.getWorkspaceModelResolver();
+        final ModelResolver modelResolver = request.getModelResolver();
+        if ( workspaceResolver == null && modelResolver == null )
+        {
+            throw new NullPointerException( String.format(
+                "request.workspaceModelResolver and request.modelResolver cannot be null (parent POM %s and POM %s)",
+                ModelProblemUtils.toId( groupId, artifactId, version ),
+                ModelProblemUtils.toSourceHint( model ) ) );
+        }
 
-                importMgmt = importModel.getDependencyManagement();
+        Model importModel = null;
+        if ( workspaceResolver != null )
+        {
+            try
+            {
+                importModel = workspaceResolver.resolveEffectiveModel( groupId, artifactId, version );
+            }
+            catch ( UnresolvableModelException e )
+            {
+                problems.add( new ModelProblemCollectorRequest( Severity.FATAL, Version.BASE )
+                    .setMessage( e.getMessage() ).setException( e ) );
+                return null;
+            }
+        }
 
-                if ( importMgmt == null )
+        // no workspace resolver or workspace resolver returned null (i.e. model not in workspace)
+        if ( importModel == null )
+        {
+            final ModelSource importSource;
+            try
+            {
+                importSource = modelResolver.resolveModel( dependency );
+            }
+            catch ( UnresolvableModelException e )
+            {
+                StringBuilder buffer = new StringBuilder( 256 );
+                buffer.append( "Non-resolvable import POM" );
+                if ( !containsCoordinates( e.getMessage(), groupId, artifactId, version ) )
                 {
-                    importMgmt = new DependencyManagement();
+                    buffer.append( ' ' ).append( ModelProblemUtils.toId( groupId, artifactId, version ) );
                 }
+                buffer.append( ": " ).append( e.getMessage() );
 
-                intoCache( request.getModelCache(), groupId, artifactId, version, ModelCacheTag.IMPORT, importMgmt );
+                problems.add( new ModelProblemCollectorRequest( Severity.ERROR, Version.BASE )
+                    .setMessage( buffer.toString() ).setLocation( dependency.getLocation( "" ) )
+                    .setException( e ) );
+                return null;
             }
 
-            if ( importMgmts == null )
+            ModelBuildingRequest importRequest = new DefaultModelBuildingRequest();
+            importRequest.setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL );
+            importRequest.setModelCache( request.getModelCache() );
+            importRequest.setSystemProperties( request.getSystemProperties() );
+            importRequest.setUserProperties( request.getUserProperties() );
+            importRequest.setLocationTracking( request.isLocationTracking() );
+            importRequest.setModelSource( importSource );
+            importRequest.setModelResolver( modelResolver.newCopy() );
+
+            final ModelBuildingResult importResult;
+            try
+            {
+                importResult = build( importRequest, importIds );
+            }
+            catch ( ModelBuildingException e )
             {
-                importMgmts = new ArrayList<>();
+                problems.addAll( e.getProblems() );
+                return null;
             }
 
-            importMgmts.add( importMgmt );
+            problems.addAll( importResult.getProblems() );
+
+            importModel = importResult.getEffectiveModel();
         }
 
-        importIds.remove( importing );
+        importMgmt = importModel.getDependencyManagement();
 
-        dependencyManagementImporter.importManagement( model, importMgmts, request, problems );
+        if ( importMgmt == null )
+        {
+            importMgmt = new DependencyManagement();
+        }
+        return importMgmt;
     }
 
     private <T> void intoCache( ModelCache modelCache, String groupId, String artifactId, String version,


[maven] 02/22: Merge branch 'master' of https://gitbox.apache.org/repos/asf/maven

Posted by rf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a commit to branch MNG-7063
in repository https://gitbox.apache.org/repos/asf/maven.git

commit 1f22b55f1c81138e32438f9bcf36be9f4e6a3d33
Merge: 7f517ed ab20190
Author: rfscholte <rf...@apache.org>
AuthorDate: Fri Feb 12 13:31:15 2021 +0100

    Merge branch 'master' of https://gitbox.apache.org/repos/asf/maven

 maven-wrapper/pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


[maven] 01/22: Make sure ITs can still be used to verify older Maven versions

Posted by rf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a commit to branch MNG-7063
in repository https://gitbox.apache.org/repos/asf/maven.git

commit 7f517ed320c8a0f9729893e147d7d97cfcb91652
Author: rfscholte <rf...@apache.org>
AuthorDate: Fri Feb 5 11:31:28 2021 +0100

    Make sure ITs can still be used to verify older Maven versions
---
 Jenkinsfile | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/Jenkinsfile b/Jenkinsfile
index ba9c3c8..5996152 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -127,6 +127,47 @@ for (String os in runITsOses) {
                 }
             }
         }
+		
+		// Verify that ITs can still be used for older Maven versions
+		String m3 = '3.6.3'
+		String stageId = "${os}-jdk${buildJdk}-${m3}"
+        String stageLabel = "Run ITs ${os.capitalize()} Java ${buildJdk} Maven ${m3}"
+        runITsTasks[stageId] = {
+            node(jenkinsEnv.nodeSelection(osLabel)) {
+                stage("${stageLabel}") {
+                    echo "NODE_NAME = ${env.NODE_NAME}"
+                    // on Windows, need a short path or we hit 256 character limit for paths
+                    // using EXECUTOR_NUMBER guarantees that concurrent builds on same agent
+                    // will not trample each other plus workaround for JENKINS-52657
+                    dir(isUnix() ? 'test' : "c:\\mvn-it-${EXECUTOR_NUMBER}.tmp") {
+                        def WORK_DIR=pwd()
+                        checkout tests
+                        if (isUnix()) {
+                            sh "rm -rvf $WORK_DIR/dists $WORK_DIR/it-local-repo"
+                        } else {
+                            bat "if exist it-local-repo rmdir /s /q it-local-repo"
+                            bat "if exist dists         rmdir /s /q dists"
+                        }
+                        try {
+                            withMaven(jdk: jdkName, maven: mvnName, mavenLocalRepo:"${WORK_DIR}/it-local-repo", options:[
+                                junitPublisher(ignoreAttachments: false)
+                            ]) {
+                                String cmd = "${runITscommand} -DmavenDistro=$WORK_DIR/dists/apache-maven-bin.zip -Dmaven.test.failure.ignore=true -DmavenVersion={m3}"
+                                if (isUnix()) {
+                                    sh "${cmd}"
+                                } else {
+                                    bat "${cmd}"
+                                }
+                            }
+                        } finally {
+                            archiveDirs(stageId, ['core-it-suite-logs':'core-it-suite/target/test-classes',
+                                                  'core-it-suite-reports':'core-it-suite/target/surefire-reports'])
+                            deleteDir() // clean up after ourselves to reduce disk space
+                        }
+                    }
+                }
+            }
+        }
     }
 }
 


[maven] 08/22: Move the ModelCacheTag usage to the ModelCache interface

Posted by rf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a commit to branch MNG-7063
in repository https://gitbox.apache.org/repos/asf/maven.git

commit d28ca061acde597bc951a6e3cdabc08ff2ff378a
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Fri Nov 27 08:23:06 2020 +0100

    Move the ModelCacheTag usage to the ModelCache interface
---
 .../maven/model/building/DefaultModelBuilder.java  | 16 ++-----
 .../apache/maven/model/building/ModelCache.java    | 56 ++++++++++++++++++++++
 2 files changed, 60 insertions(+), 12 deletions(-)

diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
index f66ae86..bc94607 100644
--- a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
+++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
@@ -1529,7 +1529,7 @@ public class DefaultModelBuilder
     {
         if ( modelCache != null )
         {
-            modelCache.put( groupId, artifactId, version, tag.getName(), tag.intoCache( data ) );
+            modelCache.put( groupId, artifactId, version, tag, data );
         }
     }
 
@@ -1537,7 +1537,7 @@ public class DefaultModelBuilder
     {
         if ( modelCache != null )
         {
-            modelCache.put( source, tag.getName(), tag.intoCache( data ) );
+            modelCache.put( source, tag, data );
         }
     }
 
@@ -1546,11 +1546,7 @@ public class DefaultModelBuilder
     {
         if ( modelCache != null )
         {
-            Object data = modelCache.get( groupId, artifactId, version, tag.getName() );
-            if ( data != null )
-            {
-                return tag.fromCache( tag.getType().cast( data ) );
-            }
+            return modelCache.get( groupId, artifactId, version, tag );
         }
         return null;
     }
@@ -1559,11 +1555,7 @@ public class DefaultModelBuilder
     {
         if ( modelCache != null )
         {
-            Object data = modelCache.get( source, tag.getName() );
-            if ( data != null )
-            {
-                return tag.fromCache( tag.getType().cast( data ) );
-            }
+            return modelCache.get( source, tag );
         }
         return null;
     }
diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelCache.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelCache.java
index 3962fe0..b44e8a4 100644
--- a/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelCache.java
+++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelCache.java
@@ -82,4 +82,60 @@ public interface ModelCache
      */
     Object get( String groupId, String artifactId, String version, String tag );
 
+    /**
+     * Puts the specified data into the cache.
+     *
+     * @param path The path of the cache record, must not be {@code null}.
+     * @param tag The tag of the cache record, must not be {@code null}.
+     * @param data The data to store in the cache, must not be {@code null}.
+     * @since 3.7.0
+     */
+    default <T> void put( Source path, ModelCacheTag<T> tag, T data )
+    {
+        put( path, tag.getName(), tag.intoCache( data ) );
+    }
+
+    /**
+     * Gets the specified data from the cache.
+     *
+     * @param path The path of the cache record, must not be {@code null}.
+     * @param tag The tag of the cache record, must not be {@code null}.
+     * @return The requested data or {@code null} if none was present in the cache.
+     * @since 3.7.0
+     */
+    default <T> T get( Source path, ModelCacheTag<T> tag )
+    {
+        Object obj = get( path, tag.getName() );
+        return ( obj != null ) ? tag.fromCache( tag.getType().cast( obj ) ) : null;
+    }
+
+    /**
+     * Puts the specified data into the cache.
+     *
+     * @param groupId The group id of the cache record, must not be {@code null}.
+     * @param artifactId The artifact id of the cache record, must not be {@code null}.
+     * @param version The version of the cache record, must not be {@code null}.
+     * @param tag The tag of the cache record, must not be {@code null}.
+     * @param data The data to store in the cache, must not be {@code null}.
+     */
+    default <T> void put( String groupId, String artifactId, String version, ModelCacheTag<T> tag, T data )
+    {
+        put( groupId, artifactId, version, tag.getName(), tag.intoCache( data ) );
+    }
+
+    /**
+     * Gets the specified data from the cache.
+     *
+     * @param groupId The group id of the cache record, must not be {@code null}.
+     * @param artifactId The artifact id of the cache record, must not be {@code null}.
+     * @param version The version of the cache record, must not be {@code null}.
+     * @param tag The tag of the cache record, must not be {@code null}.
+     * @return The requested data or {@code null} if none was present in the cache.
+     */
+    default <T> T get( String groupId, String artifactId, String version, ModelCacheTag<T> tag )
+    {
+        Object obj = get( groupId, artifactId, version, tag.getName() );
+        return ( obj != null ) ? tag.fromCache( tag.getType().cast( obj ) ) : null;
+    }
+
 }


[maven] 04/22: Use JUnit 5 extension

Posted by rf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a commit to branch MNG-7063
in repository https://gitbox.apache.org/repos/asf/maven.git

commit 9905ee36e3c61de1a9fcaa7c82143727aaac6c23
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Mon Jan 18 15:24:31 2021 +0100

    Use JUnit 5 extension
---
 .../AbstractArtifactComponentTestCase.java         | 17 ++++++---
 .../artifact/deployer/ArtifactDeployerTest.java    |  1 +
 .../factory/DefaultArtifactFactoryTest.java        |  4 +-
 .../artifact/installer/ArtifactInstallerTest.java  |  2 +
 .../artifact/resolver/ArtifactResolverTest.java    | 10 -----
 .../resolver/DefaultArtifactResolverTest.java      | 11 +-----
 .../transform/TransformationManagerTest.java       |  4 +-
 .../manager/DefaultProfileManagerTest.java         | 22 +++++++++--
 .../project/AbstractMavenProjectTestCase.java      | 38 +++++++------------
 .../apache/maven/project/ProjectClasspathTest.java | 12 ++----
 .../AbstractProjectInheritanceTestCase.java        |  2 +
 .../repository/LegacyRepositorySystemTest.java     | 12 ++++--
 .../maven/repository/MirrorProcessorTest.java      |  4 +-
 .../repository/legacy/DefaultWagonManagerTest.java |  6 ++-
 .../legacy/LegacyRepositorySystemTest.java         |  4 +-
 .../resolver/DefaultArtifactCollectorTest.java     |  7 +---
 .../conflict/AbstractConflictResolverTest.java     | 29 ++++----------
 .../DefaultClasspathTransformationTest.java        |  8 +---
 .../metadata/DefaultGraphConflictResolverTest.java |  8 +---
 .../maven/AbstractCoreMavenComponentTestCase.java  | 32 +++++++---------
 .../java/org/apache/maven/DefaultMavenTest.java    |  2 +-
 .../maven/MavenLifecycleParticipantTest.java       |  6 ---
 .../maven/ProjectDependenciesResolverTest.java     |  1 +
 .../artifact/handler/ArtifactHandlerTest.java      | 14 +++++--
 .../DefaultMavenExecutionRequestPopulatorTest.java |  5 +--
 .../maven/lifecycle/DefaultLifecyclesTest.java     |  5 +--
 .../maven/lifecycle/LifecycleExecutorTest.java     |  8 ++--
 .../PluginParameterExpressionEvaluatorTest.java    |  1 +
 .../project/AbstractMavenProjectTestCase.java      | 24 ++++++------
 .../project/DefaultMavenProjectBuilderTest.java    |  6 +--
 .../apache/maven/project/PomConstructionTest.java  | 15 ++------
 .../apache/maven/project/ProjectBuilderTest.java   | 20 +++++-----
 .../maven/project/ProjectModelResolverTest.java    |  5 ++-
 .../project/artifact/MavenMetadataSourceTest.java  | 44 ++++++++++++----------
 .../internal/DefaultRuntimeInformationTest.java    | 13 +------
 .../settings/PomConstructionWithSettingsTest.java  |  6 +--
 .../internal/AbstractRepositoryTestCase.java       | 18 ++++++---
 .../DefaultArtifactDescriptorReaderTest.java       |  2 +-
 .../internal/DefaultModelResolverTest.java         |  4 +-
 .../{PlexusTestCase.java => PlexusExtension.java}  | 42 ++++++++++++++-------
 .../java/org/apache/maven/test/PlexusTest.java     | 38 +++++++++++++++++++
 41 files changed, 264 insertions(+), 248 deletions(-)

diff --git a/maven-compat/src/test/java/org/apache/maven/artifact/AbstractArtifactComponentTestCase.java b/maven-compat/src/test/java/org/apache/maven/artifact/AbstractArtifactComponentTestCase.java
index 146ec68..0c6c062 100644
--- a/maven-compat/src/test/java/org/apache/maven/artifact/AbstractArtifactComponentTestCase.java
+++ b/maven-compat/src/test/java/org/apache/maven/artifact/AbstractArtifactComponentTestCase.java
@@ -32,7 +32,7 @@ import java.util.List;
 import javax.inject.Inject;
 import javax.inject.Named;
 
-import org.apache.maven.test.PlexusTestCase;
+import org.apache.maven.test.PlexusTest;
 import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
@@ -42,6 +42,7 @@ import org.apache.maven.execution.DefaultMavenExecutionResult;
 import org.apache.maven.execution.MavenSession;
 import org.apache.maven.plugin.LegacySupport;
 import org.apache.maven.repository.legacy.repository.ArtifactRepositoryFactory;
+import org.codehaus.plexus.PlexusContainer;
 import org.eclipse.aether.DefaultRepositorySystemSession;
 import org.eclipse.aether.RepositorySystemSession;
 import org.eclipse.aether.collection.DependencyGraphTransformer;
@@ -67,14 +68,15 @@ import org.eclipse.aether.util.repository.SimpleArtifactDescriptorPolicy;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 
+import static org.apache.maven.test.PlexusExtension.getBasedir;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 /**
  * @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
  */
-public abstract class AbstractArtifactComponentTestCase
-    extends PlexusTestCase
+@PlexusTest
+public abstract class AbstractArtifactComponentTestCase //extends PlexusTestCase
 {
     @Inject
     protected ArtifactFactory artifactFactory;
@@ -88,12 +90,17 @@ public abstract class AbstractArtifactComponentTestCase
     @Inject @Named( "default" )
     ArtifactRepositoryLayout repoLayout;
 
+    @Inject
+    PlexusContainer container;
+
+    public PlexusContainer getContainer() {
+        return container;
+    }
+
     @BeforeEach
     public void setUp()
         throws Exception
     {
-        super.setUp();
-
         RepositorySystemSession repoSession = initRepoSession();
         MavenSession session = new MavenSession( getContainer(), repoSession, new DefaultMavenExecutionRequest(),
                                                  new DefaultMavenExecutionResult() );
diff --git a/maven-compat/src/test/java/org/apache/maven/artifact/deployer/ArtifactDeployerTest.java b/maven-compat/src/test/java/org/apache/maven/artifact/deployer/ArtifactDeployerTest.java
index 05191ae..e321e45 100644
--- a/maven-compat/src/test/java/org/apache/maven/artifact/deployer/ArtifactDeployerTest.java
+++ b/maven-compat/src/test/java/org/apache/maven/artifact/deployer/ArtifactDeployerTest.java
@@ -28,6 +28,7 @@ import org.codehaus.plexus.util.FileUtils;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
+import static org.apache.maven.test.PlexusExtension.getBasedir;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
diff --git a/maven-compat/src/test/java/org/apache/maven/artifact/factory/DefaultArtifactFactoryTest.java b/maven-compat/src/test/java/org/apache/maven/artifact/factory/DefaultArtifactFactoryTest.java
index 6dcf99a..517bc71 100644
--- a/maven-compat/src/test/java/org/apache/maven/artifact/factory/DefaultArtifactFactoryTest.java
+++ b/maven-compat/src/test/java/org/apache/maven/artifact/factory/DefaultArtifactFactoryTest.java
@@ -21,15 +21,15 @@ package org.apache.maven.artifact.factory;
 
 import javax.inject.Inject;
 
-import org.apache.maven.test.PlexusTestCase;
+import org.apache.maven.test.PlexusTest;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.versioning.VersionRange;
 import org.junit.jupiter.api.Test;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
+@PlexusTest
 public class DefaultArtifactFactoryTest
-    extends PlexusTestCase
 {
 
     @Inject
diff --git a/maven-compat/src/test/java/org/apache/maven/artifact/installer/ArtifactInstallerTest.java b/maven-compat/src/test/java/org/apache/maven/artifact/installer/ArtifactInstallerTest.java
index 695c5cc..0010d4f 100644
--- a/maven-compat/src/test/java/org/apache/maven/artifact/installer/ArtifactInstallerTest.java
+++ b/maven-compat/src/test/java/org/apache/maven/artifact/installer/ArtifactInstallerTest.java
@@ -28,6 +28,8 @@ import org.junit.jupiter.api.Test;
 
 import javax.inject.Inject;
 
+import static org.apache.maven.test.PlexusExtension.getBasedir;
+
 /**
  * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
  */
diff --git a/maven-compat/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolverTest.java b/maven-compat/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolverTest.java
index d621d90..6aa0652 100644
--- a/maven-compat/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolverTest.java
+++ b/maven-compat/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolverTest.java
@@ -34,7 +34,6 @@ import org.apache.maven.artifact.metadata.ResolutionGroup;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.artifact.versioning.ArtifactVersion;
 import org.apache.maven.repository.legacy.metadata.MetadataResolutionRequest;
-import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
@@ -71,15 +70,6 @@ public class ArtifactResolverTest
         projectArtifact = createLocalArtifact( "project", "3.0" );
     }
 
-    @AfterEach
-    @Override
-    public void tearDown()
-        throws Exception
-    {
-        projectArtifact = null;
-        super.tearDown();
-    }
-
     @Override
     protected String component()
     {
diff --git a/maven-compat/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactResolverTest.java b/maven-compat/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactResolverTest.java
index fdd5f62..23e93be 100644
--- a/maven-compat/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactResolverTest.java
+++ b/maven-compat/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactResolverTest.java
@@ -49,15 +49,6 @@ public class DefaultArtifactResolverTest
         projectArtifact = createLocalArtifact( "project", "3.0" );
     }
 
-    @AfterEach
-    @Override
-    public void tearDown()
-        throws Exception
-    {
-        projectArtifact = null;
-        super.tearDown();
-    }
-
     @Override
     protected String component()
     {
@@ -114,6 +105,6 @@ public class DefaultArtifactResolverTest
     public void testLookup()
         throws Exception
     {
-        ArtifactResolver resolver = lookup( ArtifactResolver.class, "default" );
+        ArtifactResolver resolver = getContainer().lookup( ArtifactResolver.class, "default" );
     }
 }
diff --git a/maven-compat/src/test/java/org/apache/maven/artifact/transform/TransformationManagerTest.java b/maven-compat/src/test/java/org/apache/maven/artifact/transform/TransformationManagerTest.java
index 5c1ae2d..08e1055 100644
--- a/maven-compat/src/test/java/org/apache/maven/artifact/transform/TransformationManagerTest.java
+++ b/maven-compat/src/test/java/org/apache/maven/artifact/transform/TransformationManagerTest.java
@@ -22,7 +22,7 @@ import org.apache.maven.repository.legacy.resolver.transform.ArtifactTransformat
 import org.apache.maven.repository.legacy.resolver.transform.LatestArtifactTransformation;
 import org.apache.maven.repository.legacy.resolver.transform.ReleaseArtifactTransformation;
 import org.apache.maven.repository.legacy.resolver.transform.SnapshotTransformation;
-import org.apache.maven.test.PlexusTestCase;
+import org.apache.maven.test.PlexusTest;
 import org.junit.jupiter.api.Test;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -31,8 +31,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
 import javax.inject.Inject;
 
 /** @author Jason van Zyl */
+@PlexusTest
 public class TransformationManagerTest
-    extends PlexusTestCase
 {
     @Inject
     ArtifactTransformationManager tm;
diff --git a/maven-compat/src/test/java/org/apache/maven/profiles/manager/DefaultProfileManagerTest.java b/maven-compat/src/test/java/org/apache/maven/profiles/manager/DefaultProfileManagerTest.java
index 442493a..5c9dc6b 100644
--- a/maven-compat/src/test/java/org/apache/maven/profiles/manager/DefaultProfileManagerTest.java
+++ b/maven-compat/src/test/java/org/apache/maven/profiles/manager/DefaultProfileManagerTest.java
@@ -22,21 +22,32 @@ package org.apache.maven.profiles.manager;
 import java.util.List;
 import java.util.Properties;
 
-import org.apache.maven.test.PlexusTestCase;
+import javax.inject.Inject;
+
+import org.apache.maven.test.PlexusTest;
 import org.apache.maven.model.Activation;
 import org.apache.maven.model.ActivationProperty;
 import org.apache.maven.model.Profile;
 import org.apache.maven.profiles.DefaultProfileManager;
 import org.apache.maven.profiles.ProfileManager;
+import org.codehaus.plexus.PlexusContainer;
+import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 
+@PlexusTest
 public class DefaultProfileManagerTest
-    extends PlexusTestCase
 {
 
+    @Inject
+    PlexusContainer container;
+
+    protected PlexusContainer getContainer() {
+        return container;
+    }
+
     @Test
     public void testShouldActivateDefaultProfile()
         throws Exception
@@ -201,10 +212,13 @@ public class DefaultProfileManagerTest
         assertNotNull( active );
         assertEquals( 0, active.size() );
     }
-/*
+
+    @Test
+    @Disabled
     public void testOsActivationProfile()
         throws Exception
     {
+        /*
         Profile osActivated = new Profile();
         osActivated.setId( "os-profile" );
 
@@ -229,7 +243,7 @@ public class DefaultProfileManagerTest
 
         assertNotNull( active );
         assertEquals( 1, active.size() );
+        */
     }
-    */
 
 }
diff --git a/maven-compat/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java b/maven-compat/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java
index 338cffa..52f8dfe 100644
--- a/maven-compat/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java
+++ b/maven-compat/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java
@@ -24,13 +24,14 @@ import java.util.Arrays;
 
 import javax.inject.Inject;
 
-import org.apache.maven.test.PlexusTestCase;
+import org.apache.maven.test.PlexusTest;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
 import org.apache.maven.model.building.ModelBuildingException;
 import org.apache.maven.model.building.ModelProblem;
 import org.apache.maven.repository.RepositorySystem;
 import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
+import org.codehaus.plexus.PlexusContainer;
 import org.eclipse.aether.DefaultRepositorySystemSession;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
@@ -40,54 +41,41 @@ import static org.junit.jupiter.api.Assertions.fail;
 /**
  * @author Jason van Zyl
  */
+@PlexusTest
 public abstract class AbstractMavenProjectTestCase
-    extends PlexusTestCase
 {
     protected ProjectBuilder projectBuilder;
 
     @Inject
     protected RepositorySystem repositorySystem;
 
-    @Override
+    @Inject
+    protected PlexusContainer container;
+
+    public PlexusContainer getContainer() {
+        return container;
+    }
+
     @BeforeEach
     public void setUp()
         throws Exception
     {
-        super.setUp();
-
         if ( getContainer().hasComponent( ProjectBuilder.class, "test" ) )
         {
-            projectBuilder = lookup( ProjectBuilder.class, "test" );
+            projectBuilder = getContainer().lookup( ProjectBuilder.class, "test" );
         }
         else
         {
             // default over to the main project builder...
-            projectBuilder = lookup( ProjectBuilder.class );
+            projectBuilder = getContainer().lookup( ProjectBuilder.class );
         }
     }
 
-    @AfterEach
-    public void tearDown()
-        throws Exception
-    {
-        projectBuilder = null;
-
-        super.tearDown();
-    }
-
     protected ProjectBuilder getProjectBuilder()
     {
         return projectBuilder;
     }
 
-    @Override
-    protected String getCustomConfigurationName()
-    {
-        String name = AbstractMavenProjectTestCase.class.getName().replace( '.', '/' ) + ".xml";
-        System.out.println( name );
-        return name;
-    }
-
     // ----------------------------------------------------------------------
     // Local repository
     // ----------------------------------------------------------------------
@@ -118,7 +106,7 @@ public abstract class AbstractMavenProjectTestCase
     protected ArtifactRepository getLocalRepository()
         throws Exception
     {
-        ArtifactRepositoryLayout repoLayout = lookup( ArtifactRepositoryLayout.class );
+        ArtifactRepositoryLayout repoLayout = getContainer().lookup( ArtifactRepositoryLayout.class );
 
         ArtifactRepository r = repositorySystem.createArtifactRepository( "local", "file://" + getLocalRepositoryPath().getAbsolutePath(), repoLayout, null, null );
 
diff --git a/maven-compat/src/test/java/org/apache/maven/project/ProjectClasspathTest.java b/maven-compat/src/test/java/org/apache/maven/project/ProjectClasspathTest.java
index 0cc449f..a2119ce 100644
--- a/maven-compat/src/test/java/org/apache/maven/project/ProjectClasspathTest.java
+++ b/maven-compat/src/test/java/org/apache/maven/project/ProjectClasspathTest.java
@@ -44,17 +44,11 @@ public class ProjectClasspathTest
     {
         super.setUp();
 
-        ArtifactResolver resolver = lookup( ArtifactResolver.class, "classpath" );
-        DefaultArtifactDescriptorReader pomReader = (DefaultArtifactDescriptorReader)lookup(ArtifactDescriptorReader.class);
+        ArtifactResolver resolver = getContainer().lookup( ArtifactResolver.class, "classpath" );
+        DefaultArtifactDescriptorReader pomReader = (DefaultArtifactDescriptorReader)getContainer().lookup(ArtifactDescriptorReader.class);
         pomReader.setArtifactResolver( resolver );
 
-        projectBuilder = lookup( ProjectBuilder.class, "classpath" );
-    }
-
-    @Override
-    protected String getCustomConfigurationName()
-    {
-        return null;
+        projectBuilder = getContainer().lookup( ProjectBuilder.class, "classpath" );
     }
 
     @Test
diff --git a/maven-compat/src/test/java/org/apache/maven/project/inheritance/AbstractProjectInheritanceTestCase.java b/maven-compat/src/test/java/org/apache/maven/project/inheritance/AbstractProjectInheritanceTestCase.java
index 93358ec..2538abc 100644
--- a/maven-compat/src/test/java/org/apache/maven/project/inheritance/AbstractProjectInheritanceTestCase.java
+++ b/maven-compat/src/test/java/org/apache/maven/project/inheritance/AbstractProjectInheritanceTestCase.java
@@ -23,6 +23,8 @@ import java.io.File;
 
 import org.apache.maven.project.AbstractMavenProjectTestCase;
 
+import static org.apache.maven.test.PlexusExtension.getTestFile;
+
 /**
  * @author Jason van Zyl
  */
diff --git a/maven-compat/src/test/java/org/apache/maven/repository/LegacyRepositorySystemTest.java b/maven-compat/src/test/java/org/apache/maven/repository/LegacyRepositorySystemTest.java
index eb56bc8..8505783 100644
--- a/maven-compat/src/test/java/org/apache/maven/repository/LegacyRepositorySystemTest.java
+++ b/maven-compat/src/test/java/org/apache/maven/repository/LegacyRepositorySystemTest.java
@@ -32,7 +32,8 @@ import org.apache.maven.model.Repository;
 import org.apache.maven.model.RepositoryPolicy;
 import org.apache.maven.plugin.LegacySupport;
 import org.apache.maven.repository.legacy.LegacyRepositorySystem;
-import org.apache.maven.test.PlexusTestCase;
+import org.apache.maven.test.PlexusTest;
+import org.codehaus.plexus.PlexusContainer;
 import org.eclipse.aether.DefaultRepositorySystemSession;
 import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory;
 import org.eclipse.aether.repository.LocalRepository;
@@ -40,6 +41,7 @@ import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
+import static org.apache.maven.test.PlexusExtension.getBasedir;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -51,13 +53,15 @@ import javax.inject.Inject;
  *
  * @author Benjamin Bentmann
  */
+@PlexusTest
 public class LegacyRepositorySystemTest
-    extends PlexusTestCase
 {
     @Inject
     private RepositorySystem repositorySystem;
     @Inject
     private ResolutionErrorHandler resolutionErrorHandler;
+    @Inject
+    private PlexusContainer container;
 
     protected List<ArtifactRepository> getRemoteRepositories()
         throws Exception
@@ -110,8 +114,8 @@ public class LegacyRepositorySystemTest
         DefaultRepositorySystemSession session = new DefaultRepositorySystemSession();
         LocalRepository localRepo = new LocalRepository( request.getLocalRepository().getBasedir() );
         session.setLocalRepositoryManager( new SimpleLocalRepositoryManagerFactory().newInstance( session, localRepo ) );
-        LegacySupport legacySupport = lookup( LegacySupport.class );
-        legacySupport.setSession( new MavenSession( getContainer(), session, new DefaultMavenExecutionRequest(),
+        LegacySupport legacySupport = container.lookup( LegacySupport.class );
+        legacySupport.setSession( new MavenSession( container, session, new DefaultMavenExecutionRequest(),
                                                     new DefaultMavenExecutionResult() ) );
 
         ArtifactResolutionResult result = repositorySystem.resolve( request );
diff --git a/maven-compat/src/test/java/org/apache/maven/repository/MirrorProcessorTest.java b/maven-compat/src/test/java/org/apache/maven/repository/MirrorProcessorTest.java
index 443bc44..49277ba 100644
--- a/maven-compat/src/test/java/org/apache/maven/repository/MirrorProcessorTest.java
+++ b/maven-compat/src/test/java/org/apache/maven/repository/MirrorProcessorTest.java
@@ -22,7 +22,7 @@ package org.apache.maven.repository;
 import java.util.Arrays;
 import java.util.List;
 
-import org.apache.maven.test.PlexusTestCase;
+import org.apache.maven.test.PlexusTest;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
 import org.apache.maven.repository.legacy.repository.ArtifactRepositoryFactory;
@@ -38,8 +38,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import javax.inject.Inject;
 
+@PlexusTest
 public class MirrorProcessorTest
-    extends PlexusTestCase
 {
     @Inject
     private DefaultMirrorSelector mirrorSelector;
diff --git a/maven-compat/src/test/java/org/apache/maven/repository/legacy/DefaultWagonManagerTest.java b/maven-compat/src/test/java/org/apache/maven/repository/legacy/DefaultWagonManagerTest.java
index e6177c7..eefe1b5 100644
--- a/maven-compat/src/test/java/org/apache/maven/repository/legacy/DefaultWagonManagerTest.java
+++ b/maven-compat/src/test/java/org/apache/maven/repository/legacy/DefaultWagonManagerTest.java
@@ -34,6 +34,7 @@ import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
 import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
 import org.apache.maven.artifact.versioning.VersionRange;
 import org.apache.maven.repository.legacy.repository.ArtifactRepositoryFactory;
+import org.apache.maven.test.PlexusTest;
 import org.apache.maven.wagon.ResourceDoesNotExistException;
 import org.apache.maven.wagon.TransferFailedException;
 import org.apache.maven.wagon.UnsupportedProtocolException;
@@ -42,13 +43,14 @@ import org.apache.maven.wagon.events.TransferEvent;
 import org.apache.maven.wagon.events.TransferListener;
 import org.apache.maven.wagon.observers.AbstractTransferListener;
 import org.apache.maven.wagon.observers.Debug;
-import org.apache.maven.test.PlexusTestCase;
+import org.codehaus.plexus.PlexusContainer;
 import org.codehaus.plexus.util.FileUtils;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
 
+import static org.apache.maven.test.PlexusExtension.getTestFile;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -61,8 +63,8 @@ import javax.inject.Inject;
 /**
  * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
  */
+@PlexusTest
 public class DefaultWagonManagerTest
-    extends PlexusTestCase
 {
     @Inject
     private WagonManager wagonManager;
diff --git a/maven-compat/src/test/java/org/apache/maven/repository/legacy/LegacyRepositorySystemTest.java b/maven-compat/src/test/java/org/apache/maven/repository/legacy/LegacyRepositorySystemTest.java
index 61f16cc..e2c90b1 100644
--- a/maven-compat/src/test/java/org/apache/maven/repository/legacy/LegacyRepositorySystemTest.java
+++ b/maven-compat/src/test/java/org/apache/maven/repository/legacy/LegacyRepositorySystemTest.java
@@ -22,7 +22,7 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.artifact.repository.Authentication;
 import org.apache.maven.repository.RepositorySystem;
 import org.apache.maven.settings.Server;
-import org.apache.maven.test.PlexusTestCase;
+import org.apache.maven.test.PlexusTest;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
@@ -37,8 +37,8 @@ import javax.inject.Inject;
  *
  * @author Benjamin Bentmann
  */
+@PlexusTest
 public class LegacyRepositorySystemTest
-    extends PlexusTestCase
 {
     @Inject
     private RepositorySystem repositorySystem;
diff --git a/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/DefaultArtifactCollectorTest.java b/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/DefaultArtifactCollectorTest.java
index 0ef67d9..a0aa336 100644
--- a/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/DefaultArtifactCollectorTest.java
+++ b/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/DefaultArtifactCollectorTest.java
@@ -49,7 +49,7 @@ import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException
 import org.apache.maven.artifact.versioning.OverConstrainedVersionException;
 import org.apache.maven.artifact.versioning.VersionRange;
 import org.apache.maven.repository.legacy.metadata.MetadataResolutionRequest;
-import org.apache.maven.test.PlexusTestCase;
+import org.apache.maven.test.PlexusTest;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Disabled;
@@ -65,8 +65,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
  *
  * @author <a href="mailto:brett@apache.org">Brett Porter</a>
  */
+@PlexusTest
 public class DefaultArtifactCollectorTest
-    extends PlexusTestCase
 {
     @Inject
     private LegacyArtifactCollector artifactCollector;
@@ -81,12 +81,9 @@ public class DefaultArtifactCollectorTest
     private static final String GROUP_ID = "test";
 
     @BeforeEach
-    @Override
     public void setUp()
         throws Exception
     {
-        super.setUp();
-
         source = new Source();
 
         projectArtifact = createArtifactSpec( "project", "1.0", null );
diff --git a/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/conflict/AbstractConflictResolverTest.java b/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/conflict/AbstractConflictResolverTest.java
index fbb2531..343e943 100644
--- a/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/conflict/AbstractConflictResolverTest.java
+++ b/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/conflict/AbstractConflictResolverTest.java
@@ -27,7 +27,8 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.artifact.resolver.ResolutionNode;
 import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
 import org.apache.maven.artifact.versioning.VersionRange;
-import org.apache.maven.test.PlexusTestCase;
+import org.apache.maven.test.PlexusTest;
+import org.codehaus.plexus.PlexusContainer;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 
@@ -41,8 +42,8 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
  *
  * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
  */
+@PlexusTest
 public abstract class AbstractConflictResolverTest
-    extends PlexusTestCase
 {
     // constants --------------------------------------------------------------
 
@@ -63,6 +64,9 @@ public abstract class AbstractConflictResolverTest
 
     private ConflictResolver conflictResolver;
 
+    @Inject
+    protected PlexusContainer container;
+
     // constructors -----------------------------------------------------------
 
     public AbstractConflictResolverTest( String roleHint )
@@ -77,35 +81,16 @@ public abstract class AbstractConflictResolverTest
      * @see junit.framework.TestCase#setUp()
      */
     @BeforeEach
-    @Override
     public void setUp()
             throws Exception
     {
-        super.setUp();
-
-        conflictResolver = lookup( ConflictResolver.ROLE, roleHint );
+        conflictResolver = (ConflictResolver) container.lookup( ConflictResolver.ROLE, roleHint );
 
         a1 = createArtifact( "a", "1.0" );
         a2 = createArtifact( "a", "2.0" );
         b1 = createArtifact( "b", "1.0" );
     }
 
-    /*
-     * @see org.codehaus.plexus.PlexusTestCase#tearDown()
-     */
-    @AfterEach
-    @Override
-    public void tearDown() throws Exception
-    {
-        a1 = null;
-        a2 = null;
-        b1 = null;
-
-        conflictResolver = null;
-
-        super.tearDown();
-    }
-
     // protected methods ------------------------------------------------------
 
     protected ConflictResolver getConflictResolver()
diff --git a/maven-compat/src/test/java/org/apache/maven/repository/metadata/DefaultClasspathTransformationTest.java b/maven-compat/src/test/java/org/apache/maven/repository/metadata/DefaultClasspathTransformationTest.java
index ebe0fd5..d5e2389 100644
--- a/maven-compat/src/test/java/org/apache/maven/repository/metadata/DefaultClasspathTransformationTest.java
+++ b/maven-compat/src/test/java/org/apache/maven/repository/metadata/DefaultClasspathTransformationTest.java
@@ -18,7 +18,7 @@ package org.apache.maven.repository.metadata;
 import javax.inject.Inject;
 
 import org.apache.maven.artifact.ArtifactScopeEnum;
-import org.apache.maven.test.PlexusTestCase;
+import org.apache.maven.test.PlexusTest;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.BeforeEach;
 
@@ -30,9 +30,8 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
  * @author <a href="mailto:oleg@codehaus.org">Oleg Gusakov</a>
  *
  */
-
+@PlexusTest
 public class DefaultClasspathTransformationTest
-extends PlexusTestCase
 {
     @Inject
     ClasspathTransformation transform;
@@ -45,11 +44,8 @@ extends PlexusTestCase
     MetadataGraphVertex v4;
     //------------------------------------------------------------------------------------------
 	@BeforeEach
-    @Override
     public void setUp() throws Exception
     {
-        super.setUp();
-
         graph = new MetadataGraph( 4, 3 );
         /*
          *       v2
diff --git a/maven-compat/src/test/java/org/apache/maven/repository/metadata/DefaultGraphConflictResolverTest.java b/maven-compat/src/test/java/org/apache/maven/repository/metadata/DefaultGraphConflictResolverTest.java
index a41464a..9d3e67d 100644
--- a/maven-compat/src/test/java/org/apache/maven/repository/metadata/DefaultGraphConflictResolverTest.java
+++ b/maven-compat/src/test/java/org/apache/maven/repository/metadata/DefaultGraphConflictResolverTest.java
@@ -18,7 +18,7 @@ package org.apache.maven.repository.metadata;
 import javax.inject.Inject;
 
 import org.apache.maven.artifact.ArtifactScopeEnum;
-import org.apache.maven.test.PlexusTestCase;
+import org.apache.maven.test.PlexusTest;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
@@ -30,9 +30,8 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
  * @author <a href="mailto:oleg@codehaus.org">Oleg Gusakov</a>
  *
  */
-
+@PlexusTest
 public class DefaultGraphConflictResolverTest
-extends PlexusTestCase
 {
     @Inject
     GraphConflictResolver resolver;
@@ -45,11 +44,8 @@ extends PlexusTestCase
     MetadataGraphVertex v4;
     //------------------------------------------------------------------------------------------
 	@BeforeEach
-    @Override
     public void setUp() throws Exception
     {
-        super.setUp();
-
         /*
          *       v2
          *   v1<
diff --git a/maven-core/src/test/java/org/apache/maven/AbstractCoreMavenComponentTestCase.java b/maven-core/src/test/java/org/apache/maven/AbstractCoreMavenComponentTestCase.java
index 3b5b7a6..14a5768 100644
--- a/maven-core/src/test/java/org/apache/maven/AbstractCoreMavenComponentTestCase.java
+++ b/maven-core/src/test/java/org/apache/maven/AbstractCoreMavenComponentTestCase.java
@@ -44,20 +44,26 @@ import org.apache.maven.project.MavenProject;
 import org.apache.maven.project.ProjectBuildingRequest;
 import org.apache.maven.repository.RepositorySystem;
 import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
-import org.apache.maven.test.PlexusTestCase;
+import org.apache.maven.test.PlexusTest;
 import org.codehaus.plexus.ContainerConfiguration;
 import org.codehaus.plexus.PlexusConstants;
+import org.codehaus.plexus.PlexusContainer;
 import org.codehaus.plexus.util.FileUtils;
 import org.eclipse.aether.DefaultRepositorySystemSession;
 import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory;
 import org.eclipse.aether.repository.LocalRepository;
-import org.junit.jupiter.api.BeforeEach;
 
 import javax.inject.Inject;
 
+import static org.apache.maven.test.PlexusExtension.getBasedir;
+
+@PlexusTest
 public abstract class AbstractCoreMavenComponentTestCase
-    extends PlexusTestCase
 {
+
+    @Inject
+    protected PlexusContainer container;
+
     @Inject
     protected RepositorySystem repositorySystem;
 
@@ -66,7 +72,11 @@ public abstract class AbstractCoreMavenComponentTestCase
 
     abstract protected String getProjectsDirectory();
 
-    protected File getProject( String name )
+    protected PlexusContainer getContainer() {
+        return container;
+    }
+
+    protected File getProject(String name )
         throws Exception
     {
         File source = new File( new File( getBasedir(), getProjectsDirectory() ), name );
@@ -75,20 +85,6 @@ public abstract class AbstractCoreMavenComponentTestCase
         return new File( target, "pom.xml" );
     }
 
-    /**
-     * We need to customize the standard Plexus container with the plugin discovery listener which
-     * is what looks for the META-INF/maven/plugin.xml resources that enter the system when a Maven
-     * plugin is loaded.
-     *
-     * We also need to customize the Plexus container with a standard plugin discovery listener
-     * which is the MavenPluginCollector. When a Maven plugin is discovered the MavenPluginCollector
-     * collects the plugin descriptors which are found.
-     */
-    protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration )
-    {
-        containerConfiguration.setAutoWiring( true ).setClassPathScanning( PlexusConstants.SCANNING_INDEX );
-    }
-
     protected MavenExecutionRequest createMavenExecutionRequest( File pom )
         throws Exception
     {
diff --git a/maven-core/src/test/java/org/apache/maven/DefaultMavenTest.java b/maven-core/src/test/java/org/apache/maven/DefaultMavenTest.java
index 3a85ea4..b65d38f 100644
--- a/maven-core/src/test/java/org/apache/maven/DefaultMavenTest.java
+++ b/maven-core/src/test/java/org/apache/maven/DefaultMavenTest.java
@@ -63,7 +63,7 @@ public class DefaultMavenTest
     public void testMavenProjectNoDuplicateArtifacts()
         throws Exception
     {
-        MavenProjectHelper mavenProjectHelper = lookup( MavenProjectHelper.class );
+        MavenProjectHelper mavenProjectHelper = getContainer().lookup( MavenProjectHelper.class );
         MavenProject mavenProject = new MavenProject();
         mavenProject.setArtifact( new DefaultArtifact( "g", "a", "1.0", Artifact.SCOPE_TEST, "jar", "", null ) );
         File artifactFile = Files.createTempFile( "foo", "tmp").toFile();
diff --git a/maven-core/src/test/java/org/apache/maven/MavenLifecycleParticipantTest.java b/maven-core/src/test/java/org/apache/maven/MavenLifecycleParticipantTest.java
index 13ff67a..6d8f975 100644
--- a/maven-core/src/test/java/org/apache/maven/MavenLifecycleParticipantTest.java
+++ b/maven-core/src/test/java/org/apache/maven/MavenLifecycleParticipantTest.java
@@ -102,12 +102,6 @@ public class MavenLifecycleParticipantTest
     }
 
     @Override
-    protected void setupContainer()
-    {
-        super.setupContainer();
-    }
-
-    @Override
     protected String getProjectsDirectory()
     {
         return "src/test/projects/lifecycle-listener";
diff --git a/maven-core/src/test/java/org/apache/maven/ProjectDependenciesResolverTest.java b/maven-core/src/test/java/org/apache/maven/ProjectDependenciesResolverTest.java
index 777bae5..2aab3db 100644
--- a/maven-core/src/test/java/org/apache/maven/ProjectDependenciesResolverTest.java
+++ b/maven-core/src/test/java/org/apache/maven/ProjectDependenciesResolverTest.java
@@ -28,6 +28,7 @@ import org.apache.maven.project.MavenProject;
 import javax.inject.Inject;
 import org.junit.jupiter.api.Test;
 
+import static org.apache.maven.test.PlexusExtension.getBasedir;
 import static org.hamcrest.Matchers.endsWith;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.hamcrest.MatcherAssert.assertThat;
diff --git a/maven-core/src/test/java/org/apache/maven/artifact/handler/ArtifactHandlerTest.java b/maven-core/src/test/java/org/apache/maven/artifact/handler/ArtifactHandlerTest.java
index 6dba994..72719c9 100644
--- a/maven-core/src/test/java/org/apache/maven/artifact/handler/ArtifactHandlerTest.java
+++ b/maven-core/src/test/java/org/apache/maven/artifact/handler/ArtifactHandlerTest.java
@@ -22,15 +22,23 @@ package org.apache.maven.artifact.handler;
 import java.io.File;
 import java.util.List;
 
-import org.apache.maven.test.PlexusTestCase;
+import javax.inject.Inject;
+
+import org.apache.maven.test.PlexusExtension;
+import org.apache.maven.test.PlexusTest;
+import org.codehaus.plexus.PlexusContainer;
 import org.codehaus.plexus.util.FileUtils;
 import org.junit.jupiter.api.Test;
 
+import static org.apache.maven.test.PlexusExtension.getTestFile;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
+@PlexusTest
 public class ArtifactHandlerTest
-    extends PlexusTestCase
 {
+    @Inject
+    PlexusContainer container;
+
     @Test
     public void testAptConsistency()
         throws Exception
@@ -66,7 +74,7 @@ public class ArtifactHandlerTest
                 String addedToClasspath = trimApt( cols[6] );
                 String includesDependencies = trimApt( cols[7] );
 
-                ArtifactHandler handler = lookup( ArtifactHandler.class, type );
+                ArtifactHandler handler = container.lookup( ArtifactHandler.class, type );
                 assertEquals( handler.getExtension(), extension, type + " extension" );
                 assertEquals( handler.getPackaging(), packaging, type + " packaging" );
                 assertEquals( handler.getClassifier(), classifier, type + " classifier" );
diff --git a/maven-core/src/test/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulatorTest.java b/maven-core/src/test/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulatorTest.java
index e57e791..46191c5 100644
--- a/maven-core/src/test/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulatorTest.java
+++ b/maven-core/src/test/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulatorTest.java
@@ -8,7 +8,7 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.settings.Profile;
 import org.apache.maven.settings.Repository;
 import org.apache.maven.settings.Settings;
-import org.apache.maven.test.PlexusTestCase;
+import org.apache.maven.test.PlexusTest;
 import org.junit.jupiter.api.Test;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -31,9 +31,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
  * specific language governing permissions and limitations
  * under the License.
  */
-
+@PlexusTest
 public class DefaultMavenExecutionRequestPopulatorTest
-    extends PlexusTestCase
 {
     @Inject
     MavenExecutionRequestPopulator testee;
diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/DefaultLifecyclesTest.java b/maven-core/src/test/java/org/apache/maven/lifecycle/DefaultLifecyclesTest.java
index 2378ddd..aea902d 100644
--- a/maven-core/src/test/java/org/apache/maven/lifecycle/DefaultLifecyclesTest.java
+++ b/maven-core/src/test/java/org/apache/maven/lifecycle/DefaultLifecyclesTest.java
@@ -23,7 +23,7 @@ import java.util.stream.Collectors;
 
 import javax.inject.Inject;
 
-import org.apache.maven.test.PlexusTestCase;
+import org.apache.maven.test.PlexusTest;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
@@ -35,9 +35,8 @@ import static org.hamcrest.Matchers.is;
 /**
  * @author Kristian Rosenvold
  */
-
+@PlexusTest
 public class DefaultLifecyclesTest
-    extends PlexusTestCase
 {
     @Inject
     private DefaultLifecycles defaultLifeCycles;
diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorTest.java b/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorTest.java
index 448ffda..b4c12a3 100644
--- a/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorTest.java
+++ b/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorTest.java
@@ -500,8 +500,8 @@ public class LifecycleExecutorTest
                 log.add( "afterProjectExecutionFailure " + event.getProject().getArtifactId() );
             }
         };
-        lookup( DelegatingProjectExecutionListener.class ).addProjectExecutionListener( projectListener );
-        lookup( DelegatingMojoExecutionListener.class ).addMojoExecutionListener( mojoListener );
+        getContainer().lookup( DelegatingProjectExecutionListener.class ).addProjectExecutionListener( projectListener );
+        getContainer().lookup( DelegatingMojoExecutionListener.class ).addMojoExecutionListener( mojoListener );
 
         try
         {
@@ -509,8 +509,8 @@ public class LifecycleExecutorTest
         }
         finally
         {
-            lookup( DelegatingProjectExecutionListener.class ).removeProjectExecutionListener( projectListener );
-            lookup( DelegatingMojoExecutionListener.class ).removeMojoExecutionListener( mojoListener );
+            getContainer().lookup( DelegatingProjectExecutionListener.class ).removeProjectExecutionListener( projectListener );
+            getContainer().lookup( DelegatingMojoExecutionListener.class ).removeMojoExecutionListener( mojoListener );
         }
 
         List<String> expectedLog = Arrays.asList( "beforeProjectExecution project-basic", //
diff --git a/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java b/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java
index 9c0da4f..b0b9b1f 100644
--- a/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java
+++ b/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java
@@ -50,6 +50,7 @@ import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
+import static org.apache.maven.test.PlexusExtension.getTestFile;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertSame;
diff --git a/maven-core/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java b/maven-core/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java
index 8b0cec0..d146927 100644
--- a/maven-core/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java
+++ b/maven-core/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java
@@ -27,7 +27,8 @@ import org.apache.maven.model.building.ModelBuildingException;
 import org.apache.maven.model.building.ModelProblem;
 import org.apache.maven.repository.RepositorySystem;
 import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
-import org.apache.maven.test.PlexusTestCase;
+import org.apache.maven.test.PlexusTest;
+import org.codehaus.plexus.PlexusContainer;
 import org.eclipse.aether.DefaultRepositorySystemSession;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
@@ -37,28 +38,33 @@ import javax.inject.Inject;
 /**
  * @author Jason van Zyl
  */
+@PlexusTest
 public abstract class AbstractMavenProjectTestCase
-    extends PlexusTestCase
 {
     protected ProjectBuilder projectBuilder;
 
     @Inject
     protected RepositorySystem repositorySystem;
 
+    @Inject
+    protected PlexusContainer container;
+
+    public PlexusContainer getContainer() {
+        return container;
+    }
+
     @BeforeEach
     public void setUp()
         throws Exception
     {
-        super.setUp();
-
         if ( getContainer().hasComponent( ProjectBuilder.class, "test" ) )
         {
-            projectBuilder = lookup( ProjectBuilder.class, "test" );
+            projectBuilder = getContainer().lookup( ProjectBuilder.class, "test" );
         }
         else
         {
             // default over to the main project builder...
-            projectBuilder = lookup( ProjectBuilder.class );
+            projectBuilder = getContainer().lookup( ProjectBuilder.class );
         }
     }
 
@@ -67,12 +73,6 @@ public abstract class AbstractMavenProjectTestCase
         return projectBuilder;
     }
 
-    @Override
-    protected String getCustomConfigurationName()
-    {
-        return AbstractMavenProjectTestCase.class.getName().replace( '.', '/' ) + ".xml";
-    }
-
     // ----------------------------------------------------------------------
     // Local repository
     // ----------------------------------------------------------------------
diff --git a/maven-core/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java b/maven-core/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java
index d73b488..73942a0 100644
--- a/maven-core/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java
+++ b/maven-core/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java
@@ -30,6 +30,7 @@ import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
+import static org.apache.maven.test.PlexusExtension.getTestFile;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.containsString;
 import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -54,7 +55,7 @@ public class DefaultMavenProjectBuilderTest
     {
         super.setUp();
 
-        projectBuilder = lookup( ProjectBuilder.class );
+        projectBuilder = getContainer().lookup( ProjectBuilder.class );
 
         localRepoDir = new File( System.getProperty( "java.io.tmpdir" ), "local-repo." + System.currentTimeMillis() );
         localRepoDir.mkdirs();
@@ -62,13 +63,10 @@ public class DefaultMavenProjectBuilderTest
         filesToDelete.add( localRepoDir );
     }
 
-    @Override
     @AfterEach
     public void tearDown()
         throws Exception
     {
-        super.tearDown();
-
         if ( !filesToDelete.isEmpty() )
         {
             for ( File file : filesToDelete )
diff --git a/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java b/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java
index 6a53907..e9492ae 100644
--- a/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java
+++ b/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java
@@ -28,7 +28,7 @@ import java.util.Properties;
 
 import javax.inject.Inject;
 
-import org.apache.maven.test.PlexusTestCase;
+import org.apache.maven.test.PlexusTest;
 import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
 import org.apache.maven.model.Plugin;
 import org.apache.maven.model.PluginExecution;
@@ -43,6 +43,7 @@ import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
+import static org.apache.maven.test.PlexusExtension.getBasedir;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.endsWith;
 import static org.hamcrest.Matchers.lessThan;
@@ -54,8 +55,8 @@ import static org.junit.jupiter.api.Assertions.assertNull;
 import static org.junit.jupiter.api.Assertions.assertSame;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 
+@PlexusTest
 public class PomConstructionTest
-    extends PlexusTestCase
 {
     private static String BASE_DIR = "src/test";
 
@@ -75,20 +76,10 @@ public class PomConstructionTest
     public void setUp()
         throws Exception
     {
-        super.setUp();
         testDirectory = new File( getBasedir(), BASE_POM_DIR );
         new File( getBasedir(), BASE_MIXIN_DIR );
     }
 
-    @AfterEach
-    public void tearDown()
-        throws Exception
-    {
-        projectBuilder = null;
-
-        super.tearDown();
-    }
-
     /**
      * Will throw exception if url is empty. MNG-4050
      *
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 506a844..f23132c 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
@@ -85,7 +85,7 @@ public class ProjectBuilderTest
         configuration.setRepositorySession( mavenSession.getRepositorySession() );
         ModelSource modelSource = new FileModelSource( pomFile );
         ProjectBuildingResult result =
-            lookup( org.apache.maven.project.ProjectBuilder.class ).build( modelSource, configuration );
+            getContainer().lookup( org.apache.maven.project.ProjectBuilder.class ).build( modelSource, configuration );
 
         assertNotNull( result.getProject().getParentFile() );
     }
@@ -100,7 +100,7 @@ public class ProjectBuilderTest
         configuration.setRepositorySession( mavenSession.getRepositorySession() );
 
         ProjectBuildingException e = assertThrows( ProjectBuildingException.class,
-                      () -> lookup( org.apache.maven.project.ProjectBuilder.class ).build( pomFile, configuration ) );
+                      () -> getContainer().lookup( org.apache.maven.project.ProjectBuilder.class ).build( pomFile, configuration ) );
         assertThat( e.getMessage(),
                     containsString( "[ERROR] 'dependencies.dependency.version' for org.apache.maven.its:a:jar is missing. "
                         + "@ line 9, column 17" ) );
@@ -117,11 +117,11 @@ public class ProjectBuilderTest
         configuration.setResolveDependencies( true );
 
         // single project build entry point
-        ProjectBuildingResult result = lookup( org.apache.maven.project.ProjectBuilder.class ).build( pomFile, configuration );
+        ProjectBuildingResult result = getContainer().lookup( org.apache.maven.project.ProjectBuilder.class ).build( pomFile, configuration );
         assertEquals( 1, result.getProject().getArtifacts().size() );
         // multi projects build entry point
         List<ProjectBuildingResult> results =
-            lookup( org.apache.maven.project.ProjectBuilder.class ).build( Collections.singletonList( pomFile ), false,
+                getContainer().lookup( org.apache.maven.project.ProjectBuilder.class ).build( Collections.singletonList( pomFile ), false,
                                                                            configuration );
         assertEquals( 1, results.size() );
         MavenProject mavenProject = results.get( 0 ).getProject();
@@ -139,10 +139,10 @@ public class ProjectBuilderTest
         configuration.setResolveDependencies( false );
 
         // single project build entry point
-        ProjectBuildingResult result = lookup( org.apache.maven.project.ProjectBuilder.class ).build( pomFile, configuration );
+        ProjectBuildingResult result = getContainer().lookup( org.apache.maven.project.ProjectBuilder.class ).build( pomFile, configuration );
         assertEquals( 0, result.getProject().getArtifacts().size() );
         // multi projects build entry point
-        List<ProjectBuildingResult> results = lookup( org.apache.maven.project.ProjectBuilder.class ).build( Collections.singletonList( pomFile ), false, configuration );
+        List<ProjectBuildingResult> results = getContainer().lookup( org.apache.maven.project.ProjectBuilder.class ).build( Collections.singletonList( pomFile ), false, configuration );
         assertEquals( 1, results.size() );
         MavenProject mavenProject = results.get( 0 ).getProject();
         assertEquals( 0, mavenProject.getArtifacts().size() );
@@ -161,7 +161,7 @@ public class ProjectBuilderTest
             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 );
+            org.apache.maven.project.ProjectBuilder projectBuilder = getContainer().lookup( org.apache.maven.project.ProjectBuilder.class );
             File child = new File( tempDir.toFile(), "child/pom.xml" );
             // build project once
             projectBuilder.build( child, configuration );
@@ -199,7 +199,7 @@ public class ProjectBuilderTest
         configuration.setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL );
         configuration.setRepositorySession( mavenSession.getRepositorySession() );
         org.apache.maven.project.ProjectBuilder projectBuilder =
-            lookup( org.apache.maven.project.ProjectBuilder.class );
+                getContainer().lookup( org.apache.maven.project.ProjectBuilder.class );
 
         // single project build entry point
         ProjectBuildingException ex1 =
@@ -233,7 +233,7 @@ public class ProjectBuilderTest
         configuration.setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL );
         configuration.setRepositorySession( mavenSession.getRepositorySession() );
         org.apache.maven.project.ProjectBuilder projectBuilder =
-            lookup( org.apache.maven.project.ProjectBuilder.class );
+                getContainer().lookup( org.apache.maven.project.ProjectBuilder.class );
 
         // single project build entry point
         Exception ex = assertThrows( Exception.class, () -> projectBuilder.build( pomFile, configuration ) );
@@ -262,7 +262,7 @@ public class ProjectBuilderTest
         configuration.setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL );
         configuration.setRepositorySession( mavenSession.getRepositorySession() );
         org.apache.maven.project.ProjectBuilder projectBuilder =
-            lookup( org.apache.maven.project.ProjectBuilder.class );
+                getContainer().lookup( org.apache.maven.project.ProjectBuilder.class );
 
         // read poms separately
         boolean parentFileWasFoundOnChild = false;
diff --git a/maven-core/src/test/java/org/apache/maven/project/ProjectModelResolverTest.java b/maven-core/src/test/java/org/apache/maven/project/ProjectModelResolverTest.java
index 4c1dcf4..9a1d9e3 100644
--- a/maven-core/src/test/java/org/apache/maven/project/ProjectModelResolverTest.java
+++ b/maven-core/src/test/java/org/apache/maven/project/ProjectModelResolverTest.java
@@ -35,6 +35,7 @@ import org.eclipse.aether.impl.RemoteRepositoryManager;
 import org.eclipse.aether.repository.RemoteRepository;
 import org.junit.jupiter.api.Test;
 
+import static org.apache.maven.test.PlexusExtension.getBasedir;
 import static org.hamcrest.Matchers.startsWith;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -208,8 +209,8 @@ public class ProjectModelResolverTest extends AbstractMavenProjectTestCase
         final DefaultRepositorySystemSession repoSession = MavenRepositorySystemUtils.newSession();
         repoSession.setLocalRepositoryManager( new LegacyLocalRepositoryManager( localRepo ) );
 
-        return new ProjectModelResolver( repoSession, null, lookup( RepositorySystem.class ),
-                                         lookup( RemoteRepositoryManager.class ),
+        return new ProjectModelResolver( repoSession, null, getContainer().lookup( RepositorySystem.class ),
+                                         getContainer().lookup( RemoteRepositoryManager.class ),
                                          this.getRemoteRepositories(),
                                          ProjectBuildingRequest.RepositoryMerging.REQUEST_DOMINANT, null );
 
diff --git a/maven-core/src/test/java/org/apache/maven/project/artifact/MavenMetadataSourceTest.java b/maven-core/src/test/java/org/apache/maven/project/artifact/MavenMetadataSourceTest.java
index a69af5e..85c6930 100644
--- a/maven-core/src/test/java/org/apache/maven/project/artifact/MavenMetadataSourceTest.java
+++ b/maven-core/src/test/java/org/apache/maven/project/artifact/MavenMetadataSourceTest.java
@@ -19,23 +19,25 @@ package org.apache.maven.project.artifact;
  * under the License.
  */
 
-import org.apache.maven.test.PlexusTestCase;
+import javax.inject.Inject;
+
 import org.apache.maven.repository.RepositorySystem;
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.BeforeEach;
+import org.apache.maven.test.PlexusTest;
+import org.codehaus.plexus.PlexusContainer;
 import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
 
-import javax.inject.Inject;
-
-@Disabled
+@PlexusTest
 public class MavenMetadataSourceTest
-    extends PlexusTestCase
 {
     @Inject
     private RepositorySystem repositorySystem;
 
+    @Inject
+    PlexusContainer container;
+
     @Test
+    @Disabled
     public void testShouldNotCarryExclusionsOverFromDependencyToDependency()
         throws Exception
     {
@@ -58,21 +60,21 @@ public class MavenMetadataSourceTest
         dep2.setVersion( "1" );
         dep2.setType( "jar" );
 
-        List deps = new ArrayList();
+        List<Dependency> deps = new ArrayList<>();
         deps.add( dep1 );
         deps.add( dep2 );
 
-        ArtifactFactory factory = lookup( ArtifactFactory.class );
+        ArtifactFactory factory = container.lookup( ArtifactFactory.class );
 
         ArtifactFilter dependencyFilter = new ScopeArtifactFilter( Artifact.SCOPE_COMPILE );
 
         MavenProject project = new MavenProject( new Model() );
 
-        Set result = project.createArtifacts( dependencyFilter );
+        Set<Artifact> result = project.createArtifacts( dependencyFilter );
 
-        for ( Iterator it = result.iterator(); it.hasNext(); )
+        for (Iterator<Artifact> it = result.iterator(); it.hasNext(); )
         {
-            Artifact artifact = ( Artifact ) it.next();
+            Artifact artifact = it.next();
 
             if ( "test-artifact2".equals( artifact.getArtifactId() ) )
             {
@@ -84,11 +86,12 @@ public class MavenMetadataSourceTest
         */
     }
 
-    //TODO restore these if it makes sense
-    /*
+    @Test
+    @Disabled("TODO restore these if it makes sense")
     public void testShouldUseCompileScopeIfDependencyScopeEmpty()
         throws Exception
     {
+        /*
         String groupId = "org.apache.maven";
         String artifactId = "maven-model";
 
@@ -111,21 +114,24 @@ public class MavenMetadataSourceTest
         Map artifactMap = project.getArtifactMap();
 
         assertNotNull( artifactMap, "artifact-map should not be null." );
-        assertEquals( "artifact-map should contain 1 element.", 1, artifactMap.size() );
+        assertEquals( 1, artifactMap.size(), "artifact-map should contain 1 element." );
 
         Artifact artifact = (Artifact) artifactMap.get( key );
 
         assertNotNull( artifact, "dependency artifact not found in map." );
-        assertEquals( "dependency artifact has wrong scope.", Artifact.SCOPE_COMPILE, artifact.getScope() );
+        assertEquals( Artifact.SCOPE_COMPILE, artifact.getScope(), "dependency artifact has wrong scope." );
 
         //check for back-propagation of default scope.
-        assertEquals( "default scope NOT back-propagated to dependency.", Artifact.SCOPE_COMPILE, dep.getScope() );
+        assertEquals( Artifact.SCOPE_COMPILE, dep.getScope(), "default scope NOT back-propagated to dependency." );
+        */
     }
 
     @Test
+    @Disabled
     public void testShouldUseInjectedTestScopeFromDependencyManagement()
         throws Exception
     {
+        /*
         String groupId = "org.apache.maven";
         String artifactId = "maven-model";
 
@@ -163,7 +169,7 @@ public class MavenMetadataSourceTest
         Map artifactMap = project.getArtifactMap();
 
         assertNotNull( artifactMap, "artifact-map should not be null." );
-        assertEquals( "artifact-map should contain 1 element.", 1, artifactMap.size() );
+        assertEquals( 1, artifactMap.size(), "artifact-map should contain 1 element." );
 
         Artifact artifact = (Artifact) artifactMap.get( key );
 
@@ -172,7 +178,7 @@ public class MavenMetadataSourceTest
 
         //check for back-propagation of default scope.
         assertEquals( "default scope NOT back-propagated to dependency.", Artifact.SCOPE_TEST, dep.getScope() );
+        */
     }
-    */
 
 }
diff --git a/maven-core/src/test/java/org/apache/maven/rtinfo/internal/DefaultRuntimeInformationTest.java b/maven-core/src/test/java/org/apache/maven/rtinfo/internal/DefaultRuntimeInformationTest.java
index 4648737..e278d8b 100644
--- a/maven-core/src/test/java/org/apache/maven/rtinfo/internal/DefaultRuntimeInformationTest.java
+++ b/maven-core/src/test/java/org/apache/maven/rtinfo/internal/DefaultRuntimeInformationTest.java
@@ -20,9 +20,9 @@ package org.apache.maven.rtinfo.internal;
  */
 
 import org.apache.maven.rtinfo.RuntimeInformation;
+import org.apache.maven.test.PlexusTest;
 import org.codehaus.plexus.ContainerConfiguration;
 import org.codehaus.plexus.PlexusConstants;
-import org.apache.maven.test.PlexusTestCase;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
@@ -33,21 +33,12 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import javax.inject.Inject;
 
+@PlexusTest
 public class DefaultRuntimeInformationTest
-    extends PlexusTestCase
 {
     @Inject
     RuntimeInformation rtInfo;
 
-    @Override
-    protected void customizeContainerConfiguration(
-            ContainerConfiguration configuration)
-    {
-        super.customizeContainerConfiguration(configuration);
-        configuration.setAutoWiring(true);
-        configuration.setClassPathScanning(PlexusConstants.SCANNING_INDEX);
-    }
-
     @Test
     public void testGetMavenVersion()
     {
diff --git a/maven-core/src/test/java/org/apache/maven/settings/PomConstructionWithSettingsTest.java b/maven-core/src/test/java/org/apache/maven/settings/PomConstructionWithSettingsTest.java
index b9c9734..d0524d7 100644
--- a/maven-core/src/test/java/org/apache/maven/settings/PomConstructionWithSettingsTest.java
+++ b/maven-core/src/test/java/org/apache/maven/settings/PomConstructionWithSettingsTest.java
@@ -32,7 +32,7 @@ import org.apache.maven.project.harness.PomTestWrapper;
 import org.apache.maven.repository.RepositorySystem;
 import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
 import org.apache.maven.settings.io.xpp3.SettingsXpp3Reader;
-import org.apache.maven.test.PlexusTestCase;
+import org.apache.maven.test.PlexusTest;
 import org.codehaus.plexus.util.ReaderFactory;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 import org.eclipse.aether.DefaultRepositorySystemSession;
@@ -43,10 +43,11 @@ import org.junit.jupiter.api.Test;
 
 import javax.inject.Inject;
 
+import static org.apache.maven.test.PlexusExtension.getBasedir;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
+@PlexusTest
 public class PomConstructionWithSettingsTest
-    extends PlexusTestCase
 {
     private static final String BASE_DIR = "src/test";
 
@@ -64,7 +65,6 @@ public class PomConstructionWithSettingsTest
     public void setUp()
         throws Exception
     {
-        super.setUp();
         testDirectory = new File( getBasedir(), BASE_POM_DIR );
     }
 
diff --git a/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/AbstractRepositoryTestCase.java b/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/AbstractRepositoryTestCase.java
index 0301a60..026f30b 100644
--- a/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/AbstractRepositoryTestCase.java
+++ b/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/AbstractRepositoryTestCase.java
@@ -23,9 +23,10 @@ import java.net.MalformedURLException;
 
 import javax.inject.Inject;
 
-import org.apache.maven.test.PlexusTestCase;
+import org.apache.maven.test.PlexusTest;
 import org.apache.maven.repository.internal.util.ConsoleRepositoryListener;
 import org.apache.maven.repository.internal.util.ConsoleTransferListener;
+import org.codehaus.plexus.PlexusContainer;
 import org.eclipse.aether.DefaultRepositorySystemSession;
 import org.eclipse.aether.RepositorySystem;
 import org.eclipse.aether.RepositorySystemSession;
@@ -34,24 +35,31 @@ import org.eclipse.aether.repository.RemoteRepository;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 
+import static org.apache.maven.test.PlexusExtension.getTestFile;
+
+@PlexusTest
 public abstract class AbstractRepositoryTestCase
-    extends PlexusTestCase
 {
     @Inject
     protected RepositorySystem system;
 
+    @Inject
+    protected PlexusContainer container;
+
     protected RepositorySystemSession session;
 
     @BeforeEach
-    @Override
     public void setUp()
         throws Exception
     {
-        super.setUp();
         session = newMavenRepositorySystemSession( system );
     }
 
-    public static RepositorySystemSession newMavenRepositorySystemSession( RepositorySystem system )
+    protected PlexusContainer getContainer() {
+        return container;
+    }
+
+    public static RepositorySystemSession newMavenRepositorySystemSession(RepositorySystem system )
     {
         DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
 
diff --git a/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/DefaultArtifactDescriptorReaderTest.java b/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/DefaultArtifactDescriptorReaderTest.java
index cd45fe3..a68a42f 100644
--- a/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/DefaultArtifactDescriptorReaderTest.java
+++ b/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/DefaultArtifactDescriptorReaderTest.java
@@ -42,7 +42,7 @@ public class DefaultArtifactDescriptorReaderTest
         throws Exception
     {
         // prepare
-        DefaultArtifactDescriptorReader reader = (DefaultArtifactDescriptorReader) lookup( ArtifactDescriptorReader.class );
+        DefaultArtifactDescriptorReader reader = (DefaultArtifactDescriptorReader) getContainer().lookup( ArtifactDescriptorReader.class );
 
         RepositoryEventDispatcher eventDispatcher = mock( RepositoryEventDispatcher.class );
 
diff --git a/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/DefaultModelResolverTest.java b/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/DefaultModelResolverTest.java
index ce09b4b..1a4d444 100644
--- a/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/DefaultModelResolverTest.java
+++ b/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/DefaultModelResolverTest.java
@@ -202,8 +202,8 @@ public final class DefaultModelResolverTest extends AbstractRepositoryTestCase
     private ModelResolver newModelResolver() throws ComponentLookupException, MalformedURLException
     {
         return new DefaultModelResolver( this.session, null, this.getClass().getName(),
-                                         lookup( ArtifactResolver.class ), lookup( VersionRangeResolver.class ),
-                                         lookup( RemoteRepositoryManager.class ),
+                                         getContainer().lookup( ArtifactResolver.class ), getContainer().lookup( VersionRangeResolver.class ),
+                                         getContainer().lookup( RemoteRepositoryManager.class ),
                                          Arrays.asList( newTestRepository() ) );
 
     }
diff --git a/maven-test-support/src/main/java/org/apache/maven/test/PlexusTestCase.java b/maven-test-support/src/main/java/org/apache/maven/test/PlexusExtension.java
similarity index 87%
rename from maven-test-support/src/main/java/org/apache/maven/test/PlexusTestCase.java
rename to maven-test-support/src/main/java/org/apache/maven/test/PlexusExtension.java
index 91dc25e..c001a6a 100644
--- a/maven-test-support/src/main/java/org/apache/maven/test/PlexusTestCase.java
+++ b/maven-test-support/src/main/java/org/apache/maven/test/PlexusExtension.java
@@ -50,8 +50,9 @@ import org.codehaus.plexus.component.repository.exception.ComponentLookupExcepti
 import org.codehaus.plexus.configuration.PlexusConfiguration;
 import org.codehaus.plexus.context.Context;
 import org.codehaus.plexus.context.DefaultContext;
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.extension.AfterEachCallback;
+import org.junit.jupiter.api.extension.BeforeEachCallback;
+import org.junit.jupiter.api.extension.ExtensionContext;
 
 /**
  * This is a slightly modified version of the original plexus class
@@ -64,20 +65,24 @@ import org.junit.jupiter.api.BeforeEach;
  * @author <a href="mailto:michal@codehaus.org">Michal Maczka</a>
  * @author Guillaume Nodet
  */
-public abstract class PlexusTestCase
+public class PlexusExtension implements BeforeEachCallback, AfterEachCallback
 {
+    private ExtensionContext context;
     private PlexusContainer container;
 
     private static String basedir;
 
-    @BeforeEach
-    public void setUp()
+    @Override
+    public void beforeEach( ExtensionContext context )
             throws Exception
     {
         basedir = getBasedir();
+        this.context = context;
+
+        getContainer().addComponent( getContainer(), PlexusContainer.class.getName() );
 
         ( (DefaultPlexusContainer) getContainer() ).addPlexusInjector( Collections.emptyList(),
-                binder -> binder.requestInjection( this ) );
+                binder -> binder.requestInjection( context.getRequiredTestInstance() ) );
     }
 
     @SuppressWarnings( "ResultOfMethodCallIgnored" )
@@ -161,8 +166,8 @@ public abstract class PlexusTestCase
         return null;
     }
 
-    @AfterEach
-    public void tearDown()
+    @Override
+    public void afterEach( ExtensionContext context )
             throws Exception
     {
         if ( container != null )
@@ -173,7 +178,7 @@ public abstract class PlexusTestCase
         }
     }
 
-    protected PlexusContainer getContainer()
+    public PlexusContainer getContainer()
     {
         if ( container == null )
         {
@@ -211,17 +216,28 @@ public abstract class PlexusTestCase
      */
     protected String getConfigurationName( String subname )
     {
-        return getClass().getName().replace( '.', '/' ) + ".xml";
+        Class<?> testClass = context.getRequiredTestClass();
+        for ( Class<?> clazz = testClass;
+              clazz != null;
+              clazz = clazz.getSuperclass() )
+        {
+            String name = clazz.getName().replace( '.', '/' ) + ".xml";
+            if ( testClass.getClassLoader().getResource( name ) != null )
+            {
+                return name;
+            }
+        }
+        return null;
     }
 
     protected InputStream getResourceAsStream( String resource )
     {
-        return getClass().getResourceAsStream( resource );
+        return context.getRequiredTestClass().getResourceAsStream( resource );
     }
 
     protected ClassLoader getClassLoader()
     {
-        return getClass().getClassLoader();
+        return context.getRequiredTestClass().getClassLoader();
     }
 
     // ----------------------------------------------------------------------
@@ -313,7 +329,7 @@ public abstract class PlexusTestCase
 
     public String getTestConfiguration()
     {
-        return getTestConfiguration( getClass() );
+        return getTestConfiguration( context.getRequiredTestClass() );
     }
 
     public static String getTestConfiguration( Class<?> clazz )
diff --git a/maven-test-support/src/main/java/org/apache/maven/test/PlexusTest.java b/maven-test-support/src/main/java/org/apache/maven/test/PlexusTest.java
new file mode 100644
index 0000000..e46228b
--- /dev/null
+++ b/maven-test-support/src/main/java/org/apache/maven/test/PlexusTest.java
@@ -0,0 +1,38 @@
+package org.apache.maven.test;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Plexus test
+ */
+@Retention( RetentionPolicy.RUNTIME )
+@ExtendWith( PlexusExtension.class )
+@Target( ElementType.TYPE )
+public @interface PlexusTest
+{
+
+}


[maven] 12/22: Avoid code duplication

Posted by rf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a commit to branch MNG-7063
in repository https://gitbox.apache.org/repos/asf/maven.git

commit db7ad7467b0d231c55d6ac5b4878936079139222
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Mon Nov 30 10:39:14 2020 +0100

    Avoid code duplication
---
 .../apache/maven/model/building/DefaultModelBuilder.java | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)

diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
index 896f324..83e69b0 100644
--- a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
+++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
@@ -660,18 +660,10 @@ public class DefaultModelBuilder
                     throw e;
                 }
 
-                if ( modelSource instanceof FileModelSource )
-                {
-                    problems.add( new ModelProblemCollectorRequest( Severity.ERROR, Version.V20 )
-                        .setMessage( "Malformed POM " + modelSource.getLocation() + ": " + e.getMessage() )
-                        .setException( e ) );
-                }
-                else
-                {
-                    problems.add( new ModelProblemCollectorRequest( Severity.WARNING, Version.V20 )
-                        .setMessage( "Malformed POM " + modelSource.getLocation() + ": " + e.getMessage() )
-                        .setException( e ) );
-                }
+                Severity severity = ( modelSource instanceof FileModelSource ) ? Severity.ERROR : Severity.WARNING;
+                problems.add( new ModelProblemCollectorRequest( severity, Version.V20 )
+                    .setMessage( "Malformed POM " + modelSource.getLocation() + ": " + e.getMessage() )
+                    .setException( e ) );
             }
 
             if ( source != null )


[maven] 11/22: Avoid calling getParentPomFile twice

Posted by rf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a commit to branch MNG-7063
in repository https://gitbox.apache.org/repos/asf/maven.git

commit 00c7f3d0e1f82ddbe545f9bc89195fb420f7508a
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Mon Nov 30 09:23:55 2020 +0100

    Avoid calling getParentPomFile twice
    
    # Conflicts:
    #	maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
---
 .../maven/model/building/DefaultModelBuilder.java  | 52 ++++++++++------------
 1 file changed, 23 insertions(+), 29 deletions(-)

diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
index 9d4a419..896f324 100644
--- a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
+++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
@@ -1001,45 +1001,39 @@ public class DefaultModelBuilder
 
         if ( parent != null )
         {
-            Source expectedParentSource = getParentPomFile( childModel, childSource );
+            ModelData candidateData = readParentLocally( childModel, childSource, request, result, problems );
 
-            if ( expectedParentSource != null )
+            if ( candidateData != null )
             {
-                ModelData candidateData = readParentLocally( childModel, childSource, request, result, problems );
-
-                if ( candidateData != null )
+                /*
+                 * NOTE: This is a sanity check of the read. If the cached parent POM was locally resolved,
+                 * the child's GAV should match with that parent, too. If it doesn't, we ignore the cache and
+                 * resolve externally, to mimic the behavior if the cache didn't exist in the first place.
+                 * Otherwise, the cache would obscure a bad POM.
+                 */
+                try
                 {
-                    /*
-                     * NOTE: This is a sanity check of the cache hit. If the cached parent POM was locally resolved,
-                     * the child's GAV should match with that parent, too. If it doesn't, we ignore the cache and
-                     * resolve externally, to mimic the behavior if the cache didn't exist in the first place.
-                     * Otherwise, the cache would obscure a bad POM.
-                     */
-                    try
-                    {
-                        VersionRange parentVersion = VersionRange.createFromVersionSpec( parent.getVersion() );
-                        ArtifactVersion actualVersion = new DefaultArtifactVersion( candidateData.getVersion() );
+                    VersionRange parentVersion = VersionRange.createFromVersionSpec( parent.getVersion() );
+                    ArtifactVersion actualVersion = new DefaultArtifactVersion( candidateData.getVersion() );
 
-                        if ( parent.getGroupId().equals( candidateData.getGroupId() )
-                            && parent.getArtifactId().equals( candidateData.getArtifactId() )
-                            && parentVersion.containsVersion( actualVersion ) )
-                        {
-                            parentData = candidateData;
-                        }
-                    }
-                    catch ( InvalidVersionSpecificationException e )
+                    if ( parent.getGroupId().equals( candidateData.getGroupId() )
+                        && parent.getArtifactId().equals( candidateData.getArtifactId() )
+                        && parentVersion.containsVersion( actualVersion ) )
                     {
-                        // This should already been blocked during validation
+                        parentData = candidateData;
                     }
                 }
+                catch ( InvalidVersionSpecificationException e )
+                {
+                    // This should already been blocked during validation
+                }
             }
 
             if ( parentData == null )
             {
-                ModelData candidateData = fromCache( request.getModelCache(),
-                                                     parent.getGroupId(), parent.getArtifactId(),
-                                                     parent.getVersion(), ModelCacheTag.RAW );
-
+                candidateData = fromCache( request.getModelCache(),
+                                           parent.getGroupId(), parent.getArtifactId(),
+                                           parent.getVersion(), ModelCacheTag.RAW );
 
                 if ( candidateData != null && candidateData.getSource() instanceof ArtifactModelSource )
                 {
@@ -1111,7 +1105,7 @@ public class DefaultModelBuilder
             catch ( UnresolvableModelException e )
             {
                 problems.add( new ModelProblemCollectorRequest( Severity.FATAL, Version.BASE ) //
-                .setMessage( e.getMessage() ).setLocation( parent.getLocation( "" ) ).setException( e ) );
+                    .setMessage( e.getMessage() ).setLocation( parent.getLocation( "" ) ).setException( e ) );
                 throw problems.newModelBuildingException();
             }
             if ( candidateModel == null )


[maven] 16/22: Reuse existing methods to avoid code duplication

Posted by rf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a commit to branch MNG-7063
in repository https://gitbox.apache.org/repos/asf/maven.git

commit e0cd91f8bc7fc0a73aa7f0ba63fcb9953808756c
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Mon Nov 30 11:49:16 2020 +0100

    Reuse existing methods to avoid code duplication
---
 .../org/apache/maven/model/building/DefaultModelBuilder.java | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)

diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
index b987f3b..7935dfa 100644
--- a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
+++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
@@ -1107,11 +1107,7 @@ public class DefaultModelBuilder
         // before because with parents as ranges it will never work in this scenario.
         //
 
-        String groupId = candidateModel.getGroupId();
-        if ( groupId == null && candidateModel.getParent() != null )
-        {
-            groupId = candidateModel.getParent().getGroupId();
-        }
+        String groupId = getGroupId( candidateModel );
         String artifactId = candidateModel.getArtifactId();
 
         if ( groupId == null || !groupId.equals( parent.getGroupId() ) || artifactId == null
@@ -1133,11 +1129,7 @@ public class DefaultModelBuilder
             return null;
         }
 
-        String version = candidateModel.getVersion();
-        if ( version == null && candidateModel.getParent() != null )
-        {
-            version = candidateModel.getParent().getVersion();
-        }
+        String version = getVersion( candidateModel );
         if ( version != null && parent.getVersion() != null && !version.equals( parent.getVersion() ) )
         {
             try


[maven] 10/22: Do not use a "persistent" cache which is the root cause MNG-6530

Posted by rf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a commit to branch MNG-7063
in repository https://gitbox.apache.org/repos/asf/maven.git

commit 5e8c509292cf58e37f22e2c306c4b065dd6efe82
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Sat Nov 28 22:27:49 2020 +0100

    Do not use a "persistent" cache which is the root cause MNG-6530
    
    The root of the problem is MNG-5312 which is a performance issue because a ModelCache was not always involved during a model build.  This lead to MNG-6030 (memory consumption issue because of the usage of multiple caches). The fix for MNG-6030 lead to MNG-6311 (problem with changes not being picked up in M2E).
    The root problem is that the fix for MNG-5312 was wrong.  The caches and its data should be managed at the RepositorySystemSession level, especially as the data is related to a given session parameters (maven global settings).
    This commit brings back the cache at the session level, and a default cache is now set on the session by the MavenCli.  The cache is used later by DefaultArtifactDescriptorReader and DefaultProjectBuilder to build a DefaultModelCache.
    
    * use the cache on the MavenExecutionRequest
    * get rid of the hack for  MNG-6530.
    * MavenCli configures a cache for the whole execution request
    * merge ReactorModelCache into DefaultModelCache
    
    # Conflicts:
    #	maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java
    #	maven-core/src/main/java/org/apache/maven/project/ReactorModelCache.java
---
 .../maven/project/DefaultProjectBuilder.java       |  32 +----
 .../apache/maven/project/ReactorModelCache.java    | 160 ---------------------
 .../apache/maven/project/ProjectBuilderTest.java   |   9 --
 .../main/java/org/apache/maven/cli/MavenCli.java   |   6 +
 .../repository/internal/DefaultModelCache.java     | 153 ++++++++++++++++----
 5 files changed, 137 insertions(+), 223 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 fa3b3e4..29f86b8 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
@@ -71,6 +71,7 @@ import org.apache.maven.model.building.StringModelSource;
 import org.apache.maven.model.building.TransformerContext;
 import org.apache.maven.model.resolution.ModelResolver;
 import org.apache.maven.repository.internal.ArtifactDescriptorUtils;
+import org.apache.maven.repository.internal.DefaultModelCache;
 import org.codehaus.plexus.logging.Logger;
 import org.codehaus.plexus.util.Os;
 import org.codehaus.plexus.util.StringUtils;
@@ -92,9 +93,6 @@ public class DefaultProjectBuilder
     implements ProjectBuilder
 {
 
-    public static final String DISABLE_GLOBAL_MODEL_CACHE_SYSTEM_PROPERTY =
-            "maven.defaultProjectBuilder.disableGlobalModelCache";
-
     @Inject
     private Logger logger;
 
@@ -119,8 +117,6 @@ public class DefaultProjectBuilder
     @Inject
     private ProjectDependenciesResolver dependencyResolver;
 
-    private final ReactorModelCache modelCache = new ReactorModelCache();
-
     // ----------------------------------------------------------------------
     // MavenProjectBuilder Implementation
     // ----------------------------------------------------------------------
@@ -130,12 +126,7 @@ public class DefaultProjectBuilder
         throws ProjectBuildingException
     {
         return build( pomFile, new FileModelSource( pomFile ),
-                new InternalConfig( request, null, useGlobalModelCache() ? getModelCache() : null, null ) );
-    }
-
-    private boolean useGlobalModelCache()
-    {
-        return !Boolean.getBoolean( DISABLE_GLOBAL_MODEL_CACHE_SYSTEM_PROPERTY );
+                new InternalConfig( request, null, null ) );
     }
 
     @Override
@@ -143,7 +134,7 @@ public class DefaultProjectBuilder
         throws ProjectBuildingException
     {
         return build( null, modelSource,
-                 new InternalConfig( request, null, useGlobalModelCache() ? getModelCache() : null, null ) );
+                 new InternalConfig( request, null, null ) );
     }
 
     private ProjectBuildingResult build( File pomFile, ModelSource modelSource, InternalConfig config )
@@ -288,7 +279,7 @@ public class DefaultProjectBuilder
         request.setUserProperties( configuration.getUserProperties() );
         request.setBuildStartTime( configuration.getBuildStartTime() );
         request.setModelResolver( resolver );
-        request.setModelCache( config.modelCache );
+        request.setModelCache( DefaultModelCache.newInstance( config.session ) );
         request.setTransformerContextBuilder( config.transformerContextBuilder );
 
         return request;
@@ -309,7 +300,7 @@ public class DefaultProjectBuilder
         pomArtifact = ArtifactDescriptorUtils.toPomArtifact( pomArtifact );
 
         InternalConfig config =
-            new InternalConfig( request, null, useGlobalModelCache() ? getModelCache() : null, null );
+            new InternalConfig( request, null, null );
 
         boolean localProject;
 
@@ -382,8 +373,7 @@ public class DefaultProjectBuilder
         final ReactorModelPool modelPool = poolBuilder.build();
 
         InternalConfig config =
-            new InternalConfig( request, modelPool, useGlobalModelCache() ? getModelCache() : new ReactorModelCache(),
-                        modelBuilder.newTransformerContextBuilder() );
+            new InternalConfig( request, modelPool, modelBuilder.newTransformerContextBuilder() );
 
         Map<File, MavenProject> projectIndex = new HashMap<>( 256 );
 
@@ -1023,16 +1013,13 @@ public class DefaultProjectBuilder
 
         private final ReactorModelPool modelPool;
 
-        private final ReactorModelCache modelCache;
-
         private final TransformerContextBuilder transformerContextBuilder;
 
-        InternalConfig( ProjectBuildingRequest request, ReactorModelPool modelPool, ReactorModelCache modelCache,
+        InternalConfig( ProjectBuildingRequest request, ReactorModelPool modelPool,
                         TransformerContextBuilder transformerContextBuilder )
         {
             this.request = request;
             this.modelPool = modelPool;
-            this.modelCache = modelCache;
             this.transformerContextBuilder = transformerContextBuilder;
 
             session =
@@ -1044,9 +1031,4 @@ public class DefaultProjectBuilder
 
     }
 
-    private ReactorModelCache getModelCache()
-    {
-        return this.modelCache;
-    }
-
 }
diff --git a/maven-core/src/main/java/org/apache/maven/project/ReactorModelCache.java b/maven-core/src/main/java/org/apache/maven/project/ReactorModelCache.java
deleted file mode 100644
index 10ca878..0000000
--- a/maven-core/src/main/java/org/apache/maven/project/ReactorModelCache.java
+++ /dev/null
@@ -1,160 +0,0 @@
-package org.apache.maven.project;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import org.apache.maven.building.Source;
-import org.apache.maven.model.building.ModelCache;
-
-import java.util.Map;
-import java.util.Objects;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * A simple model cache used to accelerate model building during a reactor build.
- *
- * @author Benjamin Bentmann
- */
-class ReactorModelCache
-    implements ModelCache
-{
-
-    private final Map<Object, Object> models = new ConcurrentHashMap<>( 256 );
-
-    @Override
-    public Object get( String groupId, String artifactId, String version, String tag )
-    {
-        return models.get( new GavCacheKey( groupId, artifactId, version, tag ) );
-    }
-
-    @Override
-    public void put( String groupId, String artifactId, String version, String tag, Object data )
-    {
-        models.put( new GavCacheKey( groupId, artifactId, version, tag ), data );
-    }
-
-    @Override
-    public Object get( Source source, String tag )
-    {
-        return models.get( new SourceCacheKey( source, tag ) );
-    }
-
-    @Override
-    public void put( Source source, String tag, Object data )
-    {
-        models.put( new SourceCacheKey( source, tag ), data );
-    }
-
-    private static final class GavCacheKey
-    {
-
-        private final String groupId;
-
-        private final String artifactId;
-
-        private final String version;
-
-        private final String tag;
-
-        private final int hashCode;
-
-        GavCacheKey( String groupId, String artifactId, String version, String tag )
-        {
-            this.groupId = ( groupId != null ) ? groupId : "";
-            this.artifactId = ( artifactId != null ) ? artifactId : "";
-            this.version = ( version != null ) ? version : "";
-            this.tag = ( tag != null ) ? tag : "";
-            this.hashCode = Objects.hash( groupId, artifactId, version, tag );
-        }
-
-        @Override
-        public boolean equals( Object obj )
-        {
-            if ( this == obj )
-            {
-                return true;
-            }
-
-            if ( !( obj instanceof GavCacheKey ) )
-            {
-                return false;
-            }
-
-            GavCacheKey that = (GavCacheKey) obj;
-
-            return artifactId.equals( that.artifactId ) && groupId.equals( that.groupId )
-                && version.equals( that.version ) && tag.equals( that.tag );
-        }
-
-        @Override
-        public int hashCode()
-        {
-            return hashCode;
-        }
-    }
-
-    private static final class SourceCacheKey
-    {
-        private final Source source;
-
-        private final String tag;
-
-        private final int hashCode;
-
-        SourceCacheKey( Source source, String tag )
-        {
-            this.source = source;
-            this.tag = tag;
-            this.hashCode = Objects.hash( source, tag );
-        }
-
-        @Override
-        public int hashCode()
-        {
-            return hashCode;
-        }
-
-        @Override
-        public boolean equals( Object obj )
-        {
-            if ( this == obj )
-            {
-                return true;
-            }
-            if ( !( obj instanceof SourceCacheKey ) )
-            {
-                return false;
-            }
-
-            SourceCacheKey other = (SourceCacheKey) obj;
-            if ( !Objects.equals( this.source, other.source ) )
-            {
-                    return false;
-            }
-
-            if ( !Objects.equals( this.tag, other.tag ) )
-            {
-                    return false;
-            }
-
-            return true;
-        }
-    }
-
-}
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 f23132c..e2babbf 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
@@ -150,7 +150,6 @@ public class ProjectBuilderTest
 
     @Test
     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
 
@@ -177,14 +176,6 @@ public class ProjectBuilderTest
         }
         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.toFile() );
         }
     }
diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
index 792a831..c217c9e 100644
--- a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
+++ b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
@@ -83,6 +83,7 @@ import org.codehaus.plexus.component.repository.exception.ComponentLookupExcepti
 import org.codehaus.plexus.logging.LoggerManager;
 import org.codehaus.plexus.util.StringUtils;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+import org.eclipse.aether.DefaultRepositoryCache;
 import org.eclipse.aether.transfer.TransferListener;
 import org.slf4j.ILoggerFactory;
 import org.slf4j.Logger;
@@ -975,6 +976,11 @@ public class MavenCli
     {
         MavenExecutionRequest request = executionRequestPopulator.populateDefaults( cliRequest.request );
 
+        if ( cliRequest.request.getRepositoryCache() == null )
+        {
+            cliRequest.request.setRepositoryCache( new DefaultRepositoryCache() );
+        }
+
         eventSpyDispatcher.onEvent( request );
 
         MavenExecutionResult result = maven.execute( request );
diff --git a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/DefaultModelCache.java b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/DefaultModelCache.java
index 86edf16..339bc08 100644
--- a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/DefaultModelCache.java
+++ b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/DefaultModelCache.java
@@ -19,8 +19,12 @@ package org.apache.maven.repository.internal;
  * under the License.
  */
 
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.maven.building.Source;
 import org.apache.maven.model.building.ModelCache;
-import org.eclipse.aether.RepositoryCache;
 import org.eclipse.aether.RepositorySystemSession;
 
 /**
@@ -28,68 +32,107 @@ import org.eclipse.aether.RepositorySystemSession;
  *
  * @author Benjamin Bentmann
  */
-class DefaultModelCache
+public class DefaultModelCache
     implements ModelCache
 {
 
-    private final RepositorySystemSession session;
+    private static final String KEY = DefaultModelCache.class.getName();
 
-    private final RepositoryCache cache;
+    private final Map<Object, Object> cache;
 
     public static ModelCache newInstance( RepositorySystemSession session )
     {
+        Map<Object, Object> cache;
         if ( session.getCache() == null )
         {
-            return null;
+            cache = new ConcurrentHashMap<>();
         }
         else
         {
-            return new DefaultModelCache( session );
+            cache = ( Map ) session.getCache().get( session, KEY );
+            if ( cache == null )
+            {
+                cache = new ConcurrentHashMap<>();
+                session.getCache().put( session, KEY, cache );
+            }
         }
+        return new DefaultModelCache( cache );
+    }
+
+    private DefaultModelCache( Map<Object, Object> cache )
+    {
+        this.cache = cache;
+    }
+
+    public Object get( Source path, String tag )
+    {
+        return get( new SourceCacheKey( path, tag ) );
     }
 
-    private DefaultModelCache( RepositorySystemSession session )
+    public void put( Source path, String tag, Object data )
     {
-        this.session = session;
-        this.cache = session.getCache();
+        put( new SourceCacheKey( path, tag ), data );
     }
 
     public Object get( String groupId, String artifactId, String version, String tag )
     {
-        return cache.get( session, new Key( groupId, artifactId, version, tag ) );
+        return get( new GavCacheKey( groupId, artifactId, version, tag ) );
     }
 
     public void put( String groupId, String artifactId, String version, String tag, Object data )
     {
-        cache.put( session, new Key( groupId, artifactId, version, tag ), data );
+        put( new GavCacheKey( groupId, artifactId, version, tag ), data );
     }
 
-    static class Key
+    protected Object get( Object key )
     {
+        return cache.get( key );
+    }
 
-        private final String groupId;
+    protected void put( Object key, Object data )
+    {
+        cache.put( key, data );
+    }
 
-        private final String artifactId;
+    static class GavCacheKey
+    {
 
-        private final String version;
+        private final String gav;
 
         private final String tag;
 
         private final int hash;
 
-        Key( String groupId, String artifactId, String version, String tag )
+        GavCacheKey( String groupId, String artifactId, String version, String tag )
+        {
+            this( gav( groupId, artifactId, version ), tag );
+        }
+
+        GavCacheKey( String gav, String tag )
         {
-            this.groupId = groupId;
-            this.artifactId = artifactId;
-            this.version = version;
+            this.gav = gav;
             this.tag = tag;
+            this.hash = Objects.hash( gav, tag );
+        }
 
-            int h = 17;
-            h = h * 31 + this.groupId.hashCode();
-            h = h * 31 + this.artifactId.hashCode();
-            h = h * 31 + this.version.hashCode();
-            h = h * 31 + this.tag.hashCode();
-            hash = h;
+        private static String gav( String groupId, String artifactId, String version )
+        {
+            StringBuilder sb = new StringBuilder();
+            if ( groupId != null )
+            {
+                sb.append( groupId );
+            }
+            sb.append( ":" );
+            if ( artifactId != null )
+            {
+                sb.append( artifactId );
+            }
+            sb.append( ":" );
+            if ( version != null )
+            {
+                sb.append( version );
+            }
+            return sb.toString();
         }
 
         @Override
@@ -103,10 +146,8 @@ class DefaultModelCache
             {
                 return false;
             }
-
-            Key that = (Key) obj;
-            return artifactId.equals( that.artifactId ) && groupId.equals( that.groupId )
-                && version.equals( that.version ) && tag.equals( that.tag );
+            GavCacheKey that = (GavCacheKey) obj;
+            return Objects.equals( this.gav, that.gav ) && Objects.equals( this.tag, that.tag );
         }
 
         @Override
@@ -115,5 +156,59 @@ class DefaultModelCache
             return hash;
         }
 
+        @Override
+        public String toString()
+        {
+            return "GavCacheKey{"
+                    + "gav='" + gav + '\''
+                    + ", tag='" + tag + '\''
+                    + '}';
+        }
+    }
+
+    private static final class SourceCacheKey
+    {
+        private final Source source;
+
+        private final String tag;
+
+        private final int hash;
+
+        SourceCacheKey( Source source, String tag )
+        {
+            this.source = source;
+            this.tag = tag;
+            this.hash = Objects.hash( source, tag );
+        }
+
+        @Override
+        public String toString()
+        {
+            return "SourceCacheKey{"
+                    + "source=" + source
+                    + ", tag='" + tag + '\''
+                    + '}';
+        }
+
+        @Override
+        public boolean equals( Object obj )
+        {
+            if ( this == obj )
+            {
+                return true;
+            }
+            if ( null == obj || !getClass().equals( obj.getClass() ) )
+            {
+                return false;
+            }
+            SourceCacheKey that = (SourceCacheKey) obj;
+            return Objects.equals( this.source, that.source ) && Objects.equals( this.tag, that.tag );
+        }
+
+        @Override
+        public int hashCode()
+        {
+            return hash;
+        }
     }
 }


[maven] 15/22: Use local variables

Posted by rf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a commit to branch MNG-7063
in repository https://gitbox.apache.org/repos/asf/maven.git

commit a1fa2006534b96516e027c93940b77f174edfc86
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Mon Nov 30 10:57:33 2020 +0100

    Use local variables
    
    # Conflicts:
    #	maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
---
 .../maven/model/building/DefaultModelBuilder.java      | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
index 1e86fce..b987f3b 100644
--- a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
+++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
@@ -995,6 +995,10 @@ public class DefaultModelBuilder
         {
             ModelData candidateData = readParentLocally( childModel, childSource, request, result, problems );
 
+            String groupId = parent.getGroupId();
+            String artifactId = parent.getArtifactId();
+            String version = parent.getVersion();
+
             if ( candidateData != null )
             {
                 /*
@@ -1005,11 +1009,11 @@ public class DefaultModelBuilder
                  */
                 try
                 {
-                    VersionRange parentVersion = VersionRange.createFromVersionSpec( parent.getVersion() );
+                    VersionRange parentVersion = VersionRange.createFromVersionSpec( version );
                     ArtifactVersion actualVersion = new DefaultArtifactVersion( candidateData.getVersion() );
 
-                    if ( parent.getGroupId().equals( candidateData.getGroupId() )
-                        && parent.getArtifactId().equals( candidateData.getArtifactId() )
+                    if ( groupId.equals( candidateData.getGroupId() )
+                        && artifactId.equals( candidateData.getArtifactId() )
                         && parentVersion.containsVersion( actualVersion ) )
                     {
                         parentData = candidateData;
@@ -1023,9 +1027,7 @@ public class DefaultModelBuilder
 
             if ( parentData == null )
             {
-                candidateData = fromCache( request.getModelCache(),
-                                           parent.getGroupId(), parent.getArtifactId(),
-                                           parent.getVersion(), ModelCacheTag.RAW );
+                candidateData = fromCache( request.getModelCache(), groupId, artifactId, version, ModelCacheTag.RAW );
 
                 if ( candidateData != null && candidateData.getSource() instanceof ArtifactModelSource )
                 {
@@ -1036,9 +1038,7 @@ public class DefaultModelBuilder
                 {
                     parentData = readParentExternally( childModel, request, result, problems );
 
-                    intoCache( request.getModelCache(),
-                              parentData.getGroupId(), parentData.getArtifactId(),
-                              parentData.getVersion(), ModelCacheTag.RAW, parentData );
+                    intoCache( request.getModelCache(), groupId, artifactId, version, ModelCacheTag.RAW, parentData );
                 }
             }
 


[maven] 17/22: Simplify readParent()

Posted by rf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a commit to branch MNG-7063
in repository https://gitbox.apache.org/repos/asf/maven.git

commit 788187a8edf9354c817cfa5dba10ded485131607
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Mon Nov 30 13:55:33 2020 +0100

    Simplify readParent()
    
    The checks were previously done after the cache hit, but they are now a duplication of the checks performed in readParentLocally.
    Doing caching is useless as the first time, the version range will be resolved and stored in the Parent and caching happens during the call to readRawModel anyway.
    
    # Conflicts:
    #	maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
---
 .../maven/model/building/DefaultModelBuilder.java  | 67 +++-------------------
 1 file changed, 9 insertions(+), 58 deletions(-)

diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
index 7935dfa..96ece55 100644
--- a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
+++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
@@ -22,7 +22,6 @@ package org.apache.maven.model.building;
 import static org.apache.maven.model.building.Result.error;
 import static org.apache.maven.model.building.Result.newResult;
 
-import org.apache.maven.artifact.versioning.ArtifactVersion;
 import java.io.File;
 import java.io.IOException;
 import java.nio.file.Files;
@@ -990,69 +989,21 @@ public class DefaultModelBuilder
         ModelData parentData = null;
 
         Parent parent = childModel.getParent();
-
         if ( parent != null )
         {
-            ModelData candidateData = readParentLocally( childModel, childSource, request, result, problems );
-
-            String groupId = parent.getGroupId();
-            String artifactId = parent.getArtifactId();
-            String version = parent.getVersion();
-
-            if ( candidateData != null )
-            {
-                /*
-                 * NOTE: This is a sanity check of the read. If the cached parent POM was locally resolved,
-                 * the child's GAV should match with that parent, too. If it doesn't, we ignore the cache and
-                 * resolve externally, to mimic the behavior if the cache didn't exist in the first place.
-                 * Otherwise, the cache would obscure a bad POM.
-                 */
-                try
-                {
-                    VersionRange parentVersion = VersionRange.createFromVersionSpec( version );
-                    ArtifactVersion actualVersion = new DefaultArtifactVersion( candidateData.getVersion() );
-
-                    if ( groupId.equals( candidateData.getGroupId() )
-                        && artifactId.equals( candidateData.getArtifactId() )
-                        && parentVersion.containsVersion( actualVersion ) )
-                    {
-                        parentData = candidateData;
-                    }
-                }
-                catch ( InvalidVersionSpecificationException e )
-                {
-                    // This should already been blocked during validation
-                }
-            }
-
+            parentData = readParentLocally( childModel, childSource, request, result, problems );
             if ( parentData == null )
             {
-                candidateData = fromCache( request.getModelCache(), groupId, artifactId, version, ModelCacheTag.RAW );
-
-                if ( candidateData != null && candidateData.getSource() instanceof ArtifactModelSource )
-                {
-                    // ArtifactModelSource means repositorySource
-                    parentData = candidateData;
-                }
-                else
-                {
-                    parentData = readParentExternally( childModel, request, result, problems );
-
-                    intoCache( request.getModelCache(), groupId, artifactId, version, ModelCacheTag.RAW, parentData );
-                }
+                parentData = readParentExternally( childModel, request, result, problems );
             }
-
-            if ( parentData != null )
+            
+            Model parentModel = parentData.getModel();
+            if ( !"pom".equals( parentModel.getPackaging() ) )
             {
-                Model parentModel = parentData.getModel();
-
-                if ( !"pom".equals( parentModel.getPackaging() ) )
-                {
-                    problems.add( new ModelProblemCollectorRequest( Severity.ERROR, Version.BASE )
-                        .setMessage( "Invalid packaging for parent POM " + ModelProblemUtils.toSourceHint( parentModel )
-                                         + ", must be \"pom\" but is \"" + parentModel.getPackaging() + "\"" )
-                        .setLocation( parentModel.getLocation( "packaging" ) ) );
-                }
+                problems.add( new ModelProblemCollectorRequest( Severity.ERROR, Version.BASE )
+                    .setMessage( "Invalid packaging for parent POM " + ModelProblemUtils.toSourceHint( parentModel )
+                                     + ", must be \"pom\" but is \"" + parentModel.getPackaging() + "\"" )
+                    .setLocation( parentModel.getLocation( "packaging" ) ) );
             }
         }
 


[maven] 18/22: Remove unneeded @SupressWarnings

Posted by rf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a commit to branch MNG-7063
in repository https://gitbox.apache.org/repos/asf/maven.git

commit 5f51e8122ff64a55860a19441404404baf6cc559
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Mon Nov 30 13:55:54 2020 +0100

    Remove unneeded @SupressWarnings
---
 .../main/java/org/apache/maven/model/building/DefaultModelBuilder.java   | 1 -
 1 file changed, 1 deletion(-)

diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
index 96ece55..d8292f5 100644
--- a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
+++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
@@ -274,7 +274,6 @@ public class DefaultModelBuilder
         return build( request, new LinkedHashSet<>() );
     }
 
-    @SuppressWarnings( "checkstyle:methodlength" )
     protected ModelBuildingResult build( ModelBuildingRequest request, Collection<String> importIds )
         throws ModelBuildingException
     {