Search in sources :

Example 11 with ProjectVersionMetadata

use of org.apache.archiva.metadata.model.ProjectVersionMetadata in project archiva by apache.

the class AbstractMetadataRepositoryTest method createArtifactWithData.

private void createArtifactWithData() throws MetadataRepositoryException, MetadataResolutionException {
    ArtifactMetadata artifact = createArtifact();
    repository.updateArtifact(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact);
    ProjectVersionMetadata metadata = repository.getProjectVersion(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION);
    metadata.setOrganization(TEST_ORGANIZATION);
    metadata.setUrl(TEST_URL);
    repository.updateProjectVersion(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata);
    repository.save();
}
Also used : ProjectVersionMetadata(org.apache.archiva.metadata.model.ProjectVersionMetadata) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata)

Example 12 with ProjectVersionMetadata

use of org.apache.archiva.metadata.model.ProjectVersionMetadata in project archiva by apache.

the class FileMetadataRepository method updateArtifact.

@Override
public void updateArtifact(String repoId, String namespace, String projectId, String projectVersion, ArtifactMetadata artifact) {
    try {
        ProjectVersionMetadata metadata = new ProjectVersionMetadata();
        metadata.setId(projectVersion);
        updateProjectVersion(repoId, namespace, projectId, metadata);
        Path directory = getDirectory(repoId).resolve(namespace + "/" + projectId + "/" + projectVersion);
        Properties properties = readOrCreateProperties(directory, PROJECT_VERSION_METADATA_KEY);
        clearMetadataFacetProperties(artifact.getFacetList(), properties, "artifact:facet:" + artifact.getId() + ":");
        String id = artifact.getId();
        properties.setProperty("artifact:updated:" + id, Long.toString(artifact.getFileLastModified().getTime()));
        properties.setProperty("artifact:whenGathered:" + id, Long.toString(artifact.getWhenGathered().getTime()));
        properties.setProperty("artifact:size:" + id, Long.toString(artifact.getSize()));
        if (artifact.getMd5() != null) {
            properties.setProperty("artifact:md5:" + id, artifact.getMd5());
        }
        if (artifact.getSha1() != null) {
            properties.setProperty("artifact:sha1:" + id, artifact.getSha1());
        }
        properties.setProperty("artifact:version:" + id, artifact.getVersion());
        Set<String> facetIds = new LinkedHashSet<>(artifact.getFacetIds());
        String property = "artifact:facetIds:" + id;
        facetIds.addAll(Arrays.asList(properties.getProperty(property, "").split(",")));
        properties.setProperty(property, join(facetIds));
        updateArtifactFacets(artifact, properties);
        writeProperties(properties, directory, PROJECT_VERSION_METADATA_KEY);
    } catch (IOException e) {
        // TODO
        log.error(e.getMessage(), e);
    }
}
Also used : Path(java.nio.file.Path) LinkedHashSet(java.util.LinkedHashSet) ProjectVersionMetadata(org.apache.archiva.metadata.model.ProjectVersionMetadata) IOException(java.io.IOException) Properties(java.util.Properties)

Example 13 with ProjectVersionMetadata

use of org.apache.archiva.metadata.model.ProjectVersionMetadata in project archiva by apache.

the class Maven2RepositoryMetadataResolverMRM1411RepoGroupTest method testGetProjectVersionMetadataWithParentSuccessful.

// Tests for MRM-1411 - START
@Test
public void testGetProjectVersionMetadataWithParentSuccessful() throws Exception {
    copyTestArtifactWithParent("src/test/resources/com/example/test/test-artifact-module-a", "target/test-repository/com/example/test/test-artifact-module-a");
    copyTestArtifactWithParent("src/test/resources/com/example/test/test-artifact-root", "target/test-repository/com/example/test/test-artifact-root");
    copyTestArtifactWithParent("src/test/resources/com/example/test/test-artifact-parent", "target/test-repository/com/example/test/test-artifact-parent");
    ReadMetadataRequest readMetadataRequest = new ReadMetadataRequest().repositoryId(TEST_REPO_ID).namespace("com.example.test").projectId("test-artifact-module-a").projectVersion("1.0");
    ProjectVersionMetadata metadata = storage.readProjectVersionMetadata(readMetadataRequest);
    MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet(MavenProjectFacet.FACET_ID);
    assertEquals("jar", facet.getPackaging());
    assertEquals("http://maven.apache.org", metadata.getUrl());
    assertEquals("com.example.test", facet.getParent().getGroupId());
    assertEquals("test-artifact-root", facet.getParent().getArtifactId());
    assertEquals("1.0", facet.getParent().getVersion());
    assertEquals("test-artifact-module-a", facet.getArtifactId());
    assertEquals("com.example.test", facet.getGroupId());
    assertNull(metadata.getCiManagement());
    assertNotNull(metadata.getDescription());
    checkApacheLicense(metadata);
    assertEquals("1.0", metadata.getId());
    assertEquals("Test Artifact :: Module A", metadata.getName());
    String path = "test-artifact/trunk/test-artifact-module-a";
    assertEquals(TEST_SCM_CONN_BASE + path, metadata.getScm().getConnection());
    assertEquals(TEST_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection());
    assertEquals(TEST_SCM_URL_BASE + path, metadata.getScm().getUrl());
    List<Dependency> dependencies = metadata.getDependencies();
    assertEquals(2, dependencies.size());
    assertDependency(dependencies.get(0), "commons-io", "commons-io", "1.4");
    assertDependency(dependencies.get(1), "junit", "junit", "3.8.1", "test");
    List<String> paths = new ArrayList<>();
    paths.add("target/test-repository/com/example/test/test-artifact-module-a");
    paths.add("target/test-repository/com/example/test/test-artifact-parent");
    paths.add("target/test-repository/com/example/test/test-artifact-root");
    deleteTestArtifactWithParent(paths);
}
Also used : ReadMetadataRequest(org.apache.archiva.metadata.repository.storage.ReadMetadataRequest) ProjectVersionMetadata(org.apache.archiva.metadata.model.ProjectVersionMetadata) ArrayList(java.util.ArrayList) Dependency(org.apache.archiva.metadata.model.Dependency) Test(org.junit.Test)

Example 14 with ProjectVersionMetadata

use of org.apache.archiva.metadata.model.ProjectVersionMetadata in project archiva by apache.

the class Maven2RepositoryMetadataResolverMRM1411RepoGroupTest method testGetProjectVersionMetadataWithParentNoRemoteReposConfigured.

@Test
public void testGetProjectVersionMetadataWithParentNoRemoteReposConfigured() throws Exception {
    // remove configuration
    Configuration config = configuration.getConfiguration();
    RemoteRepositoryConfiguration remoteRepo = config.findRemoteRepositoryById(TEST_REMOTE_REPO_ID);
    config.removeRemoteRepository(remoteRepo);
    configuration.save(config);
    copyTestArtifactWithParent("src/test/resources/com/example/test/test-artifact-module-a", "target/test-repository/com/example/test/test-artifact-module-a");
    copyTestArtifactWithParent("src/test/resources/com/example/test/test-artifact-root", "target/test-repository/com/example/test/test-artifact-root");
    copyTestArtifactWithParent("src/test/resources/com/example/test/test-artifact-parent", "target/test-repository/com/example/test/test-artifact-parent");
    ReadMetadataRequest readMetadataRequest = new ReadMetadataRequest().repositoryId(TEST_REPO_ID).namespace("com.example.test").projectId("test-artifact-module-a").projectVersion("1.0");
    ProjectVersionMetadata metadata = storage.readProjectVersionMetadata(readMetadataRequest);
    assertEquals("1.0", metadata.getId());
    MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet(MavenProjectFacet.FACET_ID);
    assertNotNull(facet);
    assertEquals("com.example.test", facet.getGroupId());
    assertEquals("test-artifact-module-a", facet.getArtifactId());
    assertEquals("jar", facet.getPackaging());
    List<String> paths = new ArrayList<>();
    paths.add("target/test-repository/com/example/test/test-artifact-module-a");
    paths.add("target/test-repository/com/example/test/test-artifact-parent");
    paths.add("target/test-repository/com/example/test/test-artifact-root");
    deleteTestArtifactWithParent(paths);
}
Also used : ArchivaConfiguration(org.apache.archiva.configuration.ArchivaConfiguration) RepositoryGroupConfiguration(org.apache.archiva.configuration.RepositoryGroupConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.ProxyConnectorConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.RemoteRepositoryConfiguration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) Configuration(org.apache.archiva.configuration.Configuration) ReadMetadataRequest(org.apache.archiva.metadata.repository.storage.ReadMetadataRequest) ProjectVersionMetadata(org.apache.archiva.metadata.model.ProjectVersionMetadata) ArrayList(java.util.ArrayList) RemoteRepositoryConfiguration(org.apache.archiva.configuration.RemoteRepositoryConfiguration) Test(org.junit.Test)

Example 15 with ProjectVersionMetadata

use of org.apache.archiva.metadata.model.ProjectVersionMetadata in project archiva by apache.

the class Maven2RepositoryMetadataResolverMRM1411RepoGroupTest method testGetProjectVersionMetadataWithParentSnapshotVersionAndSnapNotAllowed2.

@Test
public void testGetProjectVersionMetadataWithParentSnapshotVersionAndSnapNotAllowed2() throws Exception {
    copyTestArtifactWithParent("src/test/resources/com/example/test/test-artifact-module-b", "target/test-repository/com/example/test/test-artifact-module-b");
    copyTestArtifactWithParent("src/test/resources/com/example/test/test-snapshot-artifact-root", "target/test-repositorys/com/example/test/test-snapshot-artifact-root");
    ReadMetadataRequest readMetadataRequest = new ReadMetadataRequest().repositoryId(TEST_REPO_ID).namespace("com.example.test").projectId("test-artifact-module-b").projectVersion("1.0");
    ProjectVersionMetadata metadata = storage.readProjectVersionMetadata(readMetadataRequest);
    MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet(MavenProjectFacet.FACET_ID);
    assertEquals("jar", facet.getPackaging());
    assertEquals("com.example.test", facet.getParent().getGroupId());
    assertEquals("test-snapshot-artifact-root", facet.getParent().getArtifactId());
    assertEquals("1.1-SNAPSHOT", facet.getParent().getVersion());
    assertEquals("test-artifact-module-b", facet.getArtifactId());
    assertEquals("com.example.test", facet.getGroupId());
    assertNull(metadata.getCiManagement());
    assertNotNull(metadata.getDescription());
    checkApacheLicense(metadata);
    assertEquals("1.0", metadata.getId());
    assertEquals("Test Artifact :: Module B", metadata.getName());
    String path = "test-snapshot-artifact/trunk/test-artifact-module-b";
    assertEquals(TEST_SCM_CONN_BASE + path, metadata.getScm().getConnection());
    assertEquals(TEST_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection());
    assertEquals(TEST_SCM_URL_BASE + path, metadata.getScm().getUrl());
    List<Dependency> dependencies = metadata.getDependencies();
    assertEquals(2, dependencies.size());
    assertDependency(dependencies.get(0), "commons-io", "commons-io", "1.4");
    assertDependency(dependencies.get(1), "junit", "junit", "3.8.1", "test");
    List<String> paths = new ArrayList<>();
    paths.add("target/test-repository/com/example/test/test-artifact-module-b");
    paths.add("target/test-repository/com/example/test/test-snapshot-artifact-root");
    deleteTestArtifactWithParent(paths);
}
Also used : ReadMetadataRequest(org.apache.archiva.metadata.repository.storage.ReadMetadataRequest) ProjectVersionMetadata(org.apache.archiva.metadata.model.ProjectVersionMetadata) ArrayList(java.util.ArrayList) Dependency(org.apache.archiva.metadata.model.Dependency) Test(org.junit.Test)

Aggregations

ProjectVersionMetadata (org.apache.archiva.metadata.model.ProjectVersionMetadata)44 Test (org.junit.Test)29 ReadMetadataRequest (org.apache.archiva.metadata.repository.storage.ReadMetadataRequest)19 ArrayList (java.util.ArrayList)14 Dependency (org.apache.archiva.metadata.model.Dependency)11 MetadataFacet (org.apache.archiva.metadata.model.MetadataFacet)8 HashMap (java.util.HashMap)7 GenericMetadataFacet (org.apache.archiva.metadata.generic.GenericMetadataFacet)6 ArtifactMetadata (org.apache.archiva.metadata.model.ArtifactMetadata)5 RepositorySession (org.apache.archiva.metadata.repository.RepositorySession)5 RepositoryStorageRuntimeException (org.apache.archiva.metadata.repository.storage.RepositoryStorageRuntimeException)5 CiManagement (org.apache.archiva.metadata.model.CiManagement)4 IssueManagement (org.apache.archiva.metadata.model.IssueManagement)4 MailingList (org.apache.archiva.metadata.model.MailingList)4 Scm (org.apache.archiva.metadata.model.Scm)4 MetadataResolutionException (org.apache.archiva.metadata.repository.MetadataResolutionException)4 RepositoryStorageMetadataInvalidException (org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataInvalidException)4 RepositoryStorageMetadataNotFoundException (org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataNotFoundException)4 Path (java.nio.file.Path)3 License (org.apache.archiva.metadata.model.License)3