1212import org .eclipse .aether .RepositorySystemSession ;
1313import org .eclipse .aether .artifact .DefaultArtifact ;
1414import org .eclipse .aether .impl .ArtifactResolver ;
15- import org .eclipse .aether .repository .Authentication ;
1615import org .eclipse .aether .repository .LocalRepository ;
1716import org .eclipse .aether .repository .RemoteRepository ;
1817import org .eclipse .aether .resolution .ArtifactRequest ;
@@ -88,6 +87,10 @@ protected ArtifactRepository getDeploymentRepository(final String altRepository)
8887 "Invalid syntax for repository. Use \" id::layout::url::unique\" ." );
8988 }
9089
90+ if (getLog ().isDebugEnabled ()) {
91+ getLog ().debug ("Getting maven deployment repository (to target artifacts) for: " + altRepository );
92+ }
93+
9194 String id = matcher .group (1 ).trim ();
9295 String layout = matcher .group (2 ).trim ();
9396 String url = matcher .group (3 ).trim ();
@@ -107,32 +110,30 @@ protected ArtifactRepository getDeploymentRepository(final String altRepository)
107110 * @throws MojoFailureException
108111 */
109112 private RemoteRepository getRepository (final String altRepository ) throws MojoExecutionException , MojoFailureException {
110- Matcher matcher = ALT_REPO_SYNTAX_PATTERN .matcher (altRepository );
111- if (!matcher .matches ()) {
112- throw new MojoFailureException (altRepository , "Invalid syntax for repository." ,
113- "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 );
114115 }
116+ // Get an appropriate injected ArtifactRepository. (This resolves authentication in the 'normal' manner from Maven)
117+ ArtifactRepository remoteArtifactRepo = getDeploymentRepository (altRepository );
115118
116- String id = matcher .group (1 ).trim ();
117- String layout = matcher .group (2 ).trim ();
118- String url = matcher .group (3 ).trim ();
119- Authentication remoteRepoAuthentication = null ;
120-
121- for (ArtifactRepository artifactRepository : project .getRemoteArtifactRepositories ()) {
122- if (artifactRepository .getId ().equals (id )){
123- final org .apache .maven .artifact .repository .Authentication authentication = artifactRepository .getAuthentication ();
124- AuthenticationBuilder authenticationBuilder = new AuthenticationBuilder ();
125- authenticationBuilder
126- .addUsername (authentication .getUsername ())
127- .addPassword (authentication .getPassword ())
128- .addPrivateKey (authentication .getPrivateKey (), authentication .getPassphrase ());
129- remoteRepoAuthentication = authenticationBuilder .build ();
119+ if (getLog ().isDebugEnabled ()) {
120+ getLog ().debug ("Resolved maven deployment repository. Transcribing to Aether Repository..." );
121+ }
122+
123+ RemoteRepository .Builder remoteRepoBuilder = new RemoteRepository .Builder (remoteArtifactRepo .getId (), remoteArtifactRepo .getLayout ().getId (), remoteArtifactRepo .getUrl ());
130124
125+ // Add authentication.
126+ if (remoteArtifactRepo .getAuthentication () != null ) {
127+ if (getLog ().isDebugEnabled ()) {
128+ getLog ().debug ("Maven deployment repsoitory has Authentication. Transcribing to Aether Authentication..." );
131129 }
130+ remoteRepoBuilder .setAuthentication (new AuthenticationBuilder ().addUsername (remoteArtifactRepo .getAuthentication ().getUsername ())
131+ .addPassword (remoteArtifactRepo .getAuthentication ().getPassword ())
132+ .addPrivateKey (remoteArtifactRepo .getAuthentication ().getPrivateKey (), remoteArtifactRepo .getAuthentication ().getPassphrase ())
133+ .build ());
132134 }
133135
134-
135- return new RemoteRepository .Builder (id , layout , url ).setAuthentication (remoteRepoAuthentication ).build ();
136+ return remoteRepoBuilder .build ();
136137 }
137138
138139 private String getCoordinates (ArtifactResult result ) {
0 commit comments