jstrachan 2002/06/14 04:22:33 Modified: jelly/src/test/org/apache/commons/jelly/maven project.jelly maven.jelly jelly/src/java/org/apache/commons/jelly/tags/ant AntTagLibrary.java jelly/src/java/org/apache/commons/jelly/tags/werkz ProjectTag.java WerkzTagSupport.java jelly/src/test/org/apache/commons/jelly show_args.jelly Log: Tidied up some more examples, removing the redundant use of <j:expr value=, when just ${foo} will do now. Added a couple of Ant Project helper methods to the AntTagLibrary, to create Ant projects in a single place in the codebase. Also made the Werkz tag library use lazy construction for finding goals, so that a project.jelly can define pre-conditions/pre/post callbacks, then import a maven.jelly file to actually define all the goals and run the build. The 'demo.maven' target shows this in action, allowing a local project.jelly to just define the callbacks then invoke the main maven.jelly Revision Changes Path 1.2 +3 -11 jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/maven/project.jelly Index: project.jelly =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/maven/project.jelly,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- project.jelly 12 Jun 2002 14:38:57 -0000 1.1 +++ project.jelly 14 Jun 2002 11:22:33 -0000 1.2 @@ -3,22 +3,14 @@ <!-- this file represents an optional local project's build --> <werkz:project xmlns:j="jelly:core" xmlns="jelly:ant" xmlns:werkz="jelly:werkz"> - <!-- now include Maven's build --> - <j:include uri="maven.jelly"/> - <!-- define some callbacks that will be fired inside the Maven build --> <werkz:preGoal name="compile"> <echo message="I am a callback: doing something before I compile"/> </werkz:preGoal> - <!-- call all the targets made on the command line --> - <werkz:attain> - <j:forEach var="arg" items="${args}" begin="1"> - <werkz:attainGoal name="${arg}"/> - </j:forEach> - </werkz:attain> - - + <!-- now include Maven's build --> + <j:include uri="maven.jelly"/> + </werkz:project> 1.2 +6 -0 jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/maven/maven.jelly Index: maven.jelly =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/maven/maven.jelly,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- maven.jelly 12 Jun 2002 14:38:57 -0000 1.1 +++ maven.jelly 14 Jun 2002 11:22:33 -0000 1.2 @@ -19,6 +19,12 @@ <echo message="About to run the tests!"/> </werkz:goal> + <!-- call all the targets made on the command line --> + <werkz:attain> + <j:forEach var="arg" items="${args}" begin="1"> + <werkz:attainGoal name="${arg}"/> + </j:forEach> + </werkz:attain> </werkz:project> 1.11 +31 -4 jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant/AntTagLibrary.java Index: AntTagLibrary.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant/AntTagLibrary.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- AntTagLibrary.java 14 Jun 2002 10:24:14 -0000 1.10 +++ AntTagLibrary.java 14 Jun 2002 11:22:33 -0000 1.11 @@ -139,7 +139,36 @@ } public AntTagLibrary() { - this.project = new Project(); + this.project = createProject(); + } + + public AntTagLibrary(Project project) { + this.project = project; + } + + + /** + * A helper method which will attempt to find a project in the current context + * or install one if need be. + * + * #### this method could move to an AntUtils class. + */ + public static Project getProject(JellyContext context) { + Project project = (Project) context.findVariable( "org.apache.commons.jelly.ant.Project" ); + if ( project == null ) { + project = createProject(); + context.setVariable( "org.apache.commons.jelly.ant.Project", project ); + } + return project; + } + + /** + * A helper method to create a new project + * + * #### this method could move to an AntUtils class. + */ + public static Project createProject() { + Project project = new Project(); BuildLogger logger = new NoBannerLogger(); @@ -150,11 +179,9 @@ project.addBuildListener( logger ); project.init(); + return project; } - public AntTagLibrary(Project project) { - this.project = project; - } /** Creates a new script to execute the given tag name and attributes */ public TagScript createTagScript(String name, Attributes attributes) throws Exception { 1.9 +4 -4 jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/werkz/ProjectTag.java Index: ProjectTag.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/werkz/ProjectTag.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- ProjectTag.java 14 Jun 2002 04:04:12 -0000 1.8 +++ ProjectTag.java 14 Jun 2002 11:22:33 -0000 1.9 @@ -112,10 +112,10 @@ // force project to be lazily constructed getProject(); - // AntTagLibrary ant = (AntTagLibrary) context.getTagLibrary( "jelly:ant" ); - - org.apache.tools.ant.Project antProject = - (org.apache.tools.ant.Project) context.findVariable( "org.apache.commons.jelly.ant.Project" ); + org.apache.tools.ant.Project antProject = AntTagLibrary.getProject( context ); + + // allow access to Ant methods via the project class + context.setVariable( "project", antProject ); antProject.getBuildListeners().clear(); 1.5 +3 -1 jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/werkz/WerkzTagSupport.java Index: WerkzTagSupport.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/werkz/WerkzTagSupport.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- WerkzTagSupport.java 12 Jun 2002 19:28:08 -0000 1.4 +++ WerkzTagSupport.java 14 Jun 2002 11:22:33 -0000 1.5 @@ -94,7 +94,9 @@ if ( project == null ) { throw new JellyException( "Must use this tag inside a <maven:project> tag" ); } - Goal goal = project.getGoal(name); + + // #### allow lazy creation of callbacks before the goal is defined... + Goal goal = project.getGoal(name, true); if ( goal == null ) { throw new JellyException( "No such target name: " + name ); } 1.4 +1 -1 jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/show_args.jelly Index: show_args.jelly =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/show_args.jelly,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- show_args.jelly 4 Jun 2002 18:36:49 -0000 1.3 +++ show_args.jelly 14 Jun 2002 11:22:33 -0000 1.4 @@ -6,7 +6,7 @@ <j:jelly xmlns:j="jelly:core"> <arguments> <j:forEach var="arg" items="${args}" begin="1"> - <argument><j:expr value="${arg}"/></argument> + <argument>${arg}"</argument> </j:forEach> </arguments>
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>