Author: jlboudart
Date: Thu Sep 5 10:02:25 2013
New Revision: 1520266
URL: http://svn.apache.org/r1520266
Log:
Add submodule basic tests
Added:
ant/easyant/core/trunk/src/test/java/org/apache/easyant/tasks/SubModuleTest.java
ant/easyant/core/trunk/src/test/resources/org/apache/easyant/tasks/multimodule/
ant/easyant/core/trunk/src/test/resources/org/apache/easyant/tasks/multimodule/module1/
ant/easyant/core/trunk/src/test/resources/org/apache/easyant/tasks/multimodule/module1/module.ivy
ant/easyant/core/trunk/src/test/resources/org/apache/easyant/tasks/multimodule/module2/
ant/easyant/core/trunk/src/test/resources/org/apache/easyant/tasks/multimodule/module2/module.ivy
ant/easyant/core/trunk/src/test/resources/repositories/plugins/mycompany/modulewithtarget/
ant/easyant/core/trunk/src/test/resources/repositories/plugins/mycompany/modulewithtarget/ants/
ant/easyant/core/trunk/src/test/resources/repositories/plugins/mycompany/modulewithtarget/ants/modulewithtarget-0.1.ant
ant/easyant/core/trunk/src/test/resources/repositories/plugins/mycompany/modulewithtarget/ivys/
ant/easyant/core/trunk/src/test/resources/repositories/plugins/mycompany/modulewithtarget/ivys/ivy-0.1.xml
Modified:
ant/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/SubModule.java
Modified:
ant/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/SubModule.java
URL:
http://svn.apache.org/viewvc/ant/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/SubModule.java?rev=1520266&r1=1520265&r2=1520266&view=diff
==============================================================================
---
ant/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/SubModule.java
(original)
+++
ant/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/SubModule.java
Thu Sep 5 10:02:25 2013
@@ -63,7 +63,7 @@ public class SubModule extends AbstractE
private String moduleFile = EasyAntConstants.DEFAULT_BUILD_MODULE;
private Path buildpath;
- private TargetList targets = null;
+ private TargetList targets = new TargetList();
private boolean useBuildRepository = false;
private boolean overwrite = true;
@@ -338,7 +338,13 @@ public class SubModule extends AbstractE
if (keys.contains(target)) {
filteredTargets.add(target);
} else {
- subProject.log("Skipping undefined target '" + target + "'",
Project.MSG_VERBOSE);
+ StringBuilder sb = new StringBuilder();
+ sb.append("Skipping undefined target '")//
+ .append(target)//
+ .append("'")//
+ .append(" on ")//
+ .append(subProject.getName());
+ subProject.log(sb.toString(), Project.MSG_VERBOSE);
}
}
return CollectionUtils.flattenToString(filteredTargets);
Added:
ant/easyant/core/trunk/src/test/java/org/apache/easyant/tasks/SubModuleTest.java
URL:
http://svn.apache.org/viewvc/ant/easyant/core/trunk/src/test/java/org/apache/easyant/tasks/SubModuleTest.java?rev=1520266&view=auto
==============================================================================
---
ant/easyant/core/trunk/src/test/java/org/apache/easyant/tasks/SubModuleTest.java
(added)
+++
ant/easyant/core/trunk/src/test/java/org/apache/easyant/tasks/SubModuleTest.java
Thu Sep 5 10:02:25 2013
@@ -0,0 +1,172 @@
+package org.apache.easyant.tasks;
+
+import static org.hamcrest.CoreMatchers.hasItem;
+import static org.hamcrest.CoreMatchers.isA;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.junit.Assert.assertThat;
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URISyntaxException;
+
+import org.apache.easyant.core.EasyAntMagicNames;
+import org.apache.easyant.core.ant.listerners.BuildExecutionTimer;
+import org.apache.easyant.core.ant.listerners.MultiModuleLogger;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.taskdefs.Delete;
+import org.apache.tools.ant.types.FileSet;
+import org.apache.tools.ant.types.Path;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+public class SubModuleTest extends AntTaskBaseTest {
+ private File cache;
+
+ private SubModule submodule;
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ @Before
+ public void setUp() throws MalformedURLException, URISyntaxException {
+ createCache();
+ Project project = new Project();
+
+ // FIXME: property are not yet inherited
+ project.setUserProperty("ivy.cache.dir", cache.getAbsolutePath());
+ File f = new
File(this.getClass().getResource("/repositories/easyant-ivysettings-test.xml").toURI());
+ // FIXME: property are not yet inherited
+ project.setUserProperty(EasyAntMagicNames.USER_EASYANT_IVYSETTINGS,
f.getAbsolutePath());
+
+ submodule = new SubModule();
+ submodule.setProject(project);
+ }
+
+ private void createCache() {
+ cache = new File("build/cache");
+ cache.mkdirs();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ cleanCache();
+ }
+
+ private void cleanCache() {
+ Delete del = new Delete();
+ del.setProject(new Project());
+ del.setDir(cache);
+ del.execute();
+ }
+
+ @Test(expected = BuildException.class)
+ public void shouldFailIfNoMandatoryAttributesAreSet() {
+ submodule.execute();
+ }
+
+ @Test
+ public void shouldNotFailIfBuildpathAttributeIsSet() {
+ configureProject(submodule.getProject(), Project.MSG_WARN);
+
+ Path path = new Path(submodule.getProject());
+ path.createPath();
+
+ submodule.setBuildpath(path);
+ submodule.execute();
+
+ assertLogContaining("No sub-builds to iterate on");
+ }
+
+ @Test
+ public void shouldFailIfPathContainsInvalidFile() {
+ expectedException.expect(BuildException.class);
+ expectedException.expectMessage("Invalid file:");
+
+ configureProject(submodule.getProject(), Project.MSG_WARN);
+
+ Path path = new Path(submodule.getProject());
+ File file2 = new File("anotherfile");
+ path.createPathElement().setLocation(file2);
+ path.createPath();
+
+ submodule.setBuildpath(path);
+ submodule.execute();
+
+ }
+
+ @Test
+ public void shouldRunEvenIfNoTargetsAreSet() throws URISyntaxException {
+ configureProject(submodule.getProject(), Project.MSG_DEBUG);
+
+ Path path = new Path(submodule.getProject());
+ FileSet fs = new FileSet();
+ File multimodule = new
File(this.getClass().getResource("multimodule").toURI());
+ fs.setDir(multimodule);
+ path.addFileset(fs);
+ path.createPath();
+
+ submodule.setBuildpath(path);
+ submodule.execute();
+
+ assertLogContaining("Executing [] on module1");
+ assertLogContaining("Executing [] on module2");
+ assertLogContaining("Skipping sub-project build because no matching
targets were found");
+
+ verifyBuildListener();
+
+ }
+
+ @Test
+ public void shouldRunEvenIfTargetDoesntExistsInSubModules() throws
URISyntaxException {
+ configureProject(submodule.getProject(), Project.MSG_DEBUG);
+
+ Path path = new Path(submodule.getProject());
+ FileSet fs = new FileSet();
+ File multimodule = new
File(this.getClass().getResource("multimodule").toURI());
+ fs.setDir(multimodule);
+ path.addFileset(fs);
+ path.createPath();
+
+ submodule.setBuildpath(path);
+ submodule.setTarget("a-missing-target");
+ submodule.execute();
+
+ assertLogContaining("Executing [a-missing-target] on module1");
+ assertLogContaining("Skipping undefined target 'a-missing-target' on
module1");
+ assertLogContaining("Executing [a-missing-target] on module2");
+ assertLogContaining("Skipping undefined target 'a-missing-target' on
module2");
+ assertLogContaining("Skipping sub-project build because no matching
targets were found");
+ verifyBuildListener();
+
+ }
+
+ @Test
+ public void shouldRunMyTargetOnBothModule() throws URISyntaxException {
+ configureProject(submodule.getProject(), Project.MSG_DEBUG);
+
+ Path path = new Path(submodule.getProject());
+ FileSet fs = new FileSet();
+ File multimodule = new
File(this.getClass().getResource("multimodule").toURI());
+ fs.setDir(multimodule);
+ path.addFileset(fs);
+ path.createPath();
+
+ submodule.setBuildpath(path);
+ submodule.setTarget("modulewithtarget:mytarget");
+ submodule.execute();
+
+ assertLogContaining("Executing [modulewithtarget:mytarget] on
module1");
+ assertLogContaining("Executing [modulewithtarget:mytarget] on
module2");
+
+ verifyBuildListener();
+
assertThat(submodule.getProject().getReference(BuildExecutionTimer.EXECUTION_TIMER_SUBBUILD_RESULTS),
+ notNullValue());
+ }
+
+ private void verifyBuildListener() {
+ assertThat(submodule.getProject().getBuildListeners(),
hasItem(isA(MultiModuleLogger.class)));
+ }
+}
Added:
ant/easyant/core/trunk/src/test/resources/org/apache/easyant/tasks/multimodule/module1/module.ivy
URL:
http://svn.apache.org/viewvc/ant/easyant/core/trunk/src/test/resources/org/apache/easyant/tasks/multimodule/module1/module.ivy?rev=1520266&view=auto
==============================================================================
---
ant/easyant/core/trunk/src/test/resources/org/apache/easyant/tasks/multimodule/module1/module.ivy
(added)
+++
ant/easyant/core/trunk/src/test/resources/org/apache/easyant/tasks/multimodule/module1/module.ivy
Thu Sep 5 10:02:25 2013
@@ -0,0 +1,25 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+-->
+<ivy-module version="2.0" xmlns:ea="http://www.easyant.org">
+ <info organisation="org.apache.easyant" module="module1"
status="integration" revision="1.0" >
+ <ea:build org="mycompany" module="modulewithtarget" revision="0.1"/>
+ </info>
+ <configurations>
+ <conf name="default" visibility="public" description="runtime
dependencies and master artifact can be used with this conf"/>
+ <conf name="test" visibility="private" description="this scope
indicates that the dependency is not required for normal use of the
application, and is only available for the test compilation and execution
phases."/>
+ </configurations>
+</ivy-module>
Added:
ant/easyant/core/trunk/src/test/resources/org/apache/easyant/tasks/multimodule/module2/module.ivy
URL:
http://svn.apache.org/viewvc/ant/easyant/core/trunk/src/test/resources/org/apache/easyant/tasks/multimodule/module2/module.ivy?rev=1520266&view=auto
==============================================================================
---
ant/easyant/core/trunk/src/test/resources/org/apache/easyant/tasks/multimodule/module2/module.ivy
(added)
+++
ant/easyant/core/trunk/src/test/resources/org/apache/easyant/tasks/multimodule/module2/module.ivy
Thu Sep 5 10:02:25 2013
@@ -0,0 +1,25 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+-->
+<ivy-module version="2.0" xmlns:ea="http://www.easyant.org">
+ <info organisation="org.apache.easyant" module="module2"
status="integration" revision="1.0" >
+ <ea:build org="mycompany" module="modulewithtarget" revision="0.1"/>
+ </info>
+ <configurations>
+ <conf name="default" visibility="public" description="runtime
dependencies and master artifact can be used with this conf"/>
+ <conf name="test" visibility="private" description="this scope
indicates that the dependency is not required for normal use of the
application, and is only available for the test compilation and execution
phases."/>
+ </configurations>
+</ivy-module>
Added:
ant/easyant/core/trunk/src/test/resources/repositories/plugins/mycompany/modulewithtarget/ants/modulewithtarget-0.1.ant
URL:
http://svn.apache.org/viewvc/ant/easyant/core/trunk/src/test/resources/repositories/plugins/mycompany/modulewithtarget/ants/modulewithtarget-0.1.ant?rev=1520266&view=auto
==============================================================================
---
ant/easyant/core/trunk/src/test/resources/repositories/plugins/mycompany/modulewithtarget/ants/modulewithtarget-0.1.ant
(added)
+++
ant/easyant/core/trunk/src/test/resources/repositories/plugins/mycompany/modulewithtarget/ants/modulewithtarget-0.1.ant
Thu Sep 5 10:02:25 2013
@@ -0,0 +1,21 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+-->
+<project name="mycompany#modulewithtarget">
+ <target name="modulewithtarget:mytarget">
+ <echo>a message from mytarget</echo>
+ </target>
+</project>
\ No newline at end of file
Added:
ant/easyant/core/trunk/src/test/resources/repositories/plugins/mycompany/modulewithtarget/ivys/ivy-0.1.xml
URL:
http://svn.apache.org/viewvc/ant/easyant/core/trunk/src/test/resources/repositories/plugins/mycompany/modulewithtarget/ivys/ivy-0.1.xml?rev=1520266&view=auto
==============================================================================
---
ant/easyant/core/trunk/src/test/resources/repositories/plugins/mycompany/modulewithtarget/ivys/ivy-0.1.xml
(added)
+++
ant/easyant/core/trunk/src/test/resources/repositories/plugins/mycompany/modulewithtarget/ivys/ivy-0.1.xml
Thu Sep 5 10:02:25 2013
@@ -0,0 +1,22 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+-->
+<ivy-module version="2.0" xmlns:ea="http://www.easyant.org">
+ <info organisation="mycompany" module="modulewithtarget" revision="0.1"
status="integration"/>
+ <publications>
+ <artifact type="ant" />
+ </publications>
+</ivy-module>