Search in sources :

Example 6 with Artifact

use of org.apache.archiva.maven2.model.Artifact in project archiva by apache.

the class ArtifactBuilder method build.

public Artifact build() {
    ArtifactReference ref = new ArtifactReference();
    ref.setArtifactId(artifactMetadata.getProject());
    ref.setGroupId(artifactMetadata.getNamespace());
    ref.setVersion(artifactMetadata.getVersion());
    String type = null, classifier = null;
    MavenArtifactFacet facet = (MavenArtifactFacet) artifactMetadata.getFacet(MavenArtifactFacet.FACET_ID);
    if (facet != null) {
        type = facet.getType();
        classifier = facet.getClassifier();
    }
    ref.setClassifier(classifier);
    ref.setType(type);
    Path file = managedRepositoryContent.toFile(ref);
    String extension = getExtensionFromFile(file);
    Artifact artifact = new Artifact(ref.getGroupId(), ref.getArtifactId(), ref.getVersion());
    artifact.setRepositoryId(artifactMetadata.getRepositoryId());
    artifact.setClassifier(classifier);
    artifact.setPackaging(type);
    artifact.setType(type);
    artifact.setFileExtension(extension);
    artifact.setPath(managedRepositoryContent.toPath(ref));
    // TODO: find a reusable formatter for this
    double s = this.artifactMetadata.getSize();
    String symbol = "b";
    if (s > 1024) {
        symbol = "K";
        s /= 1024;
        if (s > 1024) {
            symbol = "M";
            s /= 1024;
            if (s > 1024) {
                symbol = "G";
                s /= 1024;
            }
        }
    }
    artifact.setContext(managedRepositoryContent.getId());
    DecimalFormat df = new DecimalFormat("#,###.##", new DecimalFormatSymbols(Locale.US));
    artifact.setSize(df.format(s) + " " + symbol);
    artifact.setId(ref.getArtifactId() + "-" + ref.getVersion() + "." + ref.getType());
    return artifact;
}
Also used : Path(java.nio.file.Path) DecimalFormatSymbols(java.text.DecimalFormatSymbols) DecimalFormat(java.text.DecimalFormat) MavenArtifactFacet(org.apache.archiva.metadata.model.maven2.MavenArtifactFacet) ArtifactReference(org.apache.archiva.model.ArtifactReference) Artifact(org.apache.archiva.maven2.model.Artifact)

Example 7 with Artifact

use of org.apache.archiva.maven2.model.Artifact in project archiva by apache.

the class RepositoriesServiceTest method deleteArtifact.

@Test
public void deleteArtifact() throws Exception {
    initSourceTargetRepo();
    BrowseService browseService = getBrowseService(authorizationHeader, false);
    List<Artifact> artifacts = browseService.getArtifactDownloadInfos("org.apache.karaf.features", "org.apache.karaf.features.core", "2.2.2", SOURCE_REPO_ID);
    log.info("artifacts: {}", artifacts);
    assertThat(artifacts).isNotNull().isNotEmpty().hasSize(2);
    VersionsList versionsList = browseService.getVersionsList("org.apache.karaf.features", "org.apache.karaf.features.core", SOURCE_REPO_ID);
    assertThat(versionsList.getVersions()).isNotNull().isNotEmpty().hasSize(2);
    log.info("artifacts.size: {}", artifacts.size());
    try {
        Path artifactFile = Paths.get("target/test-origin-repo/org/apache/karaf/features/org.apache.karaf.features.core/2.2.2/org.apache.karaf.features.core-2.2.2.jar");
        assertTrue("artifact not exists:" + artifactFile.toString(), Files.exists(artifactFile));
        Artifact artifact = new Artifact();
        artifact.setGroupId("org.apache.karaf.features");
        artifact.setArtifactId("org.apache.karaf.features.core");
        artifact.setVersion("2.2.2");
        artifact.setPackaging("jar");
        artifact.setContext(SOURCE_REPO_ID);
        RepositoriesService repositoriesService = getRepositoriesService(authorizationHeader);
        repositoriesService.deleteArtifact(artifact);
        assertFalse("artifact not deleted exists:" + artifactFile, Files.exists(artifactFile));
        artifacts = browseService.getArtifactDownloadInfos("org.apache.karaf.features", "org.apache.karaf.features.core", "2.2.2", SOURCE_REPO_ID);
        assertThat(artifacts).isNotNull().isEmpty();
        versionsList = browseService.getVersionsList("org.apache.karaf.features", "org.apache.karaf.features.core", SOURCE_REPO_ID);
        assertThat(versionsList.getVersions()).isNotNull().isNotEmpty().hasSize(1);
    } finally {
        cleanRepos();
    }
}
Also used : Path(java.nio.file.Path) RepositoriesService(org.apache.archiva.rest.api.services.RepositoriesService) ManagedRepositoriesService(org.apache.archiva.rest.api.services.ManagedRepositoriesService) BrowseService(org.apache.archiva.rest.api.services.BrowseService) Artifact(org.apache.archiva.maven2.model.Artifact) VersionsList(org.apache.archiva.rest.api.model.VersionsList) Test(org.junit.Test)

Example 8 with Artifact

use of org.apache.archiva.maven2.model.Artifact in project archiva by apache.

the class RepositoriesServiceTest method deleteArtifactVersion.

/**
 * delete a version of an artifact without packaging
 *
 * @throws Exception
 */
@Test
public void deleteArtifactVersion() throws Exception {
    initSourceTargetRepo();
    BrowseService browseService = getBrowseService(authorizationHeader, false);
    List<Artifact> artifacts = browseService.getArtifactDownloadInfos("org.apache.karaf.features", "org.apache.karaf.features.core", "2.2.2", SOURCE_REPO_ID);
    log.info("artifacts: {}", artifacts);
    assertThat(artifacts).isNotNull().isNotEmpty().hasSize(2);
    VersionsList versionsList = browseService.getVersionsList("org.apache.karaf.features", "org.apache.karaf.features.core", SOURCE_REPO_ID);
    assertThat(versionsList.getVersions()).isNotNull().isNotEmpty().hasSize(2);
    log.info("artifacts.size: {}", artifacts.size());
    try {
        Path artifactFile = Paths.get("target/test-origin-repo/org/apache/karaf/features/org.apache.karaf.features.core/2.2.2/org.apache.karaf.features.core-2.2.2.jar");
        assertTrue("artifact not exists:" + artifactFile, Files.exists(artifactFile));
        Artifact artifact = new Artifact();
        artifact.setGroupId("org.apache.karaf.features");
        artifact.setArtifactId("org.apache.karaf.features.core");
        artifact.setVersion("2.2.2");
        artifact.setContext(SOURCE_REPO_ID);
        RepositoriesService repositoriesService = getRepositoriesService(authorizationHeader);
        repositoriesService.deleteArtifact(artifact);
        assertFalse("artifact not deleted exists:" + artifactFile, Files.exists(artifactFile));
        artifacts = browseService.getArtifactDownloadInfos("org.apache.karaf.features", "org.apache.karaf.features.core", "2.2.2", SOURCE_REPO_ID);
        assertThat(artifacts).isNotNull().isEmpty();
        versionsList = browseService.getVersionsList("org.apache.karaf.features", "org.apache.karaf.features.core", SOURCE_REPO_ID);
        assertThat(versionsList.getVersions()).isNotNull().isNotEmpty().hasSize(1);
    } finally {
        cleanRepos();
    }
}
Also used : Path(java.nio.file.Path) RepositoriesService(org.apache.archiva.rest.api.services.RepositoriesService) ManagedRepositoriesService(org.apache.archiva.rest.api.services.ManagedRepositoriesService) BrowseService(org.apache.archiva.rest.api.services.BrowseService) Artifact(org.apache.archiva.maven2.model.Artifact) VersionsList(org.apache.archiva.rest.api.model.VersionsList) Test(org.junit.Test)

Example 9 with Artifact

use of org.apache.archiva.maven2.model.Artifact in project archiva by apache.

the class RepositoriesServiceTest method deleteSnapshot.

@Test
public void deleteSnapshot() throws Exception {
    Path targetRepo = initSnapshotRepo();
    try {
        RepositoriesService repositoriesService = getRepositoriesService(authorizationHeader);
        // repositoriesService.scanRepositoryDirectoriesNow( SNAPSHOT_REPO_ID );
        BrowseService browseService = getBrowseService(authorizationHeader, false);
        List<Artifact> artifacts = browseService.getArtifactDownloadInfos("org.apache.archiva.redback.components", "spring-quartz", "2.0-SNAPSHOT", SNAPSHOT_REPO_ID);
        log.info("artifacts: {}", artifacts);
        assertThat(artifacts).isNotNull().isNotEmpty().hasSize(10);
        Path artifactFile = targetRepo.resolve("org/apache/archiva/redback/components/spring-quartz/2.0-SNAPSHOT/spring-quartz-2.0-20120618.214127-1.jar");
        Path artifactFilemd5 = targetRepo.resolve("org/apache/archiva/redback/components/spring-quartz/2.0-SNAPSHOT/spring-quartz-2.0-20120618.214127-1.jar.md5");
        Path artifactFilepom = targetRepo.resolve("org/apache/archiva/redback/components/spring-quartz/2.0-SNAPSHOT/spring-quartz-2.0-20120618.214127-1.pom");
        assertTrue(Files.exists(artifactFile));
        assertTrue(Files.exists(artifactFilemd5));
        assertTrue(Files.exists(artifactFilepom));
        // we delete only one snapshot
        Artifact artifact = new Artifact("org.apache.archiva.redback.components", "spring-quartz", "2.0-20120618.214127-1");
        artifact.setPackaging("jar");
        artifact.setRepositoryId(SNAPSHOT_REPO_ID);
        artifact.setContext(SNAPSHOT_REPO_ID);
        repositoriesService.deleteArtifact(artifact);
        artifacts = browseService.getArtifactDownloadInfos("org.apache.archiva.redback.components", "spring-quartz", "2.0-SNAPSHOT", SNAPSHOT_REPO_ID);
        log.info("artifacts: {}", artifacts);
        assertThat(artifacts).isNotNull().isNotEmpty().hasSize(8);
        assertFalse(Files.exists(artifactFile));
        assertFalse(Files.exists(artifactFilemd5));
        assertFalse(Files.exists(artifactFilepom));
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw e;
    } finally {
        cleanSnapshotRepo();
    }
}
Also used : Path(java.nio.file.Path) RepositoriesService(org.apache.archiva.rest.api.services.RepositoriesService) ManagedRepositoriesService(org.apache.archiva.rest.api.services.ManagedRepositoriesService) BrowseService(org.apache.archiva.rest.api.services.BrowseService) Artifact(org.apache.archiva.maven2.model.Artifact) ForbiddenException(javax.ws.rs.ForbiddenException) BadRequestException(javax.ws.rs.BadRequestException) Test(org.junit.Test)

Example 10 with Artifact

use of org.apache.archiva.maven2.model.Artifact in project archiva by apache.

the class SearchServiceTest method quickSearchOnArtifactId.

@Test
public void quickSearchOnArtifactId() throws Exception {
    SearchService searchService = getSearchService(authorizationHeader);
    // START SNIPPET: quick-search
    List<Artifact> artifacts = searchService.quickSearch("commons-logging");
    // return all artifacts with groupId OR artifactId OR version OR packaging OR className
    // NOTE : only artifacts with classifier empty are returned
    // END SNIPPET: quick-search
    assertNotNull(artifacts);
    assertTrue(" not 6 results for commons-logging search but " + artifacts.size() + ":" + artifacts, artifacts.size() == 6);
    log.info("artifacts for commons-logging size {} search {}", artifacts.size(), artifacts);
}
Also used : SearchService(org.apache.archiva.rest.api.services.SearchService) Artifact(org.apache.archiva.maven2.model.Artifact) Test(org.junit.Test)

Aggregations

Artifact (org.apache.archiva.maven2.model.Artifact)37 Test (org.junit.Test)29 ArrayList (java.util.ArrayList)14 SearchService (org.apache.archiva.rest.api.services.SearchService)14 BrowseService (org.apache.archiva.rest.api.services.BrowseService)11 Path (java.nio.file.Path)10 SearchRequest (org.apache.archiva.rest.api.model.SearchRequest)9 Artifact (se.light.assembly64.model.Artifact)9 List (java.util.List)8 ManagedRepositoriesService (org.apache.archiva.rest.api.services.ManagedRepositoriesService)8 RepositoriesService (org.apache.archiva.rest.api.services.RepositoriesService)8 File (java.io.File)7 IOException (java.io.IOException)7 Logger (org.slf4j.Logger)7 LoggerFactory (org.slf4j.LoggerFactory)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 ArchivaRestServiceException (org.apache.archiva.rest.api.services.ArchivaRestServiceException)6 Arrays (java.util.Arrays)5 HashSet (java.util.HashSet)5