Search in sources :

Example 11 with SimpleProjectVersionRef

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

the class EmbeddableCDI_HTTPArtifactDownload_Test method resolveArtifactViaHttp.

@Test
public void resolveArtifactViaHttp() throws Exception {
    String path = "/group/artifact/1/artifact-1.pom";
    String content = "this is a test.";
    server.expect(path, 200, content);
    Transfer transfer = transfers.retrieve(new SimpleLocation(server.getBaseUri()), new SimpleProjectVersionRef("group", "artifact", "1").asPomArtifact());
    assertThat(transfer, notNullValue());
    InputStream stream = null;
    try {
        stream = transfer.openInputStream();
        assertThat(IOUtils.toString(stream), equalTo(content));
    } finally {
        IOUtils.closeQuietly(stream);
    }
}
Also used : InputStream(java.io.InputStream) Transfer(org.commonjava.maven.galley.model.Transfer) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) Test(org.junit.Test)

Example 12 with SimpleProjectVersionRef

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

the class XMLInfrastructure method getProjectVersionRef.

public ProjectVersionRef getProjectVersionRef(final Document doc) throws GalleyMavenXMLException {
    final Element project = doc.getDocumentElement();
    String gid = getChildText("groupId", project);
    final String aid = getChildText("artifactId", project);
    String ver = getChildText("version", project);
    if (isEmpty(gid) || isEmpty(ver)) {
        final NodeList nl = project.getElementsByTagName("parent");
        if (nl == null || nl.getLength() < 1) {
            logger.debug("No parent declaration.");
            return null;
        }
        final Element parent = (Element) nl.item(0);
        gid = getChildText("groupId", parent);
        ver = getChildText("version", parent);
    }
    if (isEmpty(gid) || isEmpty(aid) || isEmpty(ver)) {
        throw new GalleyMavenXMLException("Project GAV is invalid! (g=%s,  a=%s, v=%s)", gid, aid, ver);
    }
    return new SimpleProjectVersionRef(gid, aid, ver);
}
Also used : Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef)

Example 13 with SimpleProjectVersionRef

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

the class EmbeddableCDI_HTTPArtifactMetadataDownload_Test method resolveArtifactViaHttp.

@Test
public void resolveArtifactViaHttp() throws Exception {
    String path = "/group/artifact/1-SNAPSHOT/maven-metadata.xml";
    String content = "this is a test.";
    server.expect(path, 200, content);
    Transfer transfer = transfers.retrieve(new SimpleLocation(server.getBaseUri()), new SimpleProjectVersionRef("group", "artifact", "1-SNAPSHOT").asPomArtifact());
    assertThat(transfer, notNullValue());
    InputStream stream = null;
    try {
        stream = transfer.openInputStream();
        assertThat(IOUtils.toString(stream), equalTo(content));
    } finally {
        IOUtils.closeQuietly(stream);
    }
}
Also used : InputStream(java.io.InputStream) Transfer(org.commonjava.maven.galley.model.Transfer) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) Test(org.junit.Test)

Example 14 with SimpleProjectVersionRef

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

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

the class ArtifactPathUtilsTest method handleRemoteSnapshotArtifactPath.

@Test
public void handleRemoteSnapshotArtifactPath() throws Exception {
    final ProjectVersionRef pvr = new SimpleProjectVersionRef("org.group", "artifact-id", "1.0-20140603.151226-11");
    final TypeMapper mapper = new StandardTypeMapper();
    final String path = ArtifactPathUtils.formatArtifactPath(pvr.asJarArtifact(), mapper);
    assertThat(path.equals("org/group/artifact-id/1.0-SNAPSHOT/artifact-id-" + pvr.getVersionString() + ".jar"), equalTo(true));
}
Also used : StandardTypeMapper(org.commonjava.maven.galley.maven.internal.type.StandardTypeMapper) TypeMapper(org.commonjava.maven.galley.maven.spi.type.TypeMapper) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) StandardTypeMapper(org.commonjava.maven.galley.maven.internal.type.StandardTypeMapper) Test(org.junit.Test)

Aggregations

SimpleProjectVersionRef (org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef)21 Test (org.junit.Test)18 ProjectVersionRef (org.commonjava.maven.atlas.ident.ref.ProjectVersionRef)14 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)12 Transfer (org.commonjava.maven.galley.model.Transfer)11 TestDownload (org.commonjava.maven.galley.testing.core.transport.job.TestDownload)11 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)8 SimpleLocation (org.commonjava.maven.galley.model.SimpleLocation)7 URI (java.net.URI)5 LinkedHashMap (java.util.LinkedHashMap)5 JoinString (org.commonjava.maven.atlas.ident.util.JoinString)5 MavenPomView (org.commonjava.maven.galley.maven.model.view.MavenPomView)5 Location (org.commonjava.maven.galley.model.Location)5 EProjectDirectRelationships (org.commonjava.maven.atlas.graph.model.EProjectDirectRelationships)3 ProjectRelationship (org.commonjava.maven.atlas.graph.rel.ProjectRelationship)3 PluginView (org.commonjava.maven.galley.maven.model.view.PluginView)3 InputStream (java.io.InputStream)2 StoreResource (org.commonjava.indy.content.StoreResource)2 SingleVersion (org.commonjava.maven.atlas.ident.version.SingleVersion)2 PluginDependencyView (org.commonjava.maven.galley.maven.model.view.PluginDependencyView)2