use of org.apache.archiva.repository.content.LayoutException in project archiva by apache.
the class RetentionCountRepositoryPurge method process.
@Override
public void process(String path) throws RepositoryPurgeException {
try {
ContentItem item = repository.toItem(path);
BaseRepositoryContentLayout layout = repository.getLayout(BaseRepositoryContentLayout.class);
Artifact artifact = layout.adaptItem(Artifact.class, item);
if (!artifact.exists()) {
return;
}
if (VersionUtil.isSnapshot(artifact.getVersion().getId())) {
ArchivaItemSelector selector = ArchivaItemSelector.builder().withNamespace(artifact.getVersion().getProject().getNamespace().getId()).withProjectId(artifact.getVersion().getProject().getId()).withArtifactId(artifact.getId()).withVersion(artifact.getVersion().getId()).withClassifier("*").includeRelatedArtifacts().build();
List<String> versions;
try (Stream<? extends Artifact> stream = repository.getLayout(BaseRepositoryContentLayout.class).newArtifactStream(selector)) {
versions = stream.map(a -> a.getArtifactVersion()).filter(StringUtils::isNotEmpty).distinct().collect(Collectors.toList());
}
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;
}
ArchivaItemSelector.Builder selectorBuilder = ArchivaItemSelector.builder().withNamespace(artifact.getVersion().getProject().getNamespace().getId()).withProjectId(artifact.getVersion().getProject().getId()).withArtifactId(artifact.getId()).withClassifier("*").includeRelatedArtifacts().withVersion(artifact.getVersion().getId());
int countToPurge = versions.size() - retentionCount;
Set<Artifact> artifactsToDelete = new HashSet<>();
for (String version : versions) {
if (countToPurge-- <= 0) {
break;
}
List<? extends Artifact> delArtifacts = repository.getLayout(BaseRepositoryContentLayout.class).getArtifacts(selectorBuilder.withArtifactVersion(version).build());
if (delArtifacts != null && delArtifacts.size() > 0) {
artifactsToDelete.addAll(delArtifacts);
}
}
purge(artifactsToDelete);
}
} catch (LayoutException le) {
throw new RepositoryPurgeException(le.getMessage(), le);
} catch (ContentAccessException e) {
log.error("Error while accessing the repository data: {}", e.getMessage(), e);
throw new RepositoryPurgeException(e.getMessage(), e);
}
}
use of org.apache.archiva.repository.content.LayoutException 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();
BaseRepositoryContentLayout layout = repositoryContent.getLayout(BaseRepositoryContentLayout.class);
Artifact artifact = layout.getArtifact(path);
repositorySession.getRepository().getArtifacts(repositorySession, repository.getId(), artifact.getNamespace().getId(), artifact.getId(), artifact.getVersion().getId());
} catch (LayoutException | MetadataResolutionException e) {
throw new ConsumerException(e.getLocalizedMessage(), e);
}
}
use of org.apache.archiva.repository.content.LayoutException in project archiva by apache.
the class MavenRepositoryRequestInfoTest method testNativePathBadRequestTooShort.
@Test
public void testNativePathBadRequestTooShort() throws Exception {
ManagedRepositoryContent repository = createManagedRepo("default");
// Test bad request path (too short)
try {
repoRequest.toNativePath("org.apache.derby/license.txt");
fail("Should have thrown an exception about a too short path.");
} catch (LayoutException e) {
// expected path.
}
}
use of org.apache.archiva.repository.content.LayoutException in project archiva by apache.
the class MavenRepositoryRequestInfoTest method testNativePathBadRequestUnknownType.
@Test
public void testNativePathBadRequestUnknownType() throws Exception {
ManagedRepositoryContent repository = createManagedRepo("default");
// Test bad request path (too short)
try {
repoRequest.toNativePath("org/apache/derby/derby/10.2.2.0/license.txt");
fail("Should have thrown an exception about an invalid type.");
} catch (LayoutException e) {
// expected path.
}
}
use of org.apache.archiva.repository.content.LayoutException in project archiva by apache.
the class MavenRepositoryRequestInfoTest method testNativePathBadRequestNull.
@Test
public void testNativePathBadRequestNull() throws Exception {
ManagedRepositoryContent repository = createManagedRepo("default");
// Test bad request path (too short)
try {
repoRequest.toNativePath(null);
fail("Should have thrown an exception about an null request.");
} catch (LayoutException e) {
// expected path.
}
}
Aggregations