Search in sources :

Example 21 with VersionedReference

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

the class MetadataToolsTest method assertUpdatedReleaseVersionMetadata.

private void assertUpdatedReleaseVersionMetadata(String artifactId, String version) throws Exception {
    ManagedRepositoryContent testRepo = createTestRepoContent();
    VersionedReference reference = new VersionedReference();
    reference.setGroupId("org.apache.archiva.metadata.tests");
    reference.setArtifactId(artifactId);
    reference.setVersion(version);
    prepTestRepo(testRepo, reference);
    tools.updateMetadata(testRepo, reference);
    StringBuilder buf = new StringBuilder();
    buf.append("<metadata>\n");
    buf.append("  <groupId>").append(reference.getGroupId()).append("</groupId>\n");
    buf.append("  <artifactId>").append(reference.getArtifactId()).append("</artifactId>\n");
    buf.append("  <version>").append(reference.getVersion()).append("</version>\n");
    buf.append("</metadata>");
    assertMetadata(buf.toString(), testRepo, reference);
}
Also used : VersionedReference(org.apache.archiva.model.VersionedReference) ManagedRepositoryContent(org.apache.archiva.repository.ManagedRepositoryContent)

Example 22 with VersionedReference

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

the class MetadataToolsTest method assertVersionedReference.

private void assertVersionedReference(String groupId, String artifactId, String version, String path) throws RepositoryMetadataException {
    VersionedReference reference = tools.toVersionedReference(path);
    assertNotNull("Reference should not be null.", reference);
    assertEquals("VersionedReference.groupId", groupId, reference.getGroupId());
    assertEquals("VersionedReference.artifactId", artifactId, reference.getArtifactId());
    assertEquals("VersionedReference.version", version, reference.getVersion());
}
Also used : VersionedReference(org.apache.archiva.model.VersionedReference)

Example 23 with VersionedReference

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

the class ManagedDefaultRepositoryContentTest method assertVersions.

private void assertVersions(String artifactId, String version, String[] expectedVersions) throws Exception {
    VersionedReference reference = new VersionedReference();
    reference.setGroupId("org.apache.archiva.metadata.tests");
    reference.setArtifactId(artifactId);
    reference.setVersion(version);
    // Use the test metadata-repository, which is already setup for
    // These kind of version tests.
    Path repoDir = Paths.get("src/test/repositories/metadata-repository");
    ((EditableManagedRepository) repoContent.getRepository()).setLocation(repoDir.toAbsolutePath().toUri());
    // Request the versions.
    Set<String> testedVersionSet = repoContent.getVersions(reference);
    // Sort the list (for asserts later)
    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 Versions: length/size", expectedVersions.length, testedVersions.size());
    for (int i = 0; i < expectedVersions.length; i++) {
        String actualVersion = testedVersions.get(i);
        assertEquals("Versions[" + i + "]", expectedVersions[i], actualVersion);
    }
}
Also used : Path(java.nio.file.Path) VersionedReference(org.apache.archiva.model.VersionedReference) EditableManagedRepository(org.apache.archiva.repository.EditableManagedRepository) ArrayList(java.util.ArrayList) VersionComparator(org.apache.archiva.common.utils.VersionComparator)

Example 24 with VersionedReference

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

the class ManagedDefaultRepositoryContent method getVersions.

@Override
public Set<String> getVersions(VersionedReference reference) throws ContentNotFoundException {
    String path = toMetadataPath(reference);
    int idx = path.lastIndexOf('/');
    if (idx > 0) {
        path = path.substring(0, idx);
    }
    Path repoBase = PathUtil.getPathFromUri(repository.getLocation());
    Path repoDir = repoBase.resolve(path);
    if (!Files.exists(repoDir)) {
        throw new ContentNotFoundException("Unable to get versions on a non-existant directory: " + repoDir.toAbsolutePath());
    }
    if (!Files.isDirectory(repoDir)) {
        throw new ContentNotFoundException("Unable to get versions on a non-directory: " + repoDir.toAbsolutePath());
    }
    Set<String> foundVersions = new HashSet<>();
    try (Stream<Path> stream = Files.list(repoDir)) {
        return stream.filter(Files::isRegularFile).map(p -> repoBase.relativize(p).toString()).filter(p -> !filetypes.matchesDefaultExclusions(p)).filter(filetypes::matchesArtifactPattern).map(path1 -> {
            try {
                return toArtifactReference(path1);
            } catch (LayoutException e) {
                log.debug("Not processing file that is not an artifact: {}", e.getMessage());
                return null;
            }
        }).filter(Objects::nonNull).map(ar -> ar.getVersion()).collect(Collectors.toSet());
    } catch (IOException e) {
        log.error("Could not read directory {}: {}", repoDir, e.getMessage(), e);
    }
    return Collections.emptySet();
}
Also used : Path(java.nio.file.Path) StringUtils(org.apache.commons.lang.StringUtils) PathUtil(org.apache.archiva.common.utils.PathUtil) ArtifactMappingProvider(org.apache.archiva.metadata.repository.storage.maven2.ArtifactMappingProvider) DefaultArtifactMappingProvider(org.apache.archiva.metadata.repository.storage.maven2.DefaultArtifactMappingProvider) ProjectReference(org.apache.archiva.model.ProjectReference) HashSet(java.util.HashSet) URI(java.net.URI) LayoutException(org.apache.archiva.repository.LayoutException) Path(java.nio.file.Path) ManagedRepositoryContent(org.apache.archiva.repository.ManagedRepositoryContent) VersionedReference(org.apache.archiva.model.VersionedReference) Files(java.nio.file.Files) RepositoryException(org.apache.archiva.repository.RepositoryException) Set(java.util.Set) FileTypes(org.apache.archiva.configuration.FileTypes) IOException(java.io.IOException) ContentNotFoundException(org.apache.archiva.repository.ContentNotFoundException) ArchivaArtifact(org.apache.archiva.model.ArchivaArtifact) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) Paths(java.nio.file.Paths) ArtifactReference(org.apache.archiva.model.ArtifactReference) Collections(java.util.Collections) ContentNotFoundException(org.apache.archiva.repository.ContentNotFoundException) LayoutException(org.apache.archiva.repository.LayoutException) Objects(java.util.Objects) IOException(java.io.IOException) HashSet(java.util.HashSet)

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