Return-Path: Delivered-To: apmail-maven-m2-dev-archive@www.apache.org Received: (qmail 78779 invoked from network); 11 Oct 2004 22:56:56 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 11 Oct 2004 22:56:56 -0000 Received: (qmail 51044 invoked by uid 500); 11 Oct 2004 22:56:52 -0000 Delivered-To: apmail-maven-m2-dev-archive@maven.apache.org Received: (qmail 51020 invoked by uid 500); 11 Oct 2004 22:56:51 -0000 Mailing-List: contact m2-dev-help@maven.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: List-Id: "Maven 2 Developers List" Reply-To: "Maven 2 Developers List" Delivered-To: mailing list m2-dev@maven.apache.org Received: (qmail 50997 invoked by uid 500); 11 Oct 2004 22:56:51 -0000 Delivered-To: apmail-maven-components-cvs@apache.org Received: (qmail 50981 invoked by uid 99); 11 Oct 2004 22:56:51 -0000 X-ASF-Spam-Status: No, hits=-10.0 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Mon, 11 Oct 2004 15:56:49 -0700 Received: (qmail 78736 invoked by uid 1849); 11 Oct 2004 22:56:48 -0000 Date: 11 Oct 2004 22:56:48 -0000 Message-ID: <20041011225648.78735.qmail@minotaur.apache.org> From: trygvis@apache.org To: maven-components-cvs@apache.org Subject: cvs commit: maven-components/maven-core/src/test/java/org/apache/maven/project/inheritance/t01 ProjectInheritanceTest.java X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N trygvis 2004/10/11 15:56:48 Modified: . mboot.jar maven-core/src/main/java/org/apache/maven/project DefaultMavenProjectBuilder.java maven-core/src/main/java/org/apache/maven/project/inheritance DefaultModelInheritanceAssembler.java maven-core/src/test/java/org/apache/maven/project/inheritance DefaultModelInheritanceAssemblerTest.java ProjectInheritanceTestCase.java maven-core/src/test/java/org/apache/maven/project/inheritance/t00 ProjectInheritanceTest.java maven-core/src/test/java/org/apache/maven/project/inheritance/t01 ProjectInheritanceTest.java Log: o Fixing MNG-90: - Improved the SCM part of the ModelInheritanceAssembler o Fixing some eclipse warnings and adding some licenses. Revision Changes Path 1.36 +29 -29 maven-components/mboot.jar <> 1.20 +4 -24 maven-components/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java Index: DefaultMavenProjectBuilder.java =================================================================== RCS file: /home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- DefaultMavenProjectBuilder.java 9 Oct 2004 00:25:37 -0000 1.19 +++ DefaultMavenProjectBuilder.java 11 Oct 2004 22:56:47 -0000 1.20 @@ -21,8 +21,6 @@ import java.io.FileReader; import java.io.InputStreamReader; import java.io.Reader; -import java.io.StringReader; -import java.io.StringWriter; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; @@ -43,7 +41,6 @@ import org.apache.maven.model.Model; import org.apache.maven.model.Parent; import org.apache.maven.model.io.xpp3.MavenXpp3Reader; -import org.apache.maven.model.io.xpp3.MavenXpp3Writer; import org.apache.maven.project.inheritance.ModelInheritanceAssembler; import org.apache.maven.project.path.PathTranslator; import org.apache.maven.project.validation.ModelValidationResult; @@ -69,8 +66,6 @@ private ModelValidator validator; - private MavenXpp3Writer modelWriter; - private MavenXpp3Reader modelReader; private PathTranslator pathTranslator; @@ -78,8 +73,6 @@ public void initialize() throws Exception { - modelWriter = new MavenXpp3Writer(); - modelReader = new MavenXpp3Reader(); } @@ -127,7 +120,7 @@ superModel.getRepositories() ); Model previous = superModel; - + for ( Iterator i = lineage.iterator(); i.hasNext(); ) { Model current = ( (MavenProject) i.next() ).getModel(); @@ -146,6 +139,9 @@ project.setFile( parent.getFile() ); project.setParent( parent ); project.setType( previous.getType() ); + + // TODO: This shouldn't be necessary + project.setScm( previous.getScm() ); } project.setLocalRepository( localRepository ); @@ -313,22 +309,6 @@ } return artifact.getFile(); - } - - private Model interpolateModel( Model model, Map map ) - throws Exception - { - return modelReader.read( new StringReader( StringUtils.interpolate( getProjectString( model ), map ) ) ); - } - - private String getProjectString( Model project ) - throws Exception - { - StringWriter writer = new StringWriter(); - - modelWriter.write( writer, project ); - - return writer.toString(); } /** 1.10 +40 -6 maven-components/maven-core/src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java Index: DefaultModelInheritanceAssembler.java =================================================================== RCS file: /home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- DefaultModelInheritanceAssembler.java 1 Oct 2004 14:53:47 -0000 1.9 +++ DefaultModelInheritanceAssembler.java 11 Oct 2004 22:56:47 -0000 1.10 @@ -16,15 +16,18 @@ * limitations under the License. */ +import java.util.Iterator; +import java.util.List; + import org.apache.maven.model.Dependency; import org.apache.maven.model.Model; +import org.apache.maven.model.Plugin; import org.apache.maven.model.PostGoal; import org.apache.maven.model.PreGoal; import org.apache.maven.model.Repository; -import org.apache.maven.model.Plugin; +import org.apache.maven.model.Scm; -import java.util.Iterator; -import java.util.List; +import org.codehaus.plexus.util.StringUtils; /** * @author Jason van Zyl @@ -120,9 +123,40 @@ } // Scm - if ( child.getScm() == null ) + if ( parent.getScm() != null ) { - child.setScm( parent.getScm() ); + Scm parentScm = parent.getScm(); + + Scm childScm = child.getScm(); + + if ( childScm == null ) + { + childScm = new Scm(); + + child.setScm( childScm ); + } + + if ( StringUtils.isEmpty( childScm.getConnection() ) && + !StringUtils.isEmpty( parentScm.getConnection() ) ) + { + childScm.setConnection( parentScm.getConnection() + "/" + child.getArtifactId() ); + } + + if ( StringUtils.isEmpty( childScm.getDeveloperConnection() ) && + !StringUtils.isEmpty( parentScm.getDeveloperConnection() ) ) + { + childScm.setDeveloperConnection( parentScm.getDeveloperConnection() + "/" + child.getArtifactId() ); + } + + if ( StringUtils.isEmpty( childScm.getUrl() ) ) + { + childScm.setUrl( parentScm.getUrl() ); + } + + if ( parentScm.getBranches() != null ) + { + childScm.getBranches().addAll( parentScm.getBranches() ); + } } // developers @@ -283,4 +317,4 @@ } } } -} \ No newline at end of file +} 1.7 +185 -8 maven-components/maven-core/src/test/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssemblerTest.java Index: DefaultModelInheritanceAssemblerTest.java =================================================================== RCS file: /home/cvs/maven-components/maven-core/src/test/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssemblerTest.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- DefaultModelInheritanceAssemblerTest.java 22 Sep 2004 02:58:11 -0000 1.6 +++ DefaultModelInheritanceAssemblerTest.java 11 Oct 2004 22:56:47 -0000 1.7 @@ -1,4 +1,3 @@ -/* Created on Aug 23, 2004 */ package org.apache.maven.project.inheritance; /* @@ -17,23 +16,27 @@ * limitations under the License. */ +import java.util.Arrays; +import java.util.List; + import junit.framework.TestCase; + import org.apache.maven.model.Build; import org.apache.maven.model.Model; import org.apache.maven.model.PostGoal; import org.apache.maven.model.PreGoal; import org.apache.maven.model.Resource; +import org.apache.maven.model.Scm; import org.apache.maven.model.UnitTest; -import java.util.Arrays; -import java.util.List; - /** * @author jdcasey */ public class DefaultModelInheritanceAssemblerTest extends TestCase { + private ModelInheritanceAssembler assembler = new DefaultModelInheritanceAssembler(); + public void testShouldOverrideUnitTestExcludesOnly() { Model parent = new Model(); @@ -82,7 +85,7 @@ parent.addPostGoal(postGoal1); Model child = new Model(); - + child.setType( "plugin" ); Build childBuild = new Build(); @@ -100,8 +103,6 @@ child.addPreGoal(preGoal2); - ModelInheritanceAssembler assembler = new DefaultModelInheritanceAssembler(); - assembler.assembleModelInheritance( child, parent ); assertEquals( "source directory should be from parent", "src/main/java", child.getBuild().getSourceDirectory() ); @@ -138,4 +139,180 @@ assertEquals("1 postGoal should be inherited from parent", 1, child.getPostGoals().size()); } -} \ No newline at end of file + + /** + * root + * |--artifact1 + * | | + * | |--artifact1-1 + * | + * |--artifact2 (in another directory called a2 so it has it's own scm section) + * | + * |--artifact2-1 + * + */ + public void testScmInheritance() + throws Exception + { + // Make the models + Model root = makeScmModel( "root", "scm:foo:/scm-root", "scm:foo:/scm-dev-root", null ); + + Model artifact1 = makeScmModel( "artifact1" ); + + Model artifact1_1 = makeScmModel( "artifact1-1" ); + + Model artifact2 = makeScmModel( "artifact2", "scm:foo:/scm-root/yay-artifact2", "scm:foo:/scm-dev-root/yay-artifact2", null ); + + Model artifact2_1 = makeScmModel( "artifact2-1" ); + + // Assemble + assembler.assembleModelInheritance( artifact1, root ); + + assembler.assembleModelInheritance( artifact1_1, artifact1 ); + + assembler.assembleModelInheritance( artifact2, root ); + + assembler.assembleModelInheritance( artifact2_1, artifact2 ); + + // --- -- - + + assertConnection( "scm:foo:/scm-root/artifact1", "scm:foo:/scm-dev-root/artifact1", artifact1 ); + + assertConnection( "scm:foo:/scm-root/artifact1/artifact1-1", "scm:foo:/scm-dev-root/artifact1/artifact1-1", artifact1_1 ); + + assertConnection( "scm:foo:/scm-root/yay-artifact2", "scm:foo:/scm-dev-root/yay-artifact2", artifact2 ); + + assertConnection( "scm:foo:/scm-root/yay-artifact2/artifact2-1", "scm:foo:/scm-dev-root/yay-artifact2/artifact2-1", artifact2_1 ); + } + + public void testScmInheritanceWhereParentHasConnectionAndTheChildDoesnt() + { + Model parent = makeScmModel( "parent", "scm:foo:bar:/scm-root", null, null ); + + Model child = makeScmModel( "child" ); + + assembler.assembleModelInheritance( child, parent ); + + assertScm( "scm:foo:bar:/scm-root/child", null, null, child.getScm() ); + } + + public void testScmInheritanceWhereParentHasConnectionAndTheChildDoes() + { + Model parent = makeScmModel( "parent", "scm:foo:bar:/scm-root", null, null ); + + Model child = makeScmModel( "child", "scm:foo:bar:/another-root", null, null ); + + assembler.assembleModelInheritance( child, parent ); + + assertScm( "scm:foo:bar:/another-root", null, null, child.getScm() ); + } + + public void testScmInheritanceWhereParentHasDeveloperConnectionAndTheChildDoesnt() + { + Model parent = makeScmModel( "parent", null, "scm:foo:bar:/scm-dev-root", null ); + + Model child = makeScmModel( "child" ); + + assembler.assembleModelInheritance( child, parent ); + + assertScm( null, "scm:foo:bar:/scm-dev-root/child", null, child.getScm() ); + } + + public void testScmInheritanceWhereParentHasDeveloperConnectionAndTheChildDoes() + { + Model parent = makeScmModel( "parent", null, "scm:foo:bar:/scm-dev-root", null ); + + Model child = makeScmModel( "child", null, "scm:foo:bar:/another-dev-root", null ); + + assembler.assembleModelInheritance( child, parent ); + + assertScm( null, "scm:foo:bar:/another-dev-root", null, child.getScm() ); + } + + public void testScmInheritanceWhereParentHasUrlAndTheChildDoesnt() + { + Model parent = makeScmModel( "parent", null, null, "http://foo/bar" ); + + Model child = makeScmModel( "child" ); + + assembler.assembleModelInheritance( child, parent ); + + assertScm( null, null, "http://foo/bar", child.getScm() ); + } + + public void testScmInheritanceWhereParentHasUrlAndTheChildDoes() + { + Model parent = makeScmModel( "parent", null, null, "http://foo/bar" ); + + Model child = makeScmModel( "child", null, null, "http://bar/foo" ); + + assembler.assembleModelInheritance( child, parent ); + + assertScm( null, null, "http://bar/foo", child.getScm() ); + } + + // ---------------------------------------------------------------------- + // + // ---------------------------------------------------------------------- + + private void assertConnection( String expectedConnection, String expectedDeveloperConnection, Model model ) + { + String connection = model.getScm().getConnection(); + + assertNotNull( connection ); + + assertEquals( expectedConnection, connection ); + + String developerConnection = model.getScm().getDeveloperConnection(); + + assertNotNull( developerConnection ); + + assertEquals( expectedDeveloperConnection, developerConnection ); + } + + public void assertScm( String connection, String developerConnection, String url, Scm scm ) + { + assertNotNull( scm ); + + assertEquals( connection, scm.getConnection() ); + + assertEquals( developerConnection, scm.getDeveloperConnection() ); + + assertEquals( url, scm.getUrl() ); + + assertNotNull( scm.getBranches() ); + + assertEquals( 0, scm.getBranches().size() ); + } + + private Model makeScmModel( String artifactId ) + { + return makeScmModel( artifactId, null, null, null ); + } + + private Model makeScmModel( String artifactId, String connection, String developerConnection, String url ) + { + Model model = new Model(); + + model.setModelVersion( "4.0.0" ); + + model.setGroupId( "maven" ); + + model.setArtifactId( artifactId ); + + if ( connection != null || developerConnection != null || url != null ) + { + Scm scm = new Scm(); + + scm.setConnection( connection ); + + scm.setDeveloperConnection( developerConnection ); + + scm.setUrl( url ); + + model.setScm( scm ); + } + + return model; + } +} 1.5 +18 -5 maven-components/maven-core/src/test/java/org/apache/maven/project/inheritance/ProjectInheritanceTestCase.java Index: ProjectInheritanceTestCase.java =================================================================== RCS file: /home/cvs/maven-components/maven-core/src/test/java/org/apache/maven/project/inheritance/ProjectInheritanceTestCase.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- ProjectInheritanceTestCase.java 8 Oct 2004 19:15:01 -0000 1.4 +++ ProjectInheritanceTestCase.java 11 Oct 2004 22:56:47 -0000 1.5 @@ -1,12 +1,25 @@ +package org.apache.maven.project.inheritance; + /* - * CopyrightPlugin (c) 2004 Your Corporation. All Rights Reserved. + * Copyright 2001-2004 The Apache Software Foundation. + * + * Licensed 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. */ -package org.apache.maven.project.inheritance; + +import java.io.File; import org.apache.maven.MavenTestCase; import org.apache.maven.project.MavenProjectBuilder; - -import java.io.File; /** * @author Jason van Zyl 1.4 +17 -1 maven-components/maven-core/src/test/java/org/apache/maven/project/inheritance/t00/ProjectInheritanceTest.java Index: ProjectInheritanceTest.java =================================================================== RCS file: /home/cvs/maven-components/maven-core/src/test/java/org/apache/maven/project/inheritance/t00/ProjectInheritanceTest.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- ProjectInheritanceTest.java 8 Oct 2004 19:15:02 -0000 1.3 +++ ProjectInheritanceTest.java 11 Oct 2004 22:56:47 -0000 1.4 @@ -1,5 +1,21 @@ package org.apache.maven.project.inheritance.t00; +/* + * Copyright 2001-2004 The Apache Software Foundation. + * + * Licensed 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.model.MailingList; import org.apache.maven.project.MavenProject; import org.apache.maven.project.inheritance.ProjectInheritanceTestCase; 1.5 +16 -3 maven-components/maven-core/src/test/java/org/apache/maven/project/inheritance/t01/ProjectInheritanceTest.java Index: ProjectInheritanceTest.java =================================================================== RCS file: /home/cvs/maven-components/maven-core/src/test/java/org/apache/maven/project/inheritance/t01/ProjectInheritanceTest.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- ProjectInheritanceTest.java 8 Oct 2004 19:15:02 -0000 1.4 +++ ProjectInheritanceTest.java 11 Oct 2004 22:56:47 -0000 1.5 @@ -1,7 +1,20 @@ +package org.apache.maven.project.inheritance.t01; + /* - * CopyrightPlugin (c) 2004 Your Corporation. All Rights Reserved. + * Copyright 2001-2004 The Apache Software Foundation. + * + * Licensed 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. */ -package org.apache.maven.project.inheritance.t01; import org.apache.maven.project.MavenProject; import org.apache.maven.project.inheritance.ProjectInheritanceTestCase;