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.
}
}
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.
}
}
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.
}
}
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;
}
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;
}
}
}
Aggregations