Search in sources :

Example 1 with MavenMetadataView

use of org.commonjava.maven.galley.maven.model.view.meta.MavenMetadataView in project indy by Commonjava.

the class MavenMetadataGeneratorTest method generateFileContent_SnapshotMetadataWith2Versions.

@Test
public void generateFileContent_SnapshotMetadataWith2Versions() throws Exception {
    final StoreResource resource = setupSnapshotDirWith2Snapshots();
    final EventMetadata emd = new EventMetadata();
    final Transfer transfer = generator.generateFileContent(stores.getArtifactStore(resource.getStoreKey()), resource.getChild("maven-metadata.xml").getPath(), emd);
    assertThat(transfer, notNullValue());
    final MavenMetadataView metadata = metadataReader.readMetadata(new SimpleProjectVersionRef("org.group", "artifact", "1.0-SNAPSHOT"), Collections.singletonList(transfer), emd);
    assertThat(metadata, notNullValue());
    final VersioningView versioning = metadata.getVersioning();
    final LatestSnapshotView latestSnapshot = versioning.getLatestSnapshot();
    assertThat(latestSnapshot.isLocalCopy(), equalTo(false));
    assertThat(latestSnapshot.getTimestamp(), equalTo(SnapshotUtils.parseSnapshotTimestamp("20140828.225800")));
    assertThat(latestSnapshot.getBuildNumber(), equalTo(1));
    final List<SnapshotArtifactView> snapshots = versioning.getSnapshotArtifacts();
    assertThat(snapshots.size(), equalTo(4));
    for (final SnapshotArtifactView snap : snapshots) {
        final String extension = snap.getExtension();
        assertThat(extension.equals("jar") || extension.equals("pom"), equalTo(true));
        final String version = snap.getVersion();
        System.out.println(version);
        final SingleVersion parsed = VersionUtils.createSingleVersion(version);
        assertThat(parsed.isSnapshot(), equalTo(true));
        assertThat(parsed.isLocalSnapshot(), equalTo(false));
        final SnapshotPart part = parsed.getSnapshotPart();
        final String tstamp = SnapshotUtils.generateSnapshotTimestamp(part.getTimestamp());
        assertThat(tstamp.equals("20140828.225800") || tstamp.equals("20140828.221400"), equalTo(true));
    }
}
Also used : MavenMetadataView(org.commonjava.maven.galley.maven.model.view.meta.MavenMetadataView) VersioningView(org.commonjava.maven.galley.maven.model.view.meta.VersioningView) StoreResource(org.commonjava.indy.content.StoreResource) SnapshotPart(org.commonjava.maven.atlas.ident.version.part.SnapshotPart) Transfer(org.commonjava.maven.galley.model.Transfer) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) LatestSnapshotView(org.commonjava.maven.galley.maven.model.view.meta.LatestSnapshotView) SingleVersion(org.commonjava.maven.atlas.ident.version.SingleVersion) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) SnapshotArtifactView(org.commonjava.maven.galley.maven.model.view.meta.SnapshotArtifactView) Test(org.junit.Test)

Example 2 with MavenMetadataView

use of org.commonjava.maven.galley.maven.model.view.meta.MavenMetadataView in project indy by Commonjava.

the class MavenMetadataGeneratorTest method generateFileContent_VersionsMetadataWith2Versions.

@Test
public void generateFileContent_VersionsMetadataWith2Versions() throws Exception {
    final StoreResource resource = setupVersionsStructureWith2Versions();
    final ConcreteResource metadataFile = resource.getChild("maven-metadata.xml");
    final Transfer transfer = generator.generateFileContent(stores.getArtifactStore(resource.getStoreKey()), metadataFile.getPath(), new EventMetadata());
    assertThat(transfer, notNullValue());
    final MavenMetadataView metadata = metadataReader.readMetadata(new SimpleProjectVersionRef("org.group", "artifact", "1.0-SNAPSHOT"), Collections.singletonList(transfer), new EventMetadata());
    assertThat(metadata, notNullValue());
    final VersioningView versioning = metadata.getVersioning();
    final List<SingleVersion> versions = versioning.getVersions();
    assertThat(versions, notNullValue());
    assertThat(versions.get(0).renderStandard(), equalTo("1.0"));
    assertThat(versions.get(1).renderStandard(), equalTo("1.1"));
    assertThat(versioning.getReleaseVersion().renderStandard(), equalTo("1.1"));
    assertThat(versioning.getLatestVersion().renderStandard(), equalTo("1.1"));
}
Also used : MavenMetadataView(org.commonjava.maven.galley.maven.model.view.meta.MavenMetadataView) VersioningView(org.commonjava.maven.galley.maven.model.view.meta.VersioningView) StoreResource(org.commonjava.indy.content.StoreResource) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Transfer(org.commonjava.maven.galley.model.Transfer) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) SingleVersion(org.commonjava.maven.atlas.ident.version.SingleVersion) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Test(org.junit.Test)

Example 3 with MavenMetadataView

use of org.commonjava.maven.galley.maven.model.view.meta.MavenMetadataView in project galley by Commonjava.

the class VersionResolverImpl method resolveLatestMultiRefWithLocation.

private ProjectVersionRefLocation resolveLatestMultiRefWithLocation(final List<? extends Location> locations, final ProjectVersionRef ref, final VersionSelectionStrategy selectionStrategy, final EventMetadata eventMetadata) throws TransferException {
    final Map<SingleVersion, Location> available = new TreeMap<SingleVersion, Location>();
    for (final Location location : locations) {
        try {
            final MavenMetadataView metadata = metadataReader.getMetadata(ref.asProjectRef(), Collections.singletonList(location), eventMetadata);
            if (metadata != null) {
                final List<String> versions = metadata.resolveValues("/metadata/versioning/versions/version");
                if (versions != null) {
                    for (final String version : versions) {
                        try {
                            final SingleVersion spec = VersionUtils.createSingleVersion(version);
                            if (!available.containsKey(spec)) {
                                available.put(spec, location);
                            }
                        } catch (final InvalidVersionSpecificationException e) {
                            debug("Unparsable version spec found in metadata: '%s' for: %s from: %s.", e, version, ref, location);
                        }
                    }
                }
            }
        } catch (final GalleyMavenException e) {
            debug("Failed to resolve/parse metadata for variable version of: '%s' from: %s.", e, ref, location);
        }
    }
    if (!available.isEmpty()) {
        final VersionSpec spec = ref.getVersionSpec();
        final List<SingleVersion> versions = new ArrayList<SingleVersion>(available.keySet());
        Collections.sort(versions);
        while (!versions.isEmpty()) {
            final SingleVersion selected = selectionStrategy.select(versions);
            if (selected == null) {
                return null;
            }
            versions.remove(selected);
            if (selected.isConcrete() && spec.contains(selected)) {
                return new ProjectVersionRefLocation(ref.selectVersion(selected), available.get(selected));
            }
        }
    }
    return null;
}
Also used : GalleyMavenException(org.commonjava.maven.galley.maven.GalleyMavenException) ArrayList(java.util.ArrayList) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) TreeMap(java.util.TreeMap) VersionSpec(org.commonjava.maven.atlas.ident.version.VersionSpec) MavenMetadataView(org.commonjava.maven.galley.maven.model.view.meta.MavenMetadataView) InvalidVersionSpecificationException(org.commonjava.maven.atlas.ident.version.InvalidVersionSpecificationException) ProjectVersionRefLocation(org.commonjava.maven.galley.maven.model.ProjectVersionRefLocation) SingleVersion(org.commonjava.maven.atlas.ident.version.SingleVersion) ProjectVersionRefLocation(org.commonjava.maven.galley.maven.model.ProjectVersionRefLocation) Location(org.commonjava.maven.galley.model.Location)

Example 4 with MavenMetadataView

use of org.commonjava.maven.galley.maven.model.view.meta.MavenMetadataView in project galley by Commonjava.

the class VersionResolverImpl method resolveAllSnapshotRefsWithLocations.

private List<ProjectVersionRefLocation> resolveAllSnapshotRefsWithLocations(final List<? extends Location> locations, final ProjectVersionRef ref, final VersionSelectionStrategy selectionStrategy, final EventMetadata eventMetadata) throws TransferException {
    final Map<SingleVersion, Location> available = new TreeMap<SingleVersion, Location>();
    for (final Location location : locations) {
        try {
            final MavenMetadataView metadata = metadataReader.getMetadata(ref, Collections.singletonList(location), eventMetadata);
            if (metadata != null) {
                final String latest = metadata.resolveSingleValue("/metadata/versioning/latest");
                if (latest != null) {
                    try {
                        final SingleVersion ver = VersionUtils.createSingleVersion(latest);
                        if (ver.isSnapshot()) {
                            if (!available.containsKey(ver)) {
                                available.put(ver, location);
                            }
                        }
                    } catch (final InvalidVersionSpecificationException e) {
                        debug("Unparsable version spec found in metadata: '%s' for: %s from: %s", e, latest, ref, location);
                    }
                }
            }
        } catch (final GalleyMavenException e) {
            debug("Failed to resolve/parse metadata for snapshot version of: %s from: %s.", e, ref, location);
        }
    }
    if (!available.isEmpty()) {
        return Collections.emptyList();
    }
    final List<SingleVersion> versions = new ArrayList<SingleVersion>(available.keySet());
    Collections.sort(versions);
    final List<ProjectVersionRefLocation> result = new ArrayList<ProjectVersionRefLocation>();
    while (!versions.isEmpty()) {
        final SingleVersion selected = selectionStrategy.select(versions);
        if (selected != null) {
            versions.remove(selected);
            result.add(new ProjectVersionRefLocation(ref.selectVersion(selected), available.get(selected)));
        }
    }
    return result;
}
Also used : MavenMetadataView(org.commonjava.maven.galley.maven.model.view.meta.MavenMetadataView) GalleyMavenException(org.commonjava.maven.galley.maven.GalleyMavenException) InvalidVersionSpecificationException(org.commonjava.maven.atlas.ident.version.InvalidVersionSpecificationException) ProjectVersionRefLocation(org.commonjava.maven.galley.maven.model.ProjectVersionRefLocation) ArrayList(java.util.ArrayList) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) TreeMap(java.util.TreeMap) SingleVersion(org.commonjava.maven.atlas.ident.version.SingleVersion) ProjectVersionRefLocation(org.commonjava.maven.galley.maven.model.ProjectVersionRefLocation) Location(org.commonjava.maven.galley.model.Location)

Example 5 with MavenMetadataView

use of org.commonjava.maven.galley.maven.model.view.meta.MavenMetadataView in project galley by Commonjava.

the class MavenMetadataReader method getMetadata.

public MavenMetadataView getMetadata(final ProjectRef ref, final List<? extends Location> locations, final EventMetadata eventMetadata) throws GalleyMavenException {
    final List<DocRef<ProjectRef>> docs = new ArrayList<DocRef<ProjectRef>>(locations.size());
    final Map<Location, DocRef<ProjectRef>> cached = getAllCached(ref, locations);
    final List<? extends Location> toRetrieve = new ArrayList<Location>(locations);
    for (final Location loc : locations) {
        final DocRef<ProjectRef> dr = cached.get(loc);
        if (dr != null) {
            docs.add(dr);
            toRetrieve.remove(loc);
        } else {
            docs.add(null);
        }
    }
    List<Transfer> transfers;
    try {
        transfers = metadataManager.retrieveAll(toRetrieve, ref, eventMetadata);
    } catch (final TransferException e) {
        throw new GalleyMavenException("Failed to resolve metadata for: {} from: {}. Reason: {}", e, ref, locations, e.getMessage());
    }
    logger.debug("Resolved {} transfers:\n  {}", transfers.size(), new JoinString("\n  ", transfers));
    if (transfers != null && !transfers.isEmpty()) {
        for (final Transfer transfer : transfers) {
            final DocRef<ProjectRef> dr = new DocRef<ProjectRef>(ref, transfer.getLocation(), xml.parse(transfer, eventMetadata));
            final int idx = locations.indexOf(transfer.getLocation());
            //
            if (idx > -1) {
                docs.set(idx, dr);
            } else {
                docs.add(dr);
            }
        }
    }
    for (final Iterator<DocRef<ProjectRef>> iterator = docs.iterator(); iterator.hasNext(); ) {
        final DocRef<ProjectRef> docRef = iterator.next();
        if (docRef == null) {
            iterator.remove();
        }
    }
    logger.debug("Got {} metadata documents for: {}", docs.size(), ref);
    return new MavenMetadataView(docs, xpath, xml);
}
Also used : GalleyMavenException(org.commonjava.maven.galley.maven.GalleyMavenException) ArrayList(java.util.ArrayList) DocRef(org.commonjava.maven.galley.maven.model.view.DocRef) MavenMetadataView(org.commonjava.maven.galley.maven.model.view.meta.MavenMetadataView) TransferException(org.commonjava.maven.galley.TransferException) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) Transfer(org.commonjava.maven.galley.model.Transfer) ProjectRef(org.commonjava.maven.atlas.ident.ref.ProjectRef) Location(org.commonjava.maven.galley.model.Location)

Aggregations

MavenMetadataView (org.commonjava.maven.galley.maven.model.view.meta.MavenMetadataView)7 SingleVersion (org.commonjava.maven.atlas.ident.version.SingleVersion)6 ArrayList (java.util.ArrayList)5 GalleyMavenException (org.commonjava.maven.galley.maven.GalleyMavenException)5 Location (org.commonjava.maven.galley.model.Location)5 TreeMap (java.util.TreeMap)4 JoinString (org.commonjava.maven.atlas.ident.util.JoinString)4 ProjectVersionRefLocation (org.commonjava.maven.galley.maven.model.ProjectVersionRefLocation)4 InvalidVersionSpecificationException (org.commonjava.maven.atlas.ident.version.InvalidVersionSpecificationException)3 Transfer (org.commonjava.maven.galley.model.Transfer)3 StoreResource (org.commonjava.indy.content.StoreResource)2 SimpleProjectVersionRef (org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef)2 VersionSpec (org.commonjava.maven.atlas.ident.version.VersionSpec)2 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)2 VersioningView (org.commonjava.maven.galley.maven.model.view.meta.VersioningView)2 Test (org.junit.Test)2 ProjectRef (org.commonjava.maven.atlas.ident.ref.ProjectRef)1 SnapshotPart (org.commonjava.maven.atlas.ident.version.part.SnapshotPart)1 TransferException (org.commonjava.maven.galley.TransferException)1 DocRef (org.commonjava.maven.galley.maven.model.view.DocRef)1