It seems to work now :-) git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@273721 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -66,7 +66,7 @@ import org.apache.commons.jxpath.*; | |||||
| // Experimental: need to add code to select the 'root', etc. | // Experimental: need to add code to select the 'root', etc. | ||||
| /** | /** | ||||
| * Enable JXPath dynamic properties | |||||
| * Enable JXPath dynamic properties. | |||||
| * | * | ||||
| * @author Costin Manolache | * @author Costin Manolache | ||||
| * @author Nicola Ken Barozzi | * @author Nicola Ken Barozzi | ||||
| @@ -74,35 +74,24 @@ import org.apache.commons.jxpath.*; | |||||
| public class JXPath extends Task { | public class JXPath extends Task { | ||||
| public static String PREFIX="jxpath:"; | public static String PREFIX="jxpath:"; | ||||
| JXPathContext jxpathCtx; | |||||
| JXPathPropertyHelper helper=new JXPathPropertyHelper(); | |||||
| public JXPath() { | public JXPath() { | ||||
| } | } | ||||
| public JXPathContext getJXPathContext() { | public JXPathContext getJXPathContext() { | ||||
| return jxpathCtx; | |||||
| } | |||||
| // testing | |||||
| String foo; | |||||
| public void setFoo( String s ) { | |||||
| System.out.println("Set foo " + s ); | |||||
| foo=s; | |||||
| } | |||||
| public String getFoo() { | |||||
| return foo; | |||||
| return helper.jxpathCtx; | |||||
| } | } | ||||
| public void execute() { | public void execute() { | ||||
| JXPathIntrospector.registerDynamicClass(Hashtable.class, JXPathHashtableHandler.class); | JXPathIntrospector.registerDynamicClass(Hashtable.class, JXPathHashtableHandler.class); | ||||
| jxpathCtx=JXPathContext.newContext( project ); | |||||
| jxpathCtx.setVariables(new AntVariables()); | |||||
| helper.jxpathCtx=JXPathContext.newContext( project ); | |||||
| helper.jxpathCtx.setVariables(new AntVariables()); | |||||
| PropertyHelper phelper=PropertyHelper.getPropertyHelper( project ); | PropertyHelper phelper=PropertyHelper.getPropertyHelper( project ); | ||||
| JXPathPropertyHelper hook=new JXPathPropertyHelper(jxpathCtx); | |||||
| hook.setNext( phelper.getNext() ); | |||||
| phelper.setNext( hook ); | |||||
| helper.setProject( project ); | |||||
| helper.setNext( phelper.getNext() ); | |||||
| phelper.setNext( helper ); | |||||
| project.addReference( "jxpathTask", this ); | project.addReference( "jxpathTask", this ); | ||||
| @@ -112,15 +101,13 @@ public class JXPath extends Task { | |||||
| static class JXPathPropertyHelper extends PropertyHelper { | static class JXPathPropertyHelper extends PropertyHelper { | ||||
| JXPathContext jxpathCtx; | JXPathContext jxpathCtx; | ||||
| public JXPathPropertyHelper( JXPathContext jxCtx ) { | |||||
| this.jxpathCtx=jxCtx; | |||||
| } | |||||
| public boolean setProperty( String ns, String name, Object v, boolean inh, | |||||
| boolean user, boolean isNew) | |||||
| public boolean setPropertyHook( String ns, String name, Object v, boolean inh, | |||||
| boolean user, boolean isNew) | |||||
| { | { | ||||
| if( ! name.startsWith(PREFIX) ) | |||||
| return false; | |||||
| if( ! name.startsWith(PREFIX) ) { | |||||
| // pass to next | |||||
| return super.setPropertyHook(ns, name, v, inh, user, isNew); | |||||
| } | |||||
| name=name.substring( PREFIX.length() ); | name=name.substring( PREFIX.length() ); | ||||
| jxpathCtx.setValue( name, v ); | jxpathCtx.setValue( name, v ); | ||||
| @@ -128,10 +115,12 @@ public class JXPath extends Task { | |||||
| } | } | ||||
| public Object getPropertyHook( String ns, String name , boolean user) { | public Object getPropertyHook( String ns, String name , boolean user) { | ||||
| if( ! name.startsWith(PREFIX) ) | |||||
| return null; | |||||
| name=name.substring( PREFIX.length() ); | |||||
| if( ! name.startsWith(PREFIX) ) { | |||||
| // pass to next | |||||
| return super.getPropertyHook(ns, name, user); | |||||
| } | |||||
| name=name.substring( PREFIX.length() ); | |||||
| //Object o=jxpathCtx.getValue( name ); | //Object o=jxpathCtx.getValue( name ); | ||||
| //System.out.println("JXPath: getProperty " + ns + " " + name + "=" + o + o.getClass()); | //System.out.println("JXPath: getProperty " + ns + " " + name + "=" + o + o.getClass()); | ||||
| @@ -148,14 +137,11 @@ public class JXPath extends Task { | |||||
| while (iter.hasNext()) { | while (iter.hasNext()) { | ||||
| Object o = iter.next(); | Object o = iter.next(); | ||||
| //System.out.println("JXPath: getProperty " + ns + " " + name + "=" + o + o.getClass()); | |||||
| result += ", "+o; | result += ", "+o; | ||||
| } | } | ||||
| return result; | return result; | ||||
| } | } | ||||
| } | } | ||||
| @@ -67,6 +67,7 @@ import org.apache.commons.jxpath.*; | |||||
| * Set a JXPath property | * Set a JXPath property | ||||
| * | * | ||||
| * | * | ||||
| * @deprecated A generic <property> should be used. | |||||
| * @author Costin Manolache | * @author Costin Manolache | ||||
| */ | */ | ||||
| public class JXPathSet extends Task { | public class JXPathSet extends Task { | ||||
| @@ -55,6 +55,7 @@ | |||||
| package org.apache.tools.ant.taskdefs.optional; | package org.apache.tools.ant.taskdefs.optional; | ||||
| import org.apache.tools.ant.*; | import org.apache.tools.ant.*; | ||||
| import org.apache.tools.ant.PropertyHelper; | |||||
| import org.apache.tools.ant.types.*; | import org.apache.tools.ant.types.*; | ||||
| import java.io.*; | import java.io.*; | ||||
| import java.util.*; | import java.util.*; | ||||
| @@ -67,43 +68,47 @@ import org.apache.commons.jexl.*; | |||||
| * | * | ||||
| * @author Costin Manolache | * @author Costin Manolache | ||||
| */ | */ | ||||
| public class JexlProperties extends Task implements PropertyInterceptor { | |||||
| JexlContext jc; | |||||
| public class JexlProperties extends Task { | |||||
| public static String PREFIX="jexl:"; | public static String PREFIX="jexl:"; | ||||
| JexlPropertyHelper helper=new JexlPropertyHelper(); | |||||
| public JexlProperties() { | public JexlProperties() { | ||||
| } | } | ||||
| public boolean setProperty( Object ctx, String ns, String name, Object value ) { | |||||
| return false; | |||||
| } | |||||
| public Object getProperty( Object p, String ns, String name ) { | |||||
| if( ! name.startsWith(PREFIX) ) | |||||
| return null; | |||||
| try { | |||||
| name=name.substring( PREFIX.length() ); | |||||
| Expression e = ExpressionFactory.createExpression(name); | |||||
| Object o = e.evaluate(jc); | |||||
| static class JexlPropertyHelper extends PropertyHelper { | |||||
| JexlContext jc; | |||||
| public Object getPropertyHook( String ns, String name, boolean user ) { | |||||
| if( ! name.startsWith(PREFIX) ) { | |||||
| return super.getPropertyHook(ns, name, user); | |||||
| } | |||||
| try { | |||||
| name=name.substring( PREFIX.length() ); | |||||
| Expression e = ExpressionFactory.createExpression(name); | |||||
| Object o = e.evaluate(jc); | |||||
| return o; | |||||
| } catch( Exception ex ) { | |||||
| ex.printStackTrace(); | |||||
| return null; | |||||
| return o; | |||||
| } catch( Exception ex ) { | |||||
| ex.printStackTrace(); | |||||
| return null; | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| public void execute() { | public void execute() { | ||||
| PropertyHelper2 phelper=PropertyHelper2.getPropertyHelper( project ); | |||||
| phelper.addPropertyInterceptor( this ); | |||||
| /* | /* | ||||
| * First make a jexlContext and put stuff in it | * First make a jexlContext and put stuff in it | ||||
| */ | */ | ||||
| jc = JexlHelper.createContext(); | |||||
| helper.jc = JexlHelper.createContext(); | |||||
| helper.jc.getVars().put("ant", project); | |||||
| // register it | |||||
| PropertyHelper phelper=PropertyHelper.getPropertyHelper( project ); | |||||
| helper.setNext( phelper.getNext() ); | |||||
| helper.setProject( project ); | |||||
| phelper.setNext( helper ); | |||||
| jc.getVars().put("ant", project); | |||||
| } | } | ||||
| } | } | ||||
| @@ -55,6 +55,7 @@ | |||||
| package org.apache.tools.ant.taskdefs.optional; | package org.apache.tools.ant.taskdefs.optional; | ||||
| import org.apache.tools.ant.*; | import org.apache.tools.ant.*; | ||||
| import org.apache.tools.ant.PropertyHelper; | |||||
| import org.apache.tools.ant.types.*; | import org.apache.tools.ant.types.*; | ||||
| import java.io.*; | import java.io.*; | ||||
| import java.util.*; | import java.util.*; | ||||
| @@ -69,49 +70,56 @@ import org.apache.velocity.Template; | |||||
| * | * | ||||
| * @author Costin Manolache | * @author Costin Manolache | ||||
| */ | */ | ||||
| public class VelocityProperties extends Task implements PropertyInterceptor { | |||||
| VelocityEngine engine; | |||||
| VelocityContext context; | |||||
| public class VelocityProperties extends Task { | |||||
| public static final String PREFIX="vm:"; | public static final String PREFIX="vm:"; | ||||
| VelocityPropertyHelper helper=new VelocityPropertyHelper(); | |||||
| public VelocityProperties() { | public VelocityProperties() { | ||||
| } | } | ||||
| public boolean setProperty( Object c, String ns, String name, Object v ) { | |||||
| return false; | |||||
| } | |||||
| public Object getProperty( Object p, String ns, String name ) { | |||||
| if( ! name.startsWith(PREFIX) ) | |||||
| return null; | |||||
| try { | |||||
| name=name.substring( PREFIX.length() ); | |||||
| StringWriter sw=new StringWriter(); | |||||
| engine.evaluate( context, sw, "antVM", name ); | |||||
| System.out.println("VM: getProperty " + ns + " " + name + "=" + sw.toString()); | |||||
| return sw.toString(); | |||||
| } catch( Exception ex ) { | |||||
| ex.printStackTrace(); | |||||
| return null; | |||||
| static class VelocityPropertyHelper extends PropertyHelper { | |||||
| VelocityEngine engine; | |||||
| VelocityContext context; | |||||
| public Object getPropertyHook( String ns, String name, boolean user ) { | |||||
| if( ! name.startsWith(PREFIX) ) { | |||||
| // pass on to next | |||||
| return super.getPropertyHook(ns, name, user); | |||||
| } | |||||
| try { | |||||
| name=name.substring( PREFIX.length() ); | |||||
| StringWriter sw=new StringWriter(); | |||||
| engine.evaluate( context, sw, "antVM", name ); | |||||
| System.out.println("VM: getProperty " + ns + " " + name + "=" + sw.toString()); | |||||
| return sw.toString(); | |||||
| } catch( Exception ex ) { | |||||
| ex.printStackTrace(); | |||||
| return null; | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| public VelocityEngine getVelocityEngine() { | public VelocityEngine getVelocityEngine() { | ||||
| return engine; | |||||
| return helper.engine; | |||||
| } | } | ||||
| public void execute() { | public void execute() { | ||||
| try { | try { | ||||
| PropertyHelper2 phelper=PropertyHelper2.getPropertyHelper( project ); | |||||
| phelper.addPropertyInterceptor( this ); | |||||
| engine=new VelocityEngine(); | |||||
| engine.init(); | |||||
| // Prepare the engine | |||||
| helper.engine=new VelocityEngine(); | |||||
| helper.engine.init(); | |||||
| context=new VelocityContext(); | |||||
| context.put( "ant", project ); | |||||
| helper.context=new VelocityContext(); | |||||
| helper.context.put( "ant", project ); | |||||
| // Register it | |||||
| PropertyHelper phelper=PropertyHelper.getPropertyHelper( project ); | |||||
| helper.setNext( phelper.getNext() ); | |||||
| helper.setProject( project ); | |||||
| phelper.setNext( helper ); | |||||
| } catch( Exception ex ) { | } catch( Exception ex ) { | ||||
| ex.printStackTrace(); | ex.printStackTrace(); | ||||
| } | } | ||||