Search in sources :

Example 21 with ArchivaRepositoryMetadata

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);
}
Also used : StringWriter(java.io.StringWriter) SnapshotVersion(org.apache.archiva.model.SnapshotVersion) ArchivaRepositoryMetadata(org.apache.archiva.model.ArchivaRepositoryMetadata)

Example 22 with ArchivaRepositoryMetadata

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);
}
Also used : Path(java.nio.file.Path) VersionedReference(org.apache.archiva.model.VersionedReference) StringWriter(java.io.StringWriter) ArchivaRepositoryMetadata(org.apache.archiva.model.ArchivaRepositoryMetadata)

Example 23 with ArchivaRepositoryMetadata

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 );
}
Also used : DetailedDiff(org.custommonkey.xmlunit.DetailedDiff) StringWriter(java.io.StringWriter) DetailedDiff(org.custommonkey.xmlunit.DetailedDiff) Diff(org.custommonkey.xmlunit.Diff) ArchivaRepositoryMetadata(org.apache.archiva.model.ArchivaRepositoryMetadata)

Example 24 with ArchivaRepositoryMetadata

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);
}
Also used : StringWriter(java.io.StringWriter) ArchivaRepositoryMetadata(org.apache.archiva.model.ArchivaRepositoryMetadata) Plugin(org.apache.archiva.model.Plugin)

Example 25 with ArchivaRepositoryMetadata

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);
    }
}
Also used : Path(java.nio.file.Path) ArrayList(java.util.ArrayList) ArchivaRepositoryMetadata(org.apache.archiva.model.ArchivaRepositoryMetadata)

Aggregations

ArchivaRepositoryMetadata (org.apache.archiva.model.ArchivaRepositoryMetadata)37 Path (java.nio.file.Path)29 StringWriter (java.io.StringWriter)8 XMLException (org.apache.archiva.xml.XMLException)8 ArrayList (java.util.ArrayList)7 SnapshotVersion (org.apache.archiva.model.SnapshotVersion)7 Test (org.junit.Test)7 IOException (java.io.IOException)5 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)5 ManagedRepository (org.apache.archiva.admin.model.beans.ManagedRepository)4 Plugin (org.apache.archiva.model.Plugin)4 ManagedRepositoryContent (org.apache.archiva.repository.ManagedRepositoryContent)4 Date (java.util.Date)3 ChecksummedFile (org.apache.archiva.checksum.ChecksummedFile)3 ArtifactReference (org.apache.archiva.model.ArtifactReference)3 RepositoryException (org.apache.archiva.repository.RepositoryException)3 ArchivaRestServiceException (org.apache.archiva.rest.api.services.ArchivaRestServiceException)3 DateFormat (java.text.DateFormat)2 SimpleDateFormat (java.text.SimpleDateFormat)2 TimeZone (java.util.TimeZone)2