summaryrefslogtreecommitdiffstats
path: root/ant1.5/src/java/net/sf/antcontrib/math/MathTask.java
diff options
context:
space:
mode:
authormattinger <[email protected]>2007-03-07 21:39:57 +0000
committermattinger <[email protected]>2007-03-07 21:39:57 +0000
commit69da5b36470f85cc514a5661298cf6d5bfc01116 (patch)
tree313bb58f47fdfde3d40b1706266ec0a742fb798c /ant1.5/src/java/net/sf/antcontrib/math/MathTask.java
parent1bce0a66a11f4cbf8d6bcc46fbd9a36cb7ebe64a (diff)
Code and build re-organized to produce ant-version specific jar files and library sets
git-svn-id: file:///home/sven/projects/JOGL/temp/ant-contrib/svn/ant-contrib-code/branches/ant-1.7.0-upgrade@100 32d7a393-a5a9-423c-abd3-5d954feb1f2f
Diffstat (limited to 'ant1.5/src/java/net/sf/antcontrib/math/MathTask.java')
-rw-r--r--ant1.5/src/java/net/sf/antcontrib/math/MathTask.java134
1 files changed, 134 insertions, 0 deletions
diff --git a/ant1.5/src/java/net/sf/antcontrib/math/MathTask.java b/ant1.5/src/java/net/sf/antcontrib/math/MathTask.java
new file mode 100644
index 0000000..233902e
--- /dev/null
+++ b/ant1.5/src/java/net/sf/antcontrib/math/MathTask.java
@@ -0,0 +1,134 @@
+/*
+ * Copyright (c) 2001-2004 Ant-Contrib project. All rights reserved.
+ *
+ * Licensed 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 net.sf.antcontrib.math;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.DynamicConfigurator;
+
+/**
+ * Task for mathematical operations.
+ *
+ * @author inger
+ * @ant.task name="math"
+ */
+
+
+public class MathTask
+ extends Task
+ implements DynamicConfigurator
+{
+ // storage for result
+ private String result = null;
+ private Operation operation = null;
+ private Operation locOperation = null;
+ private String datatype = null;
+ private boolean strict = false;
+
+ public MathTask()
+ {
+ super();
+ }
+
+ public void execute()
+ throws BuildException
+ {
+ Operation op = locOperation;
+ if (op == null)
+ op = operation;
+
+ Number res = op.evaluate();
+
+ if (datatype != null)
+ res = Math.convert(res, datatype);
+ getProject().setUserProperty(result, res.toString());
+ }
+
+ public void setDynamicAttribute(String s, String s1)
+ throws BuildException {
+ throw new BuildException("No dynamic attributes for this task");
+ }
+
+ public Object createDynamicElement(String name)
+ throws BuildException {
+ Operation op = new Operation();
+ op.setOperation(name);
+ operation = op;
+ return op;
+ }
+
+ public void setResult(String result)
+ {
+ this.result = result;
+ }
+
+ public void setDatatype(String datatype)
+ {
+ this.datatype = datatype;
+ }
+
+ public void setStrict(boolean strict)
+ {
+ this.strict = strict;
+ }
+
+ private Operation getLocalOperation()
+ {
+ if (locOperation == null)
+ {
+ locOperation = new Operation();
+ locOperation.setDatatype(datatype);
+ locOperation.setStrict(strict);
+ }
+ return locOperation;
+ }
+
+ public void setOperation(String operation)
+ {
+ getLocalOperation().setOperation(operation);
+ }
+
+ public void setDataType(String dataType)
+ {
+ getLocalOperation().setDatatype(dataType);
+ }
+
+ public void setOperand1(String operand1)
+ {
+ getLocalOperation().setArg1(operand1);
+ }
+
+ public void setOperand2(String operand2)
+ {
+ getLocalOperation().setArg2(operand2);
+ }
+
+ public Operation createOperation()
+ {
+ if (locOperation != null || operation != null)
+ throw new BuildException("Only 1 operation can be specified");
+ this.operation = new Operation();
+ this.operation.setStrict(strict);
+ this.operation.setDatatype(datatype);
+ return this.operation;
+ }
+
+ // conform to old task
+ public Operation createOp()
+ {
+ return createOperation();
+ }
+}