Search in sources :

Example 26 with Artifact

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

the class MergeRepositoriesServiceTest method getMergeConflictedArtifacts.

@Test
public void getMergeConflictedArtifacts() throws Exception {
    MergeRepositoriesService service = getMergeRepositoriesService(authorizationHeader);
    waitForScanToComplete(TEST_REPOSITORY);
    waitForScanToComplete(TEST_REPOSITORY_STAGE);
    int checks = maxChecks;
    Throwable ex = null;
    while (checks-- > 0) {
        try {
            log.info("Test Try " + checks);
            List<Artifact> artifactMetadatas = service.getMergeConflictedArtifacts(TEST_REPOSITORY_STAGE, TEST_REPOSITORY);
            log.info("conflicts: {}", artifactMetadatas);
            assertThat(artifactMetadatas).isNotNull().isNotEmpty().hasSize(8);
            return;
        } catch (Throwable e) {
            ex = e;
        }
        Thread.currentThread().sleep(checkWaitMs);
    }
    if (ex != null && ex instanceof AssertionError) {
        throw (AssertionError) ex;
    } else {
        throw new Exception(ex);
    }
}
Also used : MergeRepositoriesService(org.apache.archiva.rest.api.services.MergeRepositoriesService) Artifact(org.apache.archiva.maven.model.Artifact) Test(org.junit.Test)

Example 27 with Artifact

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

the class DefaultRepositoriesService method removeProjectVersion.

@Override
public ActionStatus removeProjectVersion(String repositoryId, String namespace, String projectId, String version) throws ArchivaRestServiceException {
    // if not a generic we can use the standard way to delete artifact
    if (!VersionUtil.isGenericSnapshot(version)) {
        Artifact artifact = new Artifact(namespace, projectId, version);
        artifact.setRepositoryId(repositoryId);
        artifact.setContext(repositoryId);
        return deleteArtifact(artifact);
    }
    if (StringUtils.isEmpty(repositoryId)) {
        throw new ArchivaRestServiceException("repositoryId cannot be null", 400, null);
    }
    if (!getPermissionStatus(repositoryId).isAuthorizedToDeleteArtifacts()) {
        throw new ArchivaRestServiceException("not authorized to delete artifacts", 403, null);
    }
    if (StringUtils.isEmpty(namespace)) {
        throw new ArchivaRestServiceException("groupId cannot be null", 400, null);
    }
    if (StringUtils.isEmpty(projectId)) {
        throw new ArchivaRestServiceException("artifactId cannot be null", 400, null);
    }
    if (StringUtils.isEmpty(version)) {
        throw new ArchivaRestServiceException("version cannot be null", 400, null);
    }
    RepositorySession repositorySession = null;
    try {
        repositorySession = repositorySessionFactory.createSession();
    } catch (MetadataRepositoryException e) {
        e.printStackTrace();
    }
    try {
        ManagedRepositoryContent repository = getManagedRepositoryContent(repositoryId);
        BaseRepositoryContentLayout layout = repository.getLayout(BaseRepositoryContentLayout.class);
        ArchivaItemSelector selector = ArchivaItemSelector.builder().withNamespace(namespace).withProjectId(projectId).withVersion(version).build();
        Version versionItem = layout.getVersion(selector);
        if (versionItem != null && versionItem.exists()) {
            repository.deleteItem(versionItem);
        }
        MetadataRepository metadataRepository = repositorySession.getRepository();
        Collection<ArtifactMetadata> artifacts = metadataRepository.getArtifacts(repositorySession, repositoryId, namespace, projectId, version);
        for (ArtifactMetadata artifactMetadata : artifacts) {
            metadataRepository.removeTimestampedArtifact(repositorySession, artifactMetadata, version);
        }
        metadataRepository.removeProjectVersion(repositorySession, repositoryId, namespace, projectId, version);
    } catch (MetadataRepositoryException | MetadataResolutionException | RepositoryException | ItemNotFoundException | LayoutException e) {
        throw new ArchivaRestServiceException("Repository exception: " + e.getMessage(), 500, e);
    } finally {
        try {
            repositorySession.save();
        } catch (MetadataSessionException e) {
            log.error("Session save failed {}", e.getMessage());
        }
        repositorySession.close();
    }
    return ActionStatus.SUCCESS;
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) ArchivaItemSelector(org.apache.archiva.repository.content.base.ArchivaItemSelector) RepositoryException(org.apache.archiva.repository.RepositoryException) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession) MetadataSessionException(org.apache.archiva.metadata.repository.MetadataSessionException) Artifact(org.apache.archiva.maven.model.Artifact) MetadataResolutionException(org.apache.archiva.metadata.repository.MetadataResolutionException) MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) Version(org.apache.archiva.repository.content.Version) LayoutException(org.apache.archiva.repository.content.LayoutException) BaseRepositoryContentLayout(org.apache.archiva.repository.content.BaseRepositoryContentLayout) ArchivaRestServiceException(org.apache.archiva.rest.api.services.ArchivaRestServiceException) ManagedRepositoryContent(org.apache.archiva.repository.ManagedRepositoryContent) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) ItemNotFoundException(org.apache.archiva.repository.content.ItemNotFoundException)

Example 28 with Artifact

use of org.apache.archiva.maven.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.maven.model.Artifact) Test(org.junit.Test)

Example 29 with Artifact

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

the class RepositoriesServiceTest method deleteWithRepoNull.

@Test(expected = BadRequestException.class)
public void deleteWithRepoNull() throws Exception {
    try {
        RepositoriesService repositoriesService = getRepositoriesService(authorizationHeader);
        Artifact artifact = new Artifact();
        artifact.setGroupId("commons-logging");
        artifact.setArtifactId("commons-logging");
        artifact.setVersion("1.0.1");
        artifact.setPackaging("jar");
        repositoriesService.deleteArtifact(artifact);
    } catch (BadRequestException e) {
        assertEquals("not http " + Response.Status.BAD_REQUEST.getStatusCode() + " status", Response.Status.BAD_REQUEST.getStatusCode(), e.getResponse().getStatus());
        throw e;
    }
}
Also used : RepositoriesService(org.apache.archiva.rest.api.services.RepositoriesService) ManagedRepositoriesService(org.apache.archiva.rest.api.services.ManagedRepositoriesService) BadRequestException(javax.ws.rs.BadRequestException) Artifact(org.apache.archiva.maven.model.Artifact) Test(org.junit.Test)

Example 30 with Artifact

use of org.apache.archiva.maven.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 = getAppserverBase().resolve("data/repositories/test-origin-repo/commons-logging/commons-logging/1.0.1/commons-logging-1.0.1-javadoc.jar");
        Path artifactFilemd5 = getAppserverBase().resolve("data/repositories/test-origin-repo/commons-logging/commons-logging/1.0.1/commons-logging-1.0.1-javadoc.jar.md5");
        Path artifactFilesha1 = getAppserverBase().resolve("data/repositories/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.setType("javadoc");
        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.maven.model.Artifact) VersionsList(org.apache.archiva.rest.api.model.VersionsList) Test(org.junit.Test)

Aggregations

Artifact (org.apache.archiva.maven.model.Artifact)37 Test (org.junit.Test)29 SearchService (org.apache.archiva.rest.api.services.SearchService)14 BrowseService (org.apache.archiva.rest.api.services.BrowseService)11 SearchRequest (org.apache.archiva.rest.api.model.SearchRequest)9 ManagedRepositoriesService (org.apache.archiva.rest.api.services.ManagedRepositoriesService)8 RepositoriesService (org.apache.archiva.rest.api.services.RepositoriesService)8 ArchivaRestServiceException (org.apache.archiva.rest.api.services.ArchivaRestServiceException)7 Path (java.nio.file.Path)6 ArrayList (java.util.ArrayList)4 ArtifactMetadata (org.apache.archiva.metadata.model.ArtifactMetadata)4 MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)3 VersionsList (org.apache.archiva.rest.api.model.VersionsList)3 BadRequestException (javax.ws.rs.BadRequestException)2 ForbiddenException (javax.ws.rs.ForbiddenException)2 ManagedRepository (org.apache.archiva.admin.model.beans.ManagedRepository)2 ProxyConnector (org.apache.archiva.admin.model.beans.ProxyConnector)2 RemoteRepository (org.apache.archiva.admin.model.beans.RemoteRepository)2 RepositoryGroup (org.apache.archiva.admin.model.beans.RepositoryGroup)2 MetadataRepository (org.apache.archiva.metadata.repository.MetadataRepository)2