use of org.apache.archiva.model.ArtifactReference in project archiva by apache.
the class CleanupReleasedSnapshotsRepositoryPurge method process.
@Override
public void process(String path) throws RepositoryPurgeException {
try {
Path artifactFile = Paths.get(repository.getRepoRoot(), path);
if (!Files.exists(artifactFile)) {
// Nothing to do here, file doesn't exist, skip it.
return;
}
ArtifactReference artifactRef = repository.toArtifactReference(path);
if (!VersionUtil.isSnapshot(artifactRef.getVersion())) {
// Nothing to do here, not a snapshot, skip it.
return;
}
ProjectReference reference = new ProjectReference();
reference.setGroupId(artifactRef.getGroupId());
reference.setArtifactId(artifactRef.getArtifactId());
// Gether the released versions
List<String> releasedVersions = new ArrayList<>();
Collection<org.apache.archiva.repository.ManagedRepository> repos = repositoryRegistry.getManagedRepositories();
for (org.apache.archiva.repository.ManagedRepository repo : repos) {
if (repo.getActiveReleaseSchemes().contains(ReleaseScheme.RELEASE)) {
try {
ManagedRepositoryContent repoContent = repo.getContent();
for (String version : repoContent.getVersions(reference)) {
if (!VersionUtil.isSnapshot(version)) {
releasedVersions.add(version);
}
}
} catch (RepositoryException e) {
// swallow
}
}
}
Collections.sort(releasedVersions, VersionComparator.getInstance());
// Now clean out any version that is earlier than the highest released version.
boolean needsMetadataUpdate = false;
VersionedReference versionRef = new VersionedReference();
versionRef.setGroupId(artifactRef.getGroupId());
versionRef.setArtifactId(artifactRef.getArtifactId());
MetadataRepository metadataRepository = repositorySession.getRepository();
if (releasedVersions.contains(VersionUtil.getReleaseVersion(artifactRef.getVersion()))) {
versionRef.setVersion(artifactRef.getVersion());
repository.deleteVersion(versionRef);
for (RepositoryListener listener : listeners) {
listener.deleteArtifact(metadataRepository, repository.getId(), artifactRef.getGroupId(), artifactRef.getArtifactId(), artifactRef.getVersion(), artifactFile.getFileName().toString());
}
metadataRepository.removeProjectVersion(repository.getId(), artifactRef.getGroupId(), artifactRef.getArtifactId(), artifactRef.getVersion());
needsMetadataUpdate = true;
}
if (needsMetadataUpdate) {
updateMetadata(artifactRef);
}
} catch (LayoutException e) {
log.debug("Not processing file that is not an artifact: {}", e.getMessage());
} catch (ContentNotFoundException e) {
throw new RepositoryPurgeException(e.getMessage(), e);
} catch (MetadataRepositoryException e) {
log.error("Could not remove metadata during cleanup of released snapshots of {}", path, e);
}
}
use of org.apache.archiva.model.ArtifactReference in project archiva by apache.
the class RetentionCountRepositoryPurge method process.
@Override
public void process(String path) throws RepositoryPurgeException {
try {
Path artifactFile = Paths.get(repository.getRepoRoot(), path);
if (!Files.exists(artifactFile)) {
return;
}
ArtifactReference artifact = repository.toArtifactReference(path);
if (VersionUtil.isSnapshot(artifact.getVersion())) {
VersionedReference reference = new VersionedReference();
reference.setGroupId(artifact.getGroupId());
reference.setArtifactId(artifact.getArtifactId());
reference.setVersion(artifact.getVersion());
List<String> versions = new ArrayList<>(repository.getVersions(reference));
Collections.sort(versions, VersionComparator.getInstance());
if (retentionCount > versions.size()) {
log.trace("No deletion, because retention count is higher than actual number of artifacts.");
// Done. nothing to do here. skip it.
return;
}
int countToPurge = versions.size() - retentionCount;
Set<ArtifactReference> artifactsToDelete = new HashSet<>();
for (String version : versions) {
if (countToPurge-- <= 0) {
break;
}
artifactsToDelete.addAll(repository.getRelatedArtifacts(getNewArtifactReference(artifact, version)));
}
purge(artifactsToDelete);
}
} catch (LayoutException le) {
throw new RepositoryPurgeException(le.getMessage(), le);
} catch (ContentNotFoundException e) {
log.error("Repostory artifact not found {}", path);
}
}
use of org.apache.archiva.model.ArtifactReference in project archiva by apache.
the class RetentionCountRepositoryPurge method getNewArtifactReference.
/*
* Returns a new artifact reference with different version
*/
private ArtifactReference getNewArtifactReference(ArtifactReference reference, String version) throws LayoutException {
ArtifactReference artifact = new ArtifactReference();
artifact.setGroupId(reference.getGroupId());
artifact.setArtifactId(reference.getArtifactId());
artifact.setVersion(version);
artifact.setClassifier(reference.getClassifier());
artifact.setType(reference.getType());
return artifact;
}
use of org.apache.archiva.model.ArtifactReference in project archiva by apache.
the class LegacyConverterArtifactConsumer method processFile.
@Override
public void processFile(String path) throws ConsumerException {
try {
ArtifactReference reference = managedRepository.toArtifactReference(path);
Artifact artifact = artifactFactory.createArtifact(reference.getGroupId(), reference.getArtifactId(), reference.getVersion(), reference.getClassifier(), reference.getType());
artifactConverter.convert(artifact, destinationRepository);
} catch (LayoutException e) {
log.warn("Unable to convert artifact: {} : {}", path, e.getMessage(), e);
} catch (ArtifactConversionException e) {
log.warn("Unable to convert artifact: {} : {}", path, e.getMessage(), e);
}
}
use of org.apache.archiva.model.ArtifactReference in project archiva by apache.
the class SimpleArtifactConsumer method processFile.
public void processFile(String path, boolean executeOnEntireRepo) throws ConsumerException {
log.info("Processing entry [{}] from repository [{}]", path, this.repository.getId());
try {
ManagedRepositoryContent repositoryContent = repository.getContent();
ArtifactReference artifact = repositoryContent.toArtifactReference(path);
repositorySession.getRepository().getArtifacts(repository.getId(), artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion());
} catch (LayoutException | MetadataResolutionException e) {
throw new ConsumerException(e.getLocalizedMessage(), e);
}
}
Aggregations