refactor easyant engine api
remove unnecessary catch clauses
merge init and configure method
we now have a method to configure easyant (listeners, proxy, easyant ivy instance, system plugins, etc) and another method to load an easyant project

git-svn-id: https://svn.apache.org/repos/asf/ant/easyant/core/trunk@1578248 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/easyant/core/EasyAntEngine.java b/src/main/java/org/apache/easyant/core/EasyAntEngine.java
index 8a3f888..e33c2f0 100755
--- a/src/main/java/org/apache/easyant/core/EasyAntEngine.java
+++ b/src/main/java/org/apache/easyant/core/EasyAntEngine.java
@@ -244,6 +244,8 @@
 
     public void configurePluginService(Project project, IvyAntSettings easyantIvyInstance) {
         pluginService = new DefaultPluginServiceImpl(easyantIvyInstance);
+        String property = project.getProperty(EasyAntMagicNames.EASYANT_OFFLINE);
+        pluginService.setOfflineMode(project.toBoolean(property));
         project.addReference(EasyAntMagicNames.PLUGIN_SERVICE_INSTANCE, pluginService);
 
     }
@@ -361,14 +363,13 @@
         return file;
     }
 
+
     /**
-     * configure a given project with current configuration
+     * configure easyant (listeners, inputhandlers, proxy, easyantIvyInstance, systems plugins etc...)
      * 
-     * @param project
-     *            a given project
-     * @throws BuildException
+     * @param project a project to configure
      */
-    public void configureProject(Project project) throws BuildException {
+    public void configureEasyAnt(Project project) {
 
         project.setCoreLoader(configuration.getCoreLoader());
 
@@ -396,14 +397,6 @@
 
         project.setName("EasyAnt");
 
-    }
-
-    /**
-     * Initialize an easyant Project
-     * 
-     * @param project
-     */
-    public void initProject(Project project) {
         try {
             project.init();
             project.addReference(EasyAntMagicNames.EASYANT_ENGINE_REF, this);
@@ -418,7 +411,7 @@
 
             project.setUserProperty(EasyAntMagicNames.EASYANT_OFFLINE, Boolean.toString(configuration.isOffline()));
 
-            ProjectHelper helper = ProjectUtils.configureProjectHelper(project);
+            ProjectUtils.configureProjectHelper(project);
 
             IvyAntSettings easyantIvySettings = configureEasyAntIvyInstance(project);
             configurePluginService(project, easyantIvySettings);
@@ -438,7 +431,18 @@
                 project.setProperty(EasyAntMagicNames.ACTIVE_BUILD_CONFIGURATIONS, buildConfigurations);
             }
             loadSystemPlugins(project, true);
+        } catch (RuntimeException exc) {
+            fireBuildFinished(project, exc);
+            throw exc;
+        }
+    }
 
+    /**
+     * Load an easyant project and resolve extension points
+     * @param project 
+     */
+    public void loadProject(Project project) {
+        try {
             locateBuildModuleAndBuildFile(project);
 
             if (configuration.getBuildModule() != null || configuration.getBuildFile() != null) {
@@ -447,15 +451,12 @@
                 lm.setBuildFile(configuration.getBuildFile());
                 executeTask(lm, "load-module", project);
             }
-
-            helper.resolveExtensionOfAttributes(project);
+            ProjectUtils.getConfiguredProjectHelper(project).resolveExtensionOfAttributes(project);
         } catch (RuntimeException exc) {
             fireBuildFinished(project, exc);
             throw exc;
-        } catch (Error e) {
-            fireBuildFinished(project, e);
-            throw e;
         }
+
     }
 
     protected void fireBuildFinished(Project project, Throwable error) {
@@ -576,8 +577,8 @@
      */
     public void doBuild() throws BuildException {
         final Project project = new Project();
-        configureProject(project);
-        initProject(project);
+        configureEasyAnt(project);
+        loadProject(project);
         doBuild(project);
 
     }
@@ -652,7 +653,7 @@
     }
 
     /**
-     * This is a static method used to configure and initialize an existing project
+     * This is a static method used to configure and load an existing project
      * 
      * @param project
      *            a given project
@@ -661,11 +662,11 @@
      * @return configured project
      * @throws BuildException
      */
-    public static Project configureAndInitProject(Project project, EasyAntConfiguration eaConfiguration)
+    public static Project configureAndLoadProject(Project project, EasyAntConfiguration eaConfiguration)
             throws BuildException {
         EasyAntEngine eaEngine = new EasyAntEngine(eaConfiguration);
-        eaEngine.configureProject(project);
-        eaEngine.initProject(project);
+        eaEngine.configureEasyAnt(project);
+        eaEngine.loadProject(project);
         return project;
     }
 
diff --git a/src/main/java/org/apache/easyant/core/EasyAntMain.java b/src/main/java/org/apache/easyant/core/EasyAntMain.java
index 4d4ed58..9b5208f 100755
--- a/src/main/java/org/apache/easyant/core/EasyAntMain.java
+++ b/src/main/java/org/apache/easyant/core/EasyAntMain.java
@@ -441,8 +441,8 @@
         } else {
             EasyAntEngine eaEngine = new EasyAntEngine(easyAntConfiguration);
             Project project = new Project();
-            eaEngine.configureProject(project);
-            eaEngine.initProject(project);
+            eaEngine.configureEasyAnt(project);
+            eaEngine.loadProject(project);
             // handle other easyant option (-listTargets,-describe,etc..)
             for (int i = 0; i < line.getOptions().length; i++) {
                 if (line.getOptions()[i] instanceof EasyantOption) {
@@ -603,7 +603,7 @@
 
         try {
 
-            EasyAntEngine.configureAndInitProject(project, easyAntConfiguration);
+            EasyAntEngine.configureAndLoadProject(project, easyAntConfiguration);
             printDescription(project);
             printTargets(project, easyAntConfiguration.getMsgOutputLevel() > Project.MSG_INFO);
 
diff --git a/src/main/java/org/apache/easyant/core/ant/helper/ModuleIvyProjectHelper.java b/src/main/java/org/apache/easyant/core/ant/helper/ModuleIvyProjectHelper.java
index 78a05bc..51c1534 100644
--- a/src/main/java/org/apache/easyant/core/ant/helper/ModuleIvyProjectHelper.java
+++ b/src/main/java/org/apache/easyant/core/ant/helper/ModuleIvyProjectHelper.java
@@ -47,7 +47,7 @@
         EasyAntConfiguration eaConfiguration = new EasyAntConfiguration();
         eaConfiguration.setBuildModule(buildFile);
 
-        EasyAntEngine.configureAndInitProject(project, eaConfiguration);
+        EasyAntEngine.configureAndLoadProject(project, eaConfiguration);
     }
 
     @Override
diff --git a/src/main/java/org/apache/easyant/tasks/EasyAntRunner.java b/src/main/java/org/apache/easyant/tasks/EasyAntRunner.java
index 452077e..e8fb197 100755
--- a/src/main/java/org/apache/easyant/tasks/EasyAntRunner.java
+++ b/src/main/java/org/apache/easyant/tasks/EasyAntRunner.java
@@ -41,7 +41,8 @@
         if (fork) {
             eaEngine.doBuild();
         } else {
-            eaEngine.initProject(getProject());
+            eaEngine.configureEasyAnt(getProject());
+            eaEngine.loadProject(getProject());;
             getProject().executeTargets(new Vector(getEasyantConfiguration().getTargets()));
         }
     }
diff --git a/src/test/java/org/apache/easyant/core/EasyAntBaseTest.java b/src/test/java/org/apache/easyant/core/EasyAntBaseTest.java
index 552559d..3e1495a 100755
--- a/src/test/java/org/apache/easyant/core/EasyAntBaseTest.java
+++ b/src/test/java/org/apache/easyant/core/EasyAntBaseTest.java
@@ -409,7 +409,8 @@
         project = new Project();
         project.addBuildListener(new AntTestListener(conf.getMsgOutputLevel()));
         EasyAntEngine eaEngine = new EasyAntEngine(conf);
-        eaEngine.initProject(project);
+        eaEngine.configureEasyAnt(project);
+        eaEngine.loadProject(project);//FIXME should be better handled
     }
 
     /**
diff --git a/src/test/java/org/apache/easyant/core/EasyAntEngineTest.java b/src/test/java/org/apache/easyant/core/EasyAntEngineTest.java
index e75fb89..9f33d4f 100644
--- a/src/test/java/org/apache/easyant/core/EasyAntEngineTest.java
+++ b/src/test/java/org/apache/easyant/core/EasyAntEngineTest.java
@@ -69,6 +69,9 @@
     public void setUp() throws IOException {
         File cache = temporaryFolder.newFolder("build-cache");
         project.setProperty("ivy.cache.dir", cache.getAbsolutePath());
+        easyAntConfiguration.setEasyantIvySettingsUrl(this.getClass().getResource(
+                "/repositories/easyant-ivysettings-test.xml"));
+
     }
 
     @Test
@@ -145,46 +148,46 @@
     }
 
     @Test
-    public void shouldConfigureProject() {
-        easyantEngine.configureProject(project);
+    public void shouldConfigureEasyAnt() {
+        easyantEngine.configureEasyAnt(project);
         assertThat(Thread.currentThread().getPriority(), is(Thread.NORM_PRIORITY));
         assertThat(easyAntConfiguration.getCoreLoader(), nullValue());
         assertThat(easyAntConfiguration.isProxy(), is(false));
-        assertProjectIsConfigured();
+        assertEasyAntIsConfigured();
     }
 
     @Test
-    public void shouldConfigureProjectWithCustomPriority() {
+    public void shouldConfigureEasyAntWithCustomPriority() {
         easyAntConfiguration.setThreadPriority(10);
-        easyantEngine.configureProject(project);
+        easyantEngine.configureEasyAnt(project);
         assertThat(Thread.currentThread().getPriority(), is(easyAntConfiguration.getThreadPriority()));
-        assertProjectIsConfigured();
+        assertEasyAntIsConfigured();
     }
 
     @Test
-    public void shouldConfigureProjectWithCustomCoreLoader() {
+    public void shouldConfigureEasyAntWithCustomCoreLoader() {
         easyAntConfiguration.setCoreLoader(this.getClass().getClassLoader());
-        easyantEngine.configureProject(project);
-        assertProjectIsConfigured();
+        easyantEngine.configureEasyAnt(project);
+        assertEasyAntIsConfigured();
         assertThat(project.getCoreLoader(), is(this.getClass().getClassLoader()));
     }
 
     @Test
-    public void shouldConfigureProjectWhenKeepGoingModeIsTrue() {
+    public void shouldConfigureEasyAntWhenKeepGoingModeIsTrue() {
         easyAntConfiguration.setKeepGoingMode(true);
-        easyantEngine.configureProject(project);
-        assertProjectIsConfigured();
+        easyantEngine.configureEasyAnt(project);
+        assertEasyAntIsConfigured();
     }
 
     @Test
-    public void shouldConfigureProjectWhenProxyIsTrue() {
+    public void shouldEasyAntProjectWhenProxyIsTrue() {
         String oldValue = System.getProperty(ProxySetup.USE_SYSTEM_PROXIES);
         System.getProperties().remove(ProxySetup.USE_SYSTEM_PROXIES);
 
         easyAntConfiguration.setProxy(true);
-        easyantEngine.configureProject(project);
+        easyantEngine.configureEasyAnt(project);
 
-        assertProjectIsConfigured();
+        assertEasyAntIsConfigured();
 
         if (oldValue != null) {
             System.setProperty(ProxySetup.USE_SYSTEM_PROXIES, oldValue);
@@ -193,7 +196,7 @@
         }
     }
 
-    private void assertProjectIsConfigured() {
+    private void assertEasyAntIsConfigured() {
         assertThat(project.getCoreLoader(), is(easyAntConfiguration.getCoreLoader()));
         assertThat(project.isKeepGoingMode(), is(easyAntConfiguration.isKeepGoingMode()));
         assertThat(Boolean.parseBoolean(System.getProperty(ProxySetup.USE_SYSTEM_PROXIES)),
@@ -244,6 +247,7 @@
 
     @Test
     public void shouldReturnNullGlobalEasyAntIvySettingsLocationIfNoDefaultGlobalExists() throws MalformedURLException {
+        easyAntConfiguration.setEasyantIvySettingsUrl((String)null);
         // configure default global to missing directory
         project.setNewProperty(EasyAntMagicNames.EASYANT_HOME, "/fake/path");
         URL globalEasyAntIvySettings = easyantEngine.getGlobalEasyAntIvySettings(project);
@@ -252,6 +256,7 @@
 
     @Test
     public void shouldReturnDefaultGlobalEasyAntIvySettingsLocationIfExists() throws IOException {
+        easyAntConfiguration.setEasyantIvySettingsUrl((String)null);
         File f = temporaryFolder.newFile("easyant-ivysettings.xml");
         FileOutputStream fos = null;
         try {
@@ -270,6 +275,7 @@
 
     @Test
     public void shouldReturnGlobalEasyAntIvySettingsLocationSpecifiedByConfigurationFile() throws MalformedURLException {
+        easyAntConfiguration.setEasyantIvySettingsUrl((String)null);
         easyAntConfiguration.setEasyantIvySettingsFile("/path/to/fake/easyantIvySettingsFile.xml");
         URL globalEasyAntIvySettings = easyantEngine.getGlobalEasyAntIvySettings(project);
         assertThat(globalEasyAntIvySettings.toString(), endsWith(easyAntConfiguration.getEasyantIvySettingsFile()));