use of org.apache.archiva.repository.content.ItemSelector in project archiva by apache.
the class AbstractRepositoryContentTest method assertLayout.
/**
* Perform a roundtrip through the layout routines to determine success.
*/
private void assertLayout(String path, String groupId, String artifactId, String version, String artifactVersion, String classifier, String type) throws LayoutException {
ItemSelector expectedArtifact = createItemSelector(groupId, artifactId, version, artifactVersion, classifier, type);
// --- Artifact Tests.
// Artifact to Path
assertEquals("Artifact <" + expectedArtifact + "> to path:", path, toPath(expectedArtifact));
// --- Artifact Reference Tests
// Path to Artifact Reference.
ItemSelector testReference = toItemSelector(path);
assertArtifactReference(testReference, groupId, artifactId, version, artifactVersion, classifier, type);
// And back again, using test Reference from previous step.
assertEquals("Artifact <" + expectedArtifact + "> to path:", path, toPath(testReference));
}
use of org.apache.archiva.repository.content.ItemSelector in project archiva by apache.
the class MavenContentHelperTest method assertArtifactVersion.
private void assertArtifactVersion(MavenContentHelper mavenContentHelper, String expectedVersion, StorageAsset dir, String selectorArtifactVersion, String selectorVersion) {
ItemSelector selector = ArchivaItemSelector.builder().withVersion(selectorVersion).withArtifactVersion(selectorArtifactVersion).build();
assertEquals(expectedVersion, mavenContentHelper.getArtifactVersion(dir, selector));
}
use of org.apache.archiva.repository.content.ItemSelector in project archiva by apache.
the class MavenContentHelperTest method assertClassifier.
private void assertClassifier(String expectedClassifier, String classifier, String type) {
ItemSelector selector = ArchivaItemSelector.builder().withClassifier(classifier).withType(type).build();
assertEquals(expectedClassifier, MavenContentHelper.getClassifier(selector));
}
use of org.apache.archiva.repository.content.ItemSelector in project archiva by apache.
the class ManagedDefaultRepositoryContent method getArtifact.
@Override
public Artifact getArtifact(final ItemSelector selectorArg) throws ContentAccessException {
ItemSelector selector = selectorArg;
if (!selectorArg.hasProjectId()) {
throw new IllegalArgumentException("Project id must be set");
}
if (!selectorArg.hasVersion()) {
if (selectorArg.hasArtifactVersion() && VersionUtil.isSnapshot(selectorArg.getArtifactVersion())) {
selector = ArchivaItemSelector.builder().withSelector(selectorArg).withVersion(VersionUtil.getBaseVersion(selectorArg.getArtifactVersion())).build();
} else if (selectorArg.hasArtifactVersion()) {
selector = ArchivaItemSelector.builder().withSelector(selectorArg).withVersion(selectorArg.getArtifactVersion()).build();
} else {
throw new IllegalArgumentException("Version must be set");
}
}
if (!selectorArg.hasArtifactId()) {
throw new IllegalArgumentException("Artifact id must be set");
}
final StorageAsset artifactDir = getAsset(selector.getNamespace(), selector.getProjectId(), selector.getVersion());
final String artifactVersion = mavenContentHelper.getArtifactVersion(artifactDir, selector);
final String classifier = MavenContentHelper.getClassifier(selector);
final String extension = MavenContentHelper.getArtifactExtension(selector);
final String artifactId = StringUtils.isEmpty(selector.getArtifactId()) ? selector.getProjectId() : selector.getArtifactId();
final String fileName = MavenContentHelper.getArtifactFileName(artifactId, artifactVersion, classifier, extension);
final StorageAsset path = getAsset(selector.getNamespace(), selector.getProjectId(), selector.getVersion(), fileName);
try {
return getArtifactFromPath(path);
} catch (LayoutException e) {
throw new IllegalArgumentException("The selector is not valid " + e.getMessage(), e);
}
}
use of org.apache.archiva.repository.content.ItemSelector in project archiva by apache.
the class MetadataTransferTest method assertReleaseMetadataContents.
/**
* Test for the existance of the requestedResource in the default managed repository, and if it exists,
* does it contain the expected release maven-metadata.xml contents?
*
* @param requestedResource the requested resource
* @throws Exception
*/
private void assertReleaseMetadataContents(String requestedResource) throws Exception {
Path actualFile = managedDefaultDir.resolve(requestedResource);
assertTrue("Release Metadata should exist: " + requestedResource, Files.exists(actualFile));
ItemSelector metadata = createVersionedSelector(requestedResource);
// Build expected metadata XML
StringWriter expectedMetadataXml = new StringWriter();
ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
m.setGroupId(metadata.getNamespace());
m.setArtifactId(metadata.getArtifactId());
m.setVersion(metadata.getVersion());
RepositoryMetadataWriter.write(m, expectedMetadataXml);
// Compare the file to the actual contents.
assertMetadataEquals(expectedMetadataXml.toString(), actualFile);
}
Aggregations