diff --git a/maven-core/src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java b/maven-core/src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java index a60e21ee51..23f1335462 100644 --- a/maven-core/src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java +++ b/maven-core/src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java @@ -1,21 +1,4 @@ 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 org.apache.maven.model.Dependency; import org.apache.maven.model.Model; import org.apache.maven.model.Repository; @@ -160,6 +143,21 @@ public class DefaultModelInheritanceAssembler child.getBuild().setDirectory( parent.getBuild().getDirectory() ); } + if ( child.getBuild().getSourceDirectory() == null ) + { + child.getBuild().setSourceDirectory( parent.getBuild().getSourceDirectory() ); + } + + if ( child.getBuild().getUnitTestSourceDirectory() == null ) + { + child.getBuild().setUnitTestSourceDirectory( parent.getBuild().getUnitTestSourceDirectory() ); + } + + if ( child.getBuild().getAspectSourceDirectory() == null ) + { + child.getBuild().setAspectSourceDirectory( parent.getBuild().getAspectSourceDirectory() ); + } + if ( child.getBuild().getOutput() == null ) { child.getBuild().setOutput( parent.getBuild().getOutput() ); diff --git a/maven-core/src/test/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssemblerTest.java b/maven-core/src/test/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssemblerTest.java new file mode 100644 index 0000000000..43e30f442a --- /dev/null +++ b/maven-core/src/test/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssemblerTest.java @@ -0,0 +1,59 @@ +/* Created on Aug 23, 2004 */ +package org.apache.maven.project.inheritance; + + +import java.util.Arrays; +import java.util.List; + +import org.apache.maven.model.Build; +import org.apache.maven.model.Model; +import org.apache.maven.model.UnitTest; +import org.apache.maven.project.MavenProject; + +import junit.framework.TestCase; + +/** + * @author jdcasey + */ +public class DefaultModelInheritanceAssemblerTest extends TestCase { + + public void testShouldOverrideUnitTestExcludesOnly() { + Model parent = new Model(); + parent.setGroupId("test"); + parent.setArtifactId("test"); + parent.setVersion("0.0"); + + Build parentBuild = new Build(); + parentBuild.setSourceDirectory("src/main/java"); + parentBuild.setAspectSourceDirectory("src/main/aspects"); + parentBuild.setUnitTestSourceDirectory("src/test/java"); + + UnitTest parentUT = new UnitTest(); + parentUT.setIncludes(Arrays.asList(new String[] {"**/*Test.java"})); + parentUT.setExcludes(Arrays.asList(new String[] {"**/*Abstract*.java"})); + + parentBuild.setUnitTest(parentUT); + parent.setBuild(parentBuild); + + Model child = new Model(); + + Build childBuild = new Build(); + + UnitTest childUT = new UnitTest(); + parentUT.setExcludes(Arrays.asList(new String[] {"**/*Abstract*.java", "**/*AspectTest.java"})); + + childBuild.setUnitTest(childUT); + child.setBuild(childBuild); + + ModelInheritanceAssembler assembler = new DefaultModelInheritanceAssembler(); + assembler.assembleModelInheritance(child, parent); + + List childExcludesTest = child.getBuild().getUnitTest().getExcludes(); + assertEquals("source directory should be from parent", "src/main/java", child.getBuild().getSourceDirectory()); + assertEquals("unit test source directory should be from parent", "src/test/java", child.getBuild().getUnitTestSourceDirectory()); + assertEquals("aspect source directory should be from parent", "src/main/aspects", child.getBuild().getAspectSourceDirectory()); + assertTrue("unit test excludes should have **/*AspectTest.java", childExcludesTest.contains("**/*AspectTest.java")); + assertTrue("unit test excludes should have **/*Abstract*.java", childExcludesTest.contains("**/*Abstract*.java")); + } + +}