1717import org .eclipse .aether .resolution .ArtifactRequest ;
1818import org .eclipse .aether .resolution .ArtifactResolutionException ;
1919import org .eclipse .aether .resolution .ArtifactResult ;
20+ import org .eclipse .aether .util .repository .AuthenticationBuilder ;
2021
2122import java .io .BufferedReader ;
2223import java .io .File ;
@@ -86,6 +87,10 @@ protected ArtifactRepository getDeploymentRepository(final String altRepository)
8687 "Invalid syntax for repository. Use \" id::layout::url::unique\" ." );
8788 }
8889
90+ if (getLog ().isDebugEnabled ()) {
91+ getLog ().debug ("Getting maven deployment repository (to target artifacts) for: " + altRepository );
92+ }
93+
8994 String id = matcher .group (1 ).trim ();
9095 String layout = matcher .group (2 ).trim ();
9196 String url = matcher .group (3 ).trim ();
@@ -105,20 +110,30 @@ protected ArtifactRepository getDeploymentRepository(final String altRepository)
105110 * @throws MojoFailureException
106111 */
107112 private RemoteRepository getRepository (final String altRepository ) throws MojoExecutionException , MojoFailureException {
108- Matcher matcher = ALT_REPO_SYNTAX_PATTERN .matcher (altRepository );
109- if (!matcher .matches ()) {
110- throw new MojoFailureException (altRepository , "Invalid syntax for repository." ,
111- "Invalid syntax for repository. Use \" id::layout::url::unique\" ." );
113+ if (getLog ().isDebugEnabled ()) {
114+ getLog ().debug ("Creating remote Aether repository (to resolve remote artifacts) for: " + altRepository );
112115 }
116+ // Get an appropriate injected ArtifactRepository. (This resolves authentication in the 'normal' manner from Maven)
117+ ArtifactRepository remoteArtifactRepo = getDeploymentRepository (altRepository );
113118
114- String id = matcher .group (1 ).trim ();
115- String layout = matcher .group (2 ).trim ();
116- String url = matcher .group (3 ).trim ();
117- boolean unique = Boolean .parseBoolean (matcher .group (4 ).trim ());
119+ if (getLog ().isDebugEnabled ()) {
120+ getLog ().debug ("Resolved maven deployment repository. Transcribing to Aether Repository..." );
121+ }
118122
119- ArtifactRepositoryLayout repoLayout = getLayout (layout );
123+ RemoteRepository .Builder remoteRepoBuilder = new RemoteRepository .Builder (remoteArtifactRepo .getId (), remoteArtifactRepo .getLayout ().getId (), remoteArtifactRepo .getUrl ());
124+
125+ // Add authentication.
126+ if (remoteArtifactRepo .getAuthentication () != null ) {
127+ if (getLog ().isDebugEnabled ()) {
128+ getLog ().debug ("Maven deployment repsoitory has Authentication. Transcribing to Aether Authentication..." );
129+ }
130+ remoteRepoBuilder .setAuthentication (new AuthenticationBuilder ().addUsername (remoteArtifactRepo .getAuthentication ().getUsername ())
131+ .addPassword (remoteArtifactRepo .getAuthentication ().getPassword ())
132+ .addPrivateKey (remoteArtifactRepo .getAuthentication ().getPrivateKey (), remoteArtifactRepo .getAuthentication ().getPassphrase ())
133+ .build ());
134+ }
120135
121- return new RemoteRepository . Builder ( id , layout , url ) .build ();
136+ return remoteRepoBuilder .build ();
122137 }
123138
124139 private String getCoordinates (ArtifactResult result ) {
0 commit comments