From cae2d444f7e933d5d55072f4b546b27ce174a720 Mon Sep 17 00:00:00 2001 From: Conor MacNeill Date: Wed, 1 May 2002 07:19:30 +0000 Subject: [PATCH] Fixes to the new config task stuff git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@272636 13f79535-47bb-0310-9956-ffa450edef68 --- .../ant/antcore/antlib/AntLibManager.java | 14 ++++-- .../apache/ant/antcore/config/AntConfig.java | 8 ---- .../ant/antcore/config/AntConfigHandler.java | 1 - .../antcore/execution/ComponentManager.java | 12 ++++-- .../antcore/execution/ExecutionManager.java | 4 -- .../apache/ant/antcore/execution/Frame.java | 6 +-- .../org/apache/ant/antlib/system/LoadLib.java | 2 +- .../org/apache/ant/builder/Builder.java | 43 +++++++++---------- .../ant/common/service/ComponentService.java | 4 +- 9 files changed, 46 insertions(+), 48 deletions(-) diff --git a/proposal/mutant/src/java/antcore/org/apache/ant/antcore/antlib/AntLibManager.java b/proposal/mutant/src/java/antcore/org/apache/ant/antcore/antlib/AntLibManager.java index 81662fbf2..bb8f131ef 100644 --- a/proposal/mutant/src/java/antcore/org/apache/ant/antcore/antlib/AntLibManager.java +++ b/proposal/mutant/src/java/antcore/org/apache/ant/antcore/antlib/AntLibManager.java @@ -166,9 +166,17 @@ public class AntLibManager { if (libraries.containsKey(libraryId)) { AntLibrary currentVersion = (AntLibrary) libraries.get(libraryId); - throw new ExecutionException("Ant Library \"" + libraryId - + "\" is already loaded from " - + currentVersion.getDefinitionURL()); + // same location? + AntLibrarySpec spec + = (AntLibrarySpec) librarySpecs.get(libraryId); + URL specURL = spec.getLibraryURL(); + if (!specURL.equals(currentVersion.getDefinitionURL())) { + throw new ExecutionException("Ant Library \"" + libraryId + + "\" is already loaded from " + + currentVersion.getDefinitionURL() + + " new version found at " + + specURL); + } } } diff --git a/proposal/mutant/src/java/antcore/org/apache/ant/antcore/config/AntConfig.java b/proposal/mutant/src/java/antcore/org/apache/ant/antcore/config/AntConfig.java index 8829095df..ed16ce7e1 100755 --- a/proposal/mutant/src/java/antcore/org/apache/ant/antcore/config/AntConfig.java +++ b/proposal/mutant/src/java/antcore/org/apache/ant/antcore/config/AntConfig.java @@ -52,17 +52,9 @@ * . */ package org.apache.ant.antcore.config; -import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; import java.util.ArrayList; -import java.util.HashMap; import java.util.Iterator; import java.util.List; -import java.util.Map; -import org.apache.ant.common.util.ConfigException; -import org.apache.ant.common.util.PathTokenizer; -import org.apache.ant.init.InitUtils; import org.apache.ant.common.model.BuildElement; /** diff --git a/proposal/mutant/src/java/antcore/org/apache/ant/antcore/config/AntConfigHandler.java b/proposal/mutant/src/java/antcore/org/apache/ant/antcore/config/AntConfigHandler.java index 3d42063af..124ff1dbc 100755 --- a/proposal/mutant/src/java/antcore/org/apache/ant/antcore/config/AntConfigHandler.java +++ b/proposal/mutant/src/java/antcore/org/apache/ant/antcore/config/AntConfigHandler.java @@ -52,7 +52,6 @@ * . */ package org.apache.ant.antcore.config; -import org.apache.ant.common.util.ConfigException; import org.apache.ant.antcore.xml.ElementHandler; import org.apache.ant.antcore.modelparser.BuildElementHandler; import org.xml.sax.Attributes; diff --git a/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/ComponentManager.java b/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/ComponentManager.java index 347fc6e80..eff357c63 100644 --- a/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/ComponentManager.java +++ b/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/ComponentManager.java @@ -111,7 +111,7 @@ public class ComponentManager implements ComponentService { * These are AntLibraries which have been loaded into this component * manager */ - private Map antLibraries = new HashMap(); + private static Map antLibraries = new HashMap(); /** dynamic libraries which have been defined */ private Map dynamicLibraries; @@ -149,9 +149,12 @@ public class ComponentManager implements ComponentService { * @param libLocation the file or URL of the library location * @param importAll if true all tasks are imported as the library is * loaded + * @param autoImport true if libraries in the Ant namespace should be + * automatically imported. * @exception ExecutionException if the library cannot be loaded */ - public void loadLib(String libLocation, boolean importAll) + public void loadLib(String libLocation, boolean importAll, + boolean autoImport) throws ExecutionException { try { Map librarySpecs = new HashMap(); @@ -162,8 +165,9 @@ public class ComponentManager implements ComponentService { Iterator i = librarySpecs.keySet().iterator(); while (i.hasNext()) { String libraryId = (String) i.next(); - if (importAll - || libraryId.startsWith(Constants.ANT_LIB_PREFIX)) { + boolean doAuto = autoImport + && libraryId.startsWith(Constants.ANT_LIB_PREFIX); + if (importAll || doAuto) { importLibrary(libraryId); } } diff --git a/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/ExecutionManager.java b/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/ExecutionManager.java index 9111e9f5c..2965147e1 100755 --- a/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/ExecutionManager.java +++ b/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/ExecutionManager.java @@ -52,13 +52,9 @@ * . */ package org.apache.ant.antcore.execution; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; -import org.apache.ant.antcore.antlib.AntLibManager; import org.apache.ant.antcore.config.AntConfig; import org.apache.ant.common.event.BuildListener; import org.apache.ant.common.model.Project; diff --git a/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/Frame.java b/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/Frame.java index fee20ebf7..ef94bf78a 100644 --- a/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/Frame.java +++ b/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/Frame.java @@ -153,8 +153,6 @@ public class Frame implements DemuxOutputReceiver { /** * Create an Execution Frame for the given project * - * @param standardLibs The libraries of tasks and types available to this - * frame * @param config the user config to use for this execution of Ant * @param initConfig Ant's initialisation config * @exception ExecutionException if a component of the library cannot be @@ -951,14 +949,14 @@ public class Frame implements DemuxOutputReceiver { // load system ant lib URL systemLibs = new URL(initConfig.getLibraryURL(), "syslibs/"); - componentManager.loadLib(systemLibs.toString(), true); + componentManager.loadLib(systemLibs.toString(), true, true); // execute any config tasks executeTasks(config.getTasks()); // now load other system libraries URL antLibs = new URL(initConfig.getLibraryURL(), "antlibs/"); - componentManager.loadLib(antLibs.toString(), false); + componentManager.loadLib(antLibs.toString(), false, true); executeTasks(project.getTasks()); } catch (MalformedURLException e) { diff --git a/proposal/mutant/src/java/antlibs/system/org/apache/ant/antlib/system/LoadLib.java b/proposal/mutant/src/java/antlibs/system/org/apache/ant/antlib/system/LoadLib.java index 2b29db6c2..11cf85197 100644 --- a/proposal/mutant/src/java/antlibs/system/org/apache/ant/antlib/system/LoadLib.java +++ b/proposal/mutant/src/java/antlibs/system/org/apache/ant/antlib/system/LoadLib.java @@ -151,7 +151,7 @@ public class LoadLib extends AbstractTask { AntContext context = getAntContext(); ComponentService componentService = (ComponentService) context.getCoreService(ComponentService.class); - componentService.loadLib(url.toString(), importAll); + componentService.loadLib(url.toString(), importAll, false); } /** diff --git a/proposal/mutant/src/java/bootstrap/org/apache/ant/builder/Builder.java b/proposal/mutant/src/java/bootstrap/org/apache/ant/builder/Builder.java index f8a617f7c..63f99ba1e 100644 --- a/proposal/mutant/src/java/bootstrap/org/apache/ant/builder/Builder.java +++ b/proposal/mutant/src/java/bootstrap/org/apache/ant/builder/Builder.java @@ -53,7 +53,6 @@ */ package org.apache.ant.builder; import java.io.File; -import java.io.FilenameFilter; import java.util.ArrayList; import java.util.List; @@ -90,7 +89,7 @@ public class Builder { /** the input root */ private static final File INPUT_ROOT = new File(PACKAGE_ROOT, "input"); - + /** the input root */ /** the root forthe depend task's support classes */ private static final File DEPEND_ROOT @@ -107,21 +106,22 @@ public class Builder { } /** - * Add all the java files fro, a given directory. + * Add all the java files from a given directory. * * @param files the list to which the files are to be added. * @param dir the directory from which the Java files are added. + * @param recurse true if subdirectories should be searched. */ - private void addJavaFiles(List files, File dir) { - File[] javaFiles = dir.listFiles(new FilenameFilter() { - public boolean accept(File dir, String name) { - return name.endsWith(".java"); - } - }); + private void addJavaFiles(List files, File dir, boolean recurse) { + File[] javaFiles = dir.listFiles(); if (javaFiles != null) { for (int i = 0; i < javaFiles.length; ++i) { - files.add(javaFiles[i]); + if (javaFiles[i].isDirectory() && recurse) { + addJavaFiles(files, javaFiles[i], recurse); + } else if (javaFiles[i].getName().endsWith(".java")) { + files.add(javaFiles[i]); + } } } } @@ -134,18 +134,17 @@ public class Builder { */ private File[] getAnt1Files() { List files = new ArrayList(); - addJavaFiles(files, TASKDEFS_ROOT); - addJavaFiles(files, new File(TASKDEFS_ROOT, "compilers")); - addJavaFiles(files, new File(TASKDEFS_ROOT, "condition")); - addJavaFiles(files, DEPEND_ROOT); - addJavaFiles(files, new File(DEPEND_ROOT, "constantpool")); - addJavaFiles(files, TYPES_ROOT); - addJavaFiles(files, FILTERS_ROOT); - addJavaFiles(files, UTIL_ROOT); - addJavaFiles(files, new File(UTIL_ROOT, "depend")); - addJavaFiles(files, ZIP_ROOT); - addJavaFiles(files, new File(UTIL_ROOT, "facade")); - addJavaFiles(files, INPUT_ROOT); + addJavaFiles(files, TASKDEFS_ROOT, false); + addJavaFiles(files, new File(TASKDEFS_ROOT, "compilers"), true); + addJavaFiles(files, new File(TASKDEFS_ROOT, "condition"), true); + addJavaFiles(files, DEPEND_ROOT, true); + addJavaFiles(files, TYPES_ROOT, true); + addJavaFiles(files, FILTERS_ROOT, false); + addJavaFiles(files, UTIL_ROOT, false); + addJavaFiles(files, new File(UTIL_ROOT, "depend"), false); + addJavaFiles(files, new File(UTIL_ROOT, "facade"), true); + addJavaFiles(files, ZIP_ROOT, true); + addJavaFiles(files, INPUT_ROOT, true); files.add(new File(PACKAGE_ROOT, "BuildException.java")); files.add(new File(PACKAGE_ROOT, "Location.java")); diff --git a/proposal/mutant/src/java/common/org/apache/ant/common/service/ComponentService.java b/proposal/mutant/src/java/common/org/apache/ant/common/service/ComponentService.java index 35f997e6f..9a1a6afaa 100644 --- a/proposal/mutant/src/java/common/org/apache/ant/common/service/ComponentService.java +++ b/proposal/mutant/src/java/common/org/apache/ant/common/service/ComponentService.java @@ -77,10 +77,12 @@ public interface ComponentService { * @param libLocation the location of the library or the libraries * @param importAll true if all components of the loaded libraries * should be imported + * @param autoImport true if libraries in the Ant namespace should be + * automatically imported. * @exception ExecutionException if the library or libraries cannot be * imported. */ - void loadLib(String libLocation, boolean importAll) + void loadLib(String libLocation, boolean importAll, boolean autoImport) throws ExecutionException; /**