Author: hibou
Date: Wed Feb 17 23:19:04 2010
New Revision: 911221
URL: http://svn.apache.org/viewvc?rev=911221&view=rev
Log:
add some experiment about getting condition values directly into groovy
it is not wired yet as it just makes things worst...
Added:
ant/sandbox/groovyfront/src/main/java/org/apache/tools/
ant/sandbox/groovyfront/src/main/java/org/apache/tools/ant/
ant/sandbox/groovyfront/src/main/java/org/apache/tools/ant/taskdefs/
ant/sandbox/groovyfront/src/main/java/org/apache/tools/ant/taskdefs/condition/
ant/sandbox/groovyfront/src/main/java/org/apache/tools/ant/taskdefs/condition/AccessorHack.java
(with props)
ant/sandbox/groovyfront/src/test/antunit/conditionTest.groovy (with props)
ant/sandbox/groovyfront/src/test/java/org/apache/ant/groovyfront/GroovyFrontConditionTestSuite.java
(with props)
Modified:
ant/sandbox/groovyfront/src/main/java/org/apache/ant/groovyfront/GroovyFrontBuilder.java
ant/sandbox/groovyfront/src/main/java/org/apache/ant/groovyfront/GroovyFrontMetaClass.java
ant/sandbox/groovyfront/src/test/java/org/apache/ant/groovyfront/GroovyFrontScriptTestSuite.java
Modified:
ant/sandbox/groovyfront/src/main/java/org/apache/ant/groovyfront/GroovyFrontBuilder.java
URL:
http://svn.apache.org/viewvc/ant/sandbox/groovyfront/src/main/java/org/apache/ant/groovyfront/GroovyFrontBuilder.java?rev=911221&r1=911220&r2=911221&view=diff
==============================================================================
---
ant/sandbox/groovyfront/src/main/java/org/apache/ant/groovyfront/GroovyFrontBuilder.java
(original)
+++
ant/sandbox/groovyfront/src/main/java/org/apache/ant/groovyfront/GroovyFrontBuilder.java
Wed Feb 17 23:19:04 2010
@@ -21,10 +21,17 @@
import groovy.util.AntBuilder;
import groovy.xml.QName;
+import java.util.Collections;
+
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.ProjectHelper;
import org.apache.tools.ant.RuntimeConfigurable;
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.TaskAdapter;
import org.apache.tools.ant.UnknownElement;
+import org.apache.tools.ant.taskdefs.ConditionTask;
+import org.apache.tools.ant.taskdefs.condition.AccessorHack;
+import org.apache.tools.ant.taskdefs.condition.Condition;
public class GroovyFrontBuilder extends AntBuilder {
@@ -66,4 +73,17 @@
return true;
}
+ public Condition createCondition(String methodName, Object[] arguments) {
+ Object conditionNode = createNode("condition",
Collections.singletonMap("property", "__groovyfront_condition__"));
+ Object current = getCurrent();
+ setCurrent(conditionNode);
+ invokeMethod(methodName, arguments);
+ setCurrent(current);
+ nodeCompleted(current, conditionNode);
+ UnknownElement element = (UnknownElement) postNodeCompletion(current,
conditionNode);
+ element.maybeConfigure();
+ TaskAdapter taskAdapter = (TaskAdapter) element.getRealThing();
+ ConditionTask conditionTask = (ConditionTask) taskAdapter.getProxy();
+ return (Condition)
AccessorHack.getConditions(conditionTask).nextElement();
+ }
}
Modified:
ant/sandbox/groovyfront/src/main/java/org/apache/ant/groovyfront/GroovyFrontMetaClass.java
URL:
http://svn.apache.org/viewvc/ant/sandbox/groovyfront/src/main/java/org/apache/ant/groovyfront/GroovyFrontMetaClass.java?rev=911221&r1=911220&r2=911221&view=diff
==============================================================================
---
ant/sandbox/groovyfront/src/main/java/org/apache/ant/groovyfront/GroovyFrontMetaClass.java
(original)
+++
ant/sandbox/groovyfront/src/main/java/org/apache/ant/groovyfront/GroovyFrontMetaClass.java
Wed Feb 17 23:19:04 2010
@@ -22,29 +22,51 @@
import groovy.lang.MissingMethodException;
import groovy.lang.Tuple;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.taskdefs.condition.Condition;
import org.codehaus.groovy.runtime.MetaClassHelper;
public class GroovyFrontMetaClass extends DelegatingMetaClass {
protected final GroovyFrontBuilder groovyFrontBuilder;
+ private static final Set CONDITION_TASK_NAMES = new
HashSet(Arrays.asList(new Object[] { "available", "uptodate",
+ "antversion" }));
+
public GroovyFrontMetaClass(final MetaClass metaClass, final
GroovyFrontBuilder groovyFrontBuilder) {
super(metaClass);
this.groovyFrontBuilder = groovyFrontBuilder;
}
public Object invokeMethod(final Object object, final String methodName,
final Object[] arguments) {
- Object returnObject = null;
try {
- returnObject = super.invokeMethod(object, methodName, arguments);
+ return super.invokeMethod(object, methodName, arguments);
} catch (final MissingMethodException mme) {
- if (groovyFrontBuilder.isTaskDefined(methodName)) {
- returnObject = groovyFrontBuilder.invokeMethod(methodName,
arguments);
- } else {
- throw mme;
+ if (groovyFrontBuilder.isTaskDefined(methodName) &&
isNotCondition(methodName, arguments)) {
+ return groovyFrontBuilder.invokeMethod(methodName, arguments);
}
+// try {
+// Condition condition =
groovyFrontBuilder.createCondition(methodName, arguments);
+// return Boolean.valueOf(condition.eval());
+// } catch (BuildException e) {
+ throw mme;
+// }
+ }
+ }
+
+ // TODO this should be done more dynamically
+ private boolean isNotCondition(String methodName, Object[] arguments) {
+ if (!CONDITION_TASK_NAMES.contains(methodName)) {
+ return true;
}
- return returnObject;
+ return arguments.length > 0 && arguments[0] instanceof Map && ((Map)
arguments[0]).containsKey("property");
}
public Object invokeMethod(final Object object, final String methodName,
final Object arguments) {
Added:
ant/sandbox/groovyfront/src/main/java/org/apache/tools/ant/taskdefs/condition/AccessorHack.java
URL:
http://svn.apache.org/viewvc/ant/sandbox/groovyfront/src/main/java/org/apache/tools/ant/taskdefs/condition/AccessorHack.java?rev=911221&view=auto
==============================================================================
---
ant/sandbox/groovyfront/src/main/java/org/apache/tools/ant/taskdefs/condition/AccessorHack.java
(added)
+++
ant/sandbox/groovyfront/src/main/java/org/apache/tools/ant/taskdefs/condition/AccessorHack.java
Wed Feb 17 23:19:04 2010
@@ -0,0 +1,12 @@
+package org.apache.tools.ant.taskdefs.condition;
+
+import java.util.Enumeration;
+
+import org.apache.tools.ant.taskdefs.ConditionTask;
+
+public class AccessorHack {
+
+ public static Enumeration getConditions(ConditionTask task) {
+ return task.getConditions();
+ }
+}
Propchange:
ant/sandbox/groovyfront/src/main/java/org/apache/tools/ant/taskdefs/condition/AccessorHack.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
ant/sandbox/groovyfront/src/main/java/org/apache/tools/ant/taskdefs/condition/AccessorHack.java
------------------------------------------------------------------------------
svn:keywords = Date Revision Author HeadURL Id
Propchange:
ant/sandbox/groovyfront/src/main/java/org/apache/tools/ant/taskdefs/condition/AccessorHack.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: ant/sandbox/groovyfront/src/test/antunit/conditionTest.groovy
URL:
http://svn.apache.org/viewvc/ant/sandbox/groovyfront/src/test/antunit/conditionTest.groovy?rev=911221&view=auto
==============================================================================
--- ant/sandbox/groovyfront/src/test/antunit/conditionTest.groovy (added)
+++ ant/sandbox/groovyfront/src/test/antunit/conditionTest.groovy Wed Feb 17
23:19:04 2010
@@ -0,0 +1,36 @@
+/*
+ * 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.
+ *
+ */
+import groovy.xml.NamespaceBuilder
+
+taskdef(uri: 'org.apache.ant.antunit', resource:
'org/apache/ant/antunit/antlib.xml')
+def au = groovyns(prefix: 'au', uri: 'org.apache.ant.antunit')
+
+target(name: 'testIsSet') {
+ def myPropIsSet = isset(property: 'myprop')
+ au.assertEquals(actual: false, expected: myPropIsSet)
+ myprop = 'myvalue'
+ myPropIsSet = isset(property: 'myprop')
+ au.assertEquals(actual: true, expected: myPropIsSet)
+}
+
+target(name: 'testAvailable') {
+ available(property: 'antavailable', classname:
'org.apache.tools.ant.Project')
+ au.assertEquals(actual: true, expected: '${antavailable}')
+ def a = available(classname: 'org.apache.tools.ant.Project')
+ au.assertEquals(actual: true, expected: a)
+}
Propchange: ant/sandbox/groovyfront/src/test/antunit/conditionTest.groovy
------------------------------------------------------------------------------
svn:executable = *
Added:
ant/sandbox/groovyfront/src/test/java/org/apache/ant/groovyfront/GroovyFrontConditionTestSuite.java
URL:
http://svn.apache.org/viewvc/ant/sandbox/groovyfront/src/test/java/org/apache/ant/groovyfront/GroovyFrontConditionTestSuite.java?rev=911221&view=auto
==============================================================================
---
ant/sandbox/groovyfront/src/test/java/org/apache/ant/groovyfront/GroovyFrontConditionTestSuite.java
(added)
+++
ant/sandbox/groovyfront/src/test/java/org/apache/ant/groovyfront/GroovyFrontConditionTestSuite.java
Wed Feb 17 23:19:04 2010
@@ -0,0 +1,34 @@
+/*
+ * 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.groovyfront;
+
+import java.io.File;
+
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.ant.antunit.junit3.AntUnitSuite;
+
+public class GroovyFrontConditionTestSuite extends TestCase {
+
+ public static TestSuite suite() {
+ File script = new File(new File(new File(new File("src"), "test") ,
"antunit"), "conditionTest.groovy");
+ return new AntUnitSuite(script, GroovyFrontConditionTestSuite.class);
+ }
+
+}
Propchange:
ant/sandbox/groovyfront/src/test/java/org/apache/ant/groovyfront/GroovyFrontConditionTestSuite.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
ant/sandbox/groovyfront/src/test/java/org/apache/ant/groovyfront/GroovyFrontConditionTestSuite.java
------------------------------------------------------------------------------
svn:keywords = Date Revision Author HeadURL Id
Propchange:
ant/sandbox/groovyfront/src/test/java/org/apache/ant/groovyfront/GroovyFrontConditionTestSuite.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified:
ant/sandbox/groovyfront/src/test/java/org/apache/ant/groovyfront/GroovyFrontScriptTestSuite.java
URL:
http://svn.apache.org/viewvc/ant/sandbox/groovyfront/src/test/java/org/apache/ant/groovyfront/GroovyFrontScriptTestSuite.java?rev=911221&r1=911220&r2=911221&view=diff
==============================================================================
---
ant/sandbox/groovyfront/src/test/java/org/apache/ant/groovyfront/GroovyFrontScriptTestSuite.java
(original)
+++
ant/sandbox/groovyfront/src/test/java/org/apache/ant/groovyfront/GroovyFrontScriptTestSuite.java
Wed Feb 17 23:19:04 2010
@@ -27,7 +27,7 @@
public class GroovyFrontScriptTestSuite extends TestCase {
public static TestSuite suite() {
- File script = new File("src/test/antunit/varMappingTest.groovy");
+ File script = new File(new File(new File(new File("src"), "test"),
"antunit"), "varMappingTest.groovy");
return new AntUnitSuite(script, GroovyFrontScriptTestSuite.class);
}