Author: hibou
Date: Wed Jun 20 14:00:12 2012
New Revision: 1352105

URL: http://svn.apache.org/viewvc?rev=1352105&view=rev
Log:
Add support if / unless on targets and extension points

Added:
    
ant/sandbox/antdsl/org.apache.ant.antdsl/src/org/apache/ant/antdsl/ExtensionPoint.java
   (with props)
    
ant/sandbox/antdsl/org.apache.ant.antdsl/src/org/apache/ant/antdsl/Target.java  
 (with props)
Modified:
    
ant/sandbox/antdsl/org.apache.ant.antdsl/src/org/apache/ant/antdsl/AbstractAntDslProjectHelper.java
    ant/sandbox/antdsl/org.apache.ant.antdsl/src/org/apache/ant/antdsl/AntDSL.g
    
ant/sandbox/antdsl/org.apache.ant.antdsl/src/org/apache/ant/antdsl/xtext/AntDSL.xtext
    
ant/sandbox/antdsl/org.apache.ant.antdsl/src/org/apache/ant/antdsl/xtext/AntDslXTextProjectHelper.java
    ant/sandbox/antdsl/test/build.ant

Modified: 
ant/sandbox/antdsl/org.apache.ant.antdsl/src/org/apache/ant/antdsl/AbstractAntDslProjectHelper.java
URL: 
http://svn.apache.org/viewvc/ant/sandbox/antdsl/org.apache.ant.antdsl/src/org/apache/ant/antdsl/AbstractAntDslProjectHelper.java?rev=1352105&r1=1352104&r2=1352105&view=diff
==============================================================================
--- 
ant/sandbox/antdsl/org.apache.ant.antdsl/src/org/apache/ant/antdsl/AbstractAntDslProjectHelper.java
 (original)
+++ 
ant/sandbox/antdsl/org.apache.ant.antdsl/src/org/apache/ant/antdsl/AbstractAntDslProjectHelper.java
 Wed Jun 20 14:00:12 2012
@@ -435,6 +435,9 @@ public abstract class AbstractAntDslProj
 
     @SuppressWarnings("unchecked")
     public <T> T mapExpectedUnknown(Project project, AntDslContext context, 
InnerElement eInnerElement, Class<T> c) {
+        if (eInnerElement == null) {
+            return null;
+        }
         UnknownElement element = mapUnknown(project, context, eInnerElement, 
false);
         element.maybeConfigure();
         Object real = element.getRealThing();

Modified: 
ant/sandbox/antdsl/org.apache.ant.antdsl/src/org/apache/ant/antdsl/AntDSL.g
URL: 
http://svn.apache.org/viewvc/ant/sandbox/antdsl/org.apache.ant.antdsl/src/org/apache/ant/antdsl/AntDSL.g?rev=1352105&r1=1352104&r2=1352105&view=diff
==============================================================================
--- ant/sandbox/antdsl/org.apache.ant.antdsl/src/org/apache/ant/antdsl/AntDSL.g 
(original)
+++ ant/sandbox/antdsl/org.apache.ant.antdsl/src/org/apache/ant/antdsl/AntDSL.g 
Wed Jun 20 14:00:12 2012
@@ -27,6 +27,8 @@ package org.apache.ant.antdsl.antlr;
 import org.apache.ant.antdsl.*;
 import org.apache.ant.antdsl.AbstractAntDslProjectHelper.InnerElement;
 import org.apache.ant.antdsl.IfTask.ConditionnalSequential;
+import org.apache.ant.antdsl.Target;
+import org.apache.ant.antdsl.ExtensionPoint;
 import org.apache.tools.ant.*;
 import org.apache.tools.ant.taskdefs.*;
 import org.apache.tools.ant.taskdefs.MacroDef.Attribute;
@@ -72,7 +74,7 @@ project:
     )
     { projectHelper.setupProject(project, context, $name.text, 
readString($basedir.text), $def.text); }
     ( 'namespaces' '{' ( ns=namespace { context.addNamespace(ns.first, 
ns.second); } )* '}')?
-    tl=taskLists?
+    tl=taskList?
     { for (Task t : tl) { context.getImplicitTarget().addTask(t); } }
     (   target
       | extensionPoint
@@ -82,13 +84,15 @@ project:
 namespace returns [Pair<String, String> ns = new Pair<String, String>()]:
     NAME { ns.first = $NAME.text; } ':' STRING { ns.second = 
readString($STRING.text); };
 
-extensionPoint returns [Target t = new Target()]:
-    { context.setCurrentTarget(t); }
+extensionPoint returns [ExtensionPoint ep = new ExtensionPoint()]:
+    { context.setCurrentTarget(ep); }
     desc=DOC?
     'extension-point' n=NAME
     ('depends' d=targetList)?
     ('extensionOf' eo=targetList ('onMiss' onMiss=STRING )? )?
-    { projectHelper.mapCommonTarget(t, project, context, $n.text, $desc.text, 
d, eo, $onMiss.text); }
+    ('if' if_=innerElement { 
ep.setIf(projectHelper.mapExpectedUnknown(project, context, if_, 
Condition.class)); } )?
+    ('unless' unless=innerElement { 
ep.setUnless(projectHelper.mapExpectedUnknown(project, context, unless, 
Condition.class)); } )?
+    { projectHelper.mapCommonTarget(ep, project, context, $n.text, $desc.text, 
d, eo, $onMiss.text); }
     { context.setCurrentTarget(context.getImplicitTarget()); }
     ;
 
@@ -98,13 +102,15 @@ target returns [Target t = new Target()]
     'target' n=NAME
     ('depends' d=targetList)?
     ('extensionOf' eo=targetList ('onMiss' onMiss=STRING)? )?
+    ('if' if_=innerElement { t.setIf(projectHelper.mapExpectedUnknown(project, 
context, if_, Condition.class)); } )?
+    ('unless' unless=innerElement { 
t.setUnless(projectHelper.mapExpectedUnknown(project, context, unless, 
Condition.class)); } )?
     { projectHelper.mapCommonTarget(t, project, context, $n.text, $desc.text, 
d, eo, $onMiss.text); }
-    tl=taskLists?
+    tl=taskList?
     { for (Task task : tl) { t.addTask(task); } }
     { context.setCurrentTarget(context.getImplicitTarget()); }
     ;
 
-taskLists returns [List<Task> tl = new ArrayList<Task>()]:
+taskList returns [List<Task> tl = new ArrayList<Task>()]:
     '{' (t=task { tl.add(t); } )* '}';
 
 targetList returns [List<String> tl = new ArrayList<String>()]:
@@ -132,8 +138,8 @@ innerElements returns [List<InnerElement
 
 innerElement returns [InnerElement ie = new InnerElement()]:
     ns=nsName {ie.ns = ns.first; ie.name = ns.second;}
-    '(' args=arguments? { ie.attributes = args; } ')'
-    ies=innerElements? { ie.children = ies; };
+    '(' args=arguments? { ie.attributes = args; } 
+    (','? ies=innerElements)? { ie.children = ies; } ')';
 
 assignment returns [Task assign]:
     p=propertyAssignment { assign = p; } | r=refAssignment { assign = r; } ;
@@ -152,7 +158,7 @@ branch returns [IfTask if_ = new IfTask(
     { projectHelper.mapCommonTask(project, context, if_); }
     main=conditionedTasks { if_.setMain(main); }
     ('else' elseif=conditionedTasks { if_.addElseIf(elseif); } )*
-    ('else' tl=taskLists
+    ('else' tl=taskList
         { Sequential seq = new Sequential();
           projectHelper.mapCommonTask(project, context, seq);
           for (Task t : tl) { seq.addTask(t); }
@@ -163,7 +169,7 @@ branch returns [IfTask if_ = new IfTask(
 conditionedTasks returns [ConditionnalSequential seq = new 
ConditionnalSequential()]:
     { projectHelper.mapCommonTask(project, context, seq); }
     'if' '(' ie=innerElement { 
seq.setCondition(projectHelper.mapExpectedUnknown(project, context, ie, 
Condition.class)); } ')'
-    tl=taskLists { for (Task t : tl) { seq.addTask(t); } }
+    tl=taskList { for (Task t : tl) { seq.addTask(t); } }
     ;
 
 macrodef returns [MacroDef macroDef = new MacroDef()]:
@@ -182,7 +188,7 @@ macrodef returns [MacroDef macroDef = ne
                 }
              }
           } )? ')'
-    tl=taskLists
+    tl=taskList
     {
         NestedSequential seq = macroDef.createSequential();
         for (Task t : tl) { seq.addTask(t); }

Added: 
ant/sandbox/antdsl/org.apache.ant.antdsl/src/org/apache/ant/antdsl/ExtensionPoint.java
URL: 
http://svn.apache.org/viewvc/ant/sandbox/antdsl/org.apache.ant.antdsl/src/org/apache/ant/antdsl/ExtensionPoint.java?rev=1352105&view=auto
==============================================================================
--- 
ant/sandbox/antdsl/org.apache.ant.antdsl/src/org/apache/ant/antdsl/ExtensionPoint.java
 (added)
+++ 
ant/sandbox/antdsl/org.apache.ant.antdsl/src/org/apache/ant/antdsl/ExtensionPoint.java
 Wed Jun 20 14:00:12 2012
@@ -0,0 +1,54 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.ant.antdsl;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.taskdefs.condition.Condition;
+
+public class ExtensionPoint extends org.apache.tools.ant.ExtensionPoint {
+
+    private Condition if_;
+
+    private Condition unless;
+
+    public void setIf(Condition if_) {
+        this.if_ = if_;
+    }
+
+    public void setUnless(Condition unless) {
+        this.unless = unless;
+    }
+
+    @Override
+    public void execute() throws BuildException {
+        if (if_ != null) {
+            if (!if_.eval()) {
+                getProject().log(this, "Skipped because if condition evaluate 
to false.", Project.MSG_VERBOSE);
+                return;
+            }
+        }
+        if (unless != null) {
+            if (unless.eval()) {
+                getProject().log(this, "Skipped because unless condition 
evaluate to true.", Project.MSG_VERBOSE);
+                return;
+            }
+        }
+        super.execute();
+    }
+}

Propchange: 
ant/sandbox/antdsl/org.apache.ant.antdsl/src/org/apache/ant/antdsl/ExtensionPoint.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
ant/sandbox/antdsl/org.apache.ant.antdsl/src/org/apache/ant/antdsl/ExtensionPoint.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: 
ant/sandbox/antdsl/org.apache.ant.antdsl/src/org/apache/ant/antdsl/ExtensionPoint.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: 
ant/sandbox/antdsl/org.apache.ant.antdsl/src/org/apache/ant/antdsl/Target.java
URL: 
http://svn.apache.org/viewvc/ant/sandbox/antdsl/org.apache.ant.antdsl/src/org/apache/ant/antdsl/Target.java?rev=1352105&view=auto
==============================================================================
--- 
ant/sandbox/antdsl/org.apache.ant.antdsl/src/org/apache/ant/antdsl/Target.java 
(added)
+++ 
ant/sandbox/antdsl/org.apache.ant.antdsl/src/org/apache/ant/antdsl/Target.java 
Wed Jun 20 14:00:12 2012
@@ -0,0 +1,54 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.ant.antdsl;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.taskdefs.condition.Condition;
+
+public class Target extends org.apache.tools.ant.Target {
+
+    private Condition if_;
+
+    private Condition unless;
+
+    public void setIf(Condition if_) {
+        this.if_ = if_;
+    }
+
+    public void setUnless(Condition unless) {
+        this.unless = unless;
+    }
+
+    @Override
+    public void execute() throws BuildException {
+        if (if_ != null) {
+            if (!if_.eval()) {
+                getProject().log(this, "Skipped because if condition evaluate 
to false.", Project.MSG_VERBOSE);
+                return;
+            }
+        }
+        if (unless != null) {
+            if (unless.eval()) {
+                getProject().log(this, "Skipped because unless condition 
evaluate to true.", Project.MSG_VERBOSE);
+                return;
+            }
+        }
+        super.execute();
+    }
+}

Propchange: 
ant/sandbox/antdsl/org.apache.ant.antdsl/src/org/apache/ant/antdsl/Target.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
ant/sandbox/antdsl/org.apache.ant.antdsl/src/org/apache/ant/antdsl/Target.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: 
ant/sandbox/antdsl/org.apache.ant.antdsl/src/org/apache/ant/antdsl/Target.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: 
ant/sandbox/antdsl/org.apache.ant.antdsl/src/org/apache/ant/antdsl/xtext/AntDSL.xtext
URL: 
http://svn.apache.org/viewvc/ant/sandbox/antdsl/org.apache.ant.antdsl/src/org/apache/ant/antdsl/xtext/AntDSL.xtext?rev=1352105&r1=1352104&r2=1352105&view=diff
==============================================================================
--- 
ant/sandbox/antdsl/org.apache.ant.antdsl/src/org/apache/ant/antdsl/xtext/AntDSL.xtext
 (original)
+++ 
ant/sandbox/antdsl/org.apache.ant.antdsl/src/org/apache/ant/antdsl/xtext/AntDSL.xtext
 Wed Jun 20 14:00:12 2012
@@ -34,10 +34,14 @@ ENamespace:
     name=NAME ':' uri=STRING;
 
 EExtensionPoint:
-    description=DOC? 'extension-point' name=NAME (('extensionOf' 
extensionsOf=ETargetList ('onMiss' onMissingExtensionPoint=STRING)? )? & 
('depends' depends=ETargetList)?);
+    description=DOC? 'extension-point' name=NAME (('extensionOf' 
extensionsOf=ETargetList ('onMiss' onMissingExtensionPoint=STRING)? )?
+        & ('depends' depends=ETargetList)? & ('if' if=EInnerElement)? & 
('unless' unless=EInnerElement)?
+    );
 
 ETarget:
-    description=DOC? 'target' name=NAME (('extensionOf' 
extensionsOf=ETargetList ('onMiss' onMissingExtensionPoint=STRING)? )? & 
('depends' depends=ETargetList)? ) tasks=ETaskLists?;
+    description=DOC? 'target' name=NAME (('extensionOf' 
extensionsOf=ETargetList ('onMiss' onMissingExtensionPoint=STRING)? )?
+        & ('depends' depends=ETargetList)? & ('if' if=EInnerElement)? & 
('unless' unless=EInnerElement)?
+    ) tasks=ETaskLists?;
 
 ETaskLists:
     {ETaskLists}
@@ -62,7 +66,7 @@ EInnerElements:
     '{' elements+=EInnerElement+ '}';
 
 EInnerElement:
-    name=ENSName '(' arguments=EArguments? ')' inners=EInnerElements?;
+    name=ENSName '(' arguments=EArguments? (','? inners=EInnerElements)? ')';
 
 EAssignment:
     EPropertyAssignment | EReferenceAssignment;

Modified: 
ant/sandbox/antdsl/org.apache.ant.antdsl/src/org/apache/ant/antdsl/xtext/AntDslXTextProjectHelper.java
URL: 
http://svn.apache.org/viewvc/ant/sandbox/antdsl/org.apache.ant.antdsl/src/org/apache/ant/antdsl/xtext/AntDslXTextProjectHelper.java?rev=1352105&r1=1352104&r2=1352105&view=diff
==============================================================================
--- 
ant/sandbox/antdsl/org.apache.ant.antdsl/src/org/apache/ant/antdsl/xtext/AntDslXTextProjectHelper.java
 (original)
+++ 
ant/sandbox/antdsl/org.apache.ant.antdsl/src/org/apache/ant/antdsl/xtext/AntDslXTextProjectHelper.java
 Wed Jun 20 14:00:12 2012
@@ -26,9 +26,11 @@ import java.util.List;
 
 import org.apache.ant.antdsl.AbstractAntDslProjectHelper;
 import org.apache.ant.antdsl.AntDslContext;
+import org.apache.ant.antdsl.ExtensionPoint;
 import org.apache.ant.antdsl.IfTask;
 import org.apache.ant.antdsl.IfTask.ConditionnalSequential;
 import org.apache.ant.antdsl.RefTask;
+import org.apache.ant.antdsl.Target;
 import org.apache.ant.antdsl.xtext.antdsl.EArgAttribute;
 import org.apache.ant.antdsl.xtext.antdsl.EArgument;
 import org.apache.ant.antdsl.xtext.antdsl.EArguments;
@@ -51,9 +53,7 @@ import org.apache.ant.antdsl.xtext.antds
 import org.apache.ant.antdsl.xtext.antdsl.ETaskLists;
 import org.apache.ant.antdsl.xtext.antdsl.ETextAttribute;
 import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.ExtensionPoint;
 import org.apache.tools.ant.Project;
-import org.apache.tools.ant.Target;
 import org.apache.tools.ant.Task;
 import org.apache.tools.ant.taskdefs.MacroDef;
 import org.apache.tools.ant.taskdefs.MacroDef.Attribute;
@@ -180,6 +180,8 @@ public class AntDslXTextProjectHelper ex
     private Target mapTarget(Project project, AntDslContext context, ETarget 
eTarget) {
         Target target = new Target();
         context.setCurrentTarget(target);
+        target.setIf(mapExpectedUnknown(project, context, 
mapInnerElement(eTarget.getIf()), Condition.class));
+        target.setUnless(mapExpectedUnknown(project, context, 
mapInnerElement(eTarget.getUnless()), Condition.class));
         mapCommonTarget(target, project, context, eTarget.getName(), 
eTarget.getDescription(), mapTargetList(eTarget.getDepends()),
                 mapTargetList(eTarget.getExtensionsOf()), 
eTarget.getOnMissingExtensionPoint());
         ETaskLists tasks = eTarget.getTasks();
@@ -201,6 +203,8 @@ public class AntDslXTextProjectHelper ex
 
     private ExtensionPoint mapExtensionPoint(Project project, AntDslContext 
context, EExtensionPoint eExtensionPoint) {
         ExtensionPoint extensionPoint = new ExtensionPoint();
+        extensionPoint.setIf(mapExpectedUnknown(project, context, 
mapInnerElement(eExtensionPoint.getIf()), Condition.class));
+        extensionPoint.setUnless(mapExpectedUnknown(project, context, 
mapInnerElement(eExtensionPoint.getUnless()), Condition.class));
         mapCommonTarget(extensionPoint, project, context, 
eExtensionPoint.getName(), eExtensionPoint.getDescription(),
                 mapTargetList(eExtensionPoint.getDepends()), 
mapTargetList(eExtensionPoint.getExtensionsOf()),
                 eExtensionPoint.getOnMissingExtensionPoint());

Modified: ant/sandbox/antdsl/test/build.ant
URL: 
http://svn.apache.org/viewvc/ant/sandbox/antdsl/test/build.ant?rev=1352105&r1=1352104&r2=1352105&view=diff
==============================================================================
--- ant/sandbox/antdsl/test/build.ant (original)
+++ ant/sandbox/antdsl/test/build.ant Wed Jun 20 14:00:12 2012
@@ -2,39 +2,53 @@ name : myproject
 default : build
 
 {
-       prop foo = "hello world!"
-       echo(message="${foo}")
+    prop foo = "hello world!"
+    echo(message="${foo}")
 }
 
 % Some documentation of the macro
-macrodef mymacro(arg t = "mymacro") {
-       echo(message = "@{t}")
+macrodef mymacro(arg t = "mymacro")
+{
+    echo(message = "@{t}")
+}
+
+macrodef mymacro2(arg dest, implicit element source)
+{
+    copy(todir = "@{dest}" {
+        source()
+    })
 }
 
-macrodef mymacro2(arg dest, implicit element source) {
-       copy(todir = "@{dest}") {
-               source()
-       }
+target dep {
+    echo(message = "target dependency")
+}
+
+target notexecuted
+    unless isset(property = "foo")
+{
+    echo(message = "must not be printed")
 }
 
 % description of the target
-target build {
-       copy(file = "${basedir}/test/build.ant", tofile = 
"${basedir}/build/test/build.ant.copy")
-       // some comment
-       jar(file = "${basedir}/build/test/my.jar") {
-               fileset(dir="${basedir}/test", includes="*.ant")
-       }
-       mymacro()
-       mymacro(t = "simple macro")
-       /*
-        * Some multiline comment 
-        */
-       if (available(file = "${basedir}/test/build.ant")) {
-               mymacro2(dest = "${basedir}/build/test/dest") {
-                       fileset(dir = "${basedir}", includes="build.*")
-               }
-       } else {
-               fail(message = "fail !")
-       }
+target build
+    depends dep, notexecuted
+{
+    copy(file = "${basedir}/test/build.ant", tofile = 
"${basedir}/build/test/build.ant.copy")
+    // some comment
+    jar(file = "${basedir}/build/test/my.jar" {
+        fileset(dir="${basedir}/test", includes="*.ant")
+    })
+    mymacro()
+    mymacro(t = "simple macro")
+    /*
+     * Some multiline comment 
+     */
+    if (available(file = "${basedir}/test/build.ant")) {
+        mymacro2(dest = "${basedir}/build/test/dest", {
+            fileset(dir = "${basedir}", includes="build.*")
+        })
+    } else {
+        fail(message = "fail !")
+    }
 }
 


Reply via email to