Partially working plugin processor.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@751938 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Britton Isbell 2009-03-10 01:32:17 +00:00
parent d6bd6de6c6
commit 243d2cd6f7
7 changed files with 305 additions and 24 deletions

View File

@ -11,6 +11,7 @@ import org.apache.maven.shared.model.ModelContainerAction;
public class DependenciesProcessor
extends BaseProcessor
{
public void process( Object parent, Object child, Object target, boolean isChildMostSpecialized )
{
super.process( parent, child, target, isChildMostSpecialized );
@ -21,7 +22,7 @@ public class DependenciesProcessor
{
p = (List<Dependency>) parent;
}
List<Dependency> dependencies = ( (Model) target ).getDependencies();
List<Dependency> dependencies = (List<Dependency>) target;
DependencyProcessor processor = new DependencyProcessor();
if ( ( p == null || p.isEmpty() ) && !c.isEmpty() )

View File

@ -1,7 +1,12 @@
package org.apache.maven.project.processor;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.apache.maven.model.Build;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.DependencyManagement;
import org.apache.maven.model.Model;
/*
@ -73,11 +78,25 @@ public class ModelProcessor
t.setInceptionYear( p.getInceptionYear() );
}
List<Dependency> deps = new ArrayList<Dependency>();
DependenciesProcessor dependenciesProcessor = new DependenciesProcessor();
dependenciesProcessor.process( (p != null) ? p.getDependencies() : null, c.getDependencies(), t, isChildMostSpecialized );
dependenciesProcessor.process( (p != null) ? p.getDependencies() : null, c.getDependencies(), deps, isChildMostSpecialized );
if(deps.size() > 0)
{
t.getDependencies().addAll( deps );
}
List<Dependency> mngDeps = new ArrayList<Dependency>();
dependenciesProcessor.process( (p != null && p.getDependencyManagement() != null) ? p.getDependencyManagement().getDependencies(): null,
(c.getDependencyManagement() != null) ? c.getDependencyManagement().getDependencies(): null, t, isChildMostSpecialized );
(c.getDependencyManagement() != null) ? c.getDependencyManagement().getDependencies(): null, mngDeps, isChildMostSpecialized );
if(mngDeps.size() > 0)
{
if(t.getDependencyManagement() == null)
{
t.setDependencyManagement( new DependencyManagement() );
}
t.getDependencyManagement().getDependencies().addAll( mngDeps );
}
}
}

View File

@ -0,0 +1,87 @@
package org.apache.maven.project.processor;
import java.util.ArrayList;
import java.util.List;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Plugin;
public class PluginProcessor
extends BaseProcessor
{
public void process( Object parent, Object child, Object target, boolean isChildMostSpecialized )
{
super.process( parent, child, target, isChildMostSpecialized );
List<Plugin> t = (List<Plugin>) target;
if ( parent == null && child == null )
{
return;
}
else if ( parent == null && child != null )
{
Plugin targetPlugin = new Plugin();
copy( (Plugin) child, targetPlugin );
t.add( targetPlugin );
}
else if ( parent != null && child == null )
{
Plugin targetPlugin = new Plugin();
copy( (Plugin) parent, targetPlugin );
t.add( targetPlugin );
}
else
// JOIN
{
Plugin targetDependency = new Plugin();
copy( (Plugin) child, targetDependency );
copy( (Plugin) parent, targetDependency );
t.add( targetDependency );
}
}
private static void copy(Plugin p1, Plugin p2)
{
if(p2.getArtifactId() == null)
{
p2.setArtifactId( p1.getArtifactId() );
}
if(p2.getGroupId() == null)
{
p2.setGroupId( p1.getGroupId() );
}
if(p2.getInherited() == null)
{
p2.setInherited( p1.getInherited() );
}
if(p2.getVersion() == null)
{
p2.setVersion( p1.getVersion() );
}
if(p2.getDependencies().isEmpty())
{
DependenciesProcessor proc = new DependenciesProcessor();
proc.process( new ArrayList<Dependency>(), new ArrayList<Dependency>(p1.getDependencies()), p2.getDependencies(), false );
}
else
{
DependenciesProcessor proc = new DependenciesProcessor();
proc.process( new ArrayList<Dependency>(p1.getDependencies()), new ArrayList<Dependency>(), p2.getDependencies(), false );
}
// p2.setConfiguration( configuration ) merge nodes
//Goals
//Executions
p2.setExtensions(p1.isExtensions());
}
}

View File

@ -0,0 +1,87 @@
package org.apache.maven.project.processor;
import java.util.ArrayList;
import java.util.List;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Model;
import org.apache.maven.model.Plugin;
public class PluginsProcessor
extends BaseProcessor
{
public void process( Object parent, Object child, Object target, boolean isChildMostSpecialized )
{
super.process( parent, child, target, isChildMostSpecialized );
List<Plugin> c = (child != null) ? (List<Plugin>) child : new ArrayList<Plugin>() ;
List<Plugin> p = null;
if ( parent != null )
{
p = (List<Plugin>) parent;
}
Model t = (Model) target;
List<Plugin> plugins = t.getBuild().getPlugins();
PluginProcessor processor = new PluginProcessor();
if ( ( p == null || p.isEmpty() ) && !c.isEmpty() )
{
for ( Plugin plugin : c )
{
processor.process( null, plugin, plugins, isChildMostSpecialized );
}
}
else
{
if ( !c.isEmpty() )
{
List<Plugin> parentDependencies = new ArrayList<Plugin>();
for ( Plugin d1 : c)
{
for ( Plugin d2 : p)
{
if ( match( d1, d2 ) )
{
processor.process( d2, d1, plugins, isChildMostSpecialized );// JOIN
}
else
{
processor.process( null, d1, plugins, isChildMostSpecialized );
parentDependencies.add( d2 );
}
}
}
for ( Plugin d2 : parentDependencies )
{
processor.process( d2, null, plugins, isChildMostSpecialized );
}
}
else if( p != null)
{
for ( Plugin d2 : p )
{
processor.process( d2, null, plugins, isChildMostSpecialized );
}
}
}
}
private static boolean match( Plugin d1, Plugin d2 )
{
if ( getId( d1 ).equals( getId( d2 ) ) )
{
return ( d1.getVersion() == null ? "" : d1.getVersion() ).equals( d2.getVersion() == null ? ""
: d2.getVersion() );
}
return false;
}
private static String getId( Plugin d )
{
StringBuilder sb = new StringBuilder();
sb.append( d.getGroupId() ).append( ":" ).append( d.getArtifactId() ).append( ":" );
return sb.toString();
}
}

View File

@ -19,13 +19,13 @@ public class DependenciesProcessorTest
List<Dependency> child = Arrays.asList( dependency );
Model target = new Model();
List<Dependency> target = new ArrayList<Dependency>();
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.size() );
assertEquals( "aid", target.get( 0 ).getArtifactId() );
}
public void testParentCopy()
@ -37,13 +37,13 @@ public class DependenciesProcessorTest
List<Dependency> parent = Arrays.asList( dependency );
Model target = new Model();
List<Dependency> target = new ArrayList<Dependency>();
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.size() );
assertEquals( "aid", target.get( 0 ).getArtifactId() );
}
public void testDependencyOrder()
@ -56,14 +56,14 @@ public class DependenciesProcessorTest
dependency.setArtifactId( "aid" );
List<Dependency> parent = Arrays.asList( dependency );
Model target = new Model();
List<Dependency> target = new ArrayList<Dependency>();
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.size() );
assertEquals( "aid1", target.get( 0 ).getArtifactId() );
assertEquals( "aid", target.get( 1 ).getArtifactId() );
}
public void testJoin_NullVersion()
@ -81,13 +81,13 @@ public class DependenciesProcessorTest
List<Dependency> parent= Arrays.asList( dependency );
Model target = new Model();
List<Dependency> target = new ArrayList<Dependency>();
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.size() );
assertEquals( "sp", target.get( 0 ).getSystemPath() );
}
public void testJoin_DefaultType()
@ -107,13 +107,13 @@ public class DependenciesProcessorTest
List<Dependency> parent = Arrays.asList( dependency );
Model target = new Model();
List<Dependency> target = new ArrayList<Dependency>();
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.size() );
assertEquals( "sp", target.get( 0 ).getSystemPath() );
}
public void testJoin_DifferentClassifiers()
@ -134,12 +134,12 @@ public class DependenciesProcessorTest
List<Dependency> parent = Arrays.asList( dependency );
Model target = new Model();
List<Dependency> target = new ArrayList<Dependency>();
DependenciesProcessor processor = new DependenciesProcessor();
processor.process( parent, child, target, false );
assertEquals( 2, target.getDependencies().size() );
assertEquals( 2, target.size() );
}
public void testJoin_DifferentVersions()
@ -158,11 +158,11 @@ public class DependenciesProcessorTest
List<Dependency> parent = Arrays.asList( dependency );
Model target = new Model();
List<Dependency> target = new ArrayList<Dependency>();
DependenciesProcessor processor = new DependenciesProcessor();
processor.process( parent, child, target, false );
assertEquals( 2, target.getDependencies().size() );
assertEquals( 2, target.size() );
}
}

View File

@ -4,6 +4,8 @@ import java.util.ArrayList;
import junit.framework.TestCase;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.DependencyManagement;
import org.apache.maven.model.Model;
import org.apache.maven.model.Parent;
@ -156,4 +158,28 @@ public class ModelProcessorTest
parentModel.setInceptionYear( "2001" );
assertEquals( "2000", targetModel.getInceptionYear() );
}
public void testDependencyManagementChildCopy()
{
Model target= new Model();
Model child = new Model();
Dependency dependency = new Dependency();
dependency.setArtifactId( "aid" );
DependencyManagement mng = new DependencyManagement();
mng.addDependency( dependency );
child.setDependencyManagement( mng );
ModelProcessor mp = new ModelProcessor( new ArrayList<Processor>() );
mp.process( null, child, target, false );
assertNotNull(target.getDependencyManagement());
assertEquals(1, target.getDependencyManagement().getDependencies().size());
assertEquals("aid", target.getDependencyManagement().getDependencies().get( 0 ).getArtifactId());
}
}

View File

@ -0,0 +1,61 @@
package org.apache.maven.project.processor;
import java.util.ArrayList;
import java.util.List;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Plugin;
import junit.framework.TestCase;
public class PluginProcessorTest
extends TestCase
{
public void testPluginDependencyChildCopy_DependencyGroupId()
{
Dependency dependency = new Dependency();
dependency.setGroupId( "gid" );
List<Plugin> target = new ArrayList<Plugin>();
Plugin child = new Plugin();
child.addDependency( dependency );
PluginProcessor proc = new PluginProcessor();
proc.process( null, child, target, false );
assertEquals(1, target.size());
assertEquals(1, target.get( 0 ).getDependencies().size());
assertEquals("gid", target.get( 0 ).getDependencies().get( 0 ).getGroupId());
}
public void testPluginDependencyJoin()
{
Dependency dependency = new Dependency();
dependency.setGroupId( "gid" );
List<Plugin> target = new ArrayList<Plugin>();
Plugin child = new Plugin();
child.setArtifactId( "aid" );
child.setGroupId( "gid" );
child.setVersion( "1.0" );
child.addDependency( dependency );
Plugin parent = new Plugin();
parent.setGroupId( "gid" );
parent.setArtifactId( "aid" );
parent.setVersion( "1.0" );
Dependency dependency1 = new Dependency();
dependency1.setGroupId( "gid1" );
parent.addDependency( dependency1 );
PluginProcessor proc = new PluginProcessor();
proc.process( parent, child, target, false );
assertEquals(1, target.size());
assertEquals(2, target.get( 0 ).getDependencies().size());
assertEquals("gid", target.get( 0 ).getDependencies().get( 0 ).getGroupId());
assertEquals("gid1", target.get( 0 ).getDependencies().get( 1 ).getGroupId());
}
}