From 78191d6285e7bad6d93cea693ebdd77c37333a54 Mon Sep 17 00:00:00 2001 From: Brett Porter Date: Wed, 25 Nov 2009 11:45:49 +0000 Subject: [PATCH] [MRM-1282] more reading of Maven POM into metadata git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@884062 13f79535-47bb-0310-9956-ffa450edef68 --- .../archiva/metadata/model/License.java | 50 +++++++++++ .../Maven2RepositoryMetadataResolver.java | 85 +++++++++++++++++-- .../Maven2RepositoryMetadataResolverTest.java | 67 ++++++++++++++- 3 files changed, 195 insertions(+), 7 deletions(-) diff --git a/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/License.java b/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/License.java index 456d63951..2f5a141f8 100644 --- a/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/License.java +++ b/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/License.java @@ -25,6 +25,16 @@ public class License private String url; + public License( String name, String url ) + { + this.name = name; + this.url = url; + } + + public License() + { + } + public String getName() { return name; @@ -44,4 +54,44 @@ public class License { this.url = url; } + + @Override + public boolean equals( Object o ) + { + if ( this == o ) + { + return true; + } + if ( o == null || getClass() != o.getClass() ) + { + return false; + } + + License license = (License) o; + + if ( name != null ? !name.equals( license.name ) : license.name != null ) + { + return false; + } + if ( url != null ? !url.equals( license.url ) : license.url != null ) + { + return false; + } + + return true; + } + + @Override + public int hashCode() + { + int result = name != null ? name.hashCode() : 0; + result = 31 * result + ( url != null ? url.hashCode() : 0 ); + return result; + } + + @Override + public String toString() + { + return "License{" + "name='" + name + '\'' + ", url='" + url + '\'' + '}'; + } } diff --git a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolver.java b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolver.java index c8fed1011..b3fa377cd 100644 --- a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolver.java +++ b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolver.java @@ -20,7 +20,9 @@ package org.apache.archiva.metadata.repository.storage.maven2; */ import java.io.File; +import java.util.ArrayList; import java.util.Collection; +import java.util.List; import org.apache.archiva.metadata.model.ProjectMetadata; import org.apache.archiva.metadata.model.ProjectVersionMetadata; @@ -30,7 +32,12 @@ import org.apache.maven.archiva.common.utils.VersionUtil; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.xml.XMLException; +import org.apache.maven.model.CiManagement; +import org.apache.maven.model.IssueManagement; +import org.apache.maven.model.License; import org.apache.maven.model.Model; +import org.apache.maven.model.Organization; +import org.apache.maven.model.Scm; import org.apache.maven.model.building.DefaultModelBuildingRequest; import org.apache.maven.model.building.ModelBuilder; import org.apache.maven.model.building.ModelBuildingException; @@ -65,8 +72,6 @@ public class Maven2RepositoryMetadataResolver public ProjectVersionMetadata getProjectVersion( String repoId, String namespace, String projectId, String projectVersion ) { - // TODO: artifactVersion translation - ManagedRepositoryConfiguration repositoryConfiguration = archivaConfiguration.getConfiguration().findManagedRepositoryById( repoId ); @@ -113,6 +118,17 @@ public class Maven2RepositoryMetadataResolver throw new RuntimeException( e ); } + ProjectVersionMetadata metadata = new ProjectVersionMetadata(); + metadata.setCiManagement( convertCiManagement( model.getCiManagement() ) ); + metadata.setDescription( model.getDescription() ); + metadata.setId( projectVersion ); + metadata.setIssueManagement( convertIssueManagement( model.getIssueManagement() ) ); + metadata.setLicenses( convertLicenses( model.getLicenses() ) ); + metadata.setName( model.getName() ); + metadata.setOrganization( convertOrganization( model.getOrganization() ) ); + metadata.setScm( convertScm( model.getScm() ) ); + metadata.setUrl( model.getUrl() ); + MavenProjectFacet facet = new MavenProjectFacet(); facet.setGroupId( model.getGroupId() != null ? model.getGroupId() : model.getParent().getGroupId() ); facet.setArtifactId( model.getArtifactId() ); @@ -125,14 +141,73 @@ public class Maven2RepositoryMetadataResolver parent.setVersion( model.getParent().getVersion() ); facet.setParent( parent ); } - ProjectVersionMetadata metadata = new ProjectVersionMetadata(); - metadata.setUrl( model.getUrl() ); metadata.addFacet( facet ); - // TODO: convert project return metadata; } + private org.apache.archiva.metadata.model.Scm convertScm( Scm scm ) + { + org.apache.archiva.metadata.model.Scm newScm = null; + if ( scm != null ) + { + newScm = new org.apache.archiva.metadata.model.Scm(); + newScm.setConnection( scm.getConnection() ); + newScm.setDeveloperConnection( scm.getDeveloperConnection() ); + newScm.setUrl( scm.getUrl() ); + } + return newScm; + } + + private org.apache.archiva.metadata.model.Organization convertOrganization( Organization organization ) + { + org.apache.archiva.metadata.model.Organization org = null; + if ( organization != null ) + { + org = new org.apache.archiva.metadata.model.Organization(); + org.setName( organization.getName() ); + org.setUrl( organization.getUrl() ); + } + return org; + } + + private List convertLicenses( List licenses ) + { + List l = new ArrayList(); + for ( License license : licenses ) + { + org.apache.archiva.metadata.model.License newLicense = new org.apache.archiva.metadata.model.License(); + newLicense.setName( license.getName() ); + newLicense.setUrl( license.getUrl() ); + l.add( newLicense ); + } + return l; + } + + private org.apache.archiva.metadata.model.IssueManagement convertIssueManagement( IssueManagement issueManagement ) + { + org.apache.archiva.metadata.model.IssueManagement im = null; + if ( issueManagement != null ) + { + im = new org.apache.archiva.metadata.model.IssueManagement(); + im.setSystem( issueManagement.getSystem() ); + im.setUrl( issueManagement.getUrl() ); + } + return im; + } + + private org.apache.archiva.metadata.model.CiManagement convertCiManagement( CiManagement ciManagement ) + { + org.apache.archiva.metadata.model.CiManagement ci = null; + if ( ciManagement != null ) + { + ci = new org.apache.archiva.metadata.model.CiManagement(); + ci.setSystem( ciManagement.getSystem() ); + ci.setUrl( ciManagement.getUrl() ); + } + return ci; + } + public Collection getArtifactVersions( String repoId, String namespace, String projectId, String projectVersion ) { diff --git a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverTest.java b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverTest.java index b82c95c33..a1de458d9 100644 --- a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverTest.java +++ b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverTest.java @@ -19,6 +19,9 @@ package org.apache.archiva.metadata.repository.storage.maven2; * under the License. */ +import java.util.Arrays; + +import org.apache.archiva.metadata.model.License; import org.apache.archiva.metadata.model.ProjectVersionMetadata; import org.apache.archiva.metadata.repository.MetadataResolver; import org.apache.maven.archiva.configuration.ArchivaConfiguration; @@ -33,6 +36,12 @@ public class Maven2RepositoryMetadataResolverTest private static final String TEST_REPO_ID = "test"; + private static final String ASF_SCM_CONN_BASE = "scm:svn:http://svn.apache.org/repos/asf/"; + + private static final String ASF_SCM_DEV_CONN_BASE = "scm:svn:https://svn.apache.org/repos/asf/"; + + private static final String ASF_SCM_VIEWVC_BASE = "http://svn.apache.org/viewvc/"; + public void setUp() throws Exception { @@ -56,7 +65,28 @@ public class Maven2RepositoryMetadataResolverTest MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID ); assertEquals( "jar", facet.getPackaging() ); assertEquals( "http://archiva.apache.org/ref/1.2.1/archiva-base/archiva-common", metadata.getUrl() ); - // TODO: more testing + assertEquals( "org.apache.archiva", facet.getParent().getGroupId() ); + assertEquals( "archiva-base", facet.getParent().getArtifactId() ); + assertEquals( "1.2.1", facet.getParent().getVersion() ); + assertEquals( "archiva-common", facet.getArtifactId() ); + assertEquals( "org.apache.archiva", facet.getGroupId() ); + assertEquals( "continuum", metadata.getCiManagement().getSystem() ); + assertEquals( "http://vmbuild.apache.org/continuum", metadata.getCiManagement().getUrl() ); + assertNotNull( metadata.getDescription() ); + // TODO: this would be better +// assertEquals( +// "Archiva is an application for managing one or more remote repositories, including administration, artifact handling, browsing and searching.", +// metadata.getDescription() ); + assertEquals( "1.2.1", metadata.getId() ); + assertEquals( "jira", metadata.getIssueManagement().getSystem() ); + assertEquals( "http://jira.codehaus.org/browse/MRM", metadata.getIssueManagement().getUrl() ); + checkApacheLicense( metadata ); + assertEquals( "Archiva Base :: Common", metadata.getName() ); + String path = "archiva/tags/archiva-1.2.1/archiva-modules/archiva-base/archiva-common"; + assertEquals( ASF_SCM_CONN_BASE + path, metadata.getScm().getConnection() ); + assertEquals( ASF_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection() ); + assertEquals( ASF_SCM_VIEWVC_BASE + path, metadata.getScm().getUrl() ); + checkOrganizationApache( metadata ); } public void testGetProjectVersionMetadataForTimestampedSnapshot() @@ -66,6 +96,39 @@ public class Maven2RepositoryMetadataResolverTest MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID ); assertEquals( "pom", facet.getPackaging() ); assertEquals( "http://www.apache.org/", metadata.getUrl() ); - // TODO: more testing + assertNull( facet.getParent() ); + assertEquals( "org.apache", facet.getGroupId() ); + assertEquals( "apache", facet.getArtifactId() ); + assertNull( metadata.getCiManagement() ); + assertNotNull( metadata.getDescription() ); + // TODO: this would be better +// assertEquals( +// "The Apache Software Foundation provides support for the Apache community of open-source software projects. " + +// "The Apache projects are characterized by a collaborative, consensus based development process, an open " + +// "and pragmatic software license, and a desire to create high quality software that leads the way in its " + +// "field. We consider ourselves not simply a group of projects sharing a server, but rather a community of " + +// "developers and users.", metadata.getDescription() ); + assertEquals( "5-SNAPSHOT", metadata.getId() ); + assertNull( metadata.getIssueManagement() ); + checkApacheLicense( metadata ); + assertEquals( "The Apache Software Foundation", metadata.getName() ); + String path = "maven/pom/trunk/asf"; + assertEquals( ASF_SCM_CONN_BASE + path, metadata.getScm().getConnection() ); + assertEquals( ASF_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection() ); + assertEquals( ASF_SCM_VIEWVC_BASE + path, metadata.getScm().getUrl() ); + checkOrganizationApache( metadata ); + } + + private void checkApacheLicense( ProjectVersionMetadata metadata ) + { + assertEquals( Arrays.asList( new License( "The Apache Software License, Version 2.0", + "http://www.apache.org/licenses/LICENSE-2.0.txt" ) ), + metadata.getLicenses() ); + } + + private void checkOrganizationApache( ProjectVersionMetadata metadata ) + { + assertEquals( "The Apache Software Foundation", metadata.getOrganization().getName() ); + assertEquals( "http://www.apache.org/", metadata.getOrganization().getUrl() ); } } -- 2.39.5