Search in sources :

Example 6 with ItemSelector

use of org.apache.archiva.repository.content.ItemSelector in project archiva by apache.

the class AbstractRepositoryContentTest method assertLayout.

/**
 * Perform a roundtrip through the layout routines to determine success.
 */
private void assertLayout(String path, String groupId, String artifactId, String version, String artifactVersion, String classifier, String type) throws LayoutException {
    ItemSelector expectedArtifact = createItemSelector(groupId, artifactId, version, artifactVersion, classifier, type);
    // --- Artifact Tests.
    // Artifact to Path
    assertEquals("Artifact <" + expectedArtifact + "> to path:", path, toPath(expectedArtifact));
    // --- Artifact Reference Tests
    // Path to Artifact Reference.
    ItemSelector testReference = toItemSelector(path);
    assertArtifactReference(testReference, groupId, artifactId, version, artifactVersion, classifier, type);
    // And back again, using test Reference from previous step.
    assertEquals("Artifact <" + expectedArtifact + "> to path:", path, toPath(testReference));
}
Also used : ArchivaItemSelector(org.apache.archiva.repository.content.base.ArchivaItemSelector) ItemSelector(org.apache.archiva.repository.content.ItemSelector)

Example 7 with ItemSelector

use of org.apache.archiva.repository.content.ItemSelector in project archiva by apache.

the class MavenContentHelperTest method assertArtifactVersion.

private void assertArtifactVersion(MavenContentHelper mavenContentHelper, String expectedVersion, StorageAsset dir, String selectorArtifactVersion, String selectorVersion) {
    ItemSelector selector = ArchivaItemSelector.builder().withVersion(selectorVersion).withArtifactVersion(selectorArtifactVersion).build();
    assertEquals(expectedVersion, mavenContentHelper.getArtifactVersion(dir, selector));
}
Also used : ArchivaItemSelector(org.apache.archiva.repository.content.base.ArchivaItemSelector) ItemSelector(org.apache.archiva.repository.content.ItemSelector)

Example 8 with ItemSelector

use of org.apache.archiva.repository.content.ItemSelector in project archiva by apache.

the class MavenContentHelperTest method assertClassifier.

private void assertClassifier(String expectedClassifier, String classifier, String type) {
    ItemSelector selector = ArchivaItemSelector.builder().withClassifier(classifier).withType(type).build();
    assertEquals(expectedClassifier, MavenContentHelper.getClassifier(selector));
}
Also used : ArchivaItemSelector(org.apache.archiva.repository.content.base.ArchivaItemSelector) ItemSelector(org.apache.archiva.repository.content.ItemSelector)

Example 9 with ItemSelector

use of org.apache.archiva.repository.content.ItemSelector in project archiva by apache.

the class ManagedDefaultRepositoryContent method getArtifact.

@Override
public Artifact getArtifact(final ItemSelector selectorArg) throws ContentAccessException {
    ItemSelector selector = selectorArg;
    if (!selectorArg.hasProjectId()) {
        throw new IllegalArgumentException("Project id must be set");
    }
    if (!selectorArg.hasVersion()) {
        if (selectorArg.hasArtifactVersion() && VersionUtil.isSnapshot(selectorArg.getArtifactVersion())) {
            selector = ArchivaItemSelector.builder().withSelector(selectorArg).withVersion(VersionUtil.getBaseVersion(selectorArg.getArtifactVersion())).build();
        } else if (selectorArg.hasArtifactVersion()) {
            selector = ArchivaItemSelector.builder().withSelector(selectorArg).withVersion(selectorArg.getArtifactVersion()).build();
        } else {
            throw new IllegalArgumentException("Version must be set");
        }
    }
    if (!selectorArg.hasArtifactId()) {
        throw new IllegalArgumentException("Artifact id must be set");
    }
    final StorageAsset artifactDir = getAsset(selector.getNamespace(), selector.getProjectId(), selector.getVersion());
    final String artifactVersion = mavenContentHelper.getArtifactVersion(artifactDir, selector);
    final String classifier = MavenContentHelper.getClassifier(selector);
    final String extension = MavenContentHelper.getArtifactExtension(selector);
    final String artifactId = StringUtils.isEmpty(selector.getArtifactId()) ? selector.getProjectId() : selector.getArtifactId();
    final String fileName = MavenContentHelper.getArtifactFileName(artifactId, artifactVersion, classifier, extension);
    final StorageAsset path = getAsset(selector.getNamespace(), selector.getProjectId(), selector.getVersion(), fileName);
    try {
        return getArtifactFromPath(path);
    } catch (LayoutException e) {
        throw new IllegalArgumentException("The selector is not valid " + e.getMessage(), e);
    }
}
Also used : ItemSelector(org.apache.archiva.repository.content.ItemSelector) ArchivaItemSelector(org.apache.archiva.repository.content.base.ArchivaItemSelector) LayoutException(org.apache.archiva.repository.content.LayoutException) StorageAsset(org.apache.archiva.repository.storage.StorageAsset)

Example 10 with ItemSelector

use of org.apache.archiva.repository.content.ItemSelector in project archiva by apache.

the class MetadataTransferTest method assertReleaseMetadataContents.

/**
 * Test for the existance of the requestedResource in the default managed repository, and if it exists,
 * does it contain the expected release maven-metadata.xml contents?
 *
 * @param requestedResource the requested resource
 * @throws Exception
 */
private void assertReleaseMetadataContents(String requestedResource) throws Exception {
    Path actualFile = managedDefaultDir.resolve(requestedResource);
    assertTrue("Release Metadata should exist: " + requestedResource, Files.exists(actualFile));
    ItemSelector metadata = createVersionedSelector(requestedResource);
    // Build expected metadata XML
    StringWriter expectedMetadataXml = new StringWriter();
    ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
    m.setGroupId(metadata.getNamespace());
    m.setArtifactId(metadata.getArtifactId());
    m.setVersion(metadata.getVersion());
    RepositoryMetadataWriter.write(m, expectedMetadataXml);
    // Compare the file to the actual contents.
    assertMetadataEquals(expectedMetadataXml.toString(), actualFile);
}
Also used : Path(java.nio.file.Path) ArchivaItemSelector(org.apache.archiva.repository.content.base.ArchivaItemSelector) ItemSelector(org.apache.archiva.repository.content.ItemSelector) StringWriter(java.io.StringWriter) ArchivaRepositoryMetadata(org.apache.archiva.model.ArchivaRepositoryMetadata)

Aggregations

ItemSelector (org.apache.archiva.repository.content.ItemSelector)76 ArchivaItemSelector (org.apache.archiva.repository.content.base.ArchivaItemSelector)74 Test (org.junit.Test)41 Path (java.nio.file.Path)16 Artifact (org.apache.archiva.repository.content.Artifact)16 StorageAsset (org.apache.archiva.repository.storage.StorageAsset)13 ManagedRepositoryContent (org.apache.archiva.repository.ManagedRepositoryContent)12 BaseRepositoryContentLayout (org.apache.archiva.repository.content.BaseRepositoryContentLayout)12 LayoutException (org.apache.archiva.repository.content.LayoutException)12 IOException (java.io.IOException)11 ContentItem (org.apache.archiva.repository.content.ContentItem)11 Project (org.apache.archiva.repository.content.Project)11 ArchivaContentItem (org.apache.archiva.repository.content.base.ArchivaContentItem)10 Namespace (org.apache.archiva.repository.content.Namespace)9 Version (org.apache.archiva.repository.content.Version)9 VersionComparator (org.apache.archiva.common.utils.VersionComparator)8 EditableManagedRepository (org.apache.archiva.repository.EditableManagedRepository)7 List (java.util.List)6 Collectors (java.util.stream.Collectors)6 Stream (java.util.stream.Stream)6