Search in sources :

Example 1 with Namespace

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);
        }
    }
}
Also used : ArchivaProject(org.apache.archiva.repository.content.base.ArchivaProject) Project(org.apache.archiva.repository.content.Project) LayoutException(org.apache.archiva.repository.content.LayoutException) Version(org.apache.archiva.repository.content.Version) ArchivaVersion(org.apache.archiva.repository.content.base.ArchivaVersion) Artifact(org.apache.archiva.repository.content.Artifact) ArchivaNamespace(org.apache.archiva.repository.content.base.ArchivaNamespace) Namespace(org.apache.archiva.repository.content.Namespace)

Example 2 with Namespace

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());
}
Also used : StorageAsset(org.apache.archiva.repository.storage.StorageAsset) Namespace(org.apache.archiva.repository.content.Namespace) Test(org.junit.Test)

Example 3 with Namespace

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")));
}
Also used : Path(java.nio.file.Path) ArchivaItemSelector(org.apache.archiva.repository.content.base.ArchivaItemSelector) MavenManagedRepository(org.apache.archiva.maven.repository.MavenManagedRepository) ManagedRepository(org.apache.archiva.repository.ManagedRepository) EditableManagedRepository(org.apache.archiva.repository.EditableManagedRepository) ManagedRepositoryContent(org.apache.archiva.repository.ManagedRepositoryContent) ContentItem(org.apache.archiva.repository.content.ContentItem) ArchivaContentItem(org.apache.archiva.repository.content.base.ArchivaContentItem) Namespace(org.apache.archiva.repository.content.Namespace) Test(org.junit.Test)

Example 4 with Namespace

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());
}
Also used : Project(org.apache.archiva.repository.content.Project) ArchivaItemSelector(org.apache.archiva.repository.content.base.ArchivaItemSelector) ItemSelector(org.apache.archiva.repository.content.ItemSelector) Version(org.apache.archiva.repository.content.Version) Namespace(org.apache.archiva.repository.content.Namespace) ContentItem(org.apache.archiva.repository.content.ContentItem) ArchivaContentItem(org.apache.archiva.repository.content.base.ArchivaContentItem) Test(org.junit.Test)

Example 5 with Namespace

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);
}
Also used : ArchivaItemSelector(org.apache.archiva.repository.content.base.ArchivaItemSelector) ItemSelector(org.apache.archiva.repository.content.ItemSelector) ContentItem(org.apache.archiva.repository.content.ContentItem) ArchivaContentItem(org.apache.archiva.repository.content.base.ArchivaContentItem) Namespace(org.apache.archiva.repository.content.Namespace) Test(org.junit.Test)

Aggregations

Namespace (org.apache.archiva.repository.content.Namespace)8 ArchivaItemSelector (org.apache.archiva.repository.content.base.ArchivaItemSelector)6 Test (org.junit.Test)6 ContentItem (org.apache.archiva.repository.content.ContentItem)4 ItemSelector (org.apache.archiva.repository.content.ItemSelector)4 Project (org.apache.archiva.repository.content.Project)4 Version (org.apache.archiva.repository.content.Version)4 ArchivaContentItem (org.apache.archiva.repository.content.base.ArchivaContentItem)4 Artifact (org.apache.archiva.repository.content.Artifact)3 Path (java.nio.file.Path)2 MavenManagedRepository (org.apache.archiva.maven.repository.MavenManagedRepository)2 EditableManagedRepository (org.apache.archiva.repository.EditableManagedRepository)2 ManagedRepository (org.apache.archiva.repository.ManagedRepository)2 ManagedRepositoryContent (org.apache.archiva.repository.ManagedRepositoryContent)2 BaseRepositoryContentLayout (org.apache.archiva.repository.content.BaseRepositoryContentLayout)1 ItemNotFoundException (org.apache.archiva.repository.content.ItemNotFoundException)1 LayoutException (org.apache.archiva.repository.content.LayoutException)1 ArchivaNamespace (org.apache.archiva.repository.content.base.ArchivaNamespace)1 ArchivaProject (org.apache.archiva.repository.content.base.ArchivaProject)1 ArchivaVersion (org.apache.archiva.repository.content.base.ArchivaVersion)1