[ 
https://issues.apache.org/jira/browse/SUREFIRE-1564?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16641188#comment-16641188
 ] 

ASF GitHub Bot commented on SUREFIRE-1564:
------------------------------------------

rmannibucau closed pull request #193: [SUREFIRE-1564] ensure provider 
dependencies can be overriden
URL: https://github.com/apache/maven-surefire/pull/193
 
 
   

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

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

diff --git 
a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
 
b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
index fa1921468..c0580a688 100644
--- 
a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
+++ 
b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
@@ -2856,7 +2856,7 @@ public Classpath getProviderClasspath()
         {
             Artifact surefireArtifact = getPluginArtifactMap().get( 
"org.apache.maven.surefire:surefire-booter" );
             return dependencyResolver.getProviderClasspath( "surefire-testng", 
surefireArtifact.getBaseVersion(),
-                                                            testNgArtifact );
+                                                            testNgArtifact, 
project );
         }
     }
 
@@ -2888,7 +2888,7 @@ public Classpath getProviderClasspath()
             // add the JUnit provider as default - it doesn't require JUnit to 
be present,
             // since it supports POJO tests.
             return dependencyResolver.getProviderClasspath( "surefire-junit3", 
surefireBooterArtifact.getBaseVersion(),
-                                                            null );
+                                                            null, project );
 
         }
     }
@@ -2929,7 +2929,7 @@ public Classpath getProviderClasspath()
             throws ArtifactResolutionException, ArtifactNotFoundException
         {
             return dependencyResolver.getProviderClasspath( "surefire-junit4", 
surefireBooterArtifact.getBaseVersion(),
-                                                            null );
+                                                            null, project );
         }
 
     }
@@ -2964,7 +2964,7 @@ public Classpath getProviderClasspath()
         {
             return dependencyResolver.getProviderClasspath( 
"surefire-junit-platform",
                                                             
surefireBooterArtifact.getBaseVersion(),
-                                                            null );
+                                                            null, project );
         }
     }
 
@@ -3013,7 +3013,7 @@ public Classpath getProviderClasspath()
             throws ArtifactResolutionException, ArtifactNotFoundException
         {
             return dependencyResolver.getProviderClasspath( 
"surefire-junit47", surefireBooterArtifact.getBaseVersion(),
-                                                            null );
+                                                            null, project );
         }
     }
 
diff --git 
a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireDependencyResolver.java
 
b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireDependencyResolver.java
index a43c4def2..eb6fb6741 100644
--- 
a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireDependencyResolver.java
+++ 
b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireDependencyResolver.java
@@ -37,6 +37,9 @@
 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.model.Dependency;
+import org.apache.maven.model.Plugin;
+import org.apache.maven.project.MavenProject;
 import org.apache.maven.surefire.booter.Classpath;
 import org.apache.maven.plugin.surefire.log.api.ConsoleLogger;
 
@@ -129,7 +132,8 @@ private ArtifactResolutionResult resolveArtifact( Artifact 
filteredArtifact, Art
     }
 
     @Nonnull
-    public Classpath getProviderClasspath( String provider, String version, 
Artifact filteredArtifact )
+    public Classpath getProviderClasspath( String provider, String version, 
Artifact filteredArtifact,
+                                           MavenProject project )
         throws ArtifactNotFoundException, ArtifactResolutionException
     {
         Classpath classPath = ClasspathCache.getCachedClassPath( provider );
@@ -146,6 +150,57 @@ public Classpath getProviderClasspath( String provider, 
String version, Artifact
             {
                 Artifact artifact = (Artifact) o;
 
+                final List plugins = project.getBuildPlugins();
+                if ( plugins != null ) // try to override the version from the 
plugin dependencies first (forced)
+                {
+                    for ( Object pluginRef : plugins )
+                    {
+                        Plugin plugin = (Plugin) pluginRef;
+                        if ( !( "maven-surefire-plugin".equals( 
plugin.getArtifactId() )
+                                && "org.apache.maven.plugins".equals( 
plugin.getGroupId() ) ) )
+                        {
+                            continue;
+                        }
+
+                        boolean found = false;
+                        for ( Dependency dependency : plugin.getDependencies() 
)
+                        {
+                            if ( artifact.getGroupId().equals( 
dependency.getGroupId() )
+                                    && artifact.getArtifactId().equals( 
dependency.getArtifactId() )
+                                    && ( ( artifact.getClassifier() != null
+                                        && artifact.getClassifier().equals( 
dependency.getClassifier() ) )
+                                        || ( artifact.getClassifier() == null 
&& dependency.getClassifier() == null ) )
+                            )
+                            {
+                                final Artifact pluginArtifact = 
artifactFactory.createDependencyArtifact(
+                                        dependency.getGroupId(),
+                                        dependency.getArtifactId(),
+                                        VersionRange.createFromVersion( 
dependency.getVersion() ),
+                                        dependency.getType(),
+                                        dependency.getClassifier(),
+                                        Artifact.SCOPE_TEST );
+                                artifactResolver.resolve( pluginArtifact, 
remoteRepositories, localRepository );
+                                artifact = pluginArtifact;
+                                found = true;
+                                break;
+                            }
+                        }
+                        if ( found )
+                        {
+                            break;
+                        }
+                    }
+                }
+
+                if ( artifact == o )  // if we kept the same instance we will 
try to override it from the project deps
+                {
+                    Artifact projectOverride = (Artifact) 
project.getArtifactMap()
+                            .get( artifact.getGroupId() + ":" + 
artifact.getArtifactId() );
+                    if ( projectOverride != null )
+                    {
+                        artifact = projectOverride;
+                    }
+                }
                 log.debug(
                     "Adding to " + pluginName + " test classpath: " + 
artifact.getFile().getAbsolutePath() + " Scope: "
                         + artifact.getScope() );


 

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


> Can't override platform version through project/plugin dependencies
> -------------------------------------------------------------------
>
>                 Key: SUREFIRE-1564
>                 URL: https://issues.apache.org/jira/browse/SUREFIRE-1564
>             Project: Maven Surefire
>          Issue Type: Bug
>          Components: JUnit 5.x support
>    Affects Versions: 2.22.0
>            Reporter: Romain Manni-Bucau
>            Assignee: Tibor Digana
>            Priority: Major
>              Labels: junit5
>             Fix For: 2.22.1
>
>




--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to