[aether] IDEA-264046: Allow providing auth data for remote maven repositories

GitOrigin-RevId: 2787fb80907d2c290a0d90224fdc84e30e245420
This commit is contained in:
Nikolay Rykunov
2021-07-07 12:05:30 +02:00
committed by intellij-monorepo-bot
parent e9d3150345
commit e05eef9a47

View File

@@ -32,6 +32,7 @@ import org.eclipse.aether.util.graph.selector.ExclusionDependencySelector;
import org.eclipse.aether.util.graph.transformer.ConflictResolver;
import org.eclipse.aether.util.graph.visitor.FilteringDependencyVisitor;
import org.eclipse.aether.util.graph.visitor.TreeDependencyVisitor;
import org.eclipse.aether.util.repository.AuthenticationBuilder;
import org.eclipse.aether.util.version.GenericVersionScheme;
import org.eclipse.aether.version.*;
import org.jetbrains.annotations.NotNull;
@@ -423,17 +424,34 @@ public final class ArtifactRepositoryManager {
public static RemoteRepository createRemoteRepository(final String id,
final String url) {
return createRemoteRepository(id, url, true);
return createRemoteRepository(id, url, null, true);
}
public static RemoteRepository createRemoteRepository(final String id,
final String url,
boolean allowSnapshots) {
return createRemoteRepository(id, url, null, allowSnapshots);
}
public static RemoteRepository createRemoteRepository(String id, String url, ArtifactAuthenticationData authenticationData) {
return createRemoteRepository(id, url, authenticationData, true);
}
public static RemoteRepository createRemoteRepository(String id,
String url,
ArtifactAuthenticationData authenticationData,
boolean allowSnapshots) {
// for maven repos repository type should be 'default'
RemoteRepository.Builder builder = new RemoteRepository.Builder(id, "default", url);
if (!allowSnapshots) {
builder.setSnapshotPolicy(new RepositoryPolicy(false, null, null));
}
if (authenticationData != null) {
AuthenticationBuilder authenticationBuilder = new AuthenticationBuilder();
authenticationBuilder.addUsername(authenticationData.getUsername());
authenticationBuilder.addPassword(authenticationData.getPassword());
builder.setAuthentication(authenticationBuilder.build());
}
return builder.setProxy(ourProxySelector.getProxy(url)).build();
}
@@ -489,6 +507,24 @@ public final class ArtifactRepositoryManager {
return result;
}
public static class ArtifactAuthenticationData {
private final String username;
private final String password;
public ArtifactAuthenticationData(String username, String password) {
this.username = username;
this.password = password;
}
private String getUsername() {
return username;
}
private String getPassword() {
return password;
}
}
private static class ArtifactWithChangedClassifier extends DelegatingArtifact {
private final String myClassifier;