Search in sources :

Example 31 with ArtifactMetadata

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;
}
Also used : LongSerializer(me.prettyprint.cassandra.serializers.LongSerializer) OrderedRows(me.prettyprint.hector.api.beans.OrderedRows) ArrayList(java.util.ArrayList) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata)

Example 32 with ArtifactMetadata

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;
}
Also used : LayoutException(org.apache.archiva.repository.LayoutException) MavenArtifactFacet(org.apache.archiva.metadata.model.maven2.MavenArtifactFacet) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) ArtifactReference(org.apache.archiva.model.ArtifactReference)

Example 33 with ArtifactMetadata

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;
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) QueryResult(javax.jcr.query.QueryResult) Query(javax.jcr.query.Query) Node(javax.jcr.Node) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata)

Example 34 with ArtifactMetadata

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;
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) Query(javax.jcr.query.Query) Node(javax.jcr.Node) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) ValueFactory(javax.jcr.ValueFactory) QueryResult(javax.jcr.query.QueryResult) RowIterator(javax.jcr.query.RowIterator) Row(javax.jcr.query.Row) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata)

Example 35 with ArtifactMetadata

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);
}
Also used : Path(java.nio.file.Path) ManagedRepository(org.apache.archiva.repository.ManagedRepository) ManagedRepositoryAdmin(org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin) DefaultManagedRepositoryAdmin(org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin) RepositoryRegistry(org.apache.archiva.repository.RepositoryRegistry) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

ArtifactMetadata (org.apache.archiva.metadata.model.ArtifactMetadata)96 Test (org.junit.Test)53 ArrayList (java.util.ArrayList)23 Path (java.nio.file.Path)20 MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)17 Date (java.util.Date)15 HashSet (java.util.HashSet)11 MetadataFacet (org.apache.archiva.metadata.model.MetadataFacet)10 MavenArtifactFacet (org.apache.archiva.metadata.model.maven2.MavenArtifactFacet)9 HashMap (java.util.HashMap)8 MetadataRepository (org.apache.archiva.metadata.repository.MetadataRepository)8 MetadataResolutionException (org.apache.archiva.metadata.repository.MetadataResolutionException)7 RepositorySession (org.apache.archiva.metadata.repository.RepositorySession)7 ReadMetadataRequest (org.apache.archiva.metadata.repository.storage.ReadMetadataRequest)7 ArtifactCleanupFeature (org.apache.archiva.repository.features.ArtifactCleanupFeature)7 ArchivaRestServiceException (org.apache.archiva.rest.api.services.ArchivaRestServiceException)7 Node (javax.jcr.Node)6 ProjectVersionMetadata (org.apache.archiva.metadata.model.ProjectVersionMetadata)6 IOException (java.io.IOException)5 RepositoryException (javax.jcr.RepositoryException)5