use of org.jboss.pnc.spi.repositorymanager.ArtifactRepository in project pnc by project-ncl.
the class RepositoryManagerDriver method setupBuildRepos.
/**
* Create the hosted repository and group necessary to support a single build. The hosted repository holds artifacts
* uploaded from the build, and the group coordinates access to this hosted repository, along with content from the
* product-level content group with which this build is associated. The group also provides a tracking target, so
* the repository manager can keep track of downloads and uploads for the build.
*
* @param execution The execution object, which contains the content id for creating the repo, and the build id.
* @param packageType the package type key used by Indy
* @throws IndyClientException
*/
private void setupBuildRepos(BuildExecution execution, String packageType, Indy indy, Map<String, String> genericParameters, boolean brewPullActive) throws IndyClientException {
String buildContentId = execution.getBuildContentId();
String id = execution.getId();
BuildType buildType = execution.getBuildType();
// if the build-level group doesn't exist, create it.
StoreKey groupKey = new StoreKey(packageType, StoreType.group, buildContentId);
StoreKey hostedKey = new StoreKey(packageType, StoreType.hosted, buildContentId);
if (!indy.stores().exists(groupKey)) {
// if the product-level storage repo (for in-progress product builds) doesn't exist, create it.
boolean tempBuild = execution.isTempBuild();
if (!indy.stores().exists(hostedKey)) {
HostedRepository buildArtifacts = new HostedRepository(packageType, buildContentId);
buildArtifacts.setAllowSnapshots(false);
buildArtifacts.setAllowReleases(true);
buildArtifacts.setDescription(String.format("Build output for PNC %s build #%s", packageType, id));
indy.stores().create(buildArtifacts, "Creating hosted repository for " + packageType + " build: " + id + " (repo: " + buildContentId + ")", HostedRepository.class);
}
Group buildGroup = new Group(packageType, buildContentId);
String adjective = tempBuild ? "temporary " : "";
buildGroup.setDescription(String.format("Aggregation group for PNC %sbuild #%s", adjective, id));
// build-local artifacts
buildGroup.addConstituent(hostedKey);
// [MMENG-1262] set if brew pull is active or not via group metadata
buildGroup.setMetadata(BREW_PULL_ACTIVE_METADATA_KEY, Boolean.toString(brewPullActive));
// Global-level repos, for captured/shared artifacts and access to the outside world
addGlobalConstituents(buildType, packageType, buildGroup, tempBuild);
// add extra repositories removed from poms by the adjust process and set in BC by user
List<ArtifactRepository> extraDependencyRepositories = extractExtraRepositoriesFromGenericParameters(genericParameters);
if (execution.getArtifactRepositories() != null) {
extraDependencyRepositories.addAll(execution.getArtifactRepositories());
}
addExtraConstituents(packageType, extraDependencyRepositories, id, buildContentId, indy, buildGroup);
String changelog = "Creating repository group for resolving artifacts in build: " + id + " (repo: " + buildContentId + ")";
indy.stores().create(buildGroup, changelog, Group.class);
}
}
use of org.jboss.pnc.spi.repositorymanager.ArtifactRepository in project pnc by project-ncl.
the class RepositoryManagerDriver method addExtraConstituents.
/**
* Adds extra remote repositories to the build group that are requested for the particular build. For a Maven build
* these are repositories defined in the root pom removed by PME by the adjust process.
*
* @param packageType the package type key used by Indy
* @param repositories the list of repositories to be added
* @param buildId build ID
* @param buildContentId build content ID
* @param indy Indy client
* @param buildGroup target build group in which the repositories are added
*
* @throws IndyClientException in case of an issue when communicating with the repository manager
*/
private void addExtraConstituents(String packageType, List<ArtifactRepository> repositories, String buildId, String buildContentId, Indy indy, Group buildGroup) throws IndyClientException {
if (repositories != null && !repositories.isEmpty()) {
StoreListingDTO<RemoteRepository> existingRepos = indy.stores().listRemoteRepositories(packageType);
for (ArtifactRepository repository : repositories) {
StoreKey remoteKey = null;
for (RemoteRepository existingRepo : existingRepos) {
if (StringUtils.equals(existingRepo.getUrl(), repository.getUrl())) {
remoteKey = existingRepo.getKey();
break;
}
}
if (remoteKey == null) {
// this is basically an implied repo, so using the same prefix "i-"
String remoteName = "i-" + convertIllegalCharacters(repository.getId());
// find a free repository ID for the newly created repo
remoteKey = new StoreKey(packageType, StoreType.remote, remoteName);
int i = 2;
while (indy.stores().exists(remoteKey)) {
remoteKey = new StoreKey(packageType, StoreType.remote, remoteName + "-" + i++);
}
RemoteRepository remoteRepo = new RemoteRepository(packageType, remoteKey.getName(), repository.getUrl());
remoteRepo.setAllowReleases(repository.getReleases());
remoteRepo.setAllowSnapshots(repository.getSnapshots());
remoteRepo.setDescription("Implicitly created " + packageType + " repo for: " + repository.getName() + " (" + repository.getId() + ") from repository declaration removed by PME in build " + buildId + " (repo: " + buildContentId + ")");
indy.stores().create(remoteRepo, "Creating extra remote repository " + repository.getName() + " (" + repository.getId() + ") for build: " + buildId + " (repo: " + buildContentId + ")", RemoteRepository.class);
}
buildGroup.addConstituent(remoteKey);
}
}
}
Aggregations