Search in sources :

Example 31 with Artifact

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

the class DefaultBrowseService method getArtifactDownloadInfos.

@Override
public List<Artifact> getArtifactDownloadInfos(String groupId, String artifactId, String version, String repositoryId) throws ArchivaRestServiceException {
    List<String> selectedRepos = getSelectedRepos(repositoryId);
    List<Artifact> artifactDownloadInfos = new ArrayList<>();
    try (RepositorySession session = repositorySessionFactory.createSession()) {
        MetadataResolver metadataResolver = session.getResolver();
        for (String repoId : selectedRepos) {
            List<ArtifactMetadata> artifacts = new ArrayList<>(metadataResolver.resolveArtifacts(session, repoId, groupId, artifactId, version));
            Collections.sort(artifacts, ArtifactMetadataVersionComparator.INSTANCE);
            if (artifacts != null && !artifacts.isEmpty()) {
                return buildArtifacts(artifacts, repoId);
            }
        }
    } catch (MetadataResolutionException e) {
        log.error(e.getMessage(), e);
        throw new ArchivaRestServiceException(e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e);
    }
    return artifactDownloadInfos;
}
Also used : ArchivaRestServiceException(org.apache.archiva.rest.api.services.ArchivaRestServiceException) ArrayList(java.util.ArrayList) MetadataResolver(org.apache.archiva.metadata.repository.MetadataResolver) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) Artifact(org.apache.archiva.maven2.model.Artifact) ArchivaArtifact(org.apache.archiva.model.ArchivaArtifact) MetadataResolutionException(org.apache.archiva.metadata.repository.MetadataResolutionException)

Example 32 with Artifact

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

the class BrowseServiceTest method getArtifactsByProperty.

@Test
public void getArtifactsByProperty() throws Exception {
    // START SNIPPET: get-artifacts-by-property
    BrowseService browseService = getBrowseService(authorizationHeader, true);
    List<Artifact> artifactDownloadInfos = browseService.getArtifactsByProperty("org.name", "The Apache Software Foundation", TEST_REPO_ID);
    assertThat(artifactDownloadInfos).isNotNull().isNotEmpty().hasSize(7);
// END SNIPPET: get-artifacts-by-property
}
Also used : BrowseService(org.apache.archiva.rest.api.services.BrowseService) Artifact(org.apache.archiva.maven2.model.Artifact) Test(org.junit.Test)

Example 33 with Artifact

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

the class MergeRepositoriesServiceTest method getMergeConflictedArtifacts.

@Test
public void getMergeConflictedArtifacts() throws Exception {
    MergeRepositoriesService service = getMergeRepositoriesService(authorizationHeader);
    List<Artifact> artifactMetadatas = service.getMergeConflictedArtifacts(TEST_REPOSITORY + "-stage", TEST_REPOSITORY);
    log.info("conflicts: {}", artifactMetadatas);
    assertThat(artifactMetadatas).isNotNull().isNotEmpty().hasSize(8);
}
Also used : MergeRepositoriesService(org.apache.archiva.rest.api.services.MergeRepositoriesService) Artifact(org.apache.archiva.maven2.model.Artifact) Test(org.junit.Test)

Example 34 with Artifact

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

the class RepositoriesServiceTest method deleteArtifactKarmaFailed.

@Test(expected = ForbiddenException.class)
public void deleteArtifactKarmaFailed() throws Exception {
    try {
        Artifact artifact = new Artifact();
        artifact.setGroupId("commons-logging");
        artifact.setArtifactId("commons-logging");
        artifact.setVersion("1.0.1");
        artifact.setPackaging("jar");
        artifact.setContext(SOURCE_REPO_ID);
        RepositoriesService repositoriesService = getRepositoriesService(null);
        repositoriesService.deleteArtifact(artifact);
    } catch (ForbiddenException e) {
        assertEquals(403, e.getResponse().getStatus());
        throw e;
    }
}
Also used : ForbiddenException(javax.ws.rs.ForbiddenException) RepositoriesService(org.apache.archiva.rest.api.services.RepositoriesService) ManagedRepositoriesService(org.apache.archiva.rest.api.services.ManagedRepositoriesService) Artifact(org.apache.archiva.maven2.model.Artifact) Test(org.junit.Test)

Example 35 with Artifact

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

the class RepositoriesServiceTest method deleteArtifactWithClassifier.

@Test
public void deleteArtifactWithClassifier() throws Exception {
    initSourceTargetRepo();
    BrowseService browseService = getBrowseService(authorizationHeader, false);
    List<Artifact> artifacts = browseService.getArtifactDownloadInfos("commons-logging", "commons-logging", "1.0.1", SOURCE_REPO_ID);
    assertThat(artifacts).isNotNull().isNotEmpty().hasSize(3);
    VersionsList versionsList = browseService.getVersionsList("commons-logging", "commons-logging", SOURCE_REPO_ID);
    assertThat(versionsList.getVersions()).isNotNull().isNotEmpty().hasSize(6);
    log.info("artifacts.size: {}", artifacts.size());
    try {
        Path artifactFile = Paths.get("target/test-origin-repo/commons-logging/commons-logging/1.0.1/commons-logging-1.0.1-javadoc.jar");
        Path artifactFilemd5 = Paths.get("target/test-origin-repo/commons-logging/commons-logging/1.0.1/commons-logging-1.0.1-javadoc.jar.md5");
        Path artifactFilesha1 = Paths.get("target/test-origin-repo/commons-logging/commons-logging/1.0.1/commons-logging-1.0.1-javadoc.jar.sha1");
        assertTrue("artifact not exists:" + artifactFile, Files.exists(artifactFile));
        assertTrue("md5 not exists:" + artifactFilemd5, Files.exists(artifactFilemd5));
        assertTrue("sha1 not exists:" + artifactFilesha1, Files.exists(artifactFilesha1));
        Artifact artifact = new Artifact();
        artifact.setGroupId("commons-logging");
        artifact.setArtifactId("commons-logging");
        artifact.setVersion("1.0.1");
        artifact.setClassifier("javadoc");
        artifact.setPackaging("jar");
        artifact.setContext(SOURCE_REPO_ID);
        RepositoriesService repositoriesService = getRepositoriesService(authorizationHeader);
        repositoriesService.deleteArtifact(artifact);
        assertFalse("artifact not deleted exists:" + artifactFile, Files.exists(artifactFile));
        assertFalse("md5 still exists:" + artifactFilemd5, Files.exists(artifactFilemd5));
        assertFalse("sha1 still exists:" + artifactFilesha1, Files.exists(artifactFilesha1));
        artifacts = browseService.getArtifactDownloadInfos("commons-logging", "commons-logging", "1.0.1", SOURCE_REPO_ID);
        log.info("artifact: {}", artifacts);
        assertThat(artifacts).isNotNull().isNotEmpty().hasSize(2);
        versionsList = browseService.getVersionsList("commons-logging", "commons-logging", SOURCE_REPO_ID);
        log.info("versionsList: {}", versionsList);
        assertThat(versionsList.getVersions()).isNotNull().isNotEmpty().hasSize(6);
    } 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)

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