use of org.apache.archiva.repository.content.Artifact in project archiva by apache.
the class MetadataUpdaterConsumer method processFile.
@Override
public void processFile(String path) throws ConsumerException {
// Ignore paths like .index etc
if (!path.startsWith(".")) {
try {
BaseRepositoryContentLayout layout = repository.getLayout(BaseRepositoryContentLayout.class);
Artifact artifact = layout.getArtifact(path);
updateVersionMetadata(artifact, path);
updateProjectMetadata(artifact, path);
} catch (LayoutException e) {
log.info("Not processing path that is not an artifact: {} ({})", path, e.getMessage());
}
}
}
use of org.apache.archiva.repository.content.Artifact 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<Artifact> references) {
if (references != null && !references.isEmpty()) {
MetadataRepository metadataRepository = repositorySession.getRepository();
Map<ArtifactInfo, ArtifactMetadata> metaRemovalList = new HashMap<>();
Map<String, Collection<ArtifactMetadata>> metaResolved = new HashMap<>();
for (Artifact reference : references) {
String baseVersion = reference.getVersion().getId();
String namespace = reference.getVersion().getProject().getNamespace().getId();
// Needed for tracking in the hashmap
String metaBaseId = reference.toKey();
if (!metaResolved.containsKey(metaBaseId)) {
try {
metaResolved.put(metaBaseId, metadataRepository.getArtifacts(repositorySession, repository.getId(), namespace, reference.getId(), baseVersion));
} catch (MetadataResolutionException e) {
log.error("Error during metadata retrieval {}: {}", metaBaseId, e.getMessage());
}
}
StorageAsset artifactFile = reference.getAsset();
for (RepositoryListener listener : listeners) {
listener.deleteArtifact(metadataRepository, repository.getId(), namespace, reference.getId(), reference.getVersion().getId(), artifactFile.getName());
}
if (reference.exists()) {
try {
repository.deleteItem(reference);
} catch (ContentAccessException e) {
log.error("Error while trying to delete artifact {}: {}", reference.toString(), e.getMessage(), e);
} catch (ItemNotFoundException e) {
log.error("Asset deleted from background other thread: {}", e.getMessage());
}
}
boolean snapshotVersion = VersionUtil.isSnapshot(baseVersion);
// 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.getArtifactVersion())) {
ArtifactInfo info = new ArtifactInfo(artifactMetadata.getNamespace(), artifactMetadata.getProject(), artifactMetadata.getProjectVersion(), artifactMetadata.getVersion());
if (StringUtils.isNotBlank(reference.getClassifier())) {
info.setClassifier(reference.getClassifier());
} else {
info.setClassifier("");
}
metaRemovalList.put(info, artifactMetadata);
}
}
}
} else // otherwise we delete the artifact version
{
ArtifactInfo info = new ArtifactInfo(namespace, reference.getId(), baseVersion, reference.getArtifactVersion());
for (ArtifactMetadata metadata : metaResolved.get(metaBaseId)) {
metaRemovalList.put(info, metadata);
}
}
triggerAuditEvent(repository.getRepository().getId(), reference.toKey(), AuditEvent.PURGE_ARTIFACT);
// purgeSupportFiles( artifactFile );
}
purgeMetadata(metadataRepository, metaRemovalList);
try {
repositorySession.save();
} catch (org.apache.archiva.metadata.repository.MetadataSessionException e) {
e.printStackTrace();
}
}
}
use of org.apache.archiva.repository.content.Artifact in project archiva by apache.
the class ManagedDefaultRepositoryContent method newArtifactStream.
/**
* Returns all related artifacts that match the given artifact. That means all artifacts that have
* the same filename plus an additional extension, e.g. ${fileName}.sha2
*
* @param item the artifact
* @return the stream of artifacts
* @throws ContentAccessException if access to the underlying storage failed
*/
public Stream<? extends Artifact> newArtifactStream(Artifact item) throws ContentAccessException {
final Version v = item.getVersion();
final String fileName = item.getFileName();
final Predicate<StorageAsset> filter = (StorageAsset a) -> a.getName().startsWith(fileName + ".");
return v.getAsset().list().stream().filter(filter).map(a -> {
try {
return getArtifactFromPath(a);
} catch (LayoutException e) {
log.error("Not a valid artifact path " + a.getPath(), e);
return null;
}
}).filter(Objects::nonNull);
}
use of org.apache.archiva.repository.content.Artifact 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);
BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout(BaseRepositoryContentLayout.class);
Artifact artifact = layout.getArtifact(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);
StorageAsset downloadedFile = proxyHandler.fetchFromProxies(managedDefaultRepository.getRepository(), artifact);
// Validate that file actually came from proxied2 (as intended).
Path proxied2File = Paths.get(REPOPATH_PROXIED2, path);
assertNotNull(downloadedFile);
assertFileEquals(expectedFile, downloadedFile.getFilePath(), proxied2File);
assertNoTempFiles(expectedFile);
}
use of org.apache.archiva.repository.content.Artifact in project archiva by apache.
the class SnapshotTransferTest method testOlderTimestampDrivenSnapshotOnFirstRepo.
@Test
public void testOlderTimestampDrivenSnapshotOnFirstRepo() throws Exception {
String path = "org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar";
setupTestableManagedRepository(path);
Path expectedFile = managedDefaultDir.resolve(path);
Path remoteFile = Paths.get(REPOPATH_PROXIED1, path);
setManagedNewerThanRemote(expectedFile, remoteFile);
BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout(BaseRepositoryContentLayout.class);
Artifact artifact = layout.getArtifact(path);
// Configure Connector (usually done within archiva.xml configuration)
saveConnector(ID_DEFAULT_MANAGED, ID_PROXIED1, false);
// Attempt to download.
StorageAsset downloadedFile = proxyHandler.fetchFromProxies(managedDefaultRepository.getRepository(), artifact);
// Should not have downloaded as managed is newer than remote.
assertNotDownloaded(downloadedFile);
assertNoTempFiles(expectedFile);
}
Aggregations