Browse Source

Initial attempt to fix the optional.jar ( for 1.5+ ). The ProjectHelper

will replace all optional tasks, using an AntClassLoader to load
( delegation disabled for the optional package ).

Next step is to add a task that adds jars to the loader for optional.
( like junit.jar, etc ).


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@273106 13f79535-47bb-0310-9956-ffa450edef68
master
Costin Manolache 23 years ago
parent
commit
f1a2814606
3 changed files with 42 additions and 2 deletions
  1. +36
    -0
      proposal/sandbox/embed/ProjectHelperImpl2.java
  2. BIN
      proposal/sandbox/embed/ant-sax2.jar
  3. +6
    -2
      proposal/sandbox/embed/build.xml

+ 36
- 0
proposal/sandbox/embed/ProjectHelperImpl2.java View File

@@ -97,6 +97,39 @@ public class ProjectHelperImpl2 extends ProjectHelper {
*/
private static SAXParserFactory parserFactory = null;

/** Will prepare the class loader to allow dynamic modifications
of the classpath. Optional tasks are loaded in a different loader.
*/
public void initClassLoader(Project project) {
try {
// reverse loader
AntClassLoader acl=new AntClassLoader( this.getClass().getClassLoader(), true );
acl.addLoaderPackageRoot( "org.apache.tools.ant.taskdefs.optional");

// XXX find the classpath
String antHome=project.getProperty( "ant.home" );
File optionalJar=new File( antHome + "/lib/optional.jar" );
System.out.println("Optional.jar = " +optionalJar.getAbsolutePath());
acl.addPathElement(optionalJar.getAbsolutePath() );
// reload all optional tasks in this loader.
Hashtable tasks=project.getTaskDefinitions();
Enumeration keys=tasks.keys();
while( keys.hasMoreElements() ) {
String n=(String)keys.nextElement();
Class c=(Class)tasks.get(n);
if( ! c.getName().startsWith( "org.apache.tools.ant.taskdefs.optional" ))
continue;
// System.out.println("Reloading " + n + " " + c + " " + c.getClassLoader() );
c=acl.loadClass( c.getName() );
tasks.put( n, c );
// System.out.println("Loaded " + n + " " + c.getClassLoader() );
}
} catch( Exception ex ) {
ex.printStackTrace();
}
}
/**
* Parses the project file, configuring the project as it goes.
*
@@ -104,6 +137,9 @@ public class ProjectHelperImpl2 extends ProjectHelper {
* be read
*/
public void parse(Project project, Object source) throws BuildException {
// re-init class loader for optional.jar
initClassLoader( project );

AntXmlContext context=new AntXmlContext();
if(source instanceof File) {
context.buildFile=(File)source;


BIN
proposal/sandbox/embed/ant-sax2.jar View File


+ 6
- 2
proposal/sandbox/embed/build.xml View File

@@ -2,13 +2,15 @@
<property name="ant.src" location="../../.." />
<property name="ant.build" location="${ant.src}/build" />
<property name="debug" value="true"/>
<target name="main">
<copy file="ProjectHelperImpl2.java"
<copy id="test" file="ProjectHelperImpl2.java"
todir="${ant.src}/src/main/org/apache/tools/ant/helper" />
<copy file="RuntimeConfigurable2.java"
todir="${ant.src}/src/main/org/apache/tools/ant" />

<echo message="${toString:test}" />

<javac srcdir="${ant.src}/src"
debug="${debug}"
destdir="${ant.build}/classes" >
@@ -27,6 +29,8 @@
<include name="org/apache/tools/ant/helper/ProjectHelperImpl2*" />
<include name="org/apache/tools/ant/RuntimeConfigurable2*" />
</jar>

<copy file="ant-sax2.jar" todir="${ant.home}/lib" />
</target>

<target name="clean">


Loading…
Cancel
Save