use of org.eclipse.aether.repository.RepositoryPolicy 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.repository.RepositoryPolicy in project build-info by JFrogDev.
the class ArtifactoryEclipseRepositoryListener method setRepositoryPolicy.
/**
* Enables both snapshot and release polocies for a repository
*/
private void setRepositoryPolicy(RemoteRepository repo) throws NoSuchFieldException, IllegalAccessException {
RepositoryPolicy policy = new RepositoryPolicy(true, RepositoryPolicy.UPDATE_POLICY_DAILY, RepositoryPolicy.CHECKSUM_POLICY_WARN);
Field releasePolicyField = RemoteRepository.class.getDeclaredField("releasePolicy");
Field snapshotPolicyField = RemoteRepository.class.getDeclaredField("snapshotPolicy");
releasePolicyField.setAccessible(true);
snapshotPolicyField.setAccessible(true);
releasePolicyField.set(repo, policy);
snapshotPolicyField.set(repo, policy);
}
Aggregations