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. | |||
| /** | |||
| * Enable JXPath dynamic properties | |||
| * Enable JXPath dynamic properties. | |||
| * | |||
| * @author Costin Manolache | |||
| * @author Nicola Ken Barozzi | |||
| @@ -74,35 +74,24 @@ import org.apache.commons.jxpath.*; | |||
| public class JXPath extends Task { | |||
| public static String PREFIX="jxpath:"; | |||
| JXPathContext jxpathCtx; | |||
| JXPathPropertyHelper helper=new JXPathPropertyHelper(); | |||
| public JXPath() { | |||
| } | |||
| 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() { | |||
| 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 ); | |||
| 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 ); | |||
| @@ -112,15 +101,13 @@ public class JXPath extends Task { | |||
| static class JXPathPropertyHelper extends PropertyHelper { | |||
| 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() ); | |||
| jxpathCtx.setValue( name, v ); | |||
| @@ -128,10 +115,12 @@ public class JXPath extends Task { | |||
| } | |||
| 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 ); | |||
| //System.out.println("JXPath: getProperty " + ns + " " + name + "=" + o + o.getClass()); | |||
| @@ -148,14 +137,11 @@ public class JXPath extends Task { | |||
| while (iter.hasNext()) { | |||
| Object o = iter.next(); | |||
| //System.out.println("JXPath: getProperty " + ns + " " + name + "=" + o + o.getClass()); | |||
| result += ", "+o; | |||
| } | |||
| return result; | |||
| } | |||
| } | |||
| @@ -67,6 +67,7 @@ import org.apache.commons.jxpath.*; | |||
| * Set a JXPath property | |||
| * | |||
| * | |||
| * @deprecated A generic <property> should be used. | |||
| * @author Costin Manolache | |||
| */ | |||
| public class JXPathSet extends Task { | |||
| @@ -55,6 +55,7 @@ | |||
| package org.apache.tools.ant.taskdefs.optional; | |||
| import org.apache.tools.ant.*; | |||
| import org.apache.tools.ant.PropertyHelper; | |||
| import org.apache.tools.ant.types.*; | |||
| import java.io.*; | |||
| import java.util.*; | |||
| @@ -67,43 +68,47 @@ import org.apache.commons.jexl.*; | |||
| * | |||
| * @author Costin Manolache | |||
| */ | |||
| public class JexlProperties extends Task implements PropertyInterceptor { | |||
| JexlContext jc; | |||
| public class JexlProperties extends Task { | |||
| public static String PREFIX="jexl:"; | |||
| JexlPropertyHelper helper=new JexlPropertyHelper(); | |||
| 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() { | |||
| PropertyHelper2 phelper=PropertyHelper2.getPropertyHelper( project ); | |||
| phelper.addPropertyInterceptor( this ); | |||
| /* | |||
| * 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; | |||
| import org.apache.tools.ant.*; | |||
| import org.apache.tools.ant.PropertyHelper; | |||
| import org.apache.tools.ant.types.*; | |||
| import java.io.*; | |||
| import java.util.*; | |||
| @@ -69,49 +70,56 @@ import org.apache.velocity.Template; | |||
| * | |||
| * @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:"; | |||
| VelocityPropertyHelper helper=new VelocityPropertyHelper(); | |||
| 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() { | |||
| return engine; | |||
| return helper.engine; | |||
| } | |||
| public void execute() { | |||
| 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 ) { | |||
| ex.printStackTrace(); | |||
| } | |||