5757import org .apache .catalina .startup .Tomcat ;
5858import org .apache .catalina .valves .AccessLogValve ;
5959import org .apache .commons .io .IOUtils ;
60-
6160import org .apache .maven .artifact .Artifact ;
62- import org .apache .maven .artifact .factory .ArtifactFactory ;
6361import org .apache .maven .artifact .repository .ArtifactRepository ;
64- import org .apache .maven .artifact .resolver .ArtifactNotFoundException ;
65- import org .apache .maven .artifact .resolver .ArtifactResolutionException ;
66- import org .apache .maven .artifact .resolver .ArtifactResolver ;
6762import org .apache .maven .artifact .resolver .filter .ScopeArtifactFilter ;
68- import org .apache .maven .artifact .versioning .InvalidVersionSpecificationException ;
69- import org .apache .maven .artifact .versioning .VersionRange ;
7063import org .apache .maven .execution .MavenSession ;
7164import org .apache .maven .plugin .MojoExecutionException ;
7265import org .apache .maven .plugin .MojoFailureException ;
9184import org .codehaus .plexus .classworlds .realm .DuplicateRealmException ;
9285import org .codehaus .plexus .util .DirectoryScanner ;
9386import org .codehaus .plexus .util .FileUtils ;
87+ import org .eclipse .aether .RepositorySystem ;
88+ import org .eclipse .aether .artifact .DefaultArtifact ;
89+ import org .eclipse .aether .resolution .ArtifactRequest ;
90+ import org .eclipse .aether .resolution .ArtifactResult ;
9491import org .w3c .dom .Document ;
9592import org .w3c .dom .NamedNodeMap ;
9693import org .w3c .dom .Node ;
@@ -107,23 +104,14 @@ public abstract class AbstractRunMojo
107104 // Mojo Components
108105 // ---------------------------------------------------------------------
109106
110- /**
111- * Used to look up Artifacts in the remote repository.
112- */
113- @ Component
114- protected ArtifactFactory factory ;
115-
116107 /**
117108 * Location of the local repository.
118109 */
119110 @ Parameter ( defaultValue = "${localRepository}" , required = true , readonly = true )
120111 private ArtifactRepository local ;
121112
122- /**
123- * Used to look up Artifacts in the remote repository.
124- */
125113 @ Component
126- protected ArtifactResolver resolver ;
114+ protected RepositorySystem repositorySystem ;
127115
128116 // ----------------------------------------------------------------------
129117 // Mojo Parameters
@@ -1215,21 +1203,21 @@ private void startContainer()
12151203
12161204 portProperties .put ( "tomcat.maven.http.port" , Integer .toString ( connector .getLocalPort () ) );
12171205
1218- session .getExecutionProperties ().put ( "tomcat.maven.http.port" ,
1206+ session .getUserProperties ().setProperty ( "tomcat.maven.http.port" ,
12191207 Integer .toString ( connector .getLocalPort () ) );
12201208 System .setProperty ( "tomcat.maven.http.port" , Integer .toString ( connector .getLocalPort () ) );
12211209
12221210 if ( httpsConnector != null )
12231211 {
1224- session .getExecutionProperties ().put ( "tomcat.maven.https.port" ,
1212+ session .getUserProperties ().setProperty ( "tomcat.maven.https.port" ,
12251213 Integer .toString ( httpsConnector .getLocalPort () ) );
12261214 portProperties .put ( "tomcat.maven.https.port" , Integer .toString ( httpsConnector .getLocalPort () ) );
12271215 System .setProperty ( "tomcat.maven.https.port" , Integer .toString ( httpsConnector .getLocalPort () ) );
12281216 }
12291217
12301218 if ( ajpConnector != null )
12311219 {
1232- session .getExecutionProperties ().put ( "tomcat.maven.ajp.port" ,
1220+ session .getUserProperties ().setProperty ( "tomcat.maven.ajp.port" ,
12331221 Integer .toString ( ajpConnector .getLocalPort () ) );
12341222 portProperties .put ( "tomcat.maven.ajp.port" , Integer .toString ( ajpConnector .getLocalPort () ) );
12351223 System .setProperty ( "tomcat.maven.ajp.port" , Integer .toString ( ajpConnector .getLocalPort () ) );
@@ -1485,46 +1473,50 @@ private void createStaticContext( final Tomcat container, Context context, Host
14851473 protected Artifact getArtifact ( Webapp additionalWebapp )
14861474 throws MojoExecutionException
14871475 {
1488-
1489- Artifact artifact ;
1490- VersionRange vr ;
1491- try
1492- {
1493- vr = VersionRange .createFromVersionSpec ( additionalWebapp .getVersion () );
1494- }
1495- catch ( InvalidVersionSpecificationException e )
1476+ String classifier = additionalWebapp .getClassifier ();
1477+ String version = additionalWebapp .getVersion ();
1478+
1479+ org .eclipse .aether .artifact .Artifact aetherArtifact = new DefaultArtifact (
1480+ additionalWebapp .getGroupId (),
1481+ additionalWebapp .getArtifactId (),
1482+ classifier != null && !classifier .isEmpty () ? classifier : "" ,
1483+ additionalWebapp .getType (),
1484+ version
1485+ );
1486+
1487+ ArtifactRequest artifactRequest = new ArtifactRequest ();
1488+ artifactRequest .setArtifact ( aetherArtifact );
1489+
1490+ List <org .eclipse .aether .repository .RemoteRepository > aetherRepos = new ArrayList <>();
1491+ for ( org .apache .maven .artifact .repository .ArtifactRepository repo : project .getRemoteArtifactRepositories () )
14961492 {
1497- getLog ().warn ( "fail to create versionRange from version: " + additionalWebapp .getVersion (), e );
1498- vr = VersionRange .createFromVersion ( additionalWebapp .getVersion () );
1499- }
1500-
1501- if ( additionalWebapp .getClassifier () == null || additionalWebapp .getClassifier ().isEmpty () )
1502- {
1503- artifact =
1504- factory .createDependencyArtifact ( additionalWebapp .getGroupId (), additionalWebapp .getArtifactId (), vr ,
1505- additionalWebapp .getType (), null , Artifact .SCOPE_COMPILE );
1506- }
1507- else
1508- {
1509- artifact =
1510- factory .createDependencyArtifact ( additionalWebapp .getGroupId (), additionalWebapp .getArtifactId (), vr ,
1511- additionalWebapp .getType (), additionalWebapp .getClassifier (),
1512- Artifact .SCOPE_COMPILE );
1493+ org .eclipse .aether .repository .RemoteRepository aetherRepo = new org .eclipse .aether .repository .RemoteRepository .Builder (
1494+ repo .getId (), "default" , repo .getUrl () )
1495+ .build ();
1496+ aetherRepos .add ( aetherRepo );
15131497 }
1498+ artifactRequest .setRepositories ( aetherRepos );
15141499
15151500 try
15161501 {
1517- resolver .resolve ( artifact , project .getRemoteArtifactRepositories (), this .local );
1502+ ArtifactResult artifactResult = repositorySystem .resolveArtifact ( session .getRepositorySession (), artifactRequest );
1503+ org .eclipse .aether .artifact .Artifact resolved = artifactResult .getArtifact ();
1504+
1505+ Artifact artifact = new org .apache .maven .artifact .DefaultArtifact (
1506+ additionalWebapp .getGroupId (),
1507+ additionalWebapp .getArtifactId (),
1508+ version ,
1509+ Artifact .SCOPE_COMPILE ,
1510+ additionalWebapp .getType (),
1511+ classifier != null && !classifier .isEmpty () ? classifier : "" ,
1512+ new org .apache .maven .artifact .handler .DefaultArtifactHandler ( additionalWebapp .getType () )
1513+ );
1514+ artifact .setFile ( resolved .getFile () );
1515+ return artifact ;
15181516 }
1519- catch ( ArtifactResolutionException e )
1517+ catch ( Exception e )
15201518 {
15211519 throw new MojoExecutionException ( "Unable to resolve artifact." , e );
15221520 }
1523- catch ( ArtifactNotFoundException e )
1524- {
1525- throw new MojoExecutionException ( "Unable to find artifact." , e );
1526- }
1527-
1528- return artifact ;
15291521 }
15301522}
0 commit comments