Skip to content

Commit 24b6792

Browse files
author
przemekd
committed
Add authentication info in 'promote-master'
1 parent 0962591 commit 24b6792

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@
104104
<version>3.1.0</version>
105105
<scope>provided</scope>
106106
</dependency>
107+
<dependency>
108+
<groupId>org.eclipse.aether</groupId>
109+
<artifactId>aether-util</artifactId>
110+
<version>0.9.0.M2</version>
111+
</dependency>
107112
<dependency>
108113
<groupId>junit</groupId>
109114
<artifactId>junit</artifactId>

src/main/java/com/e_gineering/maven/gitflowhelper/AbstractGitflowBasedRepositoryMojo.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212
import org.eclipse.aether.RepositorySystemSession;
1313
import org.eclipse.aether.artifact.DefaultArtifact;
1414
import org.eclipse.aether.impl.ArtifactResolver;
15+
import org.eclipse.aether.repository.Authentication;
1516
import org.eclipse.aether.repository.LocalRepository;
1617
import org.eclipse.aether.repository.RemoteRepository;
1718
import org.eclipse.aether.resolution.ArtifactRequest;
1819
import org.eclipse.aether.resolution.ArtifactResolutionException;
1920
import org.eclipse.aether.resolution.ArtifactResult;
21+
import org.eclipse.aether.util.repository.AuthenticationBuilder;
2022

2123
import java.io.BufferedReader;
2224
import java.io.File;
@@ -114,11 +116,23 @@ private RemoteRepository getRepository(final String altRepository) throws MojoEx
114116
String id = matcher.group(1).trim();
115117
String layout = matcher.group(2).trim();
116118
String url = matcher.group(3).trim();
117-
boolean unique = Boolean.parseBoolean(matcher.group(4).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();
130+
131+
}
132+
}
118133

119-
ArtifactRepositoryLayout repoLayout = getLayout(layout);
120134

121-
return new RemoteRepository.Builder(id, layout, url).build();
135+
return new RemoteRepository.Builder(id, layout, url).setAuthentication(remoteRepoAuthentication).build();
122136
}
123137

124138
private String getCoordinates(ArtifactResult result) {

0 commit comments

Comments
 (0)