aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-base/archiva-repository-layer
diff options
context:
space:
mode:
authorJoakim Erdfelt <joakime@apache.org>2007-10-04 23:48:58 +0000
committerJoakim Erdfelt <joakime@apache.org>2007-10-04 23:48:58 +0000
commit4b9cf4b9298b9906ae4975146706e6a870349e43 (patch)
tree9866fe2b84209531d6255a9b9bd017c84759d7f5 /archiva-base/archiva-repository-layer
parent13e64dfc3dfcae4bb81b9ef3a3f3bb98bddb86db (diff)
downloadarchiva-4b9cf4b9298b9906ae4975146706e6a870349e43.tar.gz
archiva-4b9cf4b9298b9906ae4975146706e6a870349e43.zip
Adding ProjectModel300Reader tests.
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@582026 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-base/archiva-repository-layer')
-rw-r--r--archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/readers/ProjectModel300Reader.java381
-rw-r--r--archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/readers/ProjectModel400Reader.java2
-rw-r--r--archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/project/readers/ProjectModel300ReaderTest.java67
-rw-r--r--archiva-base/archiva-repository-layer/src/test/repositories/legacy-repository/org.apache.maven/poms/maven-model-v3-2.0.pom15
4 files changed, 461 insertions, 4 deletions
diff --git a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/readers/ProjectModel300Reader.java b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/readers/ProjectModel300Reader.java
index b22ac2020..18cef92d6 100644
--- a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/readers/ProjectModel300Reader.java
+++ b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/readers/ProjectModel300Reader.java
@@ -19,11 +19,28 @@ package org.apache.maven.archiva.repository.project.readers;
* under the License.
*/
+import org.apache.commons.lang.StringUtils;
import org.apache.maven.archiva.model.ArchivaProjectModel;
+import org.apache.maven.archiva.model.ArtifactReference;
+import org.apache.maven.archiva.model.Dependency;
+import org.apache.maven.archiva.model.Individual;
+import org.apache.maven.archiva.model.IssueManagement;
+import org.apache.maven.archiva.model.License;
+import org.apache.maven.archiva.model.MailingList;
+import org.apache.maven.archiva.model.Organization;
+import org.apache.maven.archiva.model.ProjectRepository;
+import org.apache.maven.archiva.model.Scm;
import org.apache.maven.archiva.repository.project.ProjectModelException;
import org.apache.maven.archiva.repository.project.ProjectModelReader;
+import org.apache.maven.archiva.xml.XMLException;
+import org.apache.maven.archiva.xml.XMLReader;
+import org.dom4j.Element;
import java.io.File;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
/**
* ProjectModel300Reader
@@ -35,14 +52,372 @@ import java.io.File;
* role="org.apache.maven.archiva.repository.project.ProjectModelReader"
* role-hint="model300"
*/
-public class ProjectModel300Reader implements ProjectModelReader
+public class ProjectModel300Reader
+ implements ProjectModelReader
{
public ArchivaProjectModel read( File pomFile )
- throws ProjectModelException
+ throws ProjectModelException
{
- // TODO Auto-generated method stub
+ try
+ {
+ XMLReader xml = new XMLReader( "project", pomFile );
+
+ ArchivaProjectModel model = new ArchivaProjectModel();
+
+ xml.removeNamespaces();
+
+ Element project = xml.getElement( "//project" );
+
+ // TODO: Handle <extend /> ?? (is this even possible?)
+
+ model.setGroupId( project.elementTextTrim( "groupId" ) );
+ model.setArtifactId( project.elementTextTrim( "artifactId" ) );
+ // TODO: Handle <id />
+ model.setVersion( project.elementTextTrim( "currentVersion" ) );
+ model.setName( project.elementTextTrim( "name" ) );
+ model.setDescription( project.elementTextTrim( "description" ) );
+ // TODO: what to do with <shortDescription /> ?
+ model.setUrl( project.elementTextTrim( "url" ) );
+ // TODO: Handle <logo />
+ // TODO: Handle <inceptionYear />
+
+ model.setIssueManagement( getIssueManagement( xml ) );
+ // TODO: What to do with <gumpRepositoryId /> ?
+ // TODO: Handle <siteAddress />
+ // TODO: Handle <siteDirectory /> ?
+ // TODO: Handle <distributionSite />
+ // TODO: Handle <distributionDirectory />
+ model.setMailingLists( getMailingLists( xml ) );
+ model.setIndividuals( getIndividuals( xml ) );
+ model.setLicenses( getLicenses( xml ) );
+ model.setReports( getReports( xml ) );
+ model.setRepositories( getRepositories( xml ) );
+ model.setScm( getSCM( xml ) );
+ model.setOrganization( getOrganization( xml ) );
+ model.setProperties( getProperties( xml.getElement( "//project/properties" ) ) );
+ model.setDependencies( getDependencies( xml ) );
+
+ /* Following are not valid for <pomVersion>3</pomVersion> / Maven 1 pom files.
+ *
+ * model.setDependencyManagement()
+ * model.setPlugins()
+ * model.setParentProject()
+ * model.setPackaging()
+ * model.setCiManagement()
+ * model.setBuildExtensions()
+ * model.setRelocation()
+ */
+
+ return model;
+ }
+ catch ( XMLException e )
+ {
+ throw new ProjectModelException( e.getMessage(), e );
+ }
+ }
+
+ private ArtifactReference getArtifactReference( Element elemPlugin, String defaultType )
+ {
+ ArtifactReference reference = new ArtifactReference();
+
+ reference.setGroupId( StringUtils.defaultString( elemPlugin.elementTextTrim( "groupId" ) ) );
+ reference.setArtifactId( elemPlugin.elementTextTrim( "artifactId" ) );
+ reference.setVersion( StringUtils.defaultString( elemPlugin.elementTextTrim( "version" ) ) );
+ reference.setClassifier( StringUtils.defaultString( elemPlugin.elementTextTrim( "classifier" ) ) );
+ reference.setType( StringUtils.defaultIfEmpty( elemPlugin.elementTextTrim( "type" ), defaultType ) );
+
+ return reference;
+ }
+
+ /**
+ * Get List of {@link ArtifactReference} objects from xpath expr.
+ */
+ private List<ArtifactReference> getArtifactReferenceList( XMLReader xml, String xpathExpr, String defaultType )
+ throws XMLException
+ {
+ List<ArtifactReference> refs = new ArrayList<ArtifactReference>();
+
+ Iterator<Element> it = xml.getElementList( xpathExpr ).iterator();
+ while ( it.hasNext() )
+ {
+ Element elemPlugin = it.next();
+
+ refs.add( getArtifactReference( elemPlugin, defaultType ) );
+ }
+
+ return refs;
+ }
+
+ private List<Dependency> getDependencies( XMLReader xml )
+ throws XMLException
+ {
+ return getDependencyList( xml, new String[] { "dependencies" } );
+ }
+
+ private List<Dependency> getDependencyList( XMLReader xml, String parts[] )
+ throws XMLException
+ {
+ List<Dependency> dependencyList = new ArrayList<Dependency>();
+
+ Element project = xml.getElement( "//project" );
+
+ Element depsParent = project;
+
+ for ( String part : parts )
+ {
+ depsParent = depsParent.element( part );
+ if ( depsParent == null )
+ {
+ return dependencyList;
+ }
+ }
+
+ Iterator<Element> it = depsParent.elementIterator( "dependency" );
+ while ( it.hasNext() )
+ {
+ Element elemDependency = it.next();
+ Dependency dependency = new Dependency();
+
+ dependency.setGroupId( elemDependency.elementTextTrim( "groupId" ) );
+ dependency.setArtifactId( elemDependency.elementTextTrim( "artifactId" ) );
+ dependency.setVersion( elemDependency.elementTextTrim( "version" ) );
+
+ dependency.setType( StringUtils.defaultIfEmpty( elemDependency.elementTextTrim( "type" ), "jar" ) );
+ dependency.setUrl( elemDependency.elementTextTrim( "url" ) );
+ /* Following are not valid for <pomVersion>3</pomVersion> / Maven 1 pom files.
+ *
+ * dependency.setClassifier( StringUtils.defaultString( elemDependency.elementTextTrim( "classifier" ) ) );
+ * dependency.setScope( StringUtils.defaultIfEmpty( elemDependency.elementTextTrim( "scope" ), "compile" ) );
+ * dependency.setOptional( toBoolean( elemDependency.elementTextTrim( "optional" ), false ) );
+ */
+
+ dependency.setSystemPath( elemDependency.elementTextTrim( "jar" ) );
+
+ if ( dependencyList.contains( dependency ) )
+ {
+ // TODO: throw into monitor as "duplicate dependency" issue.
+ }
+
+ dependencyList.add( dependency );
+ }
+
+ return dependencyList;
+ }
+
+ private List<Individual> getIndividuals( XMLReader xml )
+ throws XMLException
+ {
+ List<Individual> individuals = new ArrayList<Individual>();
+
+ individuals.addAll( getIndividuals( xml, true, "//project/developers/developer" ) );
+ individuals.addAll( getIndividuals( xml, false, "//project/contributors/contributor" ) );
+
+ return individuals;
+ }
+
+ private List<Individual> getIndividuals( XMLReader xml, boolean isCommitor, String xpathExpr )
+ throws XMLException
+ {
+ List<Individual> ret = new ArrayList<Individual>();
+
+ List<Element> modelPersonList = xml.getElementList( xpathExpr );
+
+ Iterator<Element> iter = modelPersonList.iterator();
+ while ( iter.hasNext() )
+ {
+ Element elemPerson = iter.next();
+ Individual individual = new Individual();
+
+ if ( isCommitor )
+ {
+ individual.setPrincipal( elemPerson.elementTextTrim( "id" ) );
+ }
+
+ individual.setCommitor( isCommitor );
+ individual.setEmail( elemPerson.elementTextTrim( "email" ) );
+ individual.setName( elemPerson.elementTextTrim( "name" ) );
+ individual.setOrganization( elemPerson.elementTextTrim( "organization" ) );
+ individual.setOrganizationUrl( elemPerson.elementTextTrim( "organizationUrl" ) );
+ individual.setUrl( elemPerson.elementTextTrim( "url" ) );
+ individual.setTimezone( elemPerson.elementTextTrim( "timezone" ) );
+
+ // Roles
+ Element elemRoles = elemPerson.element( "roles" );
+ if ( elemRoles != null )
+ {
+ List<Element> roleNames = elemRoles.elements( "role" );
+ Iterator<Element> itRole = roleNames.iterator();
+ while ( itRole.hasNext() )
+ {
+ Element role = itRole.next();
+ individual.addRole( role.getTextTrim() );
+ }
+ }
+
+ // Properties
+ individual.setProperties( getProperties( elemPerson.element( "properties" ) ) );
+
+ ret.add( individual );
+ }
+
+ return ret;
+ }
+
+ private IssueManagement getIssueManagement( XMLReader xml )
+ throws XMLException
+ {
+ Element issueTrackingUrlElem = xml.getElement( "//project/issueTrackingUrl" );
+
+ if ( issueTrackingUrlElem == null )
+ {
+ return null;
+ }
+
+ String issueTrackingUrl = issueTrackingUrlElem.getTextTrim();
+ if ( StringUtils.isBlank( issueTrackingUrl ) )
+ {
+ return null;
+ }
+
+ IssueManagement issueMgmt = new IssueManagement();
+ issueMgmt.setUrl( issueTrackingUrl );
+
+ return issueMgmt;
+ }
+
+ private List<License> getLicenses( XMLReader xml )
+ throws XMLException
+ {
+ List<License> licenses = new ArrayList<License>();
+
+ Element elemLicenses = xml.getElement( "//project/licenses" );
+
+ if ( elemLicenses != null )
+ {
+ List<Element> licenseList = elemLicenses.elements( "license" );
+ for ( Element elemLicense : licenseList )
+ {
+ License license = new License();
+
+ // TODO: Create LicenseIdentity class to managed license ids.
+ // license.setId( elemLicense.elementTextTrim("id") );
+ license.setName( elemLicense.elementTextTrim( "name" ) );
+ license.setUrl( elemLicense.elementTextTrim( "url" ) );
+ license.setComments( elemLicense.elementTextTrim( "comments" ) );
+
+ licenses.add( license );
+ }
+ }
+
+ return licenses;
+ }
+
+ private List<MailingList> getMailingLists( XMLReader xml )
+ throws XMLException
+ {
+ List<MailingList> mailingLists = new ArrayList<MailingList>();
+
+ List<Element> mailingListElems = xml.getElementList( "//project/mailingLists/mailingList" );
+ for ( Element elemMailingList : mailingListElems )
+ {
+ MailingList mlist = new MailingList();
+
+ mlist.setName( elemMailingList.elementTextTrim( "name" ) );
+ mlist.setSubscribeAddress( elemMailingList.elementTextTrim( "subscribe" ) );
+ mlist.setUnsubscribeAddress( elemMailingList.elementTextTrim( "unsubscribe" ) );
+ mlist.setPostAddress( elemMailingList.elementTextTrim( "post" ) );
+ mlist.setMainArchiveUrl( elemMailingList.elementTextTrim( "archive" ) );
+
+ Element elemOtherArchives = elemMailingList.element( "otherArchives" );
+ if ( elemOtherArchives != null )
+ {
+ List<String> otherArchives = new ArrayList<String>();
+ List<Element> others = elemOtherArchives.elements( "otherArchive" );
+ for ( Element other : others )
+ {
+ String otherArchive = other.getTextTrim();
+ otherArchives.add( otherArchive );
+ }
+
+ mlist.setOtherArchives( otherArchives );
+ }
+
+ mailingLists.add( mlist );
+ }
+
+ return mailingLists;
+ }
+
+ private Organization getOrganization( XMLReader xml )
+ throws XMLException
+ {
+ Element elemOrg = xml.getElement( "//project/organization" );
+ if ( elemOrg != null )
+ {
+ Organization org = new Organization();
+
+ org.setName( elemOrg.elementTextTrim( "name" ) );
+ org.setUrl( elemOrg.elementTextTrim( "url" ) );
+ // TODO: Handle <logo />
+
+ return org;
+ }
+
return null;
}
+ private Properties getProperties( Element elemProperties )
+ {
+ if ( elemProperties == null )
+ {
+ return null;
+ }
+
+ Properties ret = new Properties();
+
+ Iterator<Element> itProps = elemProperties.elements().iterator();
+ while ( itProps.hasNext() )
+ {
+ Element elemProp = (Element) itProps.next();
+ ret.setProperty( elemProp.getName(), elemProp.getText() );
+ }
+
+ return ret;
+ }
+
+ private List<ArtifactReference> getReports( XMLReader xml )
+ throws XMLException
+ {
+ return getArtifactReferenceList( xml, "//project/reports/plugins/plugin", "maven-plugin" );
+ }
+
+ private List<ProjectRepository> getRepositories( XMLReader xml )
+ throws XMLException
+ {
+ List<ProjectRepository> repos = new ArrayList<ProjectRepository>();
+
+ // Repositories are not stored within the maven 1 pom.
+
+ return repos;
+ }
+
+ private Scm getSCM( XMLReader xml )
+ throws XMLException
+ {
+ Element elemScm = xml.getElement( "//project/repository" );
+
+ if ( elemScm != null )
+ {
+ Scm scm = new Scm();
+
+ scm.setConnection( elemScm.elementTextTrim( "connection" ) );
+ scm.setDeveloperConnection( elemScm.elementTextTrim( "developerConnection" ) );
+ scm.setUrl( elemScm.elementTextTrim( "url" ) );
+
+ return scm;
+ }
+
+ return null;
+ }
}
diff --git a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/readers/ProjectModel400Reader.java b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/readers/ProjectModel400Reader.java
index df59f0f54..f619275d2 100644
--- a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/readers/ProjectModel400Reader.java
+++ b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/readers/ProjectModel400Reader.java
@@ -218,7 +218,7 @@ public class ProjectModel400Reader
if ( dependencyList.contains( dependency ) )
{
- // TODO: throw into monitor as issue.
+ // TODO: throw into monitor as "duplicate dependency" issue.
}
dependencyList.add( dependency );
diff --git a/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/project/readers/ProjectModel300ReaderTest.java b/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/project/readers/ProjectModel300ReaderTest.java
new file mode 100644
index 000000000..3b7f51c53
--- /dev/null
+++ b/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/project/readers/ProjectModel300ReaderTest.java
@@ -0,0 +1,67 @@
+package org.apache.maven.archiva.repository.project.readers;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.archiva.model.ArchivaProjectModel;
+import org.apache.maven.archiva.model.Dependency;
+import org.apache.maven.archiva.repository.project.ProjectModelException;
+import org.apache.maven.archiva.repository.project.ProjectModelReader;
+import org.codehaus.plexus.PlexusTestCase;
+
+import java.io.File;
+
+/**
+ * ProjectModel300ReaderTest
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class ProjectModel300ReaderTest
+ extends PlexusTestCase
+{
+ public void testLoadSimple()
+ throws ProjectModelException
+ {
+ File defaultRepoDir = new File( getBasedir(), "src/test/repositories/legacy-repository" );
+ File pomFile = new File( defaultRepoDir, "org.apache.maven/poms/maven-model-v3-2.0.pom" );
+
+ ProjectModelReader reader = new ProjectModel300Reader();
+
+ ArchivaProjectModel project = reader.read( pomFile );
+
+ assertNotNull( project );
+ assertEquals( "Group Id", "org.apache.maven", project.getGroupId() );
+ assertEquals( "Artifact Id", "maven-model-v3", project.getArtifactId() );
+ assertEquals( "Version", "2.0", project.getVersion() );
+ assertEquals( "Name", "Maven Model v3", project.getName() );
+ assertEquals( "Description", "Maven Model v3", project.getDescription() );
+
+ assertNull( "Has no parent project.", project.getParentProject() );
+
+ assertNotNull( "Dependencies", project.getDependencies() );
+ assertEquals( "Dependencies.size", 1, project.getDependencies().size() );
+
+ Dependency dep = (Dependency) project.getDependencies().get( 0 );
+ assertNotNull( dep );
+ assertEquals( "dep.groupId", "org.codehaus.plexus", dep.getGroupId() );
+ assertEquals( "dep.artifactId", "plexus-utils", dep.getArtifactId() );
+ assertEquals( "dep.version", "1.0.4", dep.getVersion() );
+ }
+}
diff --git a/archiva-base/archiva-repository-layer/src/test/repositories/legacy-repository/org.apache.maven/poms/maven-model-v3-2.0.pom b/archiva-base/archiva-repository-layer/src/test/repositories/legacy-repository/org.apache.maven/poms/maven-model-v3-2.0.pom
new file mode 100644
index 000000000..509552ef9
--- /dev/null
+++ b/archiva-base/archiva-repository-layer/src/test/repositories/legacy-repository/org.apache.maven/poms/maven-model-v3-2.0.pom
@@ -0,0 +1,15 @@
+<project>
+ <pomVersion>3</pomVersion>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-model-v3</artifactId>
+ <name>Maven Model v3</name>
+ <currentVersion>2.0</currentVersion>
+ <description>Maven Model v3</description>
+ <dependencies>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-utils</artifactId>
+ <version>1.0.4</version>
+ </dependency>
+ </dependencies>
+</project> \ No newline at end of file