Search in sources :

Example 26 with SimpleProjectVersionRef

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

the class XMLInfrastructure method getParentRef.

public ProjectVersionRef getParentRef(final Document doc) throws GalleyMavenXMLException {
    final Element project = doc.getDocumentElement();
    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);
    final String gid = getChildText("groupId", parent);
    final String aid = getChildText("artifactId", parent);
    final String ver = getChildText("version", parent);
    if (isEmpty(gid) || isEmpty(aid) || isEmpty(ver)) {
        throw new GalleyMavenXMLException("Project parent is present but 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 27 with SimpleProjectVersionRef

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

the class VersionResolverImplTest method resolveSnapshot_FirstMatch_TwoLocationList_TwoSingletonSnapshotList_LatestVersionStrategy.

@Test
public void resolveSnapshot_FirstMatch_TwoLocationList_TwoSingletonSnapshotList_LatestVersionStrategy() throws Exception {
    final String testResource = "2-snapshots-2-locations/maven-metadata-1.xml";
    final String testResource2 = "2-snapshots-2-locations/maven-metadata-2.xml";
    final ProjectVersionRef ref = new SimpleProjectVersionRef("org.group2", "artifact", "1.0-SNAPSHOT");
    final String path = fixture.snapshotMetadataPath(ref);
    fixture.getTransport().registerDownload(new ConcreteResource(LOCATION, path), new TestDownload(ROOT + testResource));
    fixture.getTransport().registerDownload(new ConcreteResource(LOCATION2, path), new TestDownload(ROOT + testResource2));
    final ProjectVersionRef result = fixture.getVersionResolver().resolveFirstMatchVariableVersion(TWO_LOCATIONS, ref, LatestVersionSelectionStrategy.INSTANCE, new EventMetadata());
    assertThat(result, notNullValue());
    // newest snapshot is in the SECOND location, but we're using first-match semantics here.
    assertThat(result.getVersionString(), equalTo("1.0-20140604.101244-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) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Test(org.junit.Test)

Example 28 with SimpleProjectVersionRef

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

the class VersionResolverImplTest method resolveSnapshot_FirstMatch_SingletonLocationList_TwoSnapshotList_LatestVersionStrategy.

@Test
public void resolveSnapshot_FirstMatch_SingletonLocationList_TwoSnapshotList_LatestVersionStrategy() throws Exception {
    final String testResource = "2-snapshots-1-location/two-snapshots.xml";
    final ProjectVersionRef ref = new SimpleProjectVersionRef("org.group2", "artifact", "1.0-SNAPSHOT");
    final ConcreteResource cr = new ConcreteResource(LOCATION, fixture.snapshotMetadataPath(ref));
    final TestDownload download = new TestDownload(ROOT + testResource);
    fixture.getTransport().registerDownload(cr, download);
    final ProjectVersionRef result = fixture.getVersionResolver().resolveFirstMatchVariableVersion(ONE_LOCATION, ref, LatestVersionSelectionStrategy.INSTANCE, new EventMetadata());
    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) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Test(org.junit.Test)

Example 29 with SimpleProjectVersionRef

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

the class VersionResolverImplTest method resolveSnapshot_Latest_TwoLocationList_TwoSingletonSnapshotList_LatestVersionStrategy.

@Test
public void resolveSnapshot_Latest_TwoLocationList_TwoSingletonSnapshotList_LatestVersionStrategy() throws Exception {
    final String testResource = "2-snapshots-2-locations/maven-metadata-1.xml";
    final String testResource2 = "2-snapshots-2-locations/maven-metadata-2.xml";
    final ProjectVersionRef ref = new SimpleProjectVersionRef("org.group2", "artifact", "1.0-SNAPSHOT");
    final String path = fixture.snapshotMetadataPath(ref);
    fixture.getTransport().registerDownload(new ConcreteResource(LOCATION, path), new TestDownload(ROOT + testResource));
    fixture.getTransport().registerDownload(new ConcreteResource(LOCATION2, path), new TestDownload(ROOT + testResource2));
    final ProjectVersionRef result = fixture.getVersionResolver().resolveLatestVariableVersion(TWO_LOCATIONS, ref, LatestVersionSelectionStrategy.INSTANCE, new EventMetadata());
    assertThat(result, notNullValue());
    // newest snapshot is in the SECOND location.
    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) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Test(org.junit.Test)

Example 30 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)

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