diff options
author | Joakim Erdfelt <joakime@apache.org> | 2007-09-27 23:35:03 +0000 |
---|---|---|
committer | Joakim Erdfelt <joakime@apache.org> | 2007-09-27 23:35:03 +0000 |
commit | a216251c1fea40f4cfeb9a38eb7c3b0459bedfe7 (patch) | |
tree | 75daff552f4f05466cc1a6337322de33e121d8c9 /archiva-base | |
parent | 0aa3e955eadc043909a30c9c83d96bf045412bbc (diff) | |
download | archiva-a216251c1fea40f4cfeb9a38eb7c3b0459bedfe7.tar.gz archiva-a216251c1fea40f4cfeb9a38eb7c3b0459bedfe7.zip |
[MRM-488] properties in pom are not resolved (at least while browsing)
Preparing ModelWriter to aide in testing of issue.
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@580183 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-base')
-rw-r--r-- | archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/ProjectModelWriter.java | 57 | ||||
-rw-r--r-- | archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/writers/ProjectModel400Writer.java | 309 | ||||
-rw-r--r-- | archiva-base/archiva-repository-layer/src/test/expected-poms/archiva-model-effective.pom (renamed from archiva-base/archiva-repository-layer/src/test/effective-poms/archiva-model-effective.pom) | 0 | ||||
-rw-r--r-- | archiva-base/archiva-repository-layer/src/test/expected-poms/maven-parent-4.pom | 213 | ||||
-rw-r--r-- | archiva-base/archiva-repository-layer/src/test/expected-poms/model-write-400-simple.pom | 9 | ||||
-rw-r--r-- | archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/project/writers/ProjectModel400WriterTest.java | 147 | ||||
-rw-r--r-- | archiva-base/archiva-repository-layer/src/test/repositories/default-repository/org/apache/maven/test/2.0.4-SNAPSHOT/test-2.0.4-SNAPSHOT.pom | 142 |
7 files changed, 877 insertions, 0 deletions
diff --git a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/ProjectModelWriter.java b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/ProjectModelWriter.java new file mode 100644 index 000000000..22da830bf --- /dev/null +++ b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/ProjectModelWriter.java @@ -0,0 +1,57 @@ +package org.apache.maven.archiva.repository.project; + +/* + * 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 java.io.File; +import java.io.IOException; +import java.io.Writer; + +/** + * ProjectModelWriter + * + * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> + * @version $Id$ + */ +public interface ProjectModelWriter +{ + /** + * Write a project model out to disk. + * + * @param model the model to write. + * @param pomFile the (pom) file on disk to write to. + * @throws ProjectModelException if there was a problem with the model itself. + * @throws IOException if there was a problem writing the pom file. + */ + public void write( ArchivaProjectModel model, File pomFile ) + throws ProjectModelException, IOException; + + /** + * Write a project model out to a {@link Writer}. + * + * @param model the model to write. + * @param writer the writer (stream) to write to. + * @throws ProjectModelException if there was a problem with the model itself. + * @throws IOException if there was a problem writing the pom file. + */ + public void write( ArchivaProjectModel model, Writer writer ) + throws ProjectModelException, IOException; +} diff --git a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/writers/ProjectModel400Writer.java b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/writers/ProjectModel400Writer.java new file mode 100644 index 000000000..747cf1381 --- /dev/null +++ b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/writers/ProjectModel400Writer.java @@ -0,0 +1,309 @@ +package org.apache.maven.archiva.repository.project.writers; + +/* + * 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.commons.collections.CollectionUtils; +import org.apache.commons.io.IOUtils; +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.CiManagement; +import org.apache.maven.archiva.model.Individual; +import org.apache.maven.archiva.model.IssueManagement; +import org.apache.maven.archiva.model.MailingList; +import org.apache.maven.archiva.model.Scm; +import org.apache.maven.archiva.model.VersionedReference; +import org.apache.maven.archiva.repository.project.ProjectModelException; +import org.apache.maven.archiva.repository.project.ProjectModelWriter; +import org.apache.maven.archiva.xml.XMLException; +import org.apache.maven.archiva.xml.XMLWriter; +import org.dom4j.Document; +import org.dom4j.DocumentHelper; +import org.dom4j.Element; +import org.dom4j.Namespace; +import org.dom4j.Node; +import org.dom4j.QName; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.Writer; +import java.util.Iterator; +import java.util.List; + +/** + * ProjectModel400Writer for Maven 2 project model v4.0.0 pom files. + * + * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> + * @version $Id$ + * + * @plexus.component + * role="org.apache.maven.archiva.repository.project.ProjectModelWriter" + * role-hint="model400" + */ +public class ProjectModel400Writer + implements ProjectModelWriter +{ + private static final Namespace DEFAULT_NAMESPACE = Namespace.get( "", "http://maven.apache.org/POM/4.0.0" ); + + public void write( ArchivaProjectModel model, File pomFile ) + throws ProjectModelException, IOException + { + FileWriter writer = null; + try + { + writer = new FileWriter( pomFile ); + write( model, writer ); + writer.flush(); + } + finally + { + IOUtils.closeQuietly( writer ); + } + } + + public void write( ArchivaProjectModel model, Writer writer ) + throws ProjectModelException, IOException + { + Document doc = DocumentHelper.createDocument(); + + Element root = DocumentHelper.createElement( "project" ); + + root.add( DEFAULT_NAMESPACE ); + root.addNamespace( "xsi", "http://www.w3.org/2001/XMLSchema-instance" ); + root.addAttribute( "xsi:schemaLocation", + "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" ); + + doc.setRootElement( root ); + + root.addElement( "modelVersion" ).setText( "4.0.0" ); + + addParent( root, model.getParentProject() ); + + addOptionalElementText( root, "groupId", model.getGroupId() ); + root.addElement( "artifactId" ).setText( model.getArtifactId() ); + + addOptionalElementText( root, "version", model.getVersion() ); + + addOptionalElementText( root, "packaging", model.getPackaging() ); + addOptionalElementText( root, "name", model.getName() ); + addOptionalElementText( root, "description", model.getDescription() ); + addOptionalElementText( root, "url", model.getUrl() ); + // TODO: add inceptionYear to ArchivaProjectModel + + addIssueManagement( root, model.getIssueManagement() ); + addCiManagement( root, model.getCiManagement() ); + addMailingLists( root, model.getMailingLists() ); + addDevelopersAndContributors( root, model.getIndividuals() ); + // TODO: add distribution management to ArchivaProjectModel + addReporting( root, model.getReports() ); + addScm( root, model.getScm() ); + + fixDefaultNamespace( root ); + + try + { + XMLWriter.write( doc, writer ); + } + catch ( XMLException e ) + { + throw new ProjectModelException( "Unable to write xml contents to writer: " + e.getMessage(), e ); + } + } + + private void addScm( Element root, Scm scm ) + { + if( scm == null ) + { + return; + } + + Element elem = root.addElement( "scm" ); + + addOptionalElementText( elem, "connection", scm.getConnection() ); + addOptionalElementText( elem, "developerConnection", scm.getDeveloperConnection() ); + addOptionalElementText( elem, "url", scm.getUrl() ); + } + + private void addReporting( Element root, List<ArtifactReference> reports ) + { + if ( CollectionUtils.isEmpty( reports ) ) + { + return; + } + + Element reporting = root.addElement( "reporting" ); + Element plugins = reporting.addElement( "plugins" ); + + for ( ArtifactReference reference : reports ) + { + Element plugin = plugins.addElement( "plugin" ); + addOptionalElementText( plugin, "groupId", reference.getGroupId() ); + addOptionalElementText( plugin, "artifactId", reference.getArtifactId() ); + addOptionalElementText( plugin, "version", reference.getVersion() ); + } + } + + private void addDevelopersAndContributors( Element root, List<Individual> individuals ) + { + if ( CollectionUtils.isEmpty( individuals ) ) + { + return; + } + + Element developers = null; + Element contributors = null; + + for ( Individual individual : individuals ) + { + if ( individual.isCommitor() ) + { + if ( developers == null ) + { + developers = root.addElement( "developers" ); + } + + Element developer = developers.addElement( "developer" ); + addOptionalElementText( developer, "id", individual.getPrincipal() ); + addIndividual( developer, individual ); + } + else + { + if ( contributors == null ) + { + contributors = root.addElement( "contributors" ); + } + + Element contributor = contributors.addElement( "contributor" ); + addIndividual( contributor, individual ); + } + } + } + + private void addIndividual( Element elem, Individual individual ) + { + addOptionalElementText( elem, "name", individual.getName() ); + addOptionalElementText( elem, "email", individual.getEmail() ); + addOptionalElementText( elem, "organization", individual.getOrganization() ); + addOptionalElementText( elem, "timezone", individual.getTimezone() ); + + if ( CollectionUtils.isNotEmpty( individual.getRoles() ) ) + { + Element roles = elem.addElement( "roles" ); + List<String> roleList = individual.getRoles(); + for ( String roleName : roleList ) + { + addOptionalElementText( roles, "role", roleName ); + } + } + } + + private void addMailingLists( Element root, List<MailingList> mailingLists ) + { + if ( CollectionUtils.isEmpty( mailingLists ) ) + { + return; + } + + Element mlists = root.addElement( "mailingLists" ); + + for ( MailingList mailingList : mailingLists ) + { + Element mlist = mlists.addElement( "mailingList" ); + addOptionalElementText( mlist, "name", mailingList.getName() ); + addOptionalElementText( mlist, "post", mailingList.getPostAddress() ); + addOptionalElementText( mlist, "subscribe", mailingList.getSubscribeAddress() ); + addOptionalElementText( mlist, "unsubscribe", mailingList.getUnsubscribeAddress() ); + addOptionalElementText( mlist, "archive", mailingList.getMainArchiveUrl() ); + } + } + + private void addCiManagement( Element root, CiManagement ciManagement ) + { + if ( ciManagement == null ) + { + return; + } + + Element elem = root.addElement( "ciManagement" ); + addOptionalElementText( elem, "system", ciManagement.getSystem() ); + addOptionalElementText( elem, "url", ciManagement.getUrl() ); + // TODO: Add notifiers into ArchivaProjectModel + } + + private void addIssueManagement( Element root, IssueManagement issueManagement ) + { + if ( issueManagement == null ) + { + return; + } + + Element elem = root.addElement( "issueManagement" ); + addOptionalElementText( elem, "system", issueManagement.getSystem() ); + addOptionalElementText( elem, "url", issueManagement.getUrl() ); + } + + private void addParent( Element root, VersionedReference parentProject ) + { + if ( parentProject == null ) + { + return; + } + + Element parent = root.addElement( "parent" ); + parent.addElement( "groupId" ).setText( parentProject.getGroupId() ); + parent.addElement( "artifactId" ).setText( parentProject.getArtifactId() ); + parent.addElement( "version" ).setText( parentProject.getVersion() ); + } + + /** + * Fix the default namespace on all elements recursively. + */ + public void fixDefaultNamespace( Element elem ) + { + elem.remove( elem.getNamespace() ); + elem.setQName( QName.get( elem.getName(), DEFAULT_NAMESPACE, elem.getQualifiedName() ) ); + + Node n; + + Iterator<Node> it = elem.elementIterator(); + while ( it.hasNext() ) + { + n = it.next(); + + switch ( n.getNodeType() ) + { + case Node.ELEMENT_NODE: + fixDefaultNamespace( (Element) n ); + break; + } + } + } + + private static void addOptionalElementText( Element elem, String elemName, String text ) + { + if ( StringUtils.isBlank( text ) ) + { + return; + } + + elem.addElement( elemName ).setText( text ); + } +} diff --git a/archiva-base/archiva-repository-layer/src/test/effective-poms/archiva-model-effective.pom b/archiva-base/archiva-repository-layer/src/test/expected-poms/archiva-model-effective.pom index 9129a9db4..9129a9db4 100644 --- a/archiva-base/archiva-repository-layer/src/test/effective-poms/archiva-model-effective.pom +++ b/archiva-base/archiva-repository-layer/src/test/expected-poms/archiva-model-effective.pom diff --git a/archiva-base/archiva-repository-layer/src/test/expected-poms/maven-parent-4.pom b/archiva-base/archiva-repository-layer/src/test/expected-poms/maven-parent-4.pom new file mode 100644 index 000000000..0c5488ee3 --- /dev/null +++ b/archiva-base/archiva-repository-layer/src/test/expected-poms/maven-parent-4.pom @@ -0,0 +1,213 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache</groupId> + <artifactId>apache</artifactId> + <version>3</version> + </parent> + <groupId>org.apache.maven</groupId> + <artifactId>maven-parent</artifactId> + <version>4</version> + <packaging>pom</packaging> + <name>Apache Maven</name> + <description>Maven is a software project management and comprehension tool. Based on the concept of a project object model (POM), Maven can manage a project's build, reporting and documentation from a central piece of information.</description> + <url>http://maven.apache.org/</url> + <issueManagement> + <system>jira</system> + <url>http://jira.codehaus.org/browse/MPA</url> + </issueManagement> + <ciManagement> + <system>continuum</system> + <url>http://maven.zones.apache.org:8080/continuum</url> + </ciManagement> + <mailingLists> + <mailingList> + <name>Maven Announcements List</name> + <post>announce@maven.apache.org</post> + <subscribe>announce-subscribe@maven.apache.org</subscribe> + <unsubscribe>announce-unsubscribe@maven.apache.org</unsubscribe> + <archive>http://mail-archives.apache.org/mod_mbox/maven-announce/</archive> + </mailingList> + <mailingList> + <name>Maven Issues List</name> + <post>issues@maven.apache.org</post> + <subscribe>issues-subscribe@maven.apache.org</subscribe> + <unsubscribe>issues-unsubscribe@maven.apache.org</unsubscribe> + <archive>http://mail-archives.apache.org/mod_mbox/maven-issues/</archive> + </mailingList> + <mailingList> + <name>Maven Notifications List</name> + <post>notifications@maven.apache.org</post> + <subscribe>notifications-subscribe@maven.apache.org</subscribe> + <unsubscribe>notifications-unsubscribe@maven.apache.org</unsubscribe> + <archive>http://mail-archives.apache.org/mod_mbox/maven-notifications/</archive> + </mailingList> + </mailingLists> + <developers> + <developer> + <name>Jason van Zyl</name> + <email>jason@maven.org</email> + <organization>ASF</organization> + <timezone>-5</timezone> + <roles> + <role>PMC Chair</role> + </roles> + </developer> + <developer> + <name>Brett Porter</name> + <email>brett@apache.org</email> + <organization>ASF</organization> + <timezone>+10</timezone> + <roles> + <role>PMC Member</role> + </roles> + </developer> + <developer> + <name>Emmanuel Venisse</name> + <email>evenisse@apache.org</email> + <organization>ASF</organization> + <timezone>+1</timezone> + <roles> + <role>PMC Member</role> + </roles> + </developer> + <developer> + <name>Kenney Westerhof</name> + <email>kenney@apache.org</email> + <organization>Neonics</organization> + <roles> + <role>PMC Member</role> + </roles> + </developer> + <developer> + <name>Stephane Nicoll</name> + <email>snicoll@apache.org</email> + <organization>ASF</organization> + <timezone>+1</timezone> + <roles> + <role>PMC Member</role> + </roles> + </developer> + <developer> + <name>Vincent Massol</name> + <email>vmassol@apache.org</email> + <organization>ASF</organization> + <timezone>+1</timezone> + <roles> + <role>PMC Member</role> + </roles> + </developer> + <developer> + <name>Fabrizio Giustina</name> + <email>fgiust@apache.org</email> + <organization>openmind</organization> + <timezone>+1</timezone> + <roles> + <role>PMC Member</role> + </roles> + </developer> + <developer> + <name>Edwin Punzalan</name> + <email>epunzalan@mergere.com</email> + <organization>Mergere</organization> + <timezone>+8</timezone> + <roles> + <role>Committer</role> + </roles> + </developer> + <developer> + <name>Mike Perham</name> + <email>mperham@gmail.com</email> + <organization>IBM</organization> + <timezone>-6</timezone> + <roles> + <role>PMC Member</role> + </roles> + </developer> + <developer> + <name>John Casey</name> + <email>jdcasey@apache.org</email> + <organization>ASF</organization> + <timezone>-5</timezone> + <roles> + <role>PMC Member</role> + </roles> + </developer> + <developer> + <name>Trygve Laugstol</name> + <email>trygvis@apache.org</email> + <organization>ASF</organization> + <timezone>+1</timezone> + <roles> + <role>PMC Member</role> + </roles> + </developer> + <developer> + <name>Vincent Siveton</name> + <email>vsiveton@apache.org</email> + <organization>ASF</organization> + <timezone>-5</timezone> + <roles> + <role>PMC Member</role> + </roles> + </developer> + <developer> + <name>Carlos Sanchez</name> + <email>carlos@apache.org</email> + <organization>ASF</organization> + <timezone>+1</timezone> + <roles> + <role>PMC Member</role> + </roles> + </developer> + <developer> + <name>Dennis Lundberg</name> + <email>dennisl@apache.org</email> + <organization>ASF</organization> + <timezone>+1</timezone> + <roles> + <role>PMC Member</role> + </roles> + </developer> + </developers> + <reporting> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-report-plugin</artifactId> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-checkstyle-plugin</artifactId> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-pmd-plugin</artifactId> + </plugin> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>cobertura-maven-plugin</artifactId> + </plugin> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>taglist-maven-plugin</artifactId> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jxr-plugin</artifactId> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-javadoc-plugin</artifactId> + </plugin> + </plugins> + </reporting> + <scm> + <connection>scm:svn:http://svn.apache.org/repos/asf/maven/pom/maven/tags/maven-parent-4</connection> + <developerConnection>scm:svn:https://svn.apache.org/repos/asf/maven/pom/maven/tags/maven-parent-4</developerConnection> + <url>http://svn.apache.org/viewvc/maven/pom/maven/tags/maven-parent-4</url> + </scm> +</project> + diff --git a/archiva-base/archiva-repository-layer/src/test/expected-poms/model-write-400-simple.pom b/archiva-base/archiva-repository-layer/src/test/expected-poms/model-write-400-simple.pom new file mode 100644 index 000000000..213765a92 --- /dev/null +++ b/archiva-base/archiva-repository-layer/src/test/expected-poms/model-write-400-simple.pom @@ -0,0 +1,9 @@ +<?xml version="1.0" ?> + +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <groupId>org.apache.archiva.test</groupId> + <artifactId>simple-model-write</artifactId> + <version>1.0</version> +</project> diff --git a/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/project/writers/ProjectModel400WriterTest.java b/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/project/writers/ProjectModel400WriterTest.java new file mode 100644 index 000000000..23d95e40e --- /dev/null +++ b/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/project/writers/ProjectModel400WriterTest.java @@ -0,0 +1,147 @@ +package org.apache.maven.archiva.repository.project.writers; + +/* + * 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.commons.beanutils.PropertyUtils; +import org.apache.commons.io.FileUtils; +import org.apache.maven.archiva.model.ArchivaProjectModel; +import org.apache.maven.archiva.repository.project.ProjectModelException; +import org.apache.maven.archiva.repository.project.ProjectModelReader; +import org.apache.maven.archiva.repository.project.ProjectModelWriter; +import org.apache.maven.archiva.repository.project.readers.ProjectModel400Reader; +import org.codehaus.plexus.PlexusTestCase; +import org.custommonkey.xmlunit.DetailedDiff; +import org.custommonkey.xmlunit.Diff; +import org.dom4j.Document; +import org.dom4j.DocumentType; +import org.dom4j.Element; +import org.dom4j.Namespace; +import org.dom4j.io.SAXReader; +import org.dom4j.io.XMLWriter; + +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.io.StringWriter; +import java.util.Map; + +/** + * ProjectModel400WriterTest + * + * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> + * @version $Id$ + */ +public class ProjectModel400WriterTest + extends PlexusTestCase +{ + private static final String DEFAULT_REPOSITORY = "src/test/repositories/default-repository"; + + private ProjectModelWriter modelWriter; + + @Override + protected void setUp() + throws Exception + { + super.setUp(); + + modelWriter = (ProjectModelWriter) lookup( ProjectModelWriter.class, "model400" ); + } + + public void testSimpleWrite() + throws Exception + { + ArchivaProjectModel model = new ArchivaProjectModel(); + model.setGroupId( "org.apache.archiva.test" ); + model.setArtifactId( "simple-model-write" ); + model.setVersion( "1.0" ); + + String actualModel = writeToString( model ); + String expectedModel = getExpectedModelString( "model-write-400-simple.pom" ); + + assertModelSimilar( expectedModel, actualModel ); + } + + public void testReadWriteSimple() + throws Exception + { + String pathToModel = DEFAULT_REPOSITORY + "/org/apache/maven/A/1.0/A-1.0.pom"; + ArchivaProjectModel model = createArchivaProjectModel( pathToModel ); + + String actualModel = writeToString( model ); + String expectedModel = FileUtils.readFileToString( new File( pathToModel ), null ); + + assertModelSimilar( expectedModel, actualModel ); + } + + public void testReadWriteComplex() + throws Exception + { + ArchivaProjectModel model = createArchivaProjectModel( DEFAULT_REPOSITORY + + "/org/apache/maven/maven-parent/4/maven-parent-4.pom" ); + + String actualModel = writeToString( model ); + String expectedModel = getExpectedModelString( "maven-parent-4.pom" ); + + assertModelSimilar( expectedModel, actualModel ); + } + + private void assertModelSimilar( String expectedModel, String actualModel ) + throws Exception + { + Diff diff = new Diff( expectedModel, actualModel ); + DetailedDiff detailedDiff = new DetailedDiff( diff ); + if ( !detailedDiff.similar() ) + { + // If it isn't similar, dump the difference. + System.out.println( detailedDiff.toString() ); + System.out.println( "-- Actual Model --\n" + actualModel + "\n---------------\n\n" ); + System.out.println( "-- Expected Model --\n" + expectedModel + "\n---------------\n\n" ); + + assertEquals( expectedModel, actualModel ); + } + } + + private String getExpectedModelString( String pomfilename ) + throws IOException + { + File pomFile = getTestFile( "src/test/expected-poms/" + pomfilename ); + return FileUtils.readFileToString( pomFile, null ); + } + + private ArchivaProjectModel createArchivaProjectModel( String path ) + throws ProjectModelException + { + ProjectModelReader reader = new ProjectModel400Reader(); + + File pomFile = new File( getBasedir(), path ); + + return reader.read( pomFile ); + } + + private String writeToString( ArchivaProjectModel model ) + throws ProjectModelException, IOException + { + StringWriter writer = new StringWriter(); + + modelWriter.write( model, writer ); + + return writer.toString(); + } +} diff --git a/archiva-base/archiva-repository-layer/src/test/repositories/default-repository/org/apache/maven/test/2.0.4-SNAPSHOT/test-2.0.4-SNAPSHOT.pom b/archiva-base/archiva-repository-layer/src/test/repositories/default-repository/org/apache/maven/test/2.0.4-SNAPSHOT/test-2.0.4-SNAPSHOT.pom new file mode 100644 index 000000000..a6707223e --- /dev/null +++ b/archiva-base/archiva-repository-layer/src/test/repositories/default-repository/org/apache/maven/test/2.0.4-SNAPSHOT/test-2.0.4-SNAPSHOT.pom @@ -0,0 +1,142 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>org.apache.maven</groupId> + <artifactId>test</artifactId> + <packaging>pom</packaging> + <version> + ${prj.ver.maj}.${prj.ver.min}.${prj.ver.inc}${prj.ver.suf} + </version> + + <name>Test Archiva</name> + <description> + ${pom.name} [version ${pom.version}]. Confluence: + ${kb.confluence.url}/display/${prj.confluence.path} + </description> + + <build> + <extensions> + <extension> + <groupId>org.apache.maven.wagon</groupId> + + <artifactId>wagon-webdav</artifactId> + <version>1.0-beta-2</version> + </extension> + </extensions> + </build> + + <issueManagement> + <system>jira</system> + + <url>${kb.jira.url}/browse/${prj.jira.key}</url> + </issueManagement> + <ciManagement> + <system>hudson</system> + <url> + ${kb.hudson.url}/view/${prj.hudson.view.root} + -=${prj.svn.branch}=-/ + </url> + </ciManagement> + <inceptionYear>2005</inceptionYear> + + <licenses> + <license> + <name>KB Internal License</name> + <distribution>repo</distribution> + <comments>This is internal project of KB.</comments> + </license> + </licenses> + + <organization> + <name>KB, a.s.</name> + <url>http://www.kb.cz/</url> + </organization> + + <properties> + <!-- + - common settings + --> + <kb.svn.url>http://svn-server/renaissance</kb.svn.url> + + <kb.svn.view.url>http://svn-server/renaissance</kb.svn.view.url> + <kb.site.url>http://tools-server/projects</kb.site.url> + <kb.site.dir> + scp://tools-server/home/tools/var/maven-sites + </kb.site.dir> + <kb.jira.url>http://jira-server/jira</kb.jira.url> + <kb.confluence.url> + http://confluence-server/confluence + </kb.confluence.url> + <kb.hudson.url>http://tools-server/hudson</kb.hudson.url> + + <!-- Project configuration --> + <prj.url.root>${pom.groupId}</prj.url.root> + <prj.hudson.view.root>${pom.groupId}</prj.hudson.view.root> + <prj.svn>${kb.svn.url}/${prj.svn.path}</prj.svn> + <prj.svn.tagBase>${prj.svn}/tags</prj.svn.tagBase> + <prj.svn.branch>trunk</prj.svn.branch> + + <prj.java.version>1.5</prj.java.version> + <prj.source.encoding>UTF-8</prj.source.encoding> + + <!-- + - Project specific + --> + <!-- version --> + <prj.ver.maj>2</prj.ver.maj> + <prj.ver.min>0</prj.ver.min> + <prj.ver.inc>4</prj.ver.inc> + <prj.ver.suf>-SNAPSHOT</prj.ver.suf><!-- !!! Increase this value after release. --> + + <!-- paths and identificators in external systems --> + <prj.url.relative> + ${prj.url.root}/${prj.ver.maj}.${prj.ver.min}${prj.ver.suf} + </prj.url.relative> + <prj.svn.path>test/maven-arch/test-arch</prj.svn.path> + <prj.jira.key>TSTARCH</prj.jira.key> + + <prj.confluence.path>TEST/Archiva</prj.confluence.path> + </properties> + + <url>${kb.site.url}/${prj.url.relative}</url> + + <scm> + <connection>scm:svn:${prj.svn}/${prj.svn.branch}</connection> + <developerConnection> + scm:svn:${prj.svn}/${prj.svn.branch} + </developerConnection> + + <url>${kb.svn.view.url}/${prj.svn.path}/${prj.svn.branch}</url> + </scm> + + <distributionManagement> + <repository> + <id>internal</id> + <name>Internal Release Repository</name> + <url> + dav:http://tools-server/archiva/repository/internal + </url> + + <uniqueVersion>false</uniqueVersion> + </repository> + <snapshotRepository> + <id>snapshots</id> + <name>Internal Snapshot Repository</name> + <url> + dav:http://tools-server/archiva/repository/snapshots + </url> + <uniqueVersion>false</uniqueVersion> + + </snapshotRepository> + <site> + <id>website</id> + <name>Internal Maven Website</name> + <url>${kb.site.dir}/${prj.url.relative}</url> + </site> + </distributionManagement> + +</project> |