sormuras commented on a change in pull request #196: [SUREFIRE-1585] [WIP] 
Resolve missing and align "JUnit 5" artifacts
URL: https://github.com/apache/maven-surefire/pull/196#discussion_r232469724
 
 

 ##########
 File path: 
maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
 ##########
 @@ -2846,8 +2849,92 @@ public void addProviderProperties()
         @Nonnull
         public Set<Artifact> getProviderClasspath()
         {
+            String provider = "surefire-junit-platform";
             String version = surefireBooterArtifact.getBaseVersion();
-            return dependencyResolver.getProviderClasspath( 
"surefire-junit-platform", version );
+            Set<Artifact> providerArtifacts = 
dependencyResolver.getProviderClasspath( provider, version );
+            alignJUnitPlatformVersion( providerArtifacts );
+            resolveJUnitJupiterEngine( providerArtifacts );
+            resolveJUnitVintageEngine( providerArtifacts );
+            return providerArtifacts;
+        }
+
+        private void resolveJUnitJupiterEngine( Set<Artifact> 
providerArtifacts )
+        {
+            Artifact junitJupiterApi = getProjectArtifactMap().get( 
"org.junit.jupiter:junit-jupiter-api" );
+            if ( junitJupiterApi == null ) // no api, no engine
+            {
+                return;
+            }
+            Artifact junitJupiterEngine = getProjectArtifactMap().get( 
"org.junit.jupiter:junit-jupiter-engine" );
+            if ( junitJupiterEngine != null ) // engine already resolved by 
project
+            {
+                return;
+            }
+            // resolve "junit-jupiter-engine" and its transitive dependencies
+            String version = junitJupiterApi.getBaseVersion();
+            resolve( providerArtifacts, "org.junit.jupiter", 
"junit-jupiter-engine", version );
+        }
+
+        private void resolveJUnitVintageEngine( Set<Artifact> 
providerArtifacts )
+        {
+            Artifact junit = getProjectArtifactMap().get( "junit:junit" );
+            if ( junit == null || !junit.getBaseVersion().equals( "4.12" ) ) 
// no or wrong "junit", no engine
 
 Review comment:
   Even with the longer variable name I still see value in the comment. I even 
tend to split the `if`-clause into two distinct ones.
   ```java
   if ( junit == null) { return; } // No JUnit at all? No vintage engine.
   if ( !junit.getBaseVersion().equals( "4.12" ) ) { return; } // Not exactly 
JUnit 4.12? No vintage engine.
   ```

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to