use of org.apache.archiva.repository.content.ItemSelector in project archiva by apache.
the class ManagedDefaultRepositoryContentTest method testArtifactListWithArtifactSelectorAndRelated.
@Test
public void testArtifactListWithArtifactSelectorAndRelated() {
ItemSelector selector = ArchivaItemSelector.builder().withNamespace("org.apache.maven").withProjectId("samplejar").withVersion("1.0").withArtifactVersion("1.0").withArtifactId("samplejar").withExtension("jar").includeRelatedArtifacts().build();
List<? extends Artifact> results = repoContent.getArtifacts(selector);
assertNotNull(results);
assertEquals(3, results.size());
Artifact artifact = results.stream().filter(a -> a.getFileName().equalsIgnoreCase("samplejar-1.0.jar")).findFirst().get();
assertNotNull(artifact);
assertEquals(BaseArtifactTypes.MAIN, artifact.getDataType());
artifact = results.stream().filter(a -> a.getFileName().equalsIgnoreCase("samplejar-1.0.jar.md5")).findFirst().get();
assertNotNull(artifact);
assertEquals(BaseArtifactTypes.RELATED, artifact.getDataType());
assertEquals("md5", artifact.getExtension());
artifact = results.stream().filter(a -> a.getFileName().equalsIgnoreCase("samplejar-1.0.jar.sha1")).findFirst().get();
assertNotNull(artifact);
assertEquals(BaseArtifactTypes.RELATED, artifact.getDataType());
assertEquals("sha1", artifact.getExtension());
}
use of org.apache.archiva.repository.content.ItemSelector in project archiva by apache.
the class AbstractRepositoryContentTest method assertLayoutCi.
private void assertLayoutCi(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);
assertItemSelector(testReference, groupId, artifactId, version, artifactVersion, classifier, type);
// And back again, using test Reference from previous step.
assertEquals("Artifact <" + expectedArtifact + "> to path:", path, toPath(testReference));
if (getManaged() != null) {
Namespace ns = null;
Project pr = null;
Version ver = null;
if (StringUtils.isNotEmpty(groupId)) {
ns = getManaged().getLayout(BaseRepositoryContentLayout.class).getNamespace(expectedArtifact);
assertNotNull(ns);
assertEquals(groupId, ns.getId());
}
if (StringUtils.isNotEmpty(artifactId)) {
pr = getManaged().getLayout(BaseRepositoryContentLayout.class).getProject(expectedArtifact);
assertNotNull(pr);
assertEquals(artifactId, pr.getId());
assertEquals(ns, pr.getNamespace());
}
if (StringUtils.isNotEmpty(version)) {
ver = getManaged().getLayout(BaseRepositoryContentLayout.class).getVersion(expectedArtifact);
assertNotNull(ver);
assertEquals(version, ver.getId());
assertEquals(pr, ver.getProject());
}
Artifact artifact = getManaged().getLayout(BaseRepositoryContentLayout.class).getArtifact(expectedArtifact);
assertNotNull(artifact);
assertEquals(artifactId, artifact.getId());
assertEquals(ver, artifact.getVersion());
}
}
use of org.apache.archiva.repository.content.ItemSelector in project archiva by apache.
the class AbstractRepositoryContentTest method testToPathOnNullItemSelector.
public void testToPathOnNullItemSelector() {
try {
ItemSelector selector = null;
toPath(selector);
fail("Should have failed due to null artifact reference.");
} catch (IllegalArgumentException e) {
/* expected path */
}
}
use of org.apache.archiva.repository.content.ItemSelector in project archiva by apache.
the class AbstractRepositoryContentTest method testToPathOnNullArtifactReference.
@Test
public void testToPathOnNullArtifactReference() {
try {
ItemSelector reference = null;
toPath(reference);
fail("Should have failed due to null artifact reference.");
} catch (IllegalArgumentException e) {
/* expected path */
}
}
use of org.apache.archiva.repository.content.ItemSelector in project archiva by apache.
the class ManagedDefaultRepositoryContent method newItemStream.
@Override
public Stream<? extends ContentItem> newItemStream(ItemSelector selector, boolean parallel) throws ContentAccessException, IllegalArgumentException {
final Predicate<StorageAsset> filter = getItemFileFilterFromSelector(selector);
StorageAsset startDir;
if (selector.getNamespace().contains("*")) {
startDir = getAsset("");
} else if (selector.hasProjectId() && selector.getProjectId().contains("*")) {
startDir = getAsset(selector.getNamespace());
} else if (selector.hasProjectId() && selector.hasVersion() && selector.getVersion().contains("*")) {
startDir = getAsset(selector.getNamespace(), selector.getProjectId());
} else if (selector.hasProjectId() && selector.hasVersion()) {
startDir = getAsset(selector.getNamespace(), selector.getProjectId(), selector.getVersion());
} else if (selector.hasProjectId()) {
startDir = getAsset(selector.getNamespace(), selector.getProjectId());
} else {
startDir = getAsset(selector.getNamespace());
if (!selector.recurse()) {
// We descend into 2 subdirectories (project and version)
return startDir.list().stream().flatMap(a -> getChildrenDF(a, 1)).map(this::getItemFromPath);
}
}
return StorageUtil.newAssetStream(startDir, parallel).filter(filter).map(this::getItemFromPath);
}
Aggregations