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);
}
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());
}
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);
}
}
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();
}
Aggregations