Search in sources :

Example 26 with Artifact

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

the class BrowseServiceTest method getArtifactsByProjectVersionMetadata.

@Test
public void getArtifactsByProjectVersionMetadata() throws Exception {
    // START SNIPPET: get-artifacts-by-project-version-metadata
    BrowseService browseService = getBrowseService(authorizationHeader, true);
    browseService.addMetadata("commons-cli", "commons-cli", "1.0", "wine", "bordeaux", TEST_REPO_ID);
    List<Artifact> artifactDownloadInfos = browseService.getArtifactsByProjectVersionMetadata("wine", "bordeaux", TEST_REPO_ID);
    assertThat(artifactDownloadInfos).isNotNull().isNotEmpty().hasSize(3);
// END SNIPPET: get-artifacts-by-project-version-metadata
}
Also used : BrowseService(org.apache.archiva.rest.api.services.BrowseService) Artifact(org.apache.archiva.maven2.model.Artifact) Test(org.junit.Test)

Example 27 with Artifact

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

the class BrowseServiceTest method getArtifactsByMetadata.

@Test
public void getArtifactsByMetadata() throws Exception {
    // START SNIPPET: get-artifacts-by-metadata
    BrowseService browseService = getBrowseService(authorizationHeader, true);
    List<Artifact> artifactDownloadInfos = browseService.getArtifactsByMetadata("type", "pom", TEST_REPO_ID);
    assertThat(artifactDownloadInfos).isNotNull().isNotEmpty().hasSize(11);
// END SNIPPET: get-artifacts-by-metadata
}
Also used : BrowseService(org.apache.archiva.rest.api.services.BrowseService) Artifact(org.apache.archiva.maven2.model.Artifact) Test(org.junit.Test)

Example 28 with Artifact

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

the class BrowseServiceTest method getArtifactsByProjectVersionMetadataWithNoRepository.

@Test
public void getArtifactsByProjectVersionMetadataWithNoRepository() throws Exception {
    BrowseService browseService = getBrowseService(authorizationHeader, true);
    browseService.addMetadata("commons-cli", "commons-cli", "1.0", "wine", "bordeaux", TEST_REPO_ID);
    List<Artifact> artifactDownloadInfos = browseService.getArtifactsByProjectVersionMetadata("wine", "bordeaux", null);
    assertThat(artifactDownloadInfos).isNotNull().isNotEmpty().hasSize(3);
}
Also used : BrowseService(org.apache.archiva.rest.api.services.BrowseService) Artifact(org.apache.archiva.maven2.model.Artifact) Test(org.junit.Test)

Example 29 with Artifact

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

the class BrowseServiceTest method getArtifactDownloadInfos.

@Test
public void getArtifactDownloadInfos() throws Exception {
    BrowseService browseService = getBrowseService(authorizationHeader, true);
    List<Artifact> artifactDownloadInfos = browseService.getArtifactDownloadInfos("commons-logging", "commons-logging", "1.1", TEST_REPO_ID);
    log.info("artifactDownloadInfos {}", artifactDownloadInfos);
    assertThat(artifactDownloadInfos).isNotNull().isNotEmpty().hasSize(3);
}
Also used : BrowseService(org.apache.archiva.rest.api.services.BrowseService) Artifact(org.apache.archiva.maven2.model.Artifact) Test(org.junit.Test)

Example 30 with Artifact

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

the class DefaultBrowseService method getDependees.

@Override
public List<Artifact> getDependees(String groupId, String artifactId, String version, String repositoryId) throws ArchivaRestServiceException {
    List<ProjectVersionReference> references = new ArrayList<>();
    // TODO: what if we get duplicates across repositories?
    RepositorySession repositorySession = repositorySessionFactory.createSession();
    try {
        MetadataResolver metadataResolver = repositorySession.getResolver();
        for (String repoId : getObservableRepos()) {
            // TODO: what about if we want to see this irrespective of version?
            references.addAll(metadataResolver.resolveProjectReferences(repositorySession, repoId, groupId, artifactId, version));
        }
    } catch (MetadataResolutionException e) {
        throw new ArchivaRestServiceException(e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e);
    } finally {
        repositorySession.close();
    }
    List<Artifact> artifacts = new ArrayList<>(references.size());
    for (ProjectVersionReference projectVersionReference : references) {
        artifacts.add(new Artifact(projectVersionReference.getNamespace(), projectVersionReference.getProjectId(), projectVersionReference.getProjectVersion()));
    }
    return artifacts;
}
Also used : ArchivaRestServiceException(org.apache.archiva.rest.api.services.ArchivaRestServiceException) ArrayList(java.util.ArrayList) MetadataResolver(org.apache.archiva.metadata.repository.MetadataResolver) ProjectVersionReference(org.apache.archiva.metadata.model.ProjectVersionReference) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession) MetadataResolutionException(org.apache.archiva.metadata.repository.MetadataResolutionException) Artifact(org.apache.archiva.maven2.model.Artifact) ArchivaArtifact(org.apache.archiva.model.ArchivaArtifact)

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