use of org.apache.maven.artifact.repository.metadata.Metadata in project gradle by gradle.
the class MavenLocalPublisher 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);
Snapshot snapshot = new Snapshot();
snapshot.setLocalCopy(true);
Versioning versioning = new Versioning();
versioning.updateTimestamp();
versioning.setSnapshot(snapshot);
for (MavenArtifact artifact : publication.getAllArtifacts()) {
SnapshotVersion sv = new SnapshotVersion();
sv.setClassifier(artifact.getClassifier());
sv.setExtension(artifact.getExtension());
sv.setVersion(version);
sv.setUpdated(versioning.getLastUpdated());
versioning.getSnapshotVersions().add(sv);
}
metadata.setVersioning(versioning);
return metadata;
}
use of org.apache.maven.artifact.repository.metadata.Metadata in project indy by Commonjava.
the class MavenMetadataGenerator method generateGroupMetadata.
/**
* Generate group related files (e.g maven-metadata.xml) from three levels.
* 1. cache, which means all the generation of the files will be cached. In terms of cache clearing, see #{@link MetadataMergeListener}
* 2. read cached from member hosted repos and try to download from member remote repos
* 3. generate by member hosted repos (list dir trying to find version directories)
*
* @param group
* @param members concrete store in group
* @param path
*/
private Metadata generateGroupMetadata(final Group group, final List<ArtifactStore> members, final List<StoreKey> contributingMembers, final String path) throws IndyWorkflowException {
if (!canProcess(path)) {
logger.error("The path is not a metadata file: {} ", path);
return null;
}
String toMergePath = path;
if (!path.endsWith(MavenMetadataMerger.METADATA_NAME)) {
toMergePath = normalize(normalize(parentPath(toMergePath)), MavenMetadataMerger.METADATA_NAME);
}
Metadata meta = getMetaFromCache(group.getKey(), toMergePath);
if (meta != null) {
return meta;
}
Metadata master = new Metadata();
master.setVersioning(new Versioning());
MetadataIncrementalResult incrementalResult = new MetadataIncrementalResult(new HashSet<>(members), Collections.emptySet(), master);
incrementalResult = mergeMissing(group, incrementalResult, toMergePath, "cached", this::retrieveCached);
contributingMembers.addAll(incrementalResult.merged);
incrementalResult = mergeMissing(group, incrementalResult, toMergePath, "downloaded", this::downloadMissing);
contributingMembers.addAll(incrementalResult.merged);
incrementalResult = mergeMissing(group, incrementalResult, toMergePath, "generated", this::generateMissing);
contributingMembers.addAll(incrementalResult.merged);
if (metadataProviders != null) {
master = mergeProviderMetadata(group, incrementalResult.result, toMergePath);
} else {
master = incrementalResult.result;
}
if (!incrementalResult.missing.isEmpty()) {
logger.warn("After download and generation attempts, metadata is still missing from the following stores: {}, size: {}", incrementalResult.missing, incrementalResult.missing.size());
}
Versioning versioning = master.getVersioning();
List<String> versions = versioning.getVersions();
logger.debug("Get versioning, versions: {}, release: {}, latest: {}", versions, versioning.getRelease(), versioning.getLatest());
if (versions != null && !versions.isEmpty()) {
merger.sortVersions(master);
return master;
}
List<SnapshotVersion> snapshotVersions = versioning.getSnapshotVersions();
if (snapshotVersions != null && !snapshotVersions.isEmpty()) {
if (logger.isTraceEnabled()) {
snapshotVersions.forEach(snapshotVersion -> logger.trace("snapshotVersion: {}", snapshotVersion.getVersion()));
}
return master;
}
List<Plugin> plugins = master.getPlugins();
if (plugins != null && !plugins.isEmpty()) {
return master;
}
logger.info("The group metadata generation is not successful for path: {} in group: {}", path, group);
return null;
}
use of org.apache.maven.artifact.repository.metadata.Metadata in project indy by Commonjava.
the class MavenMetadataGenerator method generateGroupFileContent.
/**
* Generate maven-metadata.xml and checksum files.
* @param group
* @param members Concrete stores in group
* @param path
* @param eventMetadata
* @return
* @throws IndyWorkflowException
*/
@Override
@Measure
public Transfer generateGroupFileContent(final Group group, final List<ArtifactStore> members, final String path, final EventMetadata eventMetadata) throws IndyWorkflowException {
final Transfer rawTarget = fileManager.getTransfer(group, path);
// First we check the metadata and all of its siblings metadata files
if (canProcess(path) && exists(rawTarget)) {
// Means there is no metadata change if this transfer exists, so directly return it.
logger.trace("Raw metadata file exists for group {} of path {}, no need to regenerate.", group.getKey(), path);
eventMetadata.set(GROUP_METADATA_EXISTS, true);
return rawTarget;
}
// Then changed back to the metadata itself whatever the path is
String toMergePath = path;
if (!path.endsWith(MavenMetadataMerger.METADATA_NAME)) {
toMergePath = normalize(normalize(parentPath(toMergePath)), MavenMetadataMerger.METADATA_NAME);
}
final Transfer target = fileManager.getTransfer(group, toMergePath);
if (exists(target)) {
// Means there is no metadata change if this transfer exists, so directly return it.
logger.trace("Merged metadata file exists for group {} of path {}, no need to regenerate.", group.getKey(), toMergePath);
eventMetadata.set(GROUP_METADATA_EXISTS, true);
return target;
}
AtomicReference<IndyWorkflowException> wfEx = new AtomicReference<>();
final String mergePath = toMergePath;
boolean mergingDone = mergerLocks.ifUnlocked(computeKey(group, toMergePath), p -> {
try {
logger.debug("Start metadata generation for metadata file {} in group {}", path, group);
List<StoreKey> contributing = new ArrayList<>();
final Metadata md = generateGroupMetadata(group, members, contributing, path);
if (md != null) {
final Versioning versioning = md.getVersioning();
logger.trace("Regenerated Metadata for group {} of path {}: latest version: {}, versions: {}", group.getKey(), mergePath, versioning != null ? versioning.getLatest() : null, versioning != null ? versioning.getVersions() : null);
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
logger.trace("Regenerate lost metadata, group: {}, path: {}", group.getKey(), path);
new MetadataXpp3Writer().write(baos, md);
final byte[] merged = baos.toByteArray();
try (final OutputStream fos = target.openOutputStream(TransferOperation.GENERATE, true, eventMetadata)) {
fos.write(merged);
} catch (final IOException e) {
throw new IndyWorkflowException("Failed to write merged metadata to: {}.\nError: {}", e, target, e.getMessage());
}
String mergeInfo = writeGroupMergeInfo(md, group, contributing, mergePath);
eventMetadata.set(GROUP_METADATA_GENERATED, true);
MetadataInfo info = new MetadataInfo(md);
info.setMetadataMergeInfo(mergeInfo);
putToMetadataCache(group.getKey(), mergePath, info);
} catch (final IOException e) {
logger.error(String.format("Cannot write consolidated metadata: %s to: %s. Reason: %s", path, group.getKey(), e.getMessage()), e);
}
}
} catch (IndyWorkflowException e) {
wfEx.set(e);
return false;
}
return true;
}, (p, mergerLock) -> {
logger.info("The metadata generation is still in process by another thread for the metadata file for this path {} in group {}, so block current thread to wait for result", path, group);
return mergerLocks.waitForLock(THREAD_WAITING_TIME_SECONDS, mergerLock);
});
IndyWorkflowException ex = wfEx.get();
if (ex != null) {
throw ex;
}
if (exists(target)) {
// if this is a checksum file, we need to return the original path (if it is metadata, original is target)
Transfer original = fileManager.getTransfer(group, path);
if (exists(original)) {
if (toMergePath != path) {
logger.debug("This is a checksum file, return the original path {}", path);
}
return original;
}
}
if (mergingDone) {
logger.info("Merging finished but the merging file not created correctly. See merging related log for details. Merging group: {}, path: {}", group, path);
} else {
logger.error("Merging not finished but thread waiting timeout, caused current thread will get a null merging result. Try to enlarge the waiting timeout. Merging group: {}, path: {}", group, path);
}
return null;
}
use of org.apache.maven.artifact.repository.metadata.Metadata in project indy by Commonjava.
the class MetadataMarshaller method readFrom.
@Override
public Metadata readFrom(ProtoStreamReader reader) throws IOException {
Metadata md = new Metadata();
md.setModelVersion(reader.readString("modelVersion"));
md.setGroupId(reader.readString("groupId"));
md.setArtifactId(reader.readString("artifactId"));
md.setVersion(reader.readString("version"));
md.setPlugins(reader.readCollection("plugins", new ArrayList<Plugin>(), Plugin.class));
md.setVersioning(reader.readObject("versioning", Versioning.class));
md.setModelEncoding(reader.readString("modelEncoding"));
return md;
}
use of org.apache.maven.artifact.repository.metadata.Metadata in project platformlayer by platformlayer.
the class MavenResolver method resolveVersion.
String resolveVersion(Path artifactPath, MavenReference reference) throws IOException {
Path artifactMavenMetadataPath = artifactPath.resolve("maven-metadata.xml");
log.info("Reading file: " + artifactMavenMetadataPath);
String mavenMetadataXml = IoUtils.readAll(Files.newInputStream(artifactMavenMetadataPath));
Metadata mavenMetadata = MavenXml.readMetadata(mavenMetadataXml);
String version = pickVersion(mavenMetadata.getVersioning());
if (version == null) {
throw new IllegalStateException("Could not find version");
}
return version;
}
Aggregations