Search in sources :

Example 1 with ArtifactRef

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);
}
Also used : Transfer(org.commonjava.maven.galley.model.Transfer) ArrayList(java.util.ArrayList) ArtifactRef(org.commonjava.atlas.maven.ident.ref.ArtifactRef) Location(org.commonjava.maven.galley.model.Location) Measure(org.commonjava.o11yphant.metrics.annotation.Measure)

Example 2 with ArtifactRef

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;
}
Also used : StoreKey(org.commonjava.indy.model.core.StoreKey) KojiArchiveInfo(com.redhat.red.build.koji.model.xmlrpc.KojiArchiveInfo) SimpleArtifactRef(org.commonjava.atlas.maven.ident.ref.SimpleArtifactRef) ArtifactRef(org.commonjava.atlas.maven.ident.ref.ArtifactRef) KojiRepairResult(org.commonjava.indy.koji.model.KojiRepairResult) KojiMultiRepairResult(org.commonjava.indy.koji.model.KojiMultiRepairResult) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) IndyDataException(org.commonjava.indy.data.IndyDataException) KojiClientException(com.redhat.red.build.koji.KojiClientException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) KojiRepairResult(org.commonjava.indy.koji.model.KojiRepairResult) KojiSessionInfo(com.redhat.red.build.koji.model.xmlrpc.KojiSessionInfo) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) KojiBuildInfo(com.redhat.red.build.koji.model.xmlrpc.KojiBuildInfo)

Example 3 with ArtifactRef

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;
}
Also used : KojiArchiveInfo(com.redhat.red.build.koji.model.xmlrpc.KojiArchiveInfo) HashSet(java.util.HashSet) ArtifactRef(org.commonjava.atlas.maven.ident.ref.ArtifactRef)

Example 4 with ArtifactRef

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);
}
Also used : IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Transfer(org.commonjava.maven.galley.model.Transfer) ArtifactRef(org.commonjava.atlas.maven.ident.ref.ArtifactRef) Measure(org.commonjava.o11yphant.metrics.annotation.Measure)

Example 5 with ArtifactRef

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);
    }
}
Also used : Transfer(org.commonjava.maven.galley.model.Transfer) ArrayList(java.util.ArrayList) URISyntaxException(java.net.URISyntaxException) Logger(org.slf4j.Logger) StoreKey(org.commonjava.indy.model.core.StoreKey) URI(java.net.URI) MavenPomView(org.commonjava.maven.galley.maven.model.view.MavenPomView) ArtifactRef(org.commonjava.atlas.maven.ident.ref.ArtifactRef) Location(org.commonjava.maven.galley.model.Location)

Aggregations

ArtifactRef (org.commonjava.atlas.maven.ident.ref.ArtifactRef)6 Transfer (org.commonjava.maven.galley.model.Transfer)3 Measure (org.commonjava.o11yphant.metrics.annotation.Measure)3 KojiArchiveInfo (com.redhat.red.build.koji.model.xmlrpc.KojiArchiveInfo)2 ArrayList (java.util.ArrayList)2 StoreKey (org.commonjava.indy.model.core.StoreKey)2 Location (org.commonjava.maven.galley.model.Location)2 Logger (org.slf4j.Logger)2 KojiClientException (com.redhat.red.build.koji.KojiClientException)1 KojiBuildInfo (com.redhat.red.build.koji.model.xmlrpc.KojiBuildInfo)1 KojiSessionInfo (com.redhat.red.build.koji.model.xmlrpc.KojiSessionInfo)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 HashSet (java.util.HashSet)1 SimpleArtifactRef (org.commonjava.atlas.maven.ident.ref.SimpleArtifactRef)1 ArtifactPathInfo (org.commonjava.atlas.maven.ident.util.ArtifactPathInfo)1 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)1 ChangeSummary (org.commonjava.indy.audit.ChangeSummary)1 IndyDataException (org.commonjava.indy.data.IndyDataException)1 KojiMultiRepairResult (org.commonjava.indy.koji.model.KojiMultiRepairResult)1