1111import java .util .ArrayList ;
1212import java .util .Arrays ;
1313import java .util .Collections ;
14- import java .util .Enumeration ;
1514import java .util .LinkedList ;
1615import java .util .List ;
1716import java .util .Set ;
18- import java .util .jar .JarEntry ;
19- import java .util .jar .JarFile ;
20- import java .util .stream .Collectors ;
21-
22- import org .apache .maven .artifact .Artifact ;
23- import org .apache .maven .artifact .factory .ArtifactFactory ;
24- import org .apache .maven .artifact .metadata .ArtifactMetadataSource ;
25- import org .apache .maven .artifact .resolver .ArtifactResolutionRequest ;
17+
2618import org .apache .maven .execution .MavenSession ;
2719import org .apache .maven .model .Dependency ;
2820import org .apache .maven .model .FileSet ;
3224import org .apache .maven .plugins .annotations .Parameter ;
3325import org .apache .maven .project .MavenProject ;
3426import org .apache .maven .project .ProjectBuilder ;
35- import org .apache .maven .project .artifact .InvalidDependencyVersionException ;
36- import org .apache .maven .project .artifact .MavenMetadataSource ;
37- import org .apache .maven .repository .RepositorySystem ;
3827import org .apache .maven .settings .Settings ;
28+ import org .eclipse .aether .RepositorySystem ;
29+ import org .eclipse .aether .RepositorySystemSession ;
30+ import org .eclipse .aether .artifact .Artifact ;
31+ import org .eclipse .aether .artifact .DefaultArtifact ;
32+ import org .eclipse .aether .repository .RemoteRepository ;
33+ import org .eclipse .aether .resolution .ArtifactRequest ;
34+ import org .eclipse .aether .resolution .ArtifactResult ;
3935import org .jvnet .jaxb .maven .util .ArtifactUtils ;
4036import org .jvnet .jaxb .maven .util .IOUtils ;
4137import org .sonatype .plexus .build .incremental .BuildContext ;
@@ -1007,11 +1003,11 @@ public void setArtifactExcludes(String[] artifactExcludes) {
10071003 @ Component
10081004 private RepositorySystem repositorySystem ;
10091005
1010- @ Component
1011- private ArtifactMetadataSource artifactMetadataSource ;
1006+ @ Parameter ( defaultValue = "${repositorySystemSession}" , readonly = true )
1007+ private RepositorySystemSession repositorySystemSession ;
10121008
1013- @ Component
1014- private ArtifactFactory artifactFactory ;
1009+ @ Parameter ( defaultValue = "${project.remoteProjectRepositories}" , readonly = true )
1010+ private List < RemoteRepository > remoteRepositories ;
10151011
10161012 /**
10171013 * Maven current session.
@@ -1028,12 +1024,6 @@ public void setArtifactExcludes(String[] artifactExcludes) {
10281024 @ Component
10291025 private BuildContext buildContext = new DefaultBuildContext ();
10301026
1031- /**
1032- * Plugin artifacts.
1033- */
1034- @ Parameter (defaultValue = "${plugin.artifacts}" , required = true )
1035- private List <org .apache .maven .artifact .Artifact > pluginArtifacts ;
1036-
10371027 /**
10381028 * If you want to use existing artifacts as episodes for separate
10391029 * compilation, configure them as episodes/episode elements. It is assumed
@@ -1100,7 +1090,6 @@ protected void logConfiguration() throws MojoExecutionException {
11001090
11011091 logApiConfiguration ();
11021092
1103- getLog ().info ("pluginArtifacts:" + getPluginArtifacts ());
11041093 getLog ().info ("specVersion:" + getSpecVersion ());
11051094 getLog ().info ("encoding:" + getEncoding ());
11061095 getLog ().info ("locale:" + getLocale ());
@@ -1173,24 +1162,23 @@ public void setRepositorySystem(RepositorySystem repositorySystem) {
11731162 private static final String XML_SCHEMA_RESOURCE_NAME = XML_SCHEMA_CLASS_NAME
11741163 + ".class" ;
11751164
1176- public ArtifactMetadataSource getArtifactMetadataSource () {
1177- return artifactMetadataSource ;
1178- }
1165+ private static final String XML_SCHEMA_RESOURCE_QNAME = "/jakarta/xml/bind/annotation/"
1166+ + XML_SCHEMA_RESOURCE_NAME ;
11791167
1180- public void setArtifactMetadataSource (
1181- ArtifactMetadataSource artifactMetadataSource ) {
1182- this .artifactMetadataSource = artifactMetadataSource ;
1168+ public RepositorySystemSession getRepositorySystemSession () {
1169+ return repositorySystemSession ;
11831170 }
11841171
1185- private static final String XML_SCHEMA_RESOURCE_QNAME = "/jakarta/xml/bind/annotation/"
1186- + XML_SCHEMA_RESOURCE_NAME ;
1172+ public void setRepositorySystemSession (RepositorySystemSession repositorySystemSession ) {
1173+ this .repositorySystemSession = repositorySystemSession ;
1174+ }
11871175
1188- public ArtifactFactory getArtifactFactory () {
1189- return artifactFactory ;
1176+ public List < RemoteRepository > getRemoteRepositories () {
1177+ return remoteRepositories ;
11901178 }
11911179
1192- public void setArtifactFactory ( ArtifactFactory artifactFactory ) {
1193- this .artifactFactory = artifactFactory ;
1180+ public void setRemoteRepositories ( List < RemoteRepository > remoteRepositories ) {
1181+ this .remoteRepositories = remoteRepositories ;
11941182 }
11951183
11961184 private static final String XML_ELEMENT_REF_CLASS_NAME = "XmlElementRef" ;
@@ -1246,25 +1234,16 @@ protected void logApiConfiguration() {
12461234 }
12471235 }
12481236
1249- public List <org .apache .maven .artifact .Artifact > getPluginArtifacts () {
1250- return pluginArtifacts ;
1251- }
1252-
1253- public void setPluginArtifacts (
1254- List <org .apache .maven .artifact .Artifact > plugingArtifacts ) {
1255- this .pluginArtifacts = plugingArtifacts ;
1256- }
1257-
12581237 public List <Dependency > getProjectDependencies () {
12591238
12601239 @ SuppressWarnings ("unchecked" )
1261- final Set <Artifact > artifacts = getProject ().getArtifacts ();
1240+ final Set <org . apache . maven . artifact . Artifact > artifacts = getProject ().getArtifacts ();
12621241
12631242 if (artifacts == null ) {
12641243 return Collections .emptyList ();
12651244 } else {
12661245 final List <Dependency > dependencies = new ArrayList <Dependency >(artifacts .size ());
1267- for (Artifact artifact : artifacts ) {
1246+ for (org . apache . maven . artifact . Artifact artifact : artifacts ) {
12681247 final Dependency dependency = new Dependency ();
12691248 dependency .setGroupId (artifact .getGroupId ());
12701249 dependency .setArtifactId (artifact .getArtifactId ());
@@ -1365,56 +1344,39 @@ public List<URI> resolveDependencyResources(DependencyResource dependencyResourc
13651344 }
13661345
13671346 try {
1368- @ SuppressWarnings ("unchecked" )
1369- final Set <Artifact > artifacts = MavenMetadataSource
1370- .createArtifacts (getArtifactFactory (),
1371- Arrays .<Dependency >asList (dependencyResource ),
1372- Artifact .SCOPE_RUNTIME , null , getProject ());
1347+ final Artifact artifact = new DefaultArtifact (dependencyResource .getGroupId (),
1348+ dependencyResource .getArtifactId (), dependencyResource .getClassifier (),
1349+ dependencyResource .getType (), dependencyResource .getVersion ());
13731350
1374- if (artifacts .size () != 1 ) {
1375- getLog ().error (
1376- MessageFormat
1377- .format ("Resolved dependency resource [{0}] to artifacts [{1}]." ,
1378- dependencyResource , artifacts ));
1379- throw new MojoExecutionException (MessageFormat .format (
1380- "Could not create artifact for dependency [{0}]." ,
1381- dependencyResource ));
1382- }
1351+ final ArtifactRequest artifactRequest = new ArtifactRequest ();
1352+ artifactRequest .setArtifact (artifact );
1353+ artifactRequest .setRepositories (getRemoteRepositories ());
13831354
1384- final Artifact artifact = artifacts .iterator ().next ();
1355+ final ArtifactResult artifactResult = getRepositorySystem ().resolveArtifact (getRepositorySystemSession (),
1356+ artifactRequest );
13851357
1386- ArtifactResolutionRequest artifactResolutionRequest = new ArtifactResolutionRequest ();
1387- artifactResolutionRequest .setArtifact (artifact );
1388- artifactResolutionRequest .setRemoteRepositories (getProject ().getRemoteArtifactRepositories ());
1389- artifactResolutionRequest .setLocalRepository (getMavenSession ().getLocalRepository ());
1390- getRepositorySystem ().resolve (artifactResolutionRequest );
1358+ final Artifact resolvedArtifact = artifactResult .getArtifact ();
13911359
13921360 final String resource = dependencyResource .getResource ();
13931361 if (resource == null ) {
1394- throw new MojoExecutionException (
1395- MessageFormat
1396- .format ("Dependency resource [{0}] does not define the resource." ,
1397- dependencyResource ));
1362+ throw new MojoExecutionException (MessageFormat .format (
1363+ "Dependency resource [{0}] does not define the resource." , dependencyResource ));
13981364 }
1399- if (resource .contains ("*" )) {
1400- final File artifactFile = artifact .getFile ();
1401- List <URI > uris = getResourceUris (artifactFile , resource );
1402- getLog ().debug (
1403- MessageFormat
1404- .format ("Resolved dependency resource [{0}] to resources URI [{1}]." ,
1405- dependencyResource , uris ));
1406- return uris ;
1407- } else {
1408- final URI resourceURI = createArtifactResourceUri (artifact , resource );
1409- getLog ().debug (
1410- MessageFormat
1411- .format ("Resolved dependency resource [{0}] to resource URI [{1}]." ,
1412- dependencyResource , resourceURI ));
1413- return Arrays .asList (resourceURI );
1414- }
1415- } catch (InvalidDependencyVersionException e ) {
1416- throw new MojoExecutionException (MessageFormat .format (
1417- "Invalid version of dependency [{0}]." , dependencyResource ));
1365+ if (resource .contains ("*" )) {
1366+ final File artifactFile = resolvedArtifact .getFile ();
1367+ List <URI > uris = getResourceUris (artifactFile , resource );
1368+ getLog ().debug (MessageFormat .format ("Resolved dependency resource [{0}] to resources URI [{1}]." ,
1369+ dependencyResource , uris ));
1370+ return uris ;
1371+ } else {
1372+ final URI resourceURI = createArtifactResourceUri (resolvedArtifact , resource );
1373+ getLog ().debug (MessageFormat .format ("Resolved dependency resource [{0}] to resource URI [{1}]." ,
1374+ dependencyResource , resourceURI ));
1375+ return Arrays .asList (resourceURI );
1376+ }
1377+ } catch (Exception e ) {
1378+ throw new MojoExecutionException (
1379+ MessageFormat .format ("Could not resolve dependency resource [{0}]." , dependencyResource ), e );
14181380 }
14191381 }
14201382
0 commit comments