Search in sources :

Example 1 with Dependency

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

the class AbstractMetadataRepositoryTest method testgetProjectReferences.

@Test
public void testgetProjectReferences() throws Exception {
    ProjectVersionMetadata metadata = new ProjectVersionMetadata();
    metadata.setId(TEST_PROJECT_VERSION);
    metadata.setName("project name");
    metadata.setDescription("project description");
    metadata.setUrl("the url");
    Dependency d = new Dependency();
    d.setArtifactId("artifactId");
    d.setClassifier("classifier");
    d.setGroupId("groupId");
    d.setScope("scope");
    d.setSystemPath("system path");
    d.setType("type");
    d.setVersion("version");
    d.setOptional(true);
    metadata.addDependency(d);
    d = new Dependency();
    d.setArtifactId("artifactId1");
    d.setClassifier("classifier");
    d.setGroupId("groupId");
    d.setScope("scope");
    d.setSystemPath("system path");
    d.setType("type");
    d.setVersion("version1");
    d.setOptional(true);
    metadata.addDependency(d);
    repository.updateProjectVersion(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata);
    repository.save();
    metadata = repository.getProjectVersion(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION);
    Collection<ProjectVersionReference> references = repository.getProjectReferences(TEST_REPO_ID, d.getGroupId(), d.getArtifactId(), d.getVersion());
    log.info("references: {}", references);
    assertThat(references).isNotNull().hasSize(1).contains(new ProjectVersionReference(ProjectVersionReference.ReferenceType.DEPENDENCY, TEST_PROJECT, TEST_NAMESPACE, TEST_PROJECT_VERSION));
}
Also used : ProjectVersionMetadata(org.apache.archiva.metadata.model.ProjectVersionMetadata) Dependency(org.apache.archiva.metadata.model.Dependency) ProjectVersionReference(org.apache.archiva.metadata.model.ProjectVersionReference) Test(org.junit.Test)

Example 2 with Dependency

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

the class FileMetadataRepository method updateProjectVersion.

@Override
public void updateProjectVersion(String repoId, String namespace, String projectId, ProjectVersionMetadata versionMetadata) {
    try {
        updateProject(repoId, namespace, projectId);
        Path directory = getDirectory(repoId).resolve(namespace + "/" + projectId + "/" + versionMetadata.getId());
        Properties properties = readOrCreateProperties(directory, PROJECT_VERSION_METADATA_KEY);
        // remove properties that are not references or artifacts
        for (Object key : new ArrayList<>(properties.keySet())) {
            String name = (String) key;
            if (!name.contains(":") && !name.equals("facetIds")) {
                properties.remove(name);
            }
            // clear the facet contents so old properties are no longer written
            clearMetadataFacetProperties(versionMetadata.getFacetList(), properties, "");
        }
        properties.setProperty("id", versionMetadata.getId());
        setProperty(properties, "name", versionMetadata.getName());
        setProperty(properties, "description", versionMetadata.getDescription());
        setProperty(properties, "url", versionMetadata.getUrl());
        setProperty(properties, "incomplete", String.valueOf(versionMetadata.isIncomplete()));
        if (versionMetadata.getScm() != null) {
            setProperty(properties, "scm.connection", versionMetadata.getScm().getConnection());
            setProperty(properties, "scm.developerConnection", versionMetadata.getScm().getDeveloperConnection());
            setProperty(properties, "scm.url", versionMetadata.getScm().getUrl());
        }
        if (versionMetadata.getCiManagement() != null) {
            setProperty(properties, "ci.system", versionMetadata.getCiManagement().getSystem());
            setProperty(properties, "ci.url", versionMetadata.getCiManagement().getUrl());
        }
        if (versionMetadata.getIssueManagement() != null) {
            setProperty(properties, "issue.system", versionMetadata.getIssueManagement().getSystem());
            setProperty(properties, "issue.url", versionMetadata.getIssueManagement().getUrl());
        }
        if (versionMetadata.getOrganization() != null) {
            setProperty(properties, "org.name", versionMetadata.getOrganization().getName());
            setProperty(properties, "org.url", versionMetadata.getOrganization().getUrl());
        }
        int i = 0;
        for (License license : versionMetadata.getLicenses()) {
            setProperty(properties, "license." + i + ".name", license.getName());
            setProperty(properties, "license." + i + ".url", license.getUrl());
            i++;
        }
        i = 0;
        for (MailingList mailingList : versionMetadata.getMailingLists()) {
            setProperty(properties, "mailingList." + i + ".archive", mailingList.getMainArchiveUrl());
            setProperty(properties, "mailingList." + i + ".name", mailingList.getName());
            setProperty(properties, "mailingList." + i + ".post", mailingList.getPostAddress());
            setProperty(properties, "mailingList." + i + ".unsubscribe", mailingList.getUnsubscribeAddress());
            setProperty(properties, "mailingList." + i + ".subscribe", mailingList.getSubscribeAddress());
            setProperty(properties, "mailingList." + i + ".otherArchives", join(mailingList.getOtherArchives()));
            i++;
        }
        i = 0;
        ProjectVersionReference reference = new ProjectVersionReference();
        reference.setNamespace(namespace);
        reference.setProjectId(projectId);
        reference.setProjectVersion(versionMetadata.getId());
        reference.setReferenceType(ProjectVersionReference.ReferenceType.DEPENDENCY);
        for (Dependency dependency : versionMetadata.getDependencies()) {
            setProperty(properties, "dependency." + i + ".classifier", dependency.getClassifier());
            setProperty(properties, "dependency." + i + ".scope", dependency.getScope());
            setProperty(properties, "dependency." + i + ".systemPath", dependency.getSystemPath());
            setProperty(properties, "dependency." + i + ".artifactId", dependency.getArtifactId());
            setProperty(properties, "dependency." + i + ".groupId", dependency.getGroupId());
            setProperty(properties, "dependency." + i + ".version", dependency.getVersion());
            setProperty(properties, "dependency." + i + ".type", dependency.getType());
            setProperty(properties, "dependency." + i + ".optional", String.valueOf(dependency.isOptional()));
            updateProjectReference(repoId, dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion(), reference);
            i++;
        }
        Set<String> facetIds = new LinkedHashSet<>(versionMetadata.getFacetIds());
        facetIds.addAll(Arrays.asList(properties.getProperty("facetIds", "").split(",")));
        properties.setProperty("facetIds", join(facetIds));
        updateProjectVersionFacets(versionMetadata, properties);
        writeProperties(properties, directory, PROJECT_VERSION_METADATA_KEY);
    } catch (IOException e) {
        log.error("Could not update project version {}, {}, {}: {}", repoId, namespace, versionMetadata.getId(), e.getMessage(), e);
    }
}
Also used : Path(java.nio.file.Path) LinkedHashSet(java.util.LinkedHashSet) ArrayList(java.util.ArrayList) License(org.apache.archiva.metadata.model.License) MailingList(org.apache.archiva.metadata.model.MailingList) Dependency(org.apache.archiva.metadata.model.Dependency) IOException(java.io.IOException) Properties(java.util.Properties) ProjectVersionReference(org.apache.archiva.metadata.model.ProjectVersionReference)

Example 3 with Dependency

use of org.apache.archiva.metadata.model.Dependency 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 4 with Dependency

use of org.apache.archiva.metadata.model.Dependency 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)

Example 5 with Dependency

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

the class Maven2RepositoryMetadataResolverMRM1411RepoGroupTest method testGetProjectVersionMetadataWithParentSnapshotVersionAndSnapNotAllowed.

@Test
public void testGetProjectVersionMetadataWithParentSnapshotVersionAndSnapNotAllowed() throws Exception {
    copyTestArtifactWithParent("target/test-classes/com/example/test/test-snapshot-artifact-module-a", "target/test-repositorys/com/example/test/test-snapshot-artifact-module-a");
    copyTestArtifactWithParent("src/test/resources/com/example/test/test-artifact-parent", "target/test-repositorys/com/example/test/test-artifact-parent");
    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_SNAP_REPO_ID).namespace("com.example.test").projectId("test-snapshot-artifact-module-a").projectVersion("1.1-SNAPSHOT");
    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-snapshot-artifact-module-a", facet.getArtifactId());
    assertEquals("com.example.test", facet.getGroupId());
    assertNull(metadata.getCiManagement());
    assertNotNull(metadata.getDescription());
    checkApacheLicense(metadata);
    assertEquals("1.1-SNAPSHOT", metadata.getId());
    assertEquals("Test Snapshot Artifact :: Module A", metadata.getName());
    String path = "test-snapshot-artifact/trunk/test-snapshot-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-repositorys/com/example/test/test-snapshot-artifact-module-a");
    paths.add("target/test-repositorys/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

Dependency (org.apache.archiva.metadata.model.Dependency)15 ProjectVersionMetadata (org.apache.archiva.metadata.model.ProjectVersionMetadata)11 ArrayList (java.util.ArrayList)9 Test (org.junit.Test)9 ReadMetadataRequest (org.apache.archiva.metadata.repository.storage.ReadMetadataRequest)7 License (org.apache.archiva.metadata.model.License)5 MailingList (org.apache.archiva.metadata.model.MailingList)5 HashMap (java.util.HashMap)3 CiManagement (org.apache.archiva.metadata.model.CiManagement)3 IssueManagement (org.apache.archiva.metadata.model.IssueManagement)3 MetadataFacet (org.apache.archiva.metadata.model.MetadataFacet)3 Scm (org.apache.archiva.metadata.model.Scm)3 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 Properties (java.util.Properties)2 Node (javax.jcr.Node)2 RepositoryException (javax.jcr.RepositoryException)2 MetadataFacetFactory (org.apache.archiva.metadata.model.MetadataFacetFactory)2 Organization (org.apache.archiva.metadata.model.Organization)2 ProjectVersionReference (org.apache.archiva.metadata.model.ProjectVersionReference)2