Search in sources :

Example 1 with ModelProcessorConfig

use of org.commonjava.maven.galley.maven.rel.ModelProcessorConfig in project indy by Commonjava.

the class RelateGenerationManager method generateRelationshipFile.

/**
     * Generate relationship file for pom transfer.
     * @param transfer
     * @param op
     * @return transfer pointing to the generated rel file.
     */
public Transfer generateRelationshipFile(Transfer transfer, TransferOperation op) {
    final Logger logger = LoggerFactory.getLogger(getClass());
    logger.debug("Relate generation for {}", transfer);
    if (transfer == null) {
        logger.debug("No transfer. No .rel generation performed.");
        return null;
    }
    String txfrPath = transfer.getPath();
    if (!txfrPath.endsWith(".pom")) {
        logger.debug("This is not a pom transfer.");
        return null;
    }
    ArtifactPathInfo artPathInfo = ArtifactPathInfo.parse(txfrPath);
    if (artPathInfo == null) {
        logger.debug("Not an artifact download ({}). No .rel generation performed.", txfrPath);
        return null;
    }
    ConcreteResource pomResource = transfer.getResource();
    StoreKey storeKey = StoreKey.fromString(transfer.getLocation().getName());
    ArtifactStore store;
    try {
        store = storeManager.getArtifactStore(storeKey);
    } catch (final IndyDataException ex) {
        logger.error("Error retrieving artifactStore with key " + storeKey, ex);
        return null;
    }
    logger.debug("Generate .rel corresponding to associated POM download: {}/{}", storeKey, pomResource.getPath());
    try {
        URI source = new URI(pomResource.getLocation().getUri() + REL_SUFFIX);
        ProjectVersionRef ref = artPathInfo.getProjectId();
        // get all groups that this store is a member of
        Set<ArtifactStore> stores = new HashSet<>();
        stores.add(store);
        stores.addAll(storeManager.query().getGroupsContaining(store.getKey()));
        List<? extends Location> supplementalLocations = LocationUtils.toLocations(stores.toArray(new ArtifactStore[0]));
        MavenPomView pomView = mavenPomReader.read(ref, transfer, supplementalLocations, ALL_PROFILES);
        EProjectDirectRelationships rel = mavenModelProcessor.readRelationships(pomView, source, new ModelProcessorConfig());
        Transfer transferRel = transfer.getSiblingMeta(REL_SUFFIX);
        writeRelationships(rel, transferRel, op);
        return transferRel;
    } catch (Exception e) {
        logger.error("Error generating .rel file for " + txfrPath + " from store " + store, e);
        return null;
    }
}
Also used : Logger(org.slf4j.Logger) StoreKey(org.commonjava.indy.model.core.StoreKey) URI(java.net.URI) IOException(java.io.IOException) IndyDataException(org.commonjava.indy.data.IndyDataException) IndyDataException(org.commonjava.indy.data.IndyDataException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) ArtifactPathInfo(org.commonjava.maven.atlas.ident.util.ArtifactPathInfo) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) EProjectDirectRelationships(org.commonjava.maven.atlas.graph.model.EProjectDirectRelationships) ModelProcessorConfig(org.commonjava.maven.galley.maven.rel.ModelProcessorConfig) Transfer(org.commonjava.maven.galley.model.Transfer) MavenPomView(org.commonjava.maven.galley.maven.model.view.MavenPomView) HashSet(java.util.HashSet)

Aggregations

IOException (java.io.IOException)1 URI (java.net.URI)1 HashSet (java.util.HashSet)1 IndyDataException (org.commonjava.indy.data.IndyDataException)1 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)1 StoreKey (org.commonjava.indy.model.core.StoreKey)1 EProjectDirectRelationships (org.commonjava.maven.atlas.graph.model.EProjectDirectRelationships)1 ProjectVersionRef (org.commonjava.maven.atlas.ident.ref.ProjectVersionRef)1 ArtifactPathInfo (org.commonjava.maven.atlas.ident.util.ArtifactPathInfo)1 MavenPomView (org.commonjava.maven.galley.maven.model.view.MavenPomView)1 ModelProcessorConfig (org.commonjava.maven.galley.maven.rel.ModelProcessorConfig)1 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)1 Transfer (org.commonjava.maven.galley.model.Transfer)1 Logger (org.slf4j.Logger)1