use of org.apache.maven.artifact.repository.metadata.Metadata in project indy by Commonjava.
the class AbstractContentManagementTest method getRealLastUpdated.
protected String getRealLastUpdated(StoreKey key, String path) throws Exception {
InputStream meta = client.content().get(key, path);
Metadata merged = new MetadataXpp3Reader().read(meta);
return merged.getVersioning().getLastUpdated();
}
use of org.apache.maven.artifact.repository.metadata.Metadata in project indy by Commonjava.
the class KojiMavenMetadataProvider method getMetadata.
@Override
@Measure
public Metadata getMetadata(StoreKey targetKey, String path) throws IndyWorkflowException {
Logger logger = LoggerFactory.getLogger(getClass());
if (group != targetKey.getType()) {
logger.debug("Not a group. Cannot supplement with metadata from Koji builds");
return null;
}
if (!kojiConfig.isEnabled()) {
logger.debug("Koji add-on is disabled.");
return null;
}
try {
ArtifactStore target = storeDataManager.getArtifactStore(targetKey);
if (!kojiConfig.isEnabledFor(target)) {
logger.debug("Koji integration is not enabled for group: {}", targetKey);
return null;
}
} catch (IndyDataException e) {
logger.error("Failed to get metadata for path {} in store {}: {}", path, targetKey, e.getMessage());
}
File mdFile = new File(path);
File artifactDir = mdFile.getParentFile();
File groupDir = artifactDir == null ? null : artifactDir.getParentFile();
if (artifactDir == null || groupDir == null) {
logger.debug("Invalid groupId / artifactId directory structure: '{}' / '{}'", groupDir, artifactDir);
return null;
}
String groupId = groupDir.getPath().replace(File.separatorChar, '.');
String artifactId = artifactDir.getName();
ProjectRef ref = null;
try {
ref = new SimpleProjectRef(groupId, artifactId);
} catch (InvalidRefException e) {
logger.warn("Not a valid Maven GA: {}:{}. Skipping Koji metadata retrieval.", groupId, artifactId);
}
if (ref == null) {
logger.debug("Could not render a valid Maven GA for path: '{}'", path);
return null;
}
ProjectRef ga = ref;
AtomicReference<IndyWorkflowException> wfError = new AtomicReference<>();
return versionMetadataLocks.lockAnd(ga, kojiConfig.getLockTimeoutSeconds(), k -> {
Metadata metadata = versionMetadata.get(ga);
if (metadata == null) {
try {
metadata = executeKojiMetadataLookup(ga, path);
} catch (IndyWorkflowException e) {
wfError.set(e);
metadata = null;
} catch (KojiClientException e) {
// FIXME: Should this bubble up like IndyWorkflowException does in the case of overloaded threadpool?
Throwable cause = e.getCause();
logger.error(String.format("Failed to retrieve version metadata for: %s from Koji. Reason: %s", ga, e.getMessage()), e);
if (cause instanceof RuntimeException) {
logger.error("Previous exception's nested cause was a RuntimeException variant:", cause);
}
metadata = null;
}
if (metadata != null) {
Metadata md = metadata;
// FIXME: Need a way to listen for cache expiration and re-request this?
versionMetadata.execute((cache) -> cache.put(ga, md, kojiConfig.getMetadataTimeoutSeconds(), TimeUnit.SECONDS));
} else {
logger.debug("Returning null metadata result for unknown reason (path: '{}')", path);
}
}
return metadata;
}, (k, lock) -> {
logger.error("Failed to acquire Koji GA version metadata lock on: '{}' in {} seconds.", ga, kojiConfig.getLockTimeoutSeconds());
return false;
});
}
use of org.apache.maven.artifact.repository.metadata.Metadata in project platformlayer by platformlayer.
the class MavenResolver method resolve.
public Path resolve(MavenReference reference) throws IOException {
Path artifactPath = toPath(reference.groupId, reference.artifactId);
if (reference.versionId == null) {
reference.versionId = resolveVersion(artifactPath, reference);
}
if (reference.classifier == null) {
reference.classifier = "jar";
}
Path versionedPath = artifactPath.resolve(reference.versionId);
Path artifactMavenMetadataPath = versionedPath.resolve("maven-metadata.xml");
log.info("Reading file: " + artifactMavenMetadataPath);
String mavenMetadataXml = IoUtils.readAll(Files.newInputStream(artifactMavenMetadataPath));
Metadata mavenMetadata = MavenXml.readMetadata(mavenMetadataXml);
return pickSnapshot(versionedPath, reference, mavenMetadata);
}
use of org.apache.maven.artifact.repository.metadata.Metadata in project gradle by gradle.
the class MavenRemotePublisher method createSnapshotMetadata.
@Override
protected Metadata createSnapshotMetadata(MavenNormalizedPublication publication, String groupId, String artifactId, String version, ExternalResourceRepository repository, ExternalResourceName metadataResource) {
Metadata metadata = new Metadata();
metadata.setModelVersion("1.1.0");
metadata.setGroupId(groupId);
metadata.setArtifactId(artifactId);
metadata.setVersion(version);
String timestamp = createSnapshotTimestamp();
Snapshot snapshot = new Snapshot();
snapshot.setBuildNumber(getNextBuildNumber(repository, metadataResource));
snapshot.setTimestamp(timestamp);
Versioning versioning = new Versioning();
versioning.setSnapshot(snapshot);
versioning.setLastUpdated(snapshot.getTimestamp().replace(".", ""));
String timestampVersion = version.replace("SNAPSHOT", snapshot.getTimestamp() + "-" + snapshot.getBuildNumber());
for (MavenArtifact artifact : publication.getAllArtifacts()) {
SnapshotVersion sv = new SnapshotVersion();
sv.setClassifier(artifact.getClassifier());
sv.setExtension(artifact.getExtension());
sv.setVersion(timestampVersion);
sv.setUpdated(versioning.getLastUpdated());
versioning.getSnapshotVersions().add(sv);
}
metadata.setVersioning(versioning);
return metadata;
}
use of org.apache.maven.artifact.repository.metadata.Metadata in project gradle by gradle.
the class MavenRemotePublisher method getNextBuildNumber.
private int getNextBuildNumber(ExternalResourceRepository repository, ExternalResourceName metadataResource) {
ExternalResourceReadResult<Metadata> existing = readExistingMetadata(repository, metadataResource);
if (existing != null) {
Metadata recessive = existing.getResult();
Versioning versioning = recessive.getVersioning();
if (versioning != null) {
Snapshot snapshot = versioning.getSnapshot();
if (snapshot != null && snapshot.getBuildNumber() > 0) {
return snapshot.getBuildNumber() + 1;
}
}
}
return 1;
}
Aggregations