Search in sources :

Example 11 with LayoutException

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);
    }
}
Also used : ArchivaItemSelector(org.apache.archiva.repository.content.base.ArchivaItemSelector) Artifact(org.apache.archiva.repository.content.Artifact) LayoutException(org.apache.archiva.repository.content.LayoutException) BaseRepositoryContentLayout(org.apache.archiva.repository.content.BaseRepositoryContentLayout) ContentItem(org.apache.archiva.repository.content.ContentItem) HashSet(java.util.HashSet) ContentAccessException(org.apache.archiva.repository.content.ContentAccessException)

Example 12 with LayoutException

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);
    }
}
Also used : LayoutException(org.apache.archiva.repository.content.LayoutException) BaseRepositoryContentLayout(org.apache.archiva.repository.content.BaseRepositoryContentLayout) ManagedRepositoryContent(org.apache.archiva.repository.ManagedRepositoryContent) ConsumerException(org.apache.archiva.consumers.ConsumerException) Artifact(org.apache.archiva.repository.content.Artifact) MetadataResolutionException(org.apache.archiva.metadata.repository.MetadataResolutionException)

Example 13 with LayoutException

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.
    }
}
Also used : LayoutException(org.apache.archiva.repository.content.LayoutException) ManagedRepositoryContent(org.apache.archiva.repository.ManagedRepositoryContent) Test(org.junit.Test)

Example 14 with LayoutException

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.
    }
}
Also used : LayoutException(org.apache.archiva.repository.content.LayoutException) ManagedRepositoryContent(org.apache.archiva.repository.ManagedRepositoryContent) Test(org.junit.Test)

Example 15 with LayoutException

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.
    }
}
Also used : LayoutException(org.apache.archiva.repository.content.LayoutException) ManagedRepositoryContent(org.apache.archiva.repository.ManagedRepositoryContent) Test(org.junit.Test)

Aggregations

LayoutException (org.apache.archiva.repository.content.LayoutException)29 ManagedRepositoryContent (org.apache.archiva.repository.ManagedRepositoryContent)14 StorageAsset (org.apache.archiva.repository.storage.StorageAsset)14 BaseRepositoryContentLayout (org.apache.archiva.repository.content.BaseRepositoryContentLayout)13 Artifact (org.apache.archiva.repository.content.Artifact)12 ArchivaItemSelector (org.apache.archiva.repository.content.base.ArchivaItemSelector)12 IOException (java.io.IOException)9 ManagedRepository (org.apache.archiva.repository.ManagedRepository)8 ContentItem (org.apache.archiva.repository.content.ContentItem)8 ItemSelector (org.apache.archiva.repository.content.ItemSelector)8 ContentAccessException (org.apache.archiva.repository.content.ContentAccessException)6 Version (org.apache.archiva.repository.content.Version)6 DavException (org.apache.jackrabbit.webdav.DavException)6 ArrayList (java.util.ArrayList)5 ArchivaRepositoryMetadata (org.apache.archiva.model.ArchivaRepositoryMetadata)4 ItemNotFoundException (org.apache.archiva.repository.content.ItemNotFoundException)4 Project (org.apache.archiva.repository.content.Project)4 DavResource (org.apache.jackrabbit.webdav.DavResource)4 Path (java.nio.file.Path)3 HashSet (java.util.HashSet)3