use of org.apache.archiva.metadata.model.ArtifactMetadata in project archiva by apache.
the class CassandraMetadataRepository method getArtifactsByDateRange.
@Override
public List<ArtifactMetadata> getArtifactsByDateRange(final String repositoryId, final Date startTime, final Date endTime) throws MetadataRepositoryException {
LongSerializer ls = LongSerializer.get();
RangeSlicesQuery<String, String, Long> query = //
HFactory.createRangeSlicesQuery(keyspace, ss, ss, //
ls).setColumnFamily(//
cassandraArchivaManager.getArtifactMetadataFamilyName()).setColumnNames(//
ArtifactMetadataModel.COLUMNS);
if (startTime != null) {
query = query.addGteExpression(WHEN_GATHERED.toString(), startTime.getTime());
}
if (endTime != null) {
query = query.addLteExpression(WHEN_GATHERED.toString(), endTime.getTime());
}
QueryResult<OrderedRows<String, String, Long>> result = query.execute();
List<ArtifactMetadata> artifactMetadatas = new ArrayList<>(result.get().getCount());
for (Row<String, String, Long> row : result.get()) {
ColumnSlice<String, Long> columnSlice = row.getColumnSlice();
String repositoryName = getAsStringValue(columnSlice, REPOSITORY_NAME.toString());
if (StringUtils.equals(repositoryName, repositoryId)) {
artifactMetadatas.add(mapArtifactMetadataLongColumnSlice(columnSlice));
}
}
return artifactMetadatas;
}
use of org.apache.archiva.metadata.model.ArtifactMetadata in project archiva by apache.
the class DefaultPathParser method toArtifactReference.
/**
* {@inheritDoc}
*
* @see org.apache.archiva.repository.content.PathParser#toArtifactReference(String)
*/
@Override
public ArtifactReference toArtifactReference(String path) throws LayoutException {
if (StringUtils.isBlank(path)) {
throw new LayoutException("Unable to convert blank path.");
}
ArtifactMetadata metadata;
try {
metadata = pathTranslator.getArtifactForPath(null, path);
} catch (IllegalArgumentException e) {
throw new LayoutException(e.getMessage(), e);
}
ArtifactReference artifact = new ArtifactReference();
artifact.setGroupId(metadata.getNamespace());
artifact.setArtifactId(metadata.getProject());
artifact.setVersion(metadata.getVersion());
MavenArtifactFacet facet = (MavenArtifactFacet) metadata.getFacet(MavenArtifactFacet.FACET_ID);
if (facet != null) {
artifact.setClassifier(facet.getClassifier());
artifact.setType(facet.getType());
}
return artifact;
}
use of org.apache.archiva.metadata.model.ArtifactMetadata in project archiva by apache.
the class JcrMetadataRepository method getArtifacts.
@Override
public List<ArtifactMetadata> getArtifacts(String repositoryId) throws MetadataRepositoryException {
List<ArtifactMetadata> artifacts;
String q = getArtifactQuery(repositoryId);
try {
Query query = getJcrSession().getWorkspace().getQueryManager().createQuery(q, Query.JCR_SQL2);
QueryResult result = query.execute();
artifacts = new ArrayList<>();
for (Node n : JcrUtils.getNodes(result)) {
if (n.isNodeType(ARTIFACT_NODE_TYPE)) {
artifacts.add(getArtifactFromNode(repositoryId, n));
}
}
} catch (RepositoryException e) {
throw new MetadataRepositoryException(e.getMessage(), e);
}
return artifacts;
}
use of org.apache.archiva.metadata.model.ArtifactMetadata in project archiva by apache.
the class JcrMetadataRepository method runJcrQuery.
private List<ArtifactMetadata> runJcrQuery(String repositoryId, String q, Map<String, String> bindings) throws MetadataRepositoryException {
List<ArtifactMetadata> artifacts;
if (repositoryId != null) {
q += " AND ISDESCENDANTNODE(artifact,'/" + getRepositoryContentPath(repositoryId) + "')";
}
log.info("Running JCR Query: {}", q);
try {
Query query = getJcrSession().getWorkspace().getQueryManager().createQuery(q, Query.JCR_SQL2);
ValueFactory valueFactory = getJcrSession().getValueFactory();
for (Entry<String, String> entry : bindings.entrySet()) {
query.bindValue(entry.getKey(), valueFactory.createValue(entry.getValue()));
}
long start = Calendar.getInstance().getTimeInMillis();
QueryResult result = query.execute();
long end = Calendar.getInstance().getTimeInMillis();
log.info("JCR Query ran in {} milliseconds: {}", end - start, q);
artifacts = new ArrayList<>();
RowIterator rows = result.getRows();
while (rows.hasNext()) {
Row row = rows.nextRow();
Node node = row.getNode("artifact");
artifacts.add(getArtifactFromNode(repositoryId, node));
}
} catch (RepositoryException e) {
throw new MetadataRepositoryException(e.getMessage(), e);
}
log.info("Artifacts found {}", artifacts.size());
for (ArtifactMetadata meta : artifacts) {
log.info("Artifact: " + meta.getVersion() + " " + meta.getFacetList());
}
return artifacts;
}
use of org.apache.archiva.metadata.model.ArtifactMetadata in project archiva by apache.
the class CleanupReleasedSnapshotsRepositoryPurgeTest method testReleasedSnapshotsExistsInDifferentRepo.
@Test
public void testReleasedSnapshotsExistsInDifferentRepo() throws Exception {
RepositoryRegistry repositoryRegistry = applicationContext.getBean(RepositoryRegistry.class);
ManagedRepository managedRepository = repositoryRegistry.getManagedRepository(TEST_REPO_ID);
repositoryRegistry.removeRepository(TEST_REPO_ID);
repositoryRegistry.putRepository(getRepoConfiguration(TEST_REPO_ID, TEST_REPO_NAME));
repositoryRegistry.putRepository(getRepoConfiguration(RELEASES_TEST_REPO_ID, RELEASES_TEST_REPO_NAME));
String repoRoot = prepareTestRepos();
String projectNs = "org.apache.archiva";
String projectPath = projectNs.replaceAll("\\.", "/");
String projectName = "released-artifact-in-diff-repo";
String projectVersion = "1.0-SNAPSHOT";
String releaseVersion = "1.0";
String projectRoot = repoRoot + "/" + projectPath + "/" + projectName;
Path repo = getTestRepoRootPath();
Path vDir = repo.resolve(projectPath).resolve(projectName).resolve(projectVersion);
Path releaseDir = repo.getParent().resolve(RELEASES_TEST_REPO_ID).resolve(projectPath).resolve(projectName).resolve(releaseVersion);
Set<String> deletedVersions = new HashSet<>();
deletedVersions.add("1.0-SNAPSHOT");
// test listeners for the correct artifacts
listener.deleteArtifact(metadataRepository, getRepository().getId(), "org.apache.archiva", "released-artifact-in-diff-repo", "1.0-SNAPSHOT", "released-artifact-in-diff-repo-1.0-SNAPSHOT.jar");
listenerControl.replay();
// Provide the metadata list
List<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID, projectName, repo.getParent(), vDir);
when(metadataRepository.getArtifacts(TEST_REPO_ID, projectNs, projectName, projectVersion)).thenReturn(ml);
List<ArtifactMetadata> ml2 = getArtifactMetadataFromDir(RELEASES_TEST_REPO_ID, projectName, repo.getParent(), releaseDir);
when(metadataRepository.getArtifacts(RELEASES_TEST_REPO_ID, projectNs, projectName, releaseVersion)).thenReturn(ml2);
repoPurge.process(PATH_TO_RELEASED_SNAPSHOT_IN_DIFF_REPO);
listenerControl.verify();
// Verify the metadataRepository invocations
// Complete version removal for cleanup
verify(metadataRepository, times(1)).removeProjectVersion(eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion));
verify(metadataRepository, never()).removeProjectVersion(eq(RELEASES_TEST_REPO_ID), eq(projectNs), eq(projectName), eq(releaseVersion));
// check if the snapshot was removed
assertDeleted(projectRoot + "/1.0-SNAPSHOT");
assertDeleted(projectRoot + "/1.0-SNAPSHOT/released-artifact-in-diff-repo-1.0-SNAPSHOT.jar");
assertDeleted(projectRoot + "/1.0-SNAPSHOT/released-artifact-in-diff-repo-1.0-SNAPSHOT.jar.md5");
assertDeleted(projectRoot + "/1.0-SNAPSHOT/released-artifact-in-diff-repo-1.0-SNAPSHOT.jar.sha1");
assertDeleted(projectRoot + "/1.0-SNAPSHOT/released-artifact-in-diff-repo-1.0-SNAPSHOT.pom");
assertDeleted(projectRoot + "/1.0-SNAPSHOT/released-artifact-in-diff-repo-1.0-SNAPSHOT.pom.md5");
assertDeleted(projectRoot + "/1.0-SNAPSHOT/released-artifact-in-diff-repo-1.0-SNAPSHOT.pom.sha1");
String releasesProjectRoot = AbstractRepositoryPurgeTest.fixPath(Paths.get("target/test-" + getName() + "/releases-test-repo-one").toAbsolutePath().toString() + "/org/apache/archiva/released-artifact-in-diff-repo");
// check if the released version was not removed
assertExists(releasesProjectRoot + "/1.0");
assertExists(releasesProjectRoot + "/1.0/released-artifact-in-diff-repo-1.0.jar");
assertExists(releasesProjectRoot + "/1.0/released-artifact-in-diff-repo-1.0.jar.md5");
assertExists(releasesProjectRoot + "/1.0/released-artifact-in-diff-repo-1.0.jar.sha1");
assertExists(releasesProjectRoot + "/1.0/released-artifact-in-diff-repo-1.0.pom");
assertExists(releasesProjectRoot + "/1.0/released-artifact-in-diff-repo-1.0.pom.md5");
assertExists(releasesProjectRoot + "/1.0/released-artifact-in-diff-repo-1.0.pom.sha1");
// remove RELEASES_TEST_REPO_ID so this test will be more independant
applicationContext.getBean(ManagedRepositoryAdmin.class).deleteManagedRepository(RELEASES_TEST_REPO_ID, null, false);
}
Aggregations