conor 02/03/11 05:01:48
Modified: src/main/org/apache/tools/ant ProjectHelper.java
src/main/org/apache/tools/ant/helper ProjectHelperImpl.java
Log:
Cleanup of ProjectHelper bits - many to go.
Revision Changes Path
1.79 +53 -51
jakarta-ant/src/main/org/apache/tools/ant/ProjectHelper.java
Index: ProjectHelper.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/ProjectHelper.java,v
retrieving revision 1.78
retrieving revision 1.79
diff -u -w -u -r1.78 -r1.79
--- ProjectHelper.java 11 Mar 2002 09:40:20 -0000 1.78
+++ ProjectHelper.java 11 Mar 2002 13:01:48 -0000 1.79
@@ -55,9 +55,6 @@
package org.apache.tools.ant;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
import java.io.InputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
@@ -65,8 +62,6 @@
import java.util.Vector;
import java.util.Enumeration;
import java.util.Locale;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
import org.xml.sax.AttributeList;
import org.apache.tools.ant.helper.ProjectHelperImpl;
@@ -92,6 +87,19 @@
* @author [EMAIL PROTECTED]
*/
public class ProjectHelper {
+ /**
+ * Name of JVM system property which provides the name of the
+ * ProjectHelper class to use.
+ */
+ public static final String HELPER_PROPERTY =
+ "org.apache.tools.ant.ProjectHelper";
+
+ /**
+ * The service identifier in jars which provide Project Helper
+ * implementations.
+ */
+ public static final String SERVICE_ID =
+ "/META-INF/services/org.apache.tools.ant.ProjectHelper";
/**
* Configures the project with the contents of the specified XML file.
@@ -103,11 +111,13 @@
* @exception BuildException if the configuration is invalid or cannot
* be read
*/
- public static void configureProject(Project project, File buildFile)
throws BuildException {
+ public static void configureProject(Project project, File buildFile)
+ throws BuildException {
ProjectHelper helper=ProjectHelper.getProjectHelper();
helper.parse(project, buildFile);
}
+ /** Default constructor */
public ProjectHelper() {
}
@@ -125,25 +135,17 @@
* be read
*/
public void parse(Project project, Object source) throws BuildException {
- throw new BuildException("ProjectHelper.parse() must be implemented
in a helper plugin "
- + this.getClass().getName());
+ throw new BuildException("ProjectHelper.parse() must be implemented "
+ + "in a helper plugin " + this.getClass().getName());
}
- /* -------------------- Helper discovery -------------------- */
- public static final String HELPER_PROPERTY =
- "org.apache.tools.ant.ProjectHelper";
-
- public static final String SERVICE_ID =
- "/META-INF/services/org.apache.tools.ant.ProjectHelper";
-
/** Discover a project helper instance. Uses the same patterns
* as JAXP, commons-logging, etc: a system property, a JDK1.3
* service discovery, default.
*/
public static ProjectHelper getProjectHelper()
- throws BuildException
- {
+ throws BuildException {
// Identify the class loader we will be using. Ant may be
// in a webapp or embeded in a different app
ProjectHelper helper=null;
@@ -209,8 +211,7 @@
* loaded this class.
*/
private static ProjectHelper newHelper(String helperClass)
- throws BuildException
- {
+ throws BuildException {
ClassLoader classLoader = getContextClassLoader();
try {
Class clazz = null;
@@ -235,8 +236,7 @@
* Cut&paste from Jaxp.
*/
public static ClassLoader getContextClassLoader()
- throws BuildException
- {
+ throws BuildException {
if (!LoaderUtils.isContextLoaderAvailable()) {
return null;
}
@@ -244,7 +244,7 @@
return LoaderUtils.getContextClassLoader();
}
- // -------------------- Static utils, used by most helpers
--------------------
+ // -------------------- Static utils, used by most helpers
----------------
/**
* Configures an object using an introspection handler.
@@ -301,8 +301,8 @@
*
* @exception BuildException if the target object doesn't accept text
*/
- public static void addText(Project project, Object target, char[] buf,
int start, int count)
- throws BuildException {
+ public static void addText(Project project, Object target, char[] buf,
+ int start, int count) throws BuildException {
addText(project, target, new String(buf, start, count));
}
@@ -330,7 +330,8 @@
target = ((TaskAdapter) target).getProxy();
}
- IntrospectionHelper.getHelper(target.getClass()).addText(project,
target, text);
+ IntrospectionHelper.getHelper(target.getClass()).addText(project,
+ target, text);
}
/**
@@ -346,7 +347,8 @@
* May be <code>null</code>, in which case
* the child is not stored.
*/
- public static void storeChild(Project project, Object parent, Object
child, String tag) {
+ public static void storeChild(Project project, Object parent,
+ Object child, String tag) {
IntrospectionHelper ih =
IntrospectionHelper.getHelper(parent.getClass());
ih.storeElement(project, parent, child, tag);
}
@@ -389,8 +391,8 @@
* @return the original string with the properties replaced, or
* <code>null</code> if the original string is <code>null</code>.
*/
- public static String replaceProperties(Project project, String value,
Hashtable keys)
- throws BuildException {
+ public static String replaceProperties(Project project, String value,
+ Hashtable keys) throws BuildException {
if (value == null) {
return null;
}
@@ -407,7 +409,8 @@
if (fragment == null) {
String propertyName = (String)j.nextElement();
if (!keys.containsKey(propertyName)) {
- project.log("Property ${" + propertyName + "} has not
been set", Project.MSG_VERBOSE);
+ project.log("Property ${" + propertyName
+ + "} has not been set", Project.MSG_VERBOSE);
}
fragment = (keys.containsKey(propertyName)) ? (String)
keys.get(propertyName)
: "${" +
propertyName + "}";
@@ -447,8 +450,7 @@
if( pos == (value.length() - 1)) {
fragments.addElement("$");
prev = pos + 1;
- }
- else if (value.charAt(pos + 1) != '{' ) {
+ } else if (value.charAt(pos + 1) != '{' ) {
fragments.addElement(value.substring(pos + 1, pos + 2));
prev = pos + 2;
} else {
1.2 +56 -50
jakarta-ant/src/main/org/apache/tools/ant/helper/ProjectHelperImpl.java
Index: ProjectHelperImpl.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/helper/ProjectHelperImpl.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -w -u -r1.1 -r1.2
--- ProjectHelperImpl.java 6 Mar 2002 16:37:58 -0000 1.1
+++ ProjectHelperImpl.java 11 Mar 2002 13:01:48 -0000 1.2
@@ -54,15 +54,10 @@
package org.apache.tools.ant.helper;
-import org.apache.tools.ant.*;
-
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
-import java.util.Hashtable;
-import java.util.Vector;
-import java.util.Enumeration;
import java.util.Locale;
import org.xml.sax.Locator;
import org.xml.sax.InputSource;
@@ -72,11 +67,22 @@
import org.xml.sax.DocumentHandler;
import org.xml.sax.AttributeList;
import org.xml.sax.helpers.XMLReaderAdapter;
-
import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.ParserConfigurationException;
+import org.apache.tools.ant.ProjectHelper;
+import org.apache.tools.ant.UnknownElement;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Target;
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.RuntimeConfigurable;
+import org.apache.tools.ant.IntrospectionHelper;
+import org.apache.tools.ant.TaskContainer;
+import org.apache.tools.ant.Location;
+import org.apache.tools.ant.TaskAdapter;
+
/**
* Original helper.
*
@@ -94,32 +100,35 @@
* SAX 1 style parser used to parse the given file. This may
* in fact be a SAX 2 XMLReader wrapped in an XMLReaderAdapter.
*/
- org.xml.sax.Parser parser;
+ private org.xml.sax.Parser parser;
/** The project to configure. */
- Project project;
+ private Project project;
/** The configuration file to parse. */
- File buildFile;
+ private File buildFile;
/**
* Parent directory of the build file. Used for resolving entities
* and setting the project's base directory.
*/
- File buildFileParent;
+ private File buildFileParent;
/**
* Locator for the configuration file parser.
* Used for giving locations of errors etc.
*/
- Locator locator;
+ private Locator locator;
/**
* Parses the project file, configuring the project as it goes.
*
+ * @param project project instance to be configured.
+ * @param source the source from which the project is read.
* @exception BuildException if the configuration is invalid or cannot
- * be read
+ * be read.
*/
public void parse(Project project, Object source) throws BuildException {
- if( ! (source instanceof File) )
+ if (!(source instanceof File)) {
throw new BuildException( "Only File source supported by default
plugin" );
+ }
File buildFile=(File)source;
FileInputStream inputStream = null;
InputSource inputSource = null;
@@ -136,6 +145,7 @@
parser = new XMLReaderAdapter(saxParser.getXMLReader());
}
+
String uri = "file:" + buildFile.getAbsolutePath().replace('\\',
'/');
for (int index = uri.indexOf('#'); index != -1; index =
uri.indexOf('#')) {
uri = uri.substring(0, index) + "%23" +
uri.substring(index+1);
@@ -144,20 +154,20 @@
inputStream = new FileInputStream(buildFile);
inputSource = new InputSource(inputStream);
inputSource.setSystemId(uri);
- project.log("parsing buildfile " + buildFile + " with URI = " +
uri, Project.MSG_VERBOSE);
+ project.log("parsing buildfile " + buildFile + " with URI = "
+ + uri, Project.MSG_VERBOSE);
HandlerBase hb = new RootHandler(this);
parser.setDocumentHandler(hb);
parser.setEntityResolver(hb);
parser.setErrorHandler(hb);
parser.setDTDHandler(hb);
parser.parse(inputSource);
- }
- catch(ParserConfigurationException exc) {
+ } catch (ParserConfigurationException exc) {
throw new BuildException("Parser has not been configured
correctly", exc);
- }
- catch(SAXParseException exc) {
+ } catch (SAXParseException exc) {
Location location =
- new Location(buildFile.toString(), exc.getLineNumber(),
exc.getColumnNumber());
+ new Location(buildFile.toString(), exc.getLineNumber(),
+ exc.getColumnNumber());
Throwable t = exc.getException();
if (t instanceof BuildException) {
@@ -169,26 +179,21 @@
}
throw new BuildException(exc.getMessage(), t, location);
- }
- catch(SAXException exc) {
+ } catch (SAXException exc) {
Throwable t = exc.getException();
if (t instanceof BuildException) {
throw (BuildException) t;
}
throw new BuildException(exc.getMessage(), t);
- }
- catch(FileNotFoundException exc) {
+ } catch (FileNotFoundException exc) {
throw new BuildException(exc);
- }
- catch(IOException exc) {
+ } catch (IOException exc) {
throw new BuildException("Error reading project file", exc);
- }
- finally {
+ } finally {
if (inputStream != null) {
try {
inputStream.close();
- }
- catch (IOException ioe) {
+ } catch (IOException ioe) {
// ignore this
}
}
@@ -227,6 +232,9 @@
* Creates a handler and sets the parser to use it
* for the current element.
*
+ * @param helperImpl the ProjectHelperImpl instance associated
+ * with this handler.
+ *
* @param parentHandler The handler which should be restored to the
* parser at the end of the element.
* Must not be <code>null</code>.
@@ -490,7 +498,7 @@
* appropriate handler is created and initialised with the details
* of the element.
*
- * @param tag The name of the element being started.
+ * @param name The name of the element being started.
* Will not be <code>null</code>.
* @param attrs Attributes of the element being started.
* Will not be <code>null</code>.
@@ -520,7 +528,7 @@
* Handles a task defintion element by creating a task handler
* and initialising is with the details of the element.
*
- * @param tag The name of the element to be handled.
+ * @param name The name of the element to be handled.
* Will not be <code>null</code>.
* @param attrs Attributes of the element to be handled.
* Will not be <code>null</code>.
@@ -537,7 +545,7 @@
* Handles a type defintion element by creating a task handler
* and initialising is with the details of the element.
*
- * @param tag The name of the element to be handled.
+ * @param name The name of the element to be handled.
* Will not be <code>null</code>.
* @param attrs Attributes of the element to be handled.
* Will not be <code>null</code>.
@@ -553,7 +561,7 @@
* Handles a property defintion element by creating a task handler
* and initialising is with the details of the element.
*
- * @param tag The name of the element to be handled.
+ * @param name The name of the element to be handled.
* Will not be <code>null</code>.
* @param attrs Attributes of the element to be handled.
* Will not be <code>null</code>.
@@ -584,7 +592,7 @@
* Handles a data type defintion element by creating a data type
* handler and initialising is with the details of the element.
*
- * @param tag The name of the element to be handled.
+ * @param name The name of the element to be handled.
* Will not be <code>null</code>.
* @param attrs Attributes of the element to be handled.
* Will not be <code>null</code>.
@@ -687,7 +695,7 @@
/**
* Handles the start of an element within a target.
*
- * @param tag The name of the element being started.
+ * @param name The name of the element being started.
* Will not be <code>null</code>.
* @param attrs Attributes of the element being started.
* Will not be <code>null</code>.
@@ -852,7 +860,7 @@
* will always use another task handler, and all other tasks
* will always use a nested element handler.
*
- * @param tag The name of the element being started.
+ * @param name The name of the element being started.
* Will not be <code>null</code>.
* @param attrs Attributes of the element being started.
* Will not be <code>null</code>.
@@ -864,8 +872,7 @@
if (task instanceof TaskContainer) {
// task can contain other tasks - no other nested elements
possible
new TaskHandler(helperImpl, this, (TaskContainer)task,
wrapper, target).init(name, attrs);
- }
- else {
+ } else {
new NestedElementHandler(helperImpl, this, task, wrapper,
target).init(name, attrs);
}
}
@@ -933,7 +940,7 @@
* its parent container (if any). Nested elements are then
* added later as the parser encounters them.
*
- * @param tag Name of the element which caused this handler
+ * @param propType Name of the element which caused this handler
* to be created. Must not be <code>null</code>.
*
* @param attrs Attributes of the element which caused this
@@ -1003,7 +1010,7 @@
* will always use a task handler, and all other elements
* will always use another nested element handler.
*
- * @param tag The name of the element being started.
+ * @param name The name of the element being started.
* Will not be <code>null</code>.
* @param attrs Attributes of the element being started.
* Will not be <code>null</code>.
@@ -1016,8 +1023,7 @@
// taskcontainer nested element can contain other tasks - no
other
// nested elements possible
new TaskHandler(helperImpl, this, (TaskContainer)child,
childWrapper, target).init(name, attrs);
- }
- else {
+ } else {
new NestedElementHandler(helperImpl, this, child,
childWrapper, target).init(name, attrs);
}
}
@@ -1067,7 +1073,7 @@
* its parent container (if any). Nested elements are then
* added later as the parser encounters them.
*
- * @param tag Name of the element which caused this handler
+ * @param propType Name of the element which caused this handler
* to be created. Must not be <code>null</code>.
*
* @param attrs Attributes of the element which caused this
@@ -1122,7 +1128,7 @@
* Handles the start of an element within this one.
* This will always use a nested element handler.
*
- * @param tag The name of the element being started.
+ * @param name The name of the element being started.
* Will not be <code>null</code>.
* @param attrs Attributes of the element being started.
* Will not be <code>null</code>.
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>