git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270812 13f79535-47bb-0310-9956-ffa450edef68master
@@ -1,87 +1,6 @@ | |||
<project default="jars"> | |||
<property name="src.dir" value="src/main"/> | |||
<property name="component.src.dir" value="${src.dir}/org/apache/ant/component"/> | |||
<property name="build.dir" value="build"/> | |||
<property name="build.classes" value="build/classes"/> | |||
<property name="component.classes.dir" value="org/apache/ant/component"/> | |||
<property name="build.javadocs" value="build/javadocs"/> | |||
<property name="build.lib" value="${build.dir}/lib"/> | |||
<property name="frontend.manifest" value="${src.dir}/org/apache/ant/frontend/manifest.mf"/> | |||
<property name="egg.manifest" value="${src.dir}/org/apache/ant/frontend/eggmanifest.mf"/> | |||
<target name="compile"> | |||
<mkdir dir="${build.classes}"/> | |||
<depend srcdir="${src.dir}" | |||
destdir="${build.classes}" closure="yes" | |||
cache="${build.dir}/depcache"/> | |||
<javac srcdir="${src.dir}" | |||
destdir="${build.classes}" | |||
deprecation="true" | |||
debug="true"/> | |||
<target name="jars"> | |||
<echo message="Mutant is being retructured - returning shortly"/> | |||
</target> | |||
<target name="build-task"> | |||
<echo message="building Task jar from ${component.classes.dir}/${taskset}/**/*.class"/> | |||
<jar jarfile="${build.lib}/task/${taskset}.tsk" | |||
basedir="${build.classes}"> | |||
<zipfileset dir="${component.src.dir}/${taskset}" | |||
prefix="ANT-INF" | |||
includes="antlib.xml"/> | |||
<include name="${component.classes.dir}/${taskset}/**/*.class" /> | |||
</jar> | |||
</target> | |||
<target name="jars" depends="compile"> | |||
<mkdir dir="${build.lib}"/> | |||
<mkdir dir="${build.lib}/task"/> | |||
<jar jarfile="${build.lib}/frontend.jar" | |||
basedir="${build.classes}" | |||
manifest="${frontend.manifest}"> | |||
<include name="org/apache/ant/frontend/*.class" /> | |||
</jar> | |||
<jar jarfile="${build.lib}/egg.jar" | |||
basedir="${build.classes}" | |||
manifest="${egg.manifest}"> | |||
<include name="org/apache/ant/frontend/RemoteLauncher.class" /> | |||
<include name="org/apache/ant/core/support/AntClassLoader.class" /> | |||
</jar> | |||
<jar jarfile="${build.lib}/core.jar" | |||
basedir="${build.classes}"> | |||
<include name="org/apache/ant/core/**/*.class" /> | |||
</jar> | |||
<antcall target="build-task"> | |||
<param name="taskset" value="core"/> | |||
</antcall> | |||
<antcall target="build-task"> | |||
<param name="taskset" value="file"/> | |||
</antcall> | |||
<antcall target="build-task"> | |||
<param name="taskset" value="thread"/> | |||
</antcall> | |||
<copy todir="${build.lib}"> | |||
<fileset dir="lib"/> | |||
</copy> | |||
</target> | |||
<target name="clean"> | |||
<delete dir="${build.dir}"/> | |||
</target> | |||
<target name="javadoc"> | |||
<mkdir dir="${build.javadocs}"/> | |||
<javadoc packagenames="org.apache.*" | |||
sourcepath="${src.dir}" | |||
destdir="${build.javadocs}" | |||
author="true" | |||
version="true" | |||
windowtitle="Ant 2.0 API" | |||
doctitle="Ant 2.0" | |||
private="true" | |||
bottom="Copyright © 2001 Apache Software Foundation. All Rights Reserved."> | |||
<group title="Ant Core" packages="org.apache.ant.core*" /> | |||
<group title="Front End" packages="org.apache.ant.frontend*" /> | |||
<group title="XML Parsing" packages="org.apache.ant.xml*" /> | |||
</javadoc> | |||
</target> | |||
</project> | |||
</project> |
@@ -1,298 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.bootstrap; | |||
import java.io.*; | |||
import java.util.*; | |||
import java.util.zip.*; | |||
import java.lang.reflect.*; | |||
/** | |||
* Bootstrap class to build the rest of ant with a minimum of user intervention | |||
* | |||
* The bootstrap class is able to act as a class loader to load new classes/jars | |||
* into the VM in which it is running. | |||
* | |||
* @author <a href="mailto:conor@apache.org">Conor MacNeill</a> | |||
*/ | |||
public class BootstrapLoader extends ClassLoader { | |||
static public final String RECURSION_GUARD = "ant.bootstrap.recursionGuard"; | |||
static private final int BUFFER_SIZE = 1024; | |||
private String[] classpathElements; | |||
public BootstrapLoader(String classpath) { | |||
StringTokenizer tokenizer = new StringTokenizer(classpath, File.pathSeparator); | |||
classpathElements = new String[tokenizer.countTokens()]; | |||
for (int i = 0; tokenizer.hasMoreTokens(); ++i) { | |||
classpathElements[i] = tokenizer.nextToken(); | |||
} | |||
} | |||
protected Class findClass(String name) | |||
throws ClassNotFoundException { | |||
String resourceName = name.replace('.', '/') + ".class"; | |||
InputStream classStream = getResourceStream(resourceName); | |||
if (classStream == null) { | |||
throw new ClassNotFoundException(); | |||
} | |||
try { | |||
return getClassFromStream(classStream, name); | |||
} | |||
catch (IOException ioe) { | |||
ioe.printStackTrace(); | |||
throw new ClassNotFoundException(); | |||
} | |||
} | |||
/** | |||
* Get a stream to read the requested resource name. | |||
* | |||
* @param name the name of the resource for which a stream is required. | |||
* | |||
* @return a stream to the required resource or null if the resource cannot be | |||
* found on the loader's classpath. | |||
*/ | |||
private InputStream getResourceStream(String name) { | |||
// we need to search the components of the path to see if we can find the | |||
// class we want. | |||
InputStream stream = null; | |||
for (int i = 0; i < classpathElements.length && stream == null; ++i) { | |||
File pathComponent = new File(classpathElements[i]); | |||
stream = getResourceStream(pathComponent, name); | |||
} | |||
return stream; | |||
} | |||
/** | |||
* Get a stream to read the requested resource name. | |||
* | |||
* @param name the name of the resource for which a stream is required. | |||
* | |||
* @return a stream to the required resource or null if the resource cannot be | |||
* found on the loader's classpath. | |||
*/ | |||
public InputStream getResourceAsStream(String name) { | |||
return getResourceStream(name); | |||
} | |||
protected Class loadClass(String name, | |||
boolean resolve) | |||
throws ClassNotFoundException { | |||
Class requestedClass = findLoadedClass(name); | |||
try { | |||
if (requestedClass == null) { | |||
requestedClass = findClass(name); | |||
if (resolve) { | |||
resolveClass(requestedClass); | |||
} | |||
} | |||
return requestedClass; | |||
} | |||
catch (ClassNotFoundException cnfe) { | |||
return super.loadClass(name, resolve); | |||
} | |||
} | |||
/** | |||
* Get an inputstream to a given resource in the given file which may | |||
* either be a directory or a zip file. | |||
* | |||
* @param file the file (directory or jar) in which to search for the resource. | |||
* @param resourceName the name of the resource for which a stream is required. | |||
* | |||
* @return a stream to the required resource or null if the resource cannot be | |||
* found in the given file object | |||
*/ | |||
private InputStream getResourceStream(File file, String resourceName) { | |||
try { | |||
if (!file.exists()) { | |||
return null; | |||
} | |||
if (file.isDirectory()) { | |||
File resource = new File(file, resourceName); | |||
if (resource.exists()) { | |||
return new FileInputStream(resource); | |||
} | |||
} | |||
else { | |||
ZipFile zipFile = null; | |||
try { | |||
zipFile = new ZipFile(file); | |||
ZipEntry entry = zipFile.getEntry(resourceName); | |||
if (entry != null) { | |||
// we need to read the entry out of the zip file into | |||
// a baos and then | |||
ByteArrayOutputStream baos = new ByteArrayOutputStream(); | |||
byte[] buffer = new byte[BUFFER_SIZE]; | |||
int bytesRead; | |||
InputStream stream = zipFile.getInputStream(entry); | |||
while ((bytesRead = stream.read(buffer, 0, BUFFER_SIZE)) != -1) { | |||
baos.write(buffer, 0, bytesRead); | |||
} | |||
return new ByteArrayInputStream(baos.toByteArray()); | |||
} | |||
} | |||
finally { | |||
if (zipFile != null) { | |||
zipFile.close(); | |||
} | |||
} | |||
} | |||
} | |||
catch (Exception e) { | |||
e.printStackTrace(); | |||
} | |||
return null; | |||
} | |||
/** | |||
* Read a class definition from a stream. | |||
* | |||
* @param stream the stream from which the class is to be read. | |||
* @param classname the class name of the class in the stream. | |||
* | |||
* @return the Class object read from the stream. | |||
* | |||
* @throws IOException if there is a problem reading the class from the | |||
* stream. | |||
*/ | |||
private Class getClassFromStream(InputStream stream, String classname) | |||
throws IOException { | |||
ByteArrayOutputStream baos = new ByteArrayOutputStream(); | |||
int bytesRead = -1; | |||
byte[] buffer = new byte[1024]; | |||
while ((bytesRead = stream.read(buffer, 0, 1024)) != -1) { | |||
baos.write(buffer, 0, bytesRead); | |||
} | |||
byte[] classData = baos.toByteArray(); | |||
return defineClass(classname, classData, 0, classData.length); | |||
} | |||
static private void buildAnt() { | |||
System.out.println("Bootstrapping Ant ..."); | |||
} | |||
static private void runWithToolsJar(String[] args) { | |||
try { | |||
String javaHome = System.getProperty("java.home"); | |||
if (javaHome.endsWith("jre")) { | |||
javaHome = javaHome.substring(0, javaHome.length() - 4); | |||
} | |||
File toolsjar = new File(javaHome + "/lib/tools.jar"); | |||
if (!toolsjar.exists()) { | |||
System.out.println("Unable to locate tools.jar. expected it to be in " + | |||
toolsjar.getPath()); | |||
return; | |||
} | |||
String newclasspath = toolsjar.getPath() + File.pathSeparator + | |||
System.getProperty("java.class.path"); | |||
System.out.println("New Classpath is " + newclasspath); | |||
BootstrapLoader loader = new BootstrapLoader(newclasspath); | |||
Class newBootClass = loader.loadClass("org.apache.ant.bootstrap.BootstrapLoader", | |||
true); | |||
final Class[] param = { Class.forName("[Ljava.lang.String;") }; | |||
final Method main = newBootClass.getMethod("main", param); | |||
final Object[] argument = { args }; | |||
main.invoke(null, argument); | |||
} | |||
catch (Exception e) { | |||
e.printStackTrace(); | |||
throw new RuntimeException("Unable to run boot with tools.jar"); | |||
} | |||
} | |||
static public void main(String[] args) { | |||
// check whether the tools.jar is already in the classpath. | |||
try { | |||
Class compilerClass = Class.forName("sun.tools.javac.Main"); | |||
System.out.println("Compiler is available"); | |||
} catch (ClassNotFoundException cnfe) { | |||
if (System.getProperty(RECURSION_GUARD) != null) { | |||
cnfe.printStackTrace(); | |||
System.out.println("Unable to load compiler"); | |||
return; | |||
} | |||
System.setProperty(RECURSION_GUARD, "yes"); | |||
System.out.println("Compiler is not on classpath - locating ..."); | |||
runWithToolsJar(args); | |||
return; | |||
} | |||
buildAnt(); | |||
} | |||
} | |||
@@ -1,75 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2000 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.component.core; | |||
import java.io.File; | |||
import java.net.*; | |||
import org.apache.ant.core.execution.*; | |||
/** | |||
* | |||
* @author <a href="mailto:conor@apache.org">Conor MacNeill</a> | |||
*/ | |||
public class AntAspectHandler extends AbstractAspectHandler { | |||
private String id; | |||
public void setId(String id) { | |||
this.id = id; | |||
} | |||
public void afterConfigElement(Object element) throws ExecutionException { | |||
getAspectContext().setDataValue(id, element); | |||
} | |||
} |
@@ -1,162 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.component.core; | |||
import org.apache.ant.core.execution.*; | |||
import org.apache.ant.core.types.*; | |||
import java.io.*; | |||
/** | |||
* Echo | |||
* | |||
* @author costin@dnt.ro | |||
*/ | |||
public class Echo extends AbstractTask { | |||
protected String message = ""; // required | |||
protected File file = null; | |||
protected boolean append = false; | |||
// by default, messages are always displayed | |||
protected int logLevel = BuildEvent.MSG_WARN; | |||
/** | |||
* Does the work. | |||
* | |||
* @throws ExecutionException if someting goes wrong with the build | |||
*/ | |||
public void execute() throws ExecutionException { | |||
if (file == null) { | |||
log(message, logLevel); | |||
} else { | |||
FileWriter out = null; | |||
try { | |||
out = new FileWriter(file.getAbsolutePath(), append); | |||
out.write(message, 0, message.length()); | |||
} catch (IOException ioe) { | |||
throw new ExecutionException(ioe); | |||
} finally { | |||
if (out != null) { | |||
try { | |||
out.close(); | |||
} catch (IOException ioex) {} | |||
} | |||
} | |||
} | |||
} | |||
/** | |||
* Sets the message variable. | |||
* | |||
* @param msg Sets the value for the message variable. | |||
*/ | |||
public void setMessage(String msg) { | |||
this.message = msg; | |||
} | |||
/** | |||
* Sets the file attribute. | |||
*/ | |||
public void setFile(File file) { | |||
this.file = file; | |||
} | |||
/** | |||
* Shall we append to an existing file? | |||
*/ | |||
public void setAppend(boolean append) { | |||
this.append = append; | |||
} | |||
/** | |||
* Set a multiline message. | |||
*/ | |||
public void addText(String msg) { | |||
message += msg; | |||
} | |||
/** | |||
* Set the logging level to one of | |||
* <ul> | |||
* <li>error</li> | |||
* <li>warning</li> | |||
* <li>info</li> | |||
* <li>verbose</li> | |||
* <li>debug</li> | |||
* <ul> | |||
* <p>The default is "warning" to ensure that messages are | |||
* displayed by default when using the -quiet command line option.</p> | |||
*/ | |||
public void setLevel(EchoLevel echoLevel) { | |||
String option = echoLevel.getValue(); | |||
if (option.equals("error")) { | |||
logLevel = BuildEvent.MSG_ERR; | |||
} else if (option.equals("warning")) { | |||
logLevel = BuildEvent.MSG_WARN; | |||
} else if (option.equals("info")) { | |||
logLevel = BuildEvent.MSG_INFO; | |||
} else if (option.equals("verbose")) { | |||
logLevel = BuildEvent.MSG_VERBOSE; | |||
} else { | |||
// must be "debug" | |||
logLevel = BuildEvent.MSG_DEBUG; | |||
} | |||
} | |||
public static class EchoLevel extends EnumeratedAttribute { | |||
public String[] getValues() { | |||
return new String[] {"error", "warning", "info", "verbose", "debug"}; | |||
} | |||
} | |||
} |
@@ -1,98 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2000 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.component.core; | |||
import org.apache.ant.core.execution.*; | |||
import org.apache.ant.core.types.EnumeratedAttribute; | |||
/** | |||
* Convert between a string and an enumeration | |||
* | |||
* @author <a href="mailto:conor@apache.org">Conor MacNeill</a> | |||
*/ | |||
public class EnumeratedAttributeConverter implements AntConverter { | |||
private ExecutionFrame frame; | |||
public void init(ExecutionFrame frame) { | |||
this.frame = frame; | |||
} | |||
public Object convert(String value, Class type) throws ConversionException { | |||
// The string represents a value | |||
// get the frame's URL | |||
try { | |||
Object instance = type.newInstance(); | |||
if (!(instance instanceof EnumeratedAttribute)) { | |||
throw new ConversionException("The type " + type.getName() | |||
+ " is not a subclass of EnumeratedAttribute"); | |||
} | |||
EnumeratedAttribute enum = (EnumeratedAttribute)instance; | |||
enum.setValue(value.trim()); | |||
return enum; | |||
} | |||
catch (InstantiationException e) { | |||
throw new ConversionException("Unable to instantiate the enumerated type " | |||
+ type.getName()); | |||
} | |||
catch (IllegalAccessException e) { | |||
throw new ConversionException("Illegale access when instantiation enumerated type " | |||
+ type.getName()); | |||
} | |||
catch (ExecutionException e) { | |||
throw new ConversionException("Unable to set the value of the enumerated type " | |||
+ type.getName() + ": " + e.getMessage()); | |||
} | |||
} | |||
} |
@@ -1,87 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2000 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.component.core; | |||
import java.io.File; | |||
import java.net.*; | |||
import org.apache.ant.core.execution.*; | |||
/** | |||
* Convert between a string and a data type | |||
* | |||
* @author <a href="mailto:conor@apache.org">Conor MacNeill</a> | |||
*/ | |||
public class FileConverter implements AntConverter { | |||
private ExecutionFrame frame; | |||
public void init(ExecutionFrame frame) { | |||
this.frame = frame; | |||
} | |||
public Object convert(String value, Class type) throws ConversionException { | |||
// The string represents a value | |||
// get the frame's URL | |||
try { | |||
URL url = new URL(frame.getBaseURL(), value); | |||
if (url.getProtocol().equals("file")) { | |||
return new File(url.getFile()); | |||
} | |||
} | |||
catch (MalformedURLException e) { | |||
// ignore and return as a file. | |||
} | |||
return new File(value); | |||
} | |||
} |
@@ -1,248 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.component.core; | |||
import java.util.*; | |||
import java.io.*; | |||
import org.apache.ant.core.execution.*; | |||
import java.net.*; | |||
/** | |||
* | |||
*/ | |||
public class Property extends AbstractTask { | |||
private String name; | |||
private String value; | |||
private URL file; | |||
private String resource; | |||
// private Path classpath; | |||
private String env; | |||
// private Reference ref = null; | |||
public void setName(String name) { | |||
this.name = name; | |||
} | |||
public String getName() { | |||
return name; | |||
} | |||
public void setValue(String value) { | |||
this.value = value; | |||
} | |||
public String getValue() { | |||
return value; | |||
} | |||
public void setFile(URL file) { | |||
this.file = file; | |||
} | |||
public URL getFile() { | |||
return file; | |||
} | |||
public void setLocation(File location) { | |||
setValue(location.getAbsolutePath()); | |||
} | |||
// public void setRefid(Reference ref) { | |||
// this.ref = ref; | |||
// } | |||
// | |||
// public Reference getRefid() { | |||
// return ref; | |||
// } | |||
// | |||
public void setResource(String resource) { | |||
this.resource = resource; | |||
} | |||
public String getResource() { | |||
return resource; | |||
} | |||
public void setEnvironment(String env) { | |||
this.env = env; | |||
} | |||
public String getEnvironment() { | |||
return env; | |||
} | |||
// public void setClasspath(Path classpath) { | |||
// if (this.classpath == null) { | |||
// this.classpath = classpath; | |||
// } else { | |||
// this.classpath.append(classpath); | |||
// } | |||
// } | |||
// | |||
// public Path createClasspath() { | |||
// if (this.classpath == null) { | |||
// this.classpath = new Path(project); | |||
// } | |||
// return this.classpath.createPath(); | |||
// } | |||
// | |||
// public void setClasspathRef(Reference r) { | |||
// createClasspath().setRefid(r); | |||
// } | |||
// | |||
public void execute() throws ExecutionException { | |||
if ((name != null) && (value != null)) { | |||
getTaskContext().setDataValue(name, value); | |||
} | |||
if (file != null) { | |||
loadFile(file); | |||
} | |||
// if (resource != null) loadResource(resource); | |||
// | |||
// if (env != null) loadEnvironment(env); | |||
// | |||
// if ((name != null) && (ref != null)) { | |||
// Object obj = ref.getReferencedObject(getProject()); | |||
// if (obj != null) { | |||
// addProperty(name, obj.toString()); | |||
// } | |||
// } | |||
} | |||
protected void loadFile (URL url) throws ExecutionException { | |||
Properties props = new Properties(); | |||
log("Loading " + url, BuildEvent.MSG_VERBOSE); | |||
try { | |||
InputStream stream = null; | |||
if (url.getProtocol().equals("file")) { | |||
File file = new File(url.getFile()); | |||
if (file.exists()) { | |||
stream = new FileInputStream(file); | |||
} | |||
} | |||
else { | |||
stream = url.openStream(); | |||
} | |||
if (stream != null) { | |||
try { | |||
props.load(stream); | |||
resolveAllProperties(props); | |||
addProperties(props); | |||
} finally { | |||
stream.close(); | |||
} | |||
} | |||
} catch (IOException e) { | |||
throw new ExecutionException("Unable to load property file: " + url, e); | |||
} | |||
} | |||
protected void addProperties(Properties properties) throws ExecutionException { | |||
for (Iterator i = properties.keySet().iterator(); i.hasNext();) { | |||
String propertyName = (String)i.next(); | |||
String propertyValue = properties.getProperty(propertyName); | |||
getTaskContext().setDataValue(propertyName, | |||
getTaskContext().replacePropertyRefs(propertyValue)); | |||
} | |||
} | |||
private void resolveAllProperties(Properties props) throws ExecutionException { | |||
for (Iterator propIterator = props.keySet().iterator(); propIterator.hasNext();) { | |||
String name = (String)propIterator.next(); | |||
String value = props.getProperty(name); | |||
boolean resolved = false; | |||
while (!resolved) { | |||
List fragments = new ArrayList(); | |||
List propertyRefs = new ArrayList(); | |||
ExecutionFrame.parsePropertyString(value, fragments, propertyRefs); | |||
resolved = true; | |||
if (propertyRefs.size() != 0) { | |||
StringBuffer sb = new StringBuffer(); | |||
Iterator i = fragments.iterator(); | |||
Iterator j = propertyRefs.iterator(); | |||
while (i.hasNext()) { | |||
String fragment = (String)i.next(); | |||
if (fragment == null) { | |||
String propertyName = (String)j.next(); | |||
if (propertyName.equals(name)) { | |||
throw new ExecutionException("Property " + name | |||
+ " from " + file | |||
+ " was circularly defined."); | |||
} | |||
if (props.containsKey(propertyName)) { | |||
fragment = props.getProperty(propertyName); | |||
resolved = false; | |||
} | |||
else { | |||
fragment = "${" + propertyName + "}"; | |||
} | |||
} | |||
sb.append(fragment); | |||
} | |||
value = sb.toString(); | |||
props.put(name, value); | |||
} | |||
} | |||
} | |||
} | |||
} | |||
@@ -1,93 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2000 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.component.core; | |||
import org.apache.ant.core.execution.*; | |||
import java.net.*; | |||
import java.io.File; | |||
/** | |||
* Convert between a string and a URL, resolved to the ExecutionFrame's base | |||
* | |||
* @author <a href="mailto:conor@apache.org">Conor MacNeill</a> | |||
*/ | |||
public class URLConverter implements AntConverter { | |||
private ExecutionFrame frame; | |||
public void init(ExecutionFrame frame) { | |||
this.frame = frame; | |||
} | |||
public Object convert(String value, Class type) throws ConversionException { | |||
// The string represents a value | |||
// get the frame's URL | |||
try { | |||
URL url = new URL(frame.getBaseURL(), value); | |||
return url; | |||
} | |||
catch (MalformedURLException e) { | |||
//try a local file | |||
try { | |||
File file = new File(value); | |||
return file.toURL(); | |||
} | |||
catch (MalformedURLException e2) { | |||
throw new ConversionException("Unable to convert " + value | |||
+ " into a URL relative to the project's base"); | |||
} | |||
} | |||
} | |||
} |
@@ -1,18 +0,0 @@ | |||
<antlib> | |||
<!-- Tasks --> | |||
<taskdef name="property" classname="org.apache.ant.component.core.Property"/> | |||
<taskdef name="echo" classname="org.apache.ant.component.core.Echo"/> | |||
<!-- Data Types --> | |||
<taskdef name="patternset" classname="org.apache.ant.core.types.PatternSet"/> | |||
<taskdef name="fileset" classname="org.apache.ant.core.types.FileSet"/> | |||
<!-- Converters --> | |||
<converter target="java.io.File" classname="org.apache.ant.component.core.FileConverter"/> | |||
<converter target="java.net.URL" classname="org.apache.ant.component.core.URLConverter"/> | |||
<converter target="org.apache.ant.core.types.EnumeratedAttribute" | |||
classname="org.apache.ant.component.core.EnumeratedAttributeConverter"/> | |||
<!-- Aspect Handlers --> | |||
<aspect prefix="ant" classname="org.apache.ant.component.core.AntAspectHandler"/> | |||
</antlib> |
@@ -1,2 +0,0 @@ | |||
<antlib> | |||
</antlib> |
@@ -1,78 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.component.thread; | |||
import org.apache.ant.core.execution.*; | |||
import java.io.*; | |||
import java.util.*; | |||
/** | |||
* Parallel execution of contained tasks. | |||
* | |||
*/ | |||
public class Parallel extends AbstractTask implements TaskContainer { | |||
private List tasks = new ArrayList(); | |||
public void addTask(Task nestedTask) { | |||
tasks.add(nestedTask); | |||
} | |||
public void execute() throws ExecutionException { | |||
for (Iterator i = tasks.iterator(); i.hasNext(); ) { | |||
Task nestedTask = (Task)i.next(); | |||
nestedTask.execute(); | |||
} | |||
} | |||
} |
@@ -1,78 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.component.thread; | |||
import org.apache.ant.core.execution.*; | |||
import java.io.*; | |||
import java.util.*; | |||
/** | |||
* Sequential execution of contained tasks. | |||
* | |||
*/ | |||
public class Sequential extends AbstractTask implements TaskContainer { | |||
private List tasks = new ArrayList(); | |||
public void addTask(Task nestedTask) { | |||
tasks.add(nestedTask); | |||
} | |||
public void execute() throws ExecutionException { | |||
for (Iterator i = tasks.iterator(); i.hasNext(); ) { | |||
Task nestedTask = (Task)i.next(); | |||
nestedTask.execute(); | |||
} | |||
} | |||
} |
@@ -1,4 +0,0 @@ | |||
<antlib> | |||
<taskdef name="parallel" classname="org.apache.ant.component.thread.Parallel"/> | |||
<taskdef name="sequential" classname="org.apache.ant.component.thread.Sequential"/> | |||
</antlib> |
@@ -1,147 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.core.config; | |||
import java.io.*; | |||
import java.net.MalformedURLException; | |||
import java.net.URL; | |||
import java.net.URLClassLoader; | |||
import java.util.*; | |||
import org.apache.ant.core.execution.*; | |||
import org.apache.ant.core.support.*; | |||
import org.apache.ant.core.xml.AntLibParser; | |||
import org.xml.sax.SAXParseException; | |||
/** | |||
* Manager for Ant components | |||
* | |||
* The component manager is responsible for locating and loading the | |||
* components contained in Ant's lib/task directory. | |||
* | |||
* @author <a href="mailto:conor@apache.org">Conor MacNeill</a> | |||
*/ | |||
public class ComponentManager { | |||
/** | |||
* When Ant is run remotely, we need to look up the list of component | |||
* libraries from the server. | |||
*/ | |||
static public String COMPONENT_INDEX = "taskindex"; | |||
/** | |||
* Create the component manager. When the component manager is created | |||
* it will read the component definitions from the files in | |||
* Ant's lib/task directory | |||
*/ | |||
static public AntLibrary[] getComponents() throws LocationException, ConfigException { | |||
try { | |||
URL componentsLocation = new URL(AntLocator.getLibraryURL(), "task/"); | |||
URL[] componentFiles = null; | |||
if (componentsLocation.getProtocol().equals("file")) { | |||
// component directory is local - we determine the | |||
// component files by scanning the local directory | |||
HashSet componentFilesTypes = new HashSet(); | |||
componentFilesTypes.add(".tsk"); | |||
componentFilesTypes.add(".jar"); | |||
componentFilesTypes.add(".zip"); | |||
File componentsDirectory = new File(componentsLocation.getFile()); | |||
componentFiles = AntLocator.getDirectoryURLs(componentsDirectory, componentFilesTypes); | |||
} | |||
else { | |||
// The component directory is remote - we determine the | |||
// list of component files by reading a "known" list file. | |||
URL componentListURL = new URL(componentsLocation, COMPONENT_INDEX); | |||
BufferedReader reader = null; | |||
List componentList = new ArrayList(); | |||
try { | |||
reader = new BufferedReader(new InputStreamReader(componentListURL.openStream())); | |||
String line = null; | |||
while ((line = reader.readLine()) != null) { | |||
componentList.add(new URL(componentsLocation, line.trim())); | |||
} | |||
} | |||
finally { | |||
if (reader != null) { | |||
reader.close(); | |||
} | |||
} | |||
componentFiles = (URL[])componentList.toArray(new URL[0]); | |||
} | |||
AntLibParser libdefParser = new AntLibParser(); | |||
List libraries = new ArrayList(); | |||
for (int i = 0; i < componentFiles.length; ++i) { | |||
// We create a classloader for the component library | |||
URL[] componentURLs = new URL[]{componentFiles[i]}; | |||
AntClassLoader componentClassLoader | |||
= new AntClassLoader(componentURLs, | |||
ComponentManager.class.getClassLoader(), | |||
componentFiles[i].toString()); | |||
URL libDefinition = componentClassLoader.getResource("ANT-INF/antlib.xml"); | |||
if (libDefinition != null) { | |||
AntLibrary library | |||
= libdefParser.parseAntLibrary(libDefinition, componentClassLoader); | |||
libraries.add(library); | |||
} | |||
} | |||
return (AntLibrary[])libraries.toArray(new AntLibrary[0]); | |||
} | |||
catch (IOException e) { | |||
throw new ConfigException(e); | |||
} | |||
} | |||
} | |||
@@ -1,83 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.core.execution; | |||
import org.apache.ant.core.model.*; | |||
import org.apache.ant.core.support.*; | |||
import java.util.*; | |||
import java.net.URL; | |||
/** | |||
* | |||
* @author <a href="mailto:conor@apache.org">Conor MacNeill</a> | |||
*/ | |||
public abstract class AbstractAspectHandler implements AspectHandler { | |||
private ExecutionContext aspectContext; | |||
public void setAspectContext(ExecutionContext context) { | |||
this.aspectContext = context; | |||
} | |||
protected ExecutionContext getAspectContext() { | |||
return aspectContext; | |||
} | |||
public void beforeConfigElement(Object element) throws ExecutionException { | |||
} | |||
public void afterConfigElement(Object element) throws ExecutionException { | |||
} | |||
} | |||
@@ -1,96 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.core.execution; | |||
import org.apache.ant.core.model.*; | |||
import org.apache.ant.core.support.*; | |||
import java.util.*; | |||
import java.net.URL; | |||
/** | |||
* @author <a href="mailto:conor@apache.org">Conor MacNeill</a> | |||
*/ | |||
public abstract class AbstractTask implements Task { | |||
private ExecutionContext taskContext; | |||
public void setTaskContext(ExecutionContext context) { | |||
this.taskContext = context; | |||
} | |||
protected ExecutionContext getTaskContext() { | |||
return taskContext; | |||
} | |||
/** | |||
* Log a message with the default (INFO) priority. | |||
* | |||
* @param msg the message to be logged. | |||
*/ | |||
public void log(String msg) { | |||
log(msg, BuildEvent.MSG_INFO); | |||
} | |||
/** | |||
* Log a mesage with the give priority. | |||
* | |||
* @param the message to be logged. | |||
* @param msgLevel the message priority at which this message is to be logged. | |||
*/ | |||
public void log(String msg, int msgLevel) { | |||
taskContext.log(msg, msgLevel); | |||
} | |||
} | |||
@@ -1,65 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2000 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.core.execution; | |||
/** | |||
* An AntConverter is a Converter which is initialised with the | |||
* ExecutionFrame context in which it will perform its conversions | |||
* | |||
* @author <a href="mailto:conor@apache.org">Conor MacNeill</a> | |||
*/ | |||
public interface AntConverter extends Converter { | |||
void init(ExecutionFrame frame); | |||
} |
@@ -1,137 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.core.execution; | |||
import org.apache.ant.core.support.*; | |||
import java.util.*; | |||
import java.net.URL; | |||
/** | |||
* This object represents an Ant library definition. An Ant library | |||
* is a set of plug-in for Ant consisting primarily of tasks but may include | |||
* other ant components. | |||
* | |||
* @author <a href="mailto:conor@apache.org">Conor MacNeill</a> | |||
*/ | |||
public class AntLibrary { | |||
/** | |||
* The task definitions contained by this library | |||
*/ | |||
private Map taskDefinitions = new HashMap(); | |||
/** | |||
* The converter definitions contained by this library | |||
*/ | |||
private Map converterDefinitions = new HashMap(); | |||
/** | |||
* The aspect handler definitions contained by this library | |||
*/ | |||
private Map aspectDefinitions = new HashMap(); | |||
/** | |||
* Add a task definition to this library | |||
*/ | |||
public void addTaskDefinition(TaskDefinition taskDefinition) { | |||
String taskName = taskDefinition.getName(); | |||
taskDefinitions.put(taskName, taskDefinition); | |||
} | |||
/** | |||
* Add a converter definition to this library | |||
*/ | |||
public void addConverterDefinition(ConverterDefinition converterDef) { | |||
String targetClassname = converterDef.getTargetClassName(); | |||
converterDefinitions.put(targetClassname, converterDef); | |||
} | |||
/** | |||
* Add an aspect handler definition to this library | |||
*/ | |||
public void addAspectDefinition(AspectDefinition aspectDef) { | |||
String aspectPrefix = aspectDef.getAspectPrefix(); | |||
aspectDefinitions.put(aspectPrefix, aspectDef); | |||
} | |||
/** | |||
* Get the task definitions | |||
* | |||
* @return an iterator which returns TaskDefinition objects. | |||
*/ | |||
public Iterator getTaskDefinitions() { | |||
return taskDefinitions.values().iterator(); | |||
} | |||
/** | |||
* Get the converter definitions | |||
* | |||
* @return an iterator which returns ConverterDefinition objects. | |||
*/ | |||
public Iterator getConverterDefinitions() { | |||
return converterDefinitions.values().iterator(); | |||
} | |||
/** | |||
* Get the aspect handler definitions | |||
* | |||
* @return an iterator which returns AspectDefinition objects. | |||
*/ | |||
public Iterator getAspectDefinitions() { | |||
return aspectDefinitions.values().iterator(); | |||
} | |||
} | |||
@@ -1,124 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.core.execution; | |||
import java.util.*; | |||
import java.net.URL; | |||
/** | |||
* @author <a href="mailto:conor@apache.org">Conor MacNeill</a> | |||
*/ | |||
public class AspectDefinition { | |||
/** The URL of the library which defines this aspect handler */ | |||
private URL aspectLibraryURL; | |||
/** The aspect's tag */ | |||
private String aspectPrefix; | |||
/** The aspect handler's classname */ | |||
private String aspectClassName; | |||
/** The aspect handler's class loader. */ | |||
private ClassLoader aspectClassLoader; | |||
/** The class to which this converter converts. */ | |||
private Class aspectHandlerClass = null; | |||
public AspectDefinition(URL aspectLibraryURL, String aspectPrefix, | |||
String aspectClassName, ClassLoader aspectClassLoader) { | |||
this.aspectLibraryURL = aspectLibraryURL; | |||
this.aspectPrefix = aspectPrefix; | |||
this.aspectClassName = aspectClassName; | |||
this.aspectClassLoader = aspectClassLoader; | |||
} | |||
/** | |||
* Get the URL where this aspect handler was defined. | |||
* | |||
* @returns a URL of the lib defintion file | |||
*/ | |||
public URL getLibraryURL() { | |||
return aspectLibraryURL; | |||
} | |||
/** | |||
* Get the Aspect's Prefix | |||
*/ | |||
public String getAspectPrefix() { | |||
return aspectPrefix; | |||
} | |||
/** | |||
* Get the aspect handler class | |||
* | |||
* @return a class object for this aspect handler's class | |||
*/ | |||
public synchronized Class getAspectHandlerClass() throws ClassNotFoundException { | |||
if (aspectHandlerClass == null) { | |||
aspectHandlerClass = Class.forName(aspectClassName, true, aspectClassLoader); | |||
} | |||
return aspectHandlerClass; | |||
} | |||
/** | |||
* Get the classname of the aspect handler that is being defined. | |||
*/ | |||
public String getAspectHandlerClassName() { | |||
return aspectClassName; | |||
} | |||
} | |||
@@ -1,75 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.core.execution; | |||
import org.apache.ant.core.model.*; | |||
import org.apache.ant.core.support.*; | |||
import java.util.*; | |||
import java.net.URL; | |||
/** | |||
* An AspectHandler is used to handle a set of aspects which may occur in a number | |||
* of elements in the build model. | |||
* | |||
* @author <a href="mailto:conor@apache.org">Conor MacNeill</a> | |||
*/ | |||
public interface AspectHandler { | |||
void setAspectContext(ExecutionContext context); | |||
void beforeConfigElement(Object element) throws ExecutionException ; | |||
void afterConfigElement(Object element) throws ExecutionException ; | |||
} | |||
@@ -1,171 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 1999 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.core.execution; | |||
import java.util.EventObject; | |||
import org.apache.ant.core.model.*; | |||
/* | |||
* A BuildEvent indicates the occurence of a significant event | |||
* in the build. | |||
* | |||
* All build events come from an ExecutionFrame or an ExecutionManager. | |||
* There are a number of different types of event and they will | |||
* generally be associated with some build element from the build model. | |||
*/ | |||
public class BuildEvent extends EventObject { | |||
public static final int MSG_ERR = 0; | |||
public static final int MSG_WARN = 1; | |||
public static final int MSG_INFO = 2; | |||
public static final int MSG_VERBOSE = 3; | |||
public static final int MSG_DEBUG = 4; | |||
public static final int BUILD_STARTED = 1; | |||
public static final int BUILD_FINISHED = 2; | |||
public static final int TARGET_STARTED = 3; | |||
public static final int TARGET_FINISHED = 4; | |||
public static final int TASK_STARTED = 5; | |||
public static final int TASK_FINISHED = 6; | |||
public static final int MESSAGE = 7; | |||
private int eventType; | |||
private BuildElement buildElement = null; | |||
private Throwable cause = null; | |||
private String message = null; | |||
private int messagePriority; | |||
/** | |||
* Create a build event. | |||
* | |||
* @param soure the source of the build event. | |||
* @param eventType the type of the buildEvent. | |||
* @param buildElement the build element with which the event is associated. | |||
*/ | |||
public BuildEvent(Object source, int eventType, BuildElement buildElement) { | |||
super(source); | |||
this.eventType = eventType; | |||
this.buildElement = buildElement; | |||
} | |||
/** | |||
* Create a build event with an associated exception. | |||
* | |||
* @param soure the source of the build event. | |||
* @param eventType the type of the buildEvent. | |||
* @param buildElement the build element with which the event is associated. | |||
*/ | |||
public BuildEvent(Object source, int eventType, BuildElement buildElement, | |||
Throwable cause) { | |||
this(source, eventType, buildElement); | |||
this.cause = cause; | |||
} | |||
/** | |||
* Create a build event for a message | |||
* | |||
* @param soure the source of the build event. | |||
* @param buildElement the build element with which the event is associated. | |||
* @param message the message associated with this event | |||
* @param priority the message priority | |||
*/ | |||
public BuildEvent(Object source, BuildElement buildElement, String message, | |||
int priority) { | |||
this(source, MESSAGE, buildElement); | |||
this.message = message; | |||
this.messagePriority = priority; | |||
} | |||
/** | |||
* Get the type of this event | |||
* | |||
* @return the event type | |||
*/ | |||
public int getEventType() { | |||
return eventType; | |||
} | |||
/** | |||
* Get the build element involved in this event. | |||
* | |||
* @return the build element to which this event is associated. | |||
*/ | |||
public BuildElement getBuildElement() { | |||
return buildElement; | |||
} | |||
/** | |||
* Returns the logging message. This field will only be set | |||
* for "messageLogged" events. | |||
* | |||
*/ | |||
public String getMessage() { | |||
return message; | |||
} | |||
/** | |||
* Returns the priority of the logging message. This field will only | |||
* be set for "messageLogged" events. | |||
*/ | |||
public int getPriority(){ | |||
return messagePriority; | |||
} | |||
/** | |||
* Returns the exception that was thrown, if any. This field will only | |||
* be set for "taskFinished", "targetFinished", and "buildFinished" events. | |||
*/ | |||
public Throwable getCause() { | |||
return cause; | |||
} | |||
} |
@@ -1,116 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 1999 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.core.execution; | |||
import java.util.*; | |||
import org.apache.ant.core.model.*; | |||
/** | |||
* BuildEventSupport is used by classes which which to send | |||
* build events to the BuoldListeners | |||
*/ | |||
public class BuildEventSupport { | |||
private List listeners = new ArrayList(); | |||
public void addBuildListener(BuildListener listener) { | |||
listeners.add(listener); | |||
} | |||
public void removeBuildListener(BuildListener listener) { | |||
listeners.remove(listener); | |||
} | |||
public void forwardEvent(BuildEvent event) { | |||
for (Iterator i = listeners.iterator(); i.hasNext();) { | |||
BuildListener listener = (BuildListener)i.next(); | |||
listener.processBuildEvent(event); | |||
} | |||
} | |||
public void fireBuildStarted(Object source, BuildElement element) { | |||
BuildEvent event = new BuildEvent(source, BuildEvent.BUILD_STARTED, element); | |||
forwardEvent(event); | |||
} | |||
public void fireBuildFinished(Object source, BuildElement element, Throwable cause) { | |||
BuildEvent event = new BuildEvent(source, BuildEvent.BUILD_FINISHED, element, cause); | |||
forwardEvent(event); | |||
} | |||
public void fireTargetStarted(Object source, BuildElement element) { | |||
BuildEvent event = new BuildEvent(source, BuildEvent.TARGET_STARTED, element); | |||
forwardEvent(event); | |||
} | |||
public void fireTargetFinished(Object source, BuildElement element, Throwable cause) { | |||
BuildEvent event = new BuildEvent(source, BuildEvent.TARGET_FINISHED, element, cause); | |||
forwardEvent(event); | |||
} | |||
public void fireTaskStarted(Object source, BuildElement element) { | |||
BuildEvent event = new BuildEvent(source, BuildEvent.TASK_STARTED, element); | |||
forwardEvent(event); | |||
} | |||
public void fireTaskFinished(Object source, BuildElement element, Throwable cause) { | |||
BuildEvent event = new BuildEvent(source, BuildEvent.TASK_FINISHED, element, cause); | |||
forwardEvent(event); | |||
} | |||
public void fireMessageLogged(Object source, BuildElement element, | |||
String message, int priority) { | |||
BuildEvent event = new BuildEvent(source, element, message, priority); | |||
forwardEvent(event); | |||
} | |||
} |
@@ -1,67 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 1999 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.core.execution; | |||
import java.util.EventListener; | |||
/** | |||
* Classes that implement this interface will be notified when | |||
* things happend during a build. | |||
* | |||
* @see BuildEvent | |||
*/ | |||
public interface BuildListener extends EventListener { | |||
void processBuildEvent(BuildEvent event); | |||
} |
@@ -1,144 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.core.execution; | |||
import java.io.*; | |||
/** | |||
* | |||
* @author <a href="mailto:conor@apache.org">Conor MacNeill</a> | |||
*/ | |||
public class ClassIntrospectionException extends Exception { | |||
/** | |||
* Exception that might have caused this one. | |||
*/ | |||
private Throwable cause = null; | |||
/** | |||
* Constructs an exception with the given descriptive message. | |||
* @param msg Description of or information about the exception. | |||
*/ | |||
public ClassIntrospectionException(String msg) { | |||
super(msg); | |||
} | |||
/** | |||
* Constructs an exception with the given message and exception as | |||
* a root cause. | |||
* @param msg Description of or information about the exception. | |||
* @param cause Throwable that might have cause this one. | |||
*/ | |||
public ClassIntrospectionException(String msg, Throwable cause) { | |||
super(msg); | |||
this.cause = cause; | |||
} | |||
/** | |||
* Constructs an exception with the given exception as a root cause. | |||
* @param cause Exception that might have caused this one. | |||
*/ | |||
public ClassIntrospectionException(Throwable cause) { | |||
super(cause.getMessage()); | |||
this.cause = cause; | |||
} | |||
/** | |||
* Returns the nested exception. | |||
* | |||
* @return the underlying exception | |||
*/ | |||
public Throwable getCause() { | |||
return cause; | |||
} | |||
/** | |||
* Print the stack trace to System.err | |||
*/ | |||
public void printStackTrace() { | |||
printStackTrace(System.err); | |||
} | |||
/** | |||
* Print the stack trace to the given PrintStream | |||
* | |||
* @param ps the PrintStream onto which the stack trace | |||
* of this exception is to be printed | |||
*/ | |||
public void printStackTrace(PrintStream ps) { | |||
synchronized (ps) { | |||
ps.println(this); | |||
if (cause != null) { | |||
ps.println("--- Nested Exception ---"); | |||
cause.printStackTrace(ps); | |||
} | |||
} | |||
} | |||
/** | |||
* Print the stack trace to the given PrintWriter | |||
* | |||
* @param pw the PrintWriter onto which the stack trace | |||
* of this exception is to be printed | |||
*/ | |||
public void printStackTrace(PrintWriter pw) { | |||
synchronized (pw) { | |||
pw.println(this); | |||
if (cause != null) { | |||
pw.println("--- Nested Exception ---"); | |||
cause.printStackTrace(pw); | |||
} | |||
} | |||
} | |||
} |
@@ -1,477 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2000 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.core.execution; | |||
import java.lang.reflect.*; | |||
import java.io.File; | |||
import java.util.*; | |||
/** | |||
* Introspects a class and builds a set of objects to assist in intospecting the | |||
* class. | |||
* | |||
* @author Stefan Bodewig <a href="mailto:stefan.bodewig@megabit.net">stefan.bodewig@megabit.net</a> | |||
* @author <a href="mailto:conor@apache.org">Conor MacNeill</a> | |||
*/ | |||
public class ClassIntrospector { | |||
/** | |||
* holds the types of the attributes that could be set. | |||
*/ | |||
private Hashtable attributeTypes; | |||
/** | |||
* holds the attribute setter methods. | |||
*/ | |||
private Hashtable attributeSetters; | |||
/** | |||
* Holds the types of nested elements that could be created. | |||
*/ | |||
private Hashtable nestedTypes; | |||
/** | |||
* Holds methods to create nested elements. | |||
*/ | |||
private Hashtable nestedCreators; | |||
/** | |||
* The method to add PCDATA stuff. | |||
*/ | |||
private Method addText = null; | |||
/** | |||
* The Class that's been introspected. | |||
*/ | |||
private Class bean; | |||
/** | |||
* returns the boolean equivalent of a string, which is considered true | |||
* if either "on", "true", or "yes" is found, ignoring case. | |||
*/ | |||
public static boolean toBoolean(String s) { | |||
return (s.equalsIgnoreCase("on") || | |||
s.equalsIgnoreCase("true") || | |||
s.equalsIgnoreCase("yes")); | |||
} | |||
public ClassIntrospector(final Class bean, Map converters) { | |||
attributeTypes = new Hashtable(); | |||
attributeSetters = new Hashtable(); | |||
nestedTypes = new Hashtable(); | |||
nestedCreators = new Hashtable(); | |||
this.bean = bean; | |||
Method[] methods = bean.getMethods(); | |||
for (int i=0; i<methods.length; i++) { | |||
final Method m = methods[i]; | |||
final String name = m.getName(); | |||
Class returnType = m.getReturnType(); | |||
Class[] args = m.getParameterTypes(); | |||
if ("addText".equals(name) | |||
&& java.lang.Void.TYPE.equals(returnType) | |||
&& args.length == 1 | |||
&& java.lang.String.class.equals(args[0])) { | |||
addText = methods[i]; | |||
} else if (name.startsWith("set") | |||
&& java.lang.Void.TYPE.equals(returnType) | |||
&& args.length == 1 | |||
&& !args[0].isArray()) { | |||
String propName = getPropertyName(name, "set"); | |||
AttributeSetter as = createAttributeSetter(m, args[0], converters); | |||
if (as != null) { | |||
attributeTypes.put(propName, args[0]); | |||
attributeSetters.put(propName, as); | |||
} | |||
} else if (name.startsWith("create") | |||
&& !returnType.isArray() | |||
&& !returnType.isPrimitive() | |||
&& args.length == 0) { | |||
String propName = getPropertyName(name, "create"); | |||
nestedTypes.put(propName, returnType); | |||
nestedCreators.put(propName, new NestedCreator() { | |||
public Object create(Object parent) | |||
throws InvocationTargetException, | |||
IllegalAccessException { | |||
return m.invoke(parent, new Object[] {}); | |||
} | |||
}); | |||
} else if (name.startsWith("add") | |||
&& java.lang.Void.TYPE.equals(returnType) | |||
&& args.length == 1 | |||
&& !java.lang.String.class.equals(args[0]) | |||
&& !args[0].isArray() | |||
&& !args[0].isPrimitive()) { | |||
try { | |||
final Constructor c = | |||
args[0].getConstructor(new Class[] {}); | |||
String propName = getPropertyName(name, "add"); | |||
nestedTypes.put(propName, args[0]); | |||
nestedCreators.put(propName, new NestedCreator() { | |||
public Object create(Object parent) | |||
throws InvocationTargetException, IllegalAccessException, InstantiationException { | |||
Object o = c.newInstance(new Object[] {}); | |||
m.invoke(parent, new Object[] {o}); | |||
return o; | |||
} | |||
}); | |||
} catch (NoSuchMethodException nse) { | |||
} | |||
} | |||
} | |||
} | |||
/** | |||
* Sets the named attribute. | |||
*/ | |||
public void setAttribute(Object element, String attributeName, | |||
String value) | |||
throws ClassIntrospectionException, ConversionException { | |||
AttributeSetter as = (AttributeSetter) attributeSetters.get(attributeName); | |||
if (as == null) { | |||
String msg = "Class " + element.getClass().getName() + | |||
" doesn't support the \"" + attributeName + "\" attribute"; | |||
throw new ClassIntrospectionException(msg); | |||
} | |||
try { | |||
as.set(element, value); | |||
} catch (IllegalAccessException ie) { | |||
// impossible as getMethods should only return public methods | |||
throw new ClassIntrospectionException(ie); | |||
} catch (InvocationTargetException ite) { | |||
Throwable t = ite.getTargetException(); | |||
if (t instanceof ClassIntrospectionException) { | |||
throw (ClassIntrospectionException) t; | |||
} | |||
throw new ClassIntrospectionException(t); | |||
} | |||
} | |||
/** | |||
* Adds PCDATA areas. | |||
*/ | |||
public void addText(Object element, String text) | |||
throws ClassIntrospectionException { | |||
if (addText == null) { | |||
String msg = "Class " + element.getClass().getName() + | |||
" doesn't support nested text elements"; | |||
throw new ClassIntrospectionException(msg); | |||
} | |||
try { | |||
addText.invoke(element, new String[] {text}); | |||
} catch (IllegalAccessException ie) { | |||
// impossible as getMethods should only return public methods | |||
throw new ClassIntrospectionException(ie); | |||
} catch (InvocationTargetException ite) { | |||
Throwable t = ite.getTargetException(); | |||
if (t instanceof ClassIntrospectionException) { | |||
throw (ClassIntrospectionException) t; | |||
} | |||
throw new ClassIntrospectionException(t); | |||
} | |||
} | |||
public boolean supportsNestedElement(String elementName) { | |||
return nestedCreators.containsKey(elementName); | |||
} | |||
/** | |||
* Creates a named nested element. | |||
*/ | |||
public Object createElement(Object element, String elementName) | |||
throws ClassIntrospectionException { | |||
NestedCreator nc = (NestedCreator) nestedCreators.get(elementName); | |||
if (nc == null) { | |||
String msg = "Class " + element.getClass().getName() + | |||
" doesn't support the nested \"" + elementName + "\" element"; | |||
throw new ClassIntrospectionException(msg); | |||
} | |||
try { | |||
return nc.create(element); | |||
} catch (IllegalAccessException ie) { | |||
// impossible as getMethods should only return public methods | |||
throw new ClassIntrospectionException(ie); | |||
} catch (InstantiationException ine) { | |||
// impossible as getMethods should only return public methods | |||
throw new ClassIntrospectionException(ine); | |||
} catch (InvocationTargetException ite) { | |||
Throwable t = ite.getTargetException(); | |||
if (t instanceof ClassIntrospectionException) { | |||
throw (ClassIntrospectionException) t; | |||
} | |||
throw new ClassIntrospectionException(t); | |||
} | |||
} | |||
/** | |||
* returns the type of a named nested element. | |||
*/ | |||
public Class getElementType(String elementName) | |||
throws ClassIntrospectionException { | |||
Class nt = (Class) nestedTypes.get(elementName); | |||
if (nt == null) { | |||
String msg = "Class " + bean.getName() + | |||
" doesn't support the nested \"" + elementName + "\" element"; | |||
throw new ClassIntrospectionException(msg); | |||
} | |||
return nt; | |||
} | |||
/** | |||
* returns the type of a named attribute. | |||
*/ | |||
public Class getAttributeType(String attributeName) | |||
throws ClassIntrospectionException { | |||
Class at = (Class) attributeTypes.get(attributeName); | |||
if (at == null) { | |||
String msg = "Class " + bean.getName() + | |||
" doesn't support the \"" + attributeName + "\" attribute"; | |||
throw new ClassIntrospectionException(msg); | |||
} | |||
return at; | |||
} | |||
/** | |||
* Does the introspected class support PCDATA? | |||
*/ | |||
public boolean supportsCharacters() { | |||
return addText != null; | |||
} | |||
/** | |||
* Return all attribues supported by the introspected class. | |||
*/ | |||
public Enumeration getAttributes() { | |||
return attributeSetters.keys(); | |||
} | |||
/** | |||
* Return all nested elements supported by the introspected class. | |||
*/ | |||
public Enumeration getNestedElements() { | |||
return nestedTypes.keys(); | |||
} | |||
/** | |||
* Create a proper implementation of AttributeSetter for the given | |||
* attribute type. | |||
*/ | |||
private AttributeSetter createAttributeSetter(final Method m, | |||
final Class arg, | |||
Map converters) { | |||
if (converters != null && converters.containsKey(arg)) { | |||
// we have a converter to use to convert the strign | |||
// value of into something the set method expects. | |||
final Converter converter = (Converter)converters.get(arg); | |||
return new AttributeSetter() { | |||
public void set(Object parent, String value) | |||
throws InvocationTargetException, IllegalAccessException, | |||
ClassIntrospectionException, ConversionException { | |||
m.invoke(parent, new Object[] {converter.convert(value, arg)}); | |||
} | |||
}; | |||
} | |||
// simplest case - setAttribute expects String | |||
else if (java.lang.String.class.equals(arg)) { | |||
return new AttributeSetter() { | |||
public void set(Object parent, String value) | |||
throws InvocationTargetException, IllegalAccessException { | |||
m.invoke(parent, new String[] {value}); | |||
} | |||
}; | |||
// now for the primitive types, use their wrappers | |||
} else if (java.lang.Character.class.equals(arg) | |||
|| java.lang.Character.TYPE.equals(arg)) { | |||
return new AttributeSetter() { | |||
public void set(Object parent, String value) | |||
throws InvocationTargetException, IllegalAccessException { | |||
m.invoke(parent, new Character[] {new Character(value.charAt(0))}); | |||
} | |||
}; | |||
} else if (java.lang.Byte.TYPE.equals(arg)) { | |||
return new AttributeSetter() { | |||
public void set(Object parent, String value) | |||
throws InvocationTargetException, IllegalAccessException { | |||
m.invoke(parent, new Byte[] {new Byte(value)}); | |||
} | |||
}; | |||
} else if (java.lang.Short.TYPE.equals(arg)) { | |||
return new AttributeSetter() { | |||
public void set(Object parent, String value) | |||
throws InvocationTargetException, IllegalAccessException { | |||
m.invoke(parent, new Short[] {new Short(value)}); | |||
} | |||
}; | |||
} else if (java.lang.Integer.TYPE.equals(arg)) { | |||
return new AttributeSetter() { | |||
public void set(Object parent, String value) | |||
throws InvocationTargetException, IllegalAccessException { | |||
m.invoke(parent, new Integer[] {new Integer(value)}); | |||
} | |||
}; | |||
} else if (java.lang.Long.TYPE.equals(arg)) { | |||
return new AttributeSetter() { | |||
public void set(Object parent, String value) | |||
throws InvocationTargetException, IllegalAccessException { | |||
m.invoke(parent, new Long[] {new Long(value)}); | |||
} | |||
}; | |||
} else if (java.lang.Float.TYPE.equals(arg)) { | |||
return new AttributeSetter() { | |||
public void set(Object parent, String value) | |||
throws InvocationTargetException, IllegalAccessException { | |||
m.invoke(parent, new Float[] {new Float(value)}); | |||
} | |||
}; | |||
} else if (java.lang.Double.TYPE.equals(arg)) { | |||
return new AttributeSetter() { | |||
public void set(Object parent, String value) | |||
throws InvocationTargetException, IllegalAccessException { | |||
m.invoke(parent, new Double[] {new Double(value)}); | |||
} | |||
}; | |||
} else if (java.lang.Boolean.class.equals(arg) | |||
|| java.lang.Boolean.TYPE.equals(arg)) { | |||
return new AttributeSetter() { | |||
public void set(Object parent, String value) | |||
throws InvocationTargetException, IllegalAccessException { | |||
m.invoke(parent, | |||
new Boolean[] {new Boolean(toBoolean(value))}); | |||
} | |||
}; | |||
// Class doesn't have a String constructor but a decent factory method | |||
} else if (java.lang.Class.class.equals(arg)) { | |||
return new AttributeSetter() { | |||
public void set(Object parent, String value) | |||
throws InvocationTargetException, IllegalAccessException, ClassIntrospectionException { | |||
try { | |||
m.invoke(parent, new Class[] {Class.forName(value)}); | |||
} catch (ClassNotFoundException ce) { | |||
throw new ClassIntrospectionException(ce); | |||
} | |||
} | |||
}; | |||
// worst case. look for a public String constructor and use it | |||
} else { | |||
try { | |||
final Constructor c = | |||
arg.getConstructor(new Class[] {java.lang.String.class}); | |||
return new AttributeSetter() { | |||
public void set(Object parent, | |||
String value) | |||
throws InvocationTargetException, IllegalAccessException, ClassIntrospectionException { | |||
try { | |||
m.invoke(parent, new Object[] {c.newInstance(new String[] {value})}); | |||
} catch (InstantiationException ie) { | |||
throw new ClassIntrospectionException(ie); | |||
} | |||
} | |||
}; | |||
} catch (NoSuchMethodException nme) { | |||
} | |||
} | |||
return null; | |||
} | |||
/** | |||
* extract the name of a property from a method name - subtracting | |||
* a given prefix. | |||
*/ | |||
private String getPropertyName(String methodName, String prefix) { | |||
int start = prefix.length(); | |||
return methodName.substring(start).toLowerCase(); | |||
} | |||
private interface NestedCreator { | |||
public Object create(Object parent) | |||
throws InvocationTargetException, IllegalAccessException, InstantiationException; | |||
} | |||
private interface AttributeSetter { | |||
public void set(Object parent, String value) | |||
throws InvocationTargetException, IllegalAccessException, | |||
ClassIntrospectionException, ConversionException; | |||
} | |||
} |
@@ -1,144 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.core.execution; | |||
import java.io.*; | |||
/** | |||
* | |||
* @author <a href="mailto:conor@apache.org">Conor MacNeill</a> | |||
*/ | |||
public class ConversionException extends Exception { | |||
/** | |||
* Exception that might have caused this one. | |||
*/ | |||
private Throwable cause = null; | |||
/** | |||
* Constructs an exception with the given descriptive message. | |||
* @param msg Description of or information about the exception. | |||
*/ | |||
public ConversionException(String msg) { | |||
super(msg); | |||
} | |||
/** | |||
* Constructs an exception with the given message and exception as | |||
* a root cause. | |||
* @param msg Description of or information about the exception. | |||
* @param cause Throwable that might have cause this one. | |||
*/ | |||
public ConversionException(String msg, Throwable cause) { | |||
super(msg); | |||
this.cause = cause; | |||
} | |||
/** | |||
* Constructs an exception with the given exception as a root cause. | |||
* @param cause Exception that might have caused this one. | |||
*/ | |||
public ConversionException(Throwable cause) { | |||
super(cause.toString()); | |||
this.cause = cause; | |||
} | |||
/** | |||
* Returns the nested exception. | |||
* | |||
* @return the underlying exception | |||
*/ | |||
public Throwable getCause() { | |||
return cause; | |||
} | |||
/** | |||
* Print the stack trace to System.err | |||
*/ | |||
public void printStackTrace() { | |||
printStackTrace(System.err); | |||
} | |||
/** | |||
* Print the stack trace to the given PrintStream | |||
* | |||
* @param ps the PrintStream onto which the stack trace | |||
* of this exception is to be printed | |||
*/ | |||
public void printStackTrace(PrintStream ps) { | |||
synchronized (ps) { | |||
ps.println(this); | |||
if (cause != null) { | |||
ps.println("--- Nested Exception ---"); | |||
cause.printStackTrace(ps); | |||
} | |||
} | |||
} | |||
/** | |||
* Print the stack trace to the given PrintWriter | |||
* | |||
* @param pw the PrintWriter onto which the stack trace | |||
* of this exception is to be printed | |||
*/ | |||
public void printStackTrace(PrintWriter pw) { | |||
synchronized (pw) { | |||
pw.println(this); | |||
if (cause != null) { | |||
pw.println("--- Nested Exception ---"); | |||
cause.printStackTrace(pw); | |||
} | |||
} | |||
} | |||
} |
@@ -1,67 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2000 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.core.execution; | |||
/** | |||
* Convert between a string and a data type | |||
* | |||
* @author <a href="mailto:conor@apache.org">Conor MacNeill</a> | |||
*/ | |||
public interface Converter { | |||
/** | |||
* Convert a string from the value given to an instance of the given type. | |||
*/ | |||
Object convert(String value, Class type) throws ConversionException; | |||
} |
@@ -1,144 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.core.execution; | |||
import java.util.*; | |||
import java.net.URL; | |||
/** | |||
* A Converter definition defines a class which will convert | |||
* a string into an instance of a particular type of class. Converters | |||
* are typically only needed when some context information is | |||
* required to perform the conversion. | |||
* | |||
* @author <a href="mailto:conor@apache.org">Conor MacNeill</a> | |||
*/ | |||
public class ConverterDefinition { | |||
/** The URL of the library which defines this converter */ | |||
private URL converterLibraryURL; | |||
/** The converter's class name */ | |||
private String converterClassName; | |||
/** The converted class returned by this converter */ | |||
private String targetClassName; | |||
/** The converter class loaded from the loader on demand. | |||
*/ | |||
private Class converterClass = null; | |||
/** The class to which this converter converts. | |||
*/ | |||
private Class targetClass = null; | |||
/** The converters's class loader. */ | |||
private ClassLoader converterClassLoader; | |||
public ConverterDefinition(URL converterLibraryURL, String converterClassName, | |||
String targetClassName, ClassLoader converterClassLoader) { | |||
this.converterLibraryURL = converterLibraryURL; | |||
this.converterClassName = converterClassName; | |||
this.targetClassName = targetClassName; | |||
this.converterClassLoader = converterClassLoader; | |||
} | |||
/** | |||
* Get the name of the class that this converter will return. | |||
*/ | |||
public String getTargetClassName() { | |||
return targetClassName; | |||
} | |||
/** | |||
* Get the classname of the converter that is being defined. | |||
*/ | |||
public String getConverterClassName() { | |||
return converterClassName; | |||
} | |||
/** | |||
* Get the URL where this converter was defined. | |||
* | |||
* @returns a URL of the lib defintion file | |||
*/ | |||
public URL getLibraryURL() { | |||
return converterLibraryURL; | |||
} | |||
/** | |||
* Get the converter class | |||
* | |||
* @return a class object for this converter | |||
*/ | |||
public synchronized Class getConverterClass() throws ClassNotFoundException { | |||
if (converterClass == null) { | |||
converterClass = Class.forName(converterClassName, true, converterClassLoader); | |||
} | |||
return converterClass; | |||
} | |||
/** | |||
* Get the converter class | |||
* | |||
* @return a class object for this converter | |||
*/ | |||
public synchronized Class getTargetClass() throws ClassNotFoundException { | |||
if (targetClass == null) { | |||
targetClass = Class.forName(targetClassName, true, converterClassLoader); | |||
} | |||
return targetClass; | |||
} | |||
} | |||
@@ -1,108 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.core.execution; | |||
import org.apache.ant.core.model.*; | |||
import org.apache.ant.core.support.*; | |||
import java.util.*; | |||
import java.net.URL; | |||
/** | |||
* The ExecutionContext interface provides a task or apsect instance with access to the | |||
* container-provided services. This is the only way to access the container. | |||
* | |||
* @author <a href="mailto:conor@apache.org">Conor MacNeill</a> | |||
*/ | |||
public class ExecutionContext { | |||
private ExecutionFrame frame = null; | |||
private BuildEventSupport eventSupport; | |||
private BuildElement buildElement; | |||
public ExecutionContext(ExecutionFrame frame, BuildEventSupport eventSupport, | |||
BuildElement buildElement) { | |||
this.frame = frame; | |||
this.eventSupport = eventSupport; | |||
this.buildElement = buildElement; | |||
} | |||
/** | |||
* Log a mesage with the give priority. | |||
* | |||
* @param the message to be logged. | |||
* @param msgLevel the message priority at which this message is to be logged. | |||
*/ | |||
public void log(String msg, int msgLevel) { | |||
eventSupport.fireMessageLogged(this, buildElement, msg, msgLevel); | |||
} | |||
public void setDataValue(String name, Object value) throws ExecutionException { | |||
frame.setDataValue(name, value); | |||
} | |||
public Object getDataValue(String name) throws ExecutionException { | |||
return frame.getDataValue(name); | |||
} | |||
/** | |||
* Replace ${} style constructions in the given value with the string value of | |||
* the corresponding data types. | |||
* | |||
* @param value the string to be scanned for property references. | |||
*/ | |||
public String replacePropertyRefs(String value) throws ExecutionException { | |||
return frame.replacePropertyRefs(value); | |||
} | |||
} | |||
@@ -1,125 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.core.execution; | |||
import org.apache.ant.core.support.*; | |||
import java.io.*; | |||
/** | |||
* An ExecutiuonException indicates a problem during | |||
* the execution of the build files tasks | |||
* | |||
* @author <a href="mailto:conor@apache.org">Conor MacNeill</a> | |||
*/ | |||
public class ExecutionException extends AntException { | |||
/** | |||
* Constructs an exception with the given descriptive message. | |||
* | |||
* @param msg Description of or information about the exception. | |||
*/ | |||
public ExecutionException(String msg) { | |||
super(msg); | |||
} | |||
/** | |||
* Constructs an exception with the given descriptive message and a location | |||
* in a file. | |||
* @param msg Description of or information about the exception. | |||
* @param location Location in the project file where the error occured. | |||
*/ | |||
public ExecutionException(String msg, Location location) { | |||
super(msg, location); | |||
} | |||
/** | |||
* Constructs an exception with the given message and exception as | |||
* a root cause. | |||
* | |||
* @param msg Description of or information about the exception. | |||
* @param cause Throwable that might have cause this one. | |||
*/ | |||
public ExecutionException(String msg, Throwable cause) { | |||
super(msg, cause); | |||
} | |||
/** | |||
* Constructs an exception with the given message and exception as | |||
* a root cause and a location in a file. | |||
* @param msg Description of or information about the exception. | |||
* @param cause Exception that might have cause this one. | |||
* @param location Location in the project file where the error occured. | |||
*/ | |||
public ExecutionException(String msg, Throwable cause, Location location) { | |||
super(msg, cause, location); | |||
} | |||
/** | |||
* Constructs an exception with the given exception as a root cause. | |||
* | |||
* @param cause Exception that might have caused this one. | |||
*/ | |||
public ExecutionException(Throwable cause) { | |||
super(cause); | |||
} | |||
/** | |||
* Constructs an exception with the given exception as | |||
* a root cause and a location in a file. | |||
* @param cause Exception that might have cause this one. | |||
* @param location Location in the project file where the error occured. | |||
*/ | |||
public ExecutionException(Throwable cause, Location location) { | |||
super(cause, location); | |||
} | |||
} |
@@ -1,920 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.core.execution; | |||
import org.apache.ant.core.model.*; | |||
import org.apache.ant.core.support.*; | |||
import org.apache.ant.core.types.*; | |||
import java.util.*; | |||
import java.net.*; | |||
/** | |||
* An ExecutionFrame is the state of a project during an execution. | |||
* The ExecutionFrame contains the data values set by Ant tasks as | |||
* they are executed, including task definitions, property values, etc. | |||
* | |||
* @author <a href="mailto:conor@apache.org">Conor MacNeill</a> | |||
*/ | |||
public class ExecutionFrame { | |||
/** State used in dependency analysis when a target's dependencies are being | |||
examined. */ | |||
private static final String VISITING = "VISITING"; | |||
/** State used in dependency analysis to indicate a target has been examined */ | |||
private static final String VISITED = "VISITED"; | |||
/** The Project that this execiton frame is processing */ | |||
private Project project = null; | |||
/** The base URL for this frame. This is derived from the | |||
Project's source URL and it's base attribute. */ | |||
private URL baseURL = null; | |||
/** The imported frames of this frame. For each project imported by this frame's | |||
project, a corresponding ExecutionFrame is created. */ | |||
private Map importedFrames = new HashMap(); | |||
/** BuildEvent support used to fire events and manage listeners */ | |||
private BuildEventSupport eventSupport = new BuildEventSupport(); | |||
/** The context of this execution. This contains all data object's | |||
created by tasks that have been executed */ | |||
private Map dataValues = new HashMap(); | |||
/** Introspector objects used to configure Tasks from the Task models.*/ | |||
private Map introspectors = new HashMap(); | |||
/** The task defs that this frame will use to process tasks */ | |||
private Map taskDefs = new HashMap(); | |||
/** Type converters for this executionFrame. Converters are used when configuring | |||
Tasks to handle special type conversions. */ | |||
private Map converters = new HashMap(); | |||
/** The aspect handler active in this frame */ | |||
private Map aspectHandlers = new HashMap(); | |||
/** The namespace under which this execution frame lives in the hierarchical | |||
project namespace - null for the root namespace */ | |||
private String namespace; | |||
/** | |||
* Construct an execution frame to process the given project model with | |||
* the configuration represented by the libraries. | |||
* | |||
* @param project the model of the project to be built. | |||
* @param libraries an Array of AntLibrary objects containing the | |||
* configuration of Ant for this build. | |||
* | |||
* @throws ConfigException when the project cannot be setup with the | |||
* given configuration | |||
*/ | |||
public ExecutionFrame(Project project, AntLibrary[] libraries) | |||
throws ConfigException { | |||
this.namespace = null; | |||
setupFrame(project, libraries); | |||
} | |||
/** | |||
* Construct a subframe for managing a project imported into the main project. | |||
* @param project the model of the project to be built. | |||
* @param libraries an Array of AntLibrary objects containing the | |||
* configuration of Ant for this build. | |||
* @param namespace the location of this project within the overall import | |||
* namespace. | |||
* | |||
* @throws ConfigException when the project cannot be setup with the | |||
* given configuration | |||
*/ | |||
private ExecutionFrame(Project project, AntLibrary[] libraries, String namespace) | |||
throws ConfigException { | |||
this.namespace = namespace; | |||
setupFrame(project, libraries); | |||
} | |||
/** | |||
* Set up the execution frame. | |||
* | |||
* This method examines the project model and constructs the required | |||
* subframes to handle imported projects. | |||
* @param project the model of the project to be built. | |||
* @param libraries an Array of AntLibrary objects containing the | |||
* configuration of Ant for this build. | |||
* | |||
* @throws ConfigException when the project cannot be setup with the | |||
* given configuration | |||
*/ | |||
private void setupFrame(Project project, AntLibrary[] libraries) | |||
throws ConfigException { | |||
this.project = project; | |||
for (int i = 0; i < libraries.length; ++i) { | |||
addLibrary(libraries[i]); | |||
} | |||
try { | |||
String base = project.getBase(); | |||
if (base == null) { | |||
baseURL = project.getSourceURL(); | |||
} | |||
else { | |||
base = base.trim(); | |||
if (!base.endsWith("/")) { | |||
base += "/"; | |||
} | |||
baseURL = new URL(project.getSourceURL(), base); | |||
} | |||
} | |||
catch (MalformedURLException e) { | |||
throw new ConfigException("Project's base value \"" + project.getBase() | |||
+ "\" is not valid", e, project.getLocation()); | |||
} | |||
for (Iterator i = project.getImportedProjectNames(); i.hasNext();) { | |||
String importName = (String)i.next(); | |||
Project importedProject = project.getImportedProject(importName); | |||
String importNamespace | |||
= namespace == null ? importName : namespace + ":" + importName; | |||
ExecutionFrame importedFrame | |||
= new ExecutionFrame(importedProject, libraries, importNamespace); | |||
importedFrames.put(importName, importedFrame); | |||
} | |||
} | |||
/** | |||
* Add a configuration library to this execution frame. The library | |||
* will contain task definitions, converters, apsect handler definitions, | |||
* etc. | |||
* | |||
* @param library the configuration library to add to this frame. | |||
* | |||
* @throws ConfigException if the items in the library cannot be configured. | |||
*/ | |||
public void addLibrary(AntLibrary library) throws ConfigException { | |||
for (Iterator i = library.getTaskDefinitions(); i.hasNext(); ) { | |||
TaskDefinition taskDefinition = (TaskDefinition)i.next(); | |||
addTaskDefinition(taskDefinition); | |||
} | |||
for (Iterator i = library.getConverterDefinitions(); i.hasNext(); ) { | |||
ConverterDefinition converterDef = (ConverterDefinition)i.next(); | |||
addConverterDefinition(converterDef); | |||
} | |||
for (Iterator i = library.getAspectDefinitions(); i.hasNext(); ) { | |||
AspectDefinition aspectDef = (AspectDefinition)i.next(); | |||
addAspectHandler(aspectDef); | |||
} | |||
} | |||
/** | |||
* Add a task definition to this execution frame | |||
* | |||
* @param taskDefinition the TaskDefinition to be added to the project. | |||
*/ | |||
public void addTaskDefinition(TaskDefinition taskDefinition) { | |||
String taskName = taskDefinition.getName(); | |||
taskDefs.put(taskName, taskDefinition); | |||
} | |||
/** | |||
* Add a aspect handler definition to this execution frame | |||
* | |||
* @param taskDefinition the TaskDefinition to be added to the project. | |||
* | |||
* @throws ConfigException if the aspect handler cannot be created or configured. | |||
*/ | |||
public void addAspectHandler(AspectDefinition aspectDefinition) | |||
throws ConfigException { | |||
String aspectPrefix = aspectDefinition.getAspectPrefix(); | |||
try { | |||
Class aspectHandlerClass = aspectDefinition.getAspectHandlerClass(); | |||
aspectHandlers.put(aspectPrefix, aspectHandlerClass); | |||
} | |||
catch (ClassNotFoundException e) { | |||
throw new ConfigException("Unable to load aspect handler class for " | |||
+ aspectDefinition.getAspectHandlerClassName() | |||
+ " in converter from " + aspectDefinition.getLibraryURL(), | |||
e); | |||
} | |||
} | |||
/** | |||
* Add a converter definition to this library. | |||
* | |||
* The converter is created immediately to handle conversions | |||
* when items are being configured. If the converter is an instance of | |||
* an AntConverter, the converter is configured with this execution | |||
* frame giving it the context it needs to resolve items relative to the | |||
* project's base, etc. | |||
* | |||
* @param converterDef the converter definition to load | |||
* | |||
* @throws ConfigException if the converter cannot be created or configured. | |||
*/ | |||
public void addConverterDefinition(ConverterDefinition converterDef) throws ConfigException { | |||
boolean targetLoaded = false; | |||
try { | |||
Class targetClass = converterDef.getTargetClass(); | |||
targetLoaded = false; | |||
Class converterClass = converterDef.getConverterClass(); | |||
Converter converter = (AntConverter)converterClass.newInstance(); | |||
if (converter instanceof AntConverter) { | |||
((AntConverter)converter).init(this); | |||
} | |||
converters.put(targetClass, converter); | |||
} | |||
catch (ClassNotFoundException e) { | |||
if (targetLoaded) { | |||
throw new ConfigException("Unable to load converter class for " | |||
+ converterDef.getConverterClassName() | |||
+ " in converter from " + converterDef.getLibraryURL(), | |||
e); | |||
} | |||
else { | |||
throw new ConfigException("Unable to load target class " | |||
+ converterDef.getTargetClassName() | |||
+ " in converter from " + converterDef.getLibraryURL(), | |||
e); | |||
} | |||
} | |||
catch (InstantiationException e) { | |||
throw new ConfigException("Unable to instantiate converter class " | |||
+ converterDef.getTargetClassName() | |||
+ " in converter from " + converterDef.getLibraryURL(), | |||
e); | |||
} | |||
catch (IllegalAccessException e) { | |||
throw new ConfigException("Unable to access converter class " | |||
+ converterDef.getTargetClassName() | |||
+ " in converter from " + converterDef.getLibraryURL(), | |||
e); | |||
} | |||
} | |||
/** | |||
* Get the bae URL of this frame. This will either be specified by the project's | |||
* base attribute or be derived implicitly from the project's location. | |||
*/ | |||
public URL getBaseURL() { | |||
return baseURL; | |||
} | |||
public void addBuildListener(BuildListener listener) { | |||
for (Iterator i = getImportedFrames(); i.hasNext(); ) { | |||
ExecutionFrame subFrame = (ExecutionFrame)i.next(); | |||
subFrame.addBuildListener(listener); | |||
} | |||
eventSupport.addBuildListener(listener); | |||
} | |||
public void removeBuildListener(BuildListener listener) { | |||
for (Iterator i = getImportedFrames(); i.hasNext(); ) { | |||
ExecutionFrame subFrame = (ExecutionFrame)i.next(); | |||
subFrame.removeBuildListener(listener); | |||
} | |||
eventSupport.removeBuildListener(listener); | |||
} | |||
/** | |||
* Get the project associated with this execution frame. | |||
* | |||
* @return the project associated iwth this execution frame. | |||
*/ | |||
public Project getProject() { | |||
return project; | |||
} | |||
/** | |||
* Get the names of the frames representing imported projects. | |||
* | |||
* @return an iterator which returns the names of the imported frames. | |||
*/ | |||
public Iterator getImportedFrameNames() { | |||
return importedFrames.keySet().iterator(); | |||
} | |||
/** | |||
* Get the frames representing imported projects. | |||
* | |||
* @return an iterator which returns the imported ExeuctionFrames.. | |||
*/ | |||
public Iterator getImportedFrames() { | |||
return importedFrames.values().iterator(); | |||
} | |||
/** | |||
* Get an imported frame by name | |||
* | |||
* @param importName the name under which the frame was imported. | |||
* | |||
* @return the ExecutionFrame asscociated with the given import name or null | |||
* if there is no such project. | |||
*/ | |||
public ExecutionFrame getImportedFrame(String importName) { | |||
return (ExecutionFrame)importedFrames.get(importName); | |||
} | |||
/** | |||
* Get the location of this frame in the namespace hierarchy | |||
* | |||
* @return the location of this frame within the project import | |||
* namespace hierarchy. | |||
*/ | |||
public String getNamespace() { | |||
return namespace; | |||
} | |||
/** | |||
* Get the fully qualified name of something with respect to this | |||
* execution frame. | |||
* | |||
* @param name the unqualified name. | |||
* | |||
* @return the fully qualified version of the given name | |||
*/ | |||
public String getQualifiedName(String name) { | |||
return namespace == null ? name : namespace + ":" + name; | |||
} | |||
/** | |||
* Execute the given target's tasks | |||
* | |||
* @param the name of the target within this frame that is to be executed. | |||
*/ | |||
public void executeTargetTasks(String targetName) throws ExecutionException, ConfigException { | |||
Target target = project.getTarget(targetName); | |||
try { | |||
Iterator taskIterator = target.getTasks(); | |||
eventSupport.fireTargetStarted(this, target); | |||
executeTasks(taskIterator); | |||
eventSupport.fireTargetFinished(this, target, null); | |||
} | |||
catch (RuntimeException e) { | |||
eventSupport.fireTargetFinished(this, target, e); | |||
throw e; | |||
} | |||
} | |||
/** | |||
* Initialize the frame by executing the project level tasks if any | |||
*/ | |||
public void initialize() throws ExecutionException, ConfigException { | |||
for (Iterator i = getImportedFrames(); i.hasNext(); ) { | |||
ExecutionFrame subFrame = (ExecutionFrame)i.next(); | |||
subFrame.initialize(); | |||
} | |||
Iterator taskIterator = project.getTasks(); | |||
executeTasks(taskIterator); | |||
} | |||
public void fillinDependencyOrder(String targetName, List dependencyOrder, | |||
Map state, Stack visiting) throws ConfigException { | |||
String fullTargetName = getQualifiedName(targetName); | |||
if (state.get(fullTargetName) == VISITED) { | |||
return; | |||
} | |||
Target target = getProject().getTarget(targetName); | |||
if (target == null) { | |||
StringBuffer sb = new StringBuffer("Target `"); | |||
sb.append(targetName); | |||
sb.append("' does not exist in this project. "); | |||
if (!visiting.empty()) { | |||
String parent = (String)visiting.peek(); | |||
sb.append("It is used from target `"); | |||
sb.append(parent); | |||
sb.append("'."); | |||
} | |||
throw new ConfigException(new String(sb), getProject().getLocation()); | |||
} | |||
state.put(fullTargetName, VISITING); | |||
visiting.push(fullTargetName); | |||
for (Iterator i = target.getDependencies(); i.hasNext(); ) { | |||
String dependency = (String)i.next(); | |||
try { | |||
ExecutionFrame dependencyFrame = getRelativeFrame(dependency); | |||
if (dependencyFrame == null) { | |||
StringBuffer sb = new StringBuffer("Target `"); | |||
sb.append(dependency); | |||
sb.append("' does not exist in this project. "); | |||
throw new ConfigException(new String(sb), target.getLocation()); | |||
} | |||
String fullyQualifiedName = getQualifiedName(dependency); | |||
String dependencyState = (String)state.get(fullyQualifiedName); | |||
if (dependencyState == null) { | |||
dependencyFrame.fillinDependencyOrder(getNameInFrame(dependency), dependencyOrder, | |||
state, visiting); | |||
} | |||
else if (dependencyState == VISITING) { | |||
String circleDescription | |||
= getCircularDesc(dependency, visiting); | |||
throw new ConfigException(circleDescription, target.getLocation()); | |||
} | |||
} | |||
catch (ExecutionException e) { | |||
throw new ConfigException(e.getMessage(), e, target.getLocation()); | |||
} | |||
} | |||
state.put(fullTargetName, VISITED); | |||
String poppedNode = (String)visiting.pop(); | |||
if (poppedNode != fullTargetName) { | |||
throw new ConfigException("Problem determining dependencies " + | |||
" - expecting '" + fullTargetName + | |||
"' but got '" + poppedNode + "'"); | |||
} | |||
dependencyOrder.add(fullTargetName); | |||
} | |||
private String getCircularDesc(String end, Stack visitingNodes) { | |||
StringBuffer sb = new StringBuffer("Circular dependency: "); | |||
sb.append(end); | |||
String c; | |||
do { | |||
c = (String)visitingNodes.pop(); | |||
sb.append(" <- "); | |||
sb.append(c); | |||
} while(!c.equals(end)); | |||
return new String(sb); | |||
} | |||
/** | |||
* Check whether the targets in this frame and its subframes are OK | |||
*/ | |||
public void checkTargets(List dependencyOrder, Map state, Stack visiting) | |||
throws ConfigException { | |||
// get the targets and just iterate through them. | |||
for (Iterator i = getProject().getTargets(); i.hasNext();) { | |||
Target target = (Target)i.next(); | |||
fillinDependencyOrder(target.getName(), | |||
dependencyOrder, state, visiting); | |||
} | |||
// Now do the subframes. | |||
for (Iterator i = getImportedFrames(); i.hasNext();) { | |||
ExecutionFrame importedFrame = (ExecutionFrame)i.next(); | |||
importedFrame.checkTargets(dependencyOrder, state, visiting); | |||
} | |||
} | |||
/** | |||
* Create a Task and configure it according to the given model. | |||
*/ | |||
private Task configureTask(TaskElement model) | |||
throws ConfigException, ExecutionException { | |||
String taskType = model.getType(); | |||
TaskDefinition taskDefinition = (TaskDefinition)taskDefs.get(taskType); | |||
if (taskDefinition == null) { | |||
throw new ConfigException("There is no defintion for tasks of type <" | |||
+ taskType + ">", model.getLocation()); | |||
} | |||
try { | |||
Class elementClass = taskDefinition.getExecutionTaskClass(); | |||
Object element = elementClass.newInstance(); | |||
Task task = null; | |||
if (element instanceof Task) { | |||
// create a Task context for the Task | |||
task = (Task)element; | |||
} | |||
else { | |||
task = new TaskAdapter(taskType, element); | |||
} | |||
configureElement(element, model); | |||
return task; | |||
} | |||
catch (ClassNotFoundException e) { | |||
throw new ConfigException("Execution class " + taskDefinition.getTaskClassName() | |||
+ " was not found", e, model.getLocation()); | |||
} | |||
catch (InstantiationException e) { | |||
throw new ConfigException("Unable to instantiate execution class " | |||
+ taskDefinition.getTaskClassName(), | |||
e, model.getLocation()); | |||
} | |||
catch (IllegalAccessException e) { | |||
throw new ConfigException("Unable to access execution class " | |||
+ taskDefinition.getTaskClassName(), | |||
e, model.getLocation()); | |||
} | |||
} | |||
private List getActiveAspects(BuildElement model) | |||
throws ConfigException, ExecutionException, | |||
ClassIntrospectionException, ConversionException { | |||
List activeAspects = new ArrayList(); | |||
for (Iterator i = model.getAspectNames(); i.hasNext();) { | |||
String aspectPrefix = (String)i.next(); | |||
Class aspectHandlerClass = (Class)aspectHandlers.get(aspectPrefix); | |||
if (aspectHandlerClass != null) { | |||
try { | |||
AspectHandler aspectHandler | |||
= (AspectHandler)aspectHandlerClass.newInstance(); | |||
ClassIntrospector introspector = getIntrospector(aspectHandlerClass); | |||
ExecutionContext context = new ExecutionContext(this, eventSupport, model); | |||
aspectHandler.setAspectContext(context); | |||
Map aspectAttributes = model.getAspectAttributes(aspectPrefix); | |||
for (Iterator j = aspectAttributes.keySet().iterator(); j.hasNext();) { | |||
String attributeName = (String)j.next(); | |||
String attributeValue = (String)aspectAttributes.get(attributeName); | |||
introspector.setAttribute(aspectHandler, attributeName, | |||
replacePropertyRefs(attributeValue)); | |||
} | |||
activeAspects.add(aspectHandler); | |||
} | |||
catch (InstantiationException e) { | |||
throw new ConfigException("Unable to instantiate aspect handler class " | |||
+ aspectHandlerClass, | |||
e); | |||
} | |||
catch (IllegalAccessException e) { | |||
throw new ConfigException("Unable to access aspect handler class " | |||
+ aspectHandlerClass, | |||
e); | |||
} | |||
} | |||
} | |||
return activeAspects; | |||
} | |||
/** | |||
* Configure an element according to the given model. | |||
*/ | |||
private void configureElement(Object element, TaskElement model) | |||
throws ExecutionException, ConfigException { | |||
if (element instanceof Task) { | |||
Task task = (Task)element; | |||
ExecutionContext context = new ExecutionContext(this, eventSupport, model); | |||
task.setTaskContext(context); | |||
} | |||
try { | |||
ClassIntrospector introspector = getIntrospector(element.getClass()); | |||
List aspects = getActiveAspects(model); | |||
for (Iterator i = aspects.iterator(); i.hasNext(); ) { | |||
AspectHandler aspectHandler = (AspectHandler)i.next(); | |||
aspectHandler.beforeConfigElement(element); | |||
} | |||
// start by setting the attributes of this element | |||
for (Iterator i = model.getAttributeNames(); i.hasNext();) { | |||
String attributeName = (String)i.next(); | |||
String attributeValue = model.getAttributeValue(attributeName); | |||
introspector.setAttribute(element, attributeName, | |||
replacePropertyRefs(attributeValue)); | |||
} | |||
String modelText = model.getText().trim(); | |||
if (modelText.length() != 0) { | |||
introspector.addText(element, replacePropertyRefs(modelText)); | |||
} | |||
// now do the nested elements | |||
for (Iterator i = model.getNestedElements(); i.hasNext();) { | |||
TaskElement nestedElementModel = (TaskElement)i.next(); | |||
if (element instanceof TaskContainer && | |||
!introspector.supportsNestedElement(nestedElementModel.getType())) { | |||
Task nestedTask = configureTask(nestedElementModel); | |||
TaskContainer container = (TaskContainer)element; | |||
container.addTask(nestedTask); | |||
} | |||
else { | |||
Object nestedElement | |||
= introspector.createElement(element, nestedElementModel.getType()); | |||
configureElement(nestedElement, nestedElementModel); | |||
} | |||
} | |||
for (Iterator i = aspects.iterator(); i.hasNext(); ) { | |||
AspectHandler aspectHandler = (AspectHandler)i.next(); | |||
aspectHandler.afterConfigElement(element); | |||
} | |||
} | |||
catch (ClassIntrospectionException e) { | |||
throw new ExecutionException(e, model.getLocation()); | |||
} | |||
catch (ConversionException e) { | |||
throw new ExecutionException(e, model.getLocation()); | |||
} | |||
} | |||
/** | |||
* Run the tasks returned by the give iterator | |||
* | |||
* @param taskIterator the iterator giving the tasks to execute | |||
*/ | |||
public void executeTasks(Iterator taskIterator) throws ExecutionException, ConfigException { | |||
TaskElement task = null; | |||
try { | |||
while (taskIterator.hasNext()) { | |||
task = (TaskElement)taskIterator.next(); | |||
try { | |||
Task configuredTask = configureTask(task); | |||
eventSupport.fireTaskStarted(this, task); | |||
configuredTask.execute(); | |||
} | |||
catch (ExecutionException e) { | |||
if (e.getLocation() == null || e.getLocation() == Location.UNKNOWN_LOCATION) { | |||
e.setLocation(task.getLocation()); | |||
} | |||
throw e; | |||
} | |||
catch (ConfigException e) { | |||
if (e.getLocation() == null || e.getLocation() == Location.UNKNOWN_LOCATION) { | |||
e.setLocation(task.getLocation()); | |||
} | |||
throw e; | |||
} | |||
eventSupport.fireTaskFinished(this, task, null); | |||
} | |||
} | |||
catch (RuntimeException e) { | |||
eventSupport.fireTaskFinished(this, task, e); | |||
throw e; | |||
} | |||
} | |||
private ClassIntrospector getIntrospector(Class c) { | |||
if (introspectors.containsKey(c)) { | |||
return (ClassIntrospector)introspectors.get(c); | |||
} | |||
ClassIntrospector introspector = new ClassIntrospector(c, converters); | |||
introspectors.put(c, introspector); | |||
return introspector; | |||
} | |||
/** | |||
* Replace ${} style constructions in the given value with the string value of | |||
* the corresponding data types. | |||
* | |||
* @param value the string to be scanned for property references. | |||
*/ | |||
public String replacePropertyRefs(String value) throws ExecutionException { | |||
if (value == null) { | |||
return null; | |||
} | |||
List fragments = new ArrayList(); | |||
List propertyRefs = new ArrayList(); | |||
parsePropertyString(value, fragments, propertyRefs); | |||
StringBuffer sb = new StringBuffer(); | |||
Iterator i = fragments.iterator(); | |||
Iterator j = propertyRefs.iterator(); | |||
while (i.hasNext()) { | |||
String fragment = (String)i.next(); | |||
if (fragment == null) { | |||
String propertyName = (String)j.next(); | |||
if (!isDataValueSet(propertyName)) { | |||
throw new ExecutionException("Property " + propertyName + " has not been set"); | |||
} | |||
fragment = getDataValue(propertyName).toString(); | |||
} | |||
sb.append(fragment); | |||
} | |||
return sb.toString(); | |||
} | |||
/** | |||
* This method will parse a string containing ${value} style | |||
* property values into two list. The first list is a collection | |||
* of text fragments, while the other is a set of string property names | |||
* null entries in the first list indicate a property reference from the | |||
* second list. | |||
*/ | |||
static public void parsePropertyString(String value, List fragments, List propertyRefs) | |||
throws ExecutionException { | |||
int prev = 0; | |||
int pos; | |||
while ((pos = value.indexOf("$", prev)) >= 0) { | |||
if (pos > 0) { | |||
fragments.add(value.substring(prev, pos)); | |||
} | |||
if( pos == (value.length() - 1)) { | |||
fragments.add("$"); | |||
prev = pos + 1; | |||
} | |||
else if (value.charAt(pos + 1) != '{' ) { | |||
fragments.add(value.substring(pos + 1, pos + 2)); | |||
prev = pos + 2; | |||
} else { | |||
int endName = value.indexOf('}', pos); | |||
if (endName < 0) { | |||
throw new ExecutionException("Syntax error in property: " | |||
+ value ); | |||
} | |||
String propertyName = value.substring(pos + 2, endName); | |||
fragments.add(null); | |||
propertyRefs.add(propertyName); | |||
prev = endName + 1; | |||
} | |||
} | |||
if (prev < value.length()) { | |||
fragments.add(value.substring(prev)); | |||
} | |||
} | |||
/** | |||
* Given a name of an object, get the frame relative from this frame that | |||
* contains that object. | |||
*/ | |||
public ExecutionFrame getRelativeFrame(String name) throws ExecutionException { | |||
int index = name.lastIndexOf(":"); | |||
if (index == -1) { | |||
return this; | |||
} | |||
ExecutionFrame currentFrame = this; | |||
String relativeFrameName = name.substring(0, index); | |||
StringTokenizer tokenizer = new StringTokenizer(relativeFrameName, ":"); | |||
while (tokenizer.hasMoreTokens()) { | |||
String frameName = tokenizer.nextToken(); | |||
currentFrame = currentFrame.getImportedFrame(frameName); | |||
if (currentFrame == null) { | |||
throw new ExecutionException("The project " + frameName + " in " | |||
+ name + " was not found"); | |||
} | |||
} | |||
return currentFrame; | |||
} | |||
/** | |||
* Get the name of an object in its frame | |||
*/ | |||
public String getNameInFrame(String name) { | |||
int index = name.lastIndexOf(":"); | |||
if (index == -1) { | |||
return name; | |||
} | |||
return name.substring(index+1); | |||
} | |||
/** | |||
* Set a value in this frame or any of its imported frames | |||
*/ | |||
public void setDataValue(String name, Object value) throws ExecutionException { | |||
ExecutionFrame frame = getRelativeFrame(name); | |||
frame.setDirectDataValue(getNameInFrame(name), value); | |||
} | |||
/** | |||
* Get a value from this frame or any imported frame | |||
*/ | |||
public Object getDataValue(String name) throws ExecutionException { | |||
ExecutionFrame frame = getRelativeFrame(name); | |||
return frame.getDirectDataValue(getNameInFrame(name)); | |||
} | |||
/** | |||
* Set a value in this frame only | |||
*/ | |||
private void setDirectDataValue(String name, Object value) { | |||
dataValues.put(name, value); | |||
} | |||
/** | |||
* Get a value from this frame | |||
*/ | |||
private Object getDirectDataValue(String name) { | |||
return dataValues.get(name); | |||
} | |||
/** | |||
* Indicate if a data value has been set | |||
*/ | |||
public boolean isDataValueSet(String name) throws ExecutionException { | |||
ExecutionFrame frame = getRelativeFrame(name); | |||
return frame.isDirectDataValueSet(getNameInFrame(name)); | |||
} | |||
/** | |||
* Indicate if a data value has been set in this frame | |||
*/ | |||
private boolean isDirectDataValueSet(String name) { | |||
return dataValues.containsKey(name); | |||
} | |||
public void runBuild(List targetNames) throws AntException { | |||
Throwable buildFailureCause = null; | |||
try { | |||
eventSupport.fireBuildStarted(this, project); | |||
initialize(); | |||
if (targetNames.isEmpty()) { | |||
// we just execute the default target if any | |||
String defaultTarget = project.getDefaultTarget(); | |||
if (defaultTarget != null) { | |||
executeTarget(defaultTarget); | |||
} | |||
} | |||
else { | |||
for (Iterator i = targetNames.iterator(); i.hasNext();) { | |||
executeTarget((String)i.next()); | |||
} | |||
} | |||
eventSupport.fireBuildFinished(this, project, null); | |||
} | |||
catch (RuntimeException e) { | |||
buildFailureCause = e; | |||
throw e; | |||
} | |||
catch (AntException e) { | |||
buildFailureCause = e; | |||
throw e; | |||
} | |||
finally { | |||
eventSupport.fireBuildFinished(this, project, buildFailureCause); | |||
} | |||
} | |||
public void executeTarget(String targetName) throws ExecutionException, ConfigException { | |||
// to execute a target we must determine its dependencies and | |||
// execute them in order. | |||
Map state = new HashMap(); | |||
Stack visiting = new Stack(); | |||
List dependencyOrder = new ArrayList(); | |||
ExecutionFrame startingFrame = getRelativeFrame(targetName); | |||
startingFrame.fillinDependencyOrder(getNameInFrame(targetName), | |||
dependencyOrder, state, visiting); | |||
// Now tell each frame to execute the targets required | |||
for (Iterator i = dependencyOrder.iterator(); i.hasNext();) { | |||
String fullTargetName = (String)i.next(); | |||
ExecutionFrame frame = getRelativeFrame(fullTargetName); | |||
frame.executeTargetTasks(getNameInFrame(fullTargetName)); | |||
} | |||
} | |||
} |
@@ -1,77 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 1999 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.core.execution; | |||
/* | |||
* An input provider is an object which is provided to Ant's core | |||
* execution system to provide input from the user. Typically command | |||
* line based clients will request input from the console whilst | |||
* GUI clients may pop up an input dialog. Unattended operation may | |||
* be able to source input from some form of script. | |||
*/ | |||
public interface InputProvider { | |||
/** | |||
* Request input from the user | |||
* | |||
* @param prompt a string which is used to prompt the user for input. | |||
* @param defaultInput the default value initially supplied to the user | |||
* @param timeout a timeout in milliseconds which some clients may use | |||
* to either accept the default or to fail. | |||
* | |||
* @return a string of the user's input if the user provided any. | |||
* | |||
* @throws ExecutionException if the no input could be obtained from the user | |||
*/ | |||
String userInput(String prompt, String defaultInput) throws ExecutionException; | |||
} |
@@ -1,73 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.core.execution; | |||
import org.apache.ant.core.model.*; | |||
import org.apache.ant.core.support.*; | |||
import java.util.*; | |||
import java.net.URL; | |||
/** | |||
* A task is a top level element in the buidl which will be processed. Ant | |||
* currently handles two types of tasks - DataType tasks and execution tasks. | |||
* | |||
* @author <a href="mailto:conor@apache.org">Conor MacNeill</a> | |||
*/ | |||
public interface Task { | |||
void setTaskContext(ExecutionContext context); | |||
void execute() throws ExecutionException; | |||
} | |||
@@ -1,100 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 1999 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.core.execution; | |||
import java.lang.reflect.*; | |||
import java.util.*; | |||
/** | |||
* Use introspection to "adapt" an arbitrary Bean ( not extending Task, but with similar | |||
* patterns). | |||
* | |||
* @author <a href="mailto:conor@apache.org">Conor MacNeill</a> | |||
*/ | |||
public class TaskAdapter extends AbstractTask { | |||
/** | |||
* The real object that is performing the work | |||
*/ | |||
private Object worker; | |||
private Method executeMethod = null; | |||
public TaskAdapter(String taskType, Object worker) | |||
throws ExecutionException { | |||
this.worker = worker; | |||
try { | |||
Class workerClass = worker.getClass(); | |||
executeMethod = workerClass.getMethod("execute", new Class[0]); | |||
if (executeMethod == null) { | |||
throw new ExecutionException("No execute method in the class for the <" | |||
+ taskType + "> task."); | |||
} | |||
} | |||
catch (NoSuchMethodException e) { | |||
throw new ExecutionException(e); | |||
} | |||
} | |||
public void execute() throws ExecutionException { | |||
try { | |||
executeMethod.invoke(worker, null); | |||
} | |||
catch( Exception ex ) { | |||
throw new ExecutionException(ex); | |||
} | |||
} | |||
} |
@@ -1,72 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.core.execution; | |||
import java.util.*; | |||
import java.net.URL; | |||
/** | |||
* A TaskContainer is an object which can contain and manage | |||
* ExecutionTasks. | |||
* | |||
* @author <a href="mailto:conor@apache.org">Conor MacNeill</a> | |||
*/ | |||
public interface TaskContainer { | |||
/** | |||
* Add a task to the container. | |||
*/ | |||
void addTask(Task task) throws ExecutionException; | |||
} | |||
@@ -1,125 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.core.execution; | |||
import java.util.*; | |||
import java.net.URL; | |||
/** | |||
* A Task definition provides the information necessary to execute | |||
* a task implementation. | |||
* | |||
* @author <a href="mailto:conor@apache.org">Conor MacNeill</a> | |||
*/ | |||
public class TaskDefinition { | |||
/** The URL of the library which defines this task */ | |||
private URL taskLibraryURL; | |||
/** The task's name */ | |||
private String taskName; | |||
/** The task's class */ | |||
private String taskClassName; | |||
/** The task's class loaded from the loader on demand. */ | |||
private Class taskClass = null; | |||
/** The task's class loader. */ | |||
private ClassLoader taskClassLoader; | |||
public TaskDefinition(URL taskLibraryURL, String taskName, String taskClassName, | |||
ClassLoader taskClassLoader) { | |||
this.taskLibraryURL = taskLibraryURL; | |||
this.taskName = taskName; | |||
this.taskClassName = taskClassName; | |||
this.taskClassLoader = taskClassLoader; | |||
} | |||
/** | |||
* Get the name of the task that is being defined. | |||
*/ | |||
public String getName() { | |||
return taskName; | |||
} | |||
/** | |||
* Get the classname of the task that is being defined. | |||
*/ | |||
public String getTaskClassName() { | |||
return taskClassName; | |||
} | |||
/** | |||
* Get the URL where this task was defined. | |||
* | |||
* @returns a URL of the lib defintion file | |||
*/ | |||
public URL getLibraryURL() { | |||
return taskLibraryURL; | |||
} | |||
/** | |||
* Get the task class for this task | |||
* | |||
* @return a class object for this task | |||
*/ | |||
public synchronized Class getExecutionTaskClass() throws ClassNotFoundException { | |||
if (taskClass == null) { | |||
taskClass = Class.forName(taskClassName, true, taskClassLoader); | |||
} | |||
return taskClass; | |||
} | |||
} | |||
@@ -1,157 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.core.model; | |||
import java.util.*; | |||
import org.apache.ant.core.support.*; | |||
/** | |||
* A BuildElement is an element of a build file and has a location | |||
* within that file. | |||
* | |||
* @author <a href="mailto:conor@apache.org">Conor MacNeill</a> | |||
*/ | |||
public class BuildElement { | |||
/** The aspects defined for this element. */ | |||
private Map aspectMaps; | |||
/** The location of this element */ | |||
private Location location; | |||
/** A comment associated with this element, if any */ | |||
private String comment; | |||
/** | |||
* Create a build element giving its location. | |||
* | |||
* @param location identifies where this element is defined | |||
*/ | |||
public BuildElement(Location location) { | |||
this.location = location; | |||
} | |||
/** | |||
* Get the location of the source where this element is defined | |||
* | |||
* @return the element's location | |||
*/ | |||
public Location getLocation() { | |||
return location; | |||
} | |||
/** | |||
* Set a comment associated with this element | |||
* | |||
* @param comment the comment to be associated with this element. | |||
*/ | |||
public void setComment(String comment) { | |||
this.comment = comment; | |||
} | |||
/** | |||
* Get the comment associated with this element. | |||
* | |||
* @return the element's comment which may be null. | |||
*/ | |||
public String getComment() { | |||
return comment; | |||
} | |||
/** | |||
* Set the aspects of this element | |||
* | |||
* @param aspects a Map of apects that relate to this build element. | |||
*/ | |||
public void setAspects(Map aspects) { | |||
aspectMaps = new HashMap(); | |||
for (Iterator i = aspects.keySet().iterator(); i.hasNext(); ) { | |||
String aspectName = (String)i.next(); | |||
int separator = aspectName.indexOf(":"); | |||
if (separator != -1) { | |||
String prefix = aspectName.substring(0, separator); | |||
String name = aspectName.substring(separator + 1); | |||
if (prefix.length() != 0 && name.length() != 0) { | |||
Map prefixMap = (Map)aspectMaps.get(prefix); | |||
if (prefixMap == null) { | |||
prefixMap = new HashMap(); | |||
aspectMaps.put(prefix, prefixMap); | |||
} | |||
prefixMap.put(name, aspects.get(aspectName)); | |||
} | |||
} | |||
} | |||
} | |||
/** | |||
* Get an iterator on the aspects which have been given values on this element | |||
* | |||
* @return an iterator of Strings , being the aspects which have been given values on | |||
* this element. | |||
*/ | |||
public Iterator getAspectNames() { | |||
return aspectMaps.keySet().iterator(); | |||
} | |||
/** | |||
* Get the set of attribute values related to the given aspect | |||
* | |||
* @param apsectPrefix the prefix used to identify the prefix. | |||
* | |||
* @return a map of the attribute values for the given aspect. | |||
*/ | |||
public Map getAspectAttributes(String aspectPrefix) { | |||
return (Map)aspectMaps.get(aspectPrefix); | |||
} | |||
} | |||
@@ -1,267 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.core.model; | |||
import org.apache.ant.core.support.*; | |||
import java.util.*; | |||
import java.net.URL; | |||
/** | |||
* A project is a collection of targets and global tasks. A project | |||
* may reference objects in other projects using named references of | |||
* the form project:object | |||
* | |||
* @author <a href="mailto:conor@apache.org">Conor MacNeill</a> | |||
*/ | |||
public class Project extends BuildElement { | |||
/** The default target in this project. */ | |||
private String defaultTarget = null; | |||
/** The base URL of this project. Relative locations are relative to this base.*/ | |||
private String base; | |||
/** | |||
* The name of this project when referenced by a script within this project. | |||
*/ | |||
private String name; | |||
/** | |||
* These are the targets which belong to the project. They | |||
* will have interdependencies which are used to determine | |||
* which targets need to be executed before a given target. | |||
*/ | |||
private Map targets = new HashMap(); | |||
/** | |||
* The global tasks for this project. These are the tasks that will get executed | |||
* whenever an execution context is associated with this project. | |||
*/ | |||
private List tasks = new ArrayList(); | |||
/** | |||
* The projects imported into this project. Each imported project is | |||
* given a name which is used to identify access to that project's | |||
* elements. | |||
*/ | |||
private Map importedProjects = new HashMap(); | |||
/** | |||
* The URL where the project is defined. | |||
* | |||
*/ | |||
private URL sourceURL; | |||
/** | |||
* Create a Project | |||
* | |||
* @param sourceURL the URL where the project is defined. | |||
* @param location the location of this element within the source. | |||
*/ | |||
public Project(URL sourceURL, Location location) { | |||
super(location); | |||
this.sourceURL = sourceURL; | |||
} | |||
/** | |||
* Get the URL where this project is defined | |||
* | |||
* @return the project source URL | |||
*/ | |||
public URL getSourceURL() { | |||
return sourceURL; | |||
} | |||
/** | |||
* Add a target to the project. | |||
* | |||
* @param target the Target to be added | |||
* | |||
* @throws ProjectModelException if a target with the same name already exists. | |||
*/ | |||
public void addTarget(Target target) throws ProjectModelException { | |||
if (targets.containsKey(target.getName())) { | |||
throw new ProjectModelException("A target with name '" + target.getName() + | |||
"' has already been defined in this project", | |||
target.getLocation()); | |||
} | |||
targets.put(target.getName(), target); | |||
} | |||
/** | |||
* Set the defautl target of this project. | |||
* | |||
* @param defaultTarget the name of the defaultTarget of this project. | |||
*/ | |||
public void setDefaultTarget(String defaultTarget) { | |||
this.defaultTarget = defaultTarget; | |||
} | |||
/** | |||
* Get the Project's default Target, if any | |||
* | |||
* @return the project's defautl target or null if there is no default. | |||
*/ | |||
public String getDefaultTarget() { | |||
return defaultTarget; | |||
} | |||
/** | |||
* Set the base URL for this project. | |||
* | |||
* @param base the baseURL for this project. | |||
*/ | |||
public void setBase(String base) { | |||
this.base = base; | |||
} | |||
/** | |||
* Get the base URL for this project. | |||
* | |||
* @return the baseURL for this project as a string. | |||
*/ | |||
public String getBase() { | |||
return base; | |||
} | |||
/** | |||
* Set the name of this project. | |||
* | |||
* @param name the name for this project. | |||
*/ | |||
public void setName(String name) { | |||
this.name = name; | |||
} | |||
/** | |||
* Add a task to the list of global tasks for this project. | |||
* | |||
* @param task a task to be executed when an execution context | |||
* is associated with the Project (a non-target task) | |||
*/ | |||
public void addTask(TaskElement task) { | |||
tasks.add(task); | |||
} | |||
/** | |||
* Import a project to be referenced using the given name. | |||
* | |||
* @param importName the name under which the project will be referenced. | |||
* @param project the imported project. | |||
* | |||
* @throws ProjectModelException if an existing project has already | |||
* been imported with that name. | |||
*/ | |||
public void importProject(String importName, Project project) | |||
throws ProjectModelException { | |||
if (importedProjects.containsKey(importName)) { | |||
throw new ProjectModelException("A project has already been imported with name '" + | |||
importName + "'"); | |||
} | |||
importedProjects.put(importName, project); | |||
} | |||
/** | |||
* Get the targets in this project. | |||
* | |||
* @return an iterator returning Target objects. | |||
*/ | |||
public Iterator getTargets() { | |||
return targets.values().iterator(); | |||
} | |||
/** | |||
* Get the target with the given name | |||
* | |||
* @param targetName the name of the desired target. | |||
* | |||
* @return the target with the given name or null if there is no | |||
* such target. | |||
*/ | |||
public Target getTarget(String targetName) { | |||
return (Target)targets.get(targetName); | |||
} | |||
/** | |||
* Get the name sof the imported projects. | |||
* | |||
* @return an iterator which returns the name sof the imported projects. | |||
*/ | |||
public Iterator getImportedProjectNames() { | |||
return importedProjects.keySet().iterator(); | |||
} | |||
/** | |||
* Get an imported project by name | |||
* | |||
* @param importName the name under which the project was imported. | |||
* | |||
* @return the project asscociated with the given import name or null | |||
* if there is no such project. | |||
*/ | |||
public Project getImportedProject(String importName) { | |||
return (Project)importedProjects.get(importName); | |||
} | |||
/** | |||
* Get the initialisation tasks for this project | |||
* | |||
* @return an iterator over the set of tasks for this project. | |||
*/ | |||
public Iterator getTasks() { | |||
return tasks.iterator(); | |||
} | |||
} | |||
@@ -1,129 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.core.model; | |||
import org.apache.ant.core.support.*; | |||
import java.util.*; | |||
import java.net.URL; | |||
/** | |||
* A project model exception is thrown when an operation is attempted | |||
* which would violate the integrity of the Project/Target/Task object | |||
* model | |||
* | |||
* @author <a href="mailto:conor@apache.org">Conor MacNeill</a> | |||
*/ | |||
public class ProjectModelException extends AntException { | |||
/** | |||
* Constructs an exception with the given descriptive message. | |||
* | |||
* @param msg Description of or information about the exception. | |||
*/ | |||
public ProjectModelException(String msg) { | |||
super(msg); | |||
} | |||
/** | |||
* Constructs an exception with the given descriptive message and a location | |||
* in a file. | |||
* @param msg Description of or information about the exception. | |||
* @param location Location in the project file where the error occured. | |||
*/ | |||
public ProjectModelException(String msg, Location location) { | |||
super(msg, location); | |||
} | |||
/** | |||
* Constructs an exception with the given message and exception as | |||
* a root cause. | |||
* | |||
* @param msg Description of or information about the exception. | |||
* @param cause Throwable that might have cause this one. | |||
*/ | |||
public ProjectModelException(String msg, Throwable cause) { | |||
super(msg, cause); | |||
} | |||
/** | |||
* Constructs an exception with the given message and exception as | |||
* a root cause and a location in a file. | |||
* @param msg Description of or information about the exception. | |||
* @param cause Exception that might have cause this one. | |||
* @param location Location in the project file where the error occured. | |||
*/ | |||
public ProjectModelException(String msg, Throwable cause, Location location) { | |||
super(msg, cause, location); | |||
} | |||
/** | |||
* Constructs an exception with the given exception as a root cause. | |||
* | |||
* @param cause Exception that might have caused this one. | |||
*/ | |||
public ProjectModelException(Throwable cause) { | |||
super(cause); | |||
} | |||
/** | |||
* Constructs an exception with the given exception as | |||
* a root cause and a location in a file. | |||
* @param cause Exception that might have cause this one. | |||
* @param location Location in the project file where the error occured. | |||
*/ | |||
public ProjectModelException(Throwable cause, Location location) { | |||
super(cause, location); | |||
} | |||
} | |||
@@ -1,136 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.core.model; | |||
import java.util.*; | |||
import org.apache.ant.core.support.*; | |||
/** | |||
* A Target is a collection of tasks. It may have | |||
* dependencies on other targets | |||
* @author <a href="mailto:conor@apache.org">Conor MacNeill</a> | |||
*/ | |||
public class Target extends BuildElement { | |||
private List dependencies = new ArrayList(); | |||
/** | |||
* This target's list of tasks | |||
*/ | |||
private List tasks = new ArrayList(); | |||
/** | |||
* The target's name. | |||
*/ | |||
private String name; | |||
/** | |||
* Construct the target, given its name | |||
* | |||
* @param location the location of the element | |||
* @param name the target's name. | |||
*/ | |||
public Target(Location location, String name) { | |||
super(location); | |||
this.name = name; | |||
} | |||
/** | |||
* Get this target's name. | |||
* | |||
* @return the target's name. | |||
*/ | |||
public String getName() { | |||
return name; | |||
} | |||
/** | |||
* Add a task to this target | |||
* | |||
* @param task the task to be added to the target. | |||
*/ | |||
public void addTask(TaskElement task) { | |||
tasks.add(task); | |||
} | |||
/** | |||
* Add a dependency to this target | |||
* | |||
* @param dependency the name of a target upon which this target | |||
* depends | |||
*/ | |||
public void addDependency(String dependency) { | |||
dependencies.add(dependency); | |||
} | |||
/** | |||
* Get this target's dependencies. | |||
* | |||
* @return an iterator over the target's dependencies. | |||
*/ | |||
public Iterator getDependencies() { | |||
return dependencies.iterator(); | |||
} | |||
/** | |||
* Get the tasks for this target | |||
* | |||
* @return an iterator over the set of tasks for this target. | |||
*/ | |||
public Iterator getTasks() { | |||
return tasks.iterator(); | |||
} | |||
} | |||
@@ -1,169 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.core.model; | |||
import java.util.*; | |||
import org.apache.ant.core.support.*; | |||
/** | |||
* A TaskElement is a holder for Task configuration information. | |||
* TaskElements may be grouped into a hierarchy to capture | |||
* any level of Task element nesting. | |||
* | |||
* @author <a href="mailto:conor@apache.org">Conor MacNeill</a> | |||
*/ | |||
public class TaskElement extends BuildElement { | |||
/** The attributes of this task element */ | |||
private Map attributes = new HashMap(); | |||
/** | |||
* The task's name or type | |||
*/ | |||
private String type; | |||
/** | |||
* The task elements that make up this task. | |||
*/ | |||
private List taskElements = new ArrayList(); | |||
/** The content (text) of this task */ | |||
private String text = ""; | |||
/** | |||
* Create a Task of the given type | |||
* | |||
* @param location the location of the element | |||
* @param type the task element's type | |||
*/ | |||
public TaskElement(Location location, String type) { | |||
super(location); | |||
this.type = type; | |||
} | |||
/** | |||
* Add text to this task. | |||
* | |||
* @param text the element text to add. | |||
*/ | |||
public void addText(String text) { | |||
this.text += text; | |||
} | |||
/** | |||
* Get the text of this task | |||
* | |||
* @return the task's text. | |||
*/ | |||
public String getText() { | |||
return text; | |||
} | |||
/** | |||
* Add a task element to this task | |||
* | |||
* @param taskElement the task element to be added. | |||
*/ | |||
public void addTaskElement(TaskElement taskElement) { | |||
taskElements.add(taskElement); | |||
} | |||
/** | |||
* Get an iterator over this element's nexted elements | |||
* | |||
* @return an iterator which provides TaskElement instances | |||
*/ | |||
public Iterator getNestedElements() { | |||
return taskElements.iterator(); | |||
} | |||
/** | |||
* Get the type of this task element | |||
* | |||
* @return the element's type | |||
*/ | |||
public String getType() { | |||
return type; | |||
} | |||
/** | |||
* Add an attribute to this task element | |||
* | |||
* @param attributeName the name of the attribute | |||
* @param attributeValue the attribute's value. | |||
*/ | |||
public void addAttribute(String attributeName, String attributeValue) { | |||
attributes.put(attributeName, attributeValue); | |||
} | |||
/** | |||
* Get an iterator over the task's attributes | |||
* | |||
* @return an iterator which provide's attribute names | |||
*/ | |||
public Iterator getAttributeNames() { | |||
return attributes.keySet().iterator(); | |||
} | |||
/** | |||
* Get the value of an attribute. | |||
* | |||
* @param attributeName the name of the attribute | |||
* | |||
* @return the value of the attribute or null if there is no such attribute. | |||
*/ | |||
public String getAttributeValue(String attributeName) { | |||
return (String)attributes.get(attributeName); | |||
} | |||
} | |||
@@ -1,150 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.core.support; | |||
import java.util.*; | |||
import java.net.*; | |||
import java.io.*; | |||
/** | |||
* The AntClassLoader is a type of URL classloader which reverses the standard | |||
* lookup order to load things from the URLs first and then to use the parent class | |||
* loader only if the class does not exist in the URLs. | |||
* | |||
* @author <a href="mailto:conor@apache.org">Conor MacNeill</a> | |||
*/ | |||
public class AntClassLoader extends URLClassLoader { | |||
/** A Debug label to print when the Classloader finds or fails to find a class. */ | |||
private String debugLabel = null; | |||
/** A flag whihc controls whether messages are logged by the loader */ | |||
private boolean debug = false; | |||
private void dumpURLs() { | |||
if (debug && debugLabel != null) { | |||
System.out.println(debugLabel + ": loader URLs"); | |||
URL[] urls = getURLs(); | |||
for (int i = 0; i < urls.length; ++i) { | |||
System.out.println(debugLabel + ": URL: " + urls[i]); | |||
} | |||
} | |||
} | |||
public AntClassLoader(URL[] urls) { | |||
super(urls); | |||
} | |||
public AntClassLoader(URL[] urls, String debugLabel) { | |||
super(urls); | |||
this.debugLabel = debugLabel; | |||
} | |||
public AntClassLoader(URL[] urls, | |||
ClassLoader parent) { | |||
super(urls, parent); | |||
} | |||
public AntClassLoader(URL[] urls, | |||
ClassLoader parent, String debugLabel) { | |||
super(urls, parent); | |||
this.debugLabel = debugLabel; | |||
} | |||
public void setDebug(boolean debug) { | |||
this.debug = debug; | |||
dumpURLs(); | |||
} | |||
protected Class loadClass(String name, boolean resolve) | |||
throws ClassNotFoundException { | |||
if (debug && debugLabel != null) { | |||
System.out.println(debugLabel + ": Trying to load class " + name); | |||
} | |||
Class c = findLoadedClass(name); | |||
if (c == null) { | |||
try { | |||
c = findClass(name); | |||
if (debug && debugLabel != null) { | |||
System.out.println(debugLabel + ": Found class " + name + " in this loader"); | |||
} | |||
} catch (ClassNotFoundException e) { | |||
c = super.loadClass(name, resolve); | |||
if (debug && debugLabel != null) { | |||
System.out.println(debugLabel + ": Found class " + name + " in parent loader"); | |||
} | |||
return c; | |||
} | |||
} | |||
if (resolve) { | |||
resolveClass(c); | |||
} | |||
return c; | |||
} | |||
public void addURL(URL url) { | |||
super.addURL(url); | |||
} | |||
public URL getResource(String name) { | |||
URL url = findResource(name); | |||
if (url == null) { | |||
url = super.getResource(name); | |||
} | |||
return url; | |||
} | |||
} | |||
@@ -1,205 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.core.support; | |||
import java.io.*; | |||
/** | |||
* An AntException indicates some exceptional case has been encountered in | |||
* the processing of Ant. AntExceptions may accept a Throwable as a | |||
* cause allowing exceptions to be nested | |||
* | |||
* @author <a href="mailto:conor@apache.org">Conor MacNeill</a> | |||
*/ | |||
public abstract class AntException extends Exception { | |||
/** | |||
* Exception that might have caused this one. | |||
*/ | |||
private Throwable cause = null; | |||
/** | |||
* The location of the element which is associated with this exception if known. | |||
*/ | |||
private Location location = Location.UNKNOWN_LOCATION; | |||
/** | |||
* Constructs an exception with the given descriptive message. | |||
* @param msg Description of or information about the exception. | |||
*/ | |||
public AntException(String msg) { | |||
super(msg); | |||
} | |||
/** | |||
* Constructs an exception with the given message and exception as | |||
* a root cause. | |||
* @param msg Description of or information about the exception. | |||
* @param cause Throwable that might have cause this one. | |||
*/ | |||
public AntException(String msg, Throwable cause) { | |||
super(msg); | |||
this.cause = cause; | |||
} | |||
/** | |||
* Constructs an exception with the given message and exception as | |||
* a root cause and a location in a file. | |||
* @param msg Description of or information about the exception. | |||
* @param cause Exception that might have cause this one. | |||
* @param location Location in the project file where the error occured. | |||
*/ | |||
public AntException(String msg, Throwable cause, Location location) { | |||
this(msg, cause); | |||
setLocation(location); | |||
} | |||
/** | |||
* Constructs an exception with the given exception as a root cause. | |||
* @param cause Exception that might have caused this one. | |||
*/ | |||
public AntException(Throwable cause) { | |||
super(cause.getMessage()); | |||
this.cause = cause; | |||
} | |||
/** | |||
* Constructs an exception with the given descriptive message and a location | |||
* in a file. | |||
* @param msg Description of or information about the exception. | |||
* @param location Location in the project file where the error occured. | |||
*/ | |||
public AntException(String msg, Location location) { | |||
super(msg); | |||
setLocation(location); | |||
} | |||
/** | |||
* Constructs an exception with the given exception as | |||
* a root cause and a location in a file. | |||
* @param cause Exception that might have cause this one. | |||
* @param location Location in the project file where the error occured. | |||
*/ | |||
public AntException(Throwable cause, Location location) { | |||
this(cause); | |||
setLocation(location); | |||
} | |||
/** | |||
* Returns the nested exception. | |||
* | |||
* @return the underlying exception | |||
*/ | |||
public Throwable getCause() { | |||
return cause; | |||
} | |||
/** | |||
* Sets the file location where the error occured. | |||
*/ | |||
public void setLocation(Location location) { | |||
if (location == null) { | |||
this.location = Location.UNKNOWN_LOCATION; | |||
} | |||
else { | |||
this.location = location; | |||
} | |||
} | |||
/** | |||
* Returns the file location where the error occured. | |||
*/ | |||
public Location getLocation() { | |||
return location; | |||
} | |||
/** | |||
* Print the stack trace to System.err | |||
*/ | |||
public void printStackTrace() { | |||
printStackTrace(System.err); | |||
} | |||
/** | |||
* Print the stack trace to the given PrintStream | |||
* | |||
* @param ps the PrintStream onto which the stack trace | |||
* of this exception is to be printed | |||
*/ | |||
public void printStackTrace(PrintStream ps) { | |||
synchronized (ps) { | |||
ps.println(this); | |||
if (cause != null) { | |||
ps.println("--- Nested Exception ---"); | |||
cause.printStackTrace(ps); | |||
} | |||
} | |||
} | |||
/** | |||
* Print the stack trace to the given PrintWriter | |||
* | |||
* @param pw the PrintWriter onto which the stack trace | |||
* of this exception is to be printed | |||
*/ | |||
public void printStackTrace(PrintWriter pw) { | |||
synchronized (pw) { | |||
pw.println(this); | |||
if (cause != null) { | |||
pw.println("--- Nested Exception ---"); | |||
cause.printStackTrace(pw); | |||
} | |||
} | |||
} | |||
} |
@@ -1,331 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.core.support; | |||
import java.util.*; | |||
import java.net.*; | |||
import java.io.*; | |||
/** | |||
* The Ant Locator is used to find various Ant components without | |||
* requiring the user to maintain environment properties. | |||
* | |||
* @author <a href="mailto:conor@apache.org">Conor MacNeill</a> | |||
*/ | |||
public class AntLocator { | |||
private AntLocator() {} | |||
/** | |||
* Get the URL for the given class's load location. | |||
* | |||
* @param theClass the class whose loadURL is desired. | |||
* @return a URL which identifies the component from which this class was loaded. | |||
* | |||
* @throws LocationException if the class' URL cannot be constructed. | |||
*/ | |||
static public URL getClassLocationURL(Class theClass) | |||
throws LocationException { | |||
String className = theClass.getName().replace('.', '/') + ".class"; | |||
URL classRawURL = theClass.getClassLoader().getResource(className); | |||
try { | |||
String fileComponent = classRawURL.getFile(); | |||
if (classRawURL.getProtocol().equals("file")) { | |||
// Class comes from a directory of class files rather than | |||
// from a jar. | |||
int classFileIndex = fileComponent.lastIndexOf(className); | |||
if (classFileIndex != -1) { | |||
fileComponent = fileComponent.substring(0, classFileIndex); | |||
} | |||
return new URL("file:" + fileComponent); | |||
} | |||
else if (classRawURL.getProtocol().equals("jar")) { | |||
// Class is coming from a jar. The file component of the URL | |||
// is actually the URL of the jar file | |||
int classSeparatorIndex = fileComponent.lastIndexOf("!"); | |||
if (classSeparatorIndex != -1) { | |||
fileComponent = fileComponent.substring(0, classSeparatorIndex); | |||
} | |||
return new URL(fileComponent); | |||
} | |||
else { | |||
// its running out of something besides a jar. We just return the Raw | |||
// URL as a best guess | |||
return classRawURL; | |||
} | |||
} | |||
catch (MalformedURLException e) { | |||
throw new LocationException(e); | |||
} | |||
} | |||
/** | |||
* Get the location of AntHome | |||
* | |||
* @return the URL containing AntHome. | |||
* | |||
* @throws LocationException if Ant's home cannot be determined. | |||
*/ | |||
static public URL getAntHome() throws LocationException { | |||
try { | |||
URL libraryURL = getLibraryURL(); | |||
if (libraryURL != null) { | |||
return new URL(libraryURL, ".."); | |||
} | |||
else { | |||
return null; | |||
} | |||
} | |||
catch (MalformedURLException e) { | |||
e.printStackTrace(); | |||
return null; | |||
} | |||
} | |||
/** | |||
* Get a URL to the Ant core jar. Other jars can be located | |||
* from this as relative URLs | |||
* | |||
* @return a URL containing the Ant core or null if the core cannot be determined. | |||
* | |||
* @throws LocationException if the URL of the core.jar cannot be determined. | |||
*/ | |||
static public URL getCoreURL() throws LocationException { | |||
return getClassLocationURL(AntLocator.class); | |||
} | |||
/** | |||
* Get a URL to the Ant Library directory. | |||
* | |||
* @throws LocationException if the location of the Ant library directory cannot | |||
* be determined | |||
*/ | |||
static public URL getLibraryURL() throws LocationException { | |||
URL coreURL = getCoreURL(); | |||
try { | |||
if (coreURL.getProtocol().equals("file") && | |||
coreURL.getFile().endsWith("/")) { | |||
// we are running from a set of classes. This should only happen | |||
// in an Ant build situation. We use some embedded knowledge to | |||
// locate the lib directory | |||
File coreClassDirectory = new File(coreURL.getFile()); | |||
File libDirectory = coreClassDirectory.getParentFile().getParentFile(); | |||
if (!libDirectory.exists()) { | |||
throw new LocationException("Ant library directory " + libDirectory + | |||
" does not exist"); | |||
} | |||
return (new File(libDirectory, "lib")).toURL(); | |||
} | |||
else { | |||
String coreURLString = coreURL.toString(); | |||
int index = coreURLString.lastIndexOf("/"); | |||
if (index != -1) { | |||
coreURLString = coreURLString.substring(0, index+1); | |||
} | |||
return new URL(coreURLString); | |||
} | |||
} | |||
catch (MalformedURLException e) { | |||
throw new LocationException(e); | |||
} | |||
} | |||
/** | |||
* Get a classloader with which to load the SAX parser | |||
* | |||
* @return the classloader to use to load Ant's XML parser | |||
* | |||
* @throws LocationException if the location of the parser jars | |||
* could not be determined. | |||
*/ | |||
static public ClassLoader getParserClassLoader(Properties properties) | |||
throws LocationException { | |||
// we look for the parser directory based on a system property first | |||
String parserURLString = properties.getProperty(Constants.PropertyNames.PARSER_URL); | |||
URL parserURL = null; | |||
if (parserURLString != null) { | |||
try { | |||
parserURL = new URL(parserURLString); | |||
} | |||
catch (MalformedURLException e) { | |||
throw new LocationException("XML Parser URL " + parserURLString + | |||
" is malformed.", e); | |||
} | |||
} | |||
else { | |||
try { | |||
parserURL = new URL(getLibraryURL(), "parser/"); | |||
} | |||
catch (Exception e) { | |||
// ignore - we will just use the default class loader. | |||
} | |||
} | |||
if (parserURL != null) { | |||
try { | |||
URL[] parserURLs = null; | |||
if (parserURL.getProtocol().equals("file")) { | |||
// build up the URLs for each jar file in the | |||
// parser directory | |||
parserURLs = getDirectoryJarURLs(new File(parserURL.getFile())); | |||
} | |||
else { | |||
// we can't search the URL so we look for a known parser relative to | |||
// that URL | |||
String defaultParser = properties.getProperty(Constants.PropertyNames.DEFAULT_PARSER); | |||
if (defaultParser == null) { | |||
defaultParser = Constants.Defaults.DEFAULT_PARSER; | |||
} | |||
parserURLs = new URL[1]; | |||
parserURLs[0] = new URL(parserURL, defaultParser); | |||
} | |||
return new AntClassLoader(parserURLs, "parser"); | |||
} | |||
catch (MalformedURLException e) { | |||
throw new LocationException(e); | |||
} | |||
} | |||
return AntLocator.class.getClassLoader(); | |||
} | |||
/** | |||
* Get an array of URLs for each file matching the given set of extensions | |||
* | |||
* @param directory the local directory | |||
* @param extensions the set of extensions to be returned | |||
* | |||
* @return an array of URLs for the file found in the directory. | |||
*/ | |||
static public URL[] getDirectoryURLs(File directory, final Set extensions) { | |||
URL[] urls = new URL[0]; | |||
if (!directory.exists()) { | |||
return urls; | |||
} | |||
File[] jars = directory.listFiles(new FilenameFilter() { | |||
public boolean accept(File dir, String name) { | |||
int extensionIndex = name.lastIndexOf("."); | |||
if (extensionIndex == -1) { | |||
return false; | |||
} | |||
String extension = name.substring(extensionIndex); | |||
return extensions.contains(extension); | |||
} | |||
}); | |||
urls = new URL[jars.length]; | |||
for (int i = 0; i < jars.length; ++i) { | |||
try { | |||
urls[i] = jars[i].toURL(); | |||
} | |||
catch (MalformedURLException e) { | |||
// just ignore | |||
} | |||
} | |||
return urls; | |||
} | |||
/** | |||
* Get an array of URLs for each jar file in a local directory. | |||
* | |||
* @param directory the local directory | |||
* | |||
* @return an array of URLs for the jars found in the directory. | |||
*/ | |||
static private URL[] getDirectoryJarURLs(File directory) { | |||
HashSet extensions = new HashSet(); | |||
extensions.add(".jar"); | |||
return getDirectoryURLs(directory, extensions); | |||
} | |||
/** | |||
* Get the Core Class Loader. The core requires a SAX parser which must come from the | |||
* given classloader | |||
* | |||
* @throws LocationException if the location of the core ant classes could | |||
* not be determined | |||
*/ | |||
static public AntClassLoader getCoreClassLoader(Properties properties) | |||
throws LocationException { | |||
URL[] coreURL = new URL[1]; | |||
coreURL[0] = getCoreURL(); | |||
AntClassLoader coreLoader | |||
= new AntClassLoader(coreURL, getParserClassLoader(properties), "core"); | |||
URL libraryURL = getLibraryURL(); | |||
if (libraryURL != null && libraryURL.getProtocol().equals("file")) { | |||
// we can search this | |||
URL[] optionalURLs = getDirectoryJarURLs(new File(libraryURL.getFile(), "optional")); | |||
for (int i = 0; i < optionalURLs.length; ++i) { | |||
coreLoader.addURL(optionalURLs[i]); | |||
} | |||
} | |||
return coreLoader; | |||
} | |||
} | |||
@@ -1,125 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.core.support; | |||
import java.io.*; | |||
/** | |||
* A ConfigException indicates a problem with | |||
* Ant's configuration. | |||
* | |||
* @author <a href="mailto:conor@apache.org">Conor MacNeill</a> | |||
*/ | |||
public class ConfigException extends AntException { | |||
/** | |||
* Constructs an exception with the given descriptive message. | |||
* | |||
* @param msg Description of or information about the exception. | |||
*/ | |||
public ConfigException(String msg) { | |||
super(msg); | |||
} | |||
/** | |||
* Constructs an exception with the given descriptive message and a location | |||
* in a file. | |||
* @param msg Description of or information about the exception. | |||
* @param location Location in the project file where the error occured. | |||
*/ | |||
public ConfigException(String msg, Location location) { | |||
super(msg, location); | |||
} | |||
/** | |||
* Constructs an exception with the given message and exception as | |||
* a root cause. | |||
* | |||
* @param msg Description of or information about the exception. | |||
* @param cause Throwable that might have cause this one. | |||
*/ | |||
public ConfigException(String msg, Throwable cause) { | |||
super(msg, cause); | |||
} | |||
/** | |||
* Constructs an exception with the given message and exception as | |||
* a root cause and a location in a file. | |||
* @param msg Description of or information about the exception. | |||
* @param cause Exception that might have cause this one. | |||
* @param location Location in the project file where the error occured. | |||
*/ | |||
public ConfigException(String msg, Throwable cause, Location location) { | |||
super(msg, cause, location); | |||
} | |||
/** | |||
* Constructs an exception with the given exception as a root cause. | |||
* | |||
* @param cause Exception that might have caused this one. | |||
*/ | |||
public ConfigException(Throwable cause) { | |||
super(cause); | |||
} | |||
/** | |||
* Constructs an exception with the given exception as | |||
* a root cause and a location in a file. | |||
* @param cause Exception that might have cause this one. | |||
* @param location Location in the project file where the error occured. | |||
*/ | |||
public ConfigException(Throwable cause, Location location) { | |||
super(cause, location); | |||
} | |||
} |
@@ -1,76 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.core.support; | |||
import java.util.*; | |||
import java.net.*; | |||
import java.io.*; | |||
/** | |||
* Constants used by the Ant core | |||
* | |||
* @author <a href="mailto:conor@apache.org">Conor MacNeill</a> | |||
*/ | |||
public class Constants { | |||
static public class PropertyNames { | |||
static public final String PARSER_URL = "ant.parser.url"; | |||
static public final String DEFAULT_PARSER = "ant.parser.default"; | |||
} | |||
static public class Defaults { | |||
static public final String DEFAULT_PARSER = "crimson.jar"; | |||
} | |||
} | |||
@@ -1,166 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.core.support; | |||
/** | |||
* Stores the file name and line number in a file. | |||
*/ | |||
public class Location { | |||
/** | |||
* The source URL to which this location relates. | |||
*/ | |||
private String source; | |||
/** | |||
* The line number of this location within the source | |||
*/ | |||
private int lineNumber; | |||
/** | |||
* The column number of this locatin within the source | |||
*/ | |||
private int columnNumber; | |||
/** | |||
* Standard unknown location constant; | |||
*/ | |||
public static final Location UNKNOWN_LOCATION = new Location(); | |||
/** | |||
* Creates an "unknown" location. | |||
*/ | |||
private Location() { | |||
this(null, 0, 0); | |||
} | |||
/** | |||
* Creates a location consisting of a source location but no line number. | |||
* | |||
* @param source the source (URL) to which this location is associated. | |||
*/ | |||
public Location(String source) { | |||
this(source, 1, 1); | |||
} | |||
/** | |||
* Creates a location consisting of a source location and co-ordinates within that | |||
* source | |||
* | |||
* @param source the source (URL) to which this location is associated. | |||
* @param lineNumber the line number of this location | |||
* @param columnNumber the column number of this location | |||
*/ | |||
public Location(String source, int lineNumber, int columnNumber) { | |||
this.source = source; | |||
this.lineNumber = lineNumber; | |||
this.columnNumber = columnNumber; | |||
} | |||
/** | |||
* Returns the source name, line number and a trailing space. An error | |||
* message can be appended easily. For unknown locations, returns | |||
* an empty string. | |||
* | |||
* @return a suitable string representation of the location | |||
*/ | |||
public String toString() { | |||
StringBuffer buf = new StringBuffer(); | |||
if (source != null) { | |||
if (source.startsWith("file:")) { | |||
buf.append(source.substring(5)); | |||
} | |||
else { | |||
buf.append(source); | |||
} | |||
if (lineNumber != 0) { | |||
buf.append(":"); | |||
buf.append(lineNumber); | |||
} | |||
buf.append(": "); | |||
} | |||
return buf.toString(); | |||
} | |||
/** | |||
* Get the source URL for this location | |||
* | |||
* @return a URL string | |||
*/ | |||
public String getSourceURL() { | |||
return source; | |||
} | |||
/** | |||
* Get the line number of this location | |||
* | |||
* @return an integer line number | |||
*/ | |||
public int getLineNumber() { | |||
return lineNumber; | |||
} | |||
/** | |||
* Get the column number of this location | |||
* | |||
* @return an integer column number | |||
*/ | |||
public int getColumnNumber() { | |||
return columnNumber; | |||
} | |||
} |
@@ -1,97 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.core.support; | |||
import java.util.*; | |||
import java.net.URL; | |||
/** | |||
* A LocationException is thrown when there is a problem determining | |||
* the location of an Ant component. | |||
* | |||
* @author <a href="mailto:conor@apache.org">Conor MacNeill</a> | |||
*/ | |||
public class LocationException extends AntException { | |||
/** | |||
* Constructs an exception with the given descriptive message. | |||
* | |||
* @param msg Description of or information about the exception. | |||
*/ | |||
public LocationException(String msg) { | |||
super(msg); | |||
} | |||
/** | |||
* Constructs an exception with the given message and exception as | |||
* a root cause. | |||
* | |||
* @param msg Description of or information about the exception. | |||
* @param cause Throwable that might have cause this one. | |||
*/ | |||
public LocationException(String msg, Throwable cause) { | |||
super(msg, cause); | |||
} | |||
/** | |||
* Constructs an exception with the given exception as a root cause. | |||
* | |||
* @param cause Exception that might have caused this one. | |||
*/ | |||
public LocationException(Throwable cause) { | |||
super(cause); | |||
} | |||
} | |||
@@ -1,580 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2000 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.core.types; | |||
import java.io.*; | |||
import java.util.*; | |||
import org.apache.ant.core.execution.*; | |||
/** | |||
* The abstract FileSetInfo performs all of the name matching and mapping operations | |||
* common to FileSetInfo classes. | |||
*/ | |||
public abstract class AbstractScanner implements FileSetScanner { | |||
/** The list of patternSets to process on this directory */ | |||
List patternSets; | |||
/** Indicator for whether default excludes should be applied. */ | |||
boolean useDefaultExcludes; | |||
/* | |||
* The patterns for the files that should be included. | |||
*/ | |||
private String[] includes; | |||
/** | |||
* The patterns for the files that should be excluded. | |||
*/ | |||
private String[] excludes; | |||
/** | |||
* Patterns that should be excluded by default. | |||
* | |||
* @see #addDefaultExcludes() | |||
*/ | |||
protected final static String[] DEFAULTEXCLUDES = { | |||
"**/*~", | |||
"**/#*#", | |||
"**/.#*", | |||
"**/%*%", | |||
"**/CVS", | |||
"**/CVS/**", | |||
"**/.cvsignore", | |||
"**/SCCS", | |||
"**/SCCS/**" | |||
}; | |||
public AbstractScanner(List patternSets, | |||
boolean useDefaultExcludes) throws ExecutionException { | |||
this.patternSets = patternSets; | |||
this.useDefaultExcludes = useDefaultExcludes; | |||
//convert patternsets into excludes | |||
PatternSet combinedSet = new PatternSet(); | |||
for (Iterator i = patternSets.iterator(); i.hasNext(); ) { | |||
PatternSet set = (PatternSet)i.next(); | |||
combinedSet.append(set); | |||
} | |||
String[] includes = combinedSet.getIncludePatterns(); | |||
if (includes == null) { | |||
// No includes supplied, so set it to 'matches all' | |||
includes = new String[1]; | |||
includes[0] = "**"; | |||
} | |||
String[] excludes = combinedSet.getExcludePatterns(); | |||
if (excludes == null) { | |||
excludes = new String[0]; | |||
} | |||
setIncludes(includes); | |||
setExcludes(excludes); | |||
if (useDefaultExcludes) { | |||
addDefaultExcludes(); | |||
} | |||
} | |||
/** | |||
* Sets the set of include patterns to use. All '/' and '\' characters are | |||
* replaced by <code>File.separatorChar</code>. So the separator used need | |||
* not match <code>File.separatorChar</code>. | |||
* <p> | |||
* When a pattern ends with a '/' or '\', "**" is appended. | |||
* | |||
* @param includes list of include patterns | |||
*/ | |||
protected void setIncludes(String[] includes) { | |||
if (includes == null) { | |||
this.includes = null; | |||
} else { | |||
this.includes = new String[includes.length]; | |||
for (int i = 0; i < includes.length; i++) { | |||
String pattern; | |||
pattern = includes[i].replace('/',File.separatorChar).replace('\\',File.separatorChar); | |||
if (pattern.endsWith(File.separator)) { | |||
pattern += "**"; | |||
} | |||
this.includes[i] = pattern; | |||
} | |||
} | |||
} | |||
/** | |||
* Sets the set of exclude patterns to use. All '/' and '\' characters are | |||
* replaced by <code>File.separatorChar</code>. So the separator used need | |||
* not match <code>File.separatorChar</code>. | |||
* <p> | |||
* When a pattern ends with a '/' or '\', "**" is appended. | |||
* | |||
* @param excludes list of exclude patterns | |||
*/ | |||
protected void setExcludes(String[] excludes) { | |||
if (excludes == null) { | |||
this.excludes = null; | |||
} else { | |||
this.excludes = new String[excludes.length]; | |||
for (int i = 0; i < excludes.length; i++) { | |||
String pattern; | |||
pattern = excludes[i].replace('/',File.separatorChar).replace('\\',File.separatorChar); | |||
if (pattern.endsWith(File.separator)) { | |||
pattern += "**"; | |||
} | |||
this.excludes[i] = pattern; | |||
} | |||
} | |||
} | |||
/** | |||
* Does the path match the start of this pattern up to the first "**". | |||
+ | |||
* <p>This is not a general purpose test and should only be used if you | |||
* can live with false positives.</p> | |||
* | |||
* <p><code>pattern=**\\a</code> and <code>str=b</code> will yield true. | |||
* | |||
* @param pattern the (non-null) pattern to match against | |||
* @param str the (non-null) string (path) to match | |||
*/ | |||
protected static boolean matchPatternStart(String pattern, String str) { | |||
// When str starts with a File.separator, pattern has to start with a | |||
// File.separator. | |||
// When pattern starts with a File.separator, str has to start with a | |||
// File.separator. | |||
if (str.startsWith(File.separator) != | |||
pattern.startsWith(File.separator)) { | |||
return false; | |||
} | |||
Vector patDirs = new Vector(); | |||
StringTokenizer st = new StringTokenizer(pattern,File.separator); | |||
while (st.hasMoreTokens()) { | |||
patDirs.addElement(st.nextToken()); | |||
} | |||
Vector strDirs = new Vector(); | |||
st = new StringTokenizer(str,File.separator); | |||
while (st.hasMoreTokens()) { | |||
strDirs.addElement(st.nextToken()); | |||
} | |||
int patIdxStart = 0; | |||
int patIdxEnd = patDirs.size()-1; | |||
int strIdxStart = 0; | |||
int strIdxEnd = strDirs.size()-1; | |||
// up to first '**' | |||
while (patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd) { | |||
String patDir = (String)patDirs.elementAt(patIdxStart); | |||
if (patDir.equals("**")) { | |||
break; | |||
} | |||
if (!match(patDir,(String)strDirs.elementAt(strIdxStart))) { | |||
return false; | |||
} | |||
patIdxStart++; | |||
strIdxStart++; | |||
} | |||
if (strIdxStart > strIdxEnd) { | |||
// String is exhausted | |||
return true; | |||
} else if (patIdxStart > patIdxEnd) { | |||
// String not exhausted, but pattern is. Failure. | |||
return false; | |||
} else { | |||
// pattern now holds ** while string is not exhausted | |||
// this will generate false positives but we can live with that. | |||
return true; | |||
} | |||
} | |||
/** | |||
* Matches a path against a pattern. | |||
* | |||
* @param pattern the (non-null) pattern to match against | |||
* @param str the (non-null) string (path) to match | |||
* | |||
* @return <code>true</code> when the pattern matches against the string. | |||
* <code>false</code> otherwise. | |||
*/ | |||
protected static boolean matchPath(String pattern, String str) { | |||
// When str starts with a File.separator, pattern has to start with a | |||
// File.separator. | |||
// When pattern starts with a File.separator, str has to start with a | |||
// File.separator. | |||
if (str.startsWith(File.separator) != | |||
pattern.startsWith(File.separator)) { | |||
return false; | |||
} | |||
Vector patDirs = new Vector(); | |||
StringTokenizer st = new StringTokenizer(pattern,File.separator); | |||
while (st.hasMoreTokens()) { | |||
patDirs.addElement(st.nextToken()); | |||
} | |||
Vector strDirs = new Vector(); | |||
st = new StringTokenizer(str,File.separator); | |||
while (st.hasMoreTokens()) { | |||
strDirs.addElement(st.nextToken()); | |||
} | |||
int patIdxStart = 0; | |||
int patIdxEnd = patDirs.size()-1; | |||
int strIdxStart = 0; | |||
int strIdxEnd = strDirs.size()-1; | |||
// up to first '**' | |||
while (patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd) { | |||
String patDir = (String)patDirs.elementAt(patIdxStart); | |||
if (patDir.equals("**")) { | |||
break; | |||
} | |||
if (!match(patDir,(String)strDirs.elementAt(strIdxStart))) { | |||
return false; | |||
} | |||
patIdxStart++; | |||
strIdxStart++; | |||
} | |||
if (strIdxStart > strIdxEnd) { | |||
// String is exhausted | |||
for (int i = patIdxStart; i <= patIdxEnd; i++) { | |||
if (!patDirs.elementAt(i).equals("**")) { | |||
return false; | |||
} | |||
} | |||
return true; | |||
} else { | |||
if (patIdxStart > patIdxEnd) { | |||
// String not exhausted, but pattern is. Failure. | |||
return false; | |||
} | |||
} | |||
// up to last '**' | |||
while (patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd) { | |||
String patDir = (String)patDirs.elementAt(patIdxEnd); | |||
if (patDir.equals("**")) { | |||
break; | |||
} | |||
if (!match(patDir,(String)strDirs.elementAt(strIdxEnd))) { | |||
return false; | |||
} | |||
patIdxEnd--; | |||
strIdxEnd--; | |||
} | |||
if (strIdxStart > strIdxEnd) { | |||
// String is exhausted | |||
for (int i = patIdxStart; i <= patIdxEnd; i++) { | |||
if (!patDirs.elementAt(i).equals("**")) { | |||
return false; | |||
} | |||
} | |||
return true; | |||
} | |||
while (patIdxStart != patIdxEnd && strIdxStart <= strIdxEnd) { | |||
int patIdxTmp = -1; | |||
for (int i = patIdxStart+1; i <= patIdxEnd; i++) { | |||
if (patDirs.elementAt(i).equals("**")) { | |||
patIdxTmp = i; | |||
break; | |||
} | |||
} | |||
if (patIdxTmp == patIdxStart+1) { | |||
// '**/**' situation, so skip one | |||
patIdxStart++; | |||
continue; | |||
} | |||
// Find the pattern between padIdxStart & padIdxTmp in str between | |||
// strIdxStart & strIdxEnd | |||
int patLength = (patIdxTmp-patIdxStart-1); | |||
int strLength = (strIdxEnd-strIdxStart+1); | |||
int foundIdx = -1; | |||
strLoop: | |||
for (int i = 0; i <= strLength - patLength; i++) { | |||
for (int j = 0; j < patLength; j++) { | |||
String subPat = (String)patDirs.elementAt(patIdxStart+j+1); | |||
String subStr = (String)strDirs.elementAt(strIdxStart+i+j); | |||
if (!match(subPat,subStr)) { | |||
continue strLoop; | |||
} | |||
} | |||
foundIdx = strIdxStart+i; | |||
break; | |||
} | |||
if (foundIdx == -1) { | |||
return false; | |||
} | |||
patIdxStart = patIdxTmp; | |||
strIdxStart = foundIdx+patLength; | |||
} | |||
for (int i = patIdxStart; i <= patIdxEnd; i++) { | |||
if (!patDirs.elementAt(i).equals("**")) { | |||
return false; | |||
} | |||
} | |||
return true; | |||
} | |||
/** | |||
* Matches a string against a pattern. The pattern contains two special | |||
* characters: | |||
* '*' which means zero or more characters, | |||
* '?' which means one and only one character. | |||
* | |||
* @param pattern the (non-null) pattern to match against | |||
* @param str the (non-null) string that must be matched against the | |||
* pattern | |||
* | |||
* @return <code>true</code> when the string matches against the pattern, | |||
* <code>false</code> otherwise. | |||
*/ | |||
protected static boolean match(String pattern, String str) { | |||
char[] patArr = pattern.toCharArray(); | |||
char[] strArr = str.toCharArray(); | |||
int patIdxStart = 0; | |||
int patIdxEnd = patArr.length-1; | |||
int strIdxStart = 0; | |||
int strIdxEnd = strArr.length-1; | |||
char ch; | |||
boolean containsStar = false; | |||
for (int i = 0; i < patArr.length; i++) { | |||
if (patArr[i] == '*') { | |||
containsStar = true; | |||
break; | |||
} | |||
} | |||
if (!containsStar) { | |||
// No '*'s, so we make a shortcut | |||
if (patIdxEnd != strIdxEnd) { | |||
return false; // Pattern and string do not have the same size | |||
} | |||
for (int i = 0; i <= patIdxEnd; i++) { | |||
ch = patArr[i]; | |||
if (ch != '?' && ch != strArr[i]) { | |||
return false; // Character mismatch | |||
} | |||
} | |||
return true; // String matches against pattern | |||
} | |||
if (patIdxEnd == 0) { | |||
return true; // Pattern contains only '*', which matches anything | |||
} | |||
// Process characters before first star | |||
while((ch = patArr[patIdxStart]) != '*' && strIdxStart <= strIdxEnd) { | |||
if (ch != '?' && ch != strArr[strIdxStart]) { | |||
return false; | |||
} | |||
patIdxStart++; | |||
strIdxStart++; | |||
} | |||
if (strIdxStart > strIdxEnd) { | |||
// All characters in the string are used. Check if only '*'s are | |||
// left in the pattern. If so, we succeeded. Otherwise failure. | |||
for (int i = patIdxStart; i <= patIdxEnd; i++) { | |||
if (patArr[i] != '*') { | |||
return false; | |||
} | |||
} | |||
return true; | |||
} | |||
// Process characters after last star | |||
while((ch = patArr[patIdxEnd]) != '*' && strIdxStart <= strIdxEnd) { | |||
if (ch != '?' && ch != strArr[strIdxEnd]) { | |||
return false; | |||
} | |||
patIdxEnd--; | |||
strIdxEnd--; | |||
} | |||
if (strIdxStart > strIdxEnd) { | |||
// All characters in the string are used. Check if only '*'s are | |||
// left in the pattern. If so, we succeeded. Otherwise failure. | |||
for (int i = patIdxStart; i <= patIdxEnd; i++) { | |||
if (patArr[i] != '*') { | |||
return false; | |||
} | |||
} | |||
return true; | |||
} | |||
// process pattern between stars. padIdxStart and patIdxEnd point | |||
// always to a '*'. | |||
while (patIdxStart != patIdxEnd && strIdxStart <= strIdxEnd) { | |||
int patIdxTmp = -1; | |||
for (int i = patIdxStart+1; i <= patIdxEnd; i++) { | |||
if (patArr[i] == '*') { | |||
patIdxTmp = i; | |||
break; | |||
} | |||
} | |||
if (patIdxTmp == patIdxStart+1) { | |||
// Two stars next to each other, skip the first one. | |||
patIdxStart++; | |||
continue; | |||
} | |||
// Find the pattern between padIdxStart & padIdxTmp in str between | |||
// strIdxStart & strIdxEnd | |||
int patLength = (patIdxTmp-patIdxStart-1); | |||
int strLength = (strIdxEnd-strIdxStart+1); | |||
int foundIdx = -1; | |||
strLoop: | |||
for (int i = 0; i <= strLength - patLength; i++) { | |||
for (int j = 0; j < patLength; j++) { | |||
ch = patArr[patIdxStart+j+1]; | |||
if (ch != '?' && ch != strArr[strIdxStart+i+j]) { | |||
continue strLoop; | |||
} | |||
} | |||
foundIdx = strIdxStart+i; | |||
break; | |||
} | |||
if (foundIdx == -1) { | |||
return false; | |||
} | |||
patIdxStart = patIdxTmp; | |||
strIdxStart = foundIdx+patLength; | |||
} | |||
// All characters in the string are used. Check if only '*'s are left | |||
// in the pattern. If so, we succeeded. Otherwise failure. | |||
for (int i = patIdxStart; i <= patIdxEnd; i++) { | |||
if (patArr[i] != '*') { | |||
return false; | |||
} | |||
} | |||
return true; | |||
} | |||
/** | |||
* Tests whether a name matches against at least one include pattern. | |||
* | |||
* @param name the name to match | |||
* @return <code>true</code> when the name matches against at least one | |||
* include pattern, <code>false</code> otherwise. | |||
*/ | |||
protected boolean isIncluded(String name) { | |||
for (int i = 0; i < includes.length; i++) { | |||
if (matchPath(includes[i],name)) { | |||
return true; | |||
} | |||
} | |||
return false; | |||
} | |||
/** | |||
* Tests whether a name matches the start of at least one include pattern. | |||
* | |||
* @param name the name to match | |||
* @return <code>true</code> when the name matches against at least one | |||
* include pattern, <code>false</code> otherwise. | |||
*/ | |||
protected boolean couldHoldIncluded(String name) { | |||
for (int i = 0; i < includes.length; i++) { | |||
if (matchPatternStart(includes[i],name)) { | |||
return true; | |||
} | |||
} | |||
return false; | |||
} | |||
/** | |||
* Tests whether a name matches against at least one exclude pattern. | |||
* | |||
* @param name the name to match | |||
* @return <code>true</code> when the name matches against at least one | |||
* exclude pattern, <code>false</code> otherwise. | |||
*/ | |||
protected boolean isExcluded(String name) { | |||
for (int i = 0; i < excludes.length; i++) { | |||
if (matchPath(excludes[i],name)) { | |||
return true; | |||
} | |||
} | |||
return false; | |||
} | |||
/** | |||
* Adds the array with default exclusions to the current exclusions set. | |||
* | |||
*/ | |||
public void addDefaultExcludes() { | |||
int excludesLength = excludes == null ? 0 : excludes.length; | |||
String[] newExcludes; | |||
newExcludes = new String[excludesLength + DEFAULTEXCLUDES.length]; | |||
if (excludesLength > 0) { | |||
System.arraycopy(excludes,0,newExcludes,0,excludesLength); | |||
} | |||
for (int i = 0; i < DEFAULTEXCLUDES.length; i++) { | |||
newExcludes[i+excludesLength] = DEFAULTEXCLUDES[i].replace('/',File.separatorChar).replace('\\',File.separatorChar); | |||
} | |||
excludes = newExcludes; | |||
} | |||
} |
@@ -1,140 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.core.types; | |||
import org.apache.ant.core.execution.*; | |||
import java.io.*; | |||
/** | |||
* A DataType is an element which can register a named value in the | |||
* ExecutionFrame's context. | |||
* | |||
* @author <a href="mailto:conor@apache.org">Conor MacNeill</a> | |||
*/ | |||
public abstract class DataType extends AbstractTask { | |||
private String reference = null; | |||
private Object referencedObject = null; | |||
public void execute() throws ExecutionException { | |||
validate(); | |||
} | |||
protected void validate() throws ExecutionException { | |||
} | |||
/** | |||
* Creates an exception that indicates that refid has to be the | |||
* only attribute if it is set. | |||
*/ | |||
protected ExecutionException tooManyAttributes() { | |||
return new ExecutionException("You must not specify more than one attribute" + | |||
" when using refid" ); | |||
} | |||
/** | |||
* Creates an exception that indicates that this XML element must | |||
* not have child elements if the refid attribute is set. | |||
*/ | |||
protected ExecutionException noChildrenAllowed() { | |||
return new ExecutionException("You must not specify nested elements when using refid"); | |||
} | |||
/** | |||
* Creates an exception that indicates the user has generated a | |||
* loop of data types referencing each other. | |||
*/ | |||
protected ExecutionException circularReference() { | |||
return new ExecutionException("This data type contains a circular reference."); | |||
} | |||
/** | |||
* Makes this instance in effect a reference to another DataType | |||
* instance. | |||
*/ | |||
public void setRefid(String reference) throws ExecutionException { | |||
this.reference = reference; | |||
Object referencedObject = getTaskContext().getDataValue(reference); | |||
if (referencedObject == null) { | |||
throw new ExecutionException("Unable to locate the reference specified by refid '" + | |||
getReference() + "'"); | |||
} | |||
if (!this.getClass().isAssignableFrom(referencedObject.getClass())) { | |||
throw new ExecutionException("The object referenced by refid '" + | |||
getReference() + "' is not compatible with this element "); | |||
} | |||
} | |||
/** | |||
* Has the refid attribute of this element been set? | |||
*/ | |||
public boolean isReference() { | |||
return referencedObject != null; | |||
} | |||
protected Object getReferencedObject() throws ExecutionException { | |||
if (!isReference()) { | |||
throw new ExecutionException("You cannot get a referenced value from a data type " + | |||
"which does not have the refid attribute"); | |||
} | |||
return referencedObject; | |||
} | |||
protected String getReference() { | |||
return reference; | |||
} | |||
} |
@@ -1,266 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2000 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.core.types; | |||
import java.io.*; | |||
import java.util.*; | |||
import org.apache.ant.core.execution.*; | |||
/** | |||
* A DirectoryFileset is a fileset where the files come from a directory and | |||
* its subdirectories. | |||
*/ | |||
public class DirectoryScanner extends AbstractScanner { | |||
/** The directory which is the root of the search space. */ | |||
File basedir; | |||
/** | |||
* The files that where found and matched at least one includes, and matched | |||
* no excludes. | |||
*/ | |||
protected List filesIncluded; | |||
/** | |||
* The files that where found and did not match any includes. | |||
*/ | |||
protected List filesNotIncluded; | |||
/** | |||
* The files that where found and matched at least one includes, and also | |||
* matched at least one excludes. | |||
*/ | |||
protected List filesExcluded; | |||
/** | |||
* The directories that where found and matched at least one includes, and | |||
* matched no excludes. | |||
*/ | |||
protected List dirsIncluded; | |||
/** | |||
* The directories that where found and did not match any includes. | |||
*/ | |||
protected List dirsNotIncluded; | |||
/** | |||
* The files that where found and matched at least one includes, and also | |||
* matched at least one excludes. | |||
*/ | |||
protected List dirsExcluded; | |||
/** Map to map filenames to actual File objects */ | |||
private Map filenameMap = null; | |||
public DirectoryScanner(File basedir, List patternSets, | |||
boolean useDefaultExcludes) throws ExecutionException { | |||
super(patternSets, useDefaultExcludes); | |||
this.basedir = basedir; | |||
} | |||
public String[] getIncludedFiles() throws ExecutionException { | |||
if (filesIncluded == null) { | |||
scan(); | |||
} | |||
return (String[])filesIncluded.toArray(new String[0]); | |||
} | |||
/** | |||
* Scans the base directory for files that match at least one include | |||
* pattern, and don't match any exclude patterns. | |||
* | |||
* @throws ExecutionException when basedir was set incorrecly | |||
*/ | |||
public void scan() throws ExecutionException { | |||
if (basedir == null) { | |||
throw new ExecutionException("The directory to scan has not been set"); | |||
} | |||
if (!basedir.exists()) { | |||
throw new ExecutionException("basedir \"" + basedir | |||
+ "\" does not exist"); | |||
} | |||
if (!basedir.isDirectory()) { | |||
throw new ExecutionException("basedir \"" + basedir | |||
+ "\" is not a directory"); | |||
} | |||
filesIncluded = new ArrayList(); | |||
filesNotIncluded = new ArrayList(); | |||
filesExcluded = new ArrayList(); | |||
dirsIncluded = new ArrayList(); | |||
dirsNotIncluded = new ArrayList(); | |||
dirsExcluded = new ArrayList(); | |||
filenameMap = new HashMap(); | |||
String root = ""; | |||
String mappedRoot = mapName(root); | |||
filenameMap.put(mappedRoot, root); | |||
if (isIncluded(root)) { | |||
if (!isExcluded(root)) { | |||
dirsIncluded.add(mappedRoot); | |||
} else { | |||
dirsExcluded.add(mappedRoot); | |||
} | |||
} else { | |||
dirsNotIncluded.add(mappedRoot); | |||
} | |||
scandir(basedir, root, true); | |||
} | |||
/** | |||
* Scans the passed dir for files and directories. Found files and | |||
* directories are placed in their respective collections, based on the | |||
* matching of includes and excludes. When a directory is found, it is | |||
* scanned recursively. | |||
* | |||
* @param dir the directory to scan | |||
* @param vpath the path relative to the basedir (needed to prevent | |||
* problems with an absolute path when using dir) | |||
* | |||
* @see #filesIncluded | |||
* @see #filesNotIncluded | |||
* @see #filesExcluded | |||
* @see #dirsIncluded | |||
* @see #dirsNotIncluded | |||
* @see #dirsExcluded | |||
*/ | |||
protected void scandir(File dir, String vpath, boolean fast) | |||
throws ExecutionException { | |||
String[] newfiles = dir.list(); | |||
if (newfiles == null) { | |||
/* | |||
* two reasons are mentioned in the API docs for File.list | |||
* (1) dir is not a directory. This is impossible as | |||
* we wouldn't get here in this case. | |||
* (2) an IO error occurred (why doesn't it throw an exception | |||
* then???) | |||
*/ | |||
throw new ExecutionException ("IO error scanning directory " | |||
+ dir.getAbsolutePath()); | |||
} | |||
for (int i = 0; i < newfiles.length; i++) { | |||
String name = vpath+newfiles[i]; | |||
String mappedName = mapName(name); | |||
filenameMap.put(mappedName, name); | |||
File file = new File(dir,newfiles[i]); | |||
if (file.isDirectory()) { | |||
if (isIncluded(name)) { | |||
if (!isExcluded(name)) { | |||
dirsIncluded.add(mappedName); | |||
if (fast) { | |||
scandir(file, name+File.separator, fast); | |||
} | |||
} else { | |||
dirsExcluded.add(mappedName); | |||
} | |||
} else { | |||
dirsNotIncluded.add(mappedName); | |||
if (fast && couldHoldIncluded(name)) { | |||
scandir(file, name+File.separator, fast); | |||
} | |||
} | |||
if (!fast) { | |||
scandir(file, name+File.separator, fast); | |||
} | |||
} else if (file.isFile()) { | |||
if (isIncluded(name)) { | |||
if (!isExcluded(name)) { | |||
filesIncluded.add(mappedName); | |||
} else { | |||
filesExcluded.add(mappedName); | |||
} | |||
} else { | |||
filesNotIncluded.add(mappedName); | |||
} | |||
} | |||
} | |||
} | |||
private String mapName(String rawName) { | |||
return "bozo/" + rawName; | |||
} | |||
public File getLocalFile(String mappedName) throws ExecutionException { | |||
if (filesIncluded == null) { | |||
scan(); | |||
} | |||
String realName = (String)filenameMap.get(mappedName); | |||
if (realName == null) { | |||
throw new ExecutionException("\"" + mappedName + "\" was not included in the scan."); | |||
} | |||
return new File(basedir, realName); | |||
} | |||
public String toString() { | |||
try { | |||
String[] files = getIncludedFiles(); | |||
StringBuffer sb = new StringBuffer(); | |||
String lsep = System.getProperty("line.separator"); | |||
for (int i = 0; i < files.length; ++i) { | |||
sb.append(files[i]); | |||
sb.append(lsep); | |||
} | |||
return sb.toString(); | |||
} | |||
catch (ExecutionException e) { | |||
return "Fileset from \"" + basedir + "\""; | |||
} | |||
} | |||
} |
@@ -1,116 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2000 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.core.types; | |||
import org.apache.ant.core.execution.*; | |||
/** | |||
* Helper class for attributes that can only take one of a fixed list | |||
* of values. | |||
* | |||
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||
*/ | |||
public abstract class EnumeratedAttribute { | |||
/** The value of this attribute. */ | |||
private String value; | |||
/** | |||
* This is the only method a subclass needs to implement. | |||
* | |||
* @return an array holding all possible values of the enumeration. | |||
*/ | |||
public abstract String[] getValues(); | |||
/** | |||
* Set the value of the enumeration. | |||
* | |||
* Invoked by {@link org.apache.ant.core.execution.IntrospectionHelper IntrospectionHelper}. | |||
* | |||
* @param value the value of the enumeration | |||
* | |||
* @throws ExecutionException if the value is not value | |||
*/ | |||
public final void setValue(String value) throws ExecutionException { | |||
if (!containsValue(value)) { | |||
throw new ExecutionException(value + " is not a legal value for this attribute"); | |||
} | |||
this.value = value; | |||
} | |||
/** | |||
* Is this value included in the enumeration? | |||
*/ | |||
public final boolean containsValue(String value) { | |||
String[] values = getValues(); | |||
if (values == null || value == null) { | |||
return false; | |||
} | |||
for (int i = 0; i < values.length; i++) { | |||
if (value.equals(values[i])) { | |||
return true; | |||
} | |||
} | |||
return false; | |||
} | |||
/** | |||
* Retrieves the value. | |||
*/ | |||
public final String getValue() { | |||
return value; | |||
} | |||
} |
@@ -1,319 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2000 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.core.types; | |||
import java.util.*; | |||
import java.io.*; | |||
import java.net.URL; | |||
import org.apache.ant.core.execution.*; | |||
/** | |||
* Moved out of MatchingTask to make it a standalone object that could | |||
* be referenced (by scripts for example). | |||
* | |||
* @author Arnout J. Kuiper <a href="mailto:ajkuiper@wxs.nl">ajkuiper@wxs.nl</a> | |||
* @author Stefano Mazzocchi <a href="mailto:stefano@apache.org">stefano@apache.org</a> | |||
* @author Sam Ruby <a href="mailto:rubys@us.ibm.com">rubys@us.ibm.com</a> | |||
* @author Jon S. Stevens <a href="mailto:jon@clearink.com">jon@clearink.com</a> | |||
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||
*/ | |||
public class FileSet extends DataType { | |||
private FileSetScanner scanner = null; | |||
private PatternSet defaultPatterns = new PatternSet(); | |||
private List patternSets = new ArrayList(); | |||
/** | |||
* The dir attribute is set when you are generating the list of files | |||
* from a directory. | |||
*/ | |||
private File dir = null; | |||
/** The zipfile attribute is used when the source of files is a zip file */ | |||
private URL zipFile = null; | |||
/** | |||
* The filelist attribute is a file which contains a list of file names. It must be used | |||
* with the base attribute which indicates where the files are stored. | |||
*/ | |||
private URL fileList = null; | |||
/** | |||
* When using the filelist this attribute indicates the base location of the files in | |||
* the list. | |||
*/ | |||
private URL fileListBase = null; | |||
private boolean useDefaultExcludes = true; | |||
public FileSet() { | |||
patternSets.add(defaultPatterns); | |||
} | |||
/** | |||
* Makes this instance in effect a reference to another FileSet | |||
* instance. | |||
* | |||
* <p>You must not set another attribute or nest elements inside | |||
* this element if you make it a reference.</p> | |||
*/ | |||
public void setRefid(String reference) throws ExecutionException { | |||
if (dir != null || defaultPatterns.hasPatterns()) { | |||
throw tooManyAttributes(); | |||
} | |||
if (!(patternSets.size() == 1)) { | |||
throw noChildrenAllowed(); | |||
} | |||
super.setRefid(reference); | |||
} | |||
public void setDir(File dir) throws ExecutionException { | |||
if (isReference()) { | |||
throw tooManyAttributes(); | |||
} | |||
this.dir = dir; | |||
} | |||
public void setZipFile(URL zipFile) throws ExecutionException { | |||
if (isReference()) { | |||
throw tooManyAttributes(); | |||
} | |||
this.zipFile = zipFile; | |||
} | |||
public void setFileList(URL fileList) throws ExecutionException { | |||
if (isReference()) { | |||
throw tooManyAttributes(); | |||
} | |||
this.fileList = fileList; | |||
} | |||
public void setFileListBase(URL fileListBase) throws ExecutionException { | |||
if (isReference()) { | |||
throw tooManyAttributes(); | |||
} | |||
this.fileListBase = fileListBase; | |||
} | |||
public PatternSet createPatternSet() throws ExecutionException { | |||
if (isReference()) { | |||
throw noChildrenAllowed(); | |||
} | |||
PatternSet patternSet = new PatternSet(); | |||
patternSets.add(patternSet); | |||
return patternSet; | |||
} | |||
/** | |||
* add a name entry on the include list | |||
*/ | |||
public PatternSet.NameEntry createInclude() throws ExecutionException { | |||
if (isReference()) { | |||
throw noChildrenAllowed(); | |||
} | |||
return defaultPatterns.createInclude(); | |||
} | |||
/** | |||
* add a name entry on the exclude list | |||
*/ | |||
public PatternSet.NameEntry createExclude() throws ExecutionException { | |||
if (isReference()) { | |||
throw noChildrenAllowed(); | |||
} | |||
return defaultPatterns.createExclude(); | |||
} | |||
/** | |||
* Sets the set of include patterns. Patterns may be separated by a comma | |||
* or a space. | |||
* | |||
* @param includes the string containing the include patterns | |||
*/ | |||
public void setIncludes(String includes) throws ExecutionException { | |||
if (isReference()) { | |||
throw tooManyAttributes(); | |||
} | |||
defaultPatterns.setIncludes(includes); | |||
} | |||
/** | |||
* Sets the set of exclude patterns. Patterns may be separated by a comma | |||
* or a space. | |||
* | |||
* @param excludes the string containing the exclude patterns | |||
*/ | |||
public void setExcludes(String excludes) throws ExecutionException { | |||
if (isReference()) { | |||
throw tooManyAttributes(); | |||
} | |||
defaultPatterns.setExcludes(excludes); | |||
} | |||
/** | |||
* Sets the name of the file containing the includes patterns. | |||
* | |||
* @param incl The file to fetch the include patterns from. | |||
*/ | |||
public void setIncludesFile(URL incl) throws ExecutionException { | |||
if (isReference()) { | |||
throw tooManyAttributes(); | |||
} | |||
defaultPatterns.setIncludesFile(incl); | |||
} | |||
/** | |||
* Sets the name of the file containing the includes patterns. | |||
* | |||
* @param excl The file to fetch the exclude patterns from. | |||
*/ | |||
public void setExcludesFile(URL excl) throws ExecutionException { | |||
if (isReference()) { | |||
throw tooManyAttributes(); | |||
} | |||
defaultPatterns.setExcludesFile(excl); | |||
} | |||
/** | |||
* Sets whether default exclusions should be used or not. | |||
* | |||
* @param useDefaultExcludes "true"|"on"|"yes" when default exclusions | |||
* should be used, "false"|"off"|"no" when they | |||
* shouldn't be used. | |||
*/ | |||
public void setDefaultExcludes(boolean useDefaultExcludes) throws ExecutionException { | |||
if (isReference()) { | |||
throw tooManyAttributes(); | |||
} | |||
this.useDefaultExcludes = useDefaultExcludes; | |||
} | |||
protected FileSet getReferencedFileSet() throws ExecutionException { | |||
Object o = getReferencedObject(); | |||
if (!(o instanceof FileSet)) { | |||
throw new ExecutionException(getReference() + " doesn\'t denote a fileset");; | |||
} else { | |||
return (FileSet) o; | |||
} | |||
} | |||
public void validate() throws ExecutionException { | |||
if (dir != null) { | |||
// firstly validate that the other attributes are not set | |||
if (zipFile != null || fileList != null || fileListBase != null) { | |||
throw new ExecutionException("The 'dir' attribute may not be combined with any " | |||
+ "of the 'zipfile', 'filelist' and 'base' attributes"); | |||
} | |||
} | |||
else if (zipFile != null) { | |||
if (fileList != null || fileListBase != null) { | |||
throw new ExecutionException("The 'zipfile' attribute may not be combined with any " | |||
+ "of the 'dir', 'filelist' and 'base' attributes"); | |||
} | |||
} | |||
else if (fileList != null) { | |||
if (fileListBase == null) { | |||
throw new ExecutionException("A 'base' attribute is required when using the 'filelist' " | |||
+ "attribute"); | |||
} | |||
} | |||
else { | |||
throw new ExecutionException("You must specify one of the 'dir', 'zipfile', or 'filelist' " | |||
+ "attributes"); | |||
} | |||
} | |||
public FileSetScanner getScanner() throws ExecutionException { | |||
if (isReference()) { | |||
return getReferencedFileSet().getScanner(); | |||
} | |||
if (scanner != null) { | |||
return scanner; | |||
} | |||
// need to create the fileset info. For that we are going to need | |||
// to determine which type of FileSetInfo implementation we should use. | |||
if (dir != null) { | |||
scanner = new DirectoryScanner(dir, patternSets, useDefaultExcludes); | |||
} | |||
else if (zipFile != null) { | |||
} | |||
else if (fileList != null) { | |||
} | |||
else { | |||
} | |||
return scanner; | |||
} | |||
public String toString() { | |||
try { | |||
return getScanner().toString(); | |||
} | |||
catch (ExecutionException e) { | |||
return "FileSet"; | |||
} | |||
} | |||
} |
@@ -1,115 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2000 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.core.types; | |||
import java.io.*; | |||
import java.net.URL; | |||
import org.apache.ant.core.execution.*; | |||
/** | |||
* The FileSetInfo interface defines the result of applying filtering to | |||
* some base collection of files. Filtering involves both file exclusion | |||
* and file name mapping. | |||
* | |||
* FileSetInfo should be lazily evaluated to allow them to be defined before the | |||
* required files have been created. They should be evaluated at first use. | |||
*/ | |||
public interface FileSetScanner { | |||
/** | |||
* Get the included files after their file names have been mapped | |||
* | |||
* @return an array of strings, each one is the mapped name of a file. | |||
*/ | |||
String[] getIncludedFiles() throws ExecutionException ; | |||
// | |||
// /** | |||
// * Get directories included after their file names have been mapped | |||
// * | |||
// * @return an array of strings, each one is the mapped name of a file. | |||
// */ | |||
// String[] getIncludedDirectories(); | |||
// | |||
// /** | |||
// * Get a file for the content of the named included file. If the content | |||
// * is not stored in the local filesystem, a temporary file is created with the content. | |||
// * Callers should not rely on this file representing the actual location of the underlying | |||
// * data. | |||
// */ | |||
// File getContentFile(String mappedName); | |||
// | |||
// /** | |||
// * Get a URL for the content. The content may be cached on the local system and thus | |||
// * callers should not rely on the location | |||
// * | |||
// */ | |||
// URL getContentURL(String mappedName); | |||
// | |||
// /** | |||
// * Get an input stream to the content of the named entry of the fileset. | |||
// */ | |||
// InputStream getInputStream(String mappedName); | |||
// | |||
/** | |||
* Get a local file. | |||
* | |||
* This method returns a file pointing to the actual local filesystem file from | |||
* which the file content comes. If the file does not exist locally, a null is | |||
* returned. Note that due to name mapping, the actual file name may be different | |||
* from the mapped name. | |||
* | |||
* @return a file representing the mapped file in the local filesystem. | |||
*/ | |||
File getLocalFile(String mappedName) throws ExecutionException ; | |||
} |
@@ -1,373 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2000 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.core.types; | |||
import java.io.*; | |||
import java.util.*; | |||
import org.apache.ant.core.execution.*; | |||
import java.net.URL; | |||
/** | |||
* Named collection of include/exclude tags. | |||
* | |||
* @author Arnout J. Kuiper <a href="mailto:ajkuiper@wxs.nl">ajkuiper@wxs.nl</a> | |||
* @author Stefano Mazzocchi <a href="mailto:stefano@apache.org">stefano@apache.org</a> | |||
* @author Sam Ruby <a href="mailto:rubys@us.ibm.com">rubys@us.ibm.com</a> | |||
* @author Jon S. Stevens <a href="mailto:jon@clearink.com">jon@clearink.com</a> | |||
* @author <a href="mailto:stefan.bodewig@megabit.net">Stefan Bodewig</a> | |||
*/ | |||
public class PatternSet extends DataType { | |||
private boolean filesRead = false; | |||
private List includeList = new ArrayList(); | |||
private List excludeList = new ArrayList(); | |||
private URL includeFile = null; | |||
private URL excludeFile = null; | |||
/** | |||
* inner class to hold a name on list. "If" and "Unless" attributes | |||
* may be used to invalidate the entry based on the existence of a | |||
* property (typically set thru the use of the Available task). | |||
*/ | |||
public class NameEntry { | |||
private String name; | |||
// private String ifCond; | |||
// private String unlessCond; | |||
public void setName(String name) { | |||
this.name = name; | |||
} | |||
// public void setIf(String cond) { | |||
// ifCond = cond; | |||
// } | |||
// | |||
// public void setUnless(String cond) { | |||
// unlessCond = cond; | |||
// } | |||
// | |||
public String getName() { | |||
return name; | |||
} | |||
// public String evalName(Project p) { | |||
// return valid(p) ? name : null; | |||
// } | |||
// private boolean valid(Project p) { | |||
// if (ifCond != null && p.getProperty(ifCond) == null) { | |||
// return false; | |||
// } else if (unlessCond != null && p.getProperty(unlessCond) != null) { | |||
// return false; | |||
// } | |||
// return true; | |||
// } | |||
} | |||
/** | |||
* Makes this instance in effect a reference to another PatternSet | |||
* instance. | |||
* | |||
* <p>You must not set another attribute or nest elements inside | |||
* this element if you make it a reference.</p> | |||
*/ | |||
public void setRefid(String reference) throws ExecutionException { | |||
if (!includeList.isEmpty() || !excludeList.isEmpty()) { | |||
throw tooManyAttributes(); | |||
} | |||
super.setRefid(reference); | |||
} | |||
/** | |||
* add a name entry on the include list | |||
*/ | |||
public NameEntry createInclude() throws ExecutionException { | |||
if (isReference()) { | |||
throw noChildrenAllowed(); | |||
} | |||
return addPatternToList(includeList); | |||
} | |||
/** | |||
* add a name entry on the exclude list | |||
*/ | |||
public NameEntry createExclude() throws ExecutionException { | |||
if (isReference()) { | |||
throw noChildrenAllowed(); | |||
} | |||
return addPatternToList(excludeList); | |||
} | |||
/** | |||
* Sets the set of include patterns. Patterns may be separated by a comma | |||
* or a space. | |||
* | |||
* @param includes the string containing the include patterns | |||
*/ | |||
public void setIncludes(String includes) throws ExecutionException { | |||
if (isReference()) { | |||
throw tooManyAttributes(); | |||
} | |||
if (includes != null && includes.length() > 0) { | |||
StringTokenizer tok = new StringTokenizer(includes, ", ", false); | |||
while (tok.hasMoreTokens()) { | |||
createInclude().setName(tok.nextToken()); | |||
} | |||
} | |||
} | |||
/** | |||
* Sets the set of exclude patterns. Patterns may be separated by a comma | |||
* or a space. | |||
* | |||
* @param excludes the string containing the exclude patterns | |||
*/ | |||
public void setExcludes(String excludes) throws ExecutionException { | |||
if (isReference()) { | |||
throw tooManyAttributes(); | |||
} | |||
if (excludes != null && excludes.length() > 0) { | |||
StringTokenizer tok = new StringTokenizer(excludes, ", ", false); | |||
while (tok.hasMoreTokens()) { | |||
createExclude().setName(tok.nextToken()); | |||
} | |||
} | |||
} | |||
/** | |||
* add a name entry to the given list | |||
*/ | |||
private NameEntry addPatternToList(List list) { | |||
NameEntry result = new NameEntry(); | |||
list.add(result); | |||
return result; | |||
} | |||
/** | |||
* Sets the name of the file containing the includes patterns. | |||
* | |||
* @param incl The file to fetch the include patterns from. | |||
*/ | |||
public void setIncludesFile(URL includeFile) throws ExecutionException { | |||
if (isReference()) { | |||
throw tooManyAttributes(); | |||
} | |||
// if (!incl.exists()) { | |||
// throw new BuildException("Includesfile "+incl.getAbsolutePath() | |||
// +" not found."); | |||
// } | |||
this.includeFile = includeFile; | |||
} | |||
/** | |||
* Sets the name of the file containing the excludes patterns. | |||
* | |||
* @param excludeFile The file to fetch the exclude patterns from. | |||
*/ | |||
public void setExcludesFile(URL excludeFile) throws ExecutionException { | |||
if (isReference()) { | |||
throw tooManyAttributes(); | |||
} | |||
// if (!excl.exists()) { | |||
// throw new BuildException("Excludesfile "+excl.getAbsolutePath() | |||
// +" not found."); | |||
// } | |||
this.excludeFile = excludeFile; | |||
} | |||
/** | |||
* Reads path matching patterns from a file and adds them to the | |||
* includes or excludes list (as appropriate). | |||
*/ | |||
private void readPatterns(URL patternFile, List patternList) | |||
throws ExecutionException { | |||
BufferedReader patternReader = null; | |||
try { | |||
// Get a FileReader | |||
patternReader = | |||
new BufferedReader(new InputStreamReader(patternFile.openStream())); | |||
// Create one NameEntry in the appropriate pattern list for each | |||
// line in the file. | |||
String line = null; | |||
while ((line = patternReader.readLine()) != null) { | |||
if (line.length() > 0) { | |||
line = getTaskContext().replacePropertyRefs(line); | |||
addPatternToList(patternList).setName(line); | |||
} | |||
} | |||
} catch(IOException ioe) { | |||
throw new ExecutionException("An error occured while reading from pattern file: " | |||
+ patternFile, ioe); | |||
} | |||
finally { | |||
if (patternReader != null) { | |||
try { | |||
patternReader.close(); | |||
} | |||
catch (IOException e) { | |||
// do nothing | |||
} | |||
} | |||
} | |||
} | |||
/** | |||
* Adds the patterns of the other instance to this set. | |||
*/ | |||
public void append(PatternSet other) throws ExecutionException { | |||
if (isReference()) { | |||
throw new ExecutionException("Cannot append to a reference"); | |||
} | |||
String[] incl = other.getIncludePatterns(); | |||
if (incl != null) { | |||
for (int i=0; i<incl.length; i++) { | |||
createInclude().setName(incl[i]); | |||
} | |||
} | |||
String[] excl = other.getExcludePatterns(); | |||
if (excl != null) { | |||
for (int i=0; i<excl.length; i++) { | |||
createExclude().setName(excl[i]); | |||
} | |||
} | |||
} | |||
/** | |||
* Returns the filtered include patterns. | |||
*/ | |||
public String[] getIncludePatterns() throws ExecutionException { | |||
if (isReference()) { | |||
return getReferencedPatternSet().getIncludePatterns(); | |||
} else { | |||
readFiles(); | |||
return makeArray(includeList); | |||
} | |||
} | |||
/** | |||
* Returns the filtered include patterns. | |||
*/ | |||
public String[] getExcludePatterns() throws ExecutionException { | |||
if (isReference()) { | |||
return getReferencedPatternSet().getExcludePatterns(); | |||
} else { | |||
readFiles(); | |||
return makeArray(excludeList); | |||
} | |||
} | |||
/** | |||
* helper for FileSet. | |||
*/ | |||
boolean hasPatterns() { | |||
return includeFile != null || excludeFile != null | |||
|| includeList.size() > 0 || excludeList.size() > 0; | |||
} | |||
/** | |||
* Performs the check for circular references and returns the | |||
* referenced PatternSet. | |||
*/ | |||
private PatternSet getReferencedPatternSet() throws ExecutionException { | |||
Object o = getReferencedObject(); | |||
if (!(o instanceof PatternSet)) { | |||
throw new ExecutionException(getReference() + " doesn\'t denote a patternset");; | |||
} else { | |||
return (PatternSet) o; | |||
} | |||
} | |||
/** | |||
* Convert a list of NameEntry elements into an array of Strings. | |||
*/ | |||
private String[] makeArray(List list) { | |||
if (list.size() == 0) { | |||
return null; | |||
} | |||
List tmpNames = new Vector(); | |||
for (Iterator i = list.iterator() ; i.hasNext() ;) { | |||
NameEntry ne = (NameEntry)i.next(); | |||
String pattern = ne.getName(); | |||
if (pattern != null && pattern.length() > 0) { | |||
tmpNames.add(pattern); | |||
} | |||
} | |||
String[] result = (String[])tmpNames.toArray(new String[0]); | |||
return result; | |||
} | |||
/** | |||
* Read includefile ot excludefile if not already done so. | |||
*/ | |||
private void readFiles() throws ExecutionException { | |||
if (!filesRead) { | |||
filesRead = true; | |||
if (includeFile != null) { | |||
readPatterns(includeFile, includeList); | |||
} | |||
if (excludeFile != null) { | |||
readPatterns(excludeFile, excludeList); | |||
} | |||
} | |||
} | |||
} |
@@ -1,285 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.core.xml; | |||
import java.io.*; | |||
import java.net.MalformedURLException; | |||
import java.net.URL; | |||
import java.util.*; | |||
import javax.xml.parsers.*; | |||
import org.apache.ant.core.support.*; | |||
import org.apache.ant.core.execution.*; | |||
import org.xml.sax.*; | |||
import org.xml.sax.helpers.DefaultHandler; | |||
/** | |||
* Parses the TASK-INF/antlib.xml file of an ant library | |||
* component. An Ant library may contains tasks, apsects and | |||
* other ant plug in components | |||
*/ | |||
public class AntLibParser { | |||
public static final String TASK_ELEMENT = "taskdef"; | |||
public static final String CONVERTER_ELEMENT = "converter"; | |||
public static final String ASPECT_ELEMENT = "aspect"; | |||
/** | |||
* The factory used to create SAX parsers. | |||
*/ | |||
private SAXParserFactory parserFactory; | |||
/** | |||
* Parse the library definition | |||
* | |||
* @param libSource the URL from where the library XML is read. | |||
* | |||
* @throws SAXParseException if there is a problem parsing the task definitions | |||
*/ | |||
public AntLibrary parseAntLibrary(URL libSource, ClassLoader componentLoader) | |||
throws ConfigException { | |||
try { | |||
parserFactory = SAXParserFactory.newInstance(); | |||
SAXParser saxParser = parserFactory.newSAXParser(); | |||
XMLReader xmlReader = saxParser.getXMLReader(); | |||
AntLibRootHandler rootHandler = new AntLibRootHandler(libSource, xmlReader, componentLoader); | |||
saxParser.parse(libSource.toString(), rootHandler); | |||
return rootHandler.getAntLibrary(); | |||
} | |||
catch (SAXParseException e) { | |||
throw new ConfigException(e.getMessage(), e, | |||
new Location(libSource.toString(), | |||
e.getLineNumber(), e.getColumnNumber())); | |||
} | |||
catch (ParserConfigurationException e) { | |||
throw new ConfigException("Unable to parse Ant library component", e, | |||
new Location(libSource.toString())); | |||
} | |||
catch (SAXException e) { | |||
throw new ConfigException("Unable to parse Ant library component", e, | |||
new Location(libSource.toString())); | |||
} | |||
catch (IOException e) { | |||
throw new ConfigException("Unable to parse Ant library component", e, | |||
new Location(libSource.toString())); | |||
} | |||
} | |||
/** | |||
* The root handler handles the antlib element. An ant lib may | |||
* contain a number of different types of elements | |||
* <ul> | |||
* <li>taskdef</li> | |||
* <li>aspect</li> | |||
* <li>converter</li> | |||
* </ul> | |||
*/ | |||
private class AntLibRootHandler extends RootHandler { | |||
static private final int STATE_LOOKING_FOR_ROOT = 1; | |||
static private final int STATE_ROOT_SEEN = 2; | |||
static private final int STATE_FINISHED = 3; | |||
private int state = STATE_LOOKING_FOR_ROOT; | |||
/** | |||
* The AntLibrary that will be defined by parsing the library's definition | |||
* file. | |||
*/ | |||
private AntLibrary library = null; | |||
private ClassLoader componentLoader = null; | |||
/** | |||
* Create an Ant Library Root Handler. | |||
* | |||
* @param taskdefSource the URL from where the task definitions exist | |||
* @param reader the XML parser. | |||
*/ | |||
public AntLibRootHandler(URL taskdefSource, XMLReader reader, ClassLoader componentLoader) { | |||
super(taskdefSource, reader); | |||
this.componentLoader = componentLoader; | |||
} | |||
/** | |||
* Get the library which has been parsed. | |||
* | |||
* @return an AntLibary with the library definitions | |||
*/ | |||
public AntLibrary getAntLibrary() { | |||
return library; | |||
} | |||
/** | |||
* Start a new element in the root. This must be a taskdefs element | |||
* All other elements are invalid. | |||
* | |||
* @param uri The Namespace URI. | |||
* @param localName The local name (without prefix). | |||
* @param qualifiedName The qualified name (with prefix) | |||
* @param attributes The attributes attached to the element. | |||
* | |||
* @throws SAXParseException if there is a parsing problem. | |||
*/ | |||
public void startElement(String uri, String localName, String qualifiedName, | |||
Attributes attributes) throws SAXParseException { | |||
switch (state) { | |||
case STATE_LOOKING_FOR_ROOT: | |||
if (qualifiedName.equals("antlib")) { | |||
state = STATE_ROOT_SEEN; | |||
library = new AntLibrary(); | |||
} | |||
else { | |||
throw new SAXParseException("An Ant library component must start with an " + | |||
"<antlib> element and not with <" + | |||
qualifiedName + ">", getLocator()); | |||
} | |||
break; | |||
case STATE_ROOT_SEEN: | |||
if (qualifiedName.equals(TASK_ELEMENT)) { | |||
createTaskDef(attributes); | |||
} | |||
else if (qualifiedName.equals(CONVERTER_ELEMENT)) { | |||
createConverterDef(attributes); | |||
} | |||
else if (qualifiedName.equals(ASPECT_ELEMENT)) { | |||
createAspectHandler(attributes); | |||
} | |||
else { | |||
throw new SAXParseException("Unrecognized element <" + | |||
qualifiedName + "> in Ant library definition", getLocator()); | |||
} | |||
break; | |||
} | |||
} | |||
public void createTaskDef(Attributes attributes) throws SAXParseException { | |||
Set validAttributes = new HashSet(); | |||
validAttributes.add("name"); | |||
validAttributes.add("classname"); | |||
Map attributeValues | |||
= AttributeValidator.validateAttributes(TASK_ELEMENT, attributes, | |||
validAttributes, getLocator()); | |||
String taskName = (String)attributeValues.get("name"); | |||
String className = (String)attributeValues.get("classname"); | |||
if (taskName == null) { | |||
throw new SAXParseException("'name' attribute is required in a <" | |||
+ TASK_ELEMENT + "> element", | |||
getLocator()); | |||
} | |||
if (className == null) { | |||
throw new SAXParseException("'classname' attribute is required in a " + | |||
"<" + TASK_ELEMENT + "> element", getLocator()); | |||
} | |||
TaskDefinition taskdef = new TaskDefinition(getSourceURL(), taskName, className, componentLoader); | |||
library.addTaskDefinition(taskdef); | |||
} | |||
public void createConverterDef(Attributes attributes) throws SAXParseException { | |||
Set validAttributes = new HashSet(); | |||
validAttributes.add("target"); | |||
validAttributes.add("classname"); | |||
Map attributeValues | |||
= AttributeValidator.validateAttributes(CONVERTER_ELEMENT, attributes, | |||
validAttributes, getLocator()); | |||
String targetClassName = (String)attributeValues.get("target"); | |||
String className = (String)attributeValues.get("classname"); | |||
if (targetClassName == null) { | |||
throw new SAXParseException("'target' attribute is required in a <" | |||
+ CONVERTER_ELEMENT + "> element", | |||
getLocator()); | |||
} | |||
if (className == null) { | |||
throw new SAXParseException("'classname' attribute is required in a " + | |||
"<" + CONVERTER_ELEMENT + "> element", getLocator()); | |||
} | |||
ConverterDefinition converterDef | |||
= new ConverterDefinition(getSourceURL(), className, targetClassName, componentLoader); | |||
library.addConverterDefinition(converterDef); | |||
} | |||
public void createAspectHandler(Attributes attributes) throws SAXParseException { | |||
Set validAttributes = new HashSet(); | |||
validAttributes.add("prefix"); | |||
validAttributes.add("classname"); | |||
Map attributeValues | |||
= AttributeValidator.validateAttributes(ASPECT_ELEMENT, attributes, | |||
validAttributes, getLocator()); | |||
String aspectPrefix = (String)attributeValues.get("prefix"); | |||
String aspectClassname = (String)attributeValues.get("classname"); | |||
if (aspectPrefix == null) { | |||
throw new SAXParseException("'prefix' attribute is required in a <" | |||
+ ASPECT_ELEMENT + "> element", | |||
getLocator()); | |||
} | |||
if (aspectClassname == null) { | |||
throw new SAXParseException("'classname' attribute is required in a " + | |||
"<" + ASPECT_ELEMENT + "> element", getLocator()); | |||
} | |||
AspectDefinition aspectDef | |||
= new AspectDefinition(getSourceURL(), aspectPrefix, aspectClassname, componentLoader); | |||
library.addAspectDefinition(aspectDef); | |||
} | |||
public void endElement(String namespaceURI, String localName, String qName) { | |||
if (state == STATE_ROOT_SEEN && qName.equals("antlib")) { | |||
state = STATE_FINISHED; | |||
} | |||
} | |||
} | |||
} | |||
@@ -1,112 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.core.xml; | |||
import org.xml.sax.helpers.DefaultHandler; | |||
import org.xml.sax.*; | |||
import java.util.*; | |||
/** | |||
* Validates and extracts attribute values from a set of element attributes. | |||
* | |||
* @author <a href="mailto:conor@apache.org">Conor MacNeill</a> | |||
*/ | |||
public abstract class AttributeValidator { | |||
static public Map validateAttributes(String elementName, Attributes attributes, | |||
Set validAttributes, Locator locator) | |||
throws SAXParseException { | |||
return validateAttributes(elementName, attributes, null, validAttributes, locator); | |||
} | |||
static public Map validateAttributes(String elementName, Attributes attributes, Map aspects, | |||
Set validAttributes, Locator locator) | |||
throws SAXParseException { | |||
Map attributeValues = new HashMap(); | |||
Set invalidAttributes = new HashSet(); | |||
for (int i = 0; i < attributes.getLength(); ++i) { | |||
String attributeName = attributes.getQName(i); | |||
String attributeValue = attributes.getValue(i); | |||
if (validAttributes.contains(attributeName)) { | |||
attributeValues.put(attributeName, attributeValue); | |||
} | |||
else if (aspects != null && attributeName.indexOf(":") != -1) { | |||
aspects.put(attributeName, attributeValue); | |||
} | |||
else { | |||
invalidAttributes.add(attributeName); | |||
} | |||
} | |||
if (invalidAttributes.size() != 0) { | |||
StringBuffer message = new StringBuffer(); | |||
boolean justOne = invalidAttributes.size() == 1; | |||
message.append(justOne ? "The attribute " : "The attributes "); | |||
for (Iterator i = invalidAttributes.iterator(); i.hasNext();) { | |||
String attributeName = (String)i.next(); | |||
message.append(attributeName + " "); | |||
} | |||
message.append(justOne ? "is " : "are "); | |||
message.append("not valid for the <" + elementName + "> element."); | |||
throw new SAXParseException(message.toString(), locator); | |||
} | |||
return attributeValues; | |||
} | |||
} |
@@ -1,109 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.core.xml; | |||
import org.xml.sax.helpers.DefaultHandler; | |||
import org.xml.sax.*; | |||
/** | |||
* An Element Handler is a handler which handles a single element by becoming | |||
* the handler for the parser while processing the element. Any sub elements | |||
* must be delegated to separate handlers. When this element is finished, | |||
* control returns to the parent handler. | |||
*/ | |||
public abstract class ElementHandler extends DefaultHandler { | |||
private XMLReader reader; | |||
private ContentHandler parent; | |||
private Locator locator; | |||
public ElementHandler(XMLReader reader, ContentHandler parent, | |||
Locator locator) { | |||
this.reader = reader; | |||
this.parent = parent; | |||
this.locator = locator; | |||
reader.setContentHandler(this); | |||
} | |||
/** | |||
* This element is finished - complete any necessary processing. | |||
*/ | |||
protected void finish() { | |||
} | |||
/** | |||
* Get the XML Reader being used to parse the XML. | |||
* | |||
* @return the XML Reader. | |||
*/ | |||
protected XMLReader getXMLReader() { | |||
return reader; | |||
} | |||
/** | |||
* Get the locator used to locate elements in the XML source as | |||
* they are parsed. | |||
* | |||
* @return the locator object which can be used to determine an elements location | |||
* within the XML source | |||
*/ | |||
protected Locator getLocator() { | |||
return locator; | |||
} | |||
public void endElement(String namespaceURI, String localName, String qName) { | |||
finish(); | |||
reader.setContentHandler(parent); | |||
} | |||
} |
@@ -1,131 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.core.xml; | |||
import org.xml.sax.helpers.DefaultHandler; | |||
import org.xml.sax.*; | |||
import java.net.URL; | |||
/** | |||
* Handle the root of a XML parse | |||
*/ | |||
public abstract class RootHandler extends DefaultHandler { | |||
/** | |||
* Locator used to identify where in the build source particular elements | |||
* occur. | |||
*/ | |||
private Locator locator; | |||
/** | |||
* The actual XML parser used to parse the build source | |||
*/ | |||
private XMLReader reader; | |||
/** | |||
* The URL from which the XML source is being read. | |||
*/ | |||
private URL sourceURL; | |||
/** | |||
* Create a Root Handler. | |||
* | |||
* @param sourceURL the URL containing the XML source | |||
* @param reader the XML parser. | |||
*/ | |||
public RootHandler(URL sourceURL, XMLReader reader) { | |||
this.sourceURL = sourceURL; | |||
this.reader = reader; | |||
} | |||
/** | |||
* Set the locator to use when parsing elements. This is passed onto | |||
* child elements. | |||
* | |||
* @param locator the locator for locating elements in the build source. | |||
*/ | |||
public void setDocumentLocator(Locator locator) { | |||
this.locator = locator; | |||
} | |||
/** | |||
* Get the XML Reader being used to parse the XML. | |||
* | |||
* @return the XML Reader. | |||
*/ | |||
protected XMLReader getXMLReader() { | |||
return reader; | |||
} | |||
/** | |||
* Get the locator used to locate elements in the XML source as | |||
* they are parsed. | |||
* | |||
* @return the locator object which can be used to determine an elements location | |||
* within the XML source | |||
*/ | |||
protected Locator getLocator() { | |||
return locator; | |||
} | |||
/** | |||
* Get the source URL | |||
* | |||
* @return a URL identifiying from where the XML is being read. | |||
*/ | |||
public URL getSourceURL() { | |||
return sourceURL; | |||
} | |||
} | |||
@@ -1,831 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.core.xml; | |||
import java.io.*; | |||
import java.net.MalformedURLException; | |||
import java.net.URL; | |||
import java.util.*; | |||
import javax.xml.parsers.*; | |||
import org.apache.ant.core.model.*; | |||
import org.apache.ant.core.support.*; | |||
import org.xml.sax.*; | |||
import org.xml.sax.helpers.DefaultHandler; | |||
/** | |||
* Parses a project from an XML source using a SAX Parser. | |||
* | |||
* @author <a href="mailto:conor@apache.org">Conor MacNeill</a> | |||
*/ | |||
public class XMLProjectParser { | |||
private Stack recursionCheck = new Stack(); | |||
/** | |||
* The factory used to create SAX parsers. | |||
*/ | |||
private SAXParserFactory parserFactory; | |||
static private Location getLocation(Locator locator) { | |||
return new Location(locator.getSystemId(), locator.getLineNumber(), | |||
locator.getColumnNumber()); | |||
} | |||
/** | |||
* Parse a build file form the given URL. | |||
* | |||
* @param buildSource the URL from where the build source may be read. | |||
* | |||
* @throws SAXParseException if there is a problem parsing the build file. | |||
*/ | |||
public Project parseBuildFile(URL buildSource) | |||
throws ConfigException { | |||
try { | |||
parserFactory = SAXParserFactory.newInstance(); | |||
SAXParser saxParser = parserFactory.newSAXParser(); | |||
XMLReader xmlReader = saxParser.getXMLReader(); | |||
recursionCheck.push(buildSource); | |||
ProjectRootHandler projectRootHandler | |||
= new ProjectRootHandler(buildSource, xmlReader); | |||
saxParser.parse(buildSource.toString(), projectRootHandler); | |||
return projectRootHandler.getProject(); | |||
} | |||
catch (SAXParseException e) { | |||
throw new ConfigException(e.getMessage(), e, | |||
new Location(buildSource.toString(), | |||
e.getLineNumber(), e.getColumnNumber())); | |||
} | |||
catch (NoProjectReadException e) { | |||
throw new ConfigException("No project defined in build source", e, | |||
new Location(buildSource.toString())); | |||
} | |||
catch (ParserConfigurationException e) { | |||
throw new ConfigException("Unable to parse project: " + e.getMessage(), e, | |||
new Location(buildSource.toString())); | |||
} | |||
catch (SAXException e) { | |||
throw new ConfigException("Unable to parse project: " + e.getMessage(), e, | |||
new Location(buildSource.toString())); | |||
} | |||
catch (IOException e) { | |||
throw new ConfigException("Unable to parse project: " + e.getMessage(), e, | |||
new Location(buildSource.toString())); | |||
} | |||
} | |||
/** | |||
* The root handler handles the start of parsing. This element looks for the | |||
* root element which must be a project element. It then delegates handling of the | |||
* project element to a project handler from which it extracts the parsed project. | |||
*/ | |||
private class ProjectRootHandler extends RootHandler { | |||
/** | |||
* The project handler created to parse the project element. | |||
*/ | |||
ProjectHandler projectHandler; | |||
/** | |||
* Create a Root Handler. | |||
* | |||
* @param buildSource the URL containing the build definition | |||
* @param reader the XML parser. | |||
*/ | |||
public ProjectRootHandler(URL buildSource, XMLReader reader) { | |||
super(buildSource, reader); | |||
} | |||
/** | |||
* Start a new element in the root. This must be a project element | |||
* All other elements are invalid. | |||
* | |||
* @param uri The Namespace URI. | |||
* @param localName The local name (without prefix). | |||
* @param qualifiedName The qualified name (with prefix) | |||
* @param attributes The attributes attached to the element. | |||
* | |||
* @throws SAXParseException if there is a parsing problem. | |||
*/ | |||
public void startElement(String uri, String localName, String qualifiedName, | |||
Attributes attributes) throws SAXParseException { | |||
if (qualifiedName.equals("project")) { | |||
projectHandler = new ProjectHandler(getXMLReader(), this, | |||
getLocator(), attributes, getSourceURL()); | |||
} else { | |||
throw new SAXParseException("Build file should start with a <project> element not <" + | |||
qualifiedName + ">", getLocator()); | |||
} | |||
} | |||
/** | |||
* Get the project that has been parsed from the element | |||
* | |||
* @return the project that has been parsed from the build osurce | |||
* | |||
* @throws NoProjectReadException thrown if no project was read in. | |||
*/ | |||
public Project getProject() throws NoProjectReadException { | |||
if (projectHandler == null) { | |||
throw new NoProjectReadException(); | |||
} | |||
return projectHandler.getProject(); | |||
} | |||
} | |||
/** | |||
* Root Handler for include elements. | |||
* | |||
* Includes must contain either a project (which is being extended) or | |||
* a fragment element which contains the fragment to be included. | |||
*/ | |||
private class IncludeRootHandler extends RootHandler { | |||
/** | |||
* The project into which the fragment is to be included. | |||
*/ | |||
private Project project; | |||
/** | |||
* Create an Include Root Handler. | |||
* | |||
* @param buildSource the URL containing the fragment definition | |||
* @param reader the XML parser. | |||
* @param project the project into which the fragment's elements will be included. | |||
*/ | |||
public IncludeRootHandler(URL buildSource, XMLReader reader, Project project) { | |||
super(buildSource, reader); | |||
this.project = project; | |||
} | |||
/** | |||
* Start a new element in the include root. This must be a project element | |||
* or a fragment element. All other elements are invalid. | |||
* | |||
* @param uri The Namespace URI. | |||
* @param localName The local name (without prefix). | |||
* @param qualifiedName The qualified name (with prefix) | |||
* @param attributes The attributes attached to the element. | |||
* | |||
* @throws SAXParseException if there is a parsing problem. | |||
*/ | |||
public void startElement(String uri, String localName, String qualifiedName, | |||
Attributes attributes) throws SAXParseException { | |||
if (qualifiedName.equals("project") || | |||
qualifiedName.equals("fragment")) { | |||
// if it is a fragment, it must have no attributes | |||
// any project attributes are ignored | |||
if (qualifiedName.equals("fragment") && attributes.getLength() != 0) { | |||
throw new SAXParseException("<fragment> element may not have any attributes", | |||
getLocator()); | |||
} | |||
new ProjectHandler(getXMLReader(), this, getLocator(), | |||
getSourceURL(), project); | |||
} else { | |||
throw new SAXParseException("An included file should contain either a " + | |||
"<project> or <fragment> element and not a <" + | |||
qualifiedName + "> element", getLocator()); | |||
} | |||
} | |||
} | |||
/** | |||
* Element to parse the project element. | |||
* | |||
* The project handler creates a number of different handlers to which it | |||
* delegates processing of child elements. | |||
*/ | |||
private class ProjectHandler extends ElementHandler { | |||
/** | |||
* The project being parsed. | |||
*/ | |||
private Project project; | |||
/** | |||
* The sourceURL for the current content being added to the project. | |||
*/ | |||
private URL sourceURL; | |||
/** | |||
* Create a ProjectHandler to read in a complete project. | |||
* | |||
* @param xmlReader the XML parser being used to parse the project element. | |||
* @param parent the parent element handler. | |||
* @param locator the SAX locator object used to associate elements with source | |||
* locations. | |||
* @param attributes the project element's attributes. | |||
* @param projectSource the URL from which the XML source is being parsed. | |||
*/ | |||
public ProjectHandler(XMLReader xmlReader, ContentHandler parent, | |||
Locator locator, Attributes attributes, URL projectSource) | |||
throws SAXParseException { | |||
super(xmlReader, parent, locator); | |||
this.sourceURL = projectSource; | |||
project = new Project(projectSource, getLocation(locator)); | |||
String base = null; | |||
String defaultTarget = null; | |||
String projectName = null; | |||
Map aspects = new HashMap(); | |||
for (int i = 0; i < attributes.getLength(); ++i) { | |||
String attributeName = attributes.getQName(i); | |||
String attributeValue = attributes.getValue(i); | |||
if (attributeName.equals("base")) { | |||
base = attributeValue; | |||
} | |||
else if (attributeName.equals("default")) { | |||
defaultTarget = attributeValue; | |||
} | |||
else if (attributeName.equals("name")) { | |||
projectName = attributeValue; | |||
} | |||
else if (attributeName.indexOf(":") != -1) { | |||
// potential aspect attribute | |||
aspects.put(attributeName, attributeValue); | |||
} | |||
else { | |||
throw new SAXParseException("The attribute '" + attributeName + "' is not " + | |||
"supported by the <project> element", getLocator()); | |||
} | |||
} | |||
project.setDefaultTarget(defaultTarget); | |||
project.setBase(base); | |||
project.setName(projectName); | |||
project.setAspects(aspects); | |||
} | |||
/** | |||
* Create a Project handler for an included fragment. The elements | |||
* from the fragment are added to the given project. | |||
* | |||
* @param xmlReader the XML parser being used to parse the project element. | |||
* @param parent the parent element handler. | |||
* @param locator the SAX locator object used to associate elements with source | |||
* locations. | |||
* @param includeSource the URL from which the XML source is being included. | |||
* @param project the project to which the included fragments elements are added. | |||
*/ | |||
public ProjectHandler(XMLReader xmlReader, ContentHandler parent, | |||
Locator locator, URL includeSource, Project project) { | |||
super(xmlReader, parent, locator); | |||
this.sourceURL = includeSource; | |||
this.project = project; | |||
} | |||
/** | |||
* Start a new element in the project. Project currently handle the | |||
* following elements | |||
* <ul> | |||
* <li>import</li> | |||
* <li>include</li> | |||
* <li>target</li> | |||
* </ul> | |||
* | |||
* Everything else is treated as a task. | |||
* | |||
* @param uri The Namespace URI. | |||
* @param localName The local name (without prefix). | |||
* @param qualifiedName The qualified name (with prefix) | |||
* @param attributes The attributes attached to the element. | |||
* | |||
* @throws SAXParseException if there is a parsing problem. | |||
*/ | |||
public void startElement(String uri, String localName, String qualifiedName, | |||
Attributes attributes) throws SAXParseException { | |||
if (qualifiedName.equals("import")) { | |||
ImportHandler importHandler | |||
= new ImportHandler(getXMLReader(), this, getLocator(), | |||
attributes, sourceURL); | |||
try { | |||
project.importProject(importHandler.getImportName(), | |||
importHandler.getImportedProject()); | |||
} | |||
catch (ProjectModelException e) { | |||
throw new SAXParseException(e.getMessage(), getLocator(), e); | |||
} | |||
} | |||
else if (qualifiedName.equals("include")) { | |||
IncludeHandler includeHandler | |||
= new IncludeHandler(getXMLReader(), this, getLocator(), | |||
attributes, sourceURL, project); | |||
} | |||
else if (qualifiedName.equals("target")) { | |||
TargetHandler targetHandler | |||
= new TargetHandler(getXMLReader(), this, getLocator(), attributes); | |||
try { | |||
project.addTarget(targetHandler.getTarget()); | |||
} | |||
catch (ProjectModelException e) { | |||
throw new SAXParseException(e.getMessage(), getLocator(), e); | |||
} | |||
} | |||
else { | |||
// everything else is a task | |||
TaskElementHandler taskElementHandler | |||
= new TaskElementHandler(getXMLReader(), this, getLocator(), | |||
attributes, qualifiedName); | |||
project.addTask(taskElementHandler.getTaskElement()); | |||
} | |||
} | |||
/** | |||
* Get the project that has been parsed from the XML source | |||
* | |||
* @return the project model of the parsed project. | |||
*/ | |||
public Project getProject() { | |||
return project; | |||
} | |||
} | |||
/** | |||
* The import handler handles the importing of one project into another. | |||
* | |||
* The project to be imported is parsed with a new parser and then added to the | |||
* current project under the given import name | |||
*/ | |||
private class ImportHandler extends ElementHandler { | |||
/** | |||
* The attribute used to name the import. | |||
*/ | |||
static public final String IMPORT_NAME_ATTR = "name"; | |||
/** | |||
* The attribute name used to locate the project to be imported. | |||
*/ | |||
static public final String IMPORT_SYSTEMID_ATTR = "project"; | |||
/** | |||
* The project that has been imported. | |||
*/ | |||
private Project importedProject; | |||
/** | |||
* The name under which the project is being imported. | |||
*/ | |||
private String importName; | |||
/** | |||
* The systemId (URL) where the project is to be imported from. | |||
*/ | |||
private String projectSystemId; | |||
/** | |||
* Create an import handler to import a project. | |||
* | |||
* @param xmlReader the XML parser being used to parse the import element. | |||
* @param parent the parent element handler. | |||
* @param locator the SAX locator object used to associate elements with source | |||
* locations. | |||
* @param attributes attributes of the import statement. | |||
* @param importingSource the URL of the importing source. | |||
*/ | |||
public ImportHandler(XMLReader xmlReader, ContentHandler parent, | |||
Locator locator, Attributes attributes, URL importingSource) | |||
throws SAXParseException { | |||
super(xmlReader, parent, locator); | |||
for (int i = 0; i < attributes.getLength(); ++i) { | |||
String attributeName = attributes.getQName(i); | |||
String attributeValue = attributes.getValue(i); | |||
if (attributeName.equals(IMPORT_NAME_ATTR)) { | |||
importName = attributeValue; | |||
} | |||
else if (attributeName.equals(IMPORT_SYSTEMID_ATTR)) { | |||
projectSystemId = attributeValue; | |||
} | |||
else { | |||
throw new SAXParseException("Attribute " + attributeName + | |||
" is not allowed in an <import> element", getLocator()); | |||
} | |||
} | |||
if (importName == null) { | |||
throw new SAXParseException("Attribute " + IMPORT_NAME_ATTR + | |||
" is required in an <import> element", getLocator()); | |||
} | |||
if (projectSystemId == null) { | |||
throw new SAXParseException("Attribute " + IMPORT_SYSTEMID_ATTR + | |||
" is required in an <import> element", getLocator()); | |||
} | |||
// create a new parser to read this project relative to the | |||
// project's URI | |||
try { | |||
URL importURL = new URL(importingSource, projectSystemId); | |||
SAXParser importSAXParser = parserFactory.newSAXParser(); | |||
XMLReader importXMLReader = importSAXParser.getXMLReader(); | |||
if (recursionCheck.contains(importURL)) { | |||
throw new SAXParseException("Circular import detected when importing '" + | |||
importURL + "'", getLocator()); | |||
} | |||
recursionCheck.push(importURL); | |||
ProjectRootHandler importRootHandler = new ProjectRootHandler(importURL, importXMLReader); | |||
importSAXParser.parse(importURL.toString(), importRootHandler); | |||
if (recursionCheck.pop() != importURL) { | |||
throw new RuntimeException("Failure to pop expected element off recursion stack"); | |||
} | |||
importedProject = importRootHandler.getProject(); | |||
} | |||
catch (SAXParseException e) { | |||
throw e; | |||
} | |||
catch (NoProjectReadException e) { | |||
throw new SAXParseException("No project was imported from " + projectSystemId, | |||
getLocator()); | |||
} | |||
catch (MalformedURLException e) { | |||
throw new SAXParseException("Unable to import project from " + projectSystemId + | |||
": " + e.getMessage(), | |||
getLocator()); | |||
} | |||
catch (ParserConfigurationException e) { | |||
throw new SAXParseException("Unable to parse project imported from " + projectSystemId + | |||
": " + e.getMessage(), | |||
getLocator()); | |||
} | |||
catch (SAXException e) { | |||
throw new SAXParseException("Unable to parse project imported from " + projectSystemId + | |||
": " + e.getMessage(), | |||
getLocator()); | |||
} | |||
catch (IOException e) { | |||
throw new SAXParseException("Error reading project imported from " + projectSystemId + | |||
": " + e.getMessage(), | |||
getLocator()); | |||
} | |||
} | |||
/** | |||
* Import does not support nested elements. This method will always throw an | |||
* exception | |||
* @param uri The Namespace URI. | |||
* @param localName The local name (without prefix). | |||
* @param qualifiedName The qualified name (with prefix) | |||
* @param attributes The attributes attached to the element. | |||
* | |||
* @throws SAXParseException always. | |||
*/ | |||
public void startElement(String uri, String localName, String qualifiedName, | |||
Attributes attributes) throws SAXParseException { | |||
// everything is a task | |||
throw new SAXParseException("<import> does not support nested elements", getLocator()); | |||
} | |||
/** | |||
* Get the project imported. | |||
* | |||
* @return an imported Project. | |||
*/ | |||
public Project getImportedProject() { | |||
return importedProject; | |||
} | |||
/** | |||
* Get the name under which the project is imported. | |||
* | |||
* @return the import name of the project | |||
*/ | |||
public String getImportName() { | |||
return importName; | |||
} | |||
} | |||
/** | |||
* The include handler is used to read in included projects or | |||
* fragments into a project. | |||
*/ | |||
private class IncludeHandler extends ElementHandler { | |||
/** | |||
* The attribute name which identifies the fragment to be included | |||
*/ | |||
static public final String INCLUDE_SYSTEMID_ATTR = "fragment"; | |||
/** | |||
* The system id of the fragment to be included. | |||
*/ | |||
private String includeSystemId; | |||
/** | |||
* Create an IncludeHandler to include an element into the | |||
* current project | |||
* | |||
* @param xmlReader the XML parser being used to parse the include element. | |||
* @param parent the parent element handler. | |||
* @param locator the SAX locator object used to associate elements with source | |||
* locations. | |||
* @param attributes attributes of the include statement. | |||
* @param includingSource the URL of the including source. | |||
* @param project the project into which the included elements are added. | |||
*/ | |||
public IncludeHandler(XMLReader xmlReader, ContentHandler parent, | |||
Locator locator, Attributes attributes, URL includingSource, | |||
Project project) | |||
throws SAXParseException { | |||
super(xmlReader, parent, locator); | |||
for (int i = 0; i < attributes.getLength(); ++i) { | |||
String attributeName = attributes.getQName(i); | |||
String attributeValue = attributes.getValue(i); | |||
if (attributeName.equals(INCLUDE_SYSTEMID_ATTR)) { | |||
includeSystemId = attributeValue; | |||
} | |||
else { | |||
throw new SAXParseException("Attribute " + attributeName + | |||
" is not allowed in an <include> element", getLocator()); | |||
} | |||
} | |||
if (includeSystemId == null) { | |||
throw new SAXParseException("Attribute " + INCLUDE_SYSTEMID_ATTR + | |||
" is required in an <include> element", getLocator()); | |||
} | |||
// create a new parser to read this project relative to the | |||
// project's URI | |||
try { | |||
URL includeURL = new URL(includingSource, includeSystemId); | |||
SAXParser includeSAXParser = parserFactory.newSAXParser(); | |||
XMLReader includeXMLReader = includeSAXParser.getXMLReader(); | |||
if (recursionCheck.contains(includeURL)) { | |||
throw new SAXParseException("Circular include detected when including '" + | |||
includeURL + "'", getLocator()); | |||
} | |||
recursionCheck.push(includeURL); | |||
IncludeRootHandler includeRootHandler | |||
= new IncludeRootHandler(includeURL, includeXMLReader, project); | |||
includeSAXParser.parse(includeURL.toString(), includeRootHandler); | |||
if (recursionCheck.pop() != includeURL) { | |||
throw new RuntimeException("Failure to pop expected element off recursion stack"); | |||
} | |||
} | |||
catch (SAXParseException e) { | |||
throw e; | |||
} | |||
catch (MalformedURLException e) { | |||
throw new SAXParseException("Unable to include " + includeSystemId + | |||
": " + e.getMessage(), | |||
getLocator()); | |||
} | |||
catch (ParserConfigurationException e) { | |||
throw new SAXParseException("Unable to parse include " + includeSystemId + | |||
": " + e.getMessage(), | |||
getLocator()); | |||
} | |||
catch (SAXException e) { | |||
throw new SAXParseException("Unable to parse include " + includeSystemId + | |||
": " + e.getMessage(), | |||
getLocator()); | |||
} | |||
catch (IOException e) { | |||
throw new SAXParseException("Error reading include " + includeSystemId + | |||
": " + e.getMessage(), | |||
getLocator()); | |||
} | |||
} | |||
/** | |||
* Include does not support nested elements. This method will always throw an | |||
* exception | |||
* | |||
* @param uri The Namespace URI. | |||
* @param localName The local name (without prefix). | |||
* @param qualifiedName The qualified name (with prefix) | |||
* @param attributes The attributes attached to the element. | |||
* | |||
* @throws SAXParseException always. | |||
*/ | |||
public void startElement(String uri, String localName, String qualifiedName, | |||
Attributes attributes) throws SAXParseException { | |||
// everything is a task | |||
throw new SAXParseException("<include> does not support nested elements", getLocator()); | |||
} | |||
} | |||
/** | |||
* A TargetHandler process the Target element. | |||
*/ | |||
private class TargetHandler extends ElementHandler { | |||
/** | |||
* The target being configured. | |||
*/ | |||
private Target target; | |||
/** | |||
* Create a Target handler. Event element in a target is | |||
* considered to be a task | |||
* | |||
* @param xmlReader the XML parser being used to parse the target element. | |||
* @param parent the parent element handler. | |||
* @param locator the SAX locator object used to associate elements with source | |||
* locations. | |||
* @param attributes attributes of the target | |||
*/ | |||
public TargetHandler(XMLReader xmlReader, ContentHandler parent, | |||
Locator locator, Attributes attributes) | |||
throws SAXParseException { | |||
super(xmlReader, parent, locator); | |||
String targetName = null; | |||
String depends = null; | |||
Map aspects = new HashMap(); | |||
for (int i = 0; i < attributes.getLength(); ++i) { | |||
String attributeName = attributes.getQName(i); | |||
String attributeValue = attributes.getValue(i); | |||
if (attributeName.equals("name")) { | |||
targetName = attributeValue; | |||
} | |||
else if (attributeName.equals("depends")) { | |||
depends = attributeValue; | |||
} | |||
else if (attributeName.indexOf(":") != -1) { | |||
// potential aspect attribute | |||
aspects.put(attributeName, attributeValue); | |||
} | |||
else { | |||
throw new SAXParseException("The attribute '" + attributeName + "' is not " + | |||
"supported by the <target> element", getLocator()); | |||
} | |||
} | |||
if (targetName == null) { | |||
throw new SAXParseException("Targets must have a name attribute", locator); | |||
} | |||
target = new Target(getLocation(locator), targetName); | |||
target.setAspects(aspects); | |||
if (depends != null) { | |||
StringTokenizer tokenizer = new StringTokenizer(depends, ","); | |||
while (tokenizer.hasMoreTokens()) { | |||
String dependency = tokenizer.nextToken(); | |||
target.addDependency(dependency); | |||
} | |||
} | |||
} | |||
/* | |||
* Process an element within this target. All elements within the target are | |||
* treated as tasks. | |||
* | |||
* @param uri The Namespace URI. | |||
* @param localName The local name (without prefix). | |||
* @param qualifiedName The qualified name (with prefix) | |||
* @param attributes The attributes attached to the element. | |||
* | |||
* @throws SAXParseException if there is a parsing problem. | |||
*/ | |||
public void startElement(String uri, String localName, String qualifiedName, | |||
Attributes attributes) throws SAXParseException { | |||
// everything is a task | |||
TaskElementHandler taskHandler | |||
= new TaskElementHandler(getXMLReader(), this, getLocator(), | |||
attributes, qualifiedName); | |||
target.addTask(taskHandler.getTaskElement()); | |||
} | |||
/** | |||
* Get the target parsed by this handler. | |||
* | |||
* @return the Target model object parsed by this handler. | |||
*/ | |||
public Target getTarget() { | |||
return target; | |||
} | |||
} | |||
/** | |||
* A TaskElementHandler parses the task elements of a build | |||
*/ | |||
private class TaskElementHandler extends ElementHandler { | |||
/** | |||
* The task element being parsed by this handler. | |||
*/ | |||
private TaskElement taskElement; | |||
/** | |||
* Create a task element handler to parse a task element | |||
* | |||
* @param xmlReader the XML parser being used to parse the task element. | |||
* @param parent the parent element handler. | |||
* @param locator the SAX locator object used to associate elements with source | |||
* locations. | |||
* @param attributes attributes of the task element | |||
* @param elementTagName the name of the task element. | |||
*/ | |||
public TaskElementHandler(XMLReader xmlReader, ContentHandler parent, Locator locator, | |||
Attributes attributes, String elementTagName) { | |||
super(xmlReader, parent, locator); | |||
taskElement | |||
= new TaskElement(getLocation(locator), elementTagName); | |||
Map aspects = new HashMap(); | |||
for (int i = 0; i < attributes.getLength(); ++i) { | |||
String attributeName = attributes.getQName(i); | |||
String attributeValue = attributes.getValue(i); | |||
if (attributeName.indexOf(":") != -1) { | |||
// potential aspect attribute | |||
aspects.put(attributeName, attributeValue); | |||
} | |||
else { | |||
taskElement.addAttribute(attributeName, attributeValue); | |||
} | |||
} | |||
taskElement.setAspects(aspects); | |||
} | |||
/** | |||
* Process a nested element of this task element. All nested elements | |||
* of a taskElement are themselves taskElements. | |||
* | |||
* @param uri The Namespace URI. | |||
* @param localName The local name (without prefix). | |||
* @param qualifiedName The qualified name (with prefix) | |||
* @param attributes The attributes attached to the element. | |||
* | |||
* @throws SAXParseException if there is a parsing problem. | |||
*/ | |||
public void startElement(String uri, String localName, String qualifiedName, | |||
Attributes attributes) throws SAXParseException { | |||
// everything within a task element is also a task element | |||
TaskElementHandler nestedHandler | |||
= new TaskElementHandler(getXMLReader(), this, getLocator(), | |||
attributes, qualifiedName); | |||
taskElement.addTaskElement(nestedHandler.getTaskElement()); | |||
} | |||
public void characters(char[] buf, int start, int end) throws SAXParseException { | |||
taskElement.addText(new String(buf, start, end)); | |||
} | |||
/** | |||
* Get the task element being parsed by this handler. | |||
* | |||
* @return the TaskElement being parsed. | |||
*/ | |||
public TaskElement getTaskElement() { | |||
return taskElement; | |||
} | |||
} | |||
/** | |||
* A NoProjectReadException is used to indicate that a project | |||
* was not read from the particular source. This will happen | |||
* if the source is empty. | |||
*/ | |||
private class NoProjectReadException extends Exception { | |||
} | |||
} | |||
@@ -1,94 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 1999 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.frontend; | |||
import org.apache.ant.core.execution.*; | |||
import java.io.*; | |||
/** | |||
* Interface used by Ant to log the build output. | |||
* | |||
* A build logger is a build listener which has the 'right' to send output to the | |||
* ant log, which is usually System.out unles redirected by the -logfile option. | |||
* | |||
* @author <a href="mailto:conor@apache.org">Conor MacNeill</a> | |||
*/ | |||
public interface BuildLogger extends BuildListener { | |||
/** | |||
* Set the msgOutputLevel this logger is to respond to. | |||
* | |||
* Only messages with a message level lower than or equal to the given level are | |||
* output to the log. | |||
* | |||
* @param level the logging level for the logger. | |||
*/ | |||
public void setMessageOutputLevel(int level); | |||
/** | |||
* Set the output stream to which this logger is to send its output. | |||
* | |||
* @param output the output stream for the logger. | |||
*/ | |||
public void setOutputPrintStream(PrintStream output); | |||
/** | |||
* Set the output stream to which this logger is to send error messages. | |||
* | |||
* @param err the error stream for the logger. | |||
*/ | |||
public void setErrorPrintStream(PrintStream err); | |||
} |
@@ -1,311 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.frontend; | |||
import java.io.*; | |||
import java.net.*; | |||
import java.util.*; | |||
import javax.xml.parsers.*; | |||
import org.xml.sax.SAXParseException; | |||
import java.lang.reflect.*; | |||
import org.apache.ant.core.execution.*; | |||
import org.apache.ant.core.support.*; | |||
import org.apache.ant.core.xml.*; | |||
import org.apache.ant.core.config.*; | |||
import org.apache.ant.core.model.*; | |||
/** | |||
* This is the command line front end to end. It drives the core | |||
* | |||
* @author <a href="mailto:conor@apache.org">Conor MacNeill</a> | |||
*/ | |||
public class Commandline { | |||
/** The default build file name */ | |||
static public final String DEFAULT_BUILD_FILENAME = "build.ant"; | |||
/** Stream that we are using for logging */ | |||
private PrintStream out = System.out; | |||
/** Stream that we are using for logging error messages */ | |||
private PrintStream err = System.err; | |||
/** Names of classes to add as listeners to project */ | |||
private List listeners = new ArrayList(2); | |||
/** The list of targets to be evaluated in this invocation */ | |||
private List targets = new ArrayList(4); | |||
/** Our current message output status. Follows Project.MSG_XXX */ | |||
private int messageOutputLevel = BuildEvent.MSG_VERBOSE; | |||
/** | |||
* This is the build file to run. By default it is a file: type URL | |||
* but other URL protocols can be used. | |||
*/ | |||
private URL buildFileURL; | |||
/** | |||
* The Ant logger class. There may be only one logger. It will have the | |||
* right to use the 'out' PrintStream. The class must implements the BuildLogger | |||
* interface | |||
*/ | |||
private String loggerClassname = null; | |||
public static void start(String[] args) { | |||
// create a command line and use it to run ant | |||
Commandline commandline = new Commandline(); | |||
commandline.runAnt(args); | |||
} | |||
public void runAnt(String[] args) { | |||
ExecutionFrame mainFrame = null; | |||
try { | |||
parseArguments(args); | |||
Project project = getProject(); | |||
for (Iterator i = project.getTargets(); i.hasNext();) { | |||
Target target = (Target)i.next(); | |||
} | |||
// Get the list of library components | |||
AntLibrary[] libraries = ComponentManager.getComponents(); | |||
mainFrame = new ExecutionFrame(project, libraries); | |||
// We iterate through all nodes of all projects and make sure every node is OK | |||
Map state = new HashMap(); | |||
Stack visiting = new Stack(); | |||
List dependencyOrder = new ArrayList(); | |||
mainFrame.checkTargets(dependencyOrder, state, visiting); | |||
addBuildListeners(mainFrame); | |||
} | |||
catch (AntException e) { | |||
Location location = e.getLocation(); | |||
Throwable cause = e.getCause(); | |||
if (location != null && location != Location.UNKNOWN_LOCATION) { | |||
System.out.print(location); | |||
} | |||
System.out.println(e.getMessage()); | |||
if (cause != null) { | |||
System.out.println("Root cause: " + cause.getClass().getName() + ": " + cause.getMessage()); | |||
} | |||
System.exit(1); | |||
} | |||
try { | |||
mainFrame.runBuild(targets); | |||
System.exit(0); | |||
} | |||
catch (Exception e) { | |||
System.exit(1); | |||
} | |||
} | |||
protected void addBuildListeners(ExecutionFrame frame) | |||
throws ConfigException { | |||
// Add the default listener | |||
frame.addBuildListener(createLogger()); | |||
for (Iterator i = listeners.iterator(); i.hasNext(); ) { | |||
String className = (String) i.next(); | |||
try { | |||
BuildListener listener = | |||
(BuildListener) Class.forName(className).newInstance(); | |||
frame.addBuildListener(listener); | |||
} | |||
catch(Exception exc) { | |||
throw new ConfigException("Unable to instantiate listener " + className, exc); | |||
} | |||
} | |||
} | |||
/** | |||
* Creates the default build logger for sending build events to the ant log. | |||
*/ | |||
private BuildLogger createLogger() throws ConfigException { | |||
BuildLogger logger = null; | |||
if (loggerClassname != null) { | |||
try { | |||
logger = (BuildLogger)(Class.forName(loggerClassname).newInstance()); | |||
} | |||
catch (ClassCastException e) { | |||
System.err.println("The specified logger class " + loggerClassname + | |||
" does not implement the BuildLogger interface"); | |||
throw new ConfigException("Unable to instantiate logger " + loggerClassname, e); | |||
} | |||
catch (Exception e) { | |||
System.err.println("Unable to instantiate specified logger class " + | |||
loggerClassname + " : " + e.getClass().getName()); | |||
throw new ConfigException("Unable to instantiate logger " + loggerClassname, e); | |||
} | |||
} | |||
else { | |||
logger = new DefaultLogger(); | |||
} | |||
logger.setMessageOutputLevel(messageOutputLevel); | |||
logger.setOutputPrintStream(out); | |||
logger.setErrorPrintStream(err); | |||
return logger; | |||
} | |||
/** | |||
* Parse the command line arguments. | |||
*/ | |||
private void parseArguments(String[] args) throws ConfigException { | |||
for (int i = 0; i < args.length; i++) { | |||
String arg = args[i]; | |||
if (arg.equals("-buildfile") || arg.equals("-file") || arg.equals("-f")) { | |||
try { | |||
String url = args[i+1]; | |||
if (url.indexOf(":") == -1) { | |||
File file = new File(url); | |||
String uri = "file:" + file.getAbsolutePath().replace('\\', '/'); | |||
for (int index = uri.indexOf('#'); index != -1; index = uri.indexOf('#')) { | |||
uri = uri.substring(0, index) + "%23" + uri.substring(index+1); | |||
} | |||
buildFileURL = new URL(uri); | |||
// We convert any hash characters to their URL escape. | |||
} | |||
else { | |||
buildFileURL = new URL(url); | |||
} | |||
i++; | |||
} | |||
catch (MalformedURLException e) { | |||
System.err.println("Buildfile is not valid: " + e.getMessage()); | |||
throw new ConfigException("Build file is not valid", e); | |||
} | |||
catch (ArrayIndexOutOfBoundsException e) { | |||
System.err.println("You must specify a buildfile when " + | |||
"using the -buildfile argument"); | |||
return; | |||
} | |||
} | |||
else if (arg.equals("-logfile") || arg.equals("-l")) { | |||
try { | |||
File logFile = new File(args[i+1]); | |||
i++; | |||
out = new PrintStream(new FileOutputStream(logFile)); | |||
err = out; | |||
} catch (IOException ioe) { | |||
System.err.println("Cannot write on the specified log file. " + | |||
"Make sure the path exists and you have write permissions."); | |||
return; | |||
} catch (ArrayIndexOutOfBoundsException aioobe) { | |||
System.err.println("You must specify a log file when " + | |||
"using the -log argument"); | |||
return; | |||
} | |||
} | |||
else if (arg.equals("-listener")) { | |||
try { | |||
listeners.add(args[i+1]); | |||
i++; | |||
} catch (ArrayIndexOutOfBoundsException aioobe) { | |||
System.err.println("You must specify a classname when " + | |||
"using the -listener argument"); | |||
return; | |||
} | |||
} | |||
else if (arg.equals("-logger")) { | |||
if (loggerClassname != null) { | |||
System.err.println("Only one logger class may be specified."); | |||
return; | |||
} | |||
try { | |||
loggerClassname = args[++i]; | |||
} catch (ArrayIndexOutOfBoundsException aioobe) { | |||
System.err.println("You must specify a classname when " + | |||
"using the -logger argument"); | |||
return; | |||
} | |||
} | |||
else if (arg.startsWith("-")) { | |||
// we don't have any more args to recognize! | |||
System.out.println("Unknown argument: " + arg); | |||
return; | |||
} else { | |||
// if it's no other arg, it must be a target | |||
targets.add(arg); | |||
} | |||
} | |||
if (buildFileURL == null) { | |||
File defaultBuildFile = new File(DEFAULT_BUILD_FILENAME); | |||
try { | |||
buildFileURL = defaultBuildFile.toURL(); | |||
} | |||
catch (MalformedURLException e) { | |||
System.err.println("Buildfile is not valid: " + e.getMessage()); | |||
throw new ConfigException("Build file is not valid", e); | |||
} | |||
} | |||
} | |||
private Project getProject() throws ConfigException { | |||
XMLProjectParser parser = new XMLProjectParser(); | |||
Project project = parser.parseBuildFile(buildFileURL); | |||
return project; | |||
} | |||
} | |||
@@ -1,225 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 1999 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.frontend; | |||
import org.apache.ant.core.support.*; | |||
import org.apache.ant.core.model.*; | |||
import org.apache.ant.core.execution.*; | |||
import java.io.*; | |||
/** | |||
* Writes build event to a PrintStream. Currently, it | |||
* only writes which targets are being executed, and | |||
* any messages that get logged. | |||
*/ | |||
public class DefaultLogger implements BuildLogger { | |||
private static int LEFT_COLUMN_SIZE = 12; | |||
protected PrintStream out; | |||
protected PrintStream err; | |||
protected int msgOutputLevel = BuildEvent.MSG_ERR; | |||
private long startTime = System.currentTimeMillis(); | |||
protected static String lSep = System.getProperty("line.separator"); | |||
protected boolean emacsMode = false; | |||
/** | |||
* Set the msgOutputLevel this logger is to respond to. | |||
* | |||
* Only messages with a message level lower than or equal to the given level are | |||
* output to the log. | |||
* <P> | |||
* Constants for the message levels are in Project.java. The order of | |||
* the levels, from least to most verbose, is MSG_ERR, MSG_WARN, | |||
* MSG_INFO, MSG_VERBOSE, MSG_DEBUG. | |||
* | |||
* The default message level for DefaultLogger is Project.MSG_ERR. | |||
* | |||
* @param level the logging level for the logger. | |||
*/ | |||
public void setMessageOutputLevel(int level) { | |||
this.msgOutputLevel = level; | |||
} | |||
/** | |||
* Set the output stream to which this logger is to send its output. | |||
* | |||
* @param output the output stream for the logger. | |||
*/ | |||
public void setOutputPrintStream(PrintStream output) { | |||
this.out = output; | |||
} | |||
/** | |||
* Set the output stream to which this logger is to send error messages. | |||
* | |||
* @param err the error stream for the logger. | |||
*/ | |||
public void setErrorPrintStream(PrintStream err) { | |||
this.err = err; | |||
} | |||
/** | |||
* Set this logger to produce emacs (and other editor) friendly output. | |||
* | |||
* @param emacsMode true if output is to be unadorned so that emacs and other | |||
* editors can parse files names, etc. | |||
*/ | |||
public void setEmacsMode(boolean emacsMode) { | |||
this.emacsMode = emacsMode; | |||
} | |||
public void reportException(Throwable t) { | |||
if (t instanceof AntException) { | |||
AntException e = (AntException)t; | |||
Location location = e.getLocation(); | |||
Throwable cause = e.getCause(); | |||
if (location != null && location != Location.UNKNOWN_LOCATION) { | |||
out.print(location); | |||
} | |||
out.println(e.getMessage()); | |||
if (cause != null) { | |||
out.println("Root cause: " + cause.toString()); | |||
} | |||
} | |||
else { | |||
t.printStackTrace(err); | |||
} | |||
} | |||
public void processBuildEvent(BuildEvent event) { | |||
switch (event.getEventType()) { | |||
case BuildEvent.BUILD_STARTED: | |||
startTime = System.currentTimeMillis(); | |||
break; | |||
case BuildEvent.BUILD_FINISHED: | |||
Throwable cause = event.getCause(); | |||
if (cause == null) { | |||
out.println(lSep + "BUILD SUCCESSFUL"); | |||
} | |||
else { | |||
err.println(lSep + "BUILD FAILED" + lSep); | |||
reportException(cause); | |||
} | |||
out.println(lSep + "Total time: " + formatTime(System.currentTimeMillis() - startTime)); | |||
break; | |||
case BuildEvent.TARGET_STARTED: | |||
if (BuildEvent.MSG_INFO <= msgOutputLevel) { | |||
Target target = (Target)event.getBuildElement(); | |||
out.println(lSep + target.getName() + ":"); | |||
} | |||
break; | |||
case BuildEvent.TARGET_FINISHED: | |||
break; | |||
case BuildEvent.TASK_STARTED: | |||
break; | |||
case BuildEvent.TASK_FINISHED: | |||
break; | |||
case BuildEvent.MESSAGE: | |||
PrintStream logTo = event.getPriority() == BuildEvent.MSG_ERR ? err : out; | |||
// Filter out messages based on priority | |||
if (event.getPriority() <= msgOutputLevel) { | |||
// Print out the name of the task if we're in one | |||
Object buildElement = event.getBuildElement(); | |||
if (buildElement instanceof TaskElement) { | |||
TaskElement taskElement = (TaskElement)buildElement; | |||
String name = taskElement.getType(); | |||
if (!emacsMode) { | |||
String msg = "[" + name + "] "; | |||
for (int i = 0; i < (LEFT_COLUMN_SIZE - msg.length()); i++) { | |||
logTo.print(" "); | |||
} | |||
logTo.print(msg); | |||
} | |||
} | |||
// Print the message | |||
logTo.println(event.getMessage()); | |||
} | |||
break; | |||
default: | |||
err.println("Unrecognized event type = " + event.getEventType()); | |||
break; | |||
} | |||
} | |||
protected static String formatTime(long millis) { | |||
long seconds = millis / 1000; | |||
long minutes = seconds / 60; | |||
if (minutes > 0) { | |||
return Long.toString(minutes) + " minute" | |||
+ (minutes == 1 ? " " : "s ") | |||
+ Long.toString(seconds%60) + " second" | |||
+ (seconds%60 == 1 ? "" : "s"); | |||
} | |||
else { | |||
return Long.toString(seconds) + " second" | |||
+ (seconds%60 == 1 ? "" : "s"); | |||
} | |||
} | |||
} |
@@ -1,77 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.frontend; | |||
import java.io.*; | |||
import java.net.*; | |||
import java.util.*; | |||
import javax.xml.parsers.*; | |||
import org.xml.sax.SAXParseException; | |||
import java.lang.reflect.*; | |||
import org.apache.ant.core.support.*; | |||
import org.apache.ant.core.xml.*; | |||
import org.apache.ant.core.config.*; | |||
/** | |||
* This class illustrates the use of the ExecutionFrame class | |||
* standalone to execute tasks | |||
* | |||
* @author <a href="mailto:conor@apache.org">Conor MacNeill</a> | |||
*/ | |||
public class EmbedTest { | |||
} | |||
@@ -1,89 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.frontend; | |||
import java.io.*; | |||
import java.net.*; | |||
import javax.xml.parsers.*; | |||
import java.lang.reflect.*; | |||
import org.apache.ant.core.support.*; | |||
/** | |||
* This is the command line front end to end. It drives the core | |||
* | |||
* @author <a href="mailto:conor@apache.org">Conor MacNeill</a> | |||
*/ | |||
public class Launcher { | |||
public static void main(String[] args) throws Exception { | |||
// we need to find the parser jars and makre sure we are going to use | |||
// those in preference to anything else that may be lying about in the | |||
// user's classpath | |||
AntClassLoader coreClassLoader = AntLocator.getCoreClassLoader(System.getProperties()); | |||
URL frontEndURL = AntLocator.getClassLocationURL(Launcher.class); | |||
coreClassLoader.addURL(frontEndURL); | |||
Class commandLineClass = Class.forName("org.apache.ant.frontend.Commandline", true, coreClassLoader); | |||
final Class[] param = {Class.forName("[Ljava.lang.String;")}; | |||
Class target = null; | |||
final Method startMethod = commandLineClass.getMethod("start", param); | |||
final Object[] argument = {args}; | |||
startMethod.invoke(null, argument); | |||
} | |||
} | |||
@@ -1,97 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.ant.frontend; | |||
import java.io.*; | |||
import java.net.*; | |||
import javax.xml.parsers.*; | |||
import java.lang.reflect.*; | |||
import org.apache.ant.core.support.*; | |||
/** | |||
* Command line to run Ant core from a remote server | |||
* | |||
* @author <a href="mailto:conor@apache.org">Conor MacNeill</a> | |||
*/ | |||
public class RemoteLauncher { | |||
public static void main(String[] args) throws Exception { | |||
String antHome = args[0]; | |||
String parserHome = args[1]; | |||
URL[] remoteCore = new URL[3]; | |||
remoteCore[0] = new URL(antHome + "/lib/core.jar"); | |||
remoteCore[1] = new URL(antHome + "/lib/frontend.jar"); | |||
remoteCore[2] = new URL(parserHome); | |||
AntClassLoader coreClassLoader = new AntClassLoader(remoteCore); | |||
String[] realArgs = new String[args.length - 2]; | |||
System.arraycopy(args, 2, realArgs, 0, realArgs.length); | |||
System.out.print("Loading remote Ant ... "); | |||
Class launcher = Class.forName("org.apache.ant.frontend.Commandline", true, coreClassLoader); | |||
final Class[] param = { Class.forName("[Ljava.lang.String;") }; | |||
Class target = null; | |||
final Method startMethod = launcher.getMethod("start", param); | |||
final Object[] argument = {realArgs}; | |||
System.out.println("Done"); | |||
System.out.println("Starting remote Ant"); | |||
startMethod.invoke(null, argument); | |||
} | |||
} | |||
@@ -1,5 +0,0 @@ | |||
Manifest-Version: 1.0 | |||
Created-By: Ant 2.0alpha | |||
Main-Class: org.apache.ant.frontend.RemoteLauncher | |||
Class-Path: core.jar | |||
Sealed: true |
@@ -1,5 +0,0 @@ | |||
Manifest-Version: 1.0 | |||
Created-By: Ant 2.0alpha | |||
Main-Class: org.apache.ant.frontend.Launcher | |||
Class-Path: core.jar | |||
Sealed: true |