Search in sources :

Example 41 with ProjectVersionRef

use of org.commonjava.maven.atlas.ident.ref.ProjectVersionRef in project indy by Commonjava.

the class AbstractHttproxFunctionalTest method loadPom.

protected PomRef loadPom(final String name, final Map<String, String> substitutions) {
    try {
        final InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream(name.endsWith(".pom") ? name : name + ".pom");
        String pom = IOUtils.toString(stream);
        IOUtils.closeQuietly(stream);
        for (final Map.Entry<String, String> entry : substitutions.entrySet()) {
            pom = pom.replace("@" + entry.getKey() + "@", entry.getValue());
        }
        final PomPeek peek = new PomPeek(pom, false);
        final ProjectVersionRef gav = peek.getKey();
        final String path = String.format("%s/%s/%s/%s-%s.pom", gav.getGroupId().replace('.', '/'), gav.getArtifactId(), gav.getVersionString(), gav.getArtifactId(), gav.getVersionString());
        return new PomRef(pom, path);
    } catch (final Exception e) {
        e.printStackTrace();
        fail("Failed to read POM from: " + name);
    }
    return null;
}
Also used : InputStream(java.io.InputStream) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) PomPeek(org.commonjava.maven.galley.maven.parse.PomPeek) Map(java.util.Map) IOException(java.io.IOException)

Example 42 with ProjectVersionRef

use of org.commonjava.maven.atlas.ident.ref.ProjectVersionRef 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

ProjectVersionRef (org.commonjava.maven.atlas.ident.ref.ProjectVersionRef)42 SimpleProjectVersionRef (org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef)22 Test (org.junit.Test)22 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)12 TestDownload (org.commonjava.maven.galley.testing.core.transport.job.TestDownload)11 MavenPomView (org.commonjava.maven.galley.maven.model.view.MavenPomView)10 URI (java.net.URI)9 JoinString (org.commonjava.maven.atlas.ident.util.JoinString)9 GalleyMavenException (org.commonjava.maven.galley.maven.GalleyMavenException)9 Transfer (org.commonjava.maven.galley.model.Transfer)9 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)8 PomPeek (org.commonjava.maven.galley.maven.parse.PomPeek)8 InvalidVersionSpecificationException (org.commonjava.maven.atlas.ident.version.InvalidVersionSpecificationException)6 Document (org.w3c.dom.Document)6 File (java.io.File)5 ArrayList (java.util.ArrayList)5 LinkedHashMap (java.util.LinkedHashMap)5 EProjectDirectRelationships (org.commonjava.maven.atlas.graph.model.EProjectDirectRelationships)5 InvalidRefException (org.commonjava.maven.atlas.ident.ref.InvalidRefException)5 PluginDependencyView (org.commonjava.maven.galley.maven.model.view.PluginDependencyView)5