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);
}
}
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;
}
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;
}
}
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;
}
}
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();
}
}
Aggregations