Search in sources :

Example 61 with ArtifactMetadata

use of org.apache.archiva.metadata.model.ArtifactMetadata in project archiva by apache.

the class NewArtifactsRssFeedProcessorTest method createArtifact.

private ArtifactMetadata createArtifact(String artifactId, String version, Date whenGathered) {
    ArtifactMetadata artifact = new ArtifactMetadata();
    artifact.setNamespace("org.apache.archiva");
    artifact.setId(artifactId + "-" + version + ".jar");
    artifact.setRepositoryId(TEST_REPO);
    artifact.setWhenGathered(whenGathered);
    artifact.setProject(artifactId);
    artifact.setProjectVersion(version);
    artifact.setVersion(version);
    return artifact;
}
Also used : ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata)

Example 62 with ArtifactMetadata

use of org.apache.archiva.metadata.model.ArtifactMetadata in project archiva by apache.

the class DefaultMergeRepositoriesService method mergeWithOutSnapshots.

private void mergeWithOutSnapshots(MetadataRepository metadataRepository, List<ArtifactMetadata> sourceArtifacts, String sourceRepoId, String repoid) throws RepositoryMergerException {
    List<ArtifactMetadata> artifactsWithOutSnapshots = new ArrayList<>();
    for (ArtifactMetadata metadata : sourceArtifacts) {
        if (VersionUtil.isSnapshot(metadata.getProjectVersion())) // if ( metadata.getProjectVersion().contains( VersionUtil.SNAPSHOT ) )
        {
            artifactsWithOutSnapshots.add(metadata);
        } else {
            triggerAuditEvent(repoid, metadata.getId(), AuditEvent.MERGING_REPOSITORIES);
        }
    }
    sourceArtifacts.removeAll(artifactsWithOutSnapshots);
    Filter<ArtifactMetadata> artifactListWithOutSnapShots = new IncludesFilter<ArtifactMetadata>(sourceArtifacts);
    repositoryMerger.merge(metadataRepository, sourceRepoId, repoid, artifactListWithOutSnapShots);
}
Also used : IncludesFilter(org.apache.archiva.metadata.repository.filter.IncludesFilter) ArrayList(java.util.ArrayList) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata)

Example 63 with ArtifactMetadata

use of org.apache.archiva.metadata.model.ArtifactMetadata in project archiva by apache.

the class Maven2RepositoryPathTranslator method getArtifactFromId.

@Override
public ArtifactMetadata getArtifactFromId(String repoId, String namespace, String projectId, String projectVersion, String id) {
    if (!id.startsWith(projectId + "-")) {
        throw new IllegalArgumentException("Not a valid artifact path in a Maven 2 repository, filename '" + id + "' doesn't start with artifact ID '" + projectId + "'");
    }
    MavenArtifactFacet facet = new MavenArtifactFacet();
    int index = projectId.length() + 1;
    String version;
    String idSubStrFromVersion = id.substring(index);
    if (idSubStrFromVersion.startsWith(projectVersion) && !VersionUtil.isUniqueSnapshot(projectVersion)) {
        // non-snapshot versions, or non-timestamped snapshot versions
        version = projectVersion;
    } else if (VersionUtil.isGenericSnapshot(projectVersion)) {
        // timestamped snapshots
        try {
            // 8 is length of "SNAPSHOT"
            int mainVersionLength = projectVersion.length() - 8;
            if (mainVersionLength == 0) {
                throw new IllegalArgumentException("Timestamped snapshots must contain the main version, filename was '" + id + "'");
            }
            Matcher m = TIMESTAMP_PATTERN.matcher(idSubStrFromVersion.substring(mainVersionLength));
            m.matches();
            String timestamp = m.group(1);
            String buildNumber = m.group(2);
            facet.setTimestamp(timestamp);
            facet.setBuildNumber(Integer.parseInt(buildNumber));
            version = idSubStrFromVersion.substring(0, mainVersionLength) + timestamp + "-" + buildNumber;
        } catch (IllegalStateException e) {
            throw new IllegalArgumentException("Not a valid artifact path in a Maven 2 repository, filename '" + id + "' doesn't contain a timestamped version matching snapshot '" + projectVersion + "'", e);
        }
    } else {
        // invalid
        throw new IllegalArgumentException("Not a valid artifact path in a Maven 2 repository, filename '" + id + "' doesn't contain version '" + projectVersion + "'");
    }
    String classifier;
    String ext;
    index += version.length();
    if (index == id.length()) {
        // no classifier or extension
        classifier = null;
        ext = null;
    } else {
        char c = id.charAt(index);
        if (c == '-') {
            // classifier up until '.'
            int extIndex = id.indexOf('.', index);
            if (extIndex >= 0) {
                classifier = id.substring(index + 1, extIndex);
                ext = id.substring(extIndex + 1);
            } else {
                classifier = id.substring(index + 1);
                ext = null;
            }
        } else if (c == '.') {
            // rest is the extension
            classifier = null;
            ext = id.substring(index + 1);
        } else {
            throw new IllegalArgumentException("Not a valid artifact path in a Maven 2 repository, filename '" + id + "' expected classifier or extension but got '" + id.substring(index) + "'");
        }
    }
    ArtifactMetadata metadata = new ArtifactMetadata();
    metadata.setId(id);
    metadata.setNamespace(namespace);
    metadata.setProject(projectId);
    metadata.setRepositoryId(repoId);
    metadata.setProjectVersion(projectVersion);
    metadata.setVersion(version);
    facet.setClassifier(classifier);
    // we use our own provider here instead of directly accessing Maven's artifact handlers as it has no way
    // to select the correct order to apply multiple extensions mappings to a preferred type
    // TODO: this won't allow the user to decide order to apply them if there are conflicts or desired changes -
    // perhaps the plugins could register missing entries in configuration, then we just use configuration
    // here?
    String type = null;
    for (ArtifactMappingProvider mapping : artifactMappingProviders) {
        type = mapping.mapClassifierAndExtensionToType(classifier, ext);
        if (type != null) {
            break;
        }
    }
    // TODO: this is cheating! We should check the POM metadata instead
    if (type == null && "jar".equals(ext) && isArtifactIdValidMavenPlugin(projectId)) {
        type = "maven-plugin";
    }
    // use extension as default
    if (type == null) {
        type = ext;
    }
    // TODO: should we allow this instead?
    if (type == null) {
        throw new IllegalArgumentException("Not a valid artifact path in a Maven 2 repository, filename '" + id + "' does not have a type");
    }
    facet.setType(type);
    metadata.addFacet(facet);
    return metadata;
}
Also used : Matcher(java.util.regex.Matcher) MavenArtifactFacet(org.apache.archiva.metadata.model.maven2.MavenArtifactFacet) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata)

Example 64 with ArtifactMetadata

use of org.apache.archiva.metadata.model.ArtifactMetadata in project archiva by apache.

the class AbstractMetadataRepositoryTest method deleteVersion.

@Test
public void deleteVersion() throws Exception {
    ArtifactMetadata artifact = createArtifact();
    artifact.addFacet(new TestMetadataFacet("value"));
    repository.updateArtifact(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact);
    repository.updateArtifact(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact);
    Collection<String> versions = repository.getProjectVersions(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT);
    assertThat(versions).isNotNull().isNotEmpty().hasSize(1);
    repository.removeProjectVersion(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION);
    versions = repository.getProjectVersions(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT);
    assertThat(versions).isNotNull().isEmpty();
}
Also used : ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) Test(org.junit.Test)

Example 65 with ArtifactMetadata

use of org.apache.archiva.metadata.model.ArtifactMetadata in project archiva by apache.

the class AbstractMetadataRepositoryTest method testUpdateArtifactMetadataWithNoExistingFacets.

@Test
public void testUpdateArtifactMetadataWithNoExistingFacets() throws Exception {
    ArtifactMetadata metadata = createArtifact();
    repository.updateArtifact(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata);
    metadata = repository.getArtifacts(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION).iterator().next();
    assertEquals(Collections.<String>emptyList(), new ArrayList<String>(metadata.getFacetIds()));
    metadata = createArtifact();
    repository.updateArtifact(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata);
    metadata = repository.getArtifacts(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION).iterator().next();
    assertEquals(Collections.<String>emptyList(), new ArrayList<String>(metadata.getFacetIds()));
}
Also used : ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) 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