o Added unit test to express lack of source directory inheritance (*ourceDirectory within <build>)

o Fixed *ourceDirectory inheritance


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163000 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2004-08-23 20:04:34 +00:00
parent 47bdc91285
commit 2a3f7b7220
2 changed files with 74 additions and 17 deletions

View File

@ -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() );

View File

@ -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"));
}
}