This is an automated email from the ASF dual-hosted git repository. tibordigana pushed a commit to branch 3.0.0-M1 in repository https://gitbox.apache.org/repos/asf/maven-surefire.git
commit 13fb98d40f7495c63f309ba99bbaf6ae93c7cd25 Author: Tibor17 <tibordig...@apache.org> AuthorDate: Fri Oct 12 01:35:27 2018 +0200 [SUREFIRE-1493] Maven Plugin API 3.0 --- maven-failsafe-plugin/pom.xml | 15 +-- .../apache/maven/plugin/failsafe/VerifyMojo.java | 2 +- maven-surefire-common/pom.xml | 23 +++- .../plugin/surefire/AbstractSurefireMojo.java | 145 +++++---------------- .../apache/maven/plugin/surefire/ProviderInfo.java | 4 +- .../surefire/SurefireDependencyResolver.java | 78 +++++------ .../maven/plugin/surefire/SurefireHelper.java | 18 +-- maven-surefire-plugin/pom.xml | 4 + maven-surefire-report-plugin/pom.xml | 57 +++++++- pom.xml | 33 +++-- 10 files changed, 173 insertions(+), 206 deletions(-) diff --git a/maven-failsafe-plugin/pom.xml b/maven-failsafe-plugin/pom.xml index 19de66f..baa9260 100644 --- a/maven-failsafe-plugin/pom.xml +++ b/maven-failsafe-plugin/pom.xml @@ -75,6 +75,10 @@ <artifactId>mockito-core</artifactId> <scope>test</scope> </dependency> + <dependency> + <groupId>org.apache.maven.shared</groupId> + <artifactId>maven-artifact-transfer</artifactId> + </dependency> </dependencies> <build> @@ -170,7 +174,8 @@ </goals> <configuration> <target name="generate-failsafe-test-report"> - <move file="${project.build.directory}/source-site/resources/xsd/surefire-test-report.xsd" tofile="${project.build.directory}/source-site/resources/xsd/failsafe-test-report.xsd" /> + <move file="${project.build.directory}/source-site/resources/xsd/surefire-test-report.xsd" + tofile="${project.build.directory}/source-site/resources/xsd/failsafe-test-report.xsd"/> </target> </configuration> </execution> @@ -257,15 +262,7 @@ </build> </profile> <profile> - <!-- run integration tests - to use this profile: - or run integration tests: mvn -Prun-its - --> <id>run-its</id> - <properties> - <!-- skip tests with -DskipTests --> - <skipTests>false</skipTests> - </properties> <build> <defaultGoal>verify</defaultGoal> <plugins> diff --git a/maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/VerifyMojo.java b/maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/VerifyMojo.java index bbf47eb..dbb6b7e 100644 --- a/maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/VerifyMojo.java +++ b/maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/VerifyMojo.java @@ -151,7 +151,7 @@ public class VerifyMojo /** * The current build session instance. */ - @Component + @Parameter( defaultValue = "${session}", readonly = true ) private MavenSession session; @Component diff --git a/maven-surefire-common/pom.xml b/maven-surefire-common/pom.xml index 163b830..d0a4b60 100644 --- a/maven-surefire-common/pom.xml +++ b/maven-surefire-common/pom.xml @@ -37,6 +37,14 @@ </prerequisites> <dependencies> + <!--<dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-compat</artifactId> + </dependency>--> + <dependency> + <groupId>org.apache.maven.shared</groupId> + <artifactId>maven-artifact-transfer</artifactId> + </dependency> <dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-plugin-api</artifactId> @@ -61,14 +69,14 @@ <groupId>org.apache.maven</groupId> <artifactId>maven-artifact</artifactId> </dependency> - <dependency> + <!--<dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-plugin-descriptor</artifactId> </dependency> <dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-project</artifactId> - </dependency> + </dependency>--> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> @@ -97,6 +105,12 @@ <dependency> <groupId>org.apache.maven.shared</groupId> <artifactId>maven-common-artifact-filters</artifactId> + <exclusions> + <exclusion> + <groupId>org.apache.maven.shared</groupId> + <artifactId>maven-plugin-testing-harness</artifactId> + </exclusion> + </exclusions> </dependency> <dependency> <groupId>org.fusesource.jansi</groupId> @@ -208,11 +222,12 @@ <includes> <include>org.apache.maven.shared:maven-shared-utils</include> <include>org.apache.maven.shared:maven-common-artifact-filters</include> + <include>org.apache.maven.shared:maven-artifact-transfer</include> <include>commons-io:commons-io</include> <include>org.apache.commons:commons-lang3</include> </includes> </artifactSet> - <relocations> + <!--<relocations> <relocation> <pattern>org.apache.maven.shared</pattern> <shadedPattern>org.apache.maven.surefire.shade.org.apache.maven.shared</shadedPattern> @@ -225,7 +240,7 @@ <pattern>org.apache.commons.lang3</pattern> <shadedPattern>org.apache.maven.surefire.shade.org.apache.commons.lang3</shadedPattern> </relocation> - </relocations> + </relocations>--> </configuration> </execution> </executions> 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..7789e77 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 @@ -22,15 +22,12 @@ package org.apache.maven.plugin.surefire; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.factory.ArtifactFactory; -import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.resolver.AbstractArtifactResolutionException; -import org.apache.maven.artifact.resolver.ArtifactNotFoundException; -import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.artifact.resolver.ArtifactResolutionResult; -import org.apache.maven.artifact.resolver.ArtifactResolver; +import org.apache.maven.plugins.annotations.Component; +import org.apache.maven.repository.RepositorySystem; +import org.apache.maven.shared.artifact.resolve.ArtifactResolver; import org.apache.maven.artifact.resolver.filter.ArtifactFilter; -import org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter; import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter; import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.artifact.versioning.DefaultArtifactVersion; @@ -53,7 +50,6 @@ import org.apache.maven.plugin.surefire.log.PluginConsoleLogger; import org.apache.maven.plugin.surefire.log.api.ConsoleLogger; import org.apache.maven.plugin.surefire.util.DependencyScanner; import org.apache.maven.plugin.surefire.util.DirectoryScanner; -import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; import org.apache.maven.shared.artifact.filter.PatternIncludesArtifactFilter; @@ -95,7 +91,6 @@ import javax.annotation.Nonnull; import java.io.File; import java.io.IOException; import java.lang.reflect.Array; -import java.lang.reflect.Method; import java.math.BigDecimal; import java.util.ArrayList; import java.util.Collections; @@ -199,7 +194,7 @@ public abstract class AbstractSurefireMojo /** * The Maven Project Object. */ - @Component + @Parameter( defaultValue = "${project}", required = true, readonly = true ) private MavenProject project; /** @@ -330,14 +325,12 @@ public abstract class AbstractSurefireMojo /** * Map of plugin artifacts. */ - // olamy: would make more sense using defaultValue but doesn't work with maven 2.x @Parameter( property = "plugin.artifactMap", required = true, readonly = true ) private Map<String, Artifact> pluginArtifactMap; /** * Map of project artifacts. */ - // olamy: would make more sense using defaultValue but doesn't work with maven 2.x @Parameter( property = "project.artifactMap", readonly = true, required = true ) private Map<String, Artifact> projectArtifactMap; @@ -687,12 +680,6 @@ public abstract class AbstractSurefireMojo private List<ArtifactRepository> remoteRepositories; /** - * For retrieval of artifact's metadata. - */ - @Component - private ArtifactMetadataSource metadataSource; - - /** * Flag to disable the generation of report files in xml format. * * @since 2.2 @@ -712,7 +699,7 @@ public abstract class AbstractSurefireMojo /** * The current build session instance. */ - @Component + @Parameter( defaultValue = "${session}", required = true, readonly = true ) private MavenSession session; @Component @@ -727,7 +714,7 @@ public abstract class AbstractSurefireMojo private String objectFactory; /** - * + * Parallel Maven Execution. */ @Parameter( defaultValue = "${session.parallel}", readonly = true ) private Boolean parallelMavenExecution; @@ -754,9 +741,6 @@ public abstract class AbstractSurefireMojo @Parameter( property = "dependenciesToScan" ) private String[] dependenciesToScan; - /** - * - */ @Component private ToolchainManager toolchainManager; @@ -765,6 +749,9 @@ public abstract class AbstractSurefireMojo // @Component // private LocationManager locationManager; + @Component + private RepositorySystem repositorySystem; + private Artifact surefireBooterArtifact; private Toolchain toolchain; @@ -1043,9 +1030,9 @@ public abstract class AbstractSurefireMojo private void createDependencyResolver() { - dependencyResolver = new SurefireDependencyResolver( getArtifactResolver(), getArtifactFactory(), + dependencyResolver = new SurefireDependencyResolver( getRepositorySystem(), getArtifactFactory(), getConsoleLogger(), getLocalRepository(), - getRemoteRepositories(), getMetadataSource(), + getRemoteRepositories(), getPluginName() ); } @@ -1182,6 +1169,7 @@ public abstract class AbstractSurefireMojo return forkStarter.run( effectiveProperties, scanResult ); } + // tod Java 1.7 multiple exception catch block catch ( SurefireExecutionException e ) { forkStarter.killOrphanForks(); @@ -1238,6 +1226,16 @@ public abstract class AbstractSurefireMojo capitalizeFirstLetter( getPluginName() ) + " report directory: " + getReportsDirectory() ); } + public RepositorySystem getRepositorySystem() + { + return repositorySystem; + } + + public void setRepositorySystem( RepositorySystem repositorySystem ) + { + this.repositorySystem = repositorySystem; + } + final Toolchain getToolchain() { Toolchain tc = null; @@ -1730,10 +1728,6 @@ public abstract class AbstractSurefireMojo return newStartupConfigWithClasspath( classLoaderConfiguration, providerArtifacts, providerName ); } } - catch ( AbstractArtifactResolutionException e ) - { - throw new MojoExecutionException( "Unable to generate classpath: " + e, e ); - } catch ( IOException e ) { throw new MojoExecutionException( e.getMessage(), e ); @@ -2155,7 +2149,6 @@ public abstract class AbstractSurefireMojo Artifact shadeFire = getPluginArtifactMap().get( "org.apache.maven.surefire:surefire-shadefire" ); - // todo: 150 milli seconds, try to fetch List<String> within classpath asynchronously Classpath bootClasspath = getArtifactClasspath( shadeFire != null ? shadeFire : surefireBooterArtifact ); Platform platform = PLATFORM.withJdkExecAttributesForTests( getEffectiveJvm() ); @@ -2522,32 +2515,9 @@ public abstract class AbstractSurefireMojo } } - - private ArtifactResolutionResult resolveArtifact( Artifact filteredArtifact, Artifact providerArtifact ) + private ArtifactResolutionResult resolveArtifact( Artifact providerArtifact ) { - ArtifactFilter filter = null; - if ( filteredArtifact != null ) - { - filter = new ExcludesArtifactFilter( - Collections.singletonList( filteredArtifact.getGroupId() + ":" + filteredArtifact.getArtifactId() ) ); - } - - Artifact originatingArtifact = getArtifactFactory().createBuildArtifact( "dummy", "dummy", "1.0", "jar" ); - - try - { - return getArtifactResolver().resolveTransitively( Collections.singleton( providerArtifact ), - originatingArtifact, getLocalRepository(), - getRemoteRepositories(), getMetadataSource(), filter ); - } - catch ( ArtifactResolutionException e ) - { - throw new RuntimeException( e ); - } - catch ( ArtifactNotFoundException e ) - { - throw new RuntimeException( e ); - } + return dependencyResolver.resolveArtifact( providerArtifact ); } private Classpath getArtifactClasspath( Artifact surefireArtifact ) @@ -2555,17 +2525,12 @@ public abstract class AbstractSurefireMojo Classpath existing = ClasspathCache.getCachedClassPath( surefireArtifact.getArtifactId() ); if ( existing == null ) { - ArtifactResolutionResult result = resolveArtifact( null, surefireArtifact ); - List<String> items = new ArrayList<String>(); - for ( Object o : result.getArtifacts() ) + for ( Artifact artifact : resolveArtifact( surefireArtifact ).getArtifacts() ) { - Artifact artifact = (Artifact) o; - getConsoleLogger().debug( "Adding to " + getPluginName() + " booter test classpath: " + artifact.getFile().getAbsolutePath() + " Scope: " + artifact.getScope() ); - items.add( artifact.getFile().getAbsolutePath() ); } existing = new Classpath( items ); @@ -2576,34 +2541,9 @@ public abstract class AbstractSurefireMojo private Properties getUserProperties() { - Properties props = null; - try - { - // try calling MavenSession.getUserProperties() from Maven 2.1.0-M1+ - Method getUserProperties = getSession().getClass().getMethod( "getUserProperties" ); - props = (Properties) getUserProperties.invoke( getSession() ); - } - catch ( Exception e ) - { - String msg = "Build uses Maven 2.0.x, cannot propagate system properties" - + " from command line to tests (cf. SUREFIRE-121)"; - if ( getConsoleLogger().isDebugEnabled() ) - { - getConsoleLogger().debug( msg, e ); - } - else - { - getConsoleLogger().warning( msg ); - } - } - if ( props == null ) - { - props = new Properties(); - } - return props; + return getSession().getUserProperties(); } - private void ensureWorkingDirectoryExists() throws MojoFailureException { @@ -2811,11 +2751,10 @@ public abstract class AbstractSurefireMojo @Override @Nonnull public Set<Artifact> getProviderClasspath() - throws ArtifactResolutionException, ArtifactNotFoundException { Artifact surefireArtifact = getPluginArtifactMap().get( "org.apache.maven.surefire:surefire-booter" ); String version = surefireArtifact.getBaseVersion(); - return dependencyResolver.getProviderClasspath( "surefire-testng", version, testNgArtifact ); + return dependencyResolver.getProviderClasspath( "surefire-testng", version ); } } @@ -2842,12 +2781,11 @@ public abstract class AbstractSurefireMojo @Override @Nonnull public Set<Artifact> getProviderClasspath() - throws ArtifactResolutionException, ArtifactNotFoundException { // add the JUnit provider as default - it doesn't require JUnit to be present, // since it supports POJO tests. String version = surefireBooterArtifact.getBaseVersion(); - return dependencyResolver.getProviderClasspath( "surefire-junit3", version, null ); + return dependencyResolver.getProviderClasspath( "surefire-junit3", version ); } } @@ -2884,10 +2822,9 @@ public abstract class AbstractSurefireMojo @Override @Nonnull public Set<Artifact> getProviderClasspath() - throws ArtifactResolutionException, ArtifactNotFoundException { String version = surefireBooterArtifact.getBaseVersion(); - return dependencyResolver.getProviderClasspath( "surefire-junit4", version, null ); + return dependencyResolver.getProviderClasspath( "surefire-junit4", version ); } } @@ -2923,10 +2860,9 @@ public abstract class AbstractSurefireMojo @Override @Nonnull public Set<Artifact> getProviderClasspath() - throws ArtifactResolutionException, ArtifactNotFoundException { String version = surefireBooterArtifact.getBaseVersion(); - return dependencyResolver.getProviderClasspath( "surefire-junit-platform", version, null ); + return dependencyResolver.getProviderClasspath( "surefire-junit-platform", version ); } } @@ -2972,10 +2908,9 @@ public abstract class AbstractSurefireMojo @Override @Nonnull public Set<Artifact> getProviderClasspath() - throws ArtifactResolutionException, ArtifactNotFoundException { String version = surefireBooterArtifact.getBaseVersion(); - return dependencyResolver.getProviderClasspath( "surefire-junit47", version, null ); + return dependencyResolver.getProviderClasspath( "surefire-junit47", version ); } } @@ -3022,7 +2957,6 @@ public abstract class AbstractSurefireMojo @Override @Nonnull public Set<Artifact> getProviderClasspath() - throws ArtifactResolutionException, ArtifactNotFoundException { return dependencyResolver.addProviderToClasspath( pluginArtifactMap, getMojoArtifact() ); } @@ -3537,18 +3471,6 @@ public abstract class AbstractSurefireMojo this.remoteRepositories = remoteRepositories; } - public ArtifactMetadataSource getMetadataSource() - { - return metadataSource; - } - - @SuppressWarnings( "UnusedDeclaration" ) - public void setMetadataSource( ArtifactMetadataSource metadataSource ) - { - this.metadataSource = metadataSource; - } - - public boolean isDisableXmlReport() { return disableXmlReport; @@ -3633,11 +3555,6 @@ public abstract class AbstractSurefireMojo this.dependenciesToScan = dependenciesToScan; } - public PluginDescriptor getPluginDescriptor() - { - return pluginDescriptor; - } - public MavenProject getProject() { return project; diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/ProviderInfo.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/ProviderInfo.java index e99cc82..cb63cc1 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/ProviderInfo.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/ProviderInfo.java @@ -20,7 +20,6 @@ package org.apache.maven.plugin.surefire; */ import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.resolver.AbstractArtifactResolutionException; import org.apache.maven.plugin.MojoExecutionException; import javax.annotation.Nonnull; @@ -37,8 +36,7 @@ public interface ProviderInfo boolean isApplicable(); @Nonnull - Set<Artifact> getProviderClasspath() - throws AbstractArtifactResolutionException; + Set<Artifact> getProviderClasspath(); void addProviderProperties() throws MojoExecutionException; } 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 f33a316..fa3932c 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 @@ -19,31 +19,28 @@ package org.apache.maven.plugin.surefire; * under the License. */ +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.factory.ArtifactFactory; -import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.resolver.ArtifactNotFoundException; -import org.apache.maven.artifact.resolver.ArtifactResolutionException; +import org.apache.maven.artifact.resolver.ArtifactResolutionRequest; import org.apache.maven.artifact.resolver.ArtifactResolutionResult; -import org.apache.maven.artifact.resolver.ArtifactResolver; -import org.apache.maven.artifact.resolver.filter.ArtifactFilter; import org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter; import org.apache.maven.artifact.versioning.DefaultArtifactVersion; 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.plugin.surefire.log.api.ConsoleLogger; +import org.apache.maven.repository.RepositorySystem; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import java.util.Collections; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import static java.util.Collections.singleton; +import static java.util.Collections.singletonList; import static org.apache.maven.artifact.Artifact.SCOPE_TEST; import static org.apache.maven.artifact.versioning.VersionRange.createFromVersion; @@ -53,10 +50,9 @@ import static org.apache.maven.artifact.versioning.VersionRange.createFromVersio * @author Stephen Connolly * @author Kristian Rosenvold */ -public class SurefireDependencyResolver +final class SurefireDependencyResolver { - - private final ArtifactResolver artifactResolver; + private final RepositorySystem repositorySystem; private final ArtifactFactory artifactFactory; @@ -66,27 +62,21 @@ public class SurefireDependencyResolver private final List<ArtifactRepository> remoteRepositories; - private final ArtifactMetadataSource artifactMetadataSource; - private final String pluginName; - protected SurefireDependencyResolver( ArtifactResolver artifactResolver, ArtifactFactory artifactFactory, - ConsoleLogger log, + SurefireDependencyResolver( RepositorySystem repositorySystem, ArtifactFactory artifactFactory, ConsoleLogger log, ArtifactRepository localRepository, - List<ArtifactRepository> remoteRepositories, - ArtifactMetadataSource artifactMetadataSource, String pluginName ) + List<ArtifactRepository> remoteRepositories, String pluginName ) { - this.artifactResolver = artifactResolver; + this.repositorySystem = repositorySystem; this.artifactFactory = artifactFactory; this.log = log; this.localRepository = localRepository; this.remoteRepositories = remoteRepositories; - this.artifactMetadataSource = artifactMetadataSource; this.pluginName = pluginName; } - - public boolean isWithinVersionSpec( @Nullable Artifact artifact, @Nonnull String versionSpec ) + boolean isWithinVersionSpec( @Nullable Artifact artifact, @Nonnull String versionSpec ) { if ( artifact == null ) { @@ -114,39 +104,38 @@ public class SurefireDependencyResolver } } + ArtifactResolutionResult resolveArtifact( Artifact providerArtifact ) + { + return resolveArtifact( providerArtifact, null ); + } - private ArtifactResolutionResult resolveArtifact( Artifact filteredArtifact, Artifact providerArtifact ) - throws ArtifactResolutionException, ArtifactNotFoundException + private ArtifactResolutionResult resolveArtifact( Artifact providerArtifact, @Nullable Artifact excludeArtifact ) { - ArtifactFilter filter = null; - if ( filteredArtifact != null ) + ArtifactResolutionRequest request = new ArtifactResolutionRequest() + .setArtifact( providerArtifact ) + .setRemoteRepositories( remoteRepositories ) + .setLocalRepository( localRepository ) + .setResolveTransitively( true ); + if ( excludeArtifact != null ) { - filter = new ExcludesArtifactFilter( - Collections.singletonList( filteredArtifact.getGroupId() + ":" + filteredArtifact.getArtifactId() ) ); + String pattern = excludeArtifact.getGroupId() + ":" + excludeArtifact.getArtifactId(); + request.setCollectionFilter( new ExcludesArtifactFilter( singletonList( pattern ) ) ); } - - Artifact originatingArtifact = artifactFactory.createBuildArtifact( "dummy", "dummy", "1.0", "jar" ); - - return artifactResolver.resolveTransitively( singleton( providerArtifact ), originatingArtifact, - localRepository, remoteRepositories, artifactMetadataSource, - filter ); + return repositorySystem.resolve( request ); } @Nonnull - @SuppressWarnings( "unchecked" ) - public Set<Artifact> getProviderClasspath( String provider, String version, Artifact filteredArtifact ) - throws ArtifactNotFoundException, ArtifactResolutionException + Set<Artifact> getProviderClasspath( String provider, String version ) { Artifact providerArtifact = artifactFactory.createDependencyArtifact( "org.apache.maven.surefire", provider, createFromVersion( version ), "jar", null, SCOPE_TEST ); - ArtifactResolutionResult result = resolveArtifact( filteredArtifact, providerArtifact ); + ArtifactResolutionResult result = resolveArtifact( providerArtifact ); if ( log.isDebugEnabled() ) { - for ( Object o : result.getArtifacts() ) + for ( Artifact artifact : result.getArtifacts() ) { - Artifact artifact = (Artifact) o; String artifactPath = artifact.getFile().getAbsolutePath(); String scope = artifact.getScope(); log.debug( "Adding to " + pluginName + " test classpath: " + artifactPath + " Scope: " + scope ); @@ -156,13 +145,12 @@ public class SurefireDependencyResolver return result.getArtifacts(); } - public Set<Artifact> addProviderToClasspath( Map<String, Artifact> pluginArtifactMap, Artifact surefireArtifact ) - throws ArtifactResolutionException, ArtifactNotFoundException + Set<Artifact> addProviderToClasspath( Map<String, Artifact> pluginArtifactMap, Artifact surefireArtifact ) { Set<Artifact> providerArtifacts = new LinkedHashSet<Artifact>(); if ( surefireArtifact != null ) { - ArtifactResolutionResult artifactResolutionResult = resolveArtifact( null, surefireArtifact ); + final ArtifactResolutionResult artifactResolutionResult = resolveArtifact( surefireArtifact ); for ( Artifact artifact : pluginArtifactMap.values() ) { if ( !artifactResolutionResult.getArtifacts().contains( artifact ) ) diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireHelper.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireHelper.java index 44dbdd4..29bc8d9 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireHelper.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireHelper.java @@ -31,7 +31,6 @@ import org.apache.maven.surefire.util.internal.DumpFileUtils; import javax.annotation.Nonnull; import java.io.File; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collection; @@ -195,7 +194,7 @@ public final class SurefireHelper cli.add( SHOW_ERRORS ); } - String f = getFailureBehavior( request ); + String f = request.getReactorFailureBehavior(); if ( f != null ) { // compatible with enums Maven 3.0 @@ -250,21 +249,6 @@ public final class SurefireHelper return path; } - private static String getFailureBehavior( MavenExecutionRequest request ) - throws NoSuchMethodException, InvocationTargetException, IllegalAccessException - { - try - { - return request.getFailureBehavior(); - } - catch ( NoSuchMethodError e ) - { - return (String) request.getClass() - .getMethod( "getReactorFailureBehavior" ) - .invoke( request ); - } - } - private static boolean failIfNoTests( SurefireReportParameters reportParameters ) { return reportParameters.getFailIfNoTests() != null && reportParameters.getFailIfNoTests(); diff --git a/maven-surefire-plugin/pom.xml b/maven-surefire-plugin/pom.xml index 9ac4d00..e3e6979 100644 --- a/maven-surefire-plugin/pom.xml +++ b/maven-surefire-plugin/pom.xml @@ -48,6 +48,10 @@ <groupId>org.apache.maven.surefire</groupId> <artifactId>maven-surefire-common</artifactId> </dependency> + <dependency> + <groupId>org.apache.maven.shared</groupId> + <artifactId>maven-artifact-transfer</artifactId> + </dependency> </dependencies> <build> diff --git a/maven-surefire-report-plugin/pom.xml b/maven-surefire-report-plugin/pom.xml index 9e04880..fcb1f96 100644 --- a/maven-surefire-report-plugin/pom.xml +++ b/maven-surefire-report-plugin/pom.xml @@ -49,8 +49,24 @@ <dependencies> <dependency> <groupId>org.apache.maven</groupId> - <artifactId>maven-project</artifactId> + <artifactId>maven-core</artifactId> + <!-- + If 3.1.1: + org.codehaus.plexus.component.repository.exception.ComponentLookupException: java.util.NoSuchElementException + role: org.apache.maven.repository.RepositorySystem + roleHint: + <version>3.1.1</version> + + If 3.0.0: +java.lang.NoSuchMethodError: org.codehaus.plexus.ContainerConfiguration.setClassPathScanning(Ljava/lang/String;)Lorg/codehaus/plexus/ContainerConfiguration; +See DefaultContainerConfiguration and AbstractMojoTestCase#L248 + + --> </dependency> + <!--<dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-project</artifactId> + </dependency>--> <dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-model</artifactId> @@ -78,6 +94,12 @@ <groupId>org.apache.maven.reporting</groupId> <artifactId>maven-reporting-impl</artifactId> <version>2.4</version> + <exclusions> + <exclusion> + <artifactId>maven-project</artifactId> + <groupId>org.apache.maven</groupId> + </exclusion> + </exclusions> </dependency> <dependency> <groupId>org.apache.maven.doxia</groupId> @@ -97,18 +119,49 @@ <version>1.13</version> <scope>provided</scope> </dependency> + <!-- TESTING --> <dependency> <groupId>org.apache.maven.plugin-testing</groupId> <artifactId>maven-plugin-testing-harness</artifactId> - <version>1.2</version> + <version>2.1</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-compat</artifactId> <scope>test</scope> </dependency> + <!--<dependency> + <!– maven-plugin-testing-harness depends on maven-core which is dependent on scope=runtime Aether –> + <groupId>org.apache.maven</groupId> + <artifactId>maven-aether-provider</artifactId> + <version>3.0</version> + <scope>test</scope> + </dependency>--> <dependency> <groupId>org.xmlunit</groupId> <artifactId>xmlunit-core</artifactId> <version>2.6.0</version> <scope>test</scope> </dependency> + <!--<dependency> + <groupId>org.sonatype.aether</groupId> + <artifactId>aether-api</artifactId> + <version>1.7</version> + <scope>test</scope> + </dependency>--> + <!--<dependency> + <groupId>org.eclipse.aether</groupId> + <artifactId>aether-api</artifactId> + <version>0.9.0.M2</version> + <scope>test</scope> + </dependency>--> + <!--<dependency> + <groupId>org.sonatype.sisu</groupId> + <artifactId>sisu-inject-plexus</artifactId> + <version>1.4.2</version> + <scope>test</scope> + </dependency>--> </dependencies> <build> diff --git a/pom.xml b/pom.xml index 99c9746..c2ec0f2 100644 --- a/pom.xml +++ b/pom.xml @@ -84,11 +84,11 @@ </distributionManagement> <properties> - <mavenVersion>2.2.1</mavenVersion> + <mavenVersion>3.0</mavenVersion> <!-- <shadedVersion>2.12.4</shadedVersion> commented out due to https://issues.apache.org/jira/browse/MRELEASE-799 --> <commonsLang3Version>3.5</commonsLang3Version> <commonsIoVersion>2.5</commonsIoVersion> - <mavenSharedUtilsVersion>0.9</mavenSharedUtilsVersion> + <mavenSharedUtilsVersion>3.0.0</mavenSharedUtilsVersion> <powermockVersion>2.0.0-beta.5</powermockVersion> <maven.surefire.scm.devConnection>scm:git:https://gitbox.apache.org/repos/asf/maven-surefire.git</maven.surefire.scm.devConnection> <maven.site.path>surefire-archives/surefire-LATEST</maven.site.path> @@ -139,13 +139,13 @@ <dependency> <groupId>org.apache.maven.reporting</groupId> <artifactId>maven-reporting-api</artifactId> - <version>3.0</version> + <version>${mavenVersion}</version> </dependency> <dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-core</artifactId> <version>${mavenVersion}</version> - <exclusions> + <!--<exclusions> <exclusion> <groupId>org.apache.maven.wagon</groupId> <artifactId>wagon-file</artifactId> @@ -178,7 +178,7 @@ <groupId>org.codehaus.plexus</groupId> <artifactId>plexus-interactivity-api</artifactId> </exclusion> - </exclusions> + </exclusions>--> </dependency> <dependency> <groupId>org.apache.maven</groupId> @@ -196,25 +196,36 @@ <artifactId>maven-artifact</artifactId> <version>${mavenVersion}</version> </dependency> - <dependency> + <!--<dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-plugin-descriptor</artifactId> - <version>${mavenVersion}</version> - </dependency> - <dependency> + <version>2.2.1</version> + </dependency>--> + <!--<dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-project</artifactId> + <version>2.2.1</version> + </dependency>--> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-model</artifactId> <version>${mavenVersion}</version> </dependency> <dependency> <groupId>org.apache.maven</groupId> - <artifactId>maven-model</artifactId> + <artifactId>maven-compat</artifactId> <version>${mavenVersion}</version> + <scope>test</scope> </dependency> <dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-toolchain</artifactId> - <version>${mavenVersion}</version> + <version>2.2.1</version> + </dependency> + <dependency> + <groupId>org.apache.maven.shared</groupId> + <artifactId>maven-artifact-transfer</artifactId> + <version>3.0-SNAPSHOT</version> </dependency> <dependency> <groupId>org.apache.maven</groupId>