use of org.apache.archiva.repository.events.RepositoryListener in project archiva by apache.
the class DefaultMetadataResolver method resolveArtifacts.
@Override
public Collection<ArtifactMetadata> resolveArtifacts(RepositorySession session, String repoId, String namespace, String projectId, String projectVersion) throws MetadataResolutionException {
try {
MetadataRepository metadataRepository = session.getRepository();
Collection<ArtifactMetadata> artifacts = metadataRepository.getArtifacts(repoId, namespace, projectId, projectVersion);
ExcludesFilter<String> filter = new ExcludesFilter<String>(createArtifactIdList(artifacts));
ReadMetadataRequest readMetadataRequest = new ReadMetadataRequest().repositoryId(repoId).namespace(namespace).projectId(projectId).projectVersion(projectVersion).filter(filter);
Collection<ArtifactMetadata> storageArtifacts = repositoryStorage.readArtifactsMetadata(readMetadataRequest);
if (storageArtifacts != null && !storageArtifacts.isEmpty()) {
log.debug("Resolved artifacts from storage: {}", storageArtifacts);
for (ArtifactMetadata artifact : storageArtifacts) {
try {
metadataRepository.updateArtifact(repoId, namespace, projectId, projectVersion, artifact);
} catch (MetadataRepositoryException e) {
log.warn("Unable to persist resolved information: {}", e.getMessage(), e);
}
}
session.markDirty();
artifacts = new ArrayList<>(artifacts);
artifacts.addAll(storageArtifacts);
}
return artifacts;
} catch (RepositoryStorageRuntimeException e) {
for (RepositoryListener listener : listeners) {
listener.addArtifactProblem(session, repoId, namespace, projectId, projectVersion, e);
}
throw new MetadataResolutionException(e.getMessage(), e);
}
}
use of org.apache.archiva.repository.events.RepositoryListener 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.repository.events.RepositoryListener in project archiva by apache.
the class CleanupReleasedSnapshotsRepositoryPurgeTest method setUp.
@Before
@Override
public void setUp() throws Exception {
super.setUp();
RepositoryContentFactory factory = applicationContext.getBean("repositoryContentFactory#cleanup-released-snapshots", RepositoryContentFactory.class);
archivaConfiguration = applicationContext.getBean("archivaConfiguration#cleanup-released-snapshots", ArchivaConfiguration.class);
listenerControl = EasyMock.createControl();
listener = listenerControl.createMock(RepositoryListener.class);
List<RepositoryListener> listeners = Collections.singletonList(listener);
repoPurge = new CleanupReleasedSnapshotsRepositoryPurge(getRepository(), metadataTools, applicationContext.getBean(RepositoryRegistry.class), repositorySession, listeners);
((DefaultManagedRepositoryAdmin) applicationContext.getBean(ManagedRepositoryAdmin.class)).setArchivaConfiguration(archivaConfiguration);
}
use of org.apache.archiva.repository.events.RepositoryListener in project archiva by apache.
the class DaysOldRepositoryPurgeTest method testOrderOfDeletion.
@Test
public void testOrderOfDeletion() throws Exception {
org.apache.archiva.repository.ManagedRepository repoConfiguration = getRepoConfiguration(TEST_REPO_ID, TEST_REPO_NAME);
ArtifactCleanupFeature atf = repoConfiguration.getFeature(ArtifactCleanupFeature.class).get();
List<RepositoryListener> listeners = Collections.singletonList(listener);
repoPurge = new DaysOldRepositoryPurge(getRepository(), atf.getRetentionPeriod().getDays(), atf.getRetentionCount(), repositorySession, listeners);
String repoRoot = prepareTestRepos();
String projectNs = "org.apache.maven.plugins";
String projectPath = projectNs.replaceAll("\\.", "/");
String projectName = "maven-assembly-plugin";
String projectVersion = "1.1.2-SNAPSHOT";
String projectRoot = repoRoot + "/" + projectPath + "/" + projectName;
Path repo = getTestRepoRootPath();
Path vDir = repo.resolve(projectPath).resolve(projectName).resolve(projectVersion);
Set<String> deletedVersions = new HashSet<>();
deletedVersions.add("1.1.2-20070427.065136-1");
setLastModified(projectRoot + "/" + projectVersion + "/", OLD_TIMESTAMP);
// test listeners for the correct artifacts
String[] exts = { ".md5", ".sha1", "" };
for (int i = 0; i < exts.length; i++) {
listener.deleteArtifact(metadataRepository, getRepository().getId(), "org.apache.maven.plugins", "maven-assembly-plugin", "1.1.2-20070427.065136-1", "maven-assembly-plugin-1.1.2-20070427.065136-1.jar" + exts[i]);
listener.deleteArtifact(metadataRepository, getRepository().getId(), "org.apache.maven.plugins", "maven-assembly-plugin", "1.1.2-20070427.065136-1", "maven-assembly-plugin-1.1.2-20070427.065136-1.pom" + exts[i]);
}
listenerControl.replay();
// Provide the metadata list
List<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID, projectName, repo.getParent(), vDir);
when(metadataRepository.getArtifacts(TEST_REPO_ID, projectNs, projectName, projectVersion)).thenReturn(ml);
repoPurge.process(PATH_TO_TEST_ORDER_OF_DELETION);
listenerControl.verify();
// Verify the metadataRepository invocations
verify(metadataRepository, never()).removeProjectVersion(eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion));
ArgumentCaptor<ArtifactMetadata> metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
verify(metadataRepository, times(deletedVersions.size())).removeArtifact(metadataArg.capture(), eq(projectVersion));
List<ArtifactMetadata> metaL = metadataArg.getAllValues();
for (ArtifactMetadata meta : metaL) {
assertTrue(meta.getId().startsWith(projectName));
assertTrue(deletedVersions.contains(meta.getVersion()));
}
assertDeleted(projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070427.065136-1.jar");
assertDeleted(projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070427.065136-1.jar.sha1");
assertDeleted(projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070427.065136-1.jar.md5");
assertDeleted(projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070427.065136-1.pom");
assertDeleted(projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070427.065136-1.pom.sha1");
assertDeleted(projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070427.065136-1.pom.md5");
// the following should not have been deleted
assertExists(projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070506.163513-2.jar");
assertExists(projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070506.163513-2.jar.sha1");
assertExists(projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070506.163513-2.jar.md5");
assertExists(projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070506.163513-2.pom");
assertExists(projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070506.163513-2.pom.sha1");
assertExists(projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070506.163513-2.pom.md5");
assertExists(projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070615.105019-3.jar");
assertExists(projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070615.105019-3.jar.sha1");
assertExists(projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070615.105019-3.jar.md5");
assertExists(projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070615.105019-3.pom");
assertExists(projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070615.105019-3.pom.sha1");
assertExists(projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070615.105019-3.pom.md5");
}
use of org.apache.archiva.repository.events.RepositoryListener in project archiva by apache.
the class RetentionCountRepositoryPurgeTest method setUp.
@Before
@Override
public void setUp() throws Exception {
super.setUp();
org.apache.archiva.repository.ManagedRepository repoConfiguration = getRepoConfiguration(TEST_REPO_ID, TEST_REPO_NAME);
List<RepositoryListener> listeners = Collections.singletonList(listener);
ArtifactCleanupFeature acf = repoConfiguration.getFeature(ArtifactCleanupFeature.class).get();
repoPurge = new RetentionCountRepositoryPurge(getRepository(), acf.getRetentionCount(), repositorySession, listeners);
}
Aggregations