You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by hi...@apache.org on 2012/07/30 23:13:03 UTC
svn commit: r1367306 -
/ant/core/trunk/src/main/org/apache/tools/ant/Target.java
Author: hibou
Date: Mon Jul 30 21:13:02 2012
New Revision: 1367306
URL: http://svn.apache.org/viewvc?rev=1367306&view=rev
Log:
Allow Condition as if and unless attributes of targets and extension points (Java API only)
Modified:
ant/core/trunk/src/main/org/apache/tools/ant/Target.java
Modified: ant/core/trunk/src/main/org/apache/tools/ant/Target.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/Target.java?rev=1367306&r1=1367305&r2=1367306&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/Target.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/Target.java Mon Jul 30 21:13:02 2012
@@ -26,6 +26,7 @@ import java.util.List;
import java.util.StringTokenizer;
import org.apache.tools.ant.property.LocalProperties;
+import org.apache.tools.ant.taskdefs.condition.Condition;
/**
* Class to implement a target object with required parameters.
@@ -45,6 +46,10 @@ public class Target implements TaskConta
/** The "unless" condition to test on execution. */
private String unlessCondition = "";
+ private Condition if_;
+
+ private Condition unless;
+
/** List of targets this target is dependent on. */
private List/*<String>*/ dependencies = null;
@@ -73,6 +78,8 @@ public class Target implements TaskConta
this.name = other.name;
this.ifCondition = other.ifCondition;
this.unlessCondition = other.unlessCondition;
+ this.if_ = other.if_;
+ this.unless = other.unless;
this.dependencies = other.dependencies;
this.location = other.location;
this.project = other.project;
@@ -293,6 +300,15 @@ public class Target implements TaskConta
}
/**
+ * Same as {@link #setIf(String)} but requires a {@link Condition} instance
+ *
+ * @since 1.9
+ */
+ public void setIf(Condition if_) {
+ this.if_ = if_;
+ }
+
+ /**
* Sets the "unless" condition to test on execution. This is the
* name of a property to test for existence - if the property
* is set, the task will not execute. The property goes
@@ -321,6 +337,15 @@ public class Target implements TaskConta
}
/**
+ * Same as {@link #setUnless(String)} but requires a {@link Condition} instance
+ *
+ * @since 1.9
+ */
+ public void setUnless(Condition unless) {
+ this.unless = unless;
+ }
+
+ /**
* Sets the description of this target.
*
* @param description The description for this target.
@@ -450,32 +475,48 @@ public class Target implements TaskConta
}
/**
- * Tests whether or not the "if" condition allows the execution of this target.
+ * Tests whether or not the "if" conditions (via String AND Condition)
+ * allows the execution of this target.
*
- * @return whether or not the "if" condition is satisfied. If no
+ * @return whether or not both "if" conditions are satisfied. If no
* condition (or an empty condition) has been set,
* <code>true</code> is returned.
*
* @see #setIf(String)
+ * @see #setIf(Condition)
*/
private boolean testIfAllows() {
PropertyHelper propertyHelper = PropertyHelper.getPropertyHelper(getProject());
Object o = propertyHelper.parseProperties(ifCondition);
- return propertyHelper.testIfCondition(o);
+ if (!propertyHelper.testIfCondition(o)) {
+ return false;
+ }
+ if (if_ != null && !if_.eval()) {
+ return false;
+ }
+ return true;
}
/**
- * Tests whether or not the "unless" condition allows the execution of this target.
+ * Tests whether or not the "unless" conditions (via String AND Condition)
+ * allows the execution of this target.
*
- * @return whether or not the "unless" condition is satisfied. If no
+ * @return whether or not both "unless" condition are satisfied. If no
* condition (or an empty condition) has been set,
* <code>true</code> is returned.
*
* @see #setUnless(String)
+ * @see #setUnless(Condition)
*/
private boolean testUnlessAllows() {
PropertyHelper propertyHelper = PropertyHelper.getPropertyHelper(getProject());
Object o = propertyHelper.parseProperties(unlessCondition);
- return propertyHelper.testUnlessCondition(o);
+ if (!propertyHelper.testUnlessCondition(o)) {
+ return false;
+ }
+ if (unless != null && unless.eval()) {
+ return false;
+ }
+ return true;
}
}
Re: svn commit: r1367306 - /ant/core/trunk/src/main/org/apache/tools/ant/Target.java
Posted by Nicolas Lalevée <ni...@hibnet.org>.
It is indeed nicer. committed.
Nicolas
Le 30 juil. 2012 à 23:48, Nicolas Lalevée a écrit :
>
> Le 30 juil. 2012 à 23:25, Matt Benson a écrit :
>
>> Can't this be done more cleanly by internally wrapping all if/unless
>> to a Condition instance?
>
> I haven't thought of that.
> Probably it will make the test of executability simpler, but not the setter. I will try something.
>
> Nicolas
>
>>
>> Matt
>>
>> On Mon, Jul 30, 2012 at 4:13 PM, <hi...@apache.org> wrote:
>>> Author: hibou
>>> Date: Mon Jul 30 21:13:02 2012
>>> New Revision: 1367306
>>>
>>> URL: http://svn.apache.org/viewvc?rev=1367306&view=rev
>>> Log:
>>> Allow Condition as if and unless attributes of targets and extension points (Java API only)
>>>
>>> Modified:
>>> ant/core/trunk/src/main/org/apache/tools/ant/Target.java
>>>
>>> Modified: ant/core/trunk/src/main/org/apache/tools/ant/Target.java
>>> URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/Target.java?rev=1367306&r1=1367305&r2=1367306&view=diff
>>> ==============================================================================
>>> --- ant/core/trunk/src/main/org/apache/tools/ant/Target.java (original)
>>> +++ ant/core/trunk/src/main/org/apache/tools/ant/Target.java Mon Jul 30 21:13:02 2012
>>> @@ -26,6 +26,7 @@ import java.util.List;
>>> import java.util.StringTokenizer;
>>>
>>> import org.apache.tools.ant.property.LocalProperties;
>>> +import org.apache.tools.ant.taskdefs.condition.Condition;
>>>
>>> /**
>>> * Class to implement a target object with required parameters.
>>> @@ -45,6 +46,10 @@ public class Target implements TaskConta
>>> /** The "unless" condition to test on execution. */
>>> private String unlessCondition = "";
>>>
>>> + private Condition if_;
>>> +
>>> + private Condition unless;
>>> +
>>> /** List of targets this target is dependent on. */
>>> private List/*<String>*/ dependencies = null;
>>>
>>> @@ -73,6 +78,8 @@ public class Target implements TaskConta
>>> this.name = other.name;
>>> this.ifCondition = other.ifCondition;
>>> this.unlessCondition = other.unlessCondition;
>>> + this.if_ = other.if_;
>>> + this.unless = other.unless;
>>> this.dependencies = other.dependencies;
>>> this.location = other.location;
>>> this.project = other.project;
>>> @@ -293,6 +300,15 @@ public class Target implements TaskConta
>>> }
>>>
>>> /**
>>> + * Same as {@link #setIf(String)} but requires a {@link Condition} instance
>>> + *
>>> + * @since 1.9
>>> + */
>>> + public void setIf(Condition if_) {
>>> + this.if_ = if_;
>>> + }
>>> +
>>> + /**
>>> * Sets the "unless" condition to test on execution. This is the
>>> * name of a property to test for existence - if the property
>>> * is set, the task will not execute. The property goes
>>> @@ -321,6 +337,15 @@ public class Target implements TaskConta
>>> }
>>>
>>> /**
>>> + * Same as {@link #setUnless(String)} but requires a {@link Condition} instance
>>> + *
>>> + * @since 1.9
>>> + */
>>> + public void setUnless(Condition unless) {
>>> + this.unless = unless;
>>> + }
>>> +
>>> + /**
>>> * Sets the description of this target.
>>> *
>>> * @param description The description for this target.
>>> @@ -450,32 +475,48 @@ public class Target implements TaskConta
>>> }
>>>
>>> /**
>>> - * Tests whether or not the "if" condition allows the execution of this target.
>>> + * Tests whether or not the "if" conditions (via String AND Condition)
>>> + * allows the execution of this target.
>>> *
>>> - * @return whether or not the "if" condition is satisfied. If no
>>> + * @return whether or not both "if" conditions are satisfied. If no
>>> * condition (or an empty condition) has been set,
>>> * <code>true</code> is returned.
>>> *
>>> * @see #setIf(String)
>>> + * @see #setIf(Condition)
>>> */
>>> private boolean testIfAllows() {
>>> PropertyHelper propertyHelper = PropertyHelper.getPropertyHelper(getProject());
>>> Object o = propertyHelper.parseProperties(ifCondition);
>>> - return propertyHelper.testIfCondition(o);
>>> + if (!propertyHelper.testIfCondition(o)) {
>>> + return false;
>>> + }
>>> + if (if_ != null && !if_.eval()) {
>>> + return false;
>>> + }
>>> + return true;
>>> }
>>>
>>> /**
>>> - * Tests whether or not the "unless" condition allows the execution of this target.
>>> + * Tests whether or not the "unless" conditions (via String AND Condition)
>>> + * allows the execution of this target.
>>> *
>>> - * @return whether or not the "unless" condition is satisfied. If no
>>> + * @return whether or not both "unless" condition are satisfied. If no
>>> * condition (or an empty condition) has been set,
>>> * <code>true</code> is returned.
>>> *
>>> * @see #setUnless(String)
>>> + * @see #setUnless(Condition)
>>> */
>>> private boolean testUnlessAllows() {
>>> PropertyHelper propertyHelper = PropertyHelper.getPropertyHelper(getProject());
>>> Object o = propertyHelper.parseProperties(unlessCondition);
>>> - return propertyHelper.testUnlessCondition(o);
>>> + if (!propertyHelper.testUnlessCondition(o)) {
>>> + return false;
>>> + }
>>> + if (unless != null && unless.eval()) {
>>> + return false;
>>> + }
>>> + return true;
>>> }
>>> }
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
>> For additional commands, e-mail: dev-help@ant.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
> For additional commands, e-mail: dev-help@ant.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org
Re: svn commit: r1367306 - /ant/core/trunk/src/main/org/apache/tools/ant/Target.java
Posted by Nicolas Lalevée <ni...@hibnet.org>.
Le 30 juil. 2012 à 23:25, Matt Benson a écrit :
> Can't this be done more cleanly by internally wrapping all if/unless
> to a Condition instance?
I haven't thought of that.
Probably it will make the test of executability simpler, but not the setter. I will try something.
Nicolas
>
> Matt
>
> On Mon, Jul 30, 2012 at 4:13 PM, <hi...@apache.org> wrote:
>> Author: hibou
>> Date: Mon Jul 30 21:13:02 2012
>> New Revision: 1367306
>>
>> URL: http://svn.apache.org/viewvc?rev=1367306&view=rev
>> Log:
>> Allow Condition as if and unless attributes of targets and extension points (Java API only)
>>
>> Modified:
>> ant/core/trunk/src/main/org/apache/tools/ant/Target.java
>>
>> Modified: ant/core/trunk/src/main/org/apache/tools/ant/Target.java
>> URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/Target.java?rev=1367306&r1=1367305&r2=1367306&view=diff
>> ==============================================================================
>> --- ant/core/trunk/src/main/org/apache/tools/ant/Target.java (original)
>> +++ ant/core/trunk/src/main/org/apache/tools/ant/Target.java Mon Jul 30 21:13:02 2012
>> @@ -26,6 +26,7 @@ import java.util.List;
>> import java.util.StringTokenizer;
>>
>> import org.apache.tools.ant.property.LocalProperties;
>> +import org.apache.tools.ant.taskdefs.condition.Condition;
>>
>> /**
>> * Class to implement a target object with required parameters.
>> @@ -45,6 +46,10 @@ public class Target implements TaskConta
>> /** The "unless" condition to test on execution. */
>> private String unlessCondition = "";
>>
>> + private Condition if_;
>> +
>> + private Condition unless;
>> +
>> /** List of targets this target is dependent on. */
>> private List/*<String>*/ dependencies = null;
>>
>> @@ -73,6 +78,8 @@ public class Target implements TaskConta
>> this.name = other.name;
>> this.ifCondition = other.ifCondition;
>> this.unlessCondition = other.unlessCondition;
>> + this.if_ = other.if_;
>> + this.unless = other.unless;
>> this.dependencies = other.dependencies;
>> this.location = other.location;
>> this.project = other.project;
>> @@ -293,6 +300,15 @@ public class Target implements TaskConta
>> }
>>
>> /**
>> + * Same as {@link #setIf(String)} but requires a {@link Condition} instance
>> + *
>> + * @since 1.9
>> + */
>> + public void setIf(Condition if_) {
>> + this.if_ = if_;
>> + }
>> +
>> + /**
>> * Sets the "unless" condition to test on execution. This is the
>> * name of a property to test for existence - if the property
>> * is set, the task will not execute. The property goes
>> @@ -321,6 +337,15 @@ public class Target implements TaskConta
>> }
>>
>> /**
>> + * Same as {@link #setUnless(String)} but requires a {@link Condition} instance
>> + *
>> + * @since 1.9
>> + */
>> + public void setUnless(Condition unless) {
>> + this.unless = unless;
>> + }
>> +
>> + /**
>> * Sets the description of this target.
>> *
>> * @param description The description for this target.
>> @@ -450,32 +475,48 @@ public class Target implements TaskConta
>> }
>>
>> /**
>> - * Tests whether or not the "if" condition allows the execution of this target.
>> + * Tests whether or not the "if" conditions (via String AND Condition)
>> + * allows the execution of this target.
>> *
>> - * @return whether or not the "if" condition is satisfied. If no
>> + * @return whether or not both "if" conditions are satisfied. If no
>> * condition (or an empty condition) has been set,
>> * <code>true</code> is returned.
>> *
>> * @see #setIf(String)
>> + * @see #setIf(Condition)
>> */
>> private boolean testIfAllows() {
>> PropertyHelper propertyHelper = PropertyHelper.getPropertyHelper(getProject());
>> Object o = propertyHelper.parseProperties(ifCondition);
>> - return propertyHelper.testIfCondition(o);
>> + if (!propertyHelper.testIfCondition(o)) {
>> + return false;
>> + }
>> + if (if_ != null && !if_.eval()) {
>> + return false;
>> + }
>> + return true;
>> }
>>
>> /**
>> - * Tests whether or not the "unless" condition allows the execution of this target.
>> + * Tests whether or not the "unless" conditions (via String AND Condition)
>> + * allows the execution of this target.
>> *
>> - * @return whether or not the "unless" condition is satisfied. If no
>> + * @return whether or not both "unless" condition are satisfied. If no
>> * condition (or an empty condition) has been set,
>> * <code>true</code> is returned.
>> *
>> * @see #setUnless(String)
>> + * @see #setUnless(Condition)
>> */
>> private boolean testUnlessAllows() {
>> PropertyHelper propertyHelper = PropertyHelper.getPropertyHelper(getProject());
>> Object o = propertyHelper.parseProperties(unlessCondition);
>> - return propertyHelper.testUnlessCondition(o);
>> + if (!propertyHelper.testUnlessCondition(o)) {
>> + return false;
>> + }
>> + if (unless != null && unless.eval()) {
>> + return false;
>> + }
>> + return true;
>> }
>> }
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
> For additional commands, e-mail: dev-help@ant.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org
Re: svn commit: r1367306 - /ant/core/trunk/src/main/org/apache/tools/ant/Target.java
Posted by Matt Benson <gu...@gmail.com>.
Can't this be done more cleanly by internally wrapping all if/unless
to a Condition instance?
Matt
On Mon, Jul 30, 2012 at 4:13 PM, <hi...@apache.org> wrote:
> Author: hibou
> Date: Mon Jul 30 21:13:02 2012
> New Revision: 1367306
>
> URL: http://svn.apache.org/viewvc?rev=1367306&view=rev
> Log:
> Allow Condition as if and unless attributes of targets and extension points (Java API only)
>
> Modified:
> ant/core/trunk/src/main/org/apache/tools/ant/Target.java
>
> Modified: ant/core/trunk/src/main/org/apache/tools/ant/Target.java
> URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/Target.java?rev=1367306&r1=1367305&r2=1367306&view=diff
> ==============================================================================
> --- ant/core/trunk/src/main/org/apache/tools/ant/Target.java (original)
> +++ ant/core/trunk/src/main/org/apache/tools/ant/Target.java Mon Jul 30 21:13:02 2012
> @@ -26,6 +26,7 @@ import java.util.List;
> import java.util.StringTokenizer;
>
> import org.apache.tools.ant.property.LocalProperties;
> +import org.apache.tools.ant.taskdefs.condition.Condition;
>
> /**
> * Class to implement a target object with required parameters.
> @@ -45,6 +46,10 @@ public class Target implements TaskConta
> /** The "unless" condition to test on execution. */
> private String unlessCondition = "";
>
> + private Condition if_;
> +
> + private Condition unless;
> +
> /** List of targets this target is dependent on. */
> private List/*<String>*/ dependencies = null;
>
> @@ -73,6 +78,8 @@ public class Target implements TaskConta
> this.name = other.name;
> this.ifCondition = other.ifCondition;
> this.unlessCondition = other.unlessCondition;
> + this.if_ = other.if_;
> + this.unless = other.unless;
> this.dependencies = other.dependencies;
> this.location = other.location;
> this.project = other.project;
> @@ -293,6 +300,15 @@ public class Target implements TaskConta
> }
>
> /**
> + * Same as {@link #setIf(String)} but requires a {@link Condition} instance
> + *
> + * @since 1.9
> + */
> + public void setIf(Condition if_) {
> + this.if_ = if_;
> + }
> +
> + /**
> * Sets the "unless" condition to test on execution. This is the
> * name of a property to test for existence - if the property
> * is set, the task will not execute. The property goes
> @@ -321,6 +337,15 @@ public class Target implements TaskConta
> }
>
> /**
> + * Same as {@link #setUnless(String)} but requires a {@link Condition} instance
> + *
> + * @since 1.9
> + */
> + public void setUnless(Condition unless) {
> + this.unless = unless;
> + }
> +
> + /**
> * Sets the description of this target.
> *
> * @param description The description for this target.
> @@ -450,32 +475,48 @@ public class Target implements TaskConta
> }
>
> /**
> - * Tests whether or not the "if" condition allows the execution of this target.
> + * Tests whether or not the "if" conditions (via String AND Condition)
> + * allows the execution of this target.
> *
> - * @return whether or not the "if" condition is satisfied. If no
> + * @return whether or not both "if" conditions are satisfied. If no
> * condition (or an empty condition) has been set,
> * <code>true</code> is returned.
> *
> * @see #setIf(String)
> + * @see #setIf(Condition)
> */
> private boolean testIfAllows() {
> PropertyHelper propertyHelper = PropertyHelper.getPropertyHelper(getProject());
> Object o = propertyHelper.parseProperties(ifCondition);
> - return propertyHelper.testIfCondition(o);
> + if (!propertyHelper.testIfCondition(o)) {
> + return false;
> + }
> + if (if_ != null && !if_.eval()) {
> + return false;
> + }
> + return true;
> }
>
> /**
> - * Tests whether or not the "unless" condition allows the execution of this target.
> + * Tests whether or not the "unless" conditions (via String AND Condition)
> + * allows the execution of this target.
> *
> - * @return whether or not the "unless" condition is satisfied. If no
> + * @return whether or not both "unless" condition are satisfied. If no
> * condition (or an empty condition) has been set,
> * <code>true</code> is returned.
> *
> * @see #setUnless(String)
> + * @see #setUnless(Condition)
> */
> private boolean testUnlessAllows() {
> PropertyHelper propertyHelper = PropertyHelper.getPropertyHelper(getProject());
> Object o = propertyHelper.parseProperties(unlessCondition);
> - return propertyHelper.testUnlessCondition(o);
> + if (!propertyHelper.testUnlessCondition(o)) {
> + return false;
> + }
> + if (unless != null && unless.eval()) {
> + return false;
> + }
> + return true;
> }
> }
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org