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));
}
}
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"));
}
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;
}
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;
}
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);
}
Aggregations