use of org.jboss.pnc.enums.RepositoryType in project pnc by project-ncl.
the class DefaultBuildExecutor method configureRepository.
private RepositorySession configureRepository(DefaultBuildExecutionSession buildExecutionSession) {
if (buildExecutionSession.isCanceled()) {
return null;
}
ProcessStageUtils.logProcessStageBegin(BuildExecutionStatus.REPO_SETTING_UP.toString(), "Setting up repository...");
buildExecutionSession.setStatus(BuildExecutionStatus.REPO_SETTING_UP);
BuildType buildType = buildExecutionSession.getBuildExecutionConfiguration().getBuildType();
if (buildType == null) {
throw new BuildProcessException("Missing required value buildExecutionConfiguration.buildType");
}
RepositoryType repositoryType = BuildTypeToRepositoryType.getRepositoryType(buildType);
try {
RepositoryManager repositoryManager = repositoryManagerFactory.getRepositoryManager(repositoryType);
BuildExecution buildExecution = buildExecutionSession.getBuildExecutionConfiguration();
String serviceAccountToken = (serviceClient == null ? null : serviceClient.getAuthToken());
RepositorySession buildRepository = repositoryManager.createBuildRepositoryWithRetries(buildExecution, buildExecutionSession.getAccessToken(), serviceAccountToken, repositoryType, buildExecutionSession.getBuildExecutionConfiguration().getGenericParameters(), buildExecutionSession.getBuildExecutionConfiguration().isBrewPullActive());
return buildRepository;
} catch (Throwable e) {
throw new BuildProcessException(e);
} finally {
ProcessStageUtils.logProcessStageEnd(BuildExecutionStatus.REPO_SETTING_UP.toString(), "Repository setup complete.");
}
}
use of org.jboss.pnc.enums.RepositoryType in project pnc by project-ncl.
the class DefaultDatastore method checkForBuiltArtifacts.
@Override
public Map<Artifact, String> checkForBuiltArtifacts(Collection<Artifact> artifacts) {
Map<RepositoryType, Map<String, Artifact>> repoTypes = new HashMap<>();
for (Artifact artifact : artifacts) {
RepositoryType repoType = artifact.getTargetRepository().getRepositoryType();
if (!repoTypes.containsKey(repoType)) {
repoTypes.put(repoType, new HashMap<>());
}
Map<String, Artifact> identifiers = repoTypes.get(repoType);
identifiers.put(artifact.getIdentifier(), artifact);
}
Map<Artifact, String> conflicts = new HashMap<>();
for (RepositoryType repoType : repoTypes.keySet()) {
Map<String, Artifact> identifiers = repoTypes.get(repoType);
List<Artifact> conflicting = artifactRepository.queryWithPredicates(withIdentifierInAndBuilt(identifiers.keySet()));
for (Artifact conflict : conflicting) {
if (conflict.getTargetRepository().getRepositoryType() == repoType) {
Artifact artifact = identifiers.get(conflict.getIdentifier());
conflicts.put(artifact, ARTIFACT_ALREADY_BUILT_CONFLICT_MESSAGE + conflict.getBuildRecord().getId());
}
}
}
return conflicts;
}
use of org.jboss.pnc.enums.RepositoryType in project pnc by project-ncl.
the class IndyRepositorySession method collectUploads.
/**
* Return list of output artifacts for promotion.
*
* @param report The tracking report that contains info about artifacts uploaded (output) from the build
* @return List of output artifacts meta data
* @throws RepositoryManagerException In case of a client API transport error or an error during promotion of
* artifacts
*/
private Uploads collectUploads(TrackedContentDTO report) throws RepositoryManagerException {
List<Artifact> data;
List<String> promotion;
logger.info("BEGIN: Process artifacts uploaded from build");
userLog.info("Processing built artifacts");
StopWatch stopWatch = StopWatch.createStarted();
Set<TrackedContentEntryDTO> uploads = report.getUploads();
if (CollectionUtils.isEmpty(uploads)) {
data = Collections.emptyList();
promotion = Collections.emptyList();
} else {
data = new ArrayList<>();
Set<String> promotionSet = new HashSet<>();
IndyContentClientModule content;
try {
content = indy.content();
} catch (IndyClientException e) {
throw new RepositoryManagerException("Failed to retrieve Indy content module. Reason: %s", e, e.getMessage());
}
for (TrackedContentEntryDTO upload : uploads) {
String path = upload.getPath();
StoreKey storeKey = upload.getStoreKey();
if (artifactFilter.acceptsForData(upload)) {
String identifier = computeIdentifier(upload);
String purl = computePurl(upload);
logger.info("Recording upload: {}", identifier);
RepositoryType repoType = toRepoType(storeKey.getPackageType());
TargetRepository targetRepository = getUploadsTargetRepository(repoType, content);
ArtifactQuality artifactQuality = getArtifactQuality(isTempBuild);
Artifact.Builder artifactBuilder = Artifact.Builder.newBuilder().md5(upload.getMd5()).sha1(upload.getSha1()).sha256(upload.getSha256()).size(upload.getSize()).deployPath(upload.getPath()).filename(new File(path).getName()).identifier(identifier).purl(purl).targetRepository(targetRepository).artifactQuality(artifactQuality).buildCategory(buildCategory);
Artifact artifact = validateArtifact(artifactBuilder.build());
data.add(artifact);
}
if (artifactFilter.acceptsForPromotion(upload, false)) {
promotionSet.add(path);
if (MAVEN_PKG_KEY.equals(storeKey.getPackageType()) && !isChecksum(path)) {
// add the standard checksums to ensure, they are promoted (Maven usually uses only one, so
// the other would be missing) but avoid adding checksums of checksums.
promotionSet.add(path + ".md5");
promotionSet.add(path + ".sha1");
}
}
}
promotion = new ArrayList<>(promotionSet);
}
logger.info("END: Process artifacts uploaded from build, took {} seconds", stopWatch.getTime(TimeUnit.SECONDS));
return new Uploads(data, promotion);
}
use of org.jboss.pnc.enums.RepositoryType in project pnc by project-ncl.
the class ArtifactProviderTest method testStore.
@Test
public void testStore() {
TargetRepository repo = TargetRepository.refBuilder().identifier("repo-id").repositoryPath("/repo/path").repositoryType(RepositoryType.MAVEN).build();
final String identifier = "foo:bar:0.0.1";
Artifact artifact = Artifact.builder().identifier(identifier).artifactQuality(ArtifactQuality.NEW).buildCategory(BuildCategory.STANDARD).build();
Artifact stored = provider.store(artifact);
assertThat(stored.getIdentifier()).isEqualTo(identifier);
assertThat(stored.getId()).isNotNull();
Mockito.verify(repository).save(ArgumentMatchers.argThat(a -> identifier.equals(a.getIdentifier())));
}
use of org.jboss.pnc.enums.RepositoryType in project pnc by project-ncl.
the class ArtifactEndpointTest method testGetAllArtifactsFilteredByRepoType.
@Test
public void testGetAllArtifactsFilteredByRepoType() throws RemoteResourceException {
ArtifactClient client = new ArtifactClient(RestClientConfiguration.asAnonymous());
RemoteCollection<ArtifactInfo> result;
RepositoryType type = RepositoryType.NPM;
result = client.getAllFiltered(null, null, type);
// from DatabaseDataInitializer
assertThat(result).hasSize(2).allSatisfy(a -> assertThat(a.getRepositoryType().equals(type)));
}
Aggregations