Search in sources :

Example 1 with VersionedReference

use of org.apache.archiva.model.VersionedReference in project archiva by apache.

the class ManagedDefaultRepositoryContentTest method testToMetadataPathFromVersionReference.

@Test
public void testToMetadataPathFromVersionReference() {
    VersionedReference reference = new VersionedReference();
    reference.setGroupId("com.foo");
    reference.setArtifactId("foo-tool");
    reference.setVersion("1.0");
    assertEquals("com/foo/foo-tool/1.0/maven-metadata.xml", repoContent.toMetadataPath(reference));
}
Also used : VersionedReference(org.apache.archiva.model.VersionedReference) Test(org.junit.Test)

Example 2 with VersionedReference

use of org.apache.archiva.model.VersionedReference in project archiva by apache.

the class MetadataToolsTest method assertSnapshotVersions.

private void assertSnapshotVersions(String artifactId, String version, String[] expectedVersions) throws Exception {
    Path repoRootDir = Paths.get("src/test/repositories/metadata-repository");
    VersionedReference reference = new VersionedReference();
    reference.setGroupId("org.apache.archiva.metadata.tests");
    reference.setArtifactId(artifactId);
    reference.setVersion(version);
    MavenManagedRepository repo = createRepository("test-repo", "Test Repository: " + name.getMethodName(), repoRootDir);
    RepositoryContentProvider provider = applicationContext.getBean("repositoryContentProvider#maven", RepositoryContentProvider.class);
    ManagedRepositoryContent repoContent = provider.createManagedContent(repo);
    Set<String> testedVersionSet = tools.gatherSnapshotVersions(repoContent, reference);
    // Sort the list (for asserts)
    List<String> testedVersions = new ArrayList<>();
    testedVersions.addAll(testedVersionSet);
    Collections.sort(testedVersions, new VersionComparator());
    // Test the expected array of versions, to the actual tested versions
    assertEquals("Assert Snapshot Versions: length/size", expectedVersions.length, testedVersions.size());
    for (int i = 0; i < expectedVersions.length; i++) {
        String actualVersion = testedVersions.get(i);
        assertEquals("Snapshot Versions[" + i + "]", expectedVersions[i], actualVersion);
    }
}
Also used : Path(java.nio.file.Path) VersionedReference(org.apache.archiva.model.VersionedReference) RepositoryContentProvider(org.apache.archiva.repository.RepositoryContentProvider) MavenManagedRepository(org.apache.archiva.repository.maven2.MavenManagedRepository) ManagedRepositoryContent(org.apache.archiva.repository.ManagedRepositoryContent) ArrayList(java.util.ArrayList) VersionComparator(org.apache.archiva.common.utils.VersionComparator)

Example 3 with VersionedReference

use of org.apache.archiva.model.VersionedReference in project archiva by apache.

the class MetadataToolsTest method testToPathFromVersionReference.

@Test
public void testToPathFromVersionReference() {
    VersionedReference reference = new VersionedReference();
    reference.setGroupId("com.foo");
    reference.setArtifactId("foo-tool");
    reference.setVersion("1.0");
    assertEquals("com/foo/foo-tool/1.0/maven-metadata.xml", tools.toPath(reference));
}
Also used : VersionedReference(org.apache.archiva.model.VersionedReference) Test(org.junit.Test)

Example 4 with VersionedReference

use of org.apache.archiva.model.VersionedReference in project archiva by apache.

the class ManagedDefaultRepositoryContent method newVersionedRef.

static final VersionedReference newVersionedRef(final String groupId, final String artifactId, final String version) {
    VersionedReference ref = new VersionedReference();
    ref.setGroupId(groupId);
    ref.setArtifactId(artifactId);
    ref.setVersion(version);
    return ref;
}
Also used : VersionedReference(org.apache.archiva.model.VersionedReference)

Example 5 with VersionedReference

use of org.apache.archiva.model.VersionedReference in project archiva by apache.

the class CleanupReleasedSnapshotsRepositoryPurge method updateMetadata.

/*
     * TODO: Uses a deprecated API, but if we use the API with location string, it does not work as expected
     * -> not sure what needs to be changed here.
     */
@SuppressWarnings("deprecation")
private void updateMetadata(ArtifactReference artifact) {
    VersionedReference versionRef = new VersionedReference();
    versionRef.setGroupId(artifact.getGroupId());
    versionRef.setArtifactId(artifact.getArtifactId());
    versionRef.setVersion(artifact.getVersion());
    ProjectReference projectRef = new ProjectReference();
    projectRef.setGroupId(artifact.getGroupId());
    projectRef.setArtifactId(artifact.getArtifactId());
    try {
        metadataTools.updateMetadata(repository, versionRef);
    } catch (ContentNotFoundException e) {
    // Ignore. (Just means we have no snapshot versions left to reference).
    } catch (RepositoryMetadataException e) {
    // Ignore.
    } catch (IOException e) {
    // Ignore.
    } catch (LayoutException e) {
    // Ignore.
    }
    try {
        metadataTools.updateMetadata(repository, projectRef);
    } catch (ContentNotFoundException e) {
    // Ignore. (Just means we have no snapshot versions left to reference).
    } catch (RepositoryMetadataException e) {
    // Ignore.
    } catch (IOException e) {
    // Ignore.
    } catch (LayoutException e) {
    // Ignore.
    }
}
Also used : ProjectReference(org.apache.archiva.model.ProjectReference) VersionedReference(org.apache.archiva.model.VersionedReference) RepositoryMetadataException(org.apache.archiva.repository.metadata.RepositoryMetadataException) ContentNotFoundException(org.apache.archiva.repository.ContentNotFoundException) LayoutException(org.apache.archiva.repository.LayoutException) IOException(java.io.IOException)

Aggregations

VersionedReference (org.apache.archiva.model.VersionedReference)24 Path (java.nio.file.Path)15 ManagedRepositoryContent (org.apache.archiva.repository.ManagedRepositoryContent)8 ArtifactReference (org.apache.archiva.model.ArtifactReference)7 ContentNotFoundException (org.apache.archiva.repository.ContentNotFoundException)7 ArrayList (java.util.ArrayList)6 LayoutException (org.apache.archiva.repository.LayoutException)6 IOException (java.io.IOException)5 HashSet (java.util.HashSet)4 ArchivaRepositoryMetadata (org.apache.archiva.model.ArchivaRepositoryMetadata)4 ProjectReference (org.apache.archiva.model.ProjectReference)4 RepositoryException (org.apache.archiva.repository.RepositoryException)4 VersionComparator (org.apache.archiva.common.utils.VersionComparator)3 MetadataRepository (org.apache.archiva.metadata.repository.MetadataRepository)3 MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)3 StringWriter (java.io.StringWriter)2 Files (java.nio.file.Files)2 Paths (java.nio.file.Paths)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Calendar (java.util.Calendar)2