Author: jlboudart
Date: Mon Aug 19 11:54:43 2013
New Revision: 1515377
URL: http://svn.apache.org/r1515377
Log:
Add LoadModule tests
Added:
ant/easyant/core/trunk/src/test/java/org/apache/easyant/tasks/LoadModuleTest.java
ant/easyant/core/trunk/src/test/resources/org/apache/easyant/tasks/
ant/easyant/core/trunk/src/test/resources/org/apache/easyant/tasks/simple/
ant/easyant/core/trunk/src/test/resources/org/apache/easyant/tasks/simple/module.ant
- copied, changed from r1515376,
ant/easyant/core/trunk/src/test/resources/repositories/plugins/mycompany/simpleplugin/ants/simpleplugin-0.1.ant
ant/easyant/core/trunk/src/test/resources/org/apache/easyant/tasks/simple/module.ivy
Modified:
ant/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/LoadModule.java
ant/easyant/core/trunk/src/test/resources/repositories/plugins/mycompany/simpleplugin/ants/simpleplugin-0.1.ant
ant/easyant/core/trunk/src/test/resources/repositories/plugins/mycompany/simplepluginwithproperties/ants/simplepluginwithproperties-0.1.ant
Modified:
ant/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/LoadModule.java
URL:
http://svn.apache.org/viewvc/ant/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/LoadModule.java?rev=1515377&r1=1515376&r2=1515377&view=diff
==============================================================================
---
ant/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/LoadModule.java
(original)
+++
ant/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/LoadModule.java
Mon Aug 19 11:54:43 2013
@@ -117,7 +117,7 @@ public class LoadModule extends Abstract
// paranoid lets check everything category
if (buildModule.isDirectory()) {
- System.out.println("What? buildModule: " + buildModule + " is
a dir!");
+ log("What? buildModule: " + buildModule + " is a dir!");
throw new BuildException("Build failed");
}
// load override buildFile before buildModule to allow
target/extension-point
@@ -137,7 +137,7 @@ public class LoadModule extends Abstract
// paranoid lets check everything category
if (buildFile.isDirectory()) {
- System.out.println("What? buildFile: " + buildFile + " is a
dir!");
+ log("What? buildFile: " + buildFile + " is a dir!");
throw new BuildException("Build failed");
}
@@ -232,7 +232,7 @@ public class LoadModule extends Abstract
.toExternalForm();
getProject().setNewProperty(EasyAntMagicNames.PROJECT_DEFAULT_IVYSETTINGS,
defaultUrl);
if (!ivysettingsConfigured) {
- File localSettings = new File(buildModule.getParent(),
"ivysettings.xml");
+ File localSettings = new File(getProject().getBaseDir(),
"ivysettings.xml");
if (localSettings.exists()) {
getProject().log("loading local project settings file...",
Project.MSG_VERBOSE);
projectIvyInstance.setFile(localSettings);
Added:
ant/easyant/core/trunk/src/test/java/org/apache/easyant/tasks/LoadModuleTest.java
URL:
http://svn.apache.org/viewvc/ant/easyant/core/trunk/src/test/java/org/apache/easyant/tasks/LoadModuleTest.java?rev=1515377&view=auto
==============================================================================
---
ant/easyant/core/trunk/src/test/java/org/apache/easyant/tasks/LoadModuleTest.java
(added)
+++
ant/easyant/core/trunk/src/test/java/org/apache/easyant/tasks/LoadModuleTest.java
Mon Aug 19 11:54:43 2013
@@ -0,0 +1,266 @@
+/*
+ * 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.
+ *
+ */
+package org.apache.easyant.tasks;
+
+import static org.hamcrest.CoreMatchers.hasItems;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.junit.Assert.assertThat;
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URISyntaxException;
+import java.util.List;
+
+import org.apache.easyant.core.EasyAntConstants;
+import org.apache.easyant.core.EasyAntMagicNames;
+import org.apache.easyant.core.ant.ProjectUtils;
+import org.apache.easyant.core.ivy.IvyInstanceHelper;
+import org.apache.easyant.core.parser.DefaultEasyAntXmlModuleDescriptorParser;
+import org.apache.ivy.Ivy;
+import org.apache.ivy.ant.IvyAntSettings;
+import org.apache.ivy.ant.IvyConfigure;
+import org.apache.ivy.core.module.id.ModuleId;
+import org.apache.ivy.core.module.id.ModuleRevisionId;
+import org.apache.ivy.core.report.ResolveReport;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Location;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.taskdefs.Delete;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class LoadModuleTest extends BaseAntTaskTest {
+
+ private File cache;
+
+ private LoadModule loadModule;
+
+ @Before
+ public void setUp() throws MalformedURLException, URISyntaxException {
+ createCache();
+ Project project = new Project();
+ ProjectUtils.configureProjectHelper(project);
+ project.setProperty("ivy.cache.dir", cache.getAbsolutePath());
+
+ IvyConfigure configure = new IvyConfigure();
+ configure.setProject(project);
+
+ File f = new
File(this.getClass().getResource("/repositories/easyant-ivysettings-test.xml").toURI());
+ configure.setFile(f);
+
+ configure.setSettingsId(EasyAntMagicNames.EASYANT_IVY_INSTANCE);
+ configure.execute();
+
+ project.setBaseDir(new
File(this.getClass().getResource("simple").toURI()));
+
+ loadModule = new LoadModule();
+ loadModule.setProject(project);
+ loadModule.setOwningTarget(ProjectUtils.createTopLevelTarget());
+ loadModule.setLocation(new
Location(ProjectUtils.emulateMainScript(project).getAbsolutePath()));
+ }
+
+ 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
+ public void shouldLoadModuleWithCustomBuildModule() throws
URISyntaxException {
+ Project project = loadModule.getProject();
+ configureProject(project, Project.MSG_DEBUG);
+ File moduleIvyFile = new
File(this.getClass().getResource("simple/module.ivy").toURI());
+ loadModule.setBuildModule(moduleIvyFile);
+ loadModule.execute();
+
+ assertThat(project.getName(), is(project.getProperty("ivy.module")));
+
+ assertLogContaining("Loading build module : " +
moduleIvyFile.getAbsolutePath());
+ assertLogContaining("Loading EasyAnt module descriptor :"
+ + DefaultEasyAntXmlModuleDescriptorParser.class.getName());
+ assertLogNotContaining("Loading build file :");
+
+
assertThat(project.getProperty(EasyAntMagicNames.AVAILABLE_BUILD_CONFIGURATIONS),
nullValue());
+
+ assertThat(project.getProperty("run.main.classname"),
is("org.apache.easyant.example.Example"));
+
+ ResolveReport resolveReport =
project.getReference(EasyAntMagicNames.IMPORTED_MODULES_RESOLVE_REPORT_REF);
+ assertThat(resolveReport, notNullValue());
+ ModuleRevisionId buildType =
ModuleRevisionId.parse("mycompany#simpleplugin;0.1");
+ ModuleRevisionId plugin =
ModuleRevisionId.parse("mycompany#simplepluginwithproperties;0.1");
+ @SuppressWarnings("unchecked")
+ List<ModuleId> resolvedModuleIds = resolveReport.getModuleIds();
+ assertThat(resolvedModuleIds, hasItems(buildType.getModuleId(),
plugin.getModuleId()));
+
+ assertThat(project.getUserProperty("ant.file.mycompany#simpleplugin"),
notNullValue());
+
assertThat(project.getUserProperty("ant.file.mycompany#simplepluginwithproperties"),
notNullValue());
+
+ Ivy configuredIvyInstance = verifyOfflineResolverIsConfigured(project);
+
+
assertThat(configuredIvyInstance.getSettings().getResolver(EasyAntConstants.BUILD_SCOPE_REPOSITORY),
+ nullValue());
+
+ }
+
+ @Test
+ public void shouldNotFailWithNonExistingBuildModule() throws
URISyntaxException {
+ Project project = loadModule.getProject();
+ configureProject(project, Project.MSG_DEBUG);
+ File moduleIvyFile = new File("missingmodule.ivy");
+ loadModule.setBuildModule(moduleIvyFile);
+ loadModule.execute();
+
+ assertThat(project.getName(), is(project.getProperty("ivy.module")));
+
+ assertLogNotContaining("Loading build module : " +
moduleIvyFile.getAbsolutePath());
+ assertLogNotContaining("Loading build file :");
+
+
assertThat(project.getProperty(EasyAntMagicNames.AVAILABLE_BUILD_CONFIGURATIONS),
nullValue());
+
assertThat(project.getReference(EasyAntMagicNames.IMPORTED_MODULES_RESOLVE_REPORT_REF),
nullValue());
+
+ Ivy configuredIvyInstance = verifyOfflineResolverIsConfigured(project);
+
+
assertThat(configuredIvyInstance.getSettings().getResolver(EasyAntConstants.BUILD_SCOPE_REPOSITORY),
+ nullValue());
+
+ }
+
+ @Test(expected = BuildException.class)
+ public void shouldFailIfBuildModuleIsADirectory() throws
URISyntaxException {
+
+ File moduleIvyFile = new
File(this.getClass().getResource("simple").toURI());
+ loadModule.setBuildModule(moduleIvyFile);
+ loadModule.execute();
+
+ }
+
+ @Test
+ public void shouldLoadModuleWithCustomBuildFile() throws
URISyntaxException {
+ Project project = loadModule.getProject();
+ configureProject(project, Project.MSG_DEBUG);
+ File moduleAntFile = new
File(this.getClass().getResource("simple/module.ant").toURI());
+ loadModule.setBuildFile(moduleAntFile);
+ loadModule.execute();
+
+ assertLogNotContaining("Loading build module :");
+ assertLogContaining("Loading build file : " +
moduleAntFile.getAbsolutePath());
+
+ assertThat(project.getTargets().get("hello-world"), notNullValue());
+
+
assertThat(project.getProperty(EasyAntMagicNames.AVAILABLE_BUILD_CONFIGURATIONS),
nullValue());
+
assertThat(project.getReference(EasyAntMagicNames.IMPORTED_MODULES_RESOLVE_REPORT_REF),
nullValue());
+
+ Ivy projectIvyInstance = verifyOfflineResolverIsConfigured(project);
+
+
assertThat(projectIvyInstance.getSettings().getResolver(EasyAntConstants.BUILD_SCOPE_REPOSITORY),
nullValue());
+
+ }
+
+ @Test
+ public void shouldNotFailWithNonExistingBuildFile() throws
URISyntaxException {
+ Project project = loadModule.getProject();
+ configureProject(project, Project.MSG_DEBUG);
+ File moduleAntFile = new File("missingmodule.ant");
+ loadModule.setBuildFile(moduleAntFile);
+ loadModule.execute();
+
+ assertLogNotContaining("Loading build module :");
+ assertLogNotContaining("Loading build file : " +
moduleAntFile.getAbsolutePath());
+
+
assertThat(project.getProperty(EasyAntMagicNames.AVAILABLE_BUILD_CONFIGURATIONS),
nullValue());
+
assertThat(project.getReference(EasyAntMagicNames.IMPORTED_MODULES_RESOLVE_REPORT_REF),
nullValue());
+
+ Ivy projectIvyInstance = verifyOfflineResolverIsConfigured(project);
+
+
assertThat(projectIvyInstance.getSettings().getResolver(EasyAntConstants.BUILD_SCOPE_REPOSITORY),
nullValue());
+
+ }
+
+ @Test(expected = BuildException.class)
+ public void shouldFailIfBuildFileIsADirectory() throws URISyntaxException {
+
+ File moduleAntFile = new
File(this.getClass().getResource("simple").toURI());
+ loadModule.setBuildFile(moduleAntFile);
+ loadModule.execute();
+
+ }
+
+ @Test
+ public void shouldNotFailWithNoArgument() throws URISyntaxException {
+ Project project = loadModule.getProject();
+ configureProject(project, Project.MSG_DEBUG);
+ loadModule.execute();
+
+ assertLogNotContaining("Loading build module :");
+ assertLogNotContaining("Loading build file : ");
+
+
assertThat(project.getProperty(EasyAntMagicNames.AVAILABLE_BUILD_CONFIGURATIONS),
nullValue());
+
assertThat(project.getReference(EasyAntMagicNames.IMPORTED_MODULES_RESOLVE_REPORT_REF),
nullValue());
+
+ Ivy projectIvyInstance = verifyOfflineResolverIsConfigured(project);
+
+
assertThat(projectIvyInstance.getSettings().getResolver(EasyAntConstants.BUILD_SCOPE_REPOSITORY),
nullValue());
+
+ }
+
+ @Test
+ public void shouldConfigureBuildScopeRepository() throws
URISyntaxException {
+ Project project = loadModule.getProject();
+ configureProject(project, Project.MSG_DEBUG);
+ loadModule.setUseBuildRepository(true);
+ loadModule.execute();
+
+ assertLogNotContaining("Loading build module :");
+ assertLogNotContaining("Loading build file : ");
+
+
assertThat(project.getProperty(EasyAntMagicNames.AVAILABLE_BUILD_CONFIGURATIONS),
nullValue());
+
assertThat(project.getReference(EasyAntMagicNames.IMPORTED_MODULES_RESOLVE_REPORT_REF),
nullValue());
+
+ Ivy projectIvyInstance = verifyOfflineResolverIsConfigured(project);
+
+
assertThat(projectIvyInstance.getSettings().getResolver(EasyAntConstants.BUILD_SCOPE_REPOSITORY),
+ notNullValue());
+
+ }
+
+ private Ivy verifyOfflineResolverIsConfigured(Project project) {
+ IvyAntSettings projectIvyInstanceRef =
project.getReference(IvyInstanceHelper
+ .getProjectIvyInstanceName(project));
+ assertThat(projectIvyInstanceRef, notNullValue());
+
assertThat(project.getProperty(EasyAntMagicNames.OFFLINE_PROJECT_RESOLVER),
+ is(EasyAntConstants.DEFAULT_OFFLINE_PROJECT_RESOLVER));
+ Ivy configuredIvyInstance =
projectIvyInstanceRef.getConfiguredIvyInstance(loadModule);
+
assertThat(configuredIvyInstance.getSettings().getResolver(EasyAntConstants.DEFAULT_OFFLINE_PROJECT_RESOLVER),
+ notNullValue());
+ return configuredIvyInstance;
+ }
+}
Copied:
ant/easyant/core/trunk/src/test/resources/org/apache/easyant/tasks/simple/module.ant
(from r1515376,
ant/easyant/core/trunk/src/test/resources/repositories/plugins/mycompany/simpleplugin/ants/simpleplugin-0.1.ant)
URL:
http://svn.apache.org/viewvc/ant/easyant/core/trunk/src/test/resources/org/apache/easyant/tasks/simple/module.ant?p2=ant/easyant/core/trunk/src/test/resources/org/apache/easyant/tasks/simple/module.ant&p1=ant/easyant/core/trunk/src/test/resources/repositories/plugins/mycompany/simpleplugin/ants/simpleplugin-0.1.ant&r1=1515376&r2=1515377&rev=1515377&view=diff
==============================================================================
---
ant/easyant/core/trunk/src/test/resources/repositories/plugins/mycompany/simpleplugin/ants/simpleplugin-0.1.ant
(original)
+++
ant/easyant/core/trunk/src/test/resources/org/apache/easyant/tasks/simple/module.ant
Mon Aug 19 11:54:43 2013
@@ -15,5 +15,7 @@
limitations under the License.
-->
<project>
- <echo>a simple plugin</echo>
+ <target name="hello-world">
+ <echo>hello world</echo>
+ </target>
</project>
\ No newline at end of file
Added:
ant/easyant/core/trunk/src/test/resources/org/apache/easyant/tasks/simple/module.ivy
URL:
http://svn.apache.org/viewvc/ant/easyant/core/trunk/src/test/resources/org/apache/easyant/tasks/simple/module.ivy?rev=1515377&view=auto
==============================================================================
---
ant/easyant/core/trunk/src/test/resources/org/apache/easyant/tasks/simple/module.ivy
(added)
+++
ant/easyant/core/trunk/src/test/resources/org/apache/easyant/tasks/simple/module.ivy
Mon Aug 19 11:54:43 2013
@@ -0,0 +1,28 @@
+<!--
+ 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="standard-java-app"
status="integration" revision="1.0" >
+ <ea:build org="mycompany" module="simpleplugin" revision="0.1">
+ <ea:property name="run.main.classname"
value="org.apache.easyant.example.Example"/>
+ <ea:plugin org="mycompany" module="simplepluginwithproperties"
revision="0.1"/>
+ </ea:build>
+ </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>
Modified:
ant/easyant/core/trunk/src/test/resources/repositories/plugins/mycompany/simpleplugin/ants/simpleplugin-0.1.ant
URL:
http://svn.apache.org/viewvc/ant/easyant/core/trunk/src/test/resources/repositories/plugins/mycompany/simpleplugin/ants/simpleplugin-0.1.ant?rev=1515377&r1=1515376&r2=1515377&view=diff
==============================================================================
---
ant/easyant/core/trunk/src/test/resources/repositories/plugins/mycompany/simpleplugin/ants/simpleplugin-0.1.ant
(original)
+++
ant/easyant/core/trunk/src/test/resources/repositories/plugins/mycompany/simpleplugin/ants/simpleplugin-0.1.ant
Mon Aug 19 11:54:43 2013
@@ -14,6 +14,6 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<project>
+<project name="mycompany#simpleplugin">
<echo>a simple plugin</echo>
</project>
\ No newline at end of file
Modified:
ant/easyant/core/trunk/src/test/resources/repositories/plugins/mycompany/simplepluginwithproperties/ants/simplepluginwithproperties-0.1.ant
URL:
http://svn.apache.org/viewvc/ant/easyant/core/trunk/src/test/resources/repositories/plugins/mycompany/simplepluginwithproperties/ants/simplepluginwithproperties-0.1.ant?rev=1515377&r1=1515376&r2=1515377&view=diff
==============================================================================
---
ant/easyant/core/trunk/src/test/resources/repositories/plugins/mycompany/simplepluginwithproperties/ants/simplepluginwithproperties-0.1.ant
(original)
+++
ant/easyant/core/trunk/src/test/resources/repositories/plugins/mycompany/simplepluginwithproperties/ants/simplepluginwithproperties-0.1.ant
Mon Aug 19 11:54:43 2013
@@ -14,7 +14,7 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<project xmlns:ea="antlib:org.apache.easyant">
+<project name="mycompany#simplepluginwithproperties"
xmlns:ea="antlib:org.apache.easyant">
<property
file="${mycompany#simplepluginwithproperties.properties.file}"/>
<ea:parameter property="src.main.java" default="${basedir}/src/main/java"
description="directory where sources to be compiled are" />