You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by so...@apache.org on 2018/10/24 09:35:35 UTC
[maven-surefire] branch SUREFIRE-1585 updated: Resolve missing
'org.junit.jupiter:junit-jupiter-engine' artifact
This is an automated email from the ASF dual-hosted git repository.
sor pushed a commit to branch SUREFIRE-1585
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git
The following commit(s) were added to refs/heads/SUREFIRE-1585 by this push:
new 0b7a1c1 Resolve missing 'org.junit.jupiter:junit-jupiter-engine' artifact
0b7a1c1 is described below
commit 0b7a1c16f48957d92b236d2b0b5853cc5f8880d7
Author: Christian Stein <so...@gmail.com>
AuthorDate: Wed Oct 24 11:35:23 2018 +0200
Resolve missing 'org.junit.jupiter:junit-jupiter-engine' artifact
---
maven-surefire-common/pom.xml | 6 +++
.../plugin/surefire/AbstractSurefireMojo.java | 4 +-
.../maven/plugin/surefire/TestClassPath.java | 60 ++++++++++++++++------
3 files changed, 53 insertions(+), 17 deletions(-)
diff --git a/maven-surefire-common/pom.xml b/maven-surefire-common/pom.xml
index 47f0dea..60a0eb8 100644
--- a/maven-surefire-common/pom.xml
+++ b/maven-surefire-common/pom.xml
@@ -137,6 +137,12 @@
<artifactId>byte-buddy-agent</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.maven.plugin-testing</groupId>
+ <artifactId>maven-plugin-testing-harness</artifactId>
+ <version>2.1</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
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 c976a23..0cf5f62 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
@@ -2487,7 +2487,7 @@ public abstract class AbstractSurefireMojo
}
return new TestClassPath( classpathArtifacts, getClassesDirectory(),
- getTestClassesDirectory(), getAdditionalClasspathElements(), logger );
+ getTestClassesDirectory(), getAdditionalClasspathElements(), this );
}
/**
@@ -2523,7 +2523,7 @@ public abstract class AbstractSurefireMojo
}
- private ArtifactResolutionResult resolveArtifact( Artifact filteredArtifact, Artifact providerArtifact )
+ ArtifactResolutionResult resolveArtifact( Artifact filteredArtifact, Artifact providerArtifact )
{
ArtifactFilter filter = null;
if ( filteredArtifact != null )
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/TestClassPath.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/TestClassPath.java
index b9b39b5..928cc91 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/TestClassPath.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/TestClassPath.java
@@ -20,13 +20,14 @@ package org.apache.maven.plugin.surefire;
*/
import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.surefire.booter.Classpath;
-import org.codehaus.plexus.logging.Logger;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import static java.util.Collections.addAll;
@@ -35,22 +36,26 @@ import static org.apache.maven.shared.utils.StringUtils.split;
final class TestClassPath
{
private final Iterable<Artifact> artifacts;
+
private final File classesDirectory;
+
private final File testClassesDirectory;
+
private final String[] additionalClasspathElements;
- private final Logger logger;
+
+ private final AbstractSurefireMojo mojo;
TestClassPath( Iterable<Artifact> artifacts,
File classesDirectory,
File testClassesDirectory,
String[] additionalClasspathElements,
- Logger logger )
+ AbstractSurefireMojo mojo )
{
this.artifacts = artifacts;
this.classesDirectory = classesDirectory;
this.testClassesDirectory = testClassesDirectory;
this.additionalClasspathElements = additionalClasspathElements;
- this.logger = logger;
+ this.mojo = mojo;
}
void avoidArtifactDuplicates( Set<Artifact> providerArtifacts )
@@ -69,9 +74,9 @@ final class TestClassPath
&& ( classifier1 == null ? classifier2 == null : classifier1.equals( classifier2 ) ) )
{
it.remove();
- if ( logger.isDebugEnabled() )
+ if ( mojo != null && mojo.getLog().isDebugEnabled() )
{
- logger.debug( "Removed artifact " + providerArtifact + " from provider. "
+ mojo.getLog().debug( "Removed artifact " + providerArtifact + " from provider. "
+ "Already appears in test classpath." );
}
}
@@ -87,15 +92,40 @@ final class TestClassPath
// 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 );
+
+ if ( mojo.getLog().isDebugEnabled() )
+ {
+ mojo.getLog().debug( "Resolved missing artifact: " + junitJupiterEngine );
+ for ( Artifact resolvedArtifact : resolvedArtifacts )
+ {
+ mojo.getLog().debug( " -> " + resolvedArtifact );
+ }
+ }
+ }
// TODO Add missing 'junit-vintage-engine' to test runtime
// Artifact junit4 = findArtifact( "junit:junit", artifacts );