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

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

Tibor17 commented on a change in pull request #196: [SUREFIRE-1585] [WIP] 
Resolve missing artifact
URL: https://github.com/apache/maven-surefire/pull/196#discussion_r228046613
 
 

 ##########
 File path: 
maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/TestClassPath.java
 ##########
 @@ -87,15 +88,40 @@ private void addMissingArtifacts( Set<Artifact> 
providerArtifacts )
         // TODO Check for actual SurefireProvider -- the following only 
applies for when
         //      
'org.apache.maven.surefire.junitplatform.JUnitPlatformProvider' is active.
 
-        // TODO Add missing 'junit-jupiter-engine' to test runtime
-        // Artifact junitJupiterApi = findArtifact( 
"org.junit.jupiter:junit-jupiter-api", artifacts );
-        // Artifact junitJupiterEngine =
-        //   findArtifact( "org.junit.jupiter:junit-jupiter-engine", 
artifacts, providerArtifacts );
-        // if ( junitJupiterApi != null && junitJupiterEngine == null )
-        // {
-        //     [artifacts | providerArtifacts]
-        //     .add( "org.junit.jupiter:junit-jupiter-engine:" + 
junitJupiterApi.getVersion() );
-        // }
+        if ( mojo == null )
+        {
+            // mojo.getLog().warn( "Can't resolve missing artifacts when mojo 
is not set." );
+            return;
+        }
+
+        // Add missing 'junit-jupiter-engine' to test runtime
+        Map<String, Artifact> artifactMap = mojo.getProjectArtifactMap();
+        Artifact junitJupiterApi = artifactMap.get( 
"org.junit.jupiter:junit-jupiter-api" );
+        Artifact junitJupiterEngine = artifactMap.get( 
"org.junit.jupiter:junit-jupiter-engine" );
+        if ( junitJupiterApi != null && junitJupiterEngine == null )
+        {
+            junitJupiterEngine = new DefaultArtifact(
+                            "org.junit.jupiter",
+                            "junit-jupiter-engine",
+                            junitJupiterApi.getVersionRange(),
+                            "test",
+                            "jar",
+                            "",
+                            junitJupiterApi.getArtifactHandler()
+            );
+            @SuppressWarnings( "unchecked" )
+            Set<Artifact> resolvedArtifacts = mojo.resolveArtifact( null, 
junitJupiterEngine ).getArtifacts();
+            providerArtifacts.addAll( resolvedArtifacts );
 
 Review comment:
   This is a Set. Some artifacts won't be added if they are already in the Set. 
Should we override them anyway if higher version is going to be added?

----------------------------------------------------------------
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


> Auto-resolve "missing" artifacts
> --------------------------------
>
>                 Key: SUREFIRE-1585
>                 URL: https://issues.apache.org/jira/browse/SUREFIRE-1585
>             Project: Maven Surefire
>          Issue Type: Improvement
>          Components: JUnit 5.x support
>    Affects Versions: 2.22.1
>            Reporter: Christian Stein
>            Assignee: Christian Stein
>            Priority: Minor
>              Labels: features
>
> Providers should be able to enhance the test runtime by injecting "missing" 
> artifacts before executing tests.
>  
> For example, the JUnit Platform Provider should add "missing" Test Engine 
> artifacts for when users only depend on the API of a test framework.
>  * User test depends on *`junit-jupiter-api`* only? Provide 
> *`junit-jupiter-engine`* at test runtime -- automatically or via plugin deps.
>  * User test depends on *`junit-jupiter-params`* only? That pulls in 
> *`junit-jupiter-api`* transitively. Provide *`junit-jupiter-engine`* at test 
> runtime -- automatically or via plugin deps.
>  * User test depends on *`junit:junit:4.12`* only *AND* the JUnit Platform 
> Provider is forced? Provide *`junit-vintage-engine`* at test runtime -- 
> automatically or via plugin deps.



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

Reply via email to