Search in sources :

Example 6 with MavenMetadataReader

use of org.apache.archiva.maven.metadata.MavenMetadataReader in project archiva by apache.

the class MavenRepositoryMetadataReaderTest method testGroupMetadata.

@Test
public void testGroupMetadata() throws RepositoryMetadataException {
    Path metadataFile = defaultRepoDir.resolve("org/apache/maven/plugins/maven-metadata.xml");
    MavenMetadataReader metadataReader = new MavenMetadataReader();
    ArchivaRepositoryMetadata metadata = metadataReader.read(metadataFile);
    assertNotNull(metadata);
    assertEquals("org.apache.maven.plugins", metadata.getGroupId());
    assertNull(metadata.getArtifactId());
    assertNull(metadata.getReleasedVersion());
    assertNull(metadata.getLatestVersion());
    assertTrue(metadata.getAvailableVersions().isEmpty());
    assertNull(metadata.getSnapshotVersion());
    assertNull(metadata.getLastUpdated());
    Plugin cleanPlugin = new Plugin();
    cleanPlugin.setPrefix("clean");
    cleanPlugin.setArtifactId("maven-clean-plugin");
    cleanPlugin.setName("Maven Clean Plugin");
    Plugin compilerPlugin = new Plugin();
    compilerPlugin.setPrefix("compiler");
    compilerPlugin.setArtifactId("maven-compiler-plugin");
    compilerPlugin.setName("Maven Compiler Plugin");
    Plugin surefirePlugin = new Plugin();
    surefirePlugin.setPrefix("surefire");
    surefirePlugin.setArtifactId("maven-surefire-plugin");
    surefirePlugin.setName("Maven Surefire Plugin");
    assertEquals(Arrays.asList(cleanPlugin, compilerPlugin, surefirePlugin), metadata.getPlugins());
}
Also used : Path(java.nio.file.Path) MavenMetadataReader(org.apache.archiva.maven.metadata.MavenMetadataReader) ArchivaRepositoryMetadata(org.apache.archiva.model.ArchivaRepositoryMetadata) Plugin(org.apache.archiva.model.Plugin) Test(org.junit.Test)

Example 7 with MavenMetadataReader

use of org.apache.archiva.maven.metadata.MavenMetadataReader in project archiva by apache.

the class MavenRepositoryMetadataReaderTest method testProjectVersionMetadata.

@Test
public void testProjectVersionMetadata() throws RepositoryMetadataException {
    Path metadataFile = defaultRepoDir.resolve("org/apache/apache/5-SNAPSHOT/maven-metadata.xml");
    MavenMetadataReader metadataReader = new MavenMetadataReader();
    ArchivaRepositoryMetadata metadata = metadataReader.read(metadataFile);
    assertNotNull(metadata);
    assertEquals("org.apache", metadata.getGroupId());
    assertEquals("apache", metadata.getArtifactId());
    assertNull(metadata.getReleasedVersion());
    assertNull(metadata.getLatestVersion());
    assertTrue(metadata.getAvailableVersions().isEmpty());
    assertNotNull(metadata.getSnapshotVersion());
    assertEquals("20080801.151215", metadata.getSnapshotVersion().getTimestamp());
    assertEquals(1, metadata.getSnapshotVersion().getBuildNumber());
    assertEquals("20080801151215", metadata.getLastUpdated());
}
Also used : Path(java.nio.file.Path) MavenMetadataReader(org.apache.archiva.maven.metadata.MavenMetadataReader) ArchivaRepositoryMetadata(org.apache.archiva.model.ArchivaRepositoryMetadata) Test(org.junit.Test)

Example 8 with MavenMetadataReader

use of org.apache.archiva.maven.metadata.MavenMetadataReader in project archiva by apache.

the class RepositoryServletRepositoryGroupTest method testGetMergedMetadata.

// MRM-872
@Test
public void testGetMergedMetadata() throws Exception {
    // first metadata file
    String resourceName = "dummy/dummy-merged-metadata-resource/maven-metadata.xml";
    Path dummyInternalResourceFile = repoRootFirst.resolve(resourceName);
    Files.createDirectories(dummyInternalResourceFile.getParent());
    org.apache.archiva.common.utils.FileUtils.writeStringToFile(dummyInternalResourceFile, Charset.defaultCharset(), "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<metadata>\n<groupId>dummy</groupId>\n<artifactId>dummy-merged-metadata-resource</artifactId>\n" + "<versioning>\n<latest>1.0</latest>\n<release>1.0</release>\n<versions>\n<version>1.0</version>\n" + "<version>2.5</version>\n</versions>\n<lastUpdated>20080708095554</lastUpdated>\n</versioning>\n</metadata>");
    // second metadata file
    resourceName = "dummy/dummy-merged-metadata-resource/maven-metadata.xml";
    dummyInternalResourceFile = repoRootLast.resolve(resourceName);
    Files.createDirectories(dummyInternalResourceFile.getParent());
    org.apache.archiva.common.utils.FileUtils.writeStringToFile(dummyInternalResourceFile, Charset.defaultCharset(), "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<metadata><groupId>dummy</groupId><artifactId>dummy-merged-metadata-resource</artifactId>" + "<versioning><latest>2.0</latest><release>2.0</release><versions><version>1.0</version>" + "<version>1.5</version><version>2.0</version></versions><lastUpdated>20080709095554</lastUpdated>" + "</versioning></metadata>");
    WebRequest request = new GetMethodWebRequest("http://machine.com/repository/" + REPO_GROUP_WITH_VALID_REPOS + "/dummy/" + "dummy-merged-metadata-resource/maven-metadata.xml");
    WebResponse response = getServletUnitClient().getResource(request);
    Path returnedMetadata = getProjectBase().resolve("target/test-classes/retrievedMetadataFile.xml");
    org.apache.archiva.common.utils.FileUtils.writeStringToFile(returnedMetadata, Charset.defaultCharset(), response.getContentAsString());
    MavenMetadataReader metadataReader = new MavenMetadataReader();
    ArchivaRepositoryMetadata metadata = metadataReader.read(returnedMetadata);
    assertResponseOK(response);
    assertThat(metadata.getAvailableVersions()).isNotNull().hasSize(4).contains("1.0", "1.5", "2.0", "2.5");
    // check if the checksum files were generated
    Path checksumFileSha1 = repoRootFirst.resolve(resourceName + ".sha1");
    Files.createDirectories(checksumFileSha1.getParent());
    org.apache.archiva.common.utils.FileUtils.writeStringToFile(checksumFileSha1, Charset.defaultCharset(), "3290853214d3687134");
    Path checksumFileMd5 = repoRootFirst.resolve(resourceName + ".md5");
    Files.createDirectories(checksumFileMd5.getParent());
    org.apache.archiva.common.utils.FileUtils.writeStringToFile(checksumFileMd5, Charset.defaultCharset(), "98745897234eda12836423");
    // request the sha1 checksum of the metadata
    request = new GetMethodWebRequest("http://machine.com/repository/" + REPO_GROUP_WITH_VALID_REPOS + "/dummy/" + "dummy-merged-metadata-resource/maven-metadata.xml.sha1");
    response = getServletUnitClient().getResource(request);
    assertResponseOK(response);
    assertThat(response.getContentAsString()).startsWith("f8a7a858a46887368adf0b30874de1f807d91453");
    // request the md5 checksum of the metadata
    request = new GetMethodWebRequest("http://machine.com/repository/" + REPO_GROUP_WITH_VALID_REPOS + "/dummy/" + "dummy-merged-metadata-resource/maven-metadata.xml.md5");
    response = getServletUnitClient().getResource(request);
    assertResponseOK(response);
    assertThat(response.getContentAsString()).startsWith("cec864b66849153dd45fddb7cdde12b2");
}
Also used : Path(java.nio.file.Path) WebResponse(com.gargoylesoftware.htmlunit.WebResponse) WebRequest(com.gargoylesoftware.htmlunit.WebRequest) MavenMetadataReader(org.apache.archiva.maven.metadata.MavenMetadataReader) ArchivaRepositoryMetadata(org.apache.archiva.model.ArchivaRepositoryMetadata) Test(org.junit.Test)

Aggregations

Path (java.nio.file.Path)8 MavenMetadataReader (org.apache.archiva.maven.metadata.MavenMetadataReader)8 ArchivaRepositoryMetadata (org.apache.archiva.model.ArchivaRepositoryMetadata)6 Test (org.junit.Test)6 DefaultFileLockManager (org.apache.archiva.common.filelock.DefaultFileLockManager)2 FilesystemStorage (org.apache.archiva.repository.storage.fs.FilesystemStorage)2 Test (org.junit.jupiter.api.Test)2 WebRequest (com.gargoylesoftware.htmlunit.WebRequest)1 WebResponse (com.gargoylesoftware.htmlunit.WebResponse)1 Plugin (org.apache.archiva.model.Plugin)1