3535import java .util .List ;
3636import java .util .Map ;
3737import java .util .Map .Entry ;
38+ import java .util .Optional ;
3839import java .util .Properties ;
3940import java .util .Set ;
4041import java .util .SortedSet ;
4546import org .apache .maven .artifact .Artifact ;
4647import org .apache .maven .artifact .DefaultArtifact ;
4748import org .apache .maven .artifact .handler .ArtifactHandler ;
48- import org .apache .maven .artifact .repository .ArtifactRepository ;
49- import org .apache .maven .artifact .resolver .ResolutionErrorHandler ;
5049import org .apache .maven .artifact .resolver .filter .ArtifactFilter ;
5150import org .apache .maven .artifact .resolver .filter .ScopeArtifactFilter ;
5251import org .apache .maven .artifact .versioning .ArtifactVersion ;
7776import org .apache .maven .plugins .annotations .Component ;
7877import org .apache .maven .plugins .annotations .Parameter ;
7978import org .apache .maven .project .MavenProject ;
80- import org .apache .maven .repository .RepositorySystem ;
8179import org .apache .maven .shared .artifact .filter .PatternIncludesArtifactFilter ;
8280import org .apache .maven .surefire .api .booter .ProviderParameterNames ;
8381import org .apache .maven .surefire .api .booter .Shutdown ;
@@ -282,13 +280,6 @@ public abstract class AbstractSurefireMojo extends AbstractMojo implements Suref
282280 @ Parameter (defaultValue = "${project.build.testSourceDirectory}" )
283281 private File testSourceDirectory ;
284282
285- /**
286- * ArtifactRepository of the localRepository. To obtain the directory of localRepository in unit tests use
287- * System.getProperty("localRepository").
288- */
289- @ Parameter (defaultValue = "${localRepository}" , required = true , readonly = true )
290- private ArtifactRepository localRepository ;
291-
292283 /**
293284 * List of System properties to pass to a provider.
294285 *
@@ -635,17 +626,6 @@ public abstract class AbstractSurefireMojo extends AbstractMojo implements Suref
635626 @ Parameter (property = "trimStackTrace" , defaultValue = "false" )
636627 private boolean trimStackTrace ;
637628
638- /**
639- * The remote plugin repositories declared in the POM.
640- *
641- * @since 2.2
642- */
643- @ Parameter (defaultValue = "${project.pluginArtifactRepositories}" , readonly = true , required = true )
644- private List <ArtifactRepository > remoteRepositories ;
645-
646- @ Parameter (defaultValue = "${project.remoteArtifactRepositories}" , required = true , readonly = true )
647- private List <ArtifactRepository > projectRemoteRepositories ;
648-
649629 /**
650630 * Flag to disable the generation of report files in xml format.
651631 * Deprecated since 3.0.0-M4.
@@ -771,15 +751,9 @@ public abstract class AbstractSurefireMojo extends AbstractMojo implements Suref
771751 @ Component
772752 private LocationManager locationManager ;
773753
774- @ Component
775- private RepositorySystem repositorySystem ;
776-
777754 @ Component
778755 private ProviderDetector providerDetector ;
779756
780- @ Component
781- private ResolutionErrorHandler resolutionErrorHandler ;
782-
783757 private Toolchain toolchain ;
784758
785759 private int effectiveForkCount = -1 ;
@@ -855,6 +829,7 @@ private String getDefaultExcludes() {
855829 return "**/*$*" ;
856830 }
857831
832+ @ Component (role = SurefireDependencyResolver .class )
858833 private SurefireDependencyResolver surefireDependencyResolver ;
859834
860835 private TestListResolver specificTests ;
@@ -905,6 +880,10 @@ void setLogger(Logger logger) {
905880 this .logger = logger ;
906881 }
907882
883+ void setSurefireDependencyResolver (SurefireDependencyResolver surefireDependencyResolver ) {
884+ this .surefireDependencyResolver = surefireDependencyResolver ;
885+ }
886+
908887 @ Nonnull
909888 protected final PluginConsoleLogger getConsoleLogger () {
910889 if (consoleLogger == null ) {
@@ -952,15 +931,6 @@ private Toolchain getToolchain() throws MojoFailureException {
952931 }
953932
954933 private void setupStuff () throws MojoFailureException {
955- surefireDependencyResolver = new SurefireDependencyResolver (
956- getRepositorySystem (),
957- getConsoleLogger (),
958- getLocalRepository (),
959- getRemoteRepositories (),
960- getProjectRemoteRepositories (),
961- resolutionErrorHandler ,
962- getPluginName (),
963- getSession ().isOffline ());
964934
965935 if (getBooterArtifact () == null ) {
966936 throw new RuntimeException ("Unable to locate surefire-booter in the list of plugin artifacts" );
@@ -1125,7 +1095,7 @@ private SurefireProperties setupProperties() {
11251095 getSystemProperties (), getSystemPropertyVariables (), getUserProperties (), sysProps );
11261096
11271097 result .setProperty ("basedir" , getBasedir ().getAbsolutePath ());
1128- result .setProperty ("localRepository" , getLocalRepository (). getBasedir ());
1098+ result .setProperty ("localRepository" , getLocalRepositoryPath ());
11291099 if (isForking ()) {
11301100 for (Object o : result .propertiesThatCannotBeSetASystemProperties ()) {
11311101 if (getArgLine () == null || !getArgLine ().contains ("-D" + o + "=" )) {
@@ -1269,14 +1239,6 @@ protected void logReportsDirectory() {
12691239 logDebugOrCliShowErrors (capitalizeFirstLetter (getPluginName ()) + " report directory: " + getReportsDirectory ());
12701240 }
12711241
1272- public RepositorySystem getRepositorySystem () {
1273- return repositorySystem ;
1274- }
1275-
1276- public void setRepositorySystem (RepositorySystem repositorySystem ) {
1277- this .repositorySystem = repositorySystem ;
1278- }
1279-
12801242 private boolean existsModuleDescriptor (ResolvePathResultWrapper resolvedJavaModularityResult ) {
12811243 return resolvedJavaModularityResult .getResolvePathResult () != null ;
12821244 }
@@ -2467,7 +2429,7 @@ private String getConfigChecksum() {
24672429 checksum .add (getSkipAfterFailureCount ());
24682430 checksum .add (getShutdown ());
24692431 checksum .add (getExcludes ());
2470- checksum .add (getLocalRepository ());
2432+ checksum .add (getLocalRepositoryPath ());
24712433 checksum .add (getSystemProperties ());
24722434 checksum .add (getSystemPropertyVariables ());
24732435 checksum .add (getSystemPropertiesFile ());
@@ -2505,8 +2467,6 @@ private String getConfigChecksum() {
25052467 checksum .add (getParallel ());
25062468 checksum .add (isParallelOptimized ());
25072469 checksum .add (isTrimStackTrace ());
2508- checksum .add (getRemoteRepositories ());
2509- checksum .add (getProjectRemoteRepositories ());
25102470 checksum .add (isDisableXmlReport ());
25112471 checksum .add (isUseSystemClassLoader ());
25122472 checksum .add (isUseManifestOnlyJar ());
@@ -2610,13 +2570,9 @@ private Classpath getArtifactClasspath(Artifact surefireArtifact) throws MojoExe
26102570 Classpath existing = classpathCache .getCachedClassPath (surefireArtifact .getArtifactId ());
26112571 if (existing == null ) {
26122572 List <String > items = new ArrayList <>();
2613- Set <Artifact > booterArtifacts = surefireDependencyResolver
2614- .resolvePluginArtifact (surefireArtifact )
2615- .getArtifacts ();
2573+ Set <Artifact > booterArtifacts = surefireDependencyResolver .resolveArtifacts (
2574+ session .getRepositorySession (), project .getRemotePluginRepositories (), surefireArtifact );
26162575 for (Artifact artifact : booterArtifacts ) {
2617- getConsoleLogger ()
2618- .debug ("Adding to " + getPluginName () + " booter test classpath: "
2619- + artifact .getFile ().getAbsolutePath () + " Scope: " + artifact .getScope ());
26202576 items .add (artifact .getFile ().getAbsolutePath ());
26212577 }
26222578 existing = new Classpath (items );
@@ -2797,7 +2753,8 @@ public List<String[]> getJpmsArguments(@Nonnull ProviderRequirements forkRequire
27972753 public Set <Artifact > getProviderClasspath () throws MojoExecutionException {
27982754 Artifact surefireArtifact = getBooterArtifact ();
27992755 String version = surefireArtifact .getBaseVersion ();
2800- return surefireDependencyResolver .getProviderClasspath ("surefire-testng" , version );
2756+ return surefireDependencyResolver .getProviderClasspath (
2757+ session .getRepositorySession (), project .getRemotePluginRepositories (), "surefire-testng" , version );
28012758 }
28022759 }
28032760
@@ -2828,7 +2785,8 @@ public Set<Artifact> getProviderClasspath() throws MojoExecutionException {
28282785 // add the JUnit provider as default - it doesn't require JUnit to be present,
28292786 // since it supports POJO tests.
28302787 String version = getBooterArtifact ().getBaseVersion ();
2831- return surefireDependencyResolver .getProviderClasspath ("surefire-junit3" , version );
2788+ return surefireDependencyResolver .getProviderClasspath (
2789+ session .getRepositorySession (), project .getRemotePluginRepositories (), "surefire-junit3" , version );
28322790 }
28332791 }
28342792
@@ -2866,7 +2824,8 @@ public List<String[]> getJpmsArguments(@Nonnull ProviderRequirements forkRequire
28662824 @ Nonnull
28672825 public Set <Artifact > getProviderClasspath () throws MojoExecutionException {
28682826 String version = getBooterArtifact ().getBaseVersion ();
2869- return surefireDependencyResolver .getProviderClasspath ("surefire-junit4" , version );
2827+ return surefireDependencyResolver .getProviderClasspath (
2828+ session .getRepositorySession (), project .getRemotePluginRepositories (), "surefire-junit4" , version );
28702829 }
28712830 }
28722831
@@ -2915,13 +2874,19 @@ public List<String[]> getJpmsArguments(@Nonnull ProviderRequirements forkRequire
29152874 @ Nonnull
29162875 public Set <Artifact > getProviderClasspath () throws MojoExecutionException {
29172876 String surefireVersion = getBooterArtifact ().getBaseVersion ();
2918- Map <String , Artifact > providerArtifacts =
2919- surefireDependencyResolver .getProviderClasspathAsMap ("surefire-junit-platform" , surefireVersion );
2877+ Map <String , Artifact > providerArtifacts = surefireDependencyResolver .getProviderClasspathAsMap (
2878+ session .getRepositorySession (),
2879+ project .getRemotePluginRepositories (),
2880+ "surefire-junit-platform" ,
2881+ surefireVersion );
29202882 Map <String , Artifact > testDeps = testClasspath .getTestDependencies ();
29212883
29222884 Plugin plugin = getPluginDescriptor ().getPlugin ();
2923- Map <String , Artifact > pluginDeps =
2924- surefireDependencyResolver .resolvePluginDependencies (plugin , getPluginArtifactMap ());
2885+ Map <String , Artifact > pluginDeps = surefireDependencyResolver .resolvePluginDependencies (
2886+ session .getRepositorySession (),
2887+ project .getRemotePluginRepositories (),
2888+ plugin ,
2889+ getPluginArtifactMap ());
29252890
29262891 if (hasDependencyPlatformEngine (pluginDeps )) {
29272892 providerArtifacts .putAll (pluginDeps );
@@ -3006,8 +2971,8 @@ private Set<Artifact> resolve(String g, String a, String v, String c, String t)
30062971 ArtifactHandler handler = junitPlatformArtifact .getArtifactHandler ();
30072972 Artifact artifact = new DefaultArtifact (g , a , v , null , t , c , handler );
30082973 getConsoleLogger ().debug ("Resolving artifact " + g + ":" + a + ":" + v );
3009- Set <Artifact > r =
3010- surefireDependencyResolver . resolveProjectArtifact ( artifact ). getArtifacts ( );
2974+ Set <Artifact > r = surefireDependencyResolver . resolveArtifacts (
2975+ session . getRepositorySession (), project . getRemoteProjectRepositories (), artifact );
30112976 getConsoleLogger ().debug ("Resolved artifact " + g + ":" + a + ":" + v + " to " + r );
30122977 return r ;
30132978 }
@@ -3071,7 +3036,8 @@ public List<String[]> getJpmsArguments(@Nonnull ProviderRequirements forkRequire
30713036 @ Nonnull
30723037 public Set <Artifact > getProviderClasspath () throws MojoExecutionException {
30733038 String version = getBooterArtifact ().getBaseVersion ();
3074- return surefireDependencyResolver .getProviderClasspath ("surefire-junit47" , version );
3039+ return surefireDependencyResolver .getProviderClasspath (
3040+ session .getRepositorySession (), project .getRemotePluginRepositories (), "surefire-junit47" , version );
30753041 }
30763042 }
30773043
@@ -3118,8 +3084,11 @@ public List<String[]> getJpmsArguments(@Nonnull ProviderRequirements forkRequire
31183084 @ Nonnull
31193085 public Set <Artifact > getProviderClasspath () throws MojoExecutionException {
31203086 Plugin plugin = getPluginDescriptor ().getPlugin ();
3121- Map <String , Artifact > providerArtifacts =
3122- surefireDependencyResolver .resolvePluginDependencies (plugin , getPluginArtifactMap ());
3087+ Map <String , Artifact > providerArtifacts = surefireDependencyResolver .resolvePluginDependencies (
3088+ session .getRepositorySession (),
3089+ project .getRemotePluginRepositories (),
3090+ plugin ,
3091+ getPluginArtifactMap ());
31233092 return new LinkedHashSet <>(providerArtifacts .values ());
31243093 }
31253094 }
@@ -3140,13 +3109,11 @@ File createSurefireBootDirectoryInTemp() {
31403109 }
31413110
31423111 @ Override
3143- public ArtifactRepository getLocalRepository () {
3144- return localRepository ;
3145- }
3146-
3147- @ Override
3148- public void setLocalRepository (ArtifactRepository localRepository ) {
3149- this .localRepository = localRepository ;
3112+ public String getLocalRepositoryPath () {
3113+ return Optional .ofNullable (
3114+ session .getRepositorySession ().getLocalRepository ().getBasedir ())
3115+ .map (File ::getAbsolutePath )
3116+ .orElse ("." );
31503117 }
31513118
31523119 public Properties getSystemProperties () {
@@ -3383,24 +3350,6 @@ public void setTrimStackTrace(boolean trimStackTrace) {
33833350 this .trimStackTrace = trimStackTrace ;
33843351 }
33853352
3386- public List <ArtifactRepository > getProjectRemoteRepositories () {
3387- return projectRemoteRepositories ;
3388- }
3389-
3390- @ SuppressWarnings ("UnusedDeclaration" )
3391- public void setProjectRemoteRepositories (List <ArtifactRepository > projectRemoteRepositories ) {
3392- this .projectRemoteRepositories = projectRemoteRepositories ;
3393- }
3394-
3395- public List <ArtifactRepository > getRemoteRepositories () {
3396- return remoteRepositories ;
3397- }
3398-
3399- @ SuppressWarnings ("UnusedDeclaration" )
3400- public void setRemoteRepositories (List <ArtifactRepository > remoteRepositories ) {
3401- this .remoteRepositories = remoteRepositories ;
3402- }
3403-
34043353 public boolean isDisableXmlReport () {
34053354 return disableXmlReport ;
34063355 }
@@ -3556,10 +3505,6 @@ public void setTempDir(String tempDir) {
35563505 this .tempDir = tempDir ;
35573506 }
35583507
3559- public void setResolutionErrorHandler (ResolutionErrorHandler resolutionErrorHandler ) {
3560- this .resolutionErrorHandler = resolutionErrorHandler ;
3561- }
3562-
35633508 private static final class ClasspathCache {
35643509 private final Map <String , Classpath > classpaths = new HashMap <>(4 );
35653510
0 commit comments