Search in sources :

Example 6 with ProjectVersionRef

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

the class MavenModelProcessorTest method resolveRepositoriesExpressionFromPropertyInProfile.

@Test
public void resolveRepositoriesExpressionFromPropertyInProfile() throws Exception {
    final URI src = new URI("http://nowhere.com/path/to/repo");
    final ProjectVersionRef childRef = new SimpleProjectVersionRef("org.test", "test-pom", "1.0");
    final LinkedHashMap<ProjectVersionRef, String> lineage = new LinkedHashMap<ProjectVersionRef, String>();
    lineage.put(childRef, "test-pom-1.0.pom.xml");
    final Location location = new SimpleLocation("test", src.toString(), false, true, true, false, true);
    final String base = PROJ_BASE + "resolve-expression-in-a-profile/";
    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<RepositoryView> rvs = pomView.getAllRepositories();
    assertThat(rvs, notNullValue());
    assertThat(rvs.size(), equalTo(3));
    assertThat(rvs.get(0).getName(), equalTo("repo.one"));
    assertThat(rvs.get(0).getUrl(), equalTo("http://repo.one.repository"));
    assertThat(rvs.get(1).getName(), equalTo("test.oracle.repo"));
    assertThat(rvs.get(1).getUrl(), equalTo("http://test.oracle.repository"));
    assertThat(rvs.get(2).getName(), equalTo("test.second.oracle.repo"));
    assertThat(rvs.get(2).getUrl(), equalTo("http://another.test.two.oracle.repository"));
}
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) RepositoryView(org.commonjava.maven.galley.maven.model.view.RepositoryView) URI(java.net.URI) LinkedHashMap(java.util.LinkedHashMap) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Transfer(org.commonjava.maven.galley.model.Transfer) 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 7 with ProjectVersionRef

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

the class MavenModelProcessorTest method resolvePluginVersionFromPropertyInProfile.

@Test
public void resolvePluginVersionFromPropertyInProfile() throws Exception {
    final URI src = new URI("http://nowhere.com/path/to/repo");
    final ProjectVersionRef childRef = new SimpleProjectVersionRef("org.test", "test-pom", "1.0");
    final LinkedHashMap<ProjectVersionRef, String> lineage = new LinkedHashMap<ProjectVersionRef, String>();
    lineage.put(childRef, "test-pom-1.0.pom.xml");
    final Location location = new SimpleLocation("test", src.toString(), false, true, true, false, true);
    final String base = PROJ_BASE + "version-expression-in-a-profile/";
    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());
    assertThat(pv.getVersion(), equalTo("2.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 && !rel.isManaged()) {
            if (seen) {
                fail("Multiple plugins found!");
            }
            seen = true;
            assertThat(rel.getTarget().getVersionString(), equalTo("2.0"));
        }
    }
    if (!seen) {
        fail("Plugin 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) 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 8 with ProjectVersionRef

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

the class MavenModelProcessorTest method resolvePluginVersionFromManagementExpression.

@Test
public void resolvePluginVersionFromManagementExpression() 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 + "version-expression-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());
    assertThat(pv.getVersion(), 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 && !rel.isManaged()) {
            if (seen) {
                fail("Multiple plugins found!");
            }
            seen = true;
            assertThat(rel.getTarget().getVersionString(), equalTo("1.0"));
        }
    }
    if (!seen) {
        fail("Plugin 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) 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 9 with ProjectVersionRef

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

the class MavenModelProcessorTest method resolveExpressionsBothInDepAndProfile.

@Test
public void resolveExpressionsBothInDepAndProfile() throws Exception {
    final URI src = new URI("http://nowhere.com/path/to/repo");
    final ProjectVersionRef childRef = new SimpleProjectVersionRef("org.test", "test-pom", "1.0");
    final LinkedHashMap<ProjectVersionRef, String> lineage = new LinkedHashMap<ProjectVersionRef, String>();
    lineage.put(childRef, "test-pom-1.0.pom.xml");
    final Location location = new SimpleLocation("test", src.toString(), false, true, true, false, true);
    final String base = PROJ_BASE + "resolve-expression-in-a-profile/";
    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));
    String url = pomView.resolveExpressions("${repo.url}", "test.oracle");
    assertThat(url, equalTo("http://test.oracle.repository"));
    List<DependencyView> dvs = pomView.getAllDirectDependencies();
    assertThat(dvs.get(0).getVersion(), equalTo("2.5"));
    String version = pomView.resolveExpressions("${commons.lang.value}");
    assertThat(version, equalTo("2.5"));
}
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) PluginDependencyView(org.commonjava.maven.galley.maven.model.view.PluginDependencyView) DependencyView(org.commonjava.maven.galley.maven.model.view.DependencyView) LinkedHashMap(java.util.LinkedHashMap) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Transfer(org.commonjava.maven.galley.model.Transfer) 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 ProjectVersionRef

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

the class MavenModelProcessor method addParentRelationship.

protected void addParentRelationship(final URI source, final Builder builder, final MavenPomView pomView, final ProjectVersionRef projectRef) {
    try {
        final ParentView parent = pomView.getParent();
        if (parent != null) {
            final ProjectVersionRef ref = parent.asProjectVersionRef();
            // force the InvalidVersionSpecificationException.
            ref.getVersionSpec();
            logger.info("Adding parent relationship for: {} to : {}", builder.getProjectRef(), ref);
            builder.withParent(new SimpleParentRelationship(source, builder.getProjectRef(), ref));
        } else {
            logger.info("Adding self-referential parent relationship for: {} to signify project has no parent, but is parsable.", builder.getProjectRef());
            builder.withParent(new SimpleParentRelationship(builder.getProjectRef()));
        }
    } catch (final GalleyMavenException e) {
        logger.error(String.format("%s: Parent reference is invalid! Reason: %s. Skipping.", projectRef, e.getMessage()), e);
    } catch (final InvalidVersionSpecificationException e) {
        logger.error(String.format("%s: Parent reference is invalid! Reason: %s. Skipping.", projectRef, e.getMessage()), e);
    } catch (final InvalidRefException e) {
        logger.error(String.format("%s: Parent reference is invalid! Reason: %s. Skipping.", projectRef, e.getMessage()), e);
    }
}
Also used : ParentView(org.commonjava.maven.galley.maven.model.view.ParentView) GalleyMavenException(org.commonjava.maven.galley.maven.GalleyMavenException) InvalidVersionSpecificationException(org.commonjava.maven.atlas.ident.version.InvalidVersionSpecificationException) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) InvalidRefException(org.commonjava.maven.atlas.ident.ref.InvalidRefException) SimpleParentRelationship(org.commonjava.maven.atlas.graph.rel.SimpleParentRelationship)

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