mirror of https://github.com/apache/maven.git
o Fixing MNG-90:
- Improved the SCM part of the ModelInheritanceAssembler o Fixing some eclipse warnings and adding some licenses. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163191 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
91baa6e9b8
commit
74c818888a
|
@ -21,8 +21,6 @@ import java.io.FileNotFoundException;
|
|||
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.Dependency;
|
|||
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 @@ public class DefaultMavenProjectBuilder
|
|||
|
||||
private ModelValidator validator;
|
||||
|
||||
private MavenXpp3Writer modelWriter;
|
||||
|
||||
private MavenXpp3Reader modelReader;
|
||||
|
||||
private PathTranslator pathTranslator;
|
||||
|
@ -78,8 +73,6 @@ public class DefaultMavenProjectBuilder
|
|||
public void initialize()
|
||||
throws Exception
|
||||
{
|
||||
modelWriter = new MavenXpp3Writer();
|
||||
|
||||
modelReader = new MavenXpp3Reader();
|
||||
}
|
||||
|
||||
|
@ -127,7 +120,7 @@ public class DefaultMavenProjectBuilder
|
|||
superModel.getRepositories() );
|
||||
|
||||
Model previous = superModel;
|
||||
|
||||
|
||||
for ( Iterator i = lineage.iterator(); i.hasNext(); )
|
||||
{
|
||||
Model current = ( (MavenProject) i.next() ).getModel();
|
||||
|
@ -146,6 +139,9 @@ public class DefaultMavenProjectBuilder
|
|||
project.setFile( parent.getFile() );
|
||||
project.setParent( parent );
|
||||
project.setType( previous.getType() );
|
||||
|
||||
// TODO: This shouldn't be necessary
|
||||
project.setScm( previous.getScm() );
|
||||
}
|
||||
|
||||
project.setLocalRepository( localRepository );
|
||||
|
@ -315,22 +311,6 @@ public class DefaultMavenProjectBuilder
|
|||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort a list of projects.
|
||||
* <ul>
|
||||
|
|
|
@ -16,15 +16,18 @@ package org.apache.maven.project.inheritance;
|
|||
* 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 <a href="mailto:jason@maven.org">Jason van Zyl </a>
|
||||
|
@ -120,9 +123,40 @@ public class DefaultModelInheritanceAssembler
|
|||
}
|
||||
|
||||
// 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 @@ public class DefaultModelInheritanceAssembler
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
/* Created on Aug 23, 2004 */
|
||||
package org.apache.maven.project.inheritance;
|
||||
|
||||
/*
|
||||
|
@ -17,23 +16,27 @@ package org.apache.maven.project.inheritance;
|
|||
* 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 @@ public class DefaultModelInheritanceAssemblerTest
|
|||
parent.addPostGoal(postGoal1);
|
||||
|
||||
Model child = new Model();
|
||||
|
||||
|
||||
child.setType( "plugin" );
|
||||
|
||||
Build childBuild = new Build();
|
||||
|
@ -100,8 +103,6 @@ public class DefaultModelInheritanceAssemblerTest
|
|||
|
||||
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 @@ public class DefaultModelInheritanceAssemblerTest
|
|||
|
||||
assertEquals("1 postGoal should be inherited from parent", 1, child.getPostGoals().size());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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,13 +1,26 @@
|
|||
/*
|
||||
* CopyrightPlugin (c) 2004 Your Corporation. All Rights Reserved.
|
||||
*/
|
||||
package org.apache.maven.project.inheritance;
|
||||
|
||||
/*
|
||||
* 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 java.io.File;
|
||||
|
||||
import org.apache.maven.MavenTestCase;
|
||||
import org.apache.maven.project.MavenProjectBuilder;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
|
||||
* @version $Id$
|
||||
|
|
|
@ -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,8 +1,21 @@
|
|||
/*
|
||||
* CopyrightPlugin (c) 2004 Your Corporation. All Rights Reserved.
|
||||
*/
|
||||
package org.apache.maven.project.inheritance.t01;
|
||||
|
||||
/*
|
||||
* 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.project.MavenProject;
|
||||
import org.apache.maven.project.inheritance.ProjectInheritanceTestCase;
|
||||
|
||||
|
|
Loading…
Reference in New Issue