Search in sources :

Example 6 with EProjectDirectRelationships

use of org.commonjava.maven.atlas.graph.model.EProjectDirectRelationships in project galley by Commonjava.

the class MavenModelProcessor method readRelationships.

public EProjectDirectRelationships readRelationships(final MavenPomView pomView, final URI source, final ModelProcessorConfig discoveryConfig) throws GalleyMavenException {
    final boolean includeManagedDependencies = discoveryConfig.isIncludeManagedDependencies();
    final boolean includeBuildSection = discoveryConfig.isIncludeBuildSection();
    final boolean includeManagedPlugins = discoveryConfig.isIncludeManagedPlugins();
    logger.info("Reading relationships for: {}\n  (from: {})", pomView.getRef(), source);
    try {
        final ProjectVersionRef projectRef = pomView.getRef();
        final EProjectDirectRelationships.Builder builder = new EProjectDirectRelationships.Builder(source, projectRef);
        addParentRelationship(source, builder, pomView, projectRef);
        addDependencyRelationships(source, builder, pomView, projectRef, includeManagedDependencies);
        if (includeBuildSection) {
            addExtensionUsages(source, builder, pomView, projectRef);
            addPluginUsages(source, builder, pomView, projectRef, includeManagedPlugins);
        }
        return builder.build();
    } catch (final InvalidVersionSpecificationException e) {
        throw new GalleyMavenException("Failed to parse version for model: {}. Reason: {}", e, pomView, e.getMessage());
    } catch (final IllegalArgumentException e) {
        throw new GalleyMavenException("Failed to parse relationships for model: {}. Reason: {}", e, pomView, e.getMessage());
    }
}
Also used : Builder(org.commonjava.maven.atlas.graph.model.EProjectDirectRelationships.Builder) GalleyMavenException(org.commonjava.maven.galley.maven.GalleyMavenException) InvalidVersionSpecificationException(org.commonjava.maven.atlas.ident.version.InvalidVersionSpecificationException) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) Builder(org.commonjava.maven.atlas.graph.model.EProjectDirectRelationships.Builder) EProjectDirectRelationships(org.commonjava.maven.atlas.graph.model.EProjectDirectRelationships)

Example 7 with EProjectDirectRelationships

use of org.commonjava.maven.atlas.graph.model.EProjectDirectRelationships 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, false);
    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)

Aggregations

EProjectDirectRelationships (org.commonjava.maven.atlas.graph.model.EProjectDirectRelationships)7 ProjectVersionRef (org.commonjava.maven.atlas.ident.ref.ProjectVersionRef)5 Test (org.junit.Test)5 URI (java.net.URI)4 MavenPomView (org.commonjava.maven.galley.maven.model.view.MavenPomView)4 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)4 Transfer (org.commonjava.maven.galley.model.Transfer)4 LinkedHashMap (java.util.LinkedHashMap)3 ProjectRelationship (org.commonjava.maven.atlas.graph.rel.ProjectRelationship)3 SimpleProjectVersionRef (org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef)3 JoinString (org.commonjava.maven.atlas.ident.util.JoinString)3 PluginView (org.commonjava.maven.galley.maven.model.view.PluginView)3 Location (org.commonjava.maven.galley.model.Location)3 SimpleLocation (org.commonjava.maven.galley.model.SimpleLocation)3 TestDownload (org.commonjava.maven.galley.testing.core.transport.job.TestDownload)3 InputStream (java.io.InputStream)2 AbstractIndyFunctionalTest (org.commonjava.indy.ftest.core.AbstractIndyFunctionalTest)2 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1