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());
}
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;
}
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;
}
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 */
}
}
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;
}
Aggregations