use of org.apache.maven.artifact.repository.metadata.Metadata in project fabric8 by jboss-fuse.
the class AetherResolutionSupport method getOrCreateMetadata.
private Metadata getOrCreateMetadata(File repository, String groupId, String artifactId, String version, String repoId) throws IOException {
File metadata;
if (version == null) {
metadata = new File(repository, String.format("%s/%s/maven-metadata%s.xml", groupId.replaceAll("\\.", "/"), artifactId, repoId == null ? "" : "-" + repoId));
} else {
metadata = new File(repository, String.format("%s/%s/%s/maven-metadata%s.xml", groupId.replaceAll("\\.", "/"), artifactId, version, repoId == null ? "" : "-" + repoId));
}
Metadata md;
if (metadata.isFile()) {
try {
md = new MetadataXpp3Reader().read(new FileReader(metadata));
} catch (XmlPullParserException e) {
throw new IOException(e.getMessage(), e);
}
} else {
md = new Metadata();
md.setGroupId(groupId);
md.setArtifactId(artifactId);
if (version != null) {
md.setVersion(version);
}
md.setVersioning(new Versioning());
}
return md;
}
use of org.apache.maven.artifact.repository.metadata.Metadata in project archiva by apache.
the class LegacyToDefaultConverter method updateMetadata.
private void updateMetadata(RepositoryMetadata artifactMetadata, ArtifactRepository targetRepository, Metadata newMetadata, FileTransaction transaction) throws ArtifactConversionException {
Path file = Paths.get(targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata(artifactMetadata));
Metadata metadata;
boolean changed;
if (Files.exists(file)) {
metadata = readMetadata(file);
changed = metadata.merge(newMetadata);
} else {
changed = true;
metadata = newMetadata;
}
if (changed) {
try (StringWriter writer = new StringWriter()) {
MetadataXpp3Writer mappingWriter = new MetadataXpp3Writer();
mappingWriter.write(writer, metadata);
transaction.createFile(writer.toString(), file, digesters);
} catch (IOException e) {
throw new ArtifactConversionException(Messages.getString("error.writing.target.metadata"), // $NON-NLS-1$
e);
}
}
}
use of org.apache.maven.artifact.repository.metadata.Metadata in project indy by Commonjava.
the class KojiMavenMetadataProvider method handleExpired.
private void handleExpired(ProjectRef key) {
Logger logger = LoggerFactory.getLogger(getClass());
if (!kojiConfig.isEnabled()) {
logger.debug("Koji add-on is disabled.");
return;
}
logger.info("Koji metadata expired for GA: {}", key);
try {
Set<Group> affected = storeDataManager.query().getAll(s -> group == s.getType() && kojiConfig.isEnabledFor(s)).stream().map(s -> (Group) s).collect(Collectors.toSet());
if (storeDataManager instanceof AbstractStoreDataManager) {
affected = ((AbstractStoreDataManager) storeDataManager).filterAffectedGroups(affected);
}
if (!affected.isEmpty()) {
logger.info("Triggering metadata cleanup from Koji metadata expiration, for GA: {} in groups: {}", key, affected);
String path = ArtifactPathUtils.formatMetadataPath(key, METADATA_NAME);
clearPaths(affected, path);
}
} catch (IndyDataException ex) {
logger.error("Failed to clear group metadata for expired Koji metadata: " + key, ex);
} catch (TransferException ex) {
logger.error("Failed to format metadata path for: " + key, ex);
}
}
use of org.apache.maven.artifact.repository.metadata.Metadata in project indy by Commonjava.
the class KojiMavenMetadataProvider method executeKojiMetadataLookup.
@Measure
private Metadata executeKojiMetadataLookup(ProjectRef ga, String path) throws KojiClientException, IndyWorkflowException {
Logger logger = LoggerFactory.getLogger(getClass());
// short-term caches to help improve performance a bit by avoiding xml-rpc calls.
List<KojiArchiveInfo> archives = kojiContentProvider.listArchivesMatching(ga, null);
Map<Integer, KojiBuildArchiveCollection> seenBuildArchives = new ConcurrentHashMap<>();
Set<Integer> seenBuilds = new ConcurrentHashSet<>();
DrainingExecutorCompletionService<SingleVersion> svc = new DrainingExecutorCompletionService<>(kojiMDService);
detectOverloadVoid(() -> {
for (KojiArchiveInfo archive : archives) {
svc.submit(archiveScanner(path, ga, archive, seenBuilds, seenBuildArchives));
}
});
Set<SingleVersion> versions = new ConcurrentHashSet<>();
try {
svc.drain(v -> {
if (v != null) {
versions.add(v);
}
});
} catch (InterruptedException | ExecutionException e) {
logger.warn("Failed to scan for Koji metadata related to: " + ga, e);
}
if (versions.isEmpty()) {
logger.debug("No versions found in Koji builds for metadata: {}", path);
return null;
}
List<SingleVersion> sortedVersions = new ArrayList<>(versions);
Collections.sort(sortedVersions);
Metadata md = new Metadata();
md.setGroupId(ga.getGroupId());
md.setArtifactId(ga.getArtifactId());
Versioning versioning = new Versioning();
versioning.setRelease(sortedVersions.get(versions.size() - 1).renderStandard());
versioning.setLatest(sortedVersions.get(versions.size() - 1).renderStandard());
versioning.setVersions(sortedVersions.stream().map(SingleVersion::renderStandard).collect(Collectors.toList()));
Date lastUpdated = Calendar.getInstance(TimeZone.getTimeZone("UTC")).getTime();
versioning.setLastUpdated(new SimpleDateFormat(LAST_UPDATED_FORMAT).format(lastUpdated));
md.setVersioning(versioning);
return md;
}
use of org.apache.maven.artifact.repository.metadata.Metadata in project indy by Commonjava.
the class KojiMavenMetadataProviderTest method retrieveVersionMetadata.
@Test
public void retrieveVersionMetadata() throws Exception {
initKojiClient("simple-metadata-generate", false);
Metadata metadata = provider.getMetadata(new StoreKey(MAVEN_PKG_KEY, group, "public"), "commons-io/commons-io/maven-metadata.xml");
assertThat(metadata, notNullValue());
StringWriter sw = new StringWriter();
new MetadataXpp3Writer().write(sw, metadata);
System.out.println(sw.toString());
Versioning versioning = metadata.getVersioning();
assertThat(versioning, notNullValue());
assertThat(versioning.getLatest(), equalTo("2.4.0.redhat-1"));
assertThat(versioning.getRelease(), equalTo("2.4.0.redhat-1"));
List<String> versions = versioning.getVersions();
assertThat(versions, notNullValue());
assertThat(versions.size(), equalTo(2));
int idx = 0;
assertThat(versions.get(idx), equalTo("2.1-redhat-1"));
idx++;
assertThat(versions.get(idx), equalTo("2.4.0.redhat-1"));
}
Aggregations