26
26
import java .util .LinkedHashSet ;
27
27
import java .util .List ;
28
28
import java .util .Set ;
29
+ import java .util .stream .Collectors ;
29
30
31
+ import org .apache .maven .RepositoryUtils ;
30
32
import org .apache .maven .artifact .Artifact ;
31
33
import org .apache .maven .artifact .DefaultArtifact ;
32
34
import org .apache .maven .artifact .handler .DefaultArtifactHandler ;
33
- import org .apache .maven .artifact .resolver .ArtifactResolutionRequest ;
34
- import org .apache .maven .artifact .resolver .ArtifactResolutionResult ;
35
35
import org .apache .maven .artifact .resolver .ResolutionErrorHandler ;
36
36
import org .apache .maven .plugin .MojoExecutionException ;
37
37
import org .apache .maven .plugins .annotations .Component ;
38
38
import org .apache .maven .plugins .annotations .LifecyclePhase ;
39
39
import org .apache .maven .plugins .annotations .Mojo ;
40
40
import org .apache .maven .plugins .annotations .Parameter ;
41
41
import org .apache .maven .plugins .annotations .ResolutionScope ;
42
- import org .apache .maven .repository .RepositorySystem ;
42
+ import org .eclipse .aether .RepositorySystem ;
43
+ import org .eclipse .aether .collection .CollectRequest ;
44
+ import org .eclipse .aether .resolution .ArtifactResult ;
45
+ import org .eclipse .aether .resolution .DependencyRequest ;
46
+ import org .eclipse .aether .resolution .DependencyResult ;
47
+ import org .eclipse .aether .util .artifact .JavaScopes ;
48
+ import org .eclipse .aether .util .filter .DependencyFilterUtils ;
43
49
44
50
/**
45
51
* Invoke the AOT engine on tests.
@@ -97,20 +103,6 @@ public class ProcessTestAotMojo extends AbstractAotMojo {
97
103
@ Parameter (defaultValue = "${project.build.directory}/spring-aot/main/classes" , required = true )
98
104
private File generatedClasses ;
99
105
100
- /**
101
- * Local artifact repository used to resolve JUnit platform launcher jars.
102
- */
103
- @ SuppressWarnings ("deprecation" )
104
- @ Parameter (defaultValue = "${localRepository}" , required = true , readonly = true )
105
- private org .apache .maven .artifact .repository .ArtifactRepository localRepository ;
106
-
107
- /**
108
- * Remote artifact repositories used to resolve JUnit platform launcher jars.
109
- */
110
- @ SuppressWarnings ("deprecation" )
111
- @ Parameter (defaultValue = "${project.remoteArtifactRepositories}" , required = true , readonly = true )
112
- private List <org .apache .maven .artifact .repository .ArtifactRepository > remoteRepositories ;
113
-
114
106
@ Component
115
107
private RepositorySystem repositorySystem ;
116
108
@@ -165,10 +157,10 @@ private URL[] addJUnitPlatformLauncher(URL[] classPath) throws Exception {
165
157
String version = getJUnitPlatformVersion ();
166
158
DefaultArtifactHandler handler = new DefaultArtifactHandler ("jar" );
167
159
handler .setIncludesDependencies (true );
168
- ArtifactResolutionResult resolutionResult = resolveArtifact (new DefaultArtifact (JUNIT_PLATFORM_GROUP_ID ,
160
+ Set < Artifact > artifacts = resolveArtifact (new DefaultArtifact (JUNIT_PLATFORM_GROUP_ID ,
169
161
JUNIT_PLATFORM_LAUNCHER_ARTIFACT_ID , version , null , "jar" , null , handler ));
170
162
Set <URL > fullClassPath = new LinkedHashSet <>(Arrays .asList (classPath ));
171
- for (Artifact artifact : resolutionResult . getArtifacts () ) {
163
+ for (Artifact artifact : artifacts ) {
172
164
fullClassPath .add (artifact .getFile ().toURI ().toURL ());
173
165
}
174
166
return fullClassPath .toArray (URL []::new );
@@ -185,16 +177,20 @@ private String getJUnitPlatformVersion() throws MojoExecutionException {
185
177
return version ;
186
178
}
187
179
188
- private ArtifactResolutionResult resolveArtifact (Artifact artifact ) throws Exception {
189
- ArtifactResolutionRequest request = new ArtifactResolutionRequest ();
190
- request .setArtifact (artifact );
191
- request .setLocalRepository (this .localRepository );
192
- request .setResolveTransitively (true );
193
- request .setCollectionFilter (new RuntimeArtifactFilter ());
194
- request .setRemoteRepositories (this .remoteRepositories );
195
- ArtifactResolutionResult result = this .repositorySystem .resolve (request );
196
- this .resolutionErrorHandler .throwErrors (request , result );
197
- return result ;
180
+ private Set <Artifact > resolveArtifact (Artifact artifact ) throws Exception {
181
+ CollectRequest collectRequest = new CollectRequest ();
182
+ collectRequest .setRoot (RepositoryUtils .toDependency (artifact , null ));
183
+ collectRequest .setRepositories (this .project .getRemotePluginRepositories ());
184
+ DependencyRequest request = new DependencyRequest ();
185
+ request .setCollectRequest (collectRequest );
186
+ request .setFilter (DependencyFilterUtils .classpathFilter (JavaScopes .RUNTIME ));
187
+ DependencyResult dependencyResult = this .repositorySystem
188
+ .resolveDependencies (getSession ().getRepositorySession (), request );
189
+ return dependencyResult .getArtifactResults ()
190
+ .stream ()
191
+ .map (ArtifactResult ::getArtifact )
192
+ .map (RepositoryUtils ::toArtifact )
193
+ .collect (Collectors .toSet ());
198
194
}
199
195
200
196
}
0 commit comments