mirror of https://github.com/apache/maven.git
Build processor.
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@752184 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e78c2f0f8a
commit
dda2f16b43
|
@ -1,7 +1,13 @@
|
|||
package org.apache.maven.project.processor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.apache.maven.model.Build;
|
||||
import org.apache.maven.model.Extension;
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.Resource;
|
||||
|
||||
public class BuildProcessor
|
||||
extends BaseProcessor
|
||||
{
|
||||
|
@ -13,5 +19,111 @@ public class BuildProcessor
|
|||
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(t.getBuild() == null)
|
||||
{
|
||||
t.setBuild( new Build() );
|
||||
}
|
||||
|
||||
if(c.getBuild() == null && !( p == null || p.getBuild() == null))
|
||||
{
|
||||
copy(p.getBuild(), t.getBuild());
|
||||
}
|
||||
else if(c.getBuild() != null && !( p == null || p.getBuild() == null))
|
||||
{
|
||||
copy(c.getBuild(), t.getBuild());
|
||||
copy(p.getBuild(), t.getBuild());
|
||||
}
|
||||
else if(c.getBuild() != null )
|
||||
{
|
||||
copy(c.getBuild(), t.getBuild());
|
||||
}
|
||||
}
|
||||
|
||||
private static void copy(Build source, Build target)
|
||||
{
|
||||
if(target.getFinalName() == null)
|
||||
{
|
||||
target.setFinalName( source.getFinalName() );
|
||||
}
|
||||
|
||||
if(target.getDefaultGoal() == null)
|
||||
{
|
||||
target.setDefaultGoal( source.getDefaultGoal() );
|
||||
}
|
||||
|
||||
if(target.getDirectory() == null)
|
||||
{
|
||||
target.setDirectory( source.getDirectory() );
|
||||
}
|
||||
|
||||
if(target.getOutputDirectory() == null)
|
||||
{
|
||||
target.setOutputDirectory( target.getOutputDirectory() );
|
||||
}
|
||||
|
||||
if(target.getScriptSourceDirectory() == null)
|
||||
{
|
||||
target.setScriptSourceDirectory( source.getScriptSourceDirectory() );
|
||||
}
|
||||
|
||||
if(target.getSourceDirectory() == null)
|
||||
{
|
||||
target.setSourceDirectory( source.getSourceDirectory() );
|
||||
}
|
||||
|
||||
if(target.getTestOutputDirectory() == null)
|
||||
{
|
||||
target.setTestOutputDirectory( source.getTestOutputDirectory() );
|
||||
}
|
||||
|
||||
if(target.getTestSourceDirectory() == null)
|
||||
{
|
||||
target.setTestSourceDirectory( source.getTestSourceDirectory() );
|
||||
}
|
||||
|
||||
target.getFilters().addAll( new ArrayList<String>(source.getFilters()) );
|
||||
|
||||
for(Extension extension : source.getExtensions())
|
||||
{
|
||||
Extension e = new Extension();
|
||||
e.setArtifactId( extension.getArtifactId() );
|
||||
e.setGroupId( extension.getGroupId() );
|
||||
e.setVersion( extension.getVersion() );
|
||||
target.addExtension( e );
|
||||
}
|
||||
|
||||
if(target.getResources().isEmpty())
|
||||
{
|
||||
for(Resource resource : source.getResources())
|
||||
{
|
||||
Resource r = new Resource();
|
||||
r.setDirectory( resource.getDirectory());
|
||||
r.setFiltering( resource.isFiltering() );
|
||||
r.setMergeId( resource.getMergeId() );
|
||||
r.setTargetPath( resource.getTargetPath() );
|
||||
r.setExcludes( new ArrayList<String>(resource.getExcludes()) );
|
||||
r.setIncludes( new ArrayList<String>(resource.getIncludes()) );
|
||||
target.getResources().add( r );
|
||||
}
|
||||
}
|
||||
|
||||
if(target.getTestResources().isEmpty())
|
||||
{
|
||||
for(Resource resource : source.getTestResources())
|
||||
{
|
||||
Resource r = new Resource();
|
||||
r.setDirectory( resource.getDirectory());
|
||||
r.setFiltering( resource.isFiltering() );
|
||||
r.setMergeId( resource.getMergeId() );
|
||||
r.setTargetPath( resource.getTargetPath() );
|
||||
r.setExcludes( new ArrayList<String>(resource.getExcludes()) );
|
||||
r.setIncludes( new ArrayList<String>(resource.getIncludes()) );
|
||||
target.getTestResources().add( r );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,9 @@ import java.util.List;
|
|||
|
||||
import org.apache.maven.model.Dependency;
|
||||
import org.apache.maven.model.Plugin;
|
||||
import org.codehaus.plexus.util.xml.Xpp3Dom;
|
||||
import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
|
||||
import org.codehaus.plexus.util.xml.Xpp3DomUtils;
|
||||
|
||||
public class PluginProcessor
|
||||
extends BaseProcessor
|
||||
|
@ -72,8 +75,21 @@ public class PluginProcessor
|
|||
DependenciesProcessor proc = new DependenciesProcessor();
|
||||
proc.process( new ArrayList<Dependency>(p1.getDependencies()), new ArrayList<Dependency>(), p2.getDependencies(), false );
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(p1.getConfiguration() != null)
|
||||
{
|
||||
//TODO: Not copying
|
||||
if(p2.getConfiguration() != null)
|
||||
{
|
||||
p2.setConfiguration( Xpp3Dom.mergeXpp3Dom( (Xpp3Dom) p1.getConfiguration(), (Xpp3Dom) p2.getConfiguration() ));
|
||||
}
|
||||
else
|
||||
{
|
||||
p2.setConfiguration( p1.getConfiguration() );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// p2.setConfiguration( configuration ) merge nodes
|
||||
//Goals
|
||||
//Executions
|
||||
|
|
|
@ -0,0 +1,128 @@
|
|||
package org.apache.maven.project.processor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.apache.maven.model.Build;
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.Resource;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class BuildProcessorTest extends TestCase
|
||||
{
|
||||
public void testChild_FinalName()
|
||||
{
|
||||
Model child = new Model();
|
||||
child.setBuild( new Build() );
|
||||
child.getBuild().setFinalName( "name" );
|
||||
Model target = new Model();
|
||||
|
||||
BuildProcessor proc = new BuildProcessor(new ArrayList());
|
||||
proc.process( null, child, target, false );
|
||||
|
||||
assertEquals("name", target.getBuild().getFinalName());
|
||||
|
||||
child.getBuild().setFinalName( "name2" );
|
||||
assertEquals("name", target.getBuild().getFinalName());
|
||||
}
|
||||
|
||||
public void testParent_FinalName()
|
||||
{
|
||||
Model child = new Model();
|
||||
Model parent = new Model();
|
||||
parent.setBuild( new Build() );
|
||||
parent.getBuild().setFinalName( "name" );
|
||||
Model target = new Model();
|
||||
|
||||
BuildProcessor proc = new BuildProcessor(new ArrayList());
|
||||
proc.process( parent, child, target, false );
|
||||
|
||||
assertEquals("name", target.getBuild().getFinalName());
|
||||
|
||||
//Immutable
|
||||
parent.getBuild().setFinalName( "name2" );
|
||||
assertEquals("name", target.getBuild().getFinalName());
|
||||
|
||||
}
|
||||
|
||||
public void testParent_Filters()
|
||||
{
|
||||
Model child = new Model();
|
||||
|
||||
Model parent = new Model();
|
||||
parent.setBuild( new Build() );
|
||||
|
||||
parent.getBuild().getFilters().add( "filter1" );
|
||||
Model target = new Model();
|
||||
|
||||
BuildProcessor proc = new BuildProcessor(new ArrayList());
|
||||
proc.process( parent, child, target, false );
|
||||
|
||||
assertEquals(1, target.getBuild().getFilters().size());
|
||||
assertEquals("filter1", target.getBuild().getFilters().get( 0 ));
|
||||
|
||||
}
|
||||
|
||||
public void testChild_Filters()
|
||||
{
|
||||
Model child = new Model();
|
||||
child.setBuild( new Build() );
|
||||
child.getBuild().getFilters().add( "filter1" );
|
||||
Model target = new Model();
|
||||
|
||||
BuildProcessor proc = new BuildProcessor(new ArrayList());
|
||||
proc.process( null, child, target, false );
|
||||
|
||||
assertEquals(1, target.getBuild().getFilters().size());
|
||||
assertEquals("filter1", target.getBuild().getFilters().get( 0 ));
|
||||
|
||||
}
|
||||
public void testJoin_Filters()
|
||||
{
|
||||
Model child = new Model();
|
||||
child.setBuild( new Build() );
|
||||
child.getBuild().getFilters().add( "filter1" );
|
||||
Model target = new Model();
|
||||
|
||||
Model parent = new Model();
|
||||
parent.setBuild( new Build() );
|
||||
|
||||
parent.getBuild().getFilters().add( "filter2" );
|
||||
|
||||
BuildProcessor proc = new BuildProcessor(new ArrayList());
|
||||
proc.process( parent, child, target, false );
|
||||
|
||||
assertEquals(2, target.getBuild().getFilters().size());
|
||||
|
||||
//ORDER
|
||||
assertEquals("filter1", target.getBuild().getFilters().get( 0 ));
|
||||
assertEquals("filter2", target.getBuild().getFilters().get( 1 ));
|
||||
}
|
||||
|
||||
public void testDoNotInheritParentIfChildExists_Resources()
|
||||
{
|
||||
Resource r = new Resource();
|
||||
r.setDirectory( "dir" );
|
||||
|
||||
Resource r1 = new Resource();
|
||||
r1.setDirectory( "dir1" );
|
||||
|
||||
Model child = new Model();
|
||||
child.setBuild( new Build() );
|
||||
child.getBuild().getResources().add( r );
|
||||
|
||||
Model target = new Model();
|
||||
|
||||
Model parent = new Model();
|
||||
parent.setBuild( new Build() );
|
||||
|
||||
parent.getBuild().getResources().add( r1 );
|
||||
|
||||
BuildProcessor proc = new BuildProcessor(new ArrayList());
|
||||
proc.process( parent, child, target, false );
|
||||
|
||||
assertEquals(1, target.getBuild().getResources().size());
|
||||
assertEquals("dir", target.getBuild().getResources().get( 0 ).getDirectory());
|
||||
|
||||
}
|
||||
}
|
|
@ -5,6 +5,9 @@ import java.util.List;
|
|||
|
||||
import org.apache.maven.model.Dependency;
|
||||
import org.apache.maven.model.Plugin;
|
||||
import org.codehaus.plexus.util.xml.Xpp3Dom;
|
||||
import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
|
||||
import org.codehaus.plexus.util.xml.Xpp3DomUtils;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
|
@ -57,5 +60,41 @@ public class PluginProcessorTest
|
|||
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());
|
||||
}
|
||||
}
|
||||
/*
|
||||
public void testMergeOfPluginConfiguration()
|
||||
{
|
||||
|
||||
List<Plugin> target = new ArrayList<Plugin>();
|
||||
|
||||
Xpp3Dom dom = new Xpp3Dom("a");
|
||||
Xpp3Dom dom2 = new Xpp3Dom("b");
|
||||
dom2.setValue( "test3" );
|
||||
dom.addChild( dom2 );
|
||||
|
||||
Plugin child = new Plugin();
|
||||
child.setArtifactId( "aid" );
|
||||
child.setGroupId( "gid" );
|
||||
child.setVersion( "1.0" );
|
||||
child.setConfiguration( dom );
|
||||
|
||||
Plugin parent = new Plugin();
|
||||
parent.setGroupId( "gid" );
|
||||
parent.setArtifactId( "aid" );
|
||||
parent.setVersion( "1.0" );
|
||||
|
||||
Xpp3Dom dom3 = new Xpp3Dom("a");
|
||||
Xpp3Dom dom4 = new Xpp3Dom("b");
|
||||
dom4.setValue( "test2" );
|
||||
dom.addChild( dom4 );
|
||||
|
||||
parent.setConfiguration( dom3 );
|
||||
|
||||
PluginProcessor proc = new PluginProcessor();
|
||||
proc.process( parent, child, target, false );
|
||||
|
||||
assertNotNull(target.get( 0 ).getConfiguration() );
|
||||
assertEquals( 2, ((Xpp3Dom) target.get( 0 ).getConfiguration()).getChildren( "b" ).length );
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue