use of org.commonjava.atlas.maven.ident.ref.ArtifactRef in project indy by Commonjava.
the class PromotionValidationTools method readPom.
@Measure
public MavenPomView readPom(final String path, final ValidationRequest request, final StoreKey... extraLocations) throws IndyWorkflowException, GalleyMavenException, IndyDataException {
ArtifactRef artifactRef = getArtifact(path);
if (artifactRef == null) {
return null;
}
Transfer transfer = retrieve(request.getSourceRepository(), path);
List<Location> locations = new ArrayList<>(extraLocations.length + 1);
locations.add(transfer.getLocation());
addLocations(locations, extraLocations);
return pomReader.read(artifactRef.asProjectVersionRef(), transfer, locations, MavenPomView.ALL_PROFILES);
}
use of org.commonjava.atlas.maven.ident.ref.ArtifactRef in project indy by Commonjava.
the class KojiRepairManager method repairPathMask.
public KojiRepairResult repairPathMask(KojiRepairRequest request, String user, boolean skipLock) throws KojiRepairException {
KojiRepairResult ret = new KojiRepairResult(request);
if (skipLock || opLock.tryLock()) {
try {
ArtifactStore store = getRequestedStore(request, ret);
if (store == null) {
return ret;
}
store = store.copyOf();
StoreKey remoteKey = request.getSource();
if (remoteKey.getType() == remote) {
final String nvr = kojiUtils.getBuildNvr(remoteKey);
if (nvr == null) {
String error = String.format("Not a koji store: %s", remoteKey);
return ret.withError(error);
}
try {
KojiSessionInfo session = null;
KojiBuildInfo build = kojiCachedClient.getBuildInfo(nvr, session);
List<KojiArchiveInfo> archives = kojiCachedClient.listArchivesForBuild(build.getId(), session);
ArtifactRef artifactRef = SimpleArtifactRef.parse(store.getMetadata(CREATION_TRIGGER_GAV));
if (artifactRef == null) {
String error = String.format("Koji remote repository: %s does not have %s metadata. Cannot retrieve accurate path masks.", remoteKey, CREATION_TRIGGER_GAV);
return ret.withError(error);
}
// set pathMaskPatterns using build output paths
Set<String> patterns = kojiPathFormatter.getPatterns(store.getKey(), artifactRef, archives, true);
logger.debug("For repo: {}, resetting path_mask_patterns to:\n\n{}\n\n", store.getKey(), patterns);
KojiRepairResult.RepairResult repairResult = new KojiRepairResult.RepairResult(remoteKey);
repairResult.withPropertyChange("path_mask_patterns", store.getPathMaskPatterns(), patterns);
ret.withResult(repairResult);
store.setPathMaskPatterns(patterns);
final ChangeSummary changeSummary = new ChangeSummary(user, "Repairing remote repository path masks to Koji build: " + build.getNvr());
storeManager.storeArtifactStore(store, changeSummary, false, true, new EventMetadata());
} catch (KojiClientException e) {
String error = String.format("Cannot getBuildInfo: %s, error: %s", remoteKey, e);
logger.debug(error, e);
return ret.withError(error, e);
} catch (IndyDataException e) {
String error = String.format("Failed to store changed remote repository: %s, error: %s", remoteKey, e);
logger.debug(error, e);
return ret.withError(error, e);
}
} else {
String error = String.format("Not a remote koji repository: %s", remoteKey);
return ret.withError(error);
}
} finally {
if (!skipLock) {
opLock.unlock();
}
}
} else {
throw new KojiRepairException("Koji repair manager is busy.");
}
return ret;
}
use of org.commonjava.atlas.maven.ident.ref.ArtifactRef in project indy by Commonjava.
the class KojiPathPatternFormatter method getPatterns.
public Set<String> getPatterns(final StoreKey inStore, ArtifactRef artifactRef, List<KojiArchiveInfo> archives, boolean skipVersionTest) {
Set<String> patterns = new HashSet<>();
for (KojiArchiveInfo a : archives) {
if (!inStore.getPackageType().equals(a.getBuildType())) {
logger.info("Discarding non-{} archive from path patterns: {}", inStore.getPackageType(), a);
continue;
}
ArtifactRef ar = a.asArtifact();
if (!skipVersionTest && !kojiUtils.isVersionSignatureAllowedWithVersion(a.getVersion())) {
logger.warn("Cannot use Koji archive for path_mask_patterns: {}. Version '{}' is not allowed from Koji.", a, a.getVersion());
continue;
}
String pattern = getPatternString(ar, a);
if (!skipVersionTest && !kojiUtils.isVersionSignatureAllowedWithVersion(a.getVersion())) {
logger.warn("Cannot use Koji archive for path_mask_patterns: {}. Version '{}' is not allowed from Koji.", a, a.getVersion());
continue;
}
if (pattern != null) {
patterns.add(pattern);
}
}
if (!patterns.isEmpty()) {
// Add metadata.xml to path mask patterns
String meta = getMetaString(artifactRef);
if (meta != null) {
patterns.add(meta);
}
}
return patterns;
}
use of org.commonjava.atlas.maven.ident.ref.ArtifactRef in project indy by Commonjava.
the class PromotionValidationTools method readLocalPom.
@Measure
public MavenPomView readLocalPom(final String path, final ValidationRequest request) throws IndyWorkflowException, GalleyMavenException {
ArtifactRef artifactRef = getArtifact(path);
if (artifactRef == null) {
throw new IndyWorkflowException("Invalid artifact path: %s. Could not parse ArtifactRef from path.", path);
}
Transfer transfer = retrieve(request.getSourceRepository(), path);
return pomReader.readLocalPom(artifactRef.asProjectVersionRef(), transfer, MavenPomView.ALL_PROFILES);
}
use of org.commonjava.atlas.maven.ident.ref.ArtifactRef in project indy by Commonjava.
the class PromotionValidationTools method getRelationshipsForPom.
public Set<ProjectRelationship<?, ?>> getRelationshipsForPom(final String path, final ModelProcessorConfig config, final ValidationRequest request, final StoreKey... extraLocations) throws IndyWorkflowException, GalleyMavenException, IndyDataException {
Logger logger = LoggerFactory.getLogger(getClass());
logger.trace("Retrieving relationships for POM: {} (using extra locations: {})", path, Arrays.asList(extraLocations));
ArtifactRef artifactRef = getArtifact(path);
if (artifactRef == null) {
logger.trace("{} is not a valid artifact reference. Skipping.", path);
return null;
}
StoreKey key = request.getSourceRepository().getKey();
Transfer transfer = retrieve(request.getSourceRepository(), path);
if (transfer == null) {
logger.trace("Could not retrieve Transfer instance for: {} (path: {}, extra locations: {})", key, path, Arrays.asList(extraLocations));
return null;
}
List<Location> locations = new ArrayList<>(extraLocations.length + 1);
locations.add(transfer.getLocation());
addLocations(locations, extraLocations);
MavenPomView pomView = pomReader.read(artifactRef.asProjectVersionRef(), transfer, locations, MavenPomView.ALL_PROFILES);
try {
URI source = new URI("indy:" + key.getType().name() + ":" + key.getName());
return modelProcessor.readRelationships(pomView, source, config).getAllRelationships();
} catch (final URISyntaxException e) {
throw new IllegalStateException("Failed to construct URI for ArtifactStore: " + key + ". Reason: " + e.getMessage(), e);
}
}
Aggregations