35
35
import java .util .List ;
36
36
import java .util .Map ;
37
37
import java .util .Map .Entry ;
38
+ import java .util .Optional ;
38
39
import java .util .Properties ;
39
40
import java .util .Set ;
40
41
import java .util .SortedSet ;
45
46
import org .apache .maven .artifact .Artifact ;
46
47
import org .apache .maven .artifact .DefaultArtifact ;
47
48
import org .apache .maven .artifact .handler .ArtifactHandler ;
48
- import org .apache .maven .artifact .repository .ArtifactRepository ;
49
- import org .apache .maven .artifact .resolver .ResolutionErrorHandler ;
50
49
import org .apache .maven .artifact .resolver .filter .ArtifactFilter ;
51
50
import org .apache .maven .artifact .resolver .filter .ScopeArtifactFilter ;
52
51
import org .apache .maven .artifact .versioning .ArtifactVersion ;
77
76
import org .apache .maven .plugins .annotations .Component ;
78
77
import org .apache .maven .plugins .annotations .Parameter ;
79
78
import org .apache .maven .project .MavenProject ;
80
- import org .apache .maven .repository .RepositorySystem ;
81
79
import org .apache .maven .shared .artifact .filter .PatternIncludesArtifactFilter ;
82
80
import org .apache .maven .surefire .api .booter .ProviderParameterNames ;
83
81
import org .apache .maven .surefire .api .booter .Shutdown ;
@@ -282,13 +280,6 @@ public abstract class AbstractSurefireMojo extends AbstractMojo implements Suref
282
280
@ Parameter (defaultValue = "${project.build.testSourceDirectory}" )
283
281
private File testSourceDirectory ;
284
282
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
-
292
283
/**
293
284
* List of System properties to pass to a provider.
294
285
*
@@ -635,17 +626,6 @@ public abstract class AbstractSurefireMojo extends AbstractMojo implements Suref
635
626
@ Parameter (property = "trimStackTrace" , defaultValue = "false" )
636
627
private boolean trimStackTrace ;
637
628
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
-
649
629
/**
650
630
* Flag to disable the generation of report files in xml format.
651
631
* Deprecated since 3.0.0-M4.
@@ -771,15 +751,9 @@ public abstract class AbstractSurefireMojo extends AbstractMojo implements Suref
771
751
@ Component
772
752
private LocationManager locationManager ;
773
753
774
- @ Component
775
- private RepositorySystem repositorySystem ;
776
-
777
754
@ Component
778
755
private ProviderDetector providerDetector ;
779
756
780
- @ Component
781
- private ResolutionErrorHandler resolutionErrorHandler ;
782
-
783
757
private Toolchain toolchain ;
784
758
785
759
private int effectiveForkCount = -1 ;
@@ -855,6 +829,7 @@ private String getDefaultExcludes() {
855
829
return "**/*$*" ;
856
830
}
857
831
832
+ @ Component (role = SurefireDependencyResolver .class )
858
833
private SurefireDependencyResolver surefireDependencyResolver ;
859
834
860
835
private TestListResolver specificTests ;
@@ -905,6 +880,10 @@ void setLogger(Logger logger) {
905
880
this .logger = logger ;
906
881
}
907
882
883
+ void setSurefireDependencyResolver (SurefireDependencyResolver surefireDependencyResolver ) {
884
+ this .surefireDependencyResolver = surefireDependencyResolver ;
885
+ }
886
+
908
887
@ Nonnull
909
888
protected final PluginConsoleLogger getConsoleLogger () {
910
889
if (consoleLogger == null ) {
@@ -952,15 +931,6 @@ private Toolchain getToolchain() throws MojoFailureException {
952
931
}
953
932
954
933
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 ());
964
934
965
935
if (getBooterArtifact () == null ) {
966
936
throw new RuntimeException ("Unable to locate surefire-booter in the list of plugin artifacts" );
@@ -1125,7 +1095,7 @@ private SurefireProperties setupProperties() {
1125
1095
getSystemProperties (), getSystemPropertyVariables (), getUserProperties (), sysProps );
1126
1096
1127
1097
result .setProperty ("basedir" , getBasedir ().getAbsolutePath ());
1128
- result .setProperty ("localRepository" , getLocalRepository (). getBasedir ());
1098
+ result .setProperty ("localRepository" , getLocalRepositoryPath ());
1129
1099
if (isForking ()) {
1130
1100
for (Object o : result .propertiesThatCannotBeSetASystemProperties ()) {
1131
1101
if (getArgLine () == null || !getArgLine ().contains ("-D" + o + "=" )) {
@@ -1269,14 +1239,6 @@ protected void logReportsDirectory() {
1269
1239
logDebugOrCliShowErrors (capitalizeFirstLetter (getPluginName ()) + " report directory: " + getReportsDirectory ());
1270
1240
}
1271
1241
1272
- public RepositorySystem getRepositorySystem () {
1273
- return repositorySystem ;
1274
- }
1275
-
1276
- public void setRepositorySystem (RepositorySystem repositorySystem ) {
1277
- this .repositorySystem = repositorySystem ;
1278
- }
1279
-
1280
1242
private boolean existsModuleDescriptor (ResolvePathResultWrapper resolvedJavaModularityResult ) {
1281
1243
return resolvedJavaModularityResult .getResolvePathResult () != null ;
1282
1244
}
@@ -2467,7 +2429,7 @@ private String getConfigChecksum() {
2467
2429
checksum .add (getSkipAfterFailureCount ());
2468
2430
checksum .add (getShutdown ());
2469
2431
checksum .add (getExcludes ());
2470
- checksum .add (getLocalRepository ());
2432
+ checksum .add (getLocalRepositoryPath ());
2471
2433
checksum .add (getSystemProperties ());
2472
2434
checksum .add (getSystemPropertyVariables ());
2473
2435
checksum .add (getSystemPropertiesFile ());
@@ -2505,8 +2467,6 @@ private String getConfigChecksum() {
2505
2467
checksum .add (getParallel ());
2506
2468
checksum .add (isParallelOptimized ());
2507
2469
checksum .add (isTrimStackTrace ());
2508
- checksum .add (getRemoteRepositories ());
2509
- checksum .add (getProjectRemoteRepositories ());
2510
2470
checksum .add (isDisableXmlReport ());
2511
2471
checksum .add (isUseSystemClassLoader ());
2512
2472
checksum .add (isUseManifestOnlyJar ());
@@ -2610,13 +2570,9 @@ private Classpath getArtifactClasspath(Artifact surefireArtifact) throws MojoExe
2610
2570
Classpath existing = classpathCache .getCachedClassPath (surefireArtifact .getArtifactId ());
2611
2571
if (existing == null ) {
2612
2572
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 );
2616
2575
for (Artifact artifact : booterArtifacts ) {
2617
- getConsoleLogger ()
2618
- .debug ("Adding to " + getPluginName () + " booter test classpath: "
2619
- + artifact .getFile ().getAbsolutePath () + " Scope: " + artifact .getScope ());
2620
2576
items .add (artifact .getFile ().getAbsolutePath ());
2621
2577
}
2622
2578
existing = new Classpath (items );
@@ -2797,7 +2753,8 @@ public List<String[]> getJpmsArguments(@Nonnull ProviderRequirements forkRequire
2797
2753
public Set <Artifact > getProviderClasspath () throws MojoExecutionException {
2798
2754
Artifact surefireArtifact = getBooterArtifact ();
2799
2755
String version = surefireArtifact .getBaseVersion ();
2800
- return surefireDependencyResolver .getProviderClasspath ("surefire-testng" , version );
2756
+ return surefireDependencyResolver .getProviderClasspath (
2757
+ session .getRepositorySession (), project .getRemotePluginRepositories (), "surefire-testng" , version );
2801
2758
}
2802
2759
}
2803
2760
@@ -2828,7 +2785,8 @@ public Set<Artifact> getProviderClasspath() throws MojoExecutionException {
2828
2785
// add the JUnit provider as default - it doesn't require JUnit to be present,
2829
2786
// since it supports POJO tests.
2830
2787
String version = getBooterArtifact ().getBaseVersion ();
2831
- return surefireDependencyResolver .getProviderClasspath ("surefire-junit3" , version );
2788
+ return surefireDependencyResolver .getProviderClasspath (
2789
+ session .getRepositorySession (), project .getRemotePluginRepositories (), "surefire-junit3" , version );
2832
2790
}
2833
2791
}
2834
2792
@@ -2866,7 +2824,8 @@ public List<String[]> getJpmsArguments(@Nonnull ProviderRequirements forkRequire
2866
2824
@ Nonnull
2867
2825
public Set <Artifact > getProviderClasspath () throws MojoExecutionException {
2868
2826
String version = getBooterArtifact ().getBaseVersion ();
2869
- return surefireDependencyResolver .getProviderClasspath ("surefire-junit4" , version );
2827
+ return surefireDependencyResolver .getProviderClasspath (
2828
+ session .getRepositorySession (), project .getRemotePluginRepositories (), "surefire-junit4" , version );
2870
2829
}
2871
2830
}
2872
2831
@@ -2915,13 +2874,19 @@ public List<String[]> getJpmsArguments(@Nonnull ProviderRequirements forkRequire
2915
2874
@ Nonnull
2916
2875
public Set <Artifact > getProviderClasspath () throws MojoExecutionException {
2917
2876
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 );
2920
2882
Map <String , Artifact > testDeps = testClasspath .getTestDependencies ();
2921
2883
2922
2884
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 ());
2925
2890
2926
2891
if (hasDependencyPlatformEngine (pluginDeps )) {
2927
2892
providerArtifacts .putAll (pluginDeps );
@@ -3006,8 +2971,8 @@ private Set<Artifact> resolve(String g, String a, String v, String c, String t)
3006
2971
ArtifactHandler handler = junitPlatformArtifact .getArtifactHandler ();
3007
2972
Artifact artifact = new DefaultArtifact (g , a , v , null , t , c , handler );
3008
2973
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 );
3011
2976
getConsoleLogger ().debug ("Resolved artifact " + g + ":" + a + ":" + v + " to " + r );
3012
2977
return r ;
3013
2978
}
@@ -3071,7 +3036,8 @@ public List<String[]> getJpmsArguments(@Nonnull ProviderRequirements forkRequire
3071
3036
@ Nonnull
3072
3037
public Set <Artifact > getProviderClasspath () throws MojoExecutionException {
3073
3038
String version = getBooterArtifact ().getBaseVersion ();
3074
- return surefireDependencyResolver .getProviderClasspath ("surefire-junit47" , version );
3039
+ return surefireDependencyResolver .getProviderClasspath (
3040
+ session .getRepositorySession (), project .getRemotePluginRepositories (), "surefire-junit47" , version );
3075
3041
}
3076
3042
}
3077
3043
@@ -3118,8 +3084,11 @@ public List<String[]> getJpmsArguments(@Nonnull ProviderRequirements forkRequire
3118
3084
@ Nonnull
3119
3085
public Set <Artifact > getProviderClasspath () throws MojoExecutionException {
3120
3086
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 ());
3123
3092
return new LinkedHashSet <>(providerArtifacts .values ());
3124
3093
}
3125
3094
}
@@ -3140,13 +3109,11 @@ File createSurefireBootDirectoryInTemp() {
3140
3109
}
3141
3110
3142
3111
@ 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 ("." );
3150
3117
}
3151
3118
3152
3119
public Properties getSystemProperties () {
@@ -3383,24 +3350,6 @@ public void setTrimStackTrace(boolean trimStackTrace) {
3383
3350
this .trimStackTrace = trimStackTrace ;
3384
3351
}
3385
3352
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
-
3404
3353
public boolean isDisableXmlReport () {
3405
3354
return disableXmlReport ;
3406
3355
}
@@ -3556,10 +3505,6 @@ public void setTempDir(String tempDir) {
3556
3505
this .tempDir = tempDir ;
3557
3506
}
3558
3507
3559
- public void setResolutionErrorHandler (ResolutionErrorHandler resolutionErrorHandler ) {
3560
- this .resolutionErrorHandler = resolutionErrorHandler ;
3561
- }
3562
-
3563
3508
private static final class ClasspathCache {
3564
3509
private final Map <String , Classpath > classpaths = new HashMap <>(4 );
3565
3510
0 commit comments