Various model processors.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@751882 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Britton Isbell 2009-03-09 22:23:33 +00:00
parent c3f3464a57
commit e552b225fc
22 changed files with 823 additions and 416 deletions

View File

@ -0,0 +1,70 @@
package org.apache.maven.project.processor;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import org.apache.maven.model.CiManagement;
import org.apache.maven.model.Model;
import org.apache.maven.model.Notifier;
public class CiManagementProcessor
extends BaseProcessor
{
public void process( Object parent, Object child, Object target, boolean isChildMostSpecialized )
{
super.process( parent, child, target, isChildMostSpecialized );
Model t = (Model) target;
Model c = (Model) child;
Model p = (Model) parent;
if ( c.getCiManagement() != null )
{
CiManagement childMng = c.getCiManagement();
CiManagement mng = new CiManagement();
mng.setSystem( childMng.getSystem() );
mng.setUrl( childMng.getUrl() );
t.setCiManagement( mng );
addNotifiers( c.getCiManagement().getNotifiers(), t.getCiManagement() );
}
else if ( p != null && p.getCiManagement() != null )
{
CiManagement parentMng = p.getCiManagement();
CiManagement mng = new CiManagement();
mng.setSystem( parentMng.getSystem() );
mng.setUrl( parentMng.getUrl() );
t.setCiManagement( mng );
addNotifiers( p.getCiManagement().getNotifiers(), t.getCiManagement() );
}
}
private static void addNotifiers( List<Notifier> notifiers, CiManagement ciManagement )
{
if ( notifiers == null )
{
return;
}
List<Notifier> n = new ArrayList<Notifier>();
for ( Notifier notifier : notifiers )
{
Notifier notifierCopy = new Notifier();
Properties properties = new Properties();
properties.putAll( notifier.getConfiguration() );
notifierCopy.setConfiguration( properties );
notifierCopy.setAddress( notifier.getAddress() );
notifierCopy.setSendOnError( notifier.isSendOnError() );
notifierCopy.setSendOnFailure( notifier.isSendOnFailure() );
notifierCopy.setSendOnSuccess( notifier.isSendOnSuccess() );
notifierCopy.setSendOnWarning( notifier.isSendOnWarning() );
notifierCopy.setType( notifier.getType() );
n.add( notifierCopy );
}
ciManagement.getNotifiers().addAll( n );
}
}

View File

@ -20,10 +20,10 @@ public class DependenciesProcessor
{
p = (Model) parent;
}
List<Dependency> dependencies = ((Model) target).getDependencies();
List<Dependency> dependencies = ( (Model) target ).getDependencies();
DependencyProcessor processor = new DependencyProcessor();
if ( ( p == null || p.getDependencies().isEmpty() ) && !c.getDependencies().isEmpty())
if ( ( p == null || p.getDependencies().isEmpty() ) && !c.getDependencies().isEmpty() )
{
for ( Dependency dependency : c.getDependencies() )
{
@ -39,9 +39,9 @@ public class DependenciesProcessor
{
for ( Dependency d2 : p.getDependencies() )
{
if(match(d1, d2))
{
processor.process( d2, d1, dependencies, isChildMostSpecialized );//JOIN
if ( match( d1, d2 ) )
{
processor.process( d2, d1, dependencies, isChildMostSpecialized );// JOIN
}
else
{
@ -50,22 +50,22 @@ public class DependenciesProcessor
}
}
}
for(Dependency d2 : parentDependencies)
for ( Dependency d2 : parentDependencies )
{
processor.process( d2, null, dependencies, isChildMostSpecialized );
processor.process( d2, null, dependencies, isChildMostSpecialized );
}
}
else
{
for(Dependency d2 : p.getDependencies())
for ( Dependency d2 : p.getDependencies() )
{
processor.process( d2, null, dependencies, isChildMostSpecialized );
}
processor.process( d2, null, dependencies, isChildMostSpecialized );
}
}
}
}
private static boolean match( Dependency d1, Dependency d2 )
{
// TODO: Version ranges ?
@ -86,5 +86,5 @@ public class DependenciesProcessor
":" ).append(
d.getClassifier() );
return sb.toString();
}
}
}

View File

@ -0,0 +1,6 @@
package org.apache.maven.project.processor;
public class DependencyManagementProcessor
{
}

View File

@ -5,82 +5,84 @@ import java.util.List;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Exclusion;
public class DependencyProcessor extends BaseProcessor
public class DependencyProcessor
extends BaseProcessor
{
public void process( Object parent, Object child, Object target, boolean isChildMostSpecialized )
{
super.process( parent, child, target, isChildMostSpecialized );
List<Dependency> t = (List<Dependency>) target;
if (parent == null && child == null)
if ( parent == null && child == null )
{
return;
}
else if(parent == null && child != null)
else if ( parent == null && child != null )
{
Dependency targetDependency = new Dependency();
copy( (Dependency) child, targetDependency);
t.add( targetDependency );
}
else if( parent != null && child == null)
{
Dependency targetDependency = new Dependency();
copy( (Dependency) parent, targetDependency);
copy( (Dependency) child, targetDependency );
t.add( targetDependency );
}
else //JOIN
else if ( parent != null && child == null )
{
Dependency targetDependency = new Dependency();
copy( (Dependency) child, targetDependency);
copy( (Dependency) parent, targetDependency);
copy( (Dependency) parent, targetDependency );
t.add( targetDependency );
}
else
// JOIN
{
Dependency targetDependency = new Dependency();
copy( (Dependency) child, targetDependency );
copy( (Dependency) parent, targetDependency );
t.add( targetDependency );
}
}
private static void copy(Dependency dependency, Dependency targetDependency)
private static void copy( Dependency dependency, Dependency targetDependency )
{
if(targetDependency.getArtifactId() == null)
if ( targetDependency.getArtifactId() == null )
{
targetDependency.setArtifactId( dependency.getArtifactId() );
}
if(targetDependency.getClassifier() == null)
if ( targetDependency.getClassifier() == null )
{
targetDependency.setClassifier( dependency.getClassifier() );
}
if(targetDependency.getGroupId() == null)
if ( targetDependency.getGroupId() == null )
{
targetDependency.setGroupId(dependency.getGroupId());
targetDependency.setGroupId( dependency.getGroupId() );
}
if( targetDependency.getScope() == null)
if ( targetDependency.getScope() == null )
{
targetDependency.setScope( dependency.getScope() );
}
if(targetDependency.getSystemPath() == null)
if ( targetDependency.getSystemPath() == null )
{
targetDependency.setSystemPath( dependency.getSystemPath() );
}
if( targetDependency.getType() == null )
if ( targetDependency.getType() == null )
{
targetDependency.setType( dependency.getType() );
}
if(targetDependency.getVersion() == null)
if ( targetDependency.getVersion() == null )
{
targetDependency.setVersion( dependency.getVersion() );
}
if(!dependency.getExclusions().isEmpty())
if ( !dependency.getExclusions().isEmpty() )
{
List<Exclusion> targetExclusions = targetDependency.getExclusions();
for(Exclusion e : dependency.getExclusions())
for ( Exclusion e : dependency.getExclusions() )
{
if(!containsExclusion(e, targetExclusions))
if ( !containsExclusion( e, targetExclusions ) )
{
Exclusion e1 = new Exclusion();
e1.setArtifactId( e.getArtifactId() );
@ -90,16 +92,17 @@ public class DependencyProcessor extends BaseProcessor
}
}
}
private static boolean containsExclusion(Exclusion exclusion, List<Exclusion> exclusions)
private static boolean containsExclusion( Exclusion exclusion, List<Exclusion> exclusions )
{
for(Exclusion e :exclusions)
for ( Exclusion e : exclusions )
{
if(e.getGroupId().equals( exclusion.getGroupId() ) && e.getArtifactId().equals( exclusion.getArtifactId() ))
if ( e.getGroupId().equals( exclusion.getGroupId() )
&& e.getArtifactId().equals( exclusion.getArtifactId() ) )
{
return true;
}
}
}
return false;
}
}

View File

@ -3,7 +3,8 @@ package org.apache.maven.project.processor;
import org.apache.maven.model.IssueManagement;
import org.apache.maven.model.Model;
public class IssueManagementProcessor extends BaseProcessor
public class IssueManagementProcessor
extends BaseProcessor
{
public void process( Object parent, Object child, Object target, boolean isChildMostSpecialized )
{
@ -11,23 +12,23 @@ public class IssueManagementProcessor extends BaseProcessor
Model t = (Model) target;
Model c = (Model) child;
Model p = (Model) parent;
if( c.getIssueManagement() != null)
if ( c.getIssueManagement() != null )
{
IssueManagement childMng = c.getIssueManagement();
IssueManagement mng = new IssueManagement();
mng.setSystem( childMng.getSystem() );
mng.setUrl( childMng.getUrl() );
t.setIssueManagement( mng );
}
else if(p != null && p.getIssueManagement() != null)
}
else if ( p != null && p.getIssueManagement() != null )
{
IssueManagement parentMng = p.getIssueManagement();
IssueManagement mng = new IssueManagement();
mng.setSystem( parentMng .getSystem() );
mng.setUrl( parentMng .getUrl() );
mng.setSystem( parentMng.getSystem() );
mng.setUrl( parentMng.getUrl() );
t.setIssueManagement( mng );
}
}

View File

@ -0,0 +1,45 @@
package org.apache.maven.project.processor;
import java.util.ArrayList;
import java.util.List;
import org.apache.maven.model.MailingList;
import org.apache.maven.model.Model;
public class MailingListProcessor
extends BaseProcessor
{
public void process( Object parent, Object child, Object target, boolean isChildMostSpecialized )
{
super.process( parent, child, target, isChildMostSpecialized );
Model t = (Model) target;
Model c = (Model) child;
Model p = (Model) parent;
if ( !c.getMailingLists().isEmpty() )
{
copyMailingLists( c.getMailingLists(), t );
}
else if ( p != null && !p.getMailingLists().isEmpty() )
{
copyMailingLists( p.getMailingLists(), t );
}
}
private static void copyMailingLists( List<MailingList> mailingLists, Model target )
{
List<MailingList> targetList = target.getMailingLists();
for ( MailingList mailingList : mailingLists )
{
MailingList listCopy = new MailingList();
listCopy.setArchive( mailingList.getArchive() );
listCopy.setName( mailingList.getName() );
listCopy.setOtherArchives( new ArrayList<String>( mailingList.getOtherArchives() ) );
listCopy.setPost( mailingList.getPost() );
listCopy.setSubscribe( mailingList.getSubscribe() );
listCopy.setUnsubscribe( mailingList.getUnsubscribe() );
targetList.add( listCopy );
}
}
}

View File

@ -64,5 +64,13 @@ public class ModelProcessor
t.setDescription( c.getDescription() );
}
if ( c.getInceptionYear() != null )
{
t.setInceptionYear( c.getInceptionYear() );
}
else if ( p != null )
{
t.setInceptionYear( p.getInceptionYear() );
}
}
}

View File

@ -0,0 +1,35 @@
package org.apache.maven.project.processor;
import org.apache.maven.model.Model;
import org.apache.maven.model.Organization;
public class OrganizationProcessor
extends BaseProcessor
{
public void process( Object parent, Object child, Object target, boolean isChildMostSpecialized )
{
super.process( parent, child, target, isChildMostSpecialized );
Model t = (Model) target;
Model c = (Model) child;
Model p = (Model) parent;
if ( c.getOrganization() != null )
{
copy( c.getOrganization(), t );
}
else if ( p != null && p.getOrganization() != null )
{
copy( p.getOrganization(), t );
}
}
private static void copy( Organization source, Model target )
{
Organization o = new Organization();
o.setName( source.getName() );
o.setUrl( source.getUrl() );
target.setOrganization( o );
}
}

View File

@ -16,14 +16,14 @@ public class ParentProcessor
super.process( parent, child, target, isChildMostSpecialized );
Model t = (Model) target;
Model c = (Model) child;
if(c.getParent() != null)
if ( c.getParent() != null )
{
Parent p = new Parent();
p.setGroupId( c.getParent().getGroupId() );
p.setArtifactId( c.getParent().getArtifactId() );
p.setVersion( c.getParent().getVersion() );
p.setRelativePath( c.getParent().getRelativePath() );
t.setParent( p );
t.setParent( p );
}
}
}

View File

@ -3,7 +3,8 @@ package org.apache.maven.project.processor;
import org.apache.maven.model.Model;
import org.apache.maven.model.Prerequisites;
public class PrerequisitesProcessor extends BaseProcessor
public class PrerequisitesProcessor
extends BaseProcessor
{
public void process( Object parent, Object child, Object target, boolean isChildMostSpecialized )
{
@ -13,12 +14,12 @@ public class PrerequisitesProcessor extends BaseProcessor
{
Model t = (Model) target;
Model c = (Model) child;
if(c.getPrerequisites() == null)
if ( c.getPrerequisites() == null )
{
return;
}
Prerequisites prerequisites = new Prerequisites();
prerequisites.setMaven( c.getPrerequisites().getMaven());
prerequisites.setMaven( c.getPrerequisites().getMaven() );
t.setPrerequisites( prerequisites );
}
}

View File

@ -4,7 +4,8 @@ import java.util.Properties;
import org.apache.maven.model.Model;
public class PropertiesProcessor extends BaseProcessor
public class PropertiesProcessor
extends BaseProcessor
{
public void process( Object parent, Object child, Object target, boolean isChildMostSpecialized )
{
@ -16,7 +17,7 @@ public class PropertiesProcessor extends BaseProcessor
{
properties.putAll( p.getProperties() );
}
if ( c.getProperties() != null )
{
properties.putAll( c.getProperties() );

View File

@ -0,0 +1,41 @@
package org.apache.maven.project.processor;
import java.util.Properties;
import junit.framework.TestCase;
import org.apache.maven.model.CiManagement;
import org.apache.maven.model.Model;
import org.apache.maven.model.Notifier;
public class CiManagementProcessorTest
extends TestCase
{
public void testChildCopy()
{
CiManagement mng = new CiManagement();
mng.setSystem( "system" );
mng.setUrl( "uri" );
Notifier notifier = new Notifier();
notifier.setAddress( "address" );
notifier.setType( "type" );
Properties prop = new Properties();
prop.put( "key", "value" );
notifier.setConfiguration( prop );
mng.addNotifier( notifier );
Model child = new Model();
child.setCiManagement( mng );
Model target = new Model();
CiManagementProcessor proc = new CiManagementProcessor();
proc.process( null, child, target, false );
assertEquals( "system", target.getCiManagement().getSystem() );
assertEquals( "uri", target.getCiManagement().getUrl() );
assertEquals( 1, target.getCiManagement().getNotifiers().size() );
assertEquals( "address", target.getCiManagement().getNotifiers().get( 0 ).getAddress() );
}
}

View File

@ -5,172 +5,172 @@ import org.apache.maven.model.Model;
import junit.framework.TestCase;
public class DependenciesProcessorTest extends TestCase
public class DependenciesProcessorTest
extends TestCase
{
public void testCopyChild()
{
Dependency dependency = new Dependency();
dependency.setArtifactId( "aid" );
Model child = new Model();
child.addDependency( dependency );
Model target = new Model();
DependenciesProcessor processor = new DependenciesProcessor();
processor.process( null, child, target, false );
assertEquals(1, target.getDependencies().size());
assertEquals("aid", target.getDependencies().get( 0 ).getArtifactId());
assertEquals( 1, target.getDependencies().size() );
assertEquals( "aid", target.getDependencies().get( 0 ).getArtifactId() );
}
public void testParentCopy()
{
Dependency dependency = new Dependency();
dependency.setArtifactId( "aid" );
Model child = new Model();
Model parent = new Model();
parent.addDependency( dependency );
parent.addDependency( dependency );
Model target = new Model();
DependenciesProcessor processor = new DependenciesProcessor();
processor.process( parent, child, target, false );
assertEquals(1, target.getDependencies().size());
assertEquals("aid", target.getDependencies().get( 0 ).getArtifactId());
}
assertEquals( 1, target.getDependencies().size() );
assertEquals( "aid", target.getDependencies().get( 0 ).getArtifactId() );
}
public void testDependencyOrder()
{
Dependency dependency1 = new Dependency();
dependency1.setArtifactId( "aid1" );
dependency1.setArtifactId( "aid1" );
Model child = new Model();
child.addDependency( dependency1 );
Dependency dependency = new Dependency();
dependency.setArtifactId( "aid" );
dependency.setArtifactId( "aid" );
Model parent = new Model();
parent.addDependency( dependency );
parent.addDependency( dependency );
Model target = new Model();
DependenciesProcessor processor = new DependenciesProcessor();
processor.process( parent, child, target, false );
assertEquals(2, target.getDependencies().size());
assertEquals("aid1", target.getDependencies().get( 0 ).getArtifactId());
assertEquals("aid", target.getDependencies().get( 1 ).getArtifactId());
}
assertEquals( 2, target.getDependencies().size() );
assertEquals( "aid1", target.getDependencies().get( 0 ).getArtifactId() );
assertEquals( "aid", target.getDependencies().get( 1 ).getArtifactId() );
}
public void testJoin_NullVersion()
{
Dependency dependency1 = new Dependency();
dependency1.setArtifactId( "aid-c" );
dependency1.setGroupId( "gid-c" );
dependency1.setGroupId( "gid-c" );
Model child = new Model();
child.addDependency( dependency1 );
Dependency dependency = new Dependency();
dependency.setArtifactId( "aid-c" );
dependency.setGroupId( "gid-c" );
dependency.setSystemPath("sp");
dependency.setGroupId( "gid-c" );
dependency.setSystemPath( "sp" );
Model parent = new Model();
parent.addDependency( dependency );
parent.addDependency( dependency );
Model target = new Model();
DependenciesProcessor processor = new DependenciesProcessor();
processor.process( parent, child, target, false );
assertEquals(1, target.getDependencies().size());
assertEquals("sp", target.getDependencies().get( 0 ).getSystemPath());
}
assertEquals( 1, target.getDependencies().size() );
assertEquals( "sp", target.getDependencies().get( 0 ).getSystemPath() );
}
public void testJoin_DefaultType()
{
Dependency dependency1 = new Dependency();
dependency1.setArtifactId( "aid-c" );
dependency1.setGroupId( "gid-c" );
dependency1.setVersion( "1.0" );
dependency1.setGroupId( "gid-c" );
dependency1.setVersion( "1.0" );
dependency1.setType( "jar" );
Model child = new Model();
child.addDependency( dependency1 );
Dependency dependency = new Dependency();
dependency.setArtifactId( "aid-c" );
dependency.setGroupId( "gid-c" );
dependency.setVersion( "1.0" );
dependency.setSystemPath("sp");
dependency.setVersion( "1.0" );
dependency.setSystemPath( "sp" );
Model parent = new Model();
parent.addDependency( dependency );
parent.addDependency( dependency );
Model target = new Model();
DependenciesProcessor processor = new DependenciesProcessor();
processor.process( parent, child, target, false );
assertEquals(1, target.getDependencies().size());
assertEquals("sp", target.getDependencies().get( 0 ).getSystemPath());
}
assertEquals( 1, target.getDependencies().size() );
assertEquals( "sp", target.getDependencies().get( 0 ).getSystemPath() );
}
public void testJoin_DifferentClassifiers()
{
Dependency dependency1 = new Dependency();
dependency1.setArtifactId( "aid-c" );
dependency1.setGroupId( "gid-c" );
dependency1.setVersion( "1.0" );
dependency1.setGroupId( "gid-c" );
dependency1.setVersion( "1.0" );
dependency1.setClassifier( "c1" );
Model child = new Model();
child.addDependency( dependency1 );
Dependency dependency = new Dependency();
dependency.setArtifactId( "aid-c" );
dependency.setGroupId( "gid-c" );
dependency.setVersion( "1.0" );
dependency.setVersion( "1.0" );
dependency1.setClassifier( "c2" );
Model parent = new Model();
parent.addDependency( dependency );
parent.addDependency( dependency );
Model target = new Model();
DependenciesProcessor processor = new DependenciesProcessor();
processor.process( parent, child, target, false );
assertEquals(2, target.getDependencies().size());
}
assertEquals( 2, target.getDependencies().size() );
}
public void testJoin_DifferentVersions()
{
Dependency dependency1 = new Dependency();
dependency1.setArtifactId( "aid-c" );
dependency1.setGroupId( "gid-c" );
dependency1.setVersion( "1.1" );
dependency1.setGroupId( "gid-c" );
dependency1.setVersion( "1.1" );
Model child = new Model();
child.addDependency( dependency1 );
Dependency dependency = new Dependency();
dependency.setArtifactId( "aid-c" );
dependency.setGroupId( "gid-c" );
dependency.setVersion( "1.0" );
dependency.setVersion( "1.0" );
Model parent = new Model();
parent.addDependency( dependency );
parent.addDependency( dependency );
Model target = new Model();
DependenciesProcessor processor = new DependenciesProcessor();
processor.process( parent, child, target, false );
assertEquals(2, target.getDependencies().size());
}
assertEquals( 2, target.getDependencies().size() );
}
}

View File

@ -8,7 +8,8 @@ import org.apache.maven.model.Exclusion;
import junit.framework.TestCase;
public class DependencyProcessorTest extends TestCase
public class DependencyProcessorTest
extends TestCase
{
public void testCopyChild()
{
@ -16,89 +17,89 @@ public class DependencyProcessorTest extends TestCase
List<Dependency> dependencies = new ArrayList<Dependency>();
Dependency child = new Dependency();
child.setArtifactId( "aid" );
processor.process( null, child, dependencies, false );
assertEquals(1, dependencies.size());
//Immutable
assertEquals( 1, dependencies.size() );
// Immutable
child.setArtifactId( "aid2" );
assertEquals("aid", dependencies.get( 0 ).getArtifactId());
assertEquals( "aid", dependencies.get( 0 ).getArtifactId() );
}
public void testCopyParent()
{
DependencyProcessor processor = new DependencyProcessor();
List<Dependency> dependencies = new ArrayList<Dependency>();
Dependency parent = new Dependency();
parent.setArtifactId( "aid" );
processor.process( parent, null, dependencies, false );
assertEquals(1, dependencies.size());
//Immutable
assertEquals( 1, dependencies.size() );
// Immutable
parent.setArtifactId( "aid2" );
assertEquals("aid", dependencies.get( 0 ).getArtifactId());
}
assertEquals( "aid", dependencies.get( 0 ).getArtifactId() );
}
public void testJoinChildOverridesParent()
{
DependencyProcessor processor = new DependencyProcessor();
List<Dependency> dependencies = new ArrayList<Dependency>();
Dependency child = new Dependency();
child.setArtifactId( "aid" );
Dependency parent = new Dependency();
parent.setArtifactId( "aid2" );
processor.process( parent, child, dependencies, false );
assertEquals(1, dependencies.size());
assertEquals("aid", dependencies.get( 0 ).getArtifactId());
//Immutable
assertEquals( 1, dependencies.size() );
assertEquals( "aid", dependencies.get( 0 ).getArtifactId() );
// Immutable
child.setArtifactId( "aid3" );
assertEquals("aid", dependencies.get( 0 ).getArtifactId());
}
assertEquals( "aid", dependencies.get( 0 ).getArtifactId() );
}
public void testJoinElements()
{
DependencyProcessor processor = new DependencyProcessor();
List<Dependency> dependencies = new ArrayList<Dependency>();
Dependency child = new Dependency();
child.setArtifactId( "aid" );
Dependency parent = new Dependency();
parent.setGroupId( "gid" );
processor.process( parent, child, dependencies, false );
assertEquals(1, dependencies.size());
assertEquals("aid", dependencies.get( 0 ).getArtifactId());
assertEquals("gid", dependencies.get( 0 ).getGroupId());
}
assertEquals( 1, dependencies.size() );
assertEquals( "aid", dependencies.get( 0 ).getArtifactId() );
assertEquals( "gid", dependencies.get( 0 ).getGroupId() );
}
public void testExclusionJoin()
{
DependencyProcessor processor = new DependencyProcessor();
List<Dependency> dependencies = new ArrayList<Dependency>();
Exclusion e = new Exclusion();
e.setArtifactId( "aid" );
e.setGroupId( "gid" );
Dependency child = new Dependency();
child.addExclusion( e );
Exclusion e1 = new Exclusion();
e1.setArtifactId( "aid1" );
e1.setGroupId( "gid1" );
e1.setGroupId( "gid1" );
Dependency parent = new Dependency();
parent.addExclusion( e1 );
processor.process( parent, child, dependencies, false );
assertEquals(2, dependencies.get( 0 ).getExclusions().size());
assertEquals("aid", dependencies.get( 0 ).getExclusions().get( 0 ).getArtifactId());
assertEquals("aid1", dependencies.get( 0 ).getExclusions().get( 1 ).getArtifactId());
assertEquals( 2, dependencies.get( 0 ).getExclusions().size() );
assertEquals( "aid", dependencies.get( 0 ).getExclusions().get( 0 ).getArtifactId() );
assertEquals( "aid1", dependencies.get( 0 ).getExclusions().get( 1 ).getArtifactId() );
}
}

View File

@ -5,23 +5,73 @@ import org.apache.maven.model.Model;
import junit.framework.TestCase;
public class IssueManagementProcessorTest extends TestCase
public class IssueManagementProcessorTest
extends TestCase
{
public void testChildCopy()
{
IssueManagement mng = new IssueManagement();
mng.setSystem( "system" );
mng.setUrl( "http://url" );
Model child = new Model();
child.setIssueManagement( mng );
Model target = new Model();
IssueManagementProcessor proc = new IssueManagementProcessor();
proc.process( null, child, target, false );
assertEquals("system", target.getIssueManagement().getSystem());
assertEquals("http://url", target.getIssueManagement().getUrl());
assertEquals( "system", target.getIssueManagement().getSystem() );
assertEquals( "http://url", target.getIssueManagement().getUrl() );
}
/**
* If child does not have issue management node, then use parent.
*/
public void testParentCopy()
{
IssueManagement mng = new IssueManagement();
mng.setSystem( "system" );
mng.setUrl( "http://url" );
Model child = new Model();
Model parent = new Model();
;
parent.setIssueManagement( mng );
Model target = new Model();
IssueManagementProcessor proc = new IssueManagementProcessor();
proc.process( parent, child, target, false );
assertEquals( "system", target.getIssueManagement().getSystem() );
assertEquals( "http://url", target.getIssueManagement().getUrl() );
}
public void testChildCopy_DontInheritParent()
{
IssueManagement mng = new IssueManagement();
mng.setSystem( "system" );
mng.setUrl( "http://url" );
Model child = new Model();
child.setIssueManagement( mng );
IssueManagement mng1 = new IssueManagement();
Model parent = new Model();
;
mng1.setSystem( "system-1" );
mng1.setUrl( "http://url-1" );
parent.setIssueManagement( mng1 );
Model target = new Model();
IssueManagementProcessor proc = new IssueManagementProcessor();
proc.process( parent, child, target, false );
assertEquals( "system", target.getIssueManagement().getSystem() );
assertEquals( "http://url", target.getIssueManagement().getUrl() );
}
}

View File

@ -0,0 +1,54 @@
package org.apache.maven.project.processor;
import org.apache.maven.model.MailingList;
import org.apache.maven.model.Model;
import junit.framework.TestCase;
public class MailingListProcessorTest
extends TestCase
{
public void testChildCopy()
{
Model child = new Model();
MailingList list = new MailingList();
list.setArchive( "archive" );
list.setPost( "post" );
child.getMailingLists().add( list );
Model target = new Model();
MailingListProcessor proc = new MailingListProcessor();
proc.process( null, child, target, false );
assertEquals( "archive", target.getMailingLists().get( 0 ).getArchive() );
list.setArchive( "aaa" );
assertEquals( "archive", target.getMailingLists().get( 0 ).getArchive() );
}
public void testParentCopy()
{
Model child = new Model();
Model parent = new Model();
MailingList list = new MailingList();
list.setArchive( "archive" );
list.setPost( "post" );
parent.getMailingLists().add( list );
Model target = new Model();
MailingListProcessor proc = new MailingListProcessor();
proc.process( parent, child, target, false );
assertEquals( "archive", target.getMailingLists().get( 0 ).getArchive() );
list.setArchive( "aaa" );
assertEquals( "archive", target.getMailingLists().get( 0 ).getArchive() );
}
}

View File

@ -7,121 +7,153 @@ import junit.framework.TestCase;
import org.apache.maven.model.Model;
import org.apache.maven.model.Parent;
public class ModelProcessorTest extends TestCase
public class ModelProcessorTest
extends TestCase
{
public void testModelProcessorVersion()
{
Model targetModel = new Model();
Model childModel = new Model();
childModel.setVersion("1.0");
ModelProcessor mp = new ModelProcessor( new ArrayList<Processor>());
mp.process(null, childModel, targetModel, false);
assertEquals("1.0", targetModel.getVersion());
}
public void testModelProcessorVersionFromParent()
{
Model targetModel = new Model();
Model childModel = new Model();
Parent parent = new Parent();
parent.setVersion("1.0");
childModel.setParent(parent);
ModelProcessor mp = new ModelProcessor( new ArrayList<Processor>());
mp.process(null, childModel, targetModel, false);
assertEquals("1.0", targetModel.getVersion());
}
public void testModelProcessorGroupId()
{
Model targetModel = new Model();
Model childModel = new Model();
childModel.setGroupId("gid");
ModelProcessor mp = new ModelProcessor( new ArrayList<Processor>());
mp.process(null, childModel, targetModel, false);
assertEquals("gid", targetModel.getGroupId());
}
public void testModelProcessorGroupIdFromParent()
{
Model targetModel = new Model();
Model childModel = new Model();
Parent parent = new Parent();
parent.setGroupId("gid");
childModel.setParent(parent);
ModelProcessor mp = new ModelProcessor( new ArrayList<Processor>());
mp.process(null, childModel, targetModel, false);
assertEquals("gid", targetModel.getGroupId());
}
public void testModelVersion()
{
Model targetModel = new Model();
Model childModel = new Model();
childModel.setModelVersion("4.0");
ModelProcessor mp = new ModelProcessor( new ArrayList<Processor>());
mp.process(null, childModel, targetModel, false);
assertEquals("4.0", targetModel.getModelVersion());
}
public void testPackaging()
{
Model targetModel = new Model();
Model childModel = new Model();
childModel.setPackaging("pom");
ModelProcessor mp = new ModelProcessor( new ArrayList<Processor>());
mp.process(null, childModel, targetModel, false);
assertEquals("pom", targetModel.getPackaging());
}
public void testNameSpecialized()
{
Model targetModel = new Model();
Model childModel = new Model();
childModel.setName("name");
ModelProcessor mp = new ModelProcessor( new ArrayList<Processor>());
mp.process(null, childModel, targetModel, true);
assertEquals("name", targetModel.getName());
}
public void testNameNotSpecialized()
{
Model targetModel = new Model();
Model childModel = new Model();
childModel.setName("name");
ModelProcessor mp = new ModelProcessor( new ArrayList<Processor>());
mp.process(null, childModel, targetModel, false);
assertNull (targetModel.getName());
}
public void testDescriptionSpecialized()
{
Model targetModel = new Model();
Model childModel = new Model();
childModel.setDescription("description");
ModelProcessor mp = new ModelProcessor( new ArrayList<Processor>());
mp.process(null, childModel, targetModel, true);
assertEquals("description", targetModel.getDescription());
}
public void testDescriptionNotSpecialized()
{
Model targetModel = new Model();
Model childModel = new Model();
childModel.setDescription("description");
ModelProcessor mp = new ModelProcessor( new ArrayList<Processor>());
mp.process(null, childModel, targetModel, false);
assertNull(targetModel.getDescription());
}
public void testModelProcessorVersion()
{
Model targetModel = new Model();
Model childModel = new Model();
childModel.setVersion( "1.0" );
ModelProcessor mp = new ModelProcessor( new ArrayList<Processor>() );
mp.process( null, childModel, targetModel, false );
assertEquals( "1.0", targetModel.getVersion() );
}
public void testModelProcessorVersionFromParent()
{
Model targetModel = new Model();
Model childModel = new Model();
Parent parent = new Parent();
parent.setVersion( "1.0" );
childModel.setParent( parent );
ModelProcessor mp = new ModelProcessor( new ArrayList<Processor>() );
mp.process( null, childModel, targetModel, false );
assertEquals( "1.0", targetModel.getVersion() );
}
public void testModelProcessorGroupId()
{
Model targetModel = new Model();
Model childModel = new Model();
childModel.setGroupId( "gid" );
ModelProcessor mp = new ModelProcessor( new ArrayList<Processor>() );
mp.process( null, childModel, targetModel, false );
assertEquals( "gid", targetModel.getGroupId() );
}
public void testModelProcessorGroupIdFromParent()
{
Model targetModel = new Model();
Model childModel = new Model();
Parent parent = new Parent();
parent.setGroupId( "gid" );
childModel.setParent( parent );
ModelProcessor mp = new ModelProcessor( new ArrayList<Processor>() );
mp.process( null, childModel, targetModel, false );
assertEquals( "gid", targetModel.getGroupId() );
}
public void testModelVersion()
{
Model targetModel = new Model();
Model childModel = new Model();
childModel.setModelVersion( "4.0" );
ModelProcessor mp = new ModelProcessor( new ArrayList<Processor>() );
mp.process( null, childModel, targetModel, false );
assertEquals( "4.0", targetModel.getModelVersion() );
}
public void testPackaging()
{
Model targetModel = new Model();
Model childModel = new Model();
childModel.setPackaging( "pom" );
ModelProcessor mp = new ModelProcessor( new ArrayList<Processor>() );
mp.process( null, childModel, targetModel, false );
assertEquals( "pom", targetModel.getPackaging() );
}
public void testNameSpecialized()
{
Model targetModel = new Model();
Model childModel = new Model();
childModel.setName( "name" );
ModelProcessor mp = new ModelProcessor( new ArrayList<Processor>() );
mp.process( null, childModel, targetModel, true );
assertEquals( "name", targetModel.getName() );
}
public void testNameNotSpecialized()
{
Model targetModel = new Model();
Model childModel = new Model();
childModel.setName( "name" );
ModelProcessor mp = new ModelProcessor( new ArrayList<Processor>() );
mp.process( null, childModel, targetModel, false );
assertNull( targetModel.getName() );
}
public void testDescriptionSpecialized()
{
Model targetModel = new Model();
Model childModel = new Model();
childModel.setDescription( "description" );
ModelProcessor mp = new ModelProcessor( new ArrayList<Processor>() );
mp.process( null, childModel, targetModel, true );
assertEquals( "description", targetModel.getDescription() );
}
public void testDescriptionNotSpecialized()
{
Model targetModel = new Model();
Model childModel = new Model();
childModel.setDescription( "description" );
ModelProcessor mp = new ModelProcessor( new ArrayList<Processor>() );
mp.process( null, childModel, targetModel, false );
assertNull( targetModel.getDescription() );
}
public void testInceptionYearFromChild()
{
Model targetModel = new Model();
Model childModel = new Model();
childModel.setInceptionYear( "2000" );
ModelProcessor mp = new ModelProcessor( new ArrayList<Processor>() );
mp.process( null, childModel, targetModel, false );
assertEquals( "2000", targetModel.getInceptionYear() );
childModel.setInceptionYear( "2001" );
assertEquals( "2000", targetModel.getInceptionYear() );
}
public void testInceptionYearFromParent()
{
Model targetModel = new Model();
Model childModel = new Model();
Model parentModel = new Model();
parentModel.setInceptionYear( "2000" );
ModelProcessor mp = new ModelProcessor( new ArrayList<Processor>() );
mp.process( parentModel, childModel, targetModel, false );
assertEquals( "2000", targetModel.getInceptionYear() );
parentModel.setInceptionYear( "2001" );
assertEquals( "2000", targetModel.getInceptionYear() );
}
}

View File

@ -6,49 +6,51 @@ import org.apache.maven.model.Model;
import junit.framework.TestCase;
public class ModuleTest extends TestCase {
public class ModuleTest
extends TestCase
{
public void testIsMostSpecialized()
{
ModuleProcessor proc = new ModuleProcessor();
Model targetModel = new Model();
Model childModel = new Model();
childModel.setModules( Arrays.asList( "m1", "m2" ) );
proc.process( null, childModel, targetModel, true );
assertEquals( 2, targetModel.getModules().size() );
assertEquals( "m1", targetModel.getModules().get( 0 ) );
assertEquals( "m2", targetModel.getModules().get( 1 ) );
}
public void testIsNotMostSpecialized()
{
ModuleProcessor proc = new ModuleProcessor();
Model targetModel = new Model();
Model childModel = new Model();
childModel.setModules( Arrays.asList( "m1", "m2" ) );
proc.process( null, childModel, targetModel, false );
assertEquals( 0, targetModel.getModules().size() );
}
public void testImmutable()
{
ModuleProcessor proc = new ModuleProcessor();
Model targetModel = new Model();
Model childModel = new Model();
childModel.setModules( Arrays.asList( "m1", "m2" ) );
proc.process( null, childModel, targetModel, true );
childModel.getModules().set( 0, "m0" );
assertEquals( "m1", targetModel.getModules().get( 0 ) );
}
public void testIsMostSpecialized()
{
ModuleProcessor proc = new ModuleProcessor();
Model targetModel = new Model();
Model childModel = new Model();
childModel.setModules(Arrays.asList("m1", "m2"));
proc.process(null, childModel, targetModel, true);
assertEquals(2, targetModel.getModules().size());
assertEquals("m1", targetModel.getModules().get(0));
assertEquals("m2", targetModel.getModules().get(1));
}
public void testIsNotMostSpecialized()
{
ModuleProcessor proc = new ModuleProcessor();
Model targetModel = new Model();
Model childModel = new Model();
childModel.setModules(Arrays.asList("m1", "m2"));
proc.process(null, childModel, targetModel, false);
assertEquals(0, targetModel.getModules().size());
}
public void testImmutable()
{
ModuleProcessor proc = new ModuleProcessor();
Model targetModel = new Model();
Model childModel = new Model();
childModel.setModules(Arrays.asList("m1", "m2"));
proc.process(null, childModel, targetModel, true);
childModel.getModules().set(0, "m0");
assertEquals("m1", targetModel.getModules().get(0));
}
}

View File

@ -0,0 +1,55 @@
package org.apache.maven.project.processor;
import org.apache.maven.model.Model;
import org.apache.maven.model.Organization;
import junit.framework.TestCase;
public class OrganizationProcessorTest
extends TestCase
{
public void testChildCopy()
{
Model child = new Model();
Organization org = new Organization();
org.setName( "name" );
org.setUrl( "url" );
child.setOrganization( org );
Model target = new Model();
OrganizationProcessor proc = new OrganizationProcessor();
proc.process( null, child, target, false );
assertNotNull( target.getOrganization() );
assertEquals( "name", target.getOrganization().getName() );
assertEquals( "url", target.getOrganization().getUrl() );
org.setName( "new" );
assertEquals( "name", target.getOrganization().getName() );
}
public void testParentCopy()
{
Model child = new Model();
Organization org = new Organization();
org.setName( "name" );
org.setUrl( "url" );
Model parent = new Model();
parent.setOrganization( org );
Model target = new Model();
OrganizationProcessor proc = new OrganizationProcessor();
proc.process( parent, child, target, false );
assertNotNull( target.getOrganization() );
assertEquals( "name", target.getOrganization().getName() );
assertEquals( "url", target.getOrganization().getUrl() );
org.setName( "new" );
assertEquals( "name", target.getOrganization().getName() );
}
}

View File

@ -5,18 +5,19 @@ import org.apache.maven.model.Parent;
import junit.framework.TestCase;
public class ParentProcessorTest extends TestCase
public class ParentProcessorTest
extends TestCase
{
public void testVersion()
{
Model targetModel = new Model();
Model childModel = new Model();
Model childModel = new Model();
Parent parent = new Parent();
parent.setVersion( "1.0" );
childModel.setParent(parent);
childModel.setParent( parent );
ParentProcessor mp = new ParentProcessor();
mp.process(null, childModel, targetModel, false);
assertEquals("1.0", targetModel.getParent().getVersion());
mp.process( null, childModel, targetModel, false );
assertEquals( "1.0", targetModel.getParent().getVersion() );
}
}

View File

@ -5,45 +5,46 @@ import org.apache.maven.model.Prerequisites;
import junit.framework.TestCase;
public class PrerequisitesProcessorTest extends TestCase
public class PrerequisitesProcessorTest
extends TestCase
{
public void testMaven()
{
Prerequisites prerequisites = new Prerequisites();
prerequisites.setMaven( "2.1" );
Model child = new Model();
child.setPrerequisites( prerequisites );
Model target = new Model();
PrerequisitesProcessor proc = new PrerequisitesProcessor();
proc.process( null, child, target, true );
assertEquals("2.1", target.getPrerequisites().getMaven());
//Immutable
assertEquals( "2.1", target.getPrerequisites().getMaven() );
// Immutable
prerequisites.setMaven( "2.2" );
assertEquals("2.1", target.getPrerequisites().getMaven());
assertEquals( "2.1", target.getPrerequisites().getMaven() );
}
public void testMavenParent()
{
Prerequisites prerequisites = new Prerequisites();
prerequisites.setMaven( "2.1" );
Model parent = new Model();
parent.setPrerequisites( prerequisites );
Model target = new Model();
PrerequisitesProcessor proc = new PrerequisitesProcessor();
proc.process( parent, new Model(), target, false );
assertEquals(null, target.getPrerequisites());
}
assertEquals( null, target.getPrerequisites() );
}
}

View File

@ -6,64 +6,64 @@ import junit.framework.TestCase;
import org.apache.maven.model.Model;
public class PropertiesProcessorTest extends TestCase
public class PropertiesProcessorTest
extends TestCase
{
public void testParentChildMerge()
{
Model targetModel = new Model();
Model childModel = new Model();
Model parentModel = new Model();
Model childModel = new Model();
Model parentModel = new Model();
Properties childProperties = new Properties();
childProperties.put( "k1", "v1" );
childModel.setProperties( childProperties );
Properties parentProperties = new Properties();
parentProperties.put( "k2", "v2" );
parentModel.setProperties( parentProperties );
PropertiesProcessor proc = new PropertiesProcessor();
proc.process( parentModel, childModel, targetModel, false );
assertEquals(2, targetModel.getProperties().size());
//Test order of child first
assertEquals( 2, targetModel.getProperties().size() );
// Test order of child first
/*
ArrayList list = Collections.list( targetModel.getProperties().elements() );
targetModel.getProperties().list( System.out );
assertEquals("v1", list.get( 0 ));
assertEquals("v2", list.get( 1 ));
*/
* ArrayList list = Collections.list( targetModel.getProperties().elements() );
* targetModel.getProperties().list( System.out ); assertEquals("v1", list.get( 0 )); assertEquals("v2",
* list.get( 1 ));
*/
}
public void testChildCopy()
{
Model targetModel = new Model();
Model childModel = new Model();
Model childModel = new Model();
Properties childProperties = new Properties();
childProperties.put( "k1", "v1" );
childModel.setProperties( childProperties );
PropertiesProcessor proc = new PropertiesProcessor();
proc.process( null, childModel, targetModel, false );
assertEquals(1, targetModel.getProperties().size());
}
assertEquals( 1, targetModel.getProperties().size() );
}
public void testParentCopy()
{
Model targetModel = new Model();
Model childModel = new Model();
Model parentModel = new Model();
Model childModel = new Model();
Model parentModel = new Model();
Properties parentProperties = new Properties();
parentProperties.put( "k2", "v2" );
parentModel.setProperties( parentProperties );
PropertiesProcessor proc = new PropertiesProcessor();
proc.process( parentModel, childModel, targetModel, false );
assertEquals(1, targetModel.getProperties().size());
}
assertEquals( 1, targetModel.getProperties().size() );
}
}