diff options
author | Magesh Umasankar <umagesh@apache.org> | 2002-06-01 12:26:43 +0000 |
---|---|---|
committer | Magesh Umasankar <umagesh@apache.org> | 2002-06-01 12:26:43 +0000 |
commit | ca91f8cb7e4f2bfe1a191dea6126a32649af9565 (patch) | |
tree | 987dedb3cd79ebe75c1c7d7286acffa77470d14c /src/main/org/apache/tools/ant/types/selectors/ExtendSelector.java | |
parent | f19f07d6e4c72f241057ecfc32d80be21201bbf7 (diff) | |
download | ant-ca91f8cb7e4f2bfe1a191dea6126a32649af9565.tar.gz |
Merge changes made to 1.5 Beta1.
git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@272826 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/main/org/apache/tools/ant/types/selectors/ExtendSelector.java')
-rw-r--r-- | src/main/org/apache/tools/ant/types/selectors/ExtendSelector.java | 49 |
1 files changed, 33 insertions, 16 deletions
diff --git a/src/main/org/apache/tools/ant/types/selectors/ExtendSelector.java b/src/main/org/apache/tools/ant/types/selectors/ExtendSelector.java index 9925fe971..46533c31f 100644 --- a/src/main/org/apache/tools/ant/types/selectors/ExtendSelector.java +++ b/src/main/org/apache/tools/ant/types/selectors/ExtendSelector.java @@ -58,6 +58,7 @@ import java.io.File; import java.util.Vector; import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.AntClassLoader; import org.apache.tools.ant.types.DataType; import org.apache.tools.ant.types.Path; import org.apache.tools.ant.types.Parameter; @@ -72,7 +73,7 @@ import org.apache.tools.ant.types.Reference; public class ExtendSelector extends BaseSelector { private String classname = null; - private ExtendFileSelector dynselector = null; + private FileSelector dynselector = null; private Vector paramVec = new Vector(); private Path classpath = null; @@ -83,7 +84,7 @@ public class ExtendSelector extends BaseSelector { } /** - * Sets the classname of the dynamic selector. + * Sets the classname of the custom selector. * * @param classname is the class which implements this selector */ @@ -92,13 +93,21 @@ public class ExtendSelector extends BaseSelector { } /** - * Instantiates the identified dynamic selector class. + * Instantiates the identified custom selector class. */ public void selectorCreate() { if (classname != null && classname.length() > 0) { try { - dynselector = (ExtendFileSelector) - Class.forName(classname).newInstance(); + Class c = null; + if (classpath == null) { + c = Class.forName(classname); + } else { + AntClassLoader al = new AntClassLoader(getProject(), + classpath); + c = al.loadClass(classname); + AntClassLoader.initializeClass(c); + } + dynselector = (FileSelector) c.newInstance(); } catch (ClassNotFoundException cnfexcept) { setError("Selector " + classname + @@ -118,7 +127,7 @@ public class ExtendSelector extends BaseSelector { } /** - * Create new parameters to pass to dynamic selector. + * Create new parameters to pass to custom selector. * * @param p The new Parameter object */ @@ -162,7 +171,7 @@ public class ExtendSelector extends BaseSelector { } /** - * Set the classpath to use for loading a dynamic selector by using + * Set the classpath to use for loading a custom selector by using * a reference. */ public void setClasspathref(Reference r) { @@ -174,37 +183,45 @@ public class ExtendSelector extends BaseSelector { /** * These are errors specific to ExtendSelector only. If there are - * errors in the dynamic selector, it should throw a BuildException + * errors in the custom selector, it should throw a BuildException * when isSelected() is called. */ public void verifySettings() { + // Creation is done here rather than in isSelected() because some + // containers may do a validation pass before running isSelected(), + // but we need to check for the existence of the created class. + if (dynselector == null) { + selectorCreate(); + } if (classname == null || classname.length() < 1) { setError("The classname attribute is required"); } else if (dynselector == null) { - setError("Internal Error: The dynamic selector is not set"); + setError("Internal Error: The custom selector was not created"); + } + else if (!(dynselector instanceof ExtendFileSelector) && + (paramVec.size() > 0)) { + setError("Cannot set parameters on custom selector that does not " + + "implement ExtendFileSelector"); } } /** - * Allows the dynamic selector to choose whether to select a file. This - * is also where the Parameters are passed to the dynamic selector, + * Allows the custom selector to choose whether to select a file. This + * is also where the Parameters are passed to the custom selector, * since we know we must have them all by now. And since we must know * both classpath and classname, creating the class is deferred to here * as well. */ public boolean isSelected(File basedir, String filename, File file) throws BuildException { - if (dynselector == null) { - selectorCreate(); - } validate(); - if (paramVec.size() > 0) { + if (paramVec.size() > 0 && dynselector instanceof ExtendFileSelector) { Parameter[] paramArray = new Parameter[paramVec.size()]; paramVec.copyInto(paramArray); // We know that dynselector must be non-null if no error message - dynselector.setParameters(paramArray); + ((ExtendFileSelector)dynselector).setParameters(paramArray); } return dynselector.isSelected(basedir,filename,file); } |