git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274765 13f79535-47bb-0310-9956-ffa450edef68master
@@ -1,2 +0,0 @@ | |||
build | |||
dist |
@@ -1,18 +0,0 @@ | |||
There are the following features in the antlib proposal: | |||
1) antlib & antjar | |||
2) type definitions that allow to define new implementations of mappers, selectors, paths, conditions, etc. That you can define in your antlib and a way to link this with the introspectors (I am not sure how complete this is). | |||
3) A scoping framework for the symbol tables needed to manage the antlib definitions (I think ANT has something on this regard) | |||
4) A framework for managing classloaders where you can specify which classloader to use when loading an antlib. | |||
(2) would be really nice, because it will eliminate all the need for mentioning classnames all around, antlibs will be used just like core. | |||
Also useful for tasks like <ejbjar> which has vendor specific components that should be part of the antlib of the vendor. | |||
(3) Probably should die and be replaced by whatever scoping thing comes from <import> proposal. | |||
(4) This was probably what killed <antlib> the last time around. Probably needs to be treated separately. In any case, if you load | |||
multiple antlibs with dependencies, there has t be a way to make them share the same classloader otherwise you cannot use it. | |||
So there we go, take a look at the code and let us know what you think, | |||
Jose Alberto & Antoine |
@@ -1,106 +0,0 @@ | |||
<?xml version='1.0' ?> | |||
<project name="antlib" default="all"> | |||
<property name='orig' location='../../..' /> | |||
<property name='orig-build' location='${orig}/build' /> | |||
<property name='orig-classes' location='${orig-build}/classes' /> | |||
<property name='build' location='build' /> | |||
<property name='dist' location='dist' /> | |||
<property name='classes' location='${build}/classes' /> | |||
<property name='testcases' location='src/testcases' /> | |||
<property name="debug" value="true" /> | |||
<property name="deprecation" value="false" /> | |||
<property name="optimize" value="true" /> | |||
<property environment="env"/> | |||
<target name='init'> | |||
<ant target='build' dir='${orig}' inheritAll='false' /> | |||
<mkdir dir='${classes}' /> | |||
<copy toDir='${classes}' preservelastmodified='true' > | |||
<fileset dir='${orig-classes}'> | |||
<include name='**' /> | |||
<exclude name='org/apache/tools/ant/Project.class' /> | |||
<exclude name='org/apache/tools/ant/TaskAdapter.class' /> | |||
<exclude name='org/apache/tools/ant/taskdefs/Ant.class' /> | |||
<exclude name='org/apache/tools/ant/ComponentHelper.class' /> | |||
</fileset> | |||
</copy> | |||
</target> | |||
<target name='all' depends='init, build' /> | |||
<target name='fullbuild' depends='init, compile'> | |||
<ant target='internal_dist' dir='${orig}'> | |||
<property name="build.dir" value="${build}"/> | |||
<property name="dist.dir" value="${dist}"/> | |||
</ant> | |||
</target> | |||
<target name='build' depends='init, compile'> | |||
<ant target='dist-lite' dir='${orig}'> | |||
<property name="build.dir" value="${build}"/> | |||
<property name="dist.dir" value="${dist}"/> | |||
</ant> | |||
<!-- | |||
Rejar things to use lib descriptors | |||
It needs to work with the original ANT processor | |||
--> | |||
<path id="newtasks"> | |||
<pathelement location="${classes}" /> | |||
</path> | |||
<taskdef name="antjar" classname="org.apache.tools.ant.taskdefs.Antjar" | |||
classpathref="newtasks" /> | |||
<taskdef name="antlib" classname="org.apache.tools.ant.taskdefs.Antlib" | |||
classpathref="newtasks" /> | |||
<mkdir dir='${dist}/autolib' /> | |||
<antjar antxml="src/main/org/apache/tools/ant/opt-antlib.xml" | |||
destfile="${dist}/autolib/optional.jar" > | |||
<zipfileset src="${dist}/lib/optional.jar" > | |||
<include name="**/*" /> | |||
</zipfileset> | |||
</antjar> | |||
<antjar antxml="src/main/org/apache/tools/ant/antlib.xml" | |||
destfile="${dist}/lib/newant.jar" > | |||
<zipfileset src="${dist}/lib/ant.jar" > | |||
<include name="**/*" /> | |||
</zipfileset> | |||
</antjar> | |||
<delete file="${dist}/lib/optional.jar" /> | |||
<move file="${dist}/lib/newant.jar" tofile="${dist}/lib/ant.jar"/> | |||
</target> | |||
<target name='compile'> | |||
<javac srcdir='src/main' destdir='${classes}' | |||
debug="${debug}" | |||
deprecation="${deprecation}" | |||
optimize="${optimize}"> | |||
<include name='**/*.java'/> | |||
</javac> | |||
<copy toDir='${classes}' preservelastmodified='true' > | |||
<fileset dir='src/main'> | |||
<include name='**/*.xml' /> | |||
</fileset> | |||
</copy> | |||
</target> | |||
<target name='clean'> | |||
<delete dir='${build}' /> | |||
</target> | |||
<target name='test'> | |||
<ant dir='${testcases}' inheritAll='false'/> | |||
<ant dir='${testcases}' | |||
antfile='${testcases}/case.xml' inheritAll='false'/> | |||
</target> | |||
<target name='cleanall' depends='clean'> | |||
<delete dir='${dist}' /> | |||
</target> | |||
<target name="install-lite" if="env.ANT_HOME" description="primitive installation system" > | |||
<delete file="${env.ANT_HOME}/lib/optional.jar" quiet="true"/> | |||
<mkdir dir="${env.ANT_HOME}/autolib"/> | |||
<copy file="dist/autolib/optional.jar" todir="${env.ANT_HOME}/autolib"/> | |||
<copy file="dist/lib/ant.jar" todir="${env.ANT_HOME}/lib" overwrite="true"/> | |||
</target> | |||
</project> |
@@ -1,102 +0,0 @@ | |||
<html> | |||
<head> | |||
<meta http-equiv="Content-Language" content="en-us"> | |||
<title>Ant User Manual</title> | |||
</head> | |||
<body> | |||
<h2><a name="antjar">AntJar</a></h2> | |||
<h3>Description</h3> | |||
<p>An extension of the <a href="jar.html">Jar</a> task with special | |||
treatment for the library descriptor file that should end up in the | |||
<code>META-INF</code> directory of the Ant Archive.</p> | |||
<p> | |||
Descriptors must follow the following rules, although there is no fix DTD | |||
for them: | |||
<pre> | |||
<!-- Root element for the Antlib descriptor. --> | |||
<!ELEMENT antlib (role | <i>rolename</i>)* > | |||
<!-- Declaration of roles contained in the library. --> | |||
<!ELEMENT role EMPTY> | |||
<!ATTLIST role | |||
name CDATA #REQUIRED | |||
class CDATA #REQUIRED | |||
proxy CDATA #IMPLIED | |||
> | |||
<!-- Declaration of datatypes contained in the library --> | |||
<!ELEMENT <i>rolename</i> EMPTY> | |||
<!ATTLIST <i>rolename</i> | |||
name CDATA #REQUIRED | |||
class CDATA #REQUIRED | |||
> | |||
</pre> | |||
There are two predefined roles: <i><b>task</b></i> and <i><b>datatype</b></i>. | |||
<p> | |||
<h4>Role definition</h4> | |||
The <b>name</b> of the role. This name is used when specifying | |||
elements for this role. | |||
<p> | |||
The <b>class</b> defining a role must be an interface containing a | |||
unique void method with only one argument whose type is the that of | |||
elements declared on the role. | |||
<p> | |||
The <b>proxy</b> defined in a role specifies a class that can be used | |||
to bridge between the type expected by the role and the type of | |||
elements declared for that role. | |||
<h4>Element definition</h4> | |||
Any element whose name is that of a role declares an element for that role. | |||
<p> | |||
The <b>name</b> defined the name of the element to use in the buildfile | |||
to specify the element being declared. | |||
<p> | |||
The <b>class</b> the class defining the element. | |||
<h3>Parameters</h3> | |||
<table border="1" cellpadding="2" cellspacing="0"> | |||
<tr> | |||
<td valign="top"><b>Attribute</b></td> | |||
<td valign="top"><b>Description</b></td> | |||
<td align="center" valign="top"><b>Required</b></td> | |||
</tr> | |||
<tr> | |||
<td valign="top">antxml</td> | |||
<td valign="top">The library descriptor to use (META-INF/antlib.xml).</td> | |||
<td valign="top" align="center">Yes</td> | |||
</tr> | |||
<tr> | |||
<td valign="top"><b>Others...</b></td> | |||
<td valign="top">All attributes inherited form the | |||
<a href="jar.html">Jar task</a>.</td> | |||
<td valign="top" align="center"> </td> | |||
</tr> | |||
</table> | |||
<h3>Nested elements</h3> | |||
See the nested elements of the <a href="jar.html">Jar task</a>. | |||
<h3>Examples</h3> | |||
<pre> <antjar file="${dist}/lib/app.jar" | |||
antxml="${src}/applib.xml" basedir="${build}/classes"/></pre> | |||
<p>jars all files in the <code>${build}/classes</code> directory into a file | |||
called <code>app.jar</code> in the <code>${dist}/lib</code> directory and | |||
sets the content of <code>${src}/applib.xml</code> as the library descriptor | |||
in <code>META-INF/antlib.xml</code>.</p> | |||
<p>Here is a sample <code>META-INF/antlib.xml</code>:</p> | |||
<pre> | |||
<?xml version="1.0" encoding="UTF8" ?> | |||
<antlib version="1.0" > | |||
<task name="case" class="org.apache.ant.contrib.Case" /> | |||
</antlib> | |||
</pre> | |||
<hr> | |||
<p align="center">Copyright © 2000,2001 Apache Software Foundation. All rights | |||
Reserved.</p> | |||
</body> | |||
</html> | |||
@@ -1,148 +0,0 @@ | |||
<html> | |||
<head> | |||
<meta http-equiv="Content-Language" content="en-us"> | |||
<title>Ant User Manual</title> | |||
</head> | |||
<body> | |||
<h2><a name="antlib">AntLib</a></h2> | |||
<h3>Description</h3> | |||
<p>Defines and loads elements contained in an ANT library.</p> | |||
<p>It also allows the aliasing of the names being defined in order to avoid | |||
collisions and provides means to override definitions with the ones defined | |||
in the library.</p> | |||
Ant libraries are associated with ClassLoaders identified by the | |||
<tt>loaderid</tt> attribute. If no loader is specified a default loader | |||
will be used. Ant libraries specifying the same loader are loaded by the | |||
same ClassLoader as long as the libraries are defined on the same project. | |||
Classloaders with the same ID in a subproject have the corresponding | |||
classloader in the parent project as their parent classloader. | |||
<p> | |||
Ant libraries can be loaded in the current classloader, | |||
which is more efficient, | |||
but requires the tasks to be in the path already (such as in the ant lib | |||
directory) - set <tt>useCurrentClassloader</tt> to true to enable this. | |||
It is also possible to add more libraries to the path, such as any | |||
libraries the task is dependent on. | |||
<p> | |||
Ant libraries define objects of several types: | |||
<ol> | |||
<li> <b>Roles</b>: Define an interface to be implemented by elements | |||
(usually tasks) that accept subelements of the specified role. | |||
Roles may also define a proxy class which may be applied to an element | |||
in order to make it compatible with the role. | |||
</li> | |||
<li> <b>Tasks</b>: define elements that belong to the predefined | |||
role "task". | |||
<li> <b>Data types</b>: define elements that belong to the predefined role | |||
"datatype". | |||
<li> <b>Other role elements</b>: declare elements for other roles that | |||
have been previously defined. | |||
</ol> | |||
<h3>Parameters</h3> | |||
<table border="1" cellpadding="2" cellspacing="0"> | |||
<tr> | |||
<td valign="top"><b>Attribute</b></td> | |||
<td valign="top"><b>Description</b></td> | |||
<td align="center" valign="top"><b>Required</b></td> | |||
</tr> | |||
<tr> | |||
<td valign="top">file</td> | |||
<td valign="top">The jar-file of the library.</td> | |||
<td align="center" valign="middle" rowspan="2">at least one of the two</td> | |||
</tr> | |||
<tr> | |||
<td valign="top">library</td> | |||
<td valign="top">The name of a library relative to ${ant.home}/antlib.</td> | |||
</tr> | |||
<tr> | |||
<td valign="top">override</td> | |||
<td valign="top">Replace any existing definition with the same name. | |||
("true"/"false"). | |||
When "false" already defined tasks | |||
and datatytes take precedence over those in the library. | |||
Default is "false" when omitted.</td> | |||
<td align="center" valign="top">No</td> | |||
</tr> | |||
<tr> | |||
<td valign="top">useCurrentClassloader</td> | |||
<td valign="top">Set to "true" to avoid using a separate | |||
ClassLoader for the tasks in the library. Using this option requires | |||
that the library jar is already accessible by the ClassLoader of | |||
the project. Default is "false". | |||
</td> | |||
<td align="center" valign="top">No</td> | |||
</tr> | |||
<tr> | |||
<td valign="top">classpath</td> | |||
<td valign="top">A | |||
<a href="../using.html#path">classpath</a> | |||
for extra libraries to pull in. | |||
</td> | |||
<td valign="top" align="center">No</td> | |||
</tr> | |||
<tr> | |||
<td valign="top">loaderid</td> | |||
<td valign="top">The ID of the ClassLoader to use to load the classes | |||
defined in this library. If omitted a default per project ClassLoader | |||
will be used. | |||
</td> | |||
<td valign="top" align="center">No</td> | |||
</tr> | |||
</table> | |||
<h3><a name="nested">Parameters specified as nested elements</a></h3> | |||
<h4>alias</h4> | |||
<p>Specifies the usage of a different name from that defined in the library | |||
descriptor. Applies only to element definitions (not role declarations).</p> | |||
<table border="1" cellpadding="2" cellspacing="0"> | |||
<tr> | |||
<td valign="top"><b>Attribute</b></td> | |||
<td valign="top"><b>Description</b></td> | |||
<td align="center" valign="top"><b>Required</b></td> | |||
</tr> | |||
<tr> | |||
<td valign="top">name</td> | |||
<td valign="top">The name used in the library descriptor.</td> | |||
<td valign="top" align="center">Yes</td> | |||
</tr> | |||
<tr> | |||
<td valign="top">as</td> | |||
<td valign="top">The alias to use in the project.</td> | |||
<td valign="top" align="center">Yes</td> | |||
</tr> | |||
</table> | |||
<p>Specifies the usage of a different name from that defined in the library | |||
descriptor. This is used to deal with name clashes </p> | |||
<h4>classpath</h4> | |||
A classpath of extra libraries to import to support this library. | |||
<h4>classpathref</h4> | |||
A reference to an existing classpath. | |||
<h3>Examples</h3> | |||
<pre> <antlib file="${build}/lib/mylib.jar"/></pre> | |||
<p>loads the definitions from the library located at | |||
<code>${build}/lib/ant.jar</code>.</p> | |||
<pre> <antlib library="optional.jar"/></pre> | |||
<p>loads the definitions from the library <code>optional.jar</code> | |||
located at <code>${ant.home}/lib</code>.</p> | |||
<pre> <antlib file="${build}/lib/mylib.jar"> | |||
<alias name="echo" as="myecho"/> | |||
</antlib> | |||
</pre> | |||
<p>loads the definitions from the library located at | |||
<code>${build}/lib/ant.jar</code> but uses the name | |||
"<code>myecho</code>" for the "<code>echo</code>" task | |||
declared in the library.</p> | |||
<hr><p align="center">Copyright © 2000,2001 Apache Software Foundation. All rights | |||
Reserved.</p> | |||
</body> | |||
</html> | |||
@@ -1,649 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2003 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 "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.tools.ant; | |||
import org.apache.tools.ant.util.LazyHashtable; | |||
import org.apache.tools.ant.util.WeakishReference; | |||
import java.util.Enumeration; | |||
import java.util.Hashtable; | |||
import java.util.Properties; | |||
import java.util.Vector; | |||
import java.io.InputStream; | |||
import java.io.IOException; | |||
import java.lang.reflect.Modifier; | |||
/** | |||
* Component creation and configuration. | |||
* | |||
* This is cut&paste from Project.java of everything related to | |||
* task/type management. Project will just delegate. | |||
* | |||
* A very simple hook mechnism is provided that allows users to plug | |||
* in custom code. It is also possible to replace the default behavior | |||
* ( for example in an app embeding ant ) | |||
* | |||
* @author Costin Manolache | |||
* @since Ant1.6 | |||
*/ | |||
public class ComponentHelper { | |||
/** Map from data type names to implementing classes (String to Class). */ | |||
private Hashtable dataClassDefinitions; | |||
/** Map from task names to implementing classes (String to Class). */ | |||
private Hashtable taskClassDefinitions; | |||
/** | |||
* Map from task names to vectors of created tasks | |||
* (String to Vector of Task). This is used to invalidate tasks if | |||
* the task definition changes. | |||
*/ | |||
private Hashtable createdTasks = new Hashtable(); | |||
protected ComponentHelper next; | |||
protected Project project; | |||
/** | |||
*/ | |||
public static ComponentHelper getComponentHelper(Project project) { | |||
// Singleton for now, it may change ( per/classloader ) | |||
ComponentHelper ph=(ComponentHelper)project.getReference( "ant.ComponentHelper" ); | |||
if( ph!=null ) return ph; | |||
ph=new ComponentHelper(); | |||
ph.setProject( project ); | |||
project.addReference( "ant.ComponentHelper",ph ); | |||
return ph; | |||
} | |||
protected ComponentHelper() { | |||
} | |||
public void setNext( ComponentHelper next ) { | |||
this.next=next; | |||
} | |||
public ComponentHelper getNext() { | |||
return next; | |||
} | |||
public void setProject(Project project) { | |||
this.project = project; | |||
dataClassDefinitions= new AntTaskTable(project, false); | |||
taskClassDefinitions= new AntTaskTable(project, true); | |||
} | |||
/** Factory method to create the components. | |||
* | |||
* This should be called by UnknownElement. | |||
* | |||
* @param ue The component helper has access via ue to the entire XML tree. | |||
* @param ns Namespace. Also available as ue.getNamespace() | |||
* @param taskName The element name. Also available as ue.getTag() | |||
* @return | |||
* @throws BuildException | |||
*/ | |||
public Object createComponent( UnknownElement ue, | |||
String ns, | |||
String taskName ) | |||
throws BuildException | |||
{ | |||
Object component=null; | |||
// System.out.println("Fallback to project default " + taskName ); | |||
// Can't create component. Default is to use the old methods in project. | |||
// This policy is taken from 1.5 ProjectHelper. In future the difference between | |||
// task and type should disapear. | |||
if( project.getDataTypeDefinitions().get(taskName) != null ) { | |||
// This is the original policy in ProjectHelper. The 1.5 version of UnkwnonwElement | |||
// used to try first to create a task, and if it failed tried a type. In 1.6 the diff | |||
// should disapear. | |||
component = this.createDataType(taskName); | |||
if( component!=null ) return component; | |||
} | |||
// from UnkwnonwElement.createTask. The 'top level' case is removed, we're | |||
// allways lazy | |||
component = this.createTask(taskName); | |||
return component; | |||
} | |||
/** Initialization code - implementing the original ant component | |||
* loading from /org/apache/tools/ant/taskdefs/default.properties | |||
* and .../types/default.properties | |||
* | |||
* @throws BuildException | |||
*/ | |||
public void initDefaultDefinitions() throws BuildException { | |||
project.loadDefinitions(); | |||
} | |||
/** | |||
* Adds a new task definition to the project. | |||
* Attempting to override an existing definition with an | |||
* equivalent one (i.e. with the same classname) results in | |||
* a verbose log message. Attempting to override an existing definition | |||
* with a different one results in a warning log message and | |||
* invalidates any tasks which have already been created with the | |||
* old definition. | |||
* | |||
* @param taskName The name of the task to add. | |||
* Must not be <code>null</code>. | |||
* @param taskClass The full name of the class implementing the task. | |||
* Must not be <code>null</code>. | |||
* | |||
* @exception BuildException if the class is unsuitable for being an Ant | |||
* task. An error level message is logged before | |||
* this exception is thrown. | |||
* | |||
* @see #checkTaskClass(Class) | |||
*/ | |||
public void addTaskDefinition(String taskName, Class taskClass) | |||
throws BuildException { | |||
Class old = (Class) taskClassDefinitions.get(taskName); | |||
if (null != old) { | |||
if (old.equals(taskClass)) { | |||
// project.log("Ignoring override for task " + taskName | |||
// + ", it is already defined by the same class.", | |||
// Project.MSG_VERBOSE); | |||
return; | |||
} else { | |||
int logLevel = Project.MSG_WARN; | |||
if (old.getName().equals(taskClass.getName())) { | |||
ClassLoader oldLoader = old.getClassLoader(); | |||
ClassLoader newLoader = taskClass.getClassLoader(); | |||
// system classloader on older JDKs can be null | |||
if (oldLoader != null | |||
&& newLoader != null | |||
&& oldLoader instanceof AntClassLoader | |||
&& newLoader instanceof AntClassLoader | |||
&& ((AntClassLoader) oldLoader).getClasspath() | |||
.equals(((AntClassLoader) newLoader).getClasspath()) | |||
) { | |||
// same classname loaded from the same | |||
// classpath components | |||
logLevel = Project.MSG_VERBOSE; | |||
} | |||
} | |||
project.log("Trying to override old definition of task " + taskName, | |||
logLevel); | |||
invalidateCreatedTasks(taskName); | |||
} | |||
} | |||
String msg = " +User task: " + taskName + " " + taskClass.getName(); | |||
project.log(msg, Project.MSG_DEBUG); | |||
checkTaskClass(taskClass); | |||
taskClassDefinitions.put(taskName, taskClass); | |||
} | |||
/** | |||
* Checks whether or not a class is suitable for serving as Ant task. | |||
* Ant task implementation classes must be public, concrete, and have | |||
* a no-arg constructor. | |||
* | |||
* @param taskClass The class to be checked. | |||
* Must not be <code>null</code>. | |||
* | |||
* @exception BuildException if the class is unsuitable for being an Ant | |||
* task. An error level message is logged before | |||
* this exception is thrown. | |||
*/ | |||
public void checkTaskClass(final Class taskClass) throws BuildException { | |||
if (!Modifier.isPublic(taskClass.getModifiers())) { | |||
final String message = taskClass + " is not public"; | |||
project.log(message, Project.MSG_ERR); | |||
throw new BuildException(message); | |||
} | |||
if (Modifier.isAbstract(taskClass.getModifiers())) { | |||
final String message = taskClass + " is abstract"; | |||
project.log(message, Project.MSG_ERR); | |||
throw new BuildException(message); | |||
} | |||
try { | |||
taskClass.getConstructor(null); | |||
// don't have to check for public, since | |||
// getConstructor finds public constructors only. | |||
} catch (NoSuchMethodException e) { | |||
final String message = "No public no-arg constructor in " | |||
+ taskClass; | |||
project.log(message, Project.MSG_ERR); | |||
throw new BuildException(message); | |||
} | |||
if (!Task.class.isAssignableFrom(taskClass)) { | |||
TaskAdapter.checkTaskClass(taskClass, project); | |||
} | |||
} | |||
/** | |||
* Returns the current task definition hashtable. The returned hashtable is | |||
* "live" and so should not be modified. | |||
* | |||
* @return a map of from task name to implementing class | |||
* (String to Class). | |||
*/ | |||
public Hashtable getTaskDefinitions() { | |||
return taskClassDefinitions; | |||
} | |||
/** | |||
* Adds a new datatype definition. | |||
* Attempting to override an existing definition with an | |||
* equivalent one (i.e. with the same classname) results in | |||
* a verbose log message. Attempting to override an existing definition | |||
* with a different one results in a warning log message, but the | |||
* definition is changed. | |||
* | |||
* @param typeName The name of the datatype. | |||
* Must not be <code>null</code>. | |||
* @param typeClass The full name of the class implementing the datatype. | |||
* Must not be <code>null</code>. | |||
*/ | |||
public void addDataTypeDefinition(String typeName, Class typeClass) { | |||
synchronized(dataClassDefinitions) { | |||
Class old = (Class) dataClassDefinitions.get(typeName); | |||
if (null != old) { | |||
if (old.equals(typeClass)) { | |||
// project.log("Ignoring override for datatype " + typeName | |||
// + ", it is already defined by the same class.", | |||
// Project.MSG_VERBOSE); | |||
return; | |||
} else { | |||
project.log("Trying to override old definition of datatype " | |||
+ typeName, Project.MSG_WARN); | |||
} | |||
} | |||
dataClassDefinitions.put(typeName, typeClass); | |||
} | |||
String msg = " +User datatype: " + typeName + " " | |||
+ typeClass.getName(); | |||
project.log(msg, Project.MSG_DEBUG); | |||
} | |||
/** | |||
* Returns the current datatype definition hashtable. The returned | |||
* hashtable is "live" and so should not be modified. | |||
* | |||
* @return a map of from datatype name to implementing class | |||
* (String to Class). | |||
*/ | |||
public Hashtable getDataTypeDefinitions() { | |||
return dataClassDefinitions; | |||
} | |||
/** | |||
* Creates a new instance of a task, adding it to a list of | |||
* created tasks for later invalidation. This causes all tasks | |||
* to be remembered until the containing project is removed | |||
* | |||
* Called from Project.createTask(), which can be called by tasks. | |||
* The method should be deprecated, as it doesn't support ns and libs. | |||
* | |||
* @param taskType The name of the task to create an instance of. | |||
* Must not be <code>null</code>. | |||
* | |||
* @return an instance of the specified task, or <code>null</code> if | |||
* the task name is not recognised. | |||
* | |||
* @exception BuildException if the task name is recognised but task | |||
* creation fails. | |||
*/ | |||
public Task createTask(String taskType) throws BuildException { | |||
Task task=createNewTask(taskType); | |||
if(task!=null) { | |||
addCreatedTask(taskType, task); | |||
} | |||
return task; | |||
} | |||
/** | |||
* Creates a new instance of a task. This task is not | |||
* cached in the createdTasks list. | |||
* @since ant1.6 | |||
* @param taskType The name of the task to create an instance of. | |||
* Must not be <code>null</code>. | |||
* | |||
* @return an instance of the specified task, or <code>null</code> if | |||
* the task name is not recognised. | |||
* | |||
* @exception BuildException if the task name is recognised but task | |||
* creation fails. | |||
*/ | |||
private Task createNewTask(String taskType) throws BuildException { | |||
Class c = (Class) taskClassDefinitions.get(taskType); | |||
if (c == null) { | |||
return null; | |||
} | |||
try { | |||
Object o = c.newInstance(); | |||
if ( project != null ) { | |||
project.setProjectReference( o ); | |||
} | |||
Task task = null; | |||
if (o instanceof Task) { | |||
task = (Task) o; | |||
} else { | |||
// "Generic" Bean - use the setter pattern | |||
// and an Adapter | |||
TaskAdapter taskA = new TaskAdapter(); | |||
taskA.setProxy(o); | |||
if ( project != null ) { | |||
project.setProjectReference( taskA ); | |||
} | |||
task = taskA; | |||
} | |||
task.setProject( project ); | |||
task.setTaskType(taskType); | |||
// set default value, can be changed by the user | |||
task.setTaskName(taskType); | |||
String msg = " +Task: " + taskType; | |||
project.log (msg, Project.MSG_DEBUG); | |||
return task; | |||
} catch (Throwable t) { | |||
System.out.println("task CL=" + c.getClassLoader()); | |||
String msg = "Could not create task of type: " | |||
+ taskType + " due to " + t; | |||
throw new BuildException(msg, t); | |||
} | |||
} | |||
/** | |||
* Keeps a record of all tasks that have been created so that they | |||
* can be invalidated if a new task definition overrides the current one. | |||
* | |||
* @param type The name of the type of task which has been created. | |||
* Must not be <code>null</code>. | |||
* | |||
* @param task The freshly created task instance. | |||
* Must not be <code>null</code>. | |||
*/ | |||
private void addCreatedTask(String type, Task task) { | |||
synchronized (createdTasks) { | |||
Vector v = (Vector) createdTasks.get(type); | |||
if (v == null) { | |||
v = new Vector(); | |||
createdTasks.put(type, v); | |||
} | |||
v.addElement(WeakishReference.createReference(task)); | |||
} | |||
} | |||
/** | |||
* Mark tasks as invalid which no longer are of the correct type | |||
* for a given taskname. | |||
* | |||
* @param type The name of the type of task to invalidate. | |||
* Must not be <code>null</code>. | |||
*/ | |||
private void invalidateCreatedTasks(String type) { | |||
synchronized (createdTasks) { | |||
Vector v = (Vector) createdTasks.get(type); | |||
if (v != null) { | |||
Enumeration enum = v.elements(); | |||
while (enum.hasMoreElements()) { | |||
WeakishReference ref= | |||
(WeakishReference) enum.nextElement(); | |||
Task t = (Task) ref.get(); | |||
//being a weak ref, it may be null by this point | |||
if(t!=null) { | |||
t.markInvalid(); | |||
} | |||
} | |||
v.removeAllElements(); | |||
createdTasks.remove(type); | |||
} | |||
} | |||
} | |||
/** | |||
* Creates a new instance of a data type. | |||
* | |||
* @param typeName The name of the data type to create an instance of. | |||
* Must not be <code>null</code>. | |||
* | |||
* @return an instance of the specified data type, or <code>null</code> if | |||
* the data type name is not recognised. | |||
* | |||
* @exception BuildException if the data type name is recognised but | |||
* instance creation fails. | |||
*/ | |||
public Object createDataType(String typeName) throws BuildException { | |||
Class c = (Class) dataClassDefinitions.get(typeName); | |||
if (c == null) { | |||
return null; | |||
} | |||
try { | |||
java.lang.reflect.Constructor ctor = null; | |||
boolean noArg = false; | |||
// DataType can have a "no arg" constructor or take a single | |||
// Project argument. | |||
try { | |||
ctor = c.getConstructor(new Class[0]); | |||
noArg = true; | |||
} catch (NoSuchMethodException nse) { | |||
ctor = c.getConstructor(new Class[] {Project.class}); | |||
noArg = false; | |||
} | |||
Object o = null; | |||
if (noArg) { | |||
o = ctor.newInstance(new Object[0]); | |||
} else { | |||
o = ctor.newInstance(new Object[] {project}); | |||
} | |||
if ( project != null ) { | |||
project.setProjectReference( o ); | |||
} | |||
String msg = " +DataType: " + typeName; | |||
project.log(msg, Project.MSG_DEBUG); | |||
return o; | |||
} catch (java.lang.reflect.InvocationTargetException ite) { | |||
Throwable t = ite.getTargetException(); | |||
String msg = "Could not create datatype of type: " | |||
+ typeName + " due to " + t; | |||
throw new BuildException(msg, t); | |||
} catch (Throwable t) { | |||
String msg = "Could not create datatype of type: " | |||
+ typeName + " due to " + t; | |||
throw new BuildException(msg, t); | |||
} | |||
} | |||
/** | |||
* Returns a description of the type of the given element, with | |||
* special handling for instances of tasks and data types. | |||
* <p> | |||
* This is useful for logging purposes. | |||
* | |||
* @param element The element to describe. | |||
* Must not be <code>null</code>. | |||
* | |||
* @return a description of the element type | |||
* | |||
* @since Ant 1.6 | |||
*/ | |||
public String getElementName(Object element) { | |||
Hashtable elements = taskClassDefinitions; | |||
Class elementClass = element.getClass(); | |||
String typeName = "task"; | |||
if (!elements.contains(elementClass)) { | |||
elements = dataClassDefinitions; | |||
typeName = "data type"; | |||
if (!elements.contains(elementClass)) { | |||
elements = null; | |||
} | |||
} | |||
if (elements != null) { | |||
Enumeration e = elements.keys(); | |||
while (e.hasMoreElements()) { | |||
String name = (String) e.nextElement(); | |||
Class clazz = (Class) elements.get(name); | |||
if (elementClass.equals(clazz)) { | |||
return "The <" + name + "> " + typeName; | |||
} | |||
} | |||
} | |||
return "Class " + elementClass.getName(); | |||
} | |||
private static class AntTaskTable extends LazyHashtable { | |||
Project project; | |||
Properties props; | |||
boolean tasks=false; | |||
public AntTaskTable( Project p, boolean tasks ) { | |||
this.project=p; | |||
this.tasks=tasks; | |||
} | |||
public void addDefinitions( Properties props ) { | |||
this.props=props; | |||
} | |||
protected void initAll( ) { | |||
if( initAllDone ) { | |||
return; | |||
} | |||
project.log("InitAll", Project.MSG_DEBUG); | |||
if( props==null ) { | |||
return; | |||
} | |||
Enumeration enum = props.propertyNames(); | |||
while (enum.hasMoreElements()) { | |||
String key = (String) enum.nextElement(); | |||
Class taskClass=getTask( key ); | |||
if( taskClass!=null ) { | |||
// This will call a get() and a put() | |||
if( tasks ) { | |||
project.addTaskDefinition(key, taskClass); | |||
} else { | |||
project.addDataTypeDefinition(key, taskClass ); | |||
} | |||
} | |||
} | |||
initAllDone=true; | |||
} | |||
protected Class getTask(String key) { | |||
if( props==null ) { | |||
return null; // for tasks loaded before init() | |||
} | |||
String value=props.getProperty(key); | |||
if( value==null) { | |||
//project.log( "No class name for " + key, Project.MSG_VERBOSE ); | |||
return null; | |||
} | |||
try { | |||
Class taskClass=null; | |||
if( project.getCoreLoader() != null && | |||
!("only".equals(project.getProperty("build.sysclasspath")))) { | |||
try { | |||
project.log("Loading with the core loader " + value, | |||
Project.MSG_DEBUG); | |||
taskClass=project.getCoreLoader().loadClass(value); | |||
if( taskClass != null ) { | |||
return taskClass; | |||
} | |||
} catch( Exception ex ) { | |||
//ignore | |||
} | |||
} | |||
taskClass = Class.forName(value); | |||
return taskClass; | |||
} catch (NoClassDefFoundError ncdfe) { | |||
project.log("Could not load a dependent class (" | |||
+ ncdfe.getMessage() + ") for task " | |||
+ key, Project.MSG_DEBUG); | |||
} catch (ClassNotFoundException cnfe) { | |||
project.log("Could not load class (" + value | |||
+ ") for task " + key, Project.MSG_DEBUG); | |||
} | |||
return null; | |||
} | |||
// Hashtable implementation | |||
public Object get( Object key ) { | |||
Object orig=super.get( key ); | |||
if( orig!= null ) { | |||
return orig; | |||
} | |||
if( ! (key instanceof String) ) { | |||
return null; | |||
} | |||
project.log("Get task " + key, Project.MSG_DEBUG ); | |||
Object taskClass=getTask( (String) key); | |||
if( taskClass != null) { | |||
super.put( key, taskClass ); | |||
} | |||
return taskClass; | |||
} | |||
public boolean containsKey( Object key ) { | |||
return get( key ) != null; | |||
} | |||
} | |||
} |
@@ -1,74 +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.tools.ant; | |||
public interface RoleAdapter { | |||
/** | |||
* Obtain the id in case it is needed. | |||
*/ | |||
public void setId(String id); | |||
/** | |||
* Set the object being adapted. | |||
* @param o the object being adapted | |||
*/ | |||
public void setProxy(Object o); | |||
/** | |||
* Get the object adapted by this class. | |||
* @return the object being adapted, if any. | |||
*/ | |||
public Object getProxy(); | |||
} |
@@ -1,561 +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.tools.ant; | |||
import java.lang.reflect.InvocationTargetException; | |||
import java.lang.reflect.Constructor; | |||
import java.lang.reflect.Method; | |||
import java.lang.reflect.Modifier; | |||
import java.util.*; | |||
import org.apache.tools.ant.types.Path; | |||
public class SymbolTable { | |||
/** Parent symbol table */ | |||
private SymbolTable parentTable; | |||
/** Project associated with this symbol table */ | |||
private Project project; | |||
/** The table of roles available to this Project */ | |||
private Hashtable roles = new Hashtable(); | |||
/** The table of loaders active on this Project */ | |||
private Hashtable loaders = new Hashtable(); | |||
/** | |||
* Table of per role definitions. | |||
*/ | |||
private Hashtable defs = new Hashtable(); | |||
/** | |||
* Parameters for checking adapters. | |||
*/ | |||
private static final Class[] CHECK_ADAPTER_PARAMS = | |||
new Class[]{Class.class, Project.class}; | |||
/** | |||
* Create a top level Symbol table. | |||
*/ | |||
public SymbolTable() { | |||
} | |||
/** | |||
* Create a symbol table inheriting the definitions | |||
* from that defined in the calling Project. | |||
* @param st the calling project | |||
*/ | |||
public SymbolTable(SymbolTable st) { | |||
parentTable = st; | |||
} | |||
/** | |||
* Set the project associated with this symbol table. | |||
* @param p the project for this symbol table | |||
*/ | |||
public void setProject(Project p) { | |||
this.project = p; | |||
} | |||
/** | |||
* Get the specified loader for the project. | |||
* @param name the name of the loader | |||
* @return the corresponding ANT classloader | |||
*/ | |||
private AntClassLoader getLoader(String name) { | |||
AntClassLoader cl = (AntClassLoader) loaders.get(name); | |||
if (cl == null && parentTable != null) { | |||
return parentTable.getLoader(name); | |||
} | |||
return cl; | |||
} | |||
/** | |||
* Add the specified class-path to a loader. | |||
* If the loader is defined in an ancestor project then a new | |||
* classloader inheritin from the one already existing | |||
* will be created, otherwise the path willbe added to the existing | |||
* ClassLoader. | |||
* @param name the name of the loader to use. | |||
* @param clspath the path to be added to the classloader | |||
*/ | |||
public ClassLoader addToLoader(String name, Path clspath) { | |||
// Find if the loader is already defined in the current project | |||
AntClassLoader cl = (AntClassLoader) loaders.get(name); | |||
if (cl == null) { | |||
// Is it inherited from the calling project | |||
if (parentTable != null) { | |||
cl = parentTable.getLoader(name); | |||
} | |||
cl = new AntClassLoader(cl, project, clspath, true); | |||
loaders.put(name, cl); | |||
} | |||
else { | |||
// Add additional path to the existing definition | |||
String[] pathElements = clspath.list(); | |||
for (int i = 0; i < pathElements.length; ++i) { | |||
try { | |||
cl.addPathElement(pathElements[i]); | |||
} | |||
catch (BuildException e) { | |||
// ignore path elements invalid relative to the project | |||
} | |||
} | |||
} | |||
return cl; | |||
} | |||
/** | |||
* Find all the roles supported by a Class | |||
* on this symbol table. | |||
* @param clz the class to analyze | |||
* @return an array of roles supported by the class | |||
*/ | |||
public String[] findRoles(final Class clz) { | |||
Vector list = new Vector(); | |||
findRoles(clz, list); | |||
return (String[])list.toArray(new String[list.size()]); | |||
} | |||
/** | |||
* Collect the roles for the class | |||
* @param clz the class being inspected | |||
* @param list the roles collected up to this point | |||
*/ | |||
private void findRoles(final Class clz, Vector list) { | |||
for (Enumeration e = roles.keys(); e.hasMoreElements();) { | |||
String role = (String) e.nextElement(); | |||
if (((Role) roles.get(role)).isImplementedBy(clz)) { | |||
list.addElement(role); | |||
} | |||
} | |||
if (parentTable != null) parentTable.findRoles(clz, list); | |||
} | |||
/** | |||
* Get the Role definition | |||
* @param role the name of the role | |||
* @return the Role description | |||
*/ | |||
public Role getRole(String role) { | |||
Role r = (Role) roles.get(role); | |||
if (r == null && parentTable != null) { | |||
return parentTable.getRole(role); | |||
} | |||
return r; | |||
} | |||
/** | |||
* Add a new role definition to this project. | |||
* @param role the name of the role | |||
* @param rclz the interface used to specify support for the role. | |||
* @param aclz the optional adapter class | |||
* @return whether the role replaced a different definition | |||
*/ | |||
public boolean addRole(String role, Class rclz, Class aclz) { | |||
// Check if role already declared | |||
Role old = getRole(role); | |||
if (old != null && old.isSameAsFor(rclz, aclz)) { | |||
project.log("Ignoring override for role " + role | |||
+ ", it is already defined by the same definition.", | |||
project.MSG_VERBOSE); | |||
return false; | |||
} | |||
// Role interfaces should only contain one method | |||
roles.put(role, new Role(rclz, aclz)); | |||
return (old != null); | |||
} | |||
/** | |||
* Add a new type of element to a role. | |||
* @param role the role for this Class. | |||
* @param name the name of the element for this Class | |||
* @param clz the Class being declared | |||
* @return the old definition | |||
*/ | |||
public Class add(String role, String name, Class clz) { | |||
// Find the role definition | |||
Role r = getRole(role); | |||
if (r == null) { | |||
throw new BuildException("Unknown role: " + role); | |||
} | |||
// Check if it is already defined | |||
Factory old = get(role, name); | |||
if (old != null) { | |||
if (old.getOriginalClass().equals(clz)) { | |||
project.log("Ignoring override for "+ role + " " + name | |||
+ ", it is already defined by the same class.", | |||
project.MSG_VERBOSE); | |||
return old.getOriginalClass(); | |||
} | |||
else { | |||
project.log("Trying to override old definition of " + | |||
role + " " + name, | |||
project.MSG_WARN); | |||
} | |||
} | |||
Factory f = checkClass(clz); | |||
// Check that the Class is compatible with the role definition | |||
f = r.verifyAdaptability(role, f); | |||
// Record the new type | |||
Hashtable defTable = (Hashtable)defs.get(role); | |||
if (defTable == null) { | |||
defTable = new Hashtable(); | |||
defs.put(role, defTable); | |||
} | |||
defTable.put(name, f); | |||
String msg = | |||
" +User " + role + ": " + name + " " + clz.getName(); | |||
project.log(msg, project.MSG_DEBUG); | |||
return (old != null ? old.getOriginalClass() : null); | |||
} | |||
/** | |||
* Checks a class, whether it is suitable for serving in ANT. | |||
* @return the factory to use when instantiating the class | |||
* @throws BuildException and logs as Project.MSG_ERR for | |||
* conditions, that will cause execution to fail. | |||
*/ | |||
Factory checkClass(final Class clz) // Package on purpose | |||
throws BuildException { | |||
if (clz == null) return null; | |||
if(!Modifier.isPublic(clz.getModifiers())) { | |||
final String message = clz + " is not public"; | |||
project.log(message, Project.MSG_ERR); | |||
throw new BuildException(message); | |||
} | |||
if(Modifier.isAbstract(clz.getModifiers())) { | |||
final String message = clz + " is abstract"; | |||
project.log(message, Project.MSG_ERR); | |||
throw new BuildException(message); | |||
} | |||
try { | |||
// Class can have a "no arg" constructor or take a single | |||
// Project argument. | |||
// don't have to check for public, since | |||
// getConstructor finds public constructors only. | |||
try { | |||
clz.getConstructor(new Class[0]); | |||
return new Factory(){ | |||
public Object create(Project p) { | |||
try { | |||
return clz.newInstance(); | |||
} | |||
catch(Exception e) { | |||
throw new BuildException(e); | |||
} | |||
} | |||
public Class getOriginalClass() { | |||
return clz; | |||
} | |||
}; | |||
} catch (NoSuchMethodException nse) { | |||
final Constructor c = | |||
clz.getConstructor(new Class[] {Project.class}); | |||
return new Factory(){ | |||
public Object create(Project p) { | |||
try { | |||
return c.newInstance(new Object[]{p}); | |||
} | |||
catch(Exception e) { | |||
throw new BuildException(e); | |||
} | |||
} | |||
public Class getOriginalClass() { | |||
return clz; | |||
} | |||
}; | |||
} | |||
} catch(NoSuchMethodException e) { | |||
final String message = "No valid public constructor in " + clz; | |||
project.log(message, Project.MSG_ERR); | |||
throw new BuildException(message); | |||
} | |||
catch (NoClassDefFoundError ncdfe) { | |||
final String msg = "Class cannot be loaded: " + ncdfe.getMessage(); | |||
throw new BuildException(msg, ncdfe); | |||
} | |||
} | |||
/** | |||
* Get the class in the role identified with the element name. | |||
* @param role the role to look into. | |||
* @param name the name of the element to sea | |||
* @return the Class implementation | |||
*/ | |||
public Factory get(String role, String name) { | |||
Hashtable defTable = (Hashtable)defs.get(role); | |||
if (defTable != null) { | |||
Factory f = (Factory)defTable.get(name); | |||
if (f != null) return f; | |||
} | |||
if (parentTable != null) { | |||
return parentTable.get(role, name); | |||
} | |||
return null; | |||
} | |||
/** | |||
* Get a Hashtable that is usable for manipulating elements on Role. | |||
* @param role the role of the elements in the table | |||
* @return a Hashtable that delegates to the Symbol table. | |||
*/ | |||
Hashtable getDefinitions(String role) { // package scope on purpose | |||
return new SymbolHashtable(role); | |||
} | |||
/** | |||
* Hashtable implementation that delegates | |||
* the search operations to the Symbol table | |||
*/ | |||
private class SymbolHashtable extends Hashtable { | |||
final String role; | |||
SymbolHashtable(String role) { | |||
this.role = role; | |||
} | |||
public synchronized Object put(Object key, Object value) { | |||
return SymbolTable.this.add(role, (String) key, (Class) value); | |||
} | |||
public synchronized Object get(Object key) { | |||
Factory f = SymbolTable.this.get(role, (String)key); | |||
return (f == null? null : f.getOriginalClass()); | |||
} | |||
} | |||
/** | |||
* Factory for creating ANT objects. | |||
* Class objects are not instanciated directly but through a Factory | |||
* which is able to resolve issues such as proxys and such. | |||
*/ | |||
public static interface Factory { | |||
/** | |||
* Creates an object for the Role | |||
* @param p the project in which it is created | |||
* @return the instantiated object with a proxy if necessary | |||
*/ | |||
public Object create(Project p); | |||
/** | |||
* Creates an object for the Role, adapted if necessary | |||
* for a particular interface. | |||
*/ | |||
// public Object adaptFor(Class clz, Project p, Object o); | |||
/** | |||
* The original class of the object without proxy. | |||
*/ | |||
public Class getOriginalClass(); | |||
} | |||
/** | |||
* The definition of a role | |||
*/ | |||
public class Role { | |||
private Method interfaceMethod; | |||
private Method adapterVerifier; | |||
private Factory adapterFactory; | |||
/** | |||
* Creates a new Role object | |||
* @param roleClz the class that defines the role | |||
* @param adapterClz the class for the adapter, or null if none | |||
*/ | |||
Role(Class roleClz, Class adapterClz) { | |||
interfaceMethod = validInterface(roleClz); | |||
adapterFactory = checkClass(adapterClz); | |||
adapterVerifier = validAdapter(adapterClz, interfaceMethod); | |||
} | |||
/** | |||
* Get the method used to set on interface | |||
*/ | |||
public Method getInterfaceMethod() { | |||
return interfaceMethod; | |||
} | |||
/** | |||
* Instantiate a new adapter for this role. | |||
*/ | |||
public RoleAdapter createAdapter(Project p) { | |||
if (adapterFactory == null) return null; | |||
try { | |||
return (RoleAdapter) adapterFactory.create(p); | |||
} | |||
catch(BuildException be) { | |||
throw be; | |||
} | |||
catch(Exception e) { | |||
throw new BuildException(e); | |||
} | |||
} | |||
/** | |||
* Verify if the class can be adapted to use by the role | |||
* @param role the name of the role to verify | |||
* @param f the factory for the class to verify | |||
*/ | |||
public Factory verifyAdaptability(String role, final Factory f) { | |||
final Class clz = f.getOriginalClass(); | |||
if (interfaceMethod.getParameterTypes()[0].isAssignableFrom(clz)) { | |||
return f; | |||
} | |||
if (adapterVerifier == null) { | |||
String msg = "Class " + clz.getName() + | |||
" incompatible with role: " + role; | |||
throw new BuildException(msg); | |||
} | |||
try { | |||
try { | |||
adapterVerifier.invoke(null, new Object[]{clz, project}); | |||
return new Factory(){ | |||
public Object create(Project p) { | |||
RoleAdapter ra = createAdapter(p); | |||
ra.setProxy(f.create(p)); | |||
return ra; | |||
} | |||
public Class getOriginalClass() { | |||
return clz; | |||
} | |||
}; | |||
} | |||
catch (InvocationTargetException ite) { | |||
throw ite.getTargetException(); | |||
} | |||
} | |||
catch(BuildException be) { throw be; } | |||
catch(Error err) {throw err; } | |||
catch(Throwable t) { | |||
throw new BuildException(t); | |||
} | |||
} | |||
public boolean isSameAsFor(Class clz, Class pclz) { | |||
return interfaceMethod.getDeclaringClass().equals(clz) && | |||
((adapterVerifier == null && pclz == null) || | |||
adapterVerifier.getDeclaringClass().equals(pclz)); | |||
} | |||
public boolean isImplementedBy(Class clz) { | |||
return interfaceMethod.getDeclaringClass().isAssignableFrom(clz); | |||
} | |||
/** | |||
* Verify if the interface is valid. | |||
* @param clz the interface to validate | |||
* @return the method defined by the interface | |||
*/ | |||
private Method validInterface(Class clz) { | |||
Method m[] = clz.getDeclaredMethods(); | |||
if (m.length == 1 | |||
&& java.lang.Void.TYPE.equals(m[0].getReturnType())) { | |||
Class args[] = m[0].getParameterTypes(); | |||
if (args.length == 1 | |||
&& !java.lang.String.class.equals(args[0]) | |||
&& !args[0].isArray() | |||
&& !args[0].isPrimitive()) { | |||
return m[0]; | |||
} | |||
else { | |||
throw new BuildException("Invalid role interface method in: " | |||
+ clz.getName()); | |||
} | |||
} | |||
else { | |||
throw new BuildException("More than one method on role interface"); | |||
} | |||
} | |||
/** | |||
* Verify if the adapter is valid with respect to the interface. | |||
* @param clz the class adapter to validate | |||
* @param mtd the method whose only argument must match | |||
* @return the static method to use for validating adaptees | |||
*/ | |||
private Method validAdapter(Class clz, Method mtd) { | |||
if (clz == null) return null; | |||
if (!mtd.getParameterTypes()[0].isAssignableFrom(clz)) { | |||
String msg = "Adapter " + clz.getName() + | |||
" is incompatible with role interface " + | |||
mtd.getDeclaringClass().getName(); | |||
throw new BuildException(msg); | |||
} | |||
String msg = "Class " + clz.getName() + " is not an adapter: "; | |||
if (!RoleAdapter.class.isAssignableFrom(clz)) { | |||
throw new BuildException(msg + "does not implement RoleAdapter"); | |||
} | |||
try { | |||
Method chk = clz.getMethod("checkClass", CHECK_ADAPTER_PARAMS); | |||
if (!Modifier.isStatic(chk.getModifiers())) { | |||
throw new BuildException(msg + "checkClass() is not static"); | |||
} | |||
return chk; | |||
} | |||
catch(NoSuchMethodException nme){ | |||
throw new BuildException(msg + "checkClass() not found", nme); | |||
} | |||
} | |||
} | |||
} |
@@ -1,176 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2000-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.tools.ant; | |||
import java.lang.reflect.Method; | |||
import java.lang.reflect.InvocationTargetException; | |||
/** | |||
* Use introspection to "adapt" an arbitrary Bean ( not extending Task, but with similar | |||
* patterns). | |||
* | |||
* @author costin@dnt.ro | |||
* @author j_a_fernandez@yahoo.com | |||
*/ | |||
public class TaskAdapter extends Task implements RoleAdapter { | |||
Object proxy; | |||
/** | |||
* Checks a class, whether it is suitable to be adapted by TaskAdapter. | |||
* | |||
* Checks conditions only, which are additionally required for a tasks | |||
* adapted by TaskAdapter. Thus, this method should be called by | |||
* {@link Project#checkTaskClass}. | |||
* | |||
* Throws a BuildException and logs as Project.MSG_ERR for | |||
* conditions, that will cause the task execution to fail. | |||
* Logs other suspicious conditions with Project.MSG_WARN. | |||
*/ | |||
public static void checkTaskClass(final Class taskClass, final Project project) { | |||
// This code is for backward compatibility | |||
checkClass(taskClass, project); | |||
} | |||
/** | |||
* Checks a class, whether it is suitable to be adapted. | |||
* | |||
* Checks conditions only, which are additionally required for a tasks | |||
* adapted by TaskAdapter. | |||
* | |||
* Throws a BuildException and logs as Project.MSG_ERR for | |||
* conditions, that will cause the task execution to fail. | |||
* Logs other suspicious conditions with Project.MSG_WARN. | |||
*/ | |||
public static void checkClass(final Class taskClass, final Project project) { | |||
// don't have to check for interface, since then | |||
// taskClass would be abstract too. | |||
try { | |||
final Method executeM = taskClass.getMethod( "execute", null ); | |||
// don't have to check for public, since | |||
// getMethod finds public method only. | |||
// don't have to check for abstract, since then | |||
// taskClass would be abstract too. | |||
if(!Void.TYPE.equals(executeM.getReturnType())) { | |||
final String message = "return type of execute() should be void but was \""+executeM.getReturnType()+"\" in " + taskClass; | |||
project.log(message, Project.MSG_WARN); | |||
} | |||
} catch(NoSuchMethodException e) { | |||
final String message = "No public execute() in " + taskClass; | |||
project.log(message, Project.MSG_ERR); | |||
throw new BuildException(message); | |||
} | |||
} | |||
/** | |||
* Do the execution. | |||
*/ | |||
public void execute() throws BuildException { | |||
Method setProjectM = null; | |||
try { | |||
Class c = proxy.getClass(); | |||
setProjectM = | |||
c.getMethod( "setProject", new Class[] {Project.class}); | |||
if(setProjectM != null) { | |||
setProjectM.invoke(proxy, new Object[] {project}); | |||
} | |||
} catch (NoSuchMethodException e) { | |||
// ignore this if the class being used as a task does not have | |||
// a set project method. | |||
} catch( Exception ex ) { | |||
log("Error setting project in " + proxy.getClass(), | |||
Project.MSG_ERR); | |||
throw new BuildException( ex ); | |||
} | |||
Method executeM=null; | |||
try { | |||
Class c=proxy.getClass(); | |||
executeM=c.getMethod( "execute", new Class[0] ); | |||
if( executeM == null ) { | |||
log("No public execute() in " + proxy.getClass(), Project.MSG_ERR); | |||
throw new BuildException("No public execute() in " + proxy.getClass()); | |||
} | |||
executeM.invoke(proxy, null); | |||
return; | |||
} catch( InvocationTargetException ite ) { | |||
Throwable t = ite.getTargetException(); | |||
if (t instanceof BuildException) { | |||
throw (BuildException) t; | |||
} | |||
throw new BuildException(t); | |||
} catch( Exception ex ) { | |||
log("Error in " + proxy.getClass(), Project.MSG_ERR); | |||
throw new BuildException( ex ); | |||
} | |||
} | |||
/** | |||
* Set the target object class | |||
*/ | |||
public void setProxy(Object o) { | |||
this.proxy = o; | |||
} | |||
public Object getProxy() { | |||
return this.proxy ; | |||
} | |||
public void setId(String id) {} | |||
} |
@@ -1,161 +0,0 @@ | |||
<?xml version='1.0' ?> | |||
<!-- | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2000-2002 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/>. | |||
--> | |||
<antlib version="1.5" > | |||
<task name="mkdir" class="org.apache.tools.ant.taskdefs.Mkdir"/> | |||
<task name="javac" class="org.apache.tools.ant.taskdefs.Javac"/> | |||
<task name="chmod" class="org.apache.tools.ant.taskdefs.Chmod"/> | |||
<task name="delete" class="org.apache.tools.ant.taskdefs.Delete"/> | |||
<task name="copy" class="org.apache.tools.ant.taskdefs.Copy"/> | |||
<task name="move" class="org.apache.tools.ant.taskdefs.Move"/> | |||
<task name="jar" class="org.apache.tools.ant.taskdefs.Jar"/> | |||
<task name="rmic" class="org.apache.tools.ant.taskdefs.Rmic"/> | |||
<task name="cvs" class="org.apache.tools.ant.taskdefs.Cvs"/> | |||
<task name="get" class="org.apache.tools.ant.taskdefs.Get"/> | |||
<task name="unzip" class="org.apache.tools.ant.taskdefs.Expand"/> | |||
<task name="unjar" class="org.apache.tools.ant.taskdefs.Expand"/> | |||
<task name="unwar" class="org.apache.tools.ant.taskdefs.Expand"/> | |||
<task name="echo" class="org.apache.tools.ant.taskdefs.Echo"/> | |||
<task name="javadoc" class="org.apache.tools.ant.taskdefs.Javadoc"/> | |||
<task name="zip" class="org.apache.tools.ant.taskdefs.Zip"/> | |||
<task name="gzip" class="org.apache.tools.ant.taskdefs.GZip"/> | |||
<task name="gunzip" class="org.apache.tools.ant.taskdefs.GUnzip"/> | |||
<task name="replace" class="org.apache.tools.ant.taskdefs.Replace"/> | |||
<task name="java" class="org.apache.tools.ant.taskdefs.Java"/> | |||
<task name="tstamp" class="org.apache.tools.ant.taskdefs.Tstamp"/> | |||
<task name="property" class="org.apache.tools.ant.taskdefs.Property"/> | |||
<task name="xmlproperty" class="org.apache.tools.ant.taskdefs.XmlProperty"/> | |||
<task name="taskdef" class="org.apache.tools.ant.taskdefs.Taskdef"/> | |||
<task name="ant" class="org.apache.tools.ant.taskdefs.Ant"/> | |||
<task name="exec" class="org.apache.tools.ant.taskdefs.ExecTask"/> | |||
<task name="tar" class="org.apache.tools.ant.taskdefs.Tar"/> | |||
<task name="untar" class="org.apache.tools.ant.taskdefs.Untar"/> | |||
<task name="available" class="org.apache.tools.ant.taskdefs.Available"/> | |||
<task name="filter" class="org.apache.tools.ant.taskdefs.Filter"/> | |||
<task name="fixcrlf" class="org.apache.tools.ant.taskdefs.FixCRLF"/> | |||
<task name="patch" class="org.apache.tools.ant.taskdefs.Patch"/> | |||
<task name="style" class="org.apache.tools.ant.taskdefs.XSLTProcess"/> | |||
<task name="xslt" class="org.apache.tools.ant.taskdefs.XSLTProcess"/> | |||
<task name="touch" class="org.apache.tools.ant.taskdefs.Touch"/> | |||
<task name="signjar" class="org.apache.tools.ant.taskdefs.SignJar"/> | |||
<task name="genkey" class="org.apache.tools.ant.taskdefs.GenerateKey"/> | |||
<task name="antstructure" class="org.apache.tools.ant.taskdefs.AntStructure"/> | |||
<task name="execon" class="org.apache.tools.ant.taskdefs.ExecuteOn"/> | |||
<task name="antcall" class="org.apache.tools.ant.taskdefs.CallTarget"/> | |||
<task name="sql" class="org.apache.tools.ant.taskdefs.SQLExec"/> | |||
<task name="mail" class="org.apache.tools.ant.taskdefs.email.EmailTask"/> | |||
<task name="fail" class="org.apache.tools.ant.taskdefs.Exit"/> | |||
<task name="war" class="org.apache.tools.ant.taskdefs.War"/> | |||
<task name="uptodate" class="org.apache.tools.ant.taskdefs.UpToDate"/> | |||
<task name="apply" class="org.apache.tools.ant.taskdefs.Transform"/> | |||
<task name="record" class="org.apache.tools.ant.taskdefs.Recorder"/> | |||
<task name="cvspass" class="org.apache.tools.ant.taskdefs.CVSPass"/> | |||
<task name="typedef" class="org.apache.tools.ant.taskdefs.Typedef"/> | |||
<task name="sleep" class="org.apache.tools.ant.taskdefs.Sleep"/> | |||
<task name="pathconvert" class="org.apache.tools.ant.taskdefs.PathConvert"/> | |||
<task name="ear" class="org.apache.tools.ant.taskdefs.Ear"/> | |||
<task name="parallel" class="org.apache.tools.ant.taskdefs.Parallel"/> | |||
<task name="sequential" class="org.apache.tools.ant.taskdefs.Sequential"/> | |||
<task name="condition" class="org.apache.tools.ant.taskdefs.ConditionTask"/> | |||
<task name="dependset" class="org.apache.tools.ant.taskdefs.DependSet"/> | |||
<task name="bzip2" class="org.apache.tools.ant.taskdefs.BZip2"/> | |||
<task name="bunzip2" class="org.apache.tools.ant.taskdefs.BUnzip2"/> | |||
<task name="checksum" class="org.apache.tools.ant.taskdefs.Checksum"/> | |||
<task name="waitfor" class="org.apache.tools.ant.taskdefs.WaitFor"/> | |||
<task name="input" class="org.apache.tools.ant.taskdefs.Input"/> | |||
<task name="loadfile" class="org.apache.tools.ant.taskdefs.LoadFile"/> | |||
<task name="manifest" class="org.apache.tools.ant.taskdefs.ManifestTask"/> | |||
<task name="loadproperties" class="org.apache.tools.ant.taskdefs.LoadProperties"/> | |||
<task name="basename" class="org.apache.tools.ant.taskdefs.Basename"/> | |||
<task name="dirname" class="org.apache.tools.ant.taskdefs.Dirname"/> | |||
<task name="cvschangelog" class="org.apache.tools.ant.taskdefs.cvslib.ChangeLogTask"/> | |||
<task name="buildnumber" class="org.apache.tools.ant.taskdefs.BuildNumber"/> | |||
<task name="concat" class="org.apache.tools.ant.taskdefs.Concat"/> | |||
<task name="cvstagdiff" class="org.apache.tools.ant.taskdefs.cvslib.CvsTagDiff"/> | |||
<task name="tempfile" class="org.apache.tools.ant.taskdefs.TempFile"/> | |||
<task name="classloader" class="org.apache.tools.ant.taskdefs.Classloader"/> | |||
<task name="import" class="org.apache.tools.ant.taskdefs.ImportTask"/> | |||
<task name="whichresource" class="org.apache.tools.ant.taskdefs.WhichResource"/> | |||
<task name="subant" class="org.apache.tools.ant.taskdefs.SubAnt"/> | |||
<task name="sync" class="org.apache.tools.ant.taskdefs.Sync"/> | |||
<task name="antjar" class="org.apache.tools.ant.taskdefs.Antjar"/> | |||
<task name="antlib" class="org.apache.tools.ant.taskdefs.Antlib"/> | |||
<!-- deprecated ant tasks (kept for back compatibility) --> | |||
<task name="javadoc2" class="org.apache.tools.ant.taskdefs.Javadoc"/> | |||
<task name="copydir" class="org.apache.tools.ant.taskdefs.Copydir"/> | |||
<task name="copyfile" class="org.apache.tools.ant.taskdefs.Copyfile"/> | |||
<task name="deltree" class="org.apache.tools.ant.taskdefs.Deltree"/> | |||
<task name="rename" class="org.apache.tools.ant.taskdefs.Rename"/> | |||
<data-type name="description" class="org.apache.tools.ant.types.Description"/> | |||
<data-type name="dirset" class="org.apache.tools.ant.types.DirSet"/> | |||
<data-type name="filelist" class="org.apache.tools.ant.types.FileList"/> | |||
<data-type name="fileset" class="org.apache.tools.ant.types.FileSet"/> | |||
<data-type name="filterchain" class="org.apache.tools.ant.types.FilterChain"/> | |||
<data-type name="filterreader" class="org.apache.tools.ant.types.AntFilterReader"/> | |||
<data-type name="filterset" class="org.apache.tools.ant.types.FilterSet"/> | |||
<data-type name="mapper" class="org.apache.tools.ant.types.Mapper"/> | |||
<data-type name="path" class="org.apache.tools.ant.types.Path"/> | |||
<data-type name="patternset" class="org.apache.tools.ant.types.PatternSet"/> | |||
<data-type name="regexp" class="org.apache.tools.ant.types.RegularExpression"/> | |||
<data-type name="substitution" class="org.apache.tools.ant.types.Substitution"/> | |||
<data-type name="xmlcatalog" class="org.apache.tools.ant.types.XMLCatalog"/> | |||
<data-type name="extensionSet" class="org.apache.tools.ant.taskdefs.optional.extension.ExtensionSet"/> | |||
<data-type name="extension" class="org.apache.tools.ant.taskdefs.optional.extension.ExtensionAdapter"/> | |||
<data-type name="libfileset" class="org.apache.tools.ant.taskdefs.optional.extension.LibFileSet"/> | |||
<data-type name="selector" class="org.apache.tools.ant.types.selectors.SelectSelector"/> | |||
<data-type name="zipfileset" class="org.apache.tools.ant.types.ZipFileSet"/> | |||
</antlib> |
@@ -1,179 +0,0 @@ | |||
<?xml version='1.0' ?> | |||
<!-- | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2000-2002 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/>. | |||
--> | |||
<antlib version="1.5" > | |||
<!-- Declaration of optional tasks --> | |||
<task name="image" class="org.apache.tools.ant.taskdefs.optional.image.Image"/> | |||
<task name="script" class="org.apache.tools.ant.taskdefs.optional.Script"/> | |||
<task name="netrexxc" class="org.apache.tools.ant.taskdefs.optional.NetRexxC"/> | |||
<task name="renameext" class="org.apache.tools.ant.taskdefs.optional.RenameExtensions"/> | |||
<task name="ejbc" class="org.apache.tools.ant.taskdefs.optional.ejb.Ejbc"/> | |||
<task name="ddcreator" class="org.apache.tools.ant.taskdefs.optional.ejb.DDCreator"/> | |||
<task name="wlrun" class="org.apache.tools.ant.taskdefs.optional.ejb.WLRun"/> | |||
<task name="wlstop" class="org.apache.tools.ant.taskdefs.optional.ejb.WLStop"/> | |||
<task name="vssadd" class="org.apache.tools.ant.taskdefs.optional.vss.MSVSSADD"/> | |||
<task name="vsscheckin" class="org.apache.tools.ant.taskdefs.optional.vss.MSVSSCHECKIN"/> | |||
<task name="vsscheckout" class="org.apache.tools.ant.taskdefs.optional.vss.MSVSSCHECKOUT"/> | |||
<task name="vsscp" class="org.apache.tools.ant.taskdefs.optional.vss.MSVSSCP"/> | |||
<task name="vsscreate" class="org.apache.tools.ant.taskdefs.optional.vss.MSVSSCREATE"/> | |||
<task name="vssget" class="org.apache.tools.ant.taskdefs.optional.vss.MSVSSGET"/> | |||
<task name="vsshistory" class="org.apache.tools.ant.taskdefs.optional.vss.MSVSSHISTORY"/> | |||
<task name="vsslabel" class="org.apache.tools.ant.taskdefs.optional.vss.MSVSSLABEL"/> | |||
<task name="ejbjar" class="org.apache.tools.ant.taskdefs.optional.ejb.EjbJar"/> | |||
<task name="mparse" class="org.apache.tools.ant.taskdefs.optional.metamata.MParse"/> | |||
<task name="mmetrics" class="org.apache.tools.ant.taskdefs.optional.metamata.MMetrics"/> | |||
<task name="maudit" class="org.apache.tools.ant.taskdefs.optional.metamata.MAudit"/> | |||
<task name="junit" class="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask"/> | |||
<task name="cab" class="org.apache.tools.ant.taskdefs.optional.Cab"/> | |||
<task name="ftp" class="org.apache.tools.ant.taskdefs.optional.net.FTP"/> | |||
<task name="icontract" class="org.apache.tools.ant.taskdefs.optional.IContract"/> | |||
<task name="javacc" class="org.apache.tools.ant.taskdefs.optional.javacc.JavaCC"/> | |||
<task name="jjtree" class="org.apache.tools.ant.taskdefs.optional.javacc.JJTree"/> | |||
<task name="stcheckout" class="org.apache.tools.ant.taskdefs.optional.starteam.StarTeamCheckout"/> | |||
<task name="stcheckin" class="org.apache.tools.ant.taskdefs.optional.starteam.StarTeamCheckin"/> | |||
<task name="stlabel" class="org.apache.tools.ant.taskdefs.optional.starteam.StarTeamLabel"/> | |||
<task name="stlist" class="org.apache.tools.ant.taskdefs.optional.starteam.StarTeamList"/> | |||
<task name="wljspc" class="org.apache.tools.ant.taskdefs.optional.jsp.WLJspc"/> | |||
<task name="jlink" class="org.apache.tools.ant.taskdefs.optional.jlink.JlinkTask"/> | |||
<task name="native2ascii" class="org.apache.tools.ant.taskdefs.optional.Native2Ascii"/> | |||
<task name="propertyfile" class="org.apache.tools.ant.taskdefs.optional.PropertyFile"/> | |||
<task name="depend" class="org.apache.tools.ant.taskdefs.optional.depend.Depend"/> | |||
<task name="antlr" class="org.apache.tools.ant.taskdefs.optional.ANTLR"/> | |||
<task name="vajload" class="org.apache.tools.ant.taskdefs.optional.ide.VAJLoadProjects"/> | |||
<task name="vajexport" class="org.apache.tools.ant.taskdefs.optional.ide.VAJExport"/> | |||
<task name="vajimport" class="org.apache.tools.ant.taskdefs.optional.ide.VAJImport"/> | |||
<task name="telnet" class="org.apache.tools.ant.taskdefs.optional.net.TelnetTask"/> | |||
<task name="csc" class="org.apache.tools.ant.taskdefs.optional.dotnet.CSharp"/> | |||
<task name="ilasm" class="org.apache.tools.ant.taskdefs.optional.dotnet.Ilasm"/> | |||
<task name="WsdlToDotnet" class="org.apache.tools.ant.taskdefs.optional.dotnet.WsdlToDotnet"/> | |||
<task name="wsdltodotnet" class="org.apache.tools.ant.taskdefs.optional.dotnet.WsdlToDotnet"/> | |||
<task name="stylebook" class="org.apache.tools.ant.taskdefs.optional.StyleBook"/> | |||
<task name="test" class="org.apache.tools.ant.taskdefs.optional.Test"/> | |||
<task name="pvcs" class="org.apache.tools.ant.taskdefs.optional.pvcs.Pvcs"/> | |||
<task name="p4change" class="org.apache.tools.ant.taskdefs.optional.perforce.P4Change"/> | |||
<task name="p4delete" class="org.apache.tools.ant.taskdefs.optional.perforce.P4Delete"/> | |||
<task name="p4label" class="org.apache.tools.ant.taskdefs.optional.perforce.P4Label"/> | |||
<task name="p4labelsync" class="org.apache.tools.ant.taskdefs.optional.perforce.P4Labelsync"/> | |||
<task name="p4have" class="org.apache.tools.ant.taskdefs.optional.perforce.P4Have"/> | |||
<task name="p4sync" class="org.apache.tools.ant.taskdefs.optional.perforce.P4Sync"/> | |||
<task name="p4edit" class="org.apache.tools.ant.taskdefs.optional.perforce.P4Edit"/> | |||
<task name="p4integrate" class="org.apache.tools.ant.taskdefs.optional.perforce.P4Integrate"/> | |||
<task name="p4resolve" class="org.apache.tools.ant.taskdefs.optional.perforce.P4Resolve"/> | |||
<task name="p4submit" class="org.apache.tools.ant.taskdefs.optional.perforce.P4Submit"/> | |||
<task name="p4counter" class="org.apache.tools.ant.taskdefs.optional.perforce.P4Counter"/> | |||
<task name="p4revert" class="org.apache.tools.ant.taskdefs.optional.perforce.P4Revert"/> | |||
<task name="p4reopen" class="org.apache.tools.ant.taskdefs.optional.perforce.P4Reopen"/> | |||
<task name="p4fstat" class="org.apache.tools.ant.taskdefs.optional.perforce.P4Fstat"/> | |||
<task name="javah" class="org.apache.tools.ant.taskdefs.optional.Javah"/> | |||
<task name="ccupdate" class="org.apache.tools.ant.taskdefs.optional.clearcase.CCUpdate"/> | |||
<task name="cccheckout" class="org.apache.tools.ant.taskdefs.optional.clearcase.CCCheckout"/> | |||
<task name="cccheckin" class="org.apache.tools.ant.taskdefs.optional.clearcase.CCCheckin"/> | |||
<task name="ccuncheckout" class="org.apache.tools.ant.taskdefs.optional.clearcase.CCUnCheckout"/> | |||
<task name="ccmklbtype" class="org.apache.tools.ant.taskdefs.optional.clearcase.CCMklbtype"/> | |||
<task name="ccmklabel" class="org.apache.tools.ant.taskdefs.optional.clearcase.CCMklabel"/> | |||
<task name="ccrmtype" class="org.apache.tools.ant.taskdefs.optional.clearcase.CCRmtype"/> | |||
<task name="cclock" class="org.apache.tools.ant.taskdefs.optional.clearcase.CCLock"/> | |||
<task name="ccunlock" class="org.apache.tools.ant.taskdefs.optional.clearcase.CCUnlock"/> | |||
<task name="ccmkbl" class="org.apache.tools.ant.taskdefs.optional.clearcase.CCMkbl"/> | |||
<task name="sound" class="org.apache.tools.ant.taskdefs.optional.sound.SoundTask"/> | |||
<task name="junitreport" class="org.apache.tools.ant.taskdefs.optional.junit.XMLResultAggregator"/> | |||
<task name="blgenclient" class="org.apache.tools.ant.taskdefs.optional.ejb.BorlandGenerateClient"/> | |||
<task name="rpm" class="org.apache.tools.ant.taskdefs.optional.Rpm"/> | |||
<task name="xmlvalidate" class="org.apache.tools.ant.taskdefs.optional.XMLValidateTask"/> | |||
<task name="iplanet-ejbc" class="org.apache.tools.ant.taskdefs.optional.ejb.IPlanetEjbcTask"/> | |||
<task name="jdepend" class="org.apache.tools.ant.taskdefs.optional.jdepend.JDependTask"/> | |||
<task name="mimemail" class="org.apache.tools.ant.taskdefs.optional.net.MimeMail"/> | |||
<task name="ccmcheckin" class="org.apache.tools.ant.taskdefs.optional.ccm.CCMCheckin"/> | |||
<task name="ccmcheckout" class="org.apache.tools.ant.taskdefs.optional.ccm.CCMCheckout"/> | |||
<task name="ccmcheckintask" class="org.apache.tools.ant.taskdefs.optional.ccm.CCMCheckinDefault"/> | |||
<task name="ccmreconfigure" class="org.apache.tools.ant.taskdefs.optional.ccm.CCMReconfigure"/> | |||
<task name="ccmcreatetask" class="org.apache.tools.ant.taskdefs.optional.ccm.CCMCreateTask"/> | |||
<task name="jpcoverage" class="org.apache.tools.ant.taskdefs.optional.sitraka.Coverage"/> | |||
<task name="jpcovmerge" class="org.apache.tools.ant.taskdefs.optional.sitraka.CovMerge"/> | |||
<task name="jpcovreport" class="org.apache.tools.ant.taskdefs.optional.sitraka.CovReport"/> | |||
<task name="p4add" class="org.apache.tools.ant.taskdefs.optional.perforce.P4Add"/> | |||
<task name="jspc" class="org.apache.tools.ant.taskdefs.optional.jsp.JspC"/> | |||
<task name="replaceregexp" class="org.apache.tools.ant.taskdefs.optional.ReplaceRegExp"/> | |||
<task name="translate" class="org.apache.tools.ant.taskdefs.optional.i18n.Translate"/> | |||
<task name="sosget" class="org.apache.tools.ant.taskdefs.optional.sos.SOSGet"/> | |||
<task name="soscheckin" class="org.apache.tools.ant.taskdefs.optional.sos.SOSCheckin"/> | |||
<task name="soscheckout" class="org.apache.tools.ant.taskdefs.optional.sos.SOSCheckout"/> | |||
<task name="soslabel" class="org.apache.tools.ant.taskdefs.optional.sos.SOSLabel"/> | |||
<task name="echoproperties" class="org.apache.tools.ant.taskdefs.optional.EchoProperties"/> | |||
<task name="splash" class="org.apache.tools.ant.taskdefs.optional.splash.SplashTask"/> | |||
<task name="serverdeploy" class="org.apache.tools.ant.taskdefs.optional.j2ee.ServerDeploy"/> | |||
<task name="jarlib-display" class="org.apache.tools.ant.taskdefs.optional.extension.JarLibDisplayTask"/> | |||
<task name="jarlib-manifest" class="org.apache.tools.ant.taskdefs.optional.extension.JarLibManifestTask"/> | |||
<task name="jarlib-available" class="org.apache.tools.ant.taskdefs.optional.extension.JarLibAvailableTask"/> | |||
<task name="jarlib-resolve" class="org.apache.tools.ant.taskdefs.optional.extension.JarLibResolveTask"/> | |||
<task name="setproxy" class="org.apache.tools.ant.taskdefs.optional.net.SetProxy"/> | |||
<task name="vbc" class="org.apache.tools.ant.taskdefs.optional.dotnet.VisualBasicCompile"/> | |||
<task name="symlink" class="org.apache.tools.ant.taskdefs.optional.unix.Symlink"/> | |||
<task name="chgrp" class="org.apache.tools.ant.taskdefs.optional.unix.Chgrp"/> | |||
<task name="chown" class="org.apache.tools.ant.taskdefs.optional.unix.Chown"/> | |||
<task name="attrib" class="org.apache.tools.ant.taskdefs.optional.windows.Attrib"/> | |||
<task name="scp" class="org.apache.tools.ant.taskdefs.optional.ssh.Scp"/> | |||
<task name="sshexec" class="org.apache.tools.ant.taskdefs.optional.ssh.SSHExec"/> | |||
<task name="jsharpc" class="org.apache.tools.ant.taskdefs.optional.dotnet.JSharp"/> | |||
<!-- datatypes --> | |||
<data-type name="classfileset" class="org.apache.tools.ant.types.optional.depend.ClassfileSet"/> | |||
<data-type name="scriptfilter" class="org.apache.tools.ant.types.optional.ScriptFilter"/> | |||
<!-- deprecated ant tasks (kept for back compatibility) --> | |||
<task name="starteam" class="org.apache.tools.ant.taskdefs.optional.scm.AntStarTeamCheckOut"/> | |||
</antlib> |
@@ -1,651 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2000-2003 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 "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.tools.ant.taskdefs; | |||
import java.io.File; | |||
import java.io.FileOutputStream; | |||
import java.io.IOException; | |||
import java.io.PrintStream; | |||
import java.lang.reflect.Method; | |||
import java.util.Enumeration; | |||
import java.util.Hashtable; | |||
import java.util.Vector; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.BuildListener; | |||
import org.apache.tools.ant.DefaultLogger; | |||
import org.apache.tools.ant.Project; | |||
import org.apache.tools.ant.ProjectComponent; | |||
import org.apache.tools.ant.ProjectHelper; | |||
import org.apache.tools.ant.Task; | |||
import org.apache.tools.ant.util.FileUtils; | |||
/** | |||
* Build a sub-project. | |||
* | |||
* <pre> | |||
* <target name="foo" depends="init"> | |||
* <ant antfile="build.xml" target="bar" > | |||
* <property name="property1" value="aaaaa" /> | |||
* <property name="foo" value="baz" /> | |||
* </ant></SPAN> | |||
* </target></SPAN> | |||
* | |||
* <target name="bar" depends="init"> | |||
* <echo message="prop is ${property1} ${foo}" /> | |||
* </target> | |||
* </pre> | |||
* | |||
* | |||
* @author Costin Manolache | |||
* | |||
* @since Ant 1.1 | |||
* | |||
* @ant.task category="control" | |||
*/ | |||
public class Ant extends Task { | |||
/** the basedir where is executed the build file */ | |||
private File dir = null; | |||
/** | |||
* the build.xml file (can be absolute) in this case dir will be | |||
* ignored | |||
*/ | |||
private String antFile = null; | |||
/** the target to call if any */ | |||
private String target = null; | |||
/** the output */ | |||
private String output = null; | |||
/** should we inherit properties from the parent ? */ | |||
private boolean inheritAll = true; | |||
/** should we inherit references from the parent ? */ | |||
private boolean inheritRefs = false; | |||
/** the properties to pass to the new project */ | |||
private Vector properties = new Vector(); | |||
/** the references to pass to the new project */ | |||
private Vector references = new Vector(); | |||
/** the temporary project created to run the build file */ | |||
private Project newProject; | |||
/** The stream to which output is to be written. */ | |||
private PrintStream out = null; | |||
/** | |||
* If true, pass all properties to the new Ant project. | |||
* Defaults to true. | |||
*/ | |||
public void setInheritAll(boolean value) { | |||
inheritAll = value; | |||
} | |||
/** | |||
* If true, pass all references to the new Ant project. | |||
* Defaults to false. | |||
*/ | |||
public void setInheritRefs(boolean value) { | |||
inheritRefs = value; | |||
} | |||
/** | |||
* Creates a Project instance for the project to call. | |||
*/ | |||
public void init() { | |||
newProject = getProject().createSubProject(); | |||
newProject.setDefaultInputStream(getProject().getDefaultInputStream()); | |||
newProject.setJavaVersionProperty(); | |||
/* newProject.addTaskDefinition("property", | |||
(Class) getProject().getTaskDefinitions() | |||
.get("property")); | |||
*/ | |||
} | |||
/** | |||
* Called in execute or createProperty if newProject is null. | |||
* | |||
* <p>This can happen if the same instance of this task is run | |||
* twice as newProject is set to null at the end of execute (to | |||
* save memory and help the GC).</p> | |||
* | |||
* <p>Sets all properties that have been defined as nested | |||
* property elements.</p> | |||
*/ | |||
private void reinit() { | |||
init(); | |||
final int count = properties.size(); | |||
for (int i = 0; i < count; i++) { | |||
Property p = (Property) properties.elementAt(i); | |||
Property newP = (Property) newProject.getTaskDefinitions().get("property"); | |||
newP.setName(p.getName()); | |||
if (p.getValue() != null) { | |||
newP.setValue(p.getValue()); | |||
} | |||
if (p.getFile() != null) { | |||
newP.setFile(p.getFile()); | |||
} | |||
if (p.getResource() != null) { | |||
newP.setResource(p.getResource()); | |||
} | |||
if (p.getPrefix() != null) { | |||
newP.setPrefix(p.getPrefix()); | |||
} | |||
if (p.getRefid() != null) { | |||
newP.setRefid(p.getRefid()); | |||
} | |||
if (p.getEnvironment() != null) { | |||
newP.setEnvironment(p.getEnvironment()); | |||
} | |||
if (p.getClasspath() != null) { | |||
newP.setClasspath(p.getClasspath()); | |||
} | |||
properties.setElementAt(newP, i); | |||
} | |||
} | |||
/** | |||
* Attaches the build listeners of the current project to the new | |||
* project, configures a possible logfile, transfers task and | |||
* data-type definitions, transfers properties (either all or just | |||
* the ones specified as user properties to the current project, | |||
* depending on inheritall), transfers the input handler. | |||
*/ | |||
private void initializeProject() { | |||
newProject.setInputHandler(getProject().getInputHandler()); | |||
Vector listeners = getProject().getBuildListeners(); | |||
final int count = listeners.size(); | |||
for (int i = 0; i < count; i++) { | |||
newProject.addBuildListener((BuildListener) listeners.elementAt(i)); | |||
} | |||
if (output != null) { | |||
File outfile = null; | |||
if (dir != null) { | |||
outfile = FileUtils.newFileUtils().resolveFile(dir, output); | |||
} else { | |||
outfile = getProject().resolveFile(output); | |||
} | |||
try { | |||
out = new PrintStream(new FileOutputStream(outfile)); | |||
DefaultLogger logger = new DefaultLogger(); | |||
logger.setMessageOutputLevel(Project.MSG_INFO); | |||
logger.setOutputPrintStream(out); | |||
logger.setErrorPrintStream(out); | |||
newProject.addBuildListener(logger); | |||
} catch (IOException ex) { | |||
log("Ant: Can't set output to " + output); | |||
} | |||
} | |||
Hashtable taskdefs = getProject().getTaskDefinitions(); | |||
Enumeration et = taskdefs.keys(); | |||
while (et.hasMoreElements()) { | |||
String taskName = (String) et.nextElement(); | |||
Class taskClass = (Class) taskdefs.get(taskName); | |||
newProject.addTaskDefinition(taskName, taskClass); | |||
} | |||
Hashtable typedefs = getProject().getDataTypeDefinitions(); | |||
Enumeration e = typedefs.keys(); | |||
while (e.hasMoreElements()) { | |||
String typeName = (String) e.nextElement(); | |||
Class typeClass = (Class) typedefs.get(typeName); | |||
newProject.addDataTypeDefinition(typeName, typeClass); | |||
} | |||
// set user-defined properties | |||
getProject().copyUserProperties(newProject); | |||
if (!inheritAll) { | |||
// set Java built-in properties separately, | |||
// b/c we won't inherit them. | |||
newProject.setSystemProperties(); | |||
} else { | |||
// set all properties from calling project | |||
Hashtable props = getProject().getProperties(); | |||
e = props.keys(); | |||
while (e.hasMoreElements()) { | |||
String arg = e.nextElement().toString(); | |||
if ("basedir".equals(arg) || "ant.file".equals(arg)) { | |||
// basedir and ant.file get special treatment in execute() | |||
continue; | |||
} | |||
String value = props.get(arg).toString(); | |||
// don't re-set user properties, avoid the warning message | |||
if (newProject.getProperty(arg) == null){ | |||
// no user property | |||
newProject.setNewProperty(arg, value); | |||
} | |||
} | |||
} | |||
} | |||
/** | |||
* Pass output sent to System.out to the new project. | |||
* | |||
* @since Ant 1.5 | |||
*/ | |||
public void handleOutput(String line) { | |||
if (newProject != null) { | |||
newProject.demuxOutput(line, false); | |||
} else { | |||
super.handleOutput(line); | |||
} | |||
} | |||
/** | |||
* @see Task#handleInput(byte[], int, int) | |||
* | |||
* @since Ant 1.6 | |||
*/ | |||
public int handleInput(byte[] buffer, int offset, int length) | |||
throws IOException { | |||
if (newProject != null) { | |||
return newProject.demuxInput(buffer, offset, length); | |||
} else { | |||
return super.handleInput(buffer, offset, length); | |||
} | |||
} | |||
/** | |||
* Pass output sent to System.out to the new project. | |||
* | |||
* @since Ant 1.5.2 | |||
*/ | |||
public void handleFlush(String line) { | |||
if (newProject != null) { | |||
newProject.demuxFlush(line, false); | |||
} else { | |||
super.handleFlush(line); | |||
} | |||
} | |||
/** | |||
* Pass output sent to System.err to the new project. | |||
* | |||
* @since Ant 1.5 | |||
*/ | |||
public void handleErrorOutput(String line) { | |||
if (newProject != null) { | |||
newProject.demuxOutput(line, true); | |||
} else { | |||
super.handleErrorOutput(line); | |||
} | |||
} | |||
/** | |||
* Pass output sent to System.err to the new project. | |||
* | |||
* @since Ant 1.5.2 | |||
*/ | |||
public void handleErrorFlush(String line) { | |||
if (newProject != null) { | |||
newProject.demuxFlush(line, true); | |||
} else { | |||
super.handleErrorFlush(line); | |||
} | |||
} | |||
/** | |||
* Do the execution. | |||
*/ | |||
public void execute() throws BuildException { | |||
File savedDir = dir; | |||
String savedAntFile = antFile; | |||
String savedTarget = target; | |||
try { | |||
if (newProject == null) { | |||
reinit(); | |||
} | |||
if ((dir == null) && (inheritAll)) { | |||
dir = getProject().getBaseDir(); | |||
} | |||
initializeProject(); | |||
if (dir != null) { | |||
newProject.setBaseDir(dir); | |||
if (savedDir != null) { // has been set explicitly | |||
newProject.setInheritedProperty("basedir" , | |||
dir.getAbsolutePath()); | |||
} | |||
} else { | |||
dir = getProject().getBaseDir(); | |||
} | |||
overrideProperties(); | |||
if (antFile == null) { | |||
antFile = "build.xml"; | |||
} | |||
File file = FileUtils.newFileUtils().resolveFile(dir, antFile); | |||
antFile = file.getAbsolutePath(); | |||
log("calling target " + (target != null ? target : "[default]") | |||
+ " in build file " + antFile.toString(), | |||
Project.MSG_VERBOSE); | |||
newProject.setUserProperty("ant.file" , antFile); | |||
ProjectHelper.configureProject(newProject, new File(antFile)); | |||
if (target == null) { | |||
target = newProject.getDefaultTarget(); | |||
} | |||
// Are we trying to call the target in which we are defined (or | |||
// the build file if this is a top level task)? | |||
if (newProject.getBaseDir().equals(getProject().getBaseDir()) && | |||
newProject.getProperty("ant.file").equals(getProject().getProperty("ant.file")) | |||
&& getOwningTarget() != null | |||
&& (getOwningTarget().getName().equals("") || | |||
getOwningTarget().getName().equals(target))) { | |||
throw new BuildException("ant task calling its own parent " | |||
+ "target"); | |||
} | |||
addReferences(); | |||
if (target != null) { | |||
newProject.executeTarget(target); | |||
} else { | |||
newProject.executeTarget(""); | |||
} | |||
} finally { | |||
// help the gc | |||
newProject = null; | |||
Enumeration enum = properties.elements(); | |||
while (enum.hasMoreElements()) { | |||
Property p = (Property) enum.nextElement(); | |||
p.setProject(null); | |||
} | |||
if (output != null && out != null) { | |||
try { | |||
out.close(); | |||
} catch (final Exception e) { | |||
//ignore | |||
} | |||
} | |||
dir = savedDir; | |||
antFile = savedAntFile; | |||
target = savedTarget; | |||
} | |||
} | |||
/** | |||
* Override the properties in the new project with the one | |||
* explicitly defined as nested elements here. | |||
*/ | |||
private void overrideProperties() throws BuildException { | |||
Enumeration e = properties.elements(); | |||
while (e.hasMoreElements()) { | |||
Property p = (Property) e.nextElement(); | |||
p.setProject(newProject); | |||
p.execute(); | |||
} | |||
getProject().copyInheritedProperties(newProject); | |||
} | |||
/** | |||
* Add the references explicitly defined as nested elements to the | |||
* new project. Also copy over all references that don't override | |||
* existing references in the new project if inheritrefs has been | |||
* requested. | |||
*/ | |||
private void addReferences() throws BuildException { | |||
Hashtable thisReferences | |||
= (Hashtable) getProject().getReferences().clone(); | |||
Hashtable newReferences = newProject.getReferences(); | |||
Enumeration e; | |||
if (references.size() > 0) { | |||
for (e = references.elements(); e.hasMoreElements();) { | |||
Reference ref = (Reference) e.nextElement(); | |||
String refid = ref.getRefId(); | |||
if (refid == null) { | |||
throw new BuildException("the refid attribute is required" | |||
+ " for reference elements"); | |||
} | |||
if (!thisReferences.containsKey(refid)) { | |||
log("Parent project doesn't contain any reference '" | |||
+ refid + "'", | |||
Project.MSG_WARN); | |||
continue; | |||
} | |||
thisReferences.remove(refid); | |||
String toRefid = ref.getToRefid(); | |||
if (toRefid == null) { | |||
toRefid = refid; | |||
} | |||
copyReference(refid, toRefid); | |||
} | |||
} | |||
// Now add all references that are not defined in the | |||
// subproject, if inheritRefs is true | |||
if (inheritRefs) { | |||
for (e = thisReferences.keys(); e.hasMoreElements();) { | |||
String key = (String) e.nextElement(); | |||
if (newReferences.containsKey(key)) { | |||
continue; | |||
} | |||
copyReference(key, key); | |||
} | |||
} | |||
} | |||
/** | |||
* Try to clone and reconfigure the object referenced by oldkey in | |||
* the parent project and add it to the new project with the key | |||
* newkey. | |||
* | |||
* <p>If we cannot clone it, copy the referenced object itself and | |||
* keep our fingers crossed.</p> | |||
*/ | |||
private void copyReference(String oldKey, String newKey) { | |||
Object orig = getProject().getReference(oldKey); | |||
if (orig == null) { | |||
log("No object referenced by " + oldKey + ". Can't copy to " | |||
+ newKey, | |||
Project.MSG_WARN); | |||
return; | |||
} | |||
Class c = orig.getClass(); | |||
Object copy = orig; | |||
try { | |||
Method cloneM = c.getMethod("clone", new Class[0]); | |||
if (cloneM != null) { | |||
copy = cloneM.invoke(orig, new Object[0]); | |||
log("Adding clone of reference " + oldKey, Project.MSG_DEBUG); | |||
} | |||
} catch (Exception e) { | |||
// not Clonable | |||
} | |||
if (copy instanceof ProjectComponent) { | |||
((ProjectComponent) copy).setProject(newProject); | |||
} else { | |||
try { | |||
Method setProjectM = | |||
c.getMethod("setProject", new Class[] {Project.class}); | |||
if (setProjectM != null) { | |||
setProjectM.invoke(copy, new Object[] {newProject}); | |||
} | |||
} catch (NoSuchMethodException e) { | |||
// ignore this if the class being referenced does not have | |||
// a set project method. | |||
} catch (Exception e2) { | |||
String msg = "Error setting new project instance for " | |||
+ "reference with id " + oldKey; | |||
throw new BuildException(msg, e2, getLocation()); | |||
} | |||
} | |||
newProject.addReference(newKey, copy); | |||
} | |||
/** | |||
* The directory to use as a base directory for the new Ant project. | |||
* Defaults to the current project's basedir, unless inheritall | |||
* has been set to false, in which case it doesn't have a default | |||
* value. This will override the basedir setting of the called project. | |||
*/ | |||
public void setDir(File d) { | |||
this.dir = d; | |||
} | |||
/** | |||
* The build file to use. | |||
* Defaults to "build.xml". This file is expected to be a filename relative | |||
* to the dir attribute given. | |||
*/ | |||
public void setAntfile(String s) { | |||
// @note: it is a string and not a file to handle relative/absolute | |||
// otherwise a relative file will be resolved based on the current | |||
// basedir. | |||
this.antFile = s; | |||
} | |||
/** | |||
* The target of the new Ant project to execute. | |||
* Defaults to the new project's default target. | |||
*/ | |||
public void setTarget(String s) { | |||
if (s.equals("")) { | |||
throw new BuildException("target attribute must not be empty"); | |||
} | |||
this.target = s; | |||
} | |||
/** | |||
* Filename to write the output to. | |||
* This is relative to the value of the dir attribute | |||
* if it has been set or to the base directory of the | |||
* current project otherwise. | |||
*/ | |||
public void setOutput(String s) { | |||
this.output = s; | |||
} | |||
/** | |||
* Property to pass to the new project. | |||
* The property is passed as a 'user property' | |||
*/ | |||
public Property createProperty() { | |||
if (newProject == null) { | |||
reinit(); | |||
} | |||
Property p = new Property(true, getProject()); | |||
p.setProject(newProject); | |||
p.setTaskName("property"); | |||
properties.addElement(p); | |||
return p; | |||
} | |||
/** | |||
* Reference element identifying a data type to carry | |||
* over to the new project. | |||
*/ | |||
public void addReference(Reference r) { | |||
references.addElement(r); | |||
} | |||
/** | |||
* Helper class that implements the nested <reference> | |||
* element of <ant> and <antcall>. | |||
*/ | |||
public static class Reference | |||
extends org.apache.tools.ant.types.Reference { | |||
/** Creates a reference to be configured by Ant */ | |||
public Reference() { | |||
super(); | |||
} | |||
private String targetid = null; | |||
/** | |||
* Set the id that this reference to be stored under in the | |||
* new project. | |||
* | |||
* @param targetid the id under which this reference will be passed to | |||
* the new project */ | |||
public void setToRefid(String targetid) { | |||
this.targetid = targetid; | |||
} | |||
/** | |||
* Get the id under which this reference will be stored in the new | |||
* project | |||
* | |||
* @return the id of the reference in the new project. | |||
*/ | |||
public String getToRefid() { | |||
return targetid; | |||
} | |||
} | |||
} |
@@ -1,179 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2000,2003 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.tools.ant.taskdefs; | |||
import org.apache.tools.ant.*; | |||
import org.apache.tools.ant.types.ZipFileSet; | |||
import org.apache.tools.zip.*; | |||
import java.io.*; | |||
/** | |||
* Creates a ANTLIB archive. Code is similar to the War class, but with | |||
* bonus dtd validation. | |||
* | |||
* @author doc and layout changes by steve loughran, steve_l@iseran.com | |||
* @author <a href="mailto:j_a_fernandez@yahoo.com">Jose Alberto Fernandez</a> | |||
* @author Stefan Bodewig | |||
* | |||
* @since ant1.5 | |||
*/ | |||
public class Antjar extends Jar { | |||
/** | |||
* location of the xml descriptor (antxml attribute) | |||
*/ | |||
private File libraryDescriptor; | |||
/** | |||
* status flag | |||
*/ | |||
private boolean descriptorAdded; | |||
/** | |||
* Constructor for the Antjar object | |||
*/ | |||
public Antjar() { | |||
super(); | |||
archiveType = "jar"; | |||
emptyBehavior = "create"; | |||
} | |||
/** | |||
* Sets the Antxml attribute of the Antjar object | |||
* | |||
* @param descriptor The new Antxml value | |||
*/ | |||
public void setAntxml(File descriptor) { | |||
libraryDescriptor = descriptor; | |||
if (!libraryDescriptor.exists()) { | |||
throw new BuildException("Deployment descriptor: " + | |||
libraryDescriptor + " does not exist."); | |||
} | |||
// Create a ZipFileSet for this file, and pass it up. | |||
ZipFileSet fs = new ZipFileSet(); | |||
fs.setDir(new File(libraryDescriptor.getParent())); | |||
fs.setIncludes(libraryDescriptor.getName()); | |||
fs.setFullpath(Antlib.ANT_DESCRIPTOR); | |||
super.addFileset(fs); | |||
} | |||
/** | |||
* override of superclass method; add check for | |||
* valid descriptor | |||
* @param zOut stream to init | |||
* @exception IOException io trouble | |||
* @exception BuildException other trouble | |||
*/ | |||
protected void initZipOutputStream(ZipOutputStream zOut) | |||
throws IOException, BuildException { | |||
// If no antxml file is specified, it's an error. | |||
if (libraryDescriptor == null) { | |||
throw new BuildException("antxml attribute is required", | |||
getLocation()); | |||
} | |||
super.initZipOutputStream(zOut); | |||
} | |||
/** | |||
* override of parent method; warn if a second descriptor is added | |||
* | |||
* @param file file to add | |||
* @param zOut stream to add to | |||
* @param vPath the path to add it to in the zipfile | |||
* @param mode the Unix permissions to set. | |||
* @exception IOException io trouble | |||
*/ | |||
protected void zipFile(File file, ZipOutputStream zOut, String vPath, int mode) | |||
throws IOException { | |||
// If the file being added is META-INF/antlib.xml, we warn if it's not the | |||
// one specified in the "antxml" attribute - or if it's being added twice, | |||
// meaning the same file is specified by the "antxml" attribute and in | |||
// a <fileset> element. | |||
if (vPath.equalsIgnoreCase(Antlib.ANT_DESCRIPTOR)) { | |||
if (libraryDescriptor == null || | |||
!libraryDescriptor.equals(file) || descriptorAdded) { | |||
log("Warning: selected " + archiveType + " files include a " + | |||
Antlib.ANT_DESCRIPTOR + " which will be ignored " + | |||
"(please use antxml attribute to " + archiveType + | |||
" task)", Project.MSG_WARN); | |||
} | |||
else { | |||
super.zipFile(file, zOut, vPath, mode); | |||
descriptorAdded = true; | |||
} | |||
} | |||
else { | |||
super.zipFile(file, zOut, vPath, mode); | |||
} | |||
} | |||
/** | |||
* Make sure we don't think we already have a descriptor next time this | |||
* task gets executed. | |||
*/ | |||
protected void cleanUp() { | |||
descriptorAdded = false; | |||
super.cleanUp(); | |||
} | |||
} |
@@ -1,27 +0,0 @@ | |||
<?xml version='1.0' encoding="UTF8" ?> | |||
<!-- | |||
This file defines the XML format for ANT library descriptors. | |||
Descriptors must especify a DOCTYPE using "Antlib-V1_0.dtd" | |||
as the SystemId for the document. | |||
--> | |||
<!-- Root element for the Antlib descriptor. --> | |||
<!ELEMENT antlib (task | type)* > | |||
<!ATTLIST antlib | |||
version CDATA #IMPLIED | |||
> | |||
<!-- Declaration of tasks contained in the library. --> | |||
<!ELEMENT task EMPTY> | |||
<!ATTLIST task | |||
name CDATA #REQUIRED | |||
class CDATA #REQUIRED | |||
> | |||
<!-- Declaration of datatypes contained in the library --> | |||
<!ELEMENT type EMPTY> | |||
<!ATTLIST type | |||
name CDATA #REQUIRED | |||
class CDATA #REQUIRED | |||
> |
@@ -1,883 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 1999,2003 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.tools.ant.taskdefs; | |||
import org.apache.tools.ant.*; | |||
import org.apache.tools.ant.types.*; | |||
import org.xml.sax.*; | |||
import javax.xml.parsers.*; | |||
import java.util.*; | |||
import java.util.zip.*; | |||
import java.io.*; | |||
import java.net.*; | |||
/** | |||
* Make available the tasks and types from an Ant library. <pre> | |||
* <antlib library="libname.jar" > | |||
* <alias name="nameOnLib" as="newName" /> | |||
* </antlib> | |||
* | |||
* <antlib file="libname.jar" override="true" /> | |||
* </pre> | |||
* | |||
* @author minor changes by steve loughran, steve_l@iseran.com | |||
* @author <a href="j_a_fernandez@yahoo.com">Jose Alberto Fernandez</a> | |||
* @since ant1.5 | |||
*/ | |||
public class Antlib extends Task { | |||
/** | |||
* Location of descriptor in library | |||
*/ | |||
public static final String ANT_DESCRIPTOR = "META-INF/antlib.xml"; | |||
/** | |||
* The named classloader to use. | |||
* Defaults to the default classLoader. | |||
*/ | |||
private String loaderId = ""; | |||
/** | |||
* file attribute | |||
*/ | |||
private File file = null; | |||
/** | |||
* override attribute | |||
*/ | |||
private boolean override = false; | |||
/** | |||
* attribute to control failure when loading | |||
*/ | |||
private FailureAction onerror = new FailureAction(); | |||
/** | |||
* classpath to build up | |||
*/ | |||
private Path classpath = null; | |||
/** | |||
* our little xml parse | |||
*/ | |||
private SAXParserFactory saxFactory; | |||
/** | |||
* table of aliases | |||
*/ | |||
private Vector aliases = new Vector(); | |||
/** | |||
* Some internal constants. | |||
*/ | |||
private static final int FAIL = 0, REPORT = 1, IGNORE = 2; | |||
/** | |||
* Posible actions when classes are not found | |||
*/ | |||
public static class FailureAction extends EnumeratedAttribute { | |||
public String[] getValues() { | |||
return new String[]{"fail", "report", "ignore"}; | |||
} | |||
} | |||
private static class DescriptorEnumeration implements Enumeration { | |||
/** | |||
* The name of the resource being searched for. | |||
*/ | |||
private String resourceName; | |||
/** | |||
* The index of the next file to search. | |||
*/ | |||
private int index; | |||
/** | |||
* The list of files to search | |||
*/ | |||
private File files[]; | |||
/** | |||
* The URL of the next resource to return in the enumeration. If this | |||
* field is <code>null</code> then the enumeration has been completed, | |||
* i.e., there are no more elements to return. | |||
*/ | |||
private URL nextDescriptor; | |||
/** | |||
* Construct a new enumeration of resources of the given name found | |||
* within this class loader's classpath. | |||
* | |||
* @param name the name of the resource to search for. | |||
*/ | |||
DescriptorEnumeration(String fileNames[], String name) { | |||
this.resourceName = name; | |||
this.index = 0; | |||
this.files = new File[fileNames.length]; | |||
for (int i = 0; i < files.length; i++) { | |||
files[i] = new File(fileNames[i]); | |||
} | |||
findNextDescriptor(); | |||
} | |||
/** | |||
* Indicates whether there are more elements in the enumeration to | |||
* return. | |||
* | |||
* @return <code>true</code> if there are more elements in the | |||
* enumeration; <code>false</code> otherwise. | |||
*/ | |||
public boolean hasMoreElements() { | |||
return (this.nextDescriptor != null); | |||
} | |||
/** | |||
* Returns the next resource in the enumeration. | |||
* | |||
* @return the next resource in the enumeration. | |||
*/ | |||
public Object nextElement() { | |||
URL ret = this.nextDescriptor; | |||
findNextDescriptor(); | |||
return ret; | |||
} | |||
/** | |||
* Locates the next descriptor of the correct name in the files and | |||
* sets <code>nextDescriptor</code> to the URL of that resource. If no | |||
* more resources can be found, <code>nextDescriptor</code> is set to | |||
* <code>null</code>. | |||
*/ | |||
private void findNextDescriptor() { | |||
URL url = null; | |||
while (index < files.length && url == null) { | |||
try { | |||
url = getDescriptorURL(files[index], this.resourceName); | |||
index++; | |||
} | |||
catch (BuildException e) { | |||
// ignore path elements which are not valid relative to the | |||
// project | |||
} | |||
} | |||
this.nextDescriptor = url; | |||
} | |||
/** | |||
* Get an URL 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. Must not be <code>null</code>. | |||
* @param resourceName the name of the resource for which a URL | |||
* is required. Must not be <code>null</code>. | |||
* | |||
* @return a URL to the required resource or <code>null</code> if the | |||
* resource cannot be found in the given file object | |||
* @todo This code is extracted from AntClassLoader.getResourceURL | |||
* I hate when that happens but the code there is too tied to | |||
* the ClassLoader internals. Maybe we can find a nice place | |||
* to put it where both can use it. | |||
*/ | |||
private URL getDescriptorURL(File file, String resourceName) { | |||
try { | |||
if (!file.exists()) { | |||
return null; | |||
} | |||
if (file.isDirectory()) { | |||
File resource = new File(file, resourceName); | |||
if (resource.exists()) { | |||
try { | |||
return new URL("file:"+resource.toString()); | |||
} catch (MalformedURLException ex) { | |||
return null; | |||
} | |||
} | |||
} | |||
else { | |||
ZipFile zipFile = new ZipFile(file); | |||
try { | |||
ZipEntry entry = zipFile.getEntry(resourceName); | |||
if (entry != null) { | |||
try { | |||
return new URL("jar:file:"+file.toString()+"!/"+entry); | |||
} catch (MalformedURLException ex) { | |||
return null; | |||
} | |||
} | |||
} | |||
finally { | |||
zipFile.close(); | |||
} | |||
} | |||
} | |||
catch (Exception e) { | |||
e.printStackTrace(); | |||
} | |||
return null; | |||
} | |||
} | |||
/** | |||
* constructor creates a validating sax parser | |||
*/ | |||
public Antlib() { | |||
super(); | |||
// Default error action | |||
onerror.setValue("report"); | |||
saxFactory = SAXParserFactory.newInstance(); | |||
saxFactory.setValidating(false); | |||
} | |||
/** | |||
* constructor binds to a project and sets ignore mode on errors | |||
* | |||
* @param p Description of Parameter | |||
*/ | |||
public Antlib(Project p) { | |||
this(); | |||
setProject(p); | |||
} | |||
/** | |||
* Set name of library to load. The library is located in $ANT_HOME/antlib. | |||
* | |||
* @param lib the name of library relative to $ANT_HOME/antlib. | |||
*/ | |||
public void setLibrary(String lib) { | |||
setFile(libraryFile("antlib", lib)); | |||
} | |||
/** | |||
* Set file location of library to load. | |||
* | |||
* @param file the jar file for the library. | |||
*/ | |||
public void setFile(File file) { | |||
this.file = file; | |||
} | |||
/** | |||
* Set the ID of the ClassLoader to use for this library. | |||
* | |||
* @param id the id for the ClassLoader to use, | |||
* <code>null</code> means use ANT's core classloader. | |||
*/ | |||
public void setLoaderid(String id) { | |||
this.loaderId = id; | |||
} | |||
/** | |||
* Set whether to override any existing definitions. | |||
* | |||
* @param override if true new definitions will replace existing ones. | |||
*/ | |||
public void setOverride(boolean override) { | |||
this.override = override; | |||
} | |||
/** | |||
* Get what to do if a definition cannot be loaded | |||
* This method is mostly used by the core when loading core tasks. | |||
* | |||
* @return what to do if a definition cannot be loaded | |||
*/ | |||
final protected FailureAction getOnerror() { | |||
return this.onerror; | |||
} | |||
/** | |||
* Set whether to fail if a definition cannot be loaded | |||
* Default is <code>true</code>. | |||
* This property is mostly used by the core when loading core tasks. | |||
* | |||
* @param onerror if true loading will stop if classes | |||
* cannot be instantiated | |||
*/ | |||
public void setOnerror(FailureAction onerror) { | |||
this.onerror = onerror; | |||
} | |||
/** | |||
* Create new Alias element. | |||
* | |||
* @return Description of the Returned Value | |||
*/ | |||
public Alias createAlias() { | |||
Alias als = new Alias(); | |||
aliases.add(als); | |||
return als; | |||
} | |||
/** | |||
* Set the classpath to be used for this compilation | |||
* | |||
* @param cp The new Classpath value | |||
*/ | |||
public void setClasspath(Path cp) { | |||
if (classpath == null) { | |||
classpath = cp; | |||
} | |||
else { | |||
classpath.append(cp); | |||
} | |||
} | |||
/** | |||
* create a nested classpath element. | |||
* | |||
* @return classpath to use | |||
*/ | |||
public Path createClasspath() { | |||
if (classpath == null) { | |||
classpath = new Path(getProject()); | |||
} | |||
return classpath.createPath(); | |||
} | |||
/** | |||
* Adds a reference to a CLASSPATH defined elsewhere | |||
* | |||
* @param r The new ClasspathRef value | |||
*/ | |||
public void setClasspathRef(Reference r) { | |||
createClasspath().setRefid(r); | |||
} | |||
/** | |||
* Obtain library file from ANT_HOME directory. | |||
* | |||
* @param lib the library name. | |||
* @return the File instance of the library | |||
*/ | |||
private File libraryFile(String homeSubDir, String lib) { | |||
// For the time being libraries live in $ANT_HOME/antlib. | |||
// The idea being that not to load all the jars there anymore | |||
String home = getProject().getProperty("ant.home"); | |||
if (home == null) { | |||
throw new BuildException("ANT_HOME not set as required."); | |||
} | |||
return new File(new File(home, homeSubDir), lib); | |||
} | |||
/** | |||
* actually do the work of loading the library | |||
* | |||
* @exception BuildException Description of Exception | |||
*/ | |||
public void execute() | |||
throws BuildException { | |||
if (file == null && classpath == null) { | |||
String msg = | |||
"Must specify either library or file attribute or classpath."; | |||
throw new BuildException(msg, getLocation()); | |||
} | |||
if (file != null && !file.exists()) { | |||
String msg = "Cannot find library: " + file; | |||
throw new BuildException(msg, getLocation()); | |||
} | |||
loadDefinitions(); | |||
} | |||
/** | |||
* Load definitions in library and classpath | |||
* | |||
* @exception BuildException failure to access the resource | |||
*/ | |||
public boolean loadDefinitions() throws BuildException { | |||
return loadDefinitions(ANT_DESCRIPTOR); | |||
} | |||
/** | |||
* Load definitions from resource name in library and classpath | |||
* | |||
* @param res the name of the resources to load | |||
* @exception BuildException failure to access the resource | |||
*/ | |||
final protected boolean loadDefinitions(String res) | |||
throws BuildException { | |||
Path path = makeLoaderClasspath(); | |||
ClassLoader cl = makeClassLoader(path); | |||
boolean found = false; | |||
try { | |||
for (Enumeration e = getDescriptors(path, res); e.hasMoreElements(); ) { | |||
URL resURL = (URL)e.nextElement(); | |||
InputStream is = resURL.openStream(); | |||
loadDefinitions(cl, is); | |||
found = true; | |||
} | |||
if (!found && onerror.getIndex() != IGNORE) { | |||
String sPath = path.toString(); | |||
if ("".equals(sPath.trim())) { | |||
sPath = System.getProperty("java.classpath"); | |||
} | |||
String msg = "Cannot find any " + res + | |||
" antlib descriptors in: " + sPath; | |||
switch (onerror.getIndex()) { | |||
case FAIL: | |||
throw new BuildException(msg); | |||
case REPORT: | |||
log(msg, Project.MSG_WARN); | |||
} | |||
} | |||
} | |||
catch (IOException io) { | |||
String msg = "Cannot load definitions from: " + res; | |||
switch (onerror.getIndex()) { | |||
case FAIL: | |||
throw new BuildException(msg, io); | |||
case REPORT: | |||
log(io.getMessage(), Project.MSG_WARN); | |||
} | |||
} | |||
return found; | |||
} | |||
/** | |||
* Load definitions directly from InputStream. | |||
* | |||
* @param is InputStream for the Antlib descriptor. | |||
* @exception BuildException trouble | |||
*/ | |||
private void loadDefinitions(ClassLoader cl, InputStream is) | |||
throws BuildException { | |||
evaluateDescriptor(cl, processAliases(), is); | |||
} | |||
/** | |||
* get an Enumeration of URLs for all resouces corresponding to the | |||
* descriptor name. | |||
* | |||
* @param res the name of the resource to collect | |||
* @return input stream to the Descriptor or null if none existent | |||
* @exception BuildException io trouble, or it isnt a zipfile | |||
*/ | |||
private Enumeration getDescriptors(Path path, final String res) | |||
throws BuildException, IOException { | |||
if (loaderId == null) { | |||
// Path cannot be added to the CoreLoader so simply | |||
// ask for all instances of the resource descriptors | |||
return getProject().getCoreLoader().getResources(res); | |||
} | |||
return new DescriptorEnumeration(path.list(), res); | |||
} | |||
/** | |||
* turn the alias list to a property hashtable | |||
* | |||
* @return generated property hashtable | |||
*/ | |||
private Properties processAliases() { | |||
Properties p = new Properties(); | |||
for (Enumeration e = aliases.elements(); e.hasMoreElements(); ) { | |||
Alias a = (Alias) e.nextElement(); | |||
p.put(a.name, a.as); | |||
} | |||
return p; | |||
} | |||
/** | |||
* create the classpath for this library from the file passed in and | |||
* any classpath parameters | |||
* | |||
* @param clspath library file to use | |||
* @return classloader using te | |||
* @exception BuildException trouble creating the classloader | |||
*/ | |||
protected ClassLoader makeClassLoader(Path clspath) | |||
throws BuildException { | |||
if (loaderId == null) { | |||
log("Loading definitions from CORE, <classpath> ignored", | |||
Project.MSG_VERBOSE); | |||
return getProject().getCoreLoader(); | |||
} | |||
log("Using ClassLoader '" + loaderId + "' to load path: " + clspath, | |||
Project.MSG_VERBOSE); | |||
return getProject().addToLoader(loaderId, clspath); | |||
} | |||
/** | |||
* Constructs the Path to add to the ClassLoader | |||
*/ | |||
private Path makeLoaderClasspath() | |||
{ | |||
Path clspath = new Path(getProject()); | |||
if (file != null) clspath.setLocation(file); | |||
//append any build supplied classpath | |||
if (classpath != null) { | |||
clspath.append(classpath); | |||
} | |||
return clspath; | |||
} | |||
/** | |||
* parse the antlib descriptor | |||
* | |||
* @param cl optional classloader | |||
* @param als alias list as property hashtable | |||
* @param is input stream to descriptor | |||
* @exception BuildException trouble | |||
*/ | |||
protected void evaluateDescriptor(ClassLoader cl, | |||
Properties als, InputStream is) | |||
throws BuildException { | |||
try { | |||
SAXParser saxParser = saxFactory.newSAXParser(); | |||
InputSource inputSource = new InputSource(is); | |||
//inputSource.setSystemId(uri); //URI is nasty for jar entries | |||
getProject().log("parsing descriptor for library: " + file, | |||
Project.MSG_VERBOSE); | |||
saxParser.parse(inputSource, new AntLibraryHandler(cl, als)); | |||
} | |||
catch (ParserConfigurationException exc) { | |||
throw new BuildException("Parser has not been configured correctly", exc); | |||
} | |||
catch (SAXParseException exc) { | |||
Location location = | |||
new Location(ANT_DESCRIPTOR, | |||
exc.getLineNumber(), exc.getColumnNumber()); | |||
Throwable t = exc.getException(); | |||
if (t instanceof BuildException) { | |||
BuildException be = (BuildException) t; | |||
if (be.getLocation() == Location.UNKNOWN_LOCATION) { | |||
be.setLocation(location); | |||
} | |||
throw be; | |||
} | |||
throw new BuildException(exc.getMessage(), t, location); | |||
} | |||
catch (SAXException exc) { | |||
Throwable t = exc.getException(); | |||
if (t instanceof BuildException) { | |||
throw (BuildException) t; | |||
} | |||
throw new BuildException(exc.getMessage(), t); | |||
} | |||
catch (IOException exc) { | |||
throw new BuildException("Error reading library descriptor", exc); | |||
} | |||
finally { | |||
if (is != null) { | |||
try { | |||
is.close(); | |||
} | |||
catch (IOException ioe) { | |||
// ignore this | |||
} | |||
} | |||
} | |||
} | |||
/** | |||
* Parses the document describing the content of the | |||
* library. An inner class for access to Project.log | |||
*/ | |||
private class AntLibraryHandler extends HandlerBase { | |||
/** | |||
* our classloader | |||
*/ | |||
private final ClassLoader classloader; | |||
/** | |||
* the aliases | |||
*/ | |||
private final Properties aliasMap; | |||
/** | |||
* doc locator | |||
*/ | |||
private Locator locator = null; | |||
private int level = 0; | |||
private String name = null; | |||
private String className = null; | |||
private String adapter = null; | |||
/** | |||
* Constructor for the AntLibraryHandler object | |||
* | |||
* @param classloader optional classloader | |||
* @param als alias list | |||
*/ | |||
AntLibraryHandler(ClassLoader classloader, Properties als) { | |||
this.classloader = classloader; | |||
this.aliasMap = als; | |||
} | |||
/** | |||
* Sets the DocumentLocator attribute of the AntLibraryHandler | |||
* object | |||
* | |||
* @param locator The new DocumentLocator value | |||
*/ | |||
public void setDocumentLocator(Locator locator) { | |||
this.locator = locator; | |||
} | |||
private void parseAttributes(String tag, AttributeList attrs) | |||
throws SAXParseException { | |||
name = null; | |||
className = null; | |||
adapter = null; | |||
for (int i = 0, last = attrs.getLength(); i < last; i++) { | |||
String key = attrs.getName(i); | |||
String value = attrs.getValue(i); | |||
if (key.equals("name")) { | |||
name = value; | |||
} | |||
else if (key.equals("class")) { | |||
className = value; | |||
} | |||
else if ("role".equals(tag) && key.equals("adapter")) { | |||
adapter = value; | |||
} | |||
else { | |||
throw new SAXParseException("Unexpected attribute \"" | |||
+ key + "\"", locator); | |||
} | |||
} | |||
if (name == null || className == null) { | |||
String msg = "Underspecified " + tag + " declaration."; | |||
throw new SAXParseException(msg, locator); | |||
} | |||
} | |||
/** | |||
* SAX callback handler | |||
* | |||
* @param tag XML tag | |||
* @param attrs attributes | |||
* @exception SAXParseException parse trouble | |||
*/ | |||
public void startElement(String tag, AttributeList attrs) | |||
throws SAXParseException { | |||
level ++; | |||
if ("antlib".equals(tag)) { | |||
if (level > 1) { | |||
throw new SAXParseException("Unexpected element: " + tag, | |||
locator); | |||
} | |||
// No attributes to worry about | |||
return; | |||
} | |||
if (level == 1) { | |||
throw new SAXParseException("Missing antlib root element", | |||
locator); | |||
} | |||
// Must have the two attributes declared | |||
parseAttributes(tag, attrs); | |||
try { | |||
if ("role".equals(tag)) { | |||
if (getProject().isRoleDefined(name)) { | |||
String msg = "Cannot override role: " + name; | |||
log(msg, Project.MSG_WARN); | |||
return; | |||
} | |||
// Defining a new role | |||
Class clz = loadClass(className); | |||
if (clz != null) { | |||
getProject().addRoleDefinition(name, clz, | |||
(adapter == null? null : | |||
loadClass(adapter))); | |||
} | |||
return; | |||
} | |||
// Defining a new element kind | |||
//check for name alias | |||
String alias = aliasMap.getProperty(name); | |||
if (alias != null) { | |||
name = alias; | |||
} | |||
//catch an attempted override of an existing name | |||
if (!override && getProject().isDefinedOnRole(tag, name)) { | |||
String msg = "Cannot override " + tag + ": " + name; | |||
log(msg, Project.MSG_WARN); | |||
return; | |||
} | |||
Class clz = loadClass(className); | |||
if (clz != null) | |||
getProject().addDefinitionOnRole(tag, name, clz); | |||
} | |||
catch(BuildException be) { | |||
switch (onerror.getIndex()) { | |||
case FAIL: | |||
throw new SAXParseException(be.getMessage(), locator, be); | |||
case REPORT: | |||
getProject().log(be.getMessage(), Project.MSG_WARN); | |||
break; | |||
default: | |||
getProject().log(be.getMessage(), Project.MSG_DEBUG); | |||
} | |||
} | |||
} | |||
public void endElement(String tag) { | |||
level--; | |||
} | |||
private Class loadClass(String className) | |||
throws SAXParseException { | |||
String msg = null; | |||
try { | |||
//load the named class | |||
Class cls; | |||
if(classloader==null) { | |||
cls=Class.forName(className); | |||
} | |||
else { | |||
cls=classloader.loadClass(className); | |||
} | |||
return cls; | |||
} | |||
catch (ClassNotFoundException cnfe) { | |||
msg = "Class " + className + " cannot be found"; | |||
if (onerror.getIndex() == FAIL) | |||
throw new SAXParseException(msg, locator, cnfe); | |||
} | |||
catch (NoClassDefFoundError ncdfe) { | |||
msg = "Class " + className + " cannot be loaded"; | |||
if (onerror.getIndex() == FAIL) | |||
throw new SAXParseException(msg, locator); | |||
} | |||
if (onerror.getIndex() == REPORT) { | |||
getProject().log(msg, Project.MSG_WARN); | |||
} | |||
else { | |||
getProject().log(msg, Project.MSG_DEBUG); | |||
} | |||
return null; | |||
} | |||
//end inner class AntLibraryHandler | |||
} | |||
/** | |||
* this class is used for alias elements | |||
* | |||
* @author slo | |||
* @created 11 November 2001 | |||
*/ | |||
public static class Alias { | |||
/** | |||
* Description of the Field | |||
*/ | |||
private String name; | |||
/** | |||
* Description of the Field | |||
*/ | |||
private String as; | |||
/** | |||
* Sets the Name attribute of the Alias object | |||
* | |||
* @param name The new Name value | |||
*/ | |||
public void setName(String name) { | |||
this.name = name; | |||
} | |||
/** | |||
* Sets the As attribute of the Alias object | |||
* | |||
* @param as The new As value | |||
*/ | |||
public void setAs(String as) { | |||
this.as = as; | |||
} | |||
//end inner class alias | |||
} | |||
//end class Antlib | |||
} | |||
@@ -1,143 +0,0 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2000-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.tools.ant.types; | |||
import java.lang.reflect.Method; | |||
import org.apache.tools.ant.*; | |||
/** | |||
* Use introspection to "adapt" a DataType to be accepted in a Task position | |||
* | |||
* @author j_a_fernandez@yahoo.com | |||
*/ | |||
public class DataTypeAdapterTask extends Task implements RoleAdapter { | |||
Object proxy; | |||
String id = null; | |||
/** | |||
* Checks a class, whether it is suitable to be adapted. | |||
* | |||
* Throws a BuildException and logs as Project.MSG_ERR for | |||
* conditions, that will cause the task execution to fail. | |||
* Logs other suspicious conditions with Project.MSG_WARN. | |||
*/ | |||
public static void checkClass(final Class typeClass, | |||
final Project project) { | |||
// Any class can be used as a data type | |||
} | |||
/** | |||
* Do the execution. | |||
*/ | |||
public void execute() throws BuildException { | |||
if (id != null) { | |||
// Need to re-register this reference | |||
// The container has register the Adapter instead | |||
project.addReference(id, proxy); | |||
} | |||
} | |||
/** | |||
* Propagate configuration of Project | |||
*/ | |||
public void setProject(Project p) { | |||
super.setProject(p); | |||
// Check to see if the DataType has a setProject method to set | |||
if (proxy instanceof ProjectComponent) { | |||
((ProjectComponent)proxy).setProject(p); | |||
return; | |||
} | |||
// This may not be needed | |||
// We are trying to set project even if is was not declared | |||
// just like TaskAdapter does for beans, this is not done | |||
// by the original code | |||
Method setProjectM = null; | |||
try { | |||
Class c = proxy.getClass(); | |||
setProjectM = | |||
c.getMethod( "setProject", new Class[] {Project.class}); | |||
if(setProjectM != null) { | |||
setProjectM.invoke(proxy, new Object[] {p}); | |||
} | |||
} catch (NoSuchMethodException e) { | |||
// ignore this if the class being used as a task does not have | |||
// a set project method. | |||
} catch( Exception ex ) { | |||
log("Error setting project in " + proxy.getClass(), | |||
Project.MSG_ERR); | |||
throw new BuildException( ex ); | |||
} | |||
} | |||
/** | |||
* Set the target object class | |||
*/ | |||
public void setProxy(Object o) { | |||
this.proxy = o; | |||
} | |||
public Object getProxy() { | |||
return this.proxy ; | |||
} | |||
public void setId(String id) { | |||
log("Setting adapter id to: " + id, Project.MSG_DEBUG); | |||
this.id = id; | |||
} | |||
} |
@@ -1,30 +0,0 @@ | |||
<?xml version="1.0"?> | |||
<project name="local" default="libs" > | |||
<taskdef name="antjar" classname="org.apache.tools.ant.taskdefs.Antjar" /> | |||
<property name="src" location="." /> | |||
<property name="classes" location="../../build/testcases" /> | |||
<property name="contrib" location="../../build/case_contrib.jar" /> | |||
<target name="libs" depends="compile" > | |||
<antjar destfile="${contrib}" antxml="${src}/case-antlib.xml" > | |||
<fileset dir="${classes}" > | |||
<include name="org/**" /> | |||
</fileset> | |||
</antjar> | |||
</target> | |||
<target name="compile" > | |||
<mkdir dir="${classes}" /> | |||
<javac srcdir="${src}" destdir="${classes}" > | |||
<include name="org/**/*.java" /> | |||
</javac> | |||
</target> | |||
<target name="clean" > | |||
<delete dir="${classes}" /> | |||
<delete file='${contrib}'/> | |||
</target> | |||
</project> |
@@ -1,5 +0,0 @@ | |||
<?xml version="1.0" ?> | |||
<antlib version="1.0" > | |||
<task name="case" class="org.apache.ant.contrib.Case" /> | |||
</antlib> |
@@ -1,39 +0,0 @@ | |||
<?xml version="1.0"?> | |||
<project name="case-test" default="test" basedir="."> | |||
<property name="value" value="task.xml" /> | |||
<target name="init"> | |||
<taskdef name="antlib" classname="org.apache.tools.ant.taskdefs.Antlib" /> | |||
<antlib file="../../build/case_contrib.jar" /> | |||
</target> | |||
<target name="test" depends="init,case,test1,test2,test3"> | |||
<echo message="Value=${value}" /> | |||
</target> | |||
<target name="case" > | |||
<case property="value" > | |||
<when value="task.xml" property="value.xml" /> | |||
</case> | |||
<case property="location" > | |||
<when value="loc" property="location.fail" /> | |||
<when value="" property="location.fail" /> | |||
<else property="location.unset" /> | |||
</case> | |||
</target> | |||
<target name="test1" if="value.xml"> | |||
<echo message="Value equals to itself" /> | |||
</target> | |||
<target name="test2" if="location.fail"> | |||
<fail message="Location passed" /> | |||
</target> | |||
<target name="test3" if="location.unset"> | |||
<echo message="Location does not exists" /> | |||
</target> | |||
</project> |
@@ -1,169 +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", "Tomcat", 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.contrib; | |||
import java.io.*; | |||
import java.util.*; | |||
import org.apache.tools.ant.*; | |||
import org.apache.tools.ant.types.*; | |||
/** | |||
* Will set one of the given properties depending on the result of testing | |||
* the value of another property. | |||
* | |||
* <!ELEMENT case (when*, else) > | |||
* <!ATTLIST case property CDATA #REQUIRED > The name of the property to test | |||
* <!ELEMENT when EMPTY > | |||
* <!ATTLIST when value CDATA #REQUIRED > The value to compare and set prop. | |||
* <!ATTLIST when property CDATA #REQUIRED > The name of the property to set | |||
* <!ELEMENT else EMPTY > | |||
* <!ATTLIST else property CDATA #REQUIRED > The name of the property to set otherwise | |||
* <!ATTLIST else value CDATA #IMPLIED > The value to set; default "true". | |||
* | |||
* @author Jose Alberto Fernandez <a href="mailto:jfernandez@viquity.com">jfernandez@viquity.com</a> | |||
*/ | |||
public class Case extends Task { | |||
public class When { | |||
private String property; | |||
private String value; | |||
public void setProperty(String name) { | |||
property = name; | |||
} | |||
public String getProperty() { | |||
return property; | |||
} | |||
public void setValue(String val) { | |||
value = val; | |||
} | |||
public String getValue() { | |||
return value; | |||
} | |||
public boolean tryCase(String caseValue) throws BuildException { | |||
if (property == null) | |||
throw new BuildException("Property attribute is mandatory"); | |||
if (value == null) | |||
throw new BuildException("Value attribute is mandatory"); | |||
if (!value.equals(caseValue)) return false; | |||
if (getProject().getProperty(property) == null) { | |||
getProject().setProperty(property, value); | |||
} else { | |||
log("Override ignored for " + property, Project.MSG_VERBOSE); | |||
} | |||
return true; | |||
} | |||
public void doElse() throws BuildException { | |||
if (property == null) | |||
throw new BuildException("Property attribute is mandatory"); | |||
String elseValue = (value == null) ? "true" : value; | |||
if (getProject().getProperty(property) == null) { | |||
getProject().setProperty(property, elseValue); | |||
} else { | |||
log("Override ignored for " + property, Project.MSG_VERBOSE); | |||
} | |||
} | |||
} | |||
private String caseProperty; | |||
private Vector whenList = new Vector(); | |||
private When elseCase = null; | |||
public When createWhen() throws BuildException { | |||
When w = new When(); | |||
whenList.addElement(w); | |||
return w; | |||
} | |||
public When createElse() throws BuildException { | |||
if (elseCase != null) | |||
throw new BuildException("Only one else element allowed per case"); | |||
return (elseCase = new When()); | |||
} | |||
public void setProperty(String property) { | |||
this.caseProperty = property; | |||
} | |||
public void execute() throws BuildException { | |||
if (caseProperty == null) { | |||
throw new BuildException("property attribute is required", | |||
location); | |||
} | |||
String caseValue = getProject().getProperty(caseProperty); | |||
for (Enumeration e = whenList.elements(); e.hasMoreElements(); ) { | |||
When w = (When)e.nextElement(); | |||
if (w.tryCase(caseValue)) return; | |||
} | |||
if (elseCase != null) | |||
elseCase.doElse(); | |||
} | |||
} |