Search in sources :

Example 6 with MavenPomView

use of org.commonjava.maven.galley.maven.model.view.MavenPomView in project galley by Commonjava.

the class MavenPomReader method readLocalPom.

public MavenPomView readLocalPom(final ProjectVersionRef ref, final Transfer transfer, final boolean cache, final EventMetadata eventMetadata, final String... activeProfileIds) throws GalleyMavenException {
    DocRef<ProjectVersionRef> dr;
    try {
        dr = getDocRef(ref, transfer, cache, eventMetadata);
    } catch (final TransferException e) {
        throw new GalleyMavenException("Failed to parse POM for: {}. Reason: {}", e, ref, e.getMessage());
    }
    final MavenPomView view = new MavenPomView(ref, Collections.singletonList(dr), xpath, pluginDefaults, pluginImplications, xml, activeProfileIds);
    logStructure(view);
    return view;
}
Also used : TransferException(org.commonjava.maven.galley.TransferException) GalleyMavenException(org.commonjava.maven.galley.maven.GalleyMavenException) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) MavenPomView(org.commonjava.maven.galley.maven.model.view.MavenPomView)

Example 7 with MavenPomView

use of org.commonjava.maven.galley.maven.model.view.MavenPomView in project galley by Commonjava.

the class MavenPomReader method read.

public MavenPomView read(final ProjectVersionRef ref, final List<? extends Location> locations, final boolean cache, final EventMetadata eventMetadata, final String... activeProfileIds) throws GalleyMavenException {
    final List<DocRef<ProjectVersionRef>> stack = new ArrayList<DocRef<ProjectVersionRef>>();
    ProjectVersionRef next = ref;
    do {
        DocRef<ProjectVersionRef> dr;
        try {
            dr = getDocRef(next, locations, cache, eventMetadata);
        } catch (final TransferException e) {
            throw new GalleyMavenException("Failed to retrieve POM for: {}, {} levels deep in ancestry stack of: {}. Reason: {}", e, next, stack.size(), ref, e.getMessage());
        }
        if (dr == null) {
            throw new GalleyMavenException("Cannot resolve {}, {} levels dep in the ancestry stack of: {}", next, stack.size(), ref);
        }
        stack.add(dr);
        next = xml.getParentRef(dr.getDoc());
    } while (next != null);
    final MavenPomView view = new MavenPomView(ref, stack, xpath, pluginDefaults, pluginImplications, xml, activeProfileIds);
    assembleImportedInformation(view, locations);
    logStructure(view);
    return view;
}
Also used : TransferException(org.commonjava.maven.galley.TransferException) GalleyMavenException(org.commonjava.maven.galley.maven.GalleyMavenException) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) ArrayList(java.util.ArrayList) DocRef(org.commonjava.maven.galley.maven.model.view.DocRef) MavenPomView(org.commonjava.maven.galley.maven.model.view.MavenPomView)

Example 8 with MavenPomView

use of org.commonjava.maven.galley.maven.model.view.MavenPomView 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.maven.atlas.ident.ref.ArtifactRef) Location(org.commonjava.maven.galley.model.Location)

Example 9 with MavenPomView

use of org.commonjava.maven.galley.maven.model.view.MavenPomView in project galley by Commonjava.

the class MavenModelProcessorTest method resolvePluginDependencyFromManagedInfo.

@Test
public void resolvePluginDependencyFromManagedInfo() throws Exception {
    final URI src = new URI("http://nowhere.com/path/to/repo");
    final ProjectVersionRef childRef = new SimpleProjectVersionRef("org.test", "test-child", "1.0");
    final LinkedHashMap<ProjectVersionRef, String> lineage = new LinkedHashMap<ProjectVersionRef, String>();
    lineage.put(childRef, "child.pom.xml");
    lineage.put(new SimpleProjectVersionRef("org.test", "test-parent", "1.0"), "parent.pom.xml");
    final Location location = new SimpleLocation("test", src.toString(), false, true, true, false, true);
    final String base = PROJ_BASE + "dependency-in-managed-parent-plugin/";
    for (final Entry<ProjectVersionRef, String> entry : lineage.entrySet()) {
        final ProjectVersionRef ref = entry.getKey();
        final String filename = entry.getValue();
        final String path = ArtifactPathUtils.formatArtifactPath(ref.asPomArtifact(), fixture.getTypeMapper());
        fixture.getTransport().registerDownload(new ConcreteResource(location, path), new TestDownload(base + filename));
    }
    final Transfer transfer = fixture.getArtifactManager().retrieve(location, childRef.asPomArtifact());
    final MavenPomView pomView = fixture.getPomReader().read(childRef, transfer, Collections.singletonList(location));
    final List<PluginView> buildPlugins = pomView.getAllBuildPlugins();
    assertThat(buildPlugins, notNullValue());
    assertThat(buildPlugins.size(), equalTo(1));
    final PluginView pv = buildPlugins.get(0);
    assertThat(pv, notNullValue());
    final List<PluginDependencyView> deps = pv.getLocalPluginDependencies();
    assertThat(deps, notNullValue());
    assertThat(deps.size(), equalTo(1));
    final PluginDependencyView pdv = deps.get(0);
    assertThat(pdv, notNullValue());
    assertThat(pdv.asArtifactRef().getVersionString(), equalTo("1.0"));
    final ModelProcessorConfig discoveryConfig = new ModelProcessorConfig();
    discoveryConfig.setIncludeManagedDependencies(true);
    discoveryConfig.setIncludeBuildSection(true);
    discoveryConfig.setIncludeManagedPlugins(false);
    EProjectDirectRelationships result = fixture.getModelProcessor().readRelationships(pomView, src, discoveryConfig);
    final Set<ProjectRelationship<?, ?>> rels = result.getExactAllRelationships();
    logger.info("Found {} relationships:\n\n  {}", rels.size(), new JoinString("\n  ", rels));
    boolean seen = false;
    for (final ProjectRelationship<?, ?> rel : rels) {
        if (rel.getType() == RelationshipType.PLUGIN_DEP && !rel.isManaged()) {
            if (seen) {
                fail("Multiple plugin dependencies found!");
            }
            seen = true;
            assertThat(rel.getTarget().getVersionString(), equalTo("1.0"));
        }
    }
    if (!seen) {
        fail("Plugin-dependency relationship not found!");
    }
}
Also used : TestDownload(org.commonjava.maven.galley.testing.core.transport.job.TestDownload) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) URI(java.net.URI) LinkedHashMap(java.util.LinkedHashMap) PluginDependencyView(org.commonjava.maven.galley.maven.model.view.PluginDependencyView) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) ProjectRelationship(org.commonjava.maven.atlas.graph.rel.ProjectRelationship) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Transfer(org.commonjava.maven.galley.model.Transfer) EProjectDirectRelationships(org.commonjava.maven.atlas.graph.model.EProjectDirectRelationships) PluginView(org.commonjava.maven.galley.maven.model.view.PluginView) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) MavenPomView(org.commonjava.maven.galley.maven.model.view.MavenPomView) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) Location(org.commonjava.maven.galley.model.Location) Test(org.junit.Test)

Example 10 with MavenPomView

use of org.commonjava.maven.galley.maven.model.view.MavenPomView in project galley by Commonjava.

the class MavenPomReader method assembleImportedInformation.

private void assembleImportedInformation(final MavenPomView view, final List<? extends Location> locations) throws GalleyMavenException {
    final List<DependencyView> md = view.getAllBOMs();
    for (final DependencyView dv : md) {
        final ProjectVersionRef ref = dv.asProjectVersionRef();
        logger.debug("Found BOM: {} for: {}", ref, view.getRef());
        // This is a BOM, it's likely to be used in multiple locations...cache this.
        final MavenPomView imp = read(ref, locations, true);
        view.addMixin(new MavenXmlMixin<ProjectVersionRef>(imp, MavenXmlMixin.DEPENDENCY_MIXIN));
    }
}
Also used : ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) DependencyView(org.commonjava.maven.galley.maven.model.view.DependencyView) MavenPomView(org.commonjava.maven.galley.maven.model.view.MavenPomView)

Aggregations

MavenPomView (org.commonjava.maven.galley.maven.model.view.MavenPomView)12 ProjectVersionRef (org.commonjava.maven.atlas.ident.ref.ProjectVersionRef)10 SimpleProjectVersionRef (org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef)9 URI (java.net.URI)7 Transfer (org.commonjava.maven.galley.model.Transfer)7 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)6 Location (org.commonjava.maven.galley.model.Location)6 LinkedHashMap (java.util.LinkedHashMap)5 JoinString (org.commonjava.maven.atlas.ident.util.JoinString)5 SimpleLocation (org.commonjava.maven.galley.model.SimpleLocation)5 TestDownload (org.commonjava.maven.galley.testing.core.transport.job.TestDownload)5 Test (org.junit.Test)5 EProjectDirectRelationships (org.commonjava.maven.atlas.graph.model.EProjectDirectRelationships)4 ArrayList (java.util.ArrayList)3 ProjectRelationship (org.commonjava.maven.atlas.graph.rel.ProjectRelationship)3 TransferException (org.commonjava.maven.galley.TransferException)3 GalleyMavenException (org.commonjava.maven.galley.maven.GalleyMavenException)3 PluginView (org.commonjava.maven.galley.maven.model.view.PluginView)3 Logger (org.slf4j.Logger)3 StoreKey (org.commonjava.indy.model.core.StoreKey)2