use of org.apache.archiva.model.ArtifactReference in project archiva by apache.
the class AbstractRepositoryPurge method purge.
/**
* Purge the repo. Update db and index of removed artifacts.
*
* @param references
*/
protected void purge(Set<ArtifactReference> references) {
if (references != null && !references.isEmpty()) {
MetadataRepository metadataRepository = repositorySession.getRepository();
Map<ArtifactInfo, ArtifactMetadata> metaRemovalList = new HashMap<>();
Map<String, Collection<ArtifactMetadata>> metaResolved = new HashMap<>();
for (ArtifactReference reference : references) {
String baseVersion = VersionUtil.getBaseVersion(reference.getVersion());
// Needed for tracking in the hashmap
String metaBaseId = reference.getGroupId() + "/" + reference.getArtifactId() + "/" + baseVersion;
if (!metaResolved.containsKey(metaBaseId)) {
try {
metaResolved.put(metaBaseId, metadataRepository.getArtifacts(repository.getId(), reference.getGroupId(), reference.getArtifactId(), baseVersion));
} catch (MetadataResolutionException e) {
log.error("Error during metadata retrieval {}: {}", metaBaseId, e.getMessage());
}
}
Path artifactFile = repository.toFile(reference);
for (RepositoryListener listener : listeners) {
listener.deleteArtifact(metadataRepository, repository.getId(), reference.getGroupId(), reference.getArtifactId(), reference.getVersion(), artifactFile.getFileName().toString());
}
try {
Files.delete(artifactFile);
log.debug("File deleted: {}", artifactFile.toAbsolutePath());
} catch (IOException e) {
log.error("Could not delete file {}: {}", artifactFile.toAbsolutePath(), e.getMessage(), e);
continue;
}
try {
repository.deleteArtifact(reference);
} catch (ContentNotFoundException e) {
log.warn("skip error deleting artifact {}: {}", reference, e.getMessage());
}
boolean snapshotVersion = VersionUtil.isSnapshot(reference.getVersion());
// If this is a snapshot we have to search for artifacts with the same version. And remove all of them.
if (snapshotVersion) {
Collection<ArtifactMetadata> artifacts = metaResolved.get(metaBaseId);
if (artifacts != null) {
// cleanup snapshots metadata
for (ArtifactMetadata artifactMetadata : artifacts) {
// Artifact metadata and reference version should match.
if (artifactMetadata.getVersion().equals(reference.getVersion())) {
ArtifactInfo info = new ArtifactInfo(artifactMetadata.getNamespace(), artifactMetadata.getProject(), artifactMetadata.getProjectVersion(), artifactMetadata.getVersion());
if (StringUtils.isNotBlank(reference.getClassifier())) {
info.setClassifier(reference.getClassifier());
metaRemovalList.put(info, artifactMetadata);
} else {
// metadataRepository.removeArtifact( artifactMetadata, baseVersion );
metaRemovalList.put(info, artifactMetadata);
}
}
}
}
} else // otherwise we delete the artifact version
{
ArtifactInfo info = new ArtifactInfo(reference.getGroupId(), reference.getArtifactId(), baseVersion, reference.getVersion());
for (ArtifactMetadata metadata : metaResolved.get(metaBaseId)) {
metaRemovalList.put(info, metadata);
}
}
triggerAuditEvent(repository.getRepository().getId(), ArtifactReference.toKey(reference), AuditEvent.PURGE_ARTIFACT);
purgeSupportFiles(artifactFile);
}
purgeMetadata(metadataRepository, metaRemovalList);
repositorySession.save();
}
}
use of org.apache.archiva.model.ArtifactReference in project archiva by apache.
the class CacheFailuresTransferTest method testGetWhenInBothProxiedButFirstCacheFailure.
@Test
public void testGetWhenInBothProxiedButFirstCacheFailure() throws Exception {
String path = "org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar";
setupTestableManagedRepository(path);
Path expectedFile = managedDefaultDir.resolve(path);
ArtifactReference artifact = managedDefaultRepository.toArtifactReference(path);
Files.deleteIfExists(expectedFile);
assertFalse(Files.exists(expectedFile));
String url = PathUtil.toUrl(REPOPATH_PROXIED1 + "/" + path);
// Intentionally set failure on url in proxied1 (for test)
UrlFailureCache failurlCache = lookupUrlFailureCache();
failurlCache.cacheFailure(url);
// Configure Connector (usually done within archiva.xml configuration)
saveConnector(ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.YES, false);
saveConnector(ID_DEFAULT_MANAGED, "proxied2", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.YES, false);
Path downloadedFile = proxyHandler.fetchFromProxies(managedDefaultRepository, artifact);
// Validate that file actually came from proxied2 (as intended).
Path proxied2File = Paths.get(REPOPATH_PROXIED2, path);
assertFileEquals(expectedFile, downloadedFile, proxied2File);
assertNoTempFiles(expectedFile);
}
use of org.apache.archiva.model.ArtifactReference in project archiva by apache.
the class CacheFailuresTransferTest method testGetWithCacheFailuresOff.
@Test
public void testGetWithCacheFailuresOff() throws Exception {
String path = "org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar";
Path expectedFile = managedDefaultDir.resolve(path);
setupTestableManagedRepository(path);
assertNotExistsInManagedDefaultRepo(expectedFile);
ArtifactReference artifact = managedDefaultRepository.toArtifactReference(path);
// Configure Repository (usually done within archiva.xml configuration)
saveRemoteRepositoryConfig("badproxied1", "Bad Proxied 1", "test://bad.machine.com/repo/", "default");
saveRemoteRepositoryConfig("badproxied2", "Bad Proxied 2", "test://bad.machine.com/anotherrepo/", "default");
// Configure Connector (usually done within archiva.xml configuration)
saveConnector(ID_DEFAULT_MANAGED, "badproxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false);
saveConnector(ID_DEFAULT_MANAGED, "badproxied2", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false);
wagonMock.get(EasyMock.eq(path), EasyMock.anyObject(File.class));
EasyMock.expectLastCall().andThrow(new ResourceDoesNotExistException("resource does not exist.")).times(2);
wagonMockControl.replay();
Path downloadedFile = proxyHandler.fetchFromProxies(managedDefaultRepository, artifact);
wagonMockControl.verify();
// Second attempt to download same artifact DOES NOT use cache
wagonMockControl.reset();
wagonMock.get(EasyMock.eq(path), EasyMock.anyObject(File.class));
EasyMock.expectLastCall().andThrow(new ResourceDoesNotExistException("resource does not exist.")).times(2);
wagonMockControl.replay();
downloadedFile = proxyHandler.fetchFromProxies(managedDefaultRepository, artifact);
wagonMockControl.verify();
assertNotDownloaded(downloadedFile);
assertNoTempFiles(expectedFile);
}
use of org.apache.archiva.model.ArtifactReference in project archiva by apache.
the class CacheFailuresTransferTest method testGetWithCacheFailuresOn.
@Test
public void testGetWithCacheFailuresOn() throws Exception {
String path = "org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar";
Path expectedFile = managedDefaultDir.resolve(path);
setupTestableManagedRepository(path);
assertNotExistsInManagedDefaultRepo(expectedFile);
ArtifactReference artifact = managedDefaultRepository.toArtifactReference(path);
// Configure Repository (usually done within archiva.xml configuration)
saveRemoteRepositoryConfig("badproxied1", "Bad Proxied 1", "test://bad.machine.com/repo/", "default");
saveRemoteRepositoryConfig("badproxied2", "Bad Proxied 2", "test://bad.machine.com/anotherrepo/", "default");
// Configure Connector (usually done within archiva.xml configuration)
saveConnector(ID_DEFAULT_MANAGED, "badproxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.YES, false);
saveConnector(ID_DEFAULT_MANAGED, "badproxied2", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.YES, false);
wagonMock.get(EasyMock.eq(path), EasyMock.anyObject(File.class));
EasyMock.expectLastCall().andThrow(new ResourceDoesNotExistException("resource does not exist.")).times(2);
wagonMockControl.replay();
Path downloadedFile = proxyHandler.fetchFromProxies(managedDefaultRepository, artifact);
wagonMockControl.verify();
// Second attempt to download same artifact use cache
wagonMockControl.reset();
wagonMockControl.replay();
downloadedFile = proxyHandler.fetchFromProxies(managedDefaultRepository, artifact);
wagonMockControl.verify();
assertNotDownloaded(downloadedFile);
assertNoTempFiles(expectedFile);
}
use of org.apache.archiva.model.ArtifactReference in project archiva by apache.
the class ChecksumTransferTest method testGetChecksumCorrectSha1NoMd5.
@Test
public void testGetChecksumCorrectSha1NoMd5() throws Exception {
String path = "org/apache/maven/test/get-checksum-sha1-only/1.0/get-checksum-sha1-only-1.0.jar";
setupTestableManagedRepository(path);
Path expectedFile = managedDefaultDir.resolve(path);
ArtifactReference artifact = managedDefaultRepository.toArtifactReference(path);
FileUtils.deleteDirectory(expectedFile.getParent());
assertFalse(Files.exists(expectedFile));
// Configure Connector (usually done within archiva.xml configuration)
saveConnector(ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false);
Path downloadedFile = proxyHandler.fetchFromProxies(managedDefaultRepository, artifact);
Path proxied1File = Paths.get(REPOPATH_PROXIED1, path);
assertFileEquals(expectedFile, downloadedFile, proxied1File);
assertNoTempFiles(expectedFile);
assertChecksums(expectedFile, "748a3a013bf5eacf2bbb40a2ac7d37889b728837 *get-checksum-sha1-only-1.0.jar", null);
}
Aggregations