use of org.apache.archiva.model.ArchivaRepositoryMetadata in project archiva by apache.
the class MetadataTransferTest method assertSnapshotMetadata.
private void assertSnapshotMetadata(Path actualFile, VersionedReference actualMetadata, String expectedDate, String expectedTime, int expectedBuildnumber) throws RepositoryMetadataException, Exception {
// Build expected metadata XML
StringWriter expectedMetadataXml = new StringWriter();
ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
m.setGroupId(actualMetadata.getGroupId());
m.setArtifactId(actualMetadata.getArtifactId());
m.setVersion(VersionUtil.getBaseVersion(actualMetadata.getVersion()));
m.setSnapshotVersion(new SnapshotVersion());
if (StringUtils.isNotBlank(expectedDate) && StringUtils.isNotBlank(expectedTime)) {
m.getSnapshotVersion().setTimestamp(expectedDate + "." + expectedTime);
}
m.getSnapshotVersion().setBuildNumber(expectedBuildnumber);
m.setLastUpdated(expectedDate + expectedTime);
RepositoryMetadataWriter.write(m, expectedMetadataXml);
// Compare the file to the actual contents.
assertMetadataEquals(expectedMetadataXml.toString(), actualFile);
}
use of org.apache.archiva.model.ArchivaRepositoryMetadata 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));
VersionedReference metadata = createVersionedReference(requestedResource);
// Build expected metadata XML
StringWriter expectedMetadataXml = new StringWriter();
ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
m.setGroupId(metadata.getGroupId());
m.setArtifactId(metadata.getArtifactId());
m.setVersion(metadata.getVersion());
RepositoryMetadataWriter.write(m, expectedMetadataXml);
// Compare the file to the actual contents.
assertMetadataEquals(expectedMetadataXml.toString(), actualFile);
}
use of org.apache.archiva.model.ArchivaRepositoryMetadata in project archiva by apache.
the class MetadataTransferTest method assertMetadataEquals.
private void assertMetadataEquals(String expectedMetadataXml, Path actualFile) throws Exception {
assertNotNull("Actual File should not be null.", actualFile);
assertTrue("Actual file exists.", Files.exists(actualFile));
StringWriter actualContents = new StringWriter();
ArchivaRepositoryMetadata metadata = MavenMetadataReader.read(actualFile);
RepositoryMetadataWriter.write(metadata, actualContents);
DetailedDiff detailedDiff = new DetailedDiff(new Diff(expectedMetadataXml, actualContents.toString()));
if (!detailedDiff.similar()) {
assertEquals(expectedMetadataXml, actualContents);
}
// assertEquals( "Check file contents.", expectedMetadataXml, actualContents );
}
use of org.apache.archiva.model.ArchivaRepositoryMetadata in project archiva by apache.
the class MetadataTransferTest method assertGroupMetadata.
private void assertGroupMetadata(Path actualFile, ProjectReference actualMetadata, String[] expectedPlugins) throws Exception {
// Build expected metadata XML
StringWriter expectedMetadataXml = new StringWriter();
ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
m.setGroupId(actualMetadata.getGroupId());
for (String pluginId : expectedPlugins) {
Plugin p = new Plugin();
p.setPrefix(pluginId);
p.setArtifactId(pluginId + "-maven-plugin");
p.setName("The " + pluginId + " Plugin");
m.getPlugins().add(p);
}
RepositoryMetadataWriter.write(m, expectedMetadataXml);
// Compare the file to the actual contents.
assertMetadataEquals(expectedMetadataXml.toString(), actualFile);
}
use of org.apache.archiva.model.ArchivaRepositoryMetadata in project archiva by apache.
the class DefaultRepositoriesService method updateProjectMetadata.
private void updateProjectMetadata(String targetPath, Date lastUpdatedTimestamp, String timestamp, int buildNumber, boolean fixChecksums, ArtifactTransferRequest artifactTransferRequest) throws RepositoryMetadataException {
List<String> availableVersions = new ArrayList<>();
String latestVersion = artifactTransferRequest.getVersion();
Path projectDir = Paths.get(targetPath).getParent();
Path projectMetadataFile = projectDir.resolve(MetadataTools.MAVEN_METADATA);
ArchivaRepositoryMetadata projectMetadata = getMetadata(projectMetadataFile);
if (Files.exists(projectMetadataFile)) {
availableVersions = projectMetadata.getAvailableVersions();
Collections.sort(availableVersions, VersionComparator.getInstance());
if (!availableVersions.contains(artifactTransferRequest.getVersion())) {
availableVersions.add(artifactTransferRequest.getVersion());
}
latestVersion = availableVersions.get(availableVersions.size() - 1);
} else {
availableVersions.add(artifactTransferRequest.getVersion());
projectMetadata.setGroupId(artifactTransferRequest.getGroupId());
projectMetadata.setArtifactId(artifactTransferRequest.getArtifactId());
}
if (projectMetadata.getGroupId() == null) {
projectMetadata.setGroupId(artifactTransferRequest.getGroupId());
}
if (projectMetadata.getArtifactId() == null) {
projectMetadata.setArtifactId(artifactTransferRequest.getArtifactId());
}
projectMetadata.setLatestVersion(latestVersion);
projectMetadata.setLastUpdatedTimestamp(lastUpdatedTimestamp);
projectMetadata.setAvailableVersions(availableVersions);
if (!VersionUtil.isSnapshot(artifactTransferRequest.getVersion())) {
projectMetadata.setReleasedVersion(latestVersion);
}
RepositoryMetadataWriter.write(projectMetadata, projectMetadataFile);
if (fixChecksums) {
fixChecksums(projectMetadataFile);
}
}
Aggregations