use of org.eclipse.aether.util.repository.AuthenticationBuilder in project build-info by JFrogDev.
the class ArtifactoryEclipseResolversHelper method getResolutionRepositories.
/**
* Create a list containing one release and one snapshot resolution repositories, according to the configuration in the Artifactory plugin.
* The list is used to override Maven's default or configured repositories, so that the build dependencies are resolved from Artifactory.
* The list is saved and reused for further invokations to this method.
* @param session
* @return
*/
public List<RemoteRepository> getResolutionRepositories(RepositorySystemSession session) {
if (resolutionRepositories == null) {
Properties allMavenProps = new Properties();
allMavenProps.putAll(session.getSystemProperties());
allMavenProps.putAll(session.getUserProperties());
resolutionHelper.init(allMavenProps);
String releaseRepoUrl = resolutionHelper.getRepoReleaseUrl();
String snapshotRepoUrl = resolutionHelper.getRepoSnapshotUrl();
Authentication authentication = null;
if (StringUtils.isNotBlank(resolutionHelper.getRepoUsername())) {
authentication = new AuthenticationBuilder().addString("username", resolutionHelper.getRepoUsername()).addSecret("password", resolutionHelper.getRepoPassword()).build();
}
Proxy proxy = null;
if (StringUtils.isNotBlank(resolutionHelper.getProxyHost())) {
Authentication auth = new AuthenticationBuilder().addString("username", resolutionHelper.getProxyUsername()).addSecret("password", resolutionHelper.getProxyPassword()).build();
proxy = new Proxy(null, resolutionHelper.getProxyHost(), resolutionHelper.getProxyPort(), auth);
}
if (StringUtils.isNotBlank(snapshotRepoUrl)) {
logger.debug("[buildinfo] Enforcing snapshot repository for resolution: " + snapshotRepoUrl);
RepositoryPolicy releasePolicy = new RepositoryPolicy(false, RepositoryPolicy.UPDATE_POLICY_DAILY, RepositoryPolicy.CHECKSUM_POLICY_WARN);
RepositoryPolicy snapshotPolicy = new RepositoryPolicy(true, RepositoryPolicy.UPDATE_POLICY_DAILY, RepositoryPolicy.CHECKSUM_POLICY_WARN);
RemoteRepository.Builder builder = new RemoteRepository.Builder("artifactory-snapshot", "default", snapshotRepoUrl);
builder.setReleasePolicy(releasePolicy);
builder.setSnapshotPolicy(snapshotPolicy);
if (authentication != null) {
logger.debug("[buildinfo] Enforcing repository authentication: " + authentication + " for snapshot resolution repository");
builder.setAuthentication(authentication);
}
if (proxy != null) {
logger.debug("[buildinfo] Enforcing proxy: " + proxy + " for snapshot resolution repository");
builder.setProxy(proxy);
}
snapshotRepository = builder.build();
}
if (StringUtils.isNotBlank(releaseRepoUrl)) {
logger.debug("[buildinfo] Enforcing release repository for resolution: " + releaseRepoUrl);
boolean snapshotPolicyEnabled = snapshotRepository == null;
String repositoryId = snapshotPolicyEnabled ? "artifactory-release-snapshot" : "artifactory-release";
RepositoryPolicy releasePolicy = new RepositoryPolicy(true, RepositoryPolicy.UPDATE_POLICY_DAILY, RepositoryPolicy.CHECKSUM_POLICY_WARN);
RepositoryPolicy snapshotPolicy = new RepositoryPolicy(snapshotPolicyEnabled, RepositoryPolicy.UPDATE_POLICY_DAILY, RepositoryPolicy.CHECKSUM_POLICY_WARN);
RemoteRepository.Builder builder = new RemoteRepository.Builder(repositoryId, "default", releaseRepoUrl);
builder.setReleasePolicy(releasePolicy);
builder.setSnapshotPolicy(snapshotPolicy);
if (authentication != null) {
logger.debug("[buildinfo] Enforcing repository authentication: " + authentication + " for release resolution repository");
builder.setAuthentication(authentication);
}
if (proxy != null) {
logger.debug("[buildinfo] Enforcing proxy: " + proxy + " for release resolution repository");
builder.setProxy(proxy);
}
releaseRepository = builder.build();
}
List<RemoteRepository> tempRepositories = Lists.newArrayList();
if (releaseRepository != null) {
tempRepositories.add(releaseRepository);
}
if (snapshotRepository != null) {
tempRepositories.add(snapshotRepository);
}
resolutionRepositories = tempRepositories;
}
return resolutionRepositories;
}
use of org.eclipse.aether.util.repository.AuthenticationBuilder in project storm by apache.
the class DependencyResolverMain method parseProxyArg.
private static Proxy parseProxyArg(String proxyUrl, String proxyUsername, String proxyPassword) throws MalformedURLException {
URL url = new URL(proxyUrl);
if (StringUtils.isNotEmpty(proxyUsername) && StringUtils.isNotEmpty(proxyPassword)) {
AuthenticationBuilder authBuilder = new AuthenticationBuilder();
authBuilder.addUsername(proxyUsername).addPassword(proxyPassword);
return new Proxy(url.getProtocol(), url.getHost(), url.getPort(), authBuilder.build());
} else {
return new Proxy(url.getProtocol(), url.getHost(), url.getPort());
}
}
use of org.eclipse.aether.util.repository.AuthenticationBuilder in project druid by druid-io.
the class PullDependencies method createTeslaAether.
private DefaultTeslaAether createTeslaAether(List<Repository> remoteRepositories) {
if (!useProxy) {
return new DefaultTeslaAether(localRepository, remoteRepositories.toArray(new Repository[0]));
}
if (!StringUtils.toLowerCase(proxyType).equals(Proxy.TYPE_HTTP) && !StringUtils.toLowerCase(proxyType).equals(Proxy.TYPE_HTTPS)) {
throw new IllegalArgumentException("invalid proxy type: " + proxyType);
}
RepositorySystemSession repositorySystemSession = new RepositorySystemSessionProvider(new File(localRepository)).get();
List<RemoteRepository> rl = remoteRepositories.stream().map(r -> {
RemoteRepository.Builder builder = new RemoteRepository.Builder(r.getId(), "default", r.getUrl());
if (r.getUsername() != null && r.getPassword() != null) {
Authentication auth = new AuthenticationBuilder().addUsername(r.getUsername()).addPassword(r.getPassword()).build();
builder.setAuthentication(auth);
}
final Authentication proxyAuth;
if (Strings.isNullOrEmpty(proxyUsername)) {
proxyAuth = null;
} else {
proxyAuth = new AuthenticationBuilder().addUsername(proxyUsername).addPassword(proxyPassword).build();
}
builder.setProxy(new Proxy(proxyType, proxyHost, proxyPort, proxyAuth));
return builder.build();
}).collect(Collectors.toList());
return new DefaultTeslaAether(rl, repositorySystemSession);
}
use of org.eclipse.aether.util.repository.AuthenticationBuilder in project zeppelin by apache.
the class InstallInterpreter method install.
public void install(String name, String artifact) {
Proxy proxy = null;
if (proxyUrl != null) {
Authentication auth = new AuthenticationBuilder().addUsername(proxyUser).addPassword(proxyPassword).build();
proxy = new Proxy(proxyUrl.getProtocol(), proxyUrl.getHost(), proxyUrl.getPort(), auth);
}
DependencyResolver depResolver = new DependencyResolver(localRepoDir, proxy);
File installDir = new File(interpreterBaseDir, name);
if (installDir.exists()) {
System.err.println("Directory " + installDir.getAbsolutePath() + " already exists" + "\n\nSkipped");
return;
}
System.out.println("Install " + name + "(" + artifact + ") to " + installDir.getAbsolutePath() + " ... ");
try {
depResolver.load(artifact, installDir);
System.out.println("Interpreter " + name + " installed under " + installDir.getAbsolutePath() + ".");
startTip();
} catch (RepositoryException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
Aggregations