Search in sources :

Example 1 with ArtifactReference

use of org.apache.archiva.model.ArtifactReference in project archiva by apache.

the class RepositoryRequestTest method assertValid.

private void assertValid(String path, String groupId, String artifactId, String version, String classifier, String type) throws Exception {
    String expectedId = "ArtifactReference - " + groupId + ":" + artifactId + ":" + version + ":" + (classifier != null ? classifier + ":" : "") + type;
    ArtifactReference reference = repoRequest.toArtifactReference(path);
    assertNotNull(expectedId + " - Should not be null.", reference);
    assertEquals(expectedId + " - Group ID", groupId, reference.getGroupId());
    assertEquals(expectedId + " - Artifact ID", artifactId, reference.getArtifactId());
    if (StringUtils.isNotBlank(classifier)) {
        assertEquals(expectedId + " - Classifier", classifier, reference.getClassifier());
    }
    assertEquals(expectedId + " - Version ID", version, reference.getVersion());
    assertEquals(expectedId + " - Type", type, reference.getType());
}
Also used : ArtifactReference(org.apache.archiva.model.ArtifactReference)

Example 2 with ArtifactReference

use of org.apache.archiva.model.ArtifactReference 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 3 with ArtifactReference

use of org.apache.archiva.model.ArtifactReference in project archiva by apache.

the class RepositoryRequest method toNativePath.

/**
 * Adjust the requestedPath to conform to the native layout of the provided {@link org.apache.archiva.repository.ManagedRepositoryContent}.
 *
 * @param requestedPath the incoming requested path.
 * @param repository    the repository to adjust to.
 * @return the adjusted (to native) path.
 * @throws LayoutException if the path cannot be parsed.
 */
public String toNativePath(String requestedPath, ManagedRepositoryContent repository) throws LayoutException {
    if (StringUtils.isBlank(requestedPath)) {
        throw new LayoutException("Request Path is blank.");
    }
    String referencedResource = requestedPath;
    // No checksum by default.
    String supportfile = "";
    // Figure out support file, and actual referencedResource.
    if (isSupportFile(requestedPath)) {
        int idx = requestedPath.lastIndexOf('.');
        referencedResource = requestedPath.substring(0, idx);
        supportfile = requestedPath.substring(idx);
    }
    if (isMetadata(referencedResource)) {
        /* Nothing to translate.
             * Default layout is the only layout that can contain maven-metadata.xml files, and
             * if the managedRepository is layout legacy, this request would never occur.
             */
        return requestedPath;
    }
    // Treat as an artifact reference.
    ArtifactReference ref = toArtifactReference(referencedResource);
    String adjustedPath = repository.toPath(ref);
    return adjustedPath + supportfile;
}
Also used : LayoutException(org.apache.archiva.repository.LayoutException) ArtifactReference(org.apache.archiva.model.ArtifactReference)

Example 4 with ArtifactReference

use of org.apache.archiva.model.ArtifactReference in project archiva by apache.

the class AbstractDefaultRepositoryContentTestCase method testToPathOnNullArtifactReference.

@Test
public void testToPathOnNullArtifactReference() {
    try {
        ArtifactReference reference = null;
        toPath(reference);
        fail("Should have failed due to null artifact reference.");
    } catch (IllegalArgumentException e) {
    /* expected path */
    }
}
Also used : ArtifactReference(org.apache.archiva.model.ArtifactReference) Test(org.junit.Test)

Example 5 with ArtifactReference

use of org.apache.archiva.model.ArtifactReference in project archiva by apache.

the class AbstractDefaultRepositoryContentTestCase method createArtifact.

protected ArtifactReference createArtifact(String groupId, String artifactId, String version, String classifier, String type) {
    ArtifactReference artifact = new ArtifactReference();
    artifact.setGroupId(groupId);
    artifact.setArtifactId(artifactId);
    artifact.setVersion(version);
    artifact.setClassifier(classifier);
    artifact.setType(type);
    assertNotNull(artifact);
    return artifact;
}
Also used : ArtifactReference(org.apache.archiva.model.ArtifactReference)

Aggregations

ArtifactReference (org.apache.archiva.model.ArtifactReference)77 Path (java.nio.file.Path)62 Test (org.junit.Test)50 LayoutException (org.apache.archiva.repository.LayoutException)13 IOException (java.io.IOException)10 ManagedRepositoryContent (org.apache.archiva.repository.ManagedRepositoryContent)9 ContentNotFoundException (org.apache.archiva.repository.ContentNotFoundException)8 RepositoryException (org.apache.archiva.repository.RepositoryException)8 VersionedReference (org.apache.archiva.model.VersionedReference)7 File (java.io.File)5 Date (java.util.Date)5 ArchivaRestServiceException (org.apache.archiva.rest.api.services.ArchivaRestServiceException)5 RepositoryTask (org.apache.archiva.scheduler.repository.model.RepositoryTask)5 ResourceDoesNotExistException (org.apache.maven.wagon.ResourceDoesNotExistException)5 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)4 ManagedRepository (org.apache.archiva.admin.model.beans.ManagedRepository)4 ArtifactMetadata (org.apache.archiva.metadata.model.ArtifactMetadata)4 MetadataRepository (org.apache.archiva.metadata.repository.MetadataRepository)4