Author: mbenson
Date: Fri Jun 29 11:16:45 2007
New Revision: 551987
URL: http://svn.apache.org/viewvc?view=rev&rev=551987
Log:
tweakage
Added:
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/PrefixedEvaluator.java
(with props)
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/RegexBasedEvaluator.java
(with props)
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/StaticPrefixedEvaluator.java
(with props)
Removed:
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/stringops/StringOperation.java
Modified:
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/ComponentTypeEvaluator.java
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/ReferenceResolvingEvaluator.java
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/stringops/DefaultValue.java
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/stringops/DeletePartOperation.java
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/stringops/PatternOperation.java
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/stringops/ReplaceOperation.java
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/stringops/RequireProperty.java
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/stringops/SetDefaultValue.java
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/stringops/StringOperationsEvaluator.java
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/stringops/Substring.java
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/stringops/Translate.java
ant/sandbox/antlibs/props/trunk/src/tests/antunit/types-test.xml
Modified:
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/ComponentTypeEvaluator.java
URL:
http://svn.apache.org/viewvc/ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/ComponentTypeEvaluator.java?view=diff&rev=551987&r1=551986&r2=551987
==============================================================================
---
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/ComponentTypeEvaluator.java
(original)
+++
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/ComponentTypeEvaluator.java
Fri Jun 29 11:16:45 2007
@@ -24,63 +24,48 @@
import org.apache.tools.ant.PropertyHelper;
/**
- * Property evaluator that will map any colon-delimited currently defined Ant
type
- * using its String constructor, if it has any.
+ * Property evaluator that will map any colon-delimited currently defined Ant
type using its String
+ * constructor, if it has any.
*/
-public class ComponentTypeEvaluator implements
PropertyHelper.PropertyEvaluator {
- private static final String DEFAULT_DELIMITER = ":";
-
- private static final Class[] PROJECT_STRING = new Class[] { Project.class,
- String.class };
+public class ComponentTypeEvaluator extends RegexBasedEvaluator {
+ private static final Class[] PROJECT_STRING = new Class[] { Project.class,
String.class };
private static final Class[] STRING_ONLY = new Class[] { String.class };
- private String delimiter;
+ /**
+ * Create a new ComponentTypeEvaluator.
+ */
+ public ComponentTypeEvaluator() {
+ setPattern("^(.*?)\\((.*)\\)$");
+ }
/**
* [EMAIL PROTECTED]
- * @see
org.apache.tools.ant.PropertyHelper.PropertyEvaluator#evaluate(java.lang.String,
org.apache.tools.ant.PropertyHelper)
+ *
+ * @see
org.apache.ant.props.RegexBasedEvaluator#evaluate(java.lang.String[],
+ * org.apache.tools.ant.PropertyHelper)
*/
- public Object evaluate(String property, PropertyHelper propertyHelper) {
- int d = property.indexOf(getDelimiter());
+ protected Object evaluate(String[] groups, PropertyHelper propertyHelper) {
Object result = null;
- if (d >= 0) {
- Project p = propertyHelper.getProject();
- Class componentType = ComponentHelper.getComponentHelper(p)
- .getDefinition(property.substring(0, d)).getTypeClass(p);
- if (componentType != null) {
- String stringArg = property.substring(d + 1);
- try {
- result = componentType.getConstructor(PROJECT_STRING)
- .newInstance(new Object[] { p, stringArg });
- } catch (Exception e) {
- }
- try {
- result = componentType.getConstructor(STRING_ONLY)
- .newInstance(new Object[] { stringArg });
- } catch (Exception e) {
- }
- if (result != null) {
- p.setProjectReference(result);
- }
+ Project p = propertyHelper.getProject();
+ Class componentType =
ComponentHelper.getComponentHelper(p).getDefinition(groups[1])
+ .getTypeClass(p);
+ if (componentType != null) {
+ try {
+ result =
componentType.getConstructor(PROJECT_STRING).newInstance(
+ new Object[] { p, groups[2] });
+ } catch (Exception e) {
+ }
+ try {
+ result = componentType.getConstructor(STRING_ONLY).newInstance(
+ new Object[] { groups[2] });
+ } catch (Exception e) {
+ }
+ if (result != null) {
+ p.setProjectReference(result);
}
}
return result;
}
- /**
- * Get the String delimiter.
- * @return String
- */
- public String getDelimiter() {
- return delimiter == null ? DEFAULT_DELIMITER : delimiter;
- }
-
- /**
- * Set the String delimiter.
- * @param delimiter String
- */
- public void setDelimiter(String delimiter) {
- this.delimiter = delimiter;
- }
}
Added:
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/PrefixedEvaluator.java
URL:
http://svn.apache.org/viewvc/ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/PrefixedEvaluator.java?view=auto&rev=551987
==============================================================================
---
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/PrefixedEvaluator.java
(added)
+++
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/PrefixedEvaluator.java
Fri Jun 29 11:16:45 2007
@@ -0,0 +1,97 @@
+/*
+ * 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.props;
+
+import org.apache.tools.ant.PropertyHelper;
+
+/**
+ * Abstract prefixed PropertyEvaluator.
+ */
+public abstract class PrefixedEvaluator extends RegexBasedEvaluator {
+
+ /**
+ * Default prefix delimiter.
+ */
+ public static final String DEFAULT_DELIMITER = ":";
+
+ /**
+ * Create a new PrefixedEvaluator.
+ */
+ protected PrefixedEvaluator() {
+ this(DEFAULT_DELIMITER);
+ }
+
+ /**
+ * Create a new PrefixedEvaluator.
+ *
+ * @param delimiter
+ */
+ protected PrefixedEvaluator(String delimiter) {
+ setDelimiter(delimiter);
+ }
+
+ /**
+ * Learn whether this evaluator can interpret a property with the given
prefix.
+ *
+ * @param prefix
+ * @return <code>true</code> if <code>prefix</code> is recognized, else
<code>false</code>.
+ */
+ protected abstract boolean canInterpret(String prefix);
+
+ /**
+ * [EMAIL PROTECTED]
+ *
+ * @see
org.apache.ant.props.RegexBasedEvaluator#evaluate(java.lang.String[],
+ * org.apache.tools.ant.PropertyHelper)
+ */
+ protected Object evaluate(String[] groups, PropertyHelper propertyHelper) {
+ return canInterpret(groups[1]) ? evaluate(groups[2], groups[1],
propertyHelper) : null;
+ }
+
+ /**
+ * Return the result of evaluating the prefixed property.
+ *
+ * @param property
+ * @param prefix
+ * @param propertyHelper
+ * @return Object if the property can be resolved, else <code>null</code>.
+ */
+ protected abstract Object evaluate(String property, String prefix,
PropertyHelper propertyHelper);
+
+ /**
+ * Set the String delimiter.
+ *
+ * @param delimiter String
+ */
+ public void setDelimiter(String delimiter) {
+ if (delimiter == null) {
+ throw new IllegalArgumentException("invalid delimiter: null");
+ }
+ super.setPattern("^(.*?):(.*)$");
+ }
+
+ /**
+ * Ignored.
+ *
+ * @see
org.apache.ant.props.RegexBasedEvaluator#setPattern(java.lang.String)
+ */
+ public final void setPattern(String pattern) {
+ }
+}
Propchange:
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/PrefixedEvaluator.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/ReferenceResolvingEvaluator.java
URL:
http://svn.apache.org/viewvc/ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/ReferenceResolvingEvaluator.java?view=diff&rev=551987&r1=551986&r2=551987
==============================================================================
---
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/ReferenceResolvingEvaluator.java
(original)
+++
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/ReferenceResolvingEvaluator.java
Fri Jun 29 11:16:45 2007
@@ -22,21 +22,26 @@
import org.apache.tools.ant.PropertyHelper;
/**
- * Name says it all, doesn't it?
+ * PropertyEvaluator that resolves a reference against the current project.
*/
-public class ReferenceResolvingEvaluator implements
PropertyHelper.PropertyEvaluator {
+public class ReferenceResolvingEvaluator extends StaticPrefixedEvaluator {
+ /** Default prefix */
+ public static final String DEFAULT_PREFIX = "ref";
+
+ /**
+ * Create a new ReferenceResolvingEvaluator.
+ */
+ public ReferenceResolvingEvaluator() {
+ super(DEFAULT_PREFIX);
+ }
/**
* [EMAIL PROTECTED]
- * @see
org.apache.tools.ant.PropertyHelper.PropertyEvaluator#evaluate(java.lang.String,
org.apache.tools.ant.PropertyHelper)
+ *
+ * @see
org.apache.ant.props.PrefixedEvaluator#evaluatePrefixed(java.lang.String,
+ * java.lang.String, org.apache.tools.ant.PropertyHelper)
*/
- public Object evaluate(String property, PropertyHelper propertyHelper) {
- if (property.startsWith("ref:")) {
- Object o =
propertyHelper.getProject().getReference(property.substring(4));
- if (o != null) {
- return o;
- }
- }
- return null;
+ protected Object evaluate(String property, String prefix, PropertyHelper
propertyHelper) {
+ return propertyHelper.getProject().getReference(property);
}
}
Added:
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/RegexBasedEvaluator.java
URL:
http://svn.apache.org/viewvc/ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/RegexBasedEvaluator.java?view=auto&rev=551987
==============================================================================
---
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/RegexBasedEvaluator.java
(added)
+++
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/RegexBasedEvaluator.java
Fri Jun 29 11:16:45 2007
@@ -0,0 +1,110 @@
+/*
+ * 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.props;
+
+import java.util.List;
+
+import org.apache.tools.ant.MagicNames;
+import org.apache.tools.ant.PropertyHelper;
+import org.apache.tools.ant.types.RegularExpression;
+import org.apache.tools.ant.util.regexp.Regexp;
+
+/**
+ * <code>PropertyHelper.PropertyEvaluator</code> based on a regex pattern that
will produce match
+ * groups to be dealt with by [EMAIL PROTECTED] #evaluate(String[],
PropertyHelper)}.
+ */
+public abstract class RegexBasedEvaluator implements
PropertyHelper.PropertyEvaluator {
+ private String pattern;
+
+ private RegularExpression regularExpression;
+
+ /**
+ * Create a new RegexBasedEvaluator.
+ */
+ protected RegexBasedEvaluator() {
+ }
+
+ /**
+ * Construct a new RegexBasedEvaluator.
+ *
+ * @param pattern the base pattern.
+ */
+ protected RegexBasedEvaluator(String pattern) {
+ setPattern(pattern);
+ }
+
+ /** [EMAIL PROTECTED] */
+ public Object evaluate(String propertyName, PropertyHelper propertyHelper)
{
+ //never try to resolve the regex factory magic property:
+ if (MagicNames.REGEXP_IMPL.equals(propertyName)) {
+ return null;
+ }
+ Regexp regexp =
getRegularExpression().getRegexp(propertyHelper.getProject());
+ if (regexp.matches(propertyName)) {
+ List groups = regexp.getGroups(propertyName, Regexp.MATCH_DEFAULT);
+ String[] s = (String[]) groups.toArray(new String[groups.size()]);
+ return evaluate(s, propertyHelper);
+ }
+ return null;
+ }
+
+ /**
+ * Get the regular expression object to use.
+ *
+ * @return
+ */
+ protected synchronized RegularExpression getRegularExpression() {
+ if (regularExpression == null) {
+ if (getPattern() == null) {
+ throw new IllegalStateException("pattern not set");
+ }
+ regularExpression = new RegularExpression();
+ regularExpression.setPattern(getPattern());
+ }
+ return regularExpression;
+ }
+
+ /**
+ * Evaluate the matched groups.
+ *
+ * @param groups the matches from the base regex.
+ * @param propertyHelper the calling PropertyHelper.
+ */
+ protected abstract Object evaluate(String[] groups, PropertyHelper
propertyHelper);
+
+ /**
+ * Get the String pattern.
+ *
+ * @return String
+ */
+ public String getPattern() {
+ return pattern;
+ }
+
+ /**
+ * Set the String pattern.
+ *
+ * @param pattern String
+ */
+ public void setPattern(String pattern) {
+ this.pattern = pattern;
+ regularExpression = null;
+ }
+}
Propchange:
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/RegexBasedEvaluator.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/StaticPrefixedEvaluator.java
URL:
http://svn.apache.org/viewvc/ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/StaticPrefixedEvaluator.java?view=auto&rev=551987
==============================================================================
---
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/StaticPrefixedEvaluator.java
(added)
+++
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/StaticPrefixedEvaluator.java
Fri Jun 29 11:16:45 2007
@@ -0,0 +1,69 @@
+package org.apache.ant.props;
+
+/**
+ * PrefixedPropertyEvaluator that always uses the same prefix.
+ */
+public abstract class StaticPrefixedEvaluator extends PrefixedEvaluator {
+ private String prefix;
+
+ /**
+ * Create a new StaticPrefixedEvaluator.
+ */
+ protected StaticPrefixedEvaluator() {
+ }
+
+ /**
+ * Create a new StaticPrefixedEvaluator.
+ * @param prefix
+ */
+ protected StaticPrefixedEvaluator(String prefix) {
+ setPrefix(prefix);
+ }
+
+ /**
+ * Create a new StaticPrefixedEvaluator.
+ * @param prefix
+ * @param delimiter
+ */
+ protected StaticPrefixedEvaluator(String prefix, String delimiter) {
+ super(delimiter);
+ setPrefix(prefix);
+ }
+
+ /**
+ * [EMAIL PROTECTED]
+ * @see
org.apache.ant.props.PrefixedEvaluator#canInterpret(java.lang.String)
+ */
+ protected final boolean canInterpret(String prefix) {
+ return getRequiredPrefix().equals(prefix);
+ }
+
+ /**
+ * Get the non-null prefix.
+ * @return String
+ */
+ protected String getRequiredPrefix() {
+ String result = getPrefix();
+ if (result == null) {
+ throw new IllegalStateException("prefix unset");
+ }
+ return result;
+ }
+
+ /**
+ * Get the String prefix.
+ * @return String
+ */
+ public String getPrefix() {
+ return prefix;
+ }
+
+ /**
+ * Set the String prefix.
+ * @param prefix String
+ */
+ public void setPrefix(String prefix) {
+ this.prefix = prefix;
+ }
+
+}
Propchange:
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/StaticPrefixedEvaluator.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/stringops/DefaultValue.java
URL:
http://svn.apache.org/viewvc/ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/stringops/DefaultValue.java?view=diff&rev=551987&r1=551986&r2=551987
==============================================================================
---
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/stringops/DefaultValue.java
(original)
+++
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/stringops/DefaultValue.java
Fri Jun 29 11:16:45 2007
@@ -19,22 +19,23 @@
*/
package org.apache.ant.props.stringops;
+import org.apache.ant.props.RegexBasedEvaluator;
import org.apache.tools.ant.PropertyHelper;
/**
* DefaultValue operation.
*/
-public class DefaultValue extends StringOperation {
+public class DefaultValue extends RegexBasedEvaluator {
/**
* Construct a new DefaultValue operation.
*/
public DefaultValue() {
- super("^(.*):-(.*)$");
+ super("(.*):-(.*)");
}
/** [EMAIL PROTECTED] */
- protected String evaluate(String[] groups, PropertyHelper propertyHelper) {
+ protected Object evaluate(String[] groups, PropertyHelper propertyHelper) {
Object o = (String) propertyHelper.getProperty(groups[1]);
return o == null ? groups[2] : o.toString();
}
Modified:
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/stringops/DeletePartOperation.java
URL:
http://svn.apache.org/viewvc/ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/stringops/DeletePartOperation.java?view=diff&rev=551987&r1=551986&r2=551987
==============================================================================
---
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/stringops/DeletePartOperation.java
(original)
+++
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/stringops/DeletePartOperation.java
Fri Jun 29 11:16:45 2007
@@ -40,7 +40,7 @@
}
/** [EMAIL PROTECTED] */
- protected String evaluate(String[] groups, PropertyHelper propertyHelper) {
+ protected Object evaluate(String[] groups, PropertyHelper propertyHelper) {
Object value = propertyHelper.getProperty(groups[1]);
if (value != null) {
String s = value.toString();
Modified:
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/stringops/PatternOperation.java
URL:
http://svn.apache.org/viewvc/ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/stringops/PatternOperation.java?view=diff&rev=551987&r1=551986&r2=551987
==============================================================================
---
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/stringops/PatternOperation.java
(original)
+++
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/stringops/PatternOperation.java
Fri Jun 29 11:16:45 2007
@@ -21,6 +21,7 @@
import java.text.ParsePosition;
+import org.apache.ant.props.RegexBasedEvaluator;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.RegularExpression;
import org.apache.tools.ant.util.regexp.Regexp;
@@ -28,7 +29,7 @@
/**
* Abstract pattern-based operation.
*/
-public abstract class PatternOperation extends StringOperation {
+public abstract class PatternOperation extends RegexBasedEvaluator {
private interface PatternParser {
boolean process(StringBuffer sb, ParsePosition pos);
}
Modified:
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/stringops/ReplaceOperation.java
URL:
http://svn.apache.org/viewvc/ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/stringops/ReplaceOperation.java?view=diff&rev=551987&r1=551986&r2=551987
==============================================================================
---
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/stringops/ReplaceOperation.java
(original)
+++
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/stringops/ReplaceOperation.java
Fri Jun 29 11:16:45 2007
@@ -23,7 +23,7 @@
import org.apache.tools.ant.util.regexp.Regexp;
/**
- * Abstract Replace operation.
+ * Replace operation--handles 'replace all' and 'replace first' alike.
*/
public class ReplaceOperation extends PatternOperation {
private static final String ESCAPE_SLASH = "\\\\/";
@@ -39,7 +39,7 @@
}
/** [EMAIL PROTECTED] */
- protected final String evaluate(String[] groups, PropertyHelper
propertyHelper) {
+ protected final Object evaluate(String[] groups, PropertyHelper
propertyHelper) {
Object value = propertyHelper.getProperty(groups[1]);
int replaceOption = "//".equals(groups[2]) ? Regexp.REPLACE_ALL :
Regexp.REPLACE_FIRST;
StringBuffer sb = new StringBuffer(groups[3]);
Modified:
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/stringops/RequireProperty.java
URL:
http://svn.apache.org/viewvc/ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/stringops/RequireProperty.java?view=diff&rev=551987&r1=551986&r2=551987
==============================================================================
---
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/stringops/RequireProperty.java
(original)
+++
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/stringops/RequireProperty.java
Fri Jun 29 11:16:45 2007
@@ -19,24 +19,25 @@
*/
package org.apache.ant.props.stringops;
+import org.apache.ant.props.RegexBasedEvaluator;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.PropertyHelper;
/**
* Require property operation.
*/
-public class RequireProperty extends StringOperation {
+public class RequireProperty extends RegexBasedEvaluator {
private static final String DEFAULT_MESSAGE = "Missing required property ";
/**
* Construct a new RequireProperty operation.
*/
public RequireProperty() {
- super("^(.*):\\?(.*)?$");
+ super("^(.*):\\?(.*)$");
}
/** [EMAIL PROTECTED] */
- protected String evaluate(String[] groups, PropertyHelper propertyHelper) {
+ protected Object evaluate(String[] groups, PropertyHelper propertyHelper) {
String result = (String) propertyHelper.getProperty(groups[1]);
if (result == null) {
String message = "".equals(groups[2]) ? DEFAULT_MESSAGE +
groups[1] : groups[2];
Modified:
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/stringops/SetDefaultValue.java
URL:
http://svn.apache.org/viewvc/ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/stringops/SetDefaultValue.java?view=diff&rev=551987&r1=551986&r2=551987
==============================================================================
---
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/stringops/SetDefaultValue.java
(original)
+++
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/stringops/SetDefaultValue.java
Fri Jun 29 11:16:45 2007
@@ -19,13 +19,13 @@
*/
package org.apache.ant.props.stringops;
-import org.apache.tools.ant.Project;
+import org.apache.ant.props.RegexBasedEvaluator;
import org.apache.tools.ant.PropertyHelper;
/**
* SetDefaultValue operation.
*/
-public class SetDefaultValue extends StringOperation {
+public class SetDefaultValue extends RegexBasedEvaluator {
/**
* Construct a new SetDefaultValue operation.
@@ -35,16 +35,12 @@
}
/** [EMAIL PROTECTED] */
- protected String evaluate(String[] groups, PropertyHelper propertyHelper) {
- Object o = propertyHelper.getProperty(groups[1]);
- propertyHelper.getProject().log(this + ": " + groups[1] + "=" + o,
Project.MSG_DEBUG);
- String value;
- if (o == null) {
- value = groups[2];
- propertyHelper.setNewProperty(groups[1], value);
- } else {
- value = o.toString();
+ protected Object evaluate(String[] groups, PropertyHelper propertyHelper) {
+ Object result = propertyHelper.getProperty(groups[1]);
+ if (result == null) {
+ result = groups[2];
+ propertyHelper.setNewProperty(groups[1], result);
}
- return value;
+ return result;
}
}
Modified:
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/stringops/StringOperationsEvaluator.java
URL:
http://svn.apache.org/viewvc/ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/stringops/StringOperationsEvaluator.java?view=diff&rev=551987&r1=551986&r2=551987
==============================================================================
---
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/stringops/StringOperationsEvaluator.java
(original)
+++
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/stringops/StringOperationsEvaluator.java
Fri Jun 29 11:16:45 2007
@@ -24,6 +24,7 @@
import java.util.Stack;
import org.apache.tools.ant.PropertyHelper;
+import org.apache.tools.ant.PropertyHelper.PropertyEvaluator;
/**
* PropertyEvaluator to apply *nix-style string operations to Ant properties.
@@ -41,7 +42,6 @@
* Construct a new StringOperationsEvaluator.
*/
public StringOperationsEvaluator() {
- //TODO: add delegates
delegates.add(new Substring());
delegates.add(new DefaultValue());
delegates.add(new SetDefaultValue());
@@ -65,8 +65,8 @@
stk.push(propertyName);
try {
for (Iterator iter = delegates.iterator(); iter.hasNext();) {
- Object value = ((StringOperation) iter.next()).evaluate(
- propertyName, propertyHelper);
+ Object value = ((PropertyEvaluator)
iter.next()).evaluate(propertyName,
+ propertyHelper);
if (value != null) {
return value;
}
Modified:
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/stringops/Substring.java
URL:
http://svn.apache.org/viewvc/ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/stringops/Substring.java?view=diff&rev=551987&r1=551986&r2=551987
==============================================================================
---
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/stringops/Substring.java
(original)
+++
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/stringops/Substring.java
Fri Jun 29 11:16:45 2007
@@ -19,12 +19,13 @@
*/
package org.apache.ant.props.stringops;
+import org.apache.ant.props.RegexBasedEvaluator;
import org.apache.tools.ant.PropertyHelper;
/**
* Substring operation.
*/
-public class Substring extends StringOperation {
+public class Substring extends RegexBasedEvaluator {
/**
* Construct a new substring operation.
@@ -34,7 +35,7 @@
}
/** [EMAIL PROTECTED] */
- protected String evaluate(String[] groups, PropertyHelper propertyHelper) {
+ protected Object evaluate(String[] groups, PropertyHelper propertyHelper) {
String value = (String) propertyHelper.getProperty(groups[1]);
if (value != null) {
int start = Integer.parseInt(groups[2]);
Modified:
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/stringops/Translate.java
URL:
http://svn.apache.org/viewvc/ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/stringops/Translate.java?view=diff&rev=551987&r1=551986&r2=551987
==============================================================================
---
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/stringops/Translate.java
(original)
+++
ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/stringops/Translate.java
Fri Jun 29 11:16:45 2007
@@ -19,12 +19,13 @@
*/
package org.apache.ant.props.stringops;
+import org.apache.ant.props.RegexBasedEvaluator;
import org.apache.tools.ant.PropertyHelper;
/**
* Translate operation.
*/
-public class Translate extends StringOperation {
+public class Translate extends RegexBasedEvaluator {
/**
* Construct a new Translate operation.
@@ -34,7 +35,7 @@
}
/** [EMAIL PROTECTED] */
- protected String evaluate(String[] groups, PropertyHelper propertyHelper) {
+ protected Object evaluate(String[] groups, PropertyHelper propertyHelper) {
return propertyHelper.getProperty(groups[1]) == null ? null :
groups[2];
}
}
Modified: ant/sandbox/antlibs/props/trunk/src/tests/antunit/types-test.xml
URL:
http://svn.apache.org/viewvc/ant/sandbox/antlibs/props/trunk/src/tests/antunit/types-test.xml?view=diff&rev=551987&r1=551986&r2=551987
==============================================================================
--- ant/sandbox/antlibs/props/trunk/src/tests/antunit/types-test.xml (original)
+++ ant/sandbox/antlibs/props/trunk/src/tests/antunit/types-test.xml Fri Jun 29
11:16:45 2007
@@ -11,7 +11,7 @@
<whichresource property="control" class="org.apache.tools.ant.Project"
classpath="${java.class.path}" />
<whichresource property="test" class="org.apache.tools.ant.Project"
- classpath="${path:${java.class.path}}" />
+ classpath="${path(${java.class.path})}" />
<au:assertTrue>
<equals arg1="${control}" arg2="${test}" />
</au:assertTrue>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]