17
17
import org .eclipse .aether .resolution .ArtifactRequest ;
18
18
import org .eclipse .aether .resolution .ArtifactResolutionException ;
19
19
import org .eclipse .aether .resolution .ArtifactResult ;
20
+ import org .eclipse .aether .util .repository .AuthenticationBuilder ;
20
21
21
22
import java .io .BufferedReader ;
22
23
import java .io .File ;
@@ -86,6 +87,10 @@ protected ArtifactRepository getDeploymentRepository(final String altRepository)
86
87
"Invalid syntax for repository. Use \" id::layout::url::unique\" ." );
87
88
}
88
89
90
+ if (getLog ().isDebugEnabled ()) {
91
+ getLog ().debug ("Getting maven deployment repository (to target artifacts) for: " + altRepository );
92
+ }
93
+
89
94
String id = matcher .group (1 ).trim ();
90
95
String layout = matcher .group (2 ).trim ();
91
96
String url = matcher .group (3 ).trim ();
@@ -105,20 +110,30 @@ protected ArtifactRepository getDeploymentRepository(final String altRepository)
105
110
* @throws MojoFailureException
106
111
*/
107
112
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 );
112
115
}
116
+ // Get an appropriate injected ArtifactRepository. (This resolves authentication in the 'normal' manner from Maven)
117
+ ArtifactRepository remoteArtifactRepo = getDeploymentRepository (altRepository );
113
118
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
+ }
118
122
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
+ }
120
135
121
- return new RemoteRepository . Builder ( id , layout , url ) .build ();
136
+ return remoteRepoBuilder .build ();
122
137
}
123
138
124
139
private String getCoordinates (ArtifactResult result ) {
0 commit comments