Search in sources :

Example 1 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 2 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 3 with SimpleProjectVersionRef

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

the class MavenPomViewTest method buildExtension.

@Test
public void buildExtension() throws Exception {
    MavenPomView pomView = loadPoms("pom-with-build-ext.xml");
    List<ExtensionView> extensions = pomView.getBuildExtensions();
    assertThat(extensions, notNullValue());
    assertThat(extensions.size(), equalTo(1));
    assertThat(extensions.get(0).asProjectVersionRef(), equalTo((ProjectVersionRef) new SimpleProjectVersionRef("ext.group", "ext-artifact", "1.0")));
}
Also used : ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) Test(org.junit.Test)

Example 4 with SimpleProjectVersionRef

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

the class MavenPomViewTest method profileBuildExtension.

@Test
public void profileBuildExtension() throws Exception {
    MavenPomView pomView = loadPoms(new String[] { "test" }, "pom-with-profile-build-ext.xml");
    List<ExtensionView> extensions = pomView.getBuildExtensions();
    assertThat(extensions, notNullValue());
    assertThat(extensions.size(), equalTo(1));
    assertThat(extensions.get(0).asProjectVersionRef(), equalTo((ProjectVersionRef) new SimpleProjectVersionRef("ext.group", "ext-artifact", "1.0")));
}
Also used : ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) Test(org.junit.Test)

Example 5 with SimpleProjectVersionRef

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

the class ArtifactManagerImplTest method resolveSnapshot_FirstMatch_SingletonLocationList_TwoSnapshotList_LatestVersionStrategy.

@Test
public void resolveSnapshot_FirstMatch_SingletonLocationList_TwoSnapshotList_LatestVersionStrategy() throws Exception {
    final String base = "2-snapshots-1-location/";
    final String testResource = base + "two-snapshots.xml";
    final String testPomResource = base + "two-snapshots-pom.xml";
    final ProjectVersionRef ref = new SimpleProjectVersionRef("org.group2", "artifact", "1.0-SNAPSHOT");
    final ConcreteResource metadataResource = new ConcreteResource(LOCATION, fixture.snapshotMetadataPath(ref));
    final ConcreteResource pomResource = new ConcreteResource(LOCATION, fixture.pomPath(ref.selectVersion("1.0-20140604.102909-1").asPomArtifact()));
    fixture.getTransport().registerDownload(metadataResource, new TestDownload(ROOT + testResource));
    fixture.getTransport().registerDownload(pomResource, new TestDownload(ROOT + testPomResource));
    final Transfer retrieved = fixture.getArtifactManager().retrieve(LOCATION, ref.asPomArtifact(), new EventMetadata());
    final Document document = fixture.getXml().parse(retrieved, new EventMetadata());
    final ProjectVersionRef result = fixture.getXml().getProjectVersionRef(document);
    System.out.println(result);
    assertThat(result, notNullValue());
    assertThat(result.getVersionString(), equalTo("1.0-20140604.102909-1"));
}
Also used : TestDownload(org.commonjava.maven.galley.testing.core.transport.job.TestDownload) 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) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) Document(org.w3c.dom.Document) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Test(org.junit.Test)

Aggregations

SimpleProjectVersionRef (org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef)49 ProjectVersionRef (org.commonjava.maven.atlas.ident.ref.ProjectVersionRef)41 Test (org.junit.Test)36 ArrayList (java.util.ArrayList)22 HashMap (java.util.HashMap)11 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)11 TestDownload (org.commonjava.maven.galley.testing.core.transport.job.TestDownload)11 Model (org.apache.maven.model.Model)9 RestException (org.commonjava.maven.ext.io.rest.exception.RestException)9 Transfer (org.commonjava.maven.galley.model.Transfer)9 SimpleLocation (org.commonjava.maven.galley.model.SimpleLocation)7 MavenProject (org.apache.maven.project.MavenProject)6 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)6 URI (java.net.URI)5 LinkedHashMap (java.util.LinkedHashMap)5 Dependency (org.apache.maven.model.Dependency)5 DependencyManagement (org.apache.maven.model.DependencyManagement)5 JoinString (org.commonjava.maven.atlas.ident.util.JoinString)5 Map (java.util.Map)4 Project (org.commonjava.maven.ext.common.model.Project)4