Search in sources :

Example 1 with LayoutException

use of org.apache.archiva.repository.LayoutException in project archiva by apache.

the class RepositoryRequestTest 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", repository);
        fail("Should have thrown an exception about a too short path.");
    } catch (LayoutException e) {
    // expected path.
    }
}
Also used : LayoutException(org.apache.archiva.repository.LayoutException) ManagedRepositoryContent(org.apache.archiva.repository.ManagedRepositoryContent) Test(org.junit.Test)

Example 2 with LayoutException

use of org.apache.archiva.repository.LayoutException in project archiva by apache.

the class RepositoryRequestTest method testNativePathBadRequestBlank.

@Test
public void testNativePathBadRequestBlank() throws Exception {
    ManagedRepositoryContent repository = createManagedRepo("default");
    // Test bad request path (too short)
    try {
        repoRequest.toNativePath("", repository);
        fail("Should have thrown an exception about an blank request.");
    } catch (LayoutException e) {
    // expected path.
    }
}
Also used : LayoutException(org.apache.archiva.repository.LayoutException) ManagedRepositoryContent(org.apache.archiva.repository.ManagedRepositoryContent) Test(org.junit.Test)

Example 3 with LayoutException

use of org.apache.archiva.repository.LayoutException in project archiva by apache.

the class RepositoryRequestTest 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", repository);
        fail("Should have thrown an exception about an invalid type.");
    } catch (LayoutException e) {
    // expected path.
    }
}
Also used : LayoutException(org.apache.archiva.repository.LayoutException) ManagedRepositoryContent(org.apache.archiva.repository.ManagedRepositoryContent) Test(org.junit.Test)

Example 4 with LayoutException

use of org.apache.archiva.repository.LayoutException in project archiva by apache.

the class DefaultPathParser method toArtifactReference.

/**
 * {@inheritDoc}
 *
 * @see org.apache.archiva.repository.content.PathParser#toArtifactReference(String)
 */
@Override
public ArtifactReference toArtifactReference(String path) throws LayoutException {
    if (StringUtils.isBlank(path)) {
        throw new LayoutException("Unable to convert blank path.");
    }
    ArtifactMetadata metadata;
    try {
        metadata = pathTranslator.getArtifactForPath(null, path);
    } catch (IllegalArgumentException e) {
        throw new LayoutException(e.getMessage(), e);
    }
    ArtifactReference artifact = new ArtifactReference();
    artifact.setGroupId(metadata.getNamespace());
    artifact.setArtifactId(metadata.getProject());
    artifact.setVersion(metadata.getVersion());
    MavenArtifactFacet facet = (MavenArtifactFacet) metadata.getFacet(MavenArtifactFacet.FACET_ID);
    if (facet != null) {
        artifact.setClassifier(facet.getClassifier());
        artifact.setType(facet.getType());
    }
    return artifact;
}
Also used : LayoutException(org.apache.archiva.repository.LayoutException) MavenArtifactFacet(org.apache.archiva.metadata.model.maven2.MavenArtifactFacet) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) ArtifactReference(org.apache.archiva.model.ArtifactReference)

Example 5 with LayoutException

use of org.apache.archiva.repository.LayoutException in project archiva by apache.

the class ManagedDefaultRepositoryContent method getFirstArtifact.

/**
 * Get the first Artifact found in the provided VersionedReference location.
 *
 * @param reference the reference to the versioned reference to search within
 * @return the ArtifactReference to the first artifact located within the versioned reference. or null if
 *         no artifact was found within the versioned reference.
 * @throws java.io.IOException     if the versioned reference is invalid (example: doesn't exist, or isn't a directory)
 * @throws LayoutException
 */
private ArtifactReference getFirstArtifact(VersionedReference reference) throws LayoutException, IOException {
    String path = toMetadataPath(reference);
    int idx = path.lastIndexOf('/');
    if (idx > 0) {
        path = path.substring(0, idx);
    }
    Path repoBase = PathUtil.getPathFromUri(repository.getLocation()).toAbsolutePath();
    Path repoDir = repoBase.resolve(path);
    if (!Files.exists(repoDir)) {
        throw new IOException("Unable to gather the list of snapshot versions on a non-existant directory: " + repoDir.toAbsolutePath());
    }
    if (!Files.isDirectory(repoDir)) {
        throw new IOException("Unable to gather the list of snapshot versions on a non-directory: " + repoDir.toAbsolutePath());
    }
    try (Stream<Path> stream = Files.list(repoDir)) {
        return stream.filter(Files::isRegularFile).map(p -> repoBase.relativize(p).toString()).filter(filetypes::matchesArtifactPattern).map(this::toArtifactRef).findFirst().orElse(null);
    } catch (RuntimeException e) {
        if (e.getCause() != null && e.getCause() instanceof LayoutException) {
            throw (LayoutException) e.getCause();
        } else {
            throw e;
        }
    }
}
Also used : Path(java.nio.file.Path) LayoutException(org.apache.archiva.repository.LayoutException) IOException(java.io.IOException)

Aggregations

LayoutException (org.apache.archiva.repository.LayoutException)21 ArtifactReference (org.apache.archiva.model.ArtifactReference)15 Path (java.nio.file.Path)11 ManagedRepositoryContent (org.apache.archiva.repository.ManagedRepositoryContent)10 IOException (java.io.IOException)8 VersionedReference (org.apache.archiva.model.VersionedReference)8 ContentNotFoundException (org.apache.archiva.repository.ContentNotFoundException)8 HashSet (java.util.HashSet)6 ProjectReference (org.apache.archiva.model.ProjectReference)6 Files (java.nio.file.Files)4 Paths (java.nio.file.Paths)4 ArrayList (java.util.ArrayList)4 Collections (java.util.Collections)4 List (java.util.List)4 Set (java.util.Set)4 Stream (java.util.stream.Stream)4 PathUtil (org.apache.archiva.common.utils.PathUtil)4 FileTypes (org.apache.archiva.configuration.FileTypes)4 RepositoryException (org.apache.archiva.repository.RepositoryException)4 StringUtils (org.apache.commons.lang.StringUtils)4