use of org.apache.archiva.repository.content.Namespace in project archiva by apache.
the class ManagedDefaultRepositoryContent method applyCharacteristic.
@Override
public <T extends ContentItem> T applyCharacteristic(Class<T> clazz, ContentItem item) throws LayoutException {
if (item.getAsset().isLeaf()) {
if (clazz.isAssignableFrom(Artifact.class)) {
Artifact artifact = getArtifactFromPath(item.getAsset());
item.setCharacteristic(Artifact.class, artifact);
return (T) artifact;
} else {
throw new LayoutException("Could not adapt file to clazz " + clazz);
}
} else {
if (clazz.isAssignableFrom(Version.class)) {
Version version = getVersionFromPath(item.getAsset());
item.setCharacteristic(Version.class, version);
return (T) version;
} else if (clazz.isAssignableFrom(Project.class)) {
Project project = getProjectFromPath(item.getAsset());
item.setCharacteristic(Project.class, project);
return (T) project;
} else if (clazz.isAssignableFrom(Namespace.class)) {
Namespace ns = getNamespaceFromPath(item.getAsset());
item.setCharacteristic(Namespace.class, ns);
return (T) ns;
} else {
throw new LayoutException("Cannot adapt directory to clazz " + clazz);
}
}
}
use of org.apache.archiva.repository.content.Namespace in project archiva by apache.
the class ManagedDefaultRepositoryContentTest method testGetNamespaceFromPath.
@Test
public void testGetNamespaceFromPath() throws LayoutException {
StorageAsset path = repoContent.getRepository().getAsset("/org/apache/axis2");
Namespace ns = repoContent.getNamespaceFromPath(path);
assertNotNull(ns);
assertEquals("org.apache.axis2", ns.getId());
}
use of org.apache.archiva.repository.content.Namespace in project archiva by apache.
the class ManagedDefaultRepositoryContentTest method deleteNamespaceItem.
@Test
public void deleteNamespaceItem() throws IOException, URISyntaxException, ItemNotFoundException {
ManagedRepository repo = createManagedRepoWithContent("delete-repository");
ManagedRepositoryContent myRepoContent = repo.getContent();
Path repoRoot = repo.getRoot().getFilePath();
assertTrue(Files.exists(repoRoot.resolve("org/apache/maven")));
ArchivaItemSelector selector = ArchivaItemSelector.builder().withNamespace("org.apache.maven").build();
ContentItem item = myRepoContent.getItem(selector);
assertTrue(item instanceof Namespace);
myRepoContent.deleteItem(item);
assertFalse(Files.exists(repoRoot.resolve("org/apache/maven")));
assertTrue(Files.exists(repoRoot.resolve("org/apache")));
// Sub namespaces are deleted too
assertTrue(Files.exists(repoRoot.resolve("org/apache/test/samplejar")));
assertTrue(Files.exists(repoRoot.resolve("org/apache/test/sub/samplejar")));
selector = ArchivaItemSelector.builder().withNamespace("org.apache.test").build();
item = myRepoContent.getItem(selector);
assertTrue(item instanceof Namespace);
myRepoContent.deleteItem(item);
assertFalse(Files.exists(repoRoot.resolve("org/apache/test/samplejar")));
assertFalse(Files.exists(repoRoot.resolve("org/apache/test/sub/samplejar")));
}
use of org.apache.archiva.repository.content.Namespace 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.Namespace in project archiva by apache.
the class ManagedDefaultRepositoryContentTest method testGetItemWithNamespaceSelector.
@Test
public void testGetItemWithNamespaceSelector() {
ItemSelector selector = ArchivaItemSelector.builder().withNamespace("org.apache.maven").build();
ContentItem item = repoContent.getItem(selector);
assertNotNull(item);
assertTrue(item instanceof Namespace);
}
Aggregations