use of org.apache.archiva.repository.content.Version in project archiva by apache.
the class ManagedDefaultRepositoryContentTest method testGetItemWithVersionSelector.
@Test
public void testGetItemWithVersionSelector() {
ItemSelector selector = ArchivaItemSelector.builder().withNamespace("org.apache.maven").withProjectId("samplejar").withVersion("2.0").build();
ContentItem item = repoContent.getItem(selector);
assertNotNull(item);
assertTrue(item instanceof Version);
}
use of org.apache.archiva.repository.content.Version in project archiva by apache.
the class ManagedDefaultRepositoryContentTest method testGetArtifactFromContentItem.
@Test
public void testGetArtifactFromContentItem() {
ItemSelector selector = ArchivaItemSelector.builder().withNamespace("org.apache.maven").build();
Namespace ns = repoContent.getNamespace(selector);
List<? extends Artifact> artifacts = repoContent.getArtifacts(ns);
assertNotNull(artifacts);
assertEquals(39, artifacts.size());
List<? extends Artifact> artifacts2 = repoContent.getArtifacts((ContentItem) ns);
assertArrayEquals(artifacts.toArray(), artifacts2.toArray());
selector = ArchivaItemSelector.builder().withNamespace("org.apache.maven.shared").withProjectId("maven-downloader").build();
Project project = repoContent.getProject(selector);
artifacts = repoContent.getArtifacts(project);
assertNotNull(artifacts);
assertEquals(27, artifacts.size());
artifacts2 = repoContent.getArtifacts((ContentItem) project);
assertArrayEquals(artifacts.toArray(), artifacts2.toArray());
selector = ArchivaItemSelector.builder().withNamespace("org.apache.maven.shared").withProjectId("maven-downloader").withVersion("1.1").build();
Version version = repoContent.getVersion(selector);
artifacts = repoContent.getArtifacts(version);
assertNotNull(artifacts);
assertEquals(12, artifacts.size());
artifacts2 = repoContent.getArtifacts((ContentItem) version);
assertArrayEquals(artifacts.toArray(), artifacts2.toArray());
}
use of org.apache.archiva.repository.content.Version 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.Version in project archiva by apache.
the class ManagedDefaultRepositoryContent method createArtifact.
public Artifact createArtifact(final StorageAsset artifactPath, final ItemSelector selector, final String classifier) {
Version version = getVersion(selector);
ArtifactOptBuilder builder = org.apache.archiva.repository.content.base.ArchivaArtifact.withAsset(artifactPath).withVersion(version).withId(selector.getArtifactId()).withArtifactVersion(mavenContentHelper.getArtifactVersion(artifactPath, selector)).withClassifier(classifier);
if (selector.hasType()) {
builder.withType(selector.getType());
}
return builder.build();
}
use of org.apache.archiva.repository.content.Version in project archiva by apache.
the class ManagedDefaultRepositoryContent method newArtifactStream.
/**
* Returns all related artifacts that match the given artifact. That means all artifacts that have
* the same filename plus an additional extension, e.g. ${fileName}.sha2
*
* @param item the artifact
* @return the stream of artifacts
* @throws ContentAccessException if access to the underlying storage failed
*/
public Stream<? extends Artifact> newArtifactStream(Artifact item) throws ContentAccessException {
final Version v = item.getVersion();
final String fileName = item.getFileName();
final Predicate<StorageAsset> filter = (StorageAsset a) -> a.getName().startsWith(fileName + ".");
return v.getAsset().list().stream().filter(filter).map(a -> {
try {
return getArtifactFromPath(a);
} catch (LayoutException e) {
log.error("Not a valid artifact path " + a.getPath(), e);
return null;
}
}).filter(Objects::nonNull);
}
Aggregations