You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by mb...@apache.org on 2007/06/25 21:55:19 UTC
svn commit: r550589 - in /ant/sandbox/antlibs/props: ./ docs/ src/ src/main/
src/main/org/ src/main/org/apache/ src/main/org/apache/ant/
src/main/org/apache/ant/props/ src/main/org/apache/ant/props/stringops/
src/tests/ src/tests/antunit/
Author: mbenson
Date: Mon Jun 25 12:55:16 2007
New Revision: 550589
URL: http://svn.apache.org/viewvc?view=rev&rev=550589
Log:
initial checkin of experimental props antlib
Added:
ant/sandbox/antlibs/props/
ant/sandbox/antlibs/props/NOTICE (with props)
ant/sandbox/antlibs/props/build.xml (with props)
ant/sandbox/antlibs/props/docs/
ant/sandbox/antlibs/props/docs/index.html (with props)
ant/sandbox/antlibs/props/docs/stringops.html (with props)
ant/sandbox/antlibs/props/docs/style.css (with props)
ant/sandbox/antlibs/props/src/
ant/sandbox/antlibs/props/src/main/
ant/sandbox/antlibs/props/src/main/org/
ant/sandbox/antlibs/props/src/main/org/apache/
ant/sandbox/antlibs/props/src/main/org/apache/ant/
ant/sandbox/antlibs/props/src/main/org/apache/ant/props/
ant/sandbox/antlibs/props/src/main/org/apache/ant/props/ComponentTypeEvaluator.java (with props)
ant/sandbox/antlibs/props/src/main/org/apache/ant/props/NestedPropertyExpander.java (with props)
ant/sandbox/antlibs/props/src/main/org/apache/ant/props/ReferenceResolvingEvaluator.java (with props)
ant/sandbox/antlibs/props/src/main/org/apache/ant/props/antlib.xml (with props)
ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/
ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/DefaultValue.java (with props)
ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/DeleteFromEndGreedy.java (with props)
ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/DeleteFromEndReluctant.java (with props)
ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/DeleteFromStartGreedy.java (with props)
ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/DeleteFromStartReluctant.java (with props)
ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/DeletePartOperation.java (with props)
ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/PatternOperation.java (with props)
ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/ReplaceOperation.java (with props)
ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/RequireProperty.java (with props)
ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/SetDefaultValue.java (with props)
ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/StringOperation.java (with props)
ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/StringOperationsEvaluator.java (with props)
ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/Substring.java (with props)
ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/Translate.java (with props)
ant/sandbox/antlibs/props/src/tests/
ant/sandbox/antlibs/props/src/tests/antunit/
ant/sandbox/antlibs/props/src/tests/antunit/nested-test.xml (with props)
ant/sandbox/antlibs/props/src/tests/antunit/refs-test.xml (with props)
ant/sandbox/antlibs/props/src/tests/antunit/stringops-test.xml (with props)
ant/sandbox/antlibs/props/src/tests/antunit/types-test.xml (with props)
Added: ant/sandbox/antlibs/props/NOTICE
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/props/NOTICE?view=auto&rev=550589
==============================================================================
--- ant/sandbox/antlibs/props/NOTICE (added)
+++ ant/sandbox/antlibs/props/NOTICE Mon Jun 25 12:55:16 2007
@@ -0,0 +1,11 @@
+ =========================================================================
+ == NOTICE file corresponding to the section 4 d of ==
+ == the Apache License, Version 2.0 ==
+ =========================================================================
+
+ Apache Ant Property Extensions
+ Copyright 2007 The Apache Software Foundation
+
+ This product includes software developed by
+ The Apache Software Foundation (http://www.apache.org/).
+
Propchange: ant/sandbox/antlibs/props/NOTICE
------------------------------------------------------------------------------
svn:eol-style = native
Added: ant/sandbox/antlibs/props/build.xml
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/props/build.xml?view=auto&rev=550589
==============================================================================
--- ant/sandbox/antlibs/props/build.xml (added)
+++ ant/sandbox/antlibs/props/build.xml Mon Jun 25 12:55:16 2007
@@ -0,0 +1,29 @@
+<?xml version="1.0"?>
+<!--
+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.
+-->
+<project default="compile" name="props">
+
+ <!-- easy way to override properties -->
+ <property file="build.properties"/>
+
+ <!-- don't fork junit; regexp classes not available -->
+ <property name="junit.fork" value="false" />
+
+ <import file="common/build.xml"/>
+</project>
Propchange: ant/sandbox/antlibs/props/build.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: ant/sandbox/antlibs/props/docs/index.html
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/props/docs/index.html?view=auto&rev=550589
==============================================================================
--- ant/sandbox/antlibs/props/docs/index.html (added)
+++ ant/sandbox/antlibs/props/docs/index.html Mon Jun 25 12:55:16 2007
@@ -0,0 +1,125 @@
+<!--
+ 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.
+-->
+<html>
+ <head>
+ <meta http-equiv="Content-Language" content="en-us"></meta>
+ <link rel="stylesheet" type="text/css" href="style.css">
+ <title>Props Ant Library</title>
+ </head>
+
+ <body>
+ <h2>Introduction</h2>
+
+ <p>This is a library of supplementary handlers for Ant properties resolution.</p>
+
+ <h2>Requirements</h2>
+
+ <p>The current version of this antlib is built against an experimental version of Ant
+ that allows a custom PropertyEvaluator to return an Object from an attribute
+ containing a single resolvable property. A patch can be found at
+ <a
+href="http://issues.apache.org/">
+</a>.
+ </p>
+
+ <h2>Where is it?</h2>
+
+ <p>The source code for the library lives in the sandbox antlibs subspace of Ant's SVN -
+ <a href="http://svn.apache.org/viewcvs.cgi/ant/antlibs/antunit/trunk/">http://svn.apache.org/viewcvs.cgi/ant/sandbox/antlibs/props/trunk/</a>.</p>
+
+ <h2>Installation</h2>
+
+ <p>If you are building this from sources, run the antlib target
+ and you'll get a file <code>ant-props.jar</code>.</p>
+
+ <p>There are several ways to use the tasks:</p>
+
+ <ul>
+ <li>The traditional way:
+ <pre>
+ <taskdef
+ resource="org/apache/ant/props/antlib.xml">
+ <classpath>
+ <pathelement location="YOUR-PATH-TO/ant-props.jar"/>
+ </classpath>
+ </taskdef>
+ </pre>
+
+ Using this approach the provided extensions will live in the default namespace.
+ </li>
+
+ <li>Similar, but assigning a namespace URI
+ <pre>
+ <typedef uri="antlib:org.apache.ant.props"
+ resource="org/apache/ant/props/antlib.xml">
+ <classpath>
+ <pathelement location="YOUR-PATH-TO/ant-props.jar"/>
+ </classpath>
+ </taskdef>
+ </pre>
+
+ Placing the properties extensions into their own namespace, usable e.g.:
+
+ <pre>
+ <project
+ xmlns:props="antlib:org.apache.ant.props"
+ xmlns="antlib:org.apache.tools.ant">
+ ...
+ <propertyhelper>
+ <props:nested />
+ </propertyhelper>
+ </pre>
+
+ or a variation thereof.
+ </li>
+
+ <li>Using Ant's autodiscovery. Place <code>ant-props.jar</code>
+ into a directory and use <code>ant -lib
+ DIR-CONTAINING-THE-JAR</code> or copy it into
+ <code>ANT_HOME/lib</code> - and then in your build file, simply
+ declare the namespace on the <code>project</code> tag:
+
+ <pre>
+ <project
+ xmlns:props="antlib:org.apache.ant.props">
+ </pre>
+
+ And all tasks of this library will automatically be available
+ in the <code>props</code> namespace without any
+ <code>taskdef</code>.
+ </li>
+ </ul>
+
+ <h2>Tasks and Types</h2>
+
+ <p>The types provided are (so far) instances of
+ <code>org.apache.tools.ant.PropertyHelper.Delegate</code> and can be invoked
+ using the <propertyhelper> task provided at the referenced Bugzilla entry:</a>
+
+ <ul>
+ <li>nested - Implements evaluation of nested Ant properties e.g. ${${double-expand-me}}.</li>
+ <li><a href="stringops.html">stringops</a> - Implements *nix shell-inspired string ops.</li>
+ <li>refs - Given <code>ref:<em>refid</em></code>, expands to reference <em>refid</em>.</li>
+ <li>types - Given <code><em>type:arg</em></code>, attempts to invoke
+ <code><em>type</em></code> constructor <code>(<em>project, arg</em>)</code>,
+ then <code>(<em>arg</em>)</code>.
+ </li>
+ </ul>
+
+ <hr/>
+ </body>
+</html>
Propchange: ant/sandbox/antlibs/props/docs/index.html
------------------------------------------------------------------------------
svn:eol-style = native
Added: ant/sandbox/antlibs/props/docs/stringops.html
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/props/docs/stringops.html?view=auto&rev=550589
==============================================================================
--- ant/sandbox/antlibs/props/docs/stringops.html (added)
+++ ant/sandbox/antlibs/props/docs/stringops.html Mon Jun 25 12:55:16 2007
@@ -0,0 +1,106 @@
+<!--
+ 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.
+-->
+<html>
+ <head>
+ <meta http-equiv="Content-Language" content="en-us"></meta>
+ <link rel="stylesheet" type="text/css" href="style.css">
+ <title>stringops evaluator</title>
+ </head>
+
+ <body>
+ <h2><a name="stringops">stringops</a></h2>
+
+ <h3>Description</h3>
+
+ <p>Implements *nix shell-inspired string ops.</p>
+
+ <h3>Simple operations</h3>
+
+ <p>Substring property foo from index <em>start</em> for length <em>len</em>:</p>
+ <pre>${foo:<em>start</em>:<em>len</em>}</pre>
+
+ <p>Evaluate to "defaultfoo" if foo not set:</p>
+ <pre>${foo:-defaultfoo}</pre>
+
+ <p>Default unset property foo to "defaultfoo" and return:</p>
+ <pre>${foo:=defaultfoo}</pre>
+
+ <p>Fail build if property foo unset:</p>
+ <pre>${foo:?defaultfoo}</pre>
+
+ <p>Evaluate to "if-foo" if property foo set:</p>
+ <pre>${foo:+if-foo}</pre>
+
+ <hr />
+ <h3>Delete/Replace</h3>
+
+ <p>The patterns used for deletion and replacement are *nix-style; i.e. Ant
+ patternset syntax without ** support. File separators are transparently merged.
+ Characters used in the expressions themselves can be specified by backslash escaping.
+ </p>
+
+ <p>Delete shortest leading match:</p>
+ <pre>
+ <!-- given ${x}=foo/bar/baz.ext -->
+ ${x#*/} <!-- yields bar/baz.ext -->
+ </pre>
+
+ <p>Delete longest leading match:</p>
+ <pre>
+ <!-- given ${x}=foo/bar/baz.ext -->
+ ${x##*/} <!-- yields baz.ext -->
+ </pre>
+
+ <p>Delete shortest trailing match:</p>
+ <pre>
+ <!-- given ${x}=foo/bar/baz.ext -->
+ ${x%%/*} <!-- yields foo/bar -->
+ </pre>
+
+ <p>Delete longest trailing match:</p>
+ <pre>
+ <!-- given ${x}=foo/bar/baz.ext -->
+ ${x%%/*} <!-- yields foo -->
+ </pre>
+
+ <p>Delete extension:</p>
+ <pre>
+ <!-- given ${x}=foo/bar/baz.ext -->
+ ${x%%.*} <!-- yields foo/bar/baz -->
+ </pre>
+
+ <p>Extract extension:</p>
+ <pre>
+ <!-- given ${x}=foo/bar/baz.ext -->
+ ${x##*.} <!-- yields .ext -->
+ </pre>
+
+ <p>Replace first occurrence of a pattern:</p>
+ <pre>
+ <!-- given ${path}=org/apache/ant/props -->
+ ${path/\//.} <!-- yields org.apache/ant/props -->
+ </pre>
+
+ <p>Replace all occurrences of a pattern:</p>
+ <pre>
+ <!-- given ${path}=org/apache/ant/props -->
+ ${path//\//.} <!-- yields org.apache.ant.props -->
+ </pre>
+
+ <hr />
+ </body>
+</html>
Propchange: ant/sandbox/antlibs/props/docs/stringops.html
------------------------------------------------------------------------------
svn:eol-style = native
Added: ant/sandbox/antlibs/props/docs/style.css
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/props/docs/style.css?view=auto&rev=550589
==============================================================================
--- ant/sandbox/antlibs/props/docs/style.css (added)
+++ ant/sandbox/antlibs/props/docs/style.css Mon Jun 25 12:55:16 2007
@@ -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.
+ */
+h2 {
+ font-size: 200%;
+ background-color: ffffff;
+}
+
+h3 {
+ font-size: 130%;
+ color: #ffffff;
+ background-color: #525D76;
+}
+
+h4 {
+ color: #ffffff;
+ background-color: #828DA6;
+}
+
+td {
+ background-color: eeeeee;
+ color: 000000;
+}
+
+ /* first row */
+table tr:first-child td {
+ background-color: cccccc;
+ color: 000000;
+}
+
+ /* or th as first row */
+table th {
+ background-color: cccccc;
+ color: 000000;
+}
+
+pre {
+ background-color: efefef;
+}
Propchange: ant/sandbox/antlibs/props/docs/style.css
------------------------------------------------------------------------------
svn:eol-style = native
Added: ant/sandbox/antlibs/props/src/main/org/apache/ant/props/ComponentTypeEvaluator.java
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/props/src/main/org/apache/ant/props/ComponentTypeEvaluator.java?view=auto&rev=550589
==============================================================================
--- ant/sandbox/antlibs/props/src/main/org/apache/ant/props/ComponentTypeEvaluator.java (added)
+++ ant/sandbox/antlibs/props/src/main/org/apache/ant/props/ComponentTypeEvaluator.java Mon Jun 25 12:55:16 2007
@@ -0,0 +1,86 @@
+/*
+ * 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.ComponentHelper;
+import org.apache.tools.ant.Project;
+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.
+ */
+public class ComponentTypeEvaluator implements PropertyHelper.PropertyEvaluator {
+ private static final String DEFAULT_DELIMITER = ":";
+
+ 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;
+
+ /**
+ * {@inheritDoc}
+ * @see org.apache.tools.ant.PropertyHelper.PropertyEvaluator#evaluate(java.lang.String, org.apache.tools.ant.PropertyHelper)
+ */
+ public Object evaluate(String property, PropertyHelper propertyHelper) {
+ int d = property.indexOf(getDelimiter());
+ 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);
+ }
+ }
+ }
+ 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;
+ }
+}
Propchange: ant/sandbox/antlibs/props/src/main/org/apache/ant/props/ComponentTypeEvaluator.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: ant/sandbox/antlibs/props/src/main/org/apache/ant/props/NestedPropertyExpander.java
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/props/src/main/org/apache/ant/props/NestedPropertyExpander.java?view=auto&rev=550589
==============================================================================
--- ant/sandbox/antlibs/props/src/main/org/apache/ant/props/NestedPropertyExpander.java (added)
+++ ant/sandbox/antlibs/props/src/main/org/apache/ant/props/NestedPropertyExpander.java Mon Jun 25 12:55:16 2007
@@ -0,0 +1,61 @@
+/*
+ * 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.text.ParsePosition;
+
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.PropertyHelper;
+
+/**
+ * Oft-requested nested Ant property expansion.
+ */
+public class NestedPropertyExpander implements PropertyHelper.PropertyExpander {
+
+ /**
+ * {@inheritDoc}
+ * @see org.apache.tools.ant.PropertyHelper.PropertyExpander#parsePropertyName(java.lang.String, java.text.ParsePosition, org.apache.tools.ant.PropertyHelper)
+ */
+ public String parsePropertyName(String value, ParsePosition pos, PropertyHelper propertyHelper) {
+ int start = pos.getIndex();
+ Project p = propertyHelper.getProject();
+ if (value.indexOf("${", start) == start) {
+ p.log("Attempting nested property processing", Project.MSG_DEBUG);
+ pos.setIndex(start + 2);
+ StringBuffer sb = new StringBuffer();
+ for (int c = pos.getIndex(); c < value.length(); c = pos.getIndex()) {
+ if (value.charAt(c) == '}') {
+ pos.setIndex(c + 1);
+ return sb.toString();
+ }
+ Object o = propertyHelper.parseNextProperty(value, pos);
+ if (o != null) {
+ sb.append(o);
+ } else {
+ sb.append(value.charAt(c));
+ pos.setIndex(c + 1);
+ }
+ }
+ }
+ pos.setIndex(start);
+ return null;
+ }
+
+}
Propchange: ant/sandbox/antlibs/props/src/main/org/apache/ant/props/NestedPropertyExpander.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: ant/sandbox/antlibs/props/src/main/org/apache/ant/props/ReferenceResolvingEvaluator.java
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/props/src/main/org/apache/ant/props/ReferenceResolvingEvaluator.java?view=auto&rev=550589
==============================================================================
--- ant/sandbox/antlibs/props/src/main/org/apache/ant/props/ReferenceResolvingEvaluator.java (added)
+++ ant/sandbox/antlibs/props/src/main/org/apache/ant/props/ReferenceResolvingEvaluator.java Mon Jun 25 12:55:16 2007
@@ -0,0 +1,42 @@
+/*
+ * 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;
+
+/**
+ * Name says it all, doesn't it?
+ */
+public class ReferenceResolvingEvaluator implements PropertyHelper.PropertyEvaluator {
+
+ /**
+ * {@inheritDoc}
+ * @see org.apache.tools.ant.PropertyHelper.PropertyEvaluator#evaluate(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;
+ }
+}
Propchange: ant/sandbox/antlibs/props/src/main/org/apache/ant/props/ReferenceResolvingEvaluator.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: ant/sandbox/antlibs/props/src/main/org/apache/ant/props/antlib.xml
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/props/src/main/org/apache/ant/props/antlib.xml?view=auto&rev=550589
==============================================================================
--- ant/sandbox/antlibs/props/src/main/org/apache/ant/props/antlib.xml (added)
+++ ant/sandbox/antlibs/props/src/main/org/apache/ant/props/antlib.xml Mon Jun 25 12:55:16 2007
@@ -0,0 +1,25 @@
+<?xml version="1.0"?>
+<!--
+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.
+-->
+<antlib>
+ <typedef name="nested" classname="org.apache.ant.props.NestedPropertyExpander" />
+ <typedef name="stringops" classname="org.apache.ant.props.stringops.StringOperationsEvaluator" />
+ <typedef name="types" classname="org.apache.ant.props.ComponentTypeEvaluator" />
+ <typedef name="refs" classname="org.apache.ant.props.ReferenceResolvingEvaluator" />
+</antlib>
Propchange: ant/sandbox/antlibs/props/src/main/org/apache/ant/props/antlib.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/DefaultValue.java
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/DefaultValue.java?view=auto&rev=550589
==============================================================================
--- ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/DefaultValue.java (added)
+++ ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/DefaultValue.java Mon Jun 25 12:55:16 2007
@@ -0,0 +1,41 @@
+/*
+ * 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.stringops;
+
+import org.apache.tools.ant.PropertyHelper;
+
+/**
+ * DefaultValue operation.
+ */
+public class DefaultValue extends StringOperation {
+
+ /**
+ * Construct a new DefaultValue operation.
+ */
+ public DefaultValue() {
+ super("^(.*):-(.*)$");
+ }
+
+ /** {@inheritDoc} */
+ protected String evaluate(String[] groups, PropertyHelper propertyHelper) {
+ Object o = (String) propertyHelper.getProperty(groups[1]);
+ return o == null ? groups[2] : o.toString();
+ }
+}
Propchange: ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/DefaultValue.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/DeleteFromEndGreedy.java
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/DeleteFromEndGreedy.java?view=auto&rev=550589
==============================================================================
--- ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/DeleteFromEndGreedy.java (added)
+++ ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/DeleteFromEndGreedy.java Mon Jun 25 12:55:16 2007
@@ -0,0 +1,47 @@
+/*
+ * 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.stringops;
+
+/**
+ * DeleteFromEndGreedy operation.
+ */
+public class DeleteFromEndGreedy extends DeletePartOperation {
+
+ /**
+ * Construct a new DeleteFromEndGreedy operation.
+ */
+ public DeleteFromEndGreedy() {
+ super("^(.*)%%(.*)$", GREEDY);
+ }
+
+ /** {@inheritDoc} */
+ protected String specializePattern(String pattern) {
+ return "^(.*?)(?:" + pattern + ")$";
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.apache.ant.props.stringops.PatternOperation#convertToRegex(java.lang.StringBuffer, boolean)
+ */
+ protected void convertToRegex(StringBuffer sb, boolean greedy) {
+ deEscape('%', sb);
+ super.convertToRegex(sb, greedy);
+ }
+}
Propchange: ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/DeleteFromEndGreedy.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/DeleteFromEndReluctant.java
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/DeleteFromEndReluctant.java?view=auto&rev=550589
==============================================================================
--- ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/DeleteFromEndReluctant.java (added)
+++ ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/DeleteFromEndReluctant.java Mon Jun 25 12:55:16 2007
@@ -0,0 +1,47 @@
+/*
+ * 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.stringops;
+
+/**
+ * DeleteFromEndReluctant operation.
+ */
+public class DeleteFromEndReluctant extends DeletePartOperation {
+
+ /**
+ * Construct a new DeleteFromEndReluctant operation.
+ */
+ public DeleteFromEndReluctant() {
+ super("^(.*)%([^%]?.*)$", RELUCTANT);
+ }
+
+ /** {@inheritDoc} */
+ protected String specializePattern(String pattern) {
+ return "^(.*)(?:" + pattern + ")$";
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.apache.ant.props.stringops.PatternOperation#convertToRegex(java.lang.StringBuffer, boolean)
+ */
+ protected void convertToRegex(StringBuffer sb, boolean greedy) {
+ deEscape('%', sb);
+ super.convertToRegex(sb, greedy);
+ }
+}
Propchange: ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/DeleteFromEndReluctant.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/DeleteFromStartGreedy.java
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/DeleteFromStartGreedy.java?view=auto&rev=550589
==============================================================================
--- ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/DeleteFromStartGreedy.java (added)
+++ ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/DeleteFromStartGreedy.java Mon Jun 25 12:55:16 2007
@@ -0,0 +1,47 @@
+/*
+ * 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.stringops;
+
+/**
+ * DeleteFromStartGreedy operation.
+ */
+public class DeleteFromStartGreedy extends DeletePartOperation {
+
+ /**
+ * Construct a new DeleteFromStartGreedy operation.
+ */
+ public DeleteFromStartGreedy() {
+ super("^(.*)##(.*)$", GREEDY);
+ }
+
+ /** {@inheritDoc} */
+ protected String specializePattern(String pattern) {
+ return "^(?:" + pattern + ")(.*?)$";
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.apache.ant.props.stringops.PatternOperation#convertToRegex(java.lang.StringBuffer, boolean)
+ */
+ protected void convertToRegex(StringBuffer sb, boolean greedy) {
+ deEscape('#', sb);
+ super.convertToRegex(sb, greedy);
+ }
+}
Propchange: ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/DeleteFromStartGreedy.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/DeleteFromStartReluctant.java
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/DeleteFromStartReluctant.java?view=auto&rev=550589
==============================================================================
--- ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/DeleteFromStartReluctant.java (added)
+++ ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/DeleteFromStartReluctant.java Mon Jun 25 12:55:16 2007
@@ -0,0 +1,47 @@
+/*
+ * 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.stringops;
+
+/**
+ * DeleteFromStartReluctant operation.
+ */
+public class DeleteFromStartReluctant extends DeletePartOperation {
+
+ /**
+ * Construct a new DeleteFromStartReluctant operation.
+ */
+ public DeleteFromStartReluctant() {
+ super("^(.*)#([^#]?.*)$", RELUCTANT);
+ }
+
+ /** {@inheritDoc} */
+ protected String specializePattern(String pattern) {
+ return "^(?:" + pattern + ")(.*)$";
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.apache.ant.props.stringops.PatternOperation#convertToRegex(java.lang.StringBuffer, boolean)
+ */
+ protected void convertToRegex(StringBuffer sb, boolean greedy) {
+ deEscape('#', sb);
+ super.convertToRegex(sb, greedy);
+ }
+}
Propchange: ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/DeleteFromStartReluctant.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/DeletePartOperation.java
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/DeletePartOperation.java?view=auto&rev=550589
==============================================================================
--- ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/DeletePartOperation.java (added)
+++ ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/DeletePartOperation.java Mon Jun 25 12:55:16 2007
@@ -0,0 +1,64 @@
+/*
+ * 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.stringops;
+
+import org.apache.tools.ant.PropertyHelper;
+import org.apache.tools.ant.util.regexp.Regexp;
+
+/**
+ * DeletePartOperation to be subclassed for Delete[Start|End][Greedy|Reluctant]..
+ */
+public abstract class DeletePartOperation extends PatternOperation {
+ protected static final boolean GREEDY = true;
+ protected static final boolean RELUCTANT = false;
+
+ private boolean greedy;
+
+ /**
+ * Construct a new DeletePartOperation.
+ */
+ protected DeletePartOperation(String pattern, boolean greedy) {
+ super(pattern);
+ this.greedy = greedy;
+ }
+
+ /** {@inheritDoc} */
+ protected String evaluate(String[] groups, PropertyHelper propertyHelper) {
+ Object value = propertyHelper.getProperty(groups[1]);
+ if (value != null) {
+ String s = value.toString();
+ StringBuffer sb = new StringBuffer(groups[2]);
+ convertToRegex(sb, greedy);
+ String specialized = specializePattern(sb.toString());
+ Regexp regexp = createRegexp(specialized, propertyHelper.getProject());
+ String result = regexp.substitute(s, "\\1", Regexp.REPLACE_FIRST);
+ return result;
+ }
+ return null;
+ }
+
+ /**
+ * Specialize the RE pattern for the purposes of the specific subclass.
+ * @param pattern partial RE pattern.
+ * @return pattern including one group.
+ */
+ protected abstract String specializePattern(String pattern);
+
+}
Propchange: ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/DeletePartOperation.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/PatternOperation.java
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/PatternOperation.java?view=auto&rev=550589
==============================================================================
--- ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/PatternOperation.java (added)
+++ ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/PatternOperation.java Mon Jun 25 12:55:16 2007
@@ -0,0 +1,190 @@
+/*
+ * 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.stringops;
+
+import java.text.ParsePosition;
+
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.types.RegularExpression;
+import org.apache.tools.ant.util.regexp.Regexp;
+
+/**
+ * Abstract pattern-based operation.
+ */
+public abstract class PatternOperation extends StringOperation {
+ private interface PatternParser {
+ boolean process(StringBuffer sb, ParsePosition pos);
+ }
+
+ private static class RecognizeCrossPlatformSeparators implements PatternParser {
+ public boolean process(StringBuffer sb, ParsePosition pos) {
+ int index = pos.getIndex();
+ int matchLength = sb.indexOf("\\\\", index) == index ? 2
+ : sb.charAt(index) == '/' ? 1 : 0;
+ if (matchLength > 0) {
+ sb.replace(index, index + matchLength, "[/|\\\\]");
+ pos.setIndex(index + 6);
+ return true;
+ }
+ return false;
+ }
+ }
+
+ private static class PreserveEscapes implements PatternParser {
+ public boolean process(StringBuffer sb, ParsePosition pos) {
+ int index = pos.getIndex();
+ if (sb.charAt(index) == '\\') {
+ pos.setIndex(index + 2);
+ return true;
+ }
+ return false;
+ }
+ }
+
+ private static class CharToPattern implements PatternParser {
+ private char patternChar;
+ private String regexpPattern;
+ CharToPattern(char patternChar, String regexpPattern) {
+ this.patternChar = patternChar;
+ this.regexpPattern = regexpPattern;
+ }
+ public boolean process(StringBuffer sb, ParsePosition pos) {
+ int index = pos.getIndex();
+ if (sb.charAt(index) == patternChar) {
+ sb.replace(index, index + 1, regexpPattern);
+ pos.setIndex(index + regexpPattern.length());
+ return true;
+ }
+ return false;
+ }
+ }
+
+ //order is important:
+ private static final PatternParser[] GREEDY_PARSERS = new PatternParser[] {
+ new RecognizeCrossPlatformSeparators(),
+ new PreserveEscapes(),
+ new CharToPattern('?', "."),
+ new CharToPattern('.', "\\."),
+ new CharToPattern('*', ".*")
+ };
+
+ private static final PatternParser[] RELUCTANT_PARSERS = new PatternParser[] {
+ new RecognizeCrossPlatformSeparators(),
+ new PreserveEscapes(),
+ new CharToPattern('?', "."),
+ new CharToPattern('.', "\\."),
+ new CharToPattern('*', ".*?")
+ };
+
+ /**
+ * Construct a new PatternOperation.
+ */
+ protected PatternOperation(String regex) {
+ super(regex);
+ }
+
+ /**
+ * Convert a *nix-style pattern to a regex pattern.
+ * @param sb StringBuffer to convert.
+ */
+ protected void convertToRegex(StringBuffer sb) {
+ convertToRegex(sb, true);
+ }
+
+ /**
+ * Convert a *nix-style pattern to a regex pattern.
+ * @param sb StringBuffer to convert.
+ * @param greedy whether to be greedy.
+ */
+ protected void convertToRegex(StringBuffer sb, boolean greedy) {
+ ParsePosition pos = new ParsePosition(0);
+ PatternParser[] parsers = greedy ? GREEDY_PARSERS : RELUCTANT_PARSERS;
+nextpos:
+ while (pos.getIndex() < sb.length()) {
+ for (int i = 0; i < parsers.length; i++) {
+ if (parsers[i].process(sb, pos)) {
+ continue nextpos;
+ }
+ }
+ pos.setIndex(pos.getIndex() + 1);
+ }
+ }
+
+ /**
+ * Convert a *nix-style pattern to a regex pattern.
+ * @param pattern the *nix-style pattern.
+ * @return String regex pattern.
+ */
+ protected String toRegex(String pattern) {
+ return toRegex(pattern, true);
+ }
+
+ /**
+ * Convert a *nix-style pattern to a regex pattern.
+ * @param pattern the *nix-style pattern.
+ * @param greedy whether to be greedy.
+ * @return String regex pattern.
+ */
+ protected String toRegex(String pattern, boolean greedy) {
+ if (pattern == null) {
+ return null;
+ }
+ StringBuffer sb = new StringBuffer(pattern);
+ ParsePosition pos = new ParsePosition(0);
+ PatternParser[] parsers = greedy ? GREEDY_PARSERS : RELUCTANT_PARSERS;
+nextpos:
+ while (pos.getIndex() < sb.length()) {
+ for (int i = 0; i < parsers.length; i++) {
+ if (parsers[i].process(sb, pos)) {
+ continue nextpos;
+ }
+ }
+ pos.setIndex(pos.getIndex() + 1);
+ }
+ return sb.toString();
+ }
+
+ /**
+ * Create an Ant Regexp object.
+ * @param pattern the regex pattern to use.
+ * @param project the associated Project instance.
+ * @return Regexp
+ */
+ protected Regexp createRegexp(String pattern, Project project) {
+ RegularExpression re = new RegularExpression();
+ re.setPattern(pattern);
+ return re.getRegexp(project);
+ }
+
+ /**
+ * De-escape a given character.
+ * @param c the character to "unmask".
+ * @param sb the target StringBuffer.
+ */
+ protected void deEscape(char c, StringBuffer sb) {
+ ParsePosition pos = new ParsePosition(0);
+ for (int index = pos.getIndex(); index < sb.length(); index = pos.getIndex()) {
+ if (sb.charAt(index) == '\\' && sb.charAt(index + 1) == c) {
+ sb.deleteCharAt(index);
+ }
+ pos.setIndex(index + 1);
+ }
+ }
+}
Propchange: ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/PatternOperation.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/ReplaceOperation.java
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/ReplaceOperation.java?view=auto&rev=550589
==============================================================================
--- ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/ReplaceOperation.java (added)
+++ ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/ReplaceOperation.java Mon Jun 25 12:55:16 2007
@@ -0,0 +1,60 @@
+/*
+ * 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.stringops;
+
+import org.apache.tools.ant.PropertyHelper;
+import org.apache.tools.ant.util.regexp.Regexp;
+
+/**
+ * Abstract Replace operation.
+ */
+public class ReplaceOperation extends PatternOperation {
+ private static final String ESCAPE_SLASH = "\\\\/";
+ private static final String NOT_SLASH = "[^/]";
+ private static final String WORD = "(?:" + ESCAPE_SLASH + "|" + NOT_SLASH + ")*";
+ private static final String RE = "^(" + WORD + ")(//?)(" + WORD + ")/(" + WORD + ")$";
+
+ /**
+ * Construct a new ReplaceOperation.
+ */
+ protected ReplaceOperation() {
+ super(RE);
+ }
+
+ /** {@inheritDoc} */
+ protected final String 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]);
+ convertToRegex(sb);
+ return value == null ? null : createRegexp(sb.toString(), propertyHelper.getProject())
+ .substitute(value.toString(), groups[4], replaceOption);
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.apache.ant.props.stringops.PatternOperation#convertToRegex(java.lang.StringBuffer)
+ */
+ protected void convertToRegex(StringBuffer sb) {
+ deEscape('/', sb);
+ super.convertToRegex(sb);
+ }
+
+}
Propchange: ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/ReplaceOperation.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/RequireProperty.java
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/RequireProperty.java?view=auto&rev=550589
==============================================================================
--- ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/RequireProperty.java (added)
+++ ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/RequireProperty.java Mon Jun 25 12:55:16 2007
@@ -0,0 +1,47 @@
+/*
+ * 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.stringops;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.PropertyHelper;
+
+/**
+ * Require property operation.
+ */
+public class RequireProperty extends StringOperation {
+ private static final String DEFAULT_MESSAGE = "Missing required property ";
+
+ /**
+ * Construct a new RequireProperty operation.
+ */
+ public RequireProperty() {
+ super("^(.*):\\?(.*)?$");
+ }
+
+ /** {@inheritDoc} */
+ protected String 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];
+ throw new BuildException(message);
+ }
+ return result;
+ }
+}
Propchange: ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/RequireProperty.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/SetDefaultValue.java
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/SetDefaultValue.java?view=auto&rev=550589
==============================================================================
--- ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/SetDefaultValue.java (added)
+++ ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/SetDefaultValue.java Mon Jun 25 12:55:16 2007
@@ -0,0 +1,50 @@
+/*
+ * 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.stringops;
+
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.PropertyHelper;
+
+/**
+ * SetDefaultValue operation.
+ */
+public class SetDefaultValue extends StringOperation {
+
+ /**
+ * Construct a new SetDefaultValue operation.
+ */
+ public SetDefaultValue() {
+ super("^(.*):=(.*)$");
+ }
+
+ /** {@inheritDoc} */
+ 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();
+ }
+ return value;
+ }
+}
Propchange: ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/SetDefaultValue.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/StringOperation.java
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/StringOperation.java?view=auto&rev=550589
==============================================================================
--- ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/StringOperation.java (added)
+++ ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/StringOperation.java Mon Jun 25 12:55:16 2007
@@ -0,0 +1,69 @@
+/*
+ * 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.stringops;
+
+import java.util.List;
+
+import org.apache.tools.ant.PropertyHelper;
+import org.apache.tools.ant.types.RegularExpression;
+import org.apache.tools.ant.util.regexp.Regexp;
+
+/**
+ * String operation based on a regular expression.
+ */
+public abstract class StringOperation implements PropertyHelper.PropertyEvaluator {
+ private ThreadLocal preventRecursion = new ThreadLocal();
+ private RegularExpression regularExpression;
+
+ /**
+ * Construct a new StringOperation.
+ * @param pattern the base pattern.
+ */
+ protected StringOperation(String pattern) {
+ regularExpression = new RegularExpression();
+ regularExpression.setPattern(pattern);
+ }
+
+ /** {@inheritDoc} */
+ public Object evaluate(String propertyName, PropertyHelper propertyHelper) {
+ if (preventRecursion.get() != null) {
+ return null;
+ }
+ preventRecursion.set(this);
+ try {
+ Regexp regexp = regularExpression.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;
+ } finally {
+ preventRecursion.set(null);
+ }
+ }
+
+ /**
+ * Evaluate the matched groups.
+ * @param groups the matches from the base regex.
+ * @param propertyHelper the calling PropertyHelper.
+ */
+ protected abstract String evaluate(String[] groups, PropertyHelper propertyHelper);
+}
Propchange: ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/StringOperation.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/StringOperationsEvaluator.java
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/StringOperationsEvaluator.java?view=auto&rev=550589
==============================================================================
--- ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/StringOperationsEvaluator.java (added)
+++ ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/StringOperationsEvaluator.java Mon Jun 25 12:55:16 2007
@@ -0,0 +1,81 @@
+/*
+ * 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.stringops;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Stack;
+
+import org.apache.tools.ant.PropertyHelper;
+
+/**
+ * PropertyEvaluator to apply *nix-style string operations to Ant properties.
+ */
+public class StringOperationsEvaluator implements PropertyHelper.PropertyEvaluator {
+ private static final ThreadLocal STACK = new ThreadLocal() {
+ protected Object initialValue() {
+ return new Stack();
+ }
+ };
+
+ private ArrayList delegates = new ArrayList();
+
+ /**
+ * Construct a new StringOperationsEvaluator.
+ */
+ public StringOperationsEvaluator() {
+ //TODO: add delegates
+ delegates.add(new Substring());
+ delegates.add(new DefaultValue());
+ delegates.add(new SetDefaultValue());
+ delegates.add(new Translate());
+ delegates.add(new RequireProperty());
+ delegates.add(new DeleteFromStartGreedy());
+ delegates.add(new DeleteFromStartReluctant());
+ delegates.add(new DeleteFromEndGreedy());
+ delegates.add(new DeleteFromEndReluctant());
+ delegates.add(new ReplaceOperation());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object evaluate(String propertyName, PropertyHelper propertyHelper) {
+ Stack stk = (Stack) STACK.get();
+ if (stk.contains(propertyName)) {
+ return null;
+ }
+ stk.push(propertyName);
+ try {
+ for (Iterator iter = delegates.iterator(); iter.hasNext();) {
+ Object value = ((StringOperation) iter.next()).evaluate(
+ propertyName, propertyHelper);
+ if (value != null) {
+ return value;
+ }
+ }
+ } finally {
+ if (stk.pop() != propertyName) {
+ throw new IllegalStateException("stack out of balance");
+ }
+ }
+ return null;
+ }
+}
Propchange: ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/StringOperationsEvaluator.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/Substring.java
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/Substring.java?view=auto&rev=550589
==============================================================================
--- ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/Substring.java (added)
+++ ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/Substring.java Mon Jun 25 12:55:16 2007
@@ -0,0 +1,46 @@
+/*
+ * 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.stringops;
+
+import org.apache.tools.ant.PropertyHelper;
+
+/**
+ * Substring operation.
+ */
+public class Substring extends StringOperation {
+
+ /**
+ * Construct a new substring operation.
+ */
+ public Substring() {
+ super("^(.*):(\\d+):(\\d+)$");
+ }
+
+ /** {@inheritDoc} */
+ protected String evaluate(String[] groups, PropertyHelper propertyHelper) {
+ String value = (String) propertyHelper.getProperty(groups[1]);
+ if (value != null) {
+ int start = Integer.parseInt(groups[2]);
+ int end = start + Integer.parseInt(groups[3]);
+ return end > value.length() ? value.substring(start) : value.substring(start, end);
+ }
+ return null;
+ }
+}
Propchange: ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/Substring.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/Translate.java
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/Translate.java?view=auto&rev=550589
==============================================================================
--- ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/Translate.java (added)
+++ ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/Translate.java Mon Jun 25 12:55:16 2007
@@ -0,0 +1,40 @@
+/*
+ * 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.stringops;
+
+import org.apache.tools.ant.PropertyHelper;
+
+/**
+ * Translate operation.
+ */
+public class Translate extends StringOperation {
+
+ /**
+ * Construct a new Translate operation.
+ */
+ public Translate() {
+ super("^(.*):\\+(.*)$");
+ }
+
+ /** {@inheritDoc} */
+ protected String evaluate(String[] groups, PropertyHelper propertyHelper) {
+ return propertyHelper.getProperty(groups[1]) == null ? null : groups[2];
+ }
+}
Propchange: ant/sandbox/antlibs/props/src/main/org/apache/ant/props/stringops/Translate.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: ant/sandbox/antlibs/props/src/tests/antunit/nested-test.xml
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/props/src/tests/antunit/nested-test.xml?view=auto&rev=550589
==============================================================================
--- ant/sandbox/antlibs/props/src/tests/antunit/nested-test.xml (added)
+++ ant/sandbox/antlibs/props/src/tests/antunit/nested-test.xml Mon Jun 25 12:55:16 2007
@@ -0,0 +1,67 @@
+<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"
+ xmlns:props="antlib:org.apache.ant.props">
+
+ <target name="antunit">
+ <au:antunit>
+ <fileset file="${ant.file}" />
+ </au:antunit>
+ </target>
+
+ <target name="setUp">
+ <propertyhelper>
+ <props:nested />
+ </propertyhelper>
+ </target>
+
+ <target name="testNonNested" depends="setUp">
+ <property name="foo" value="foo.value" />
+ <au:assertTrue>
+ <equals arg1="${foo}" arg2="foo.value" />
+ </au:assertTrue>
+ </target>
+
+ <target name="testNested" depends="setUp">
+ <property name="foo" value="foo.value" />
+ <property name="var" value="foo" />
+ <au:assertTrue>
+ <equals arg1="${${var}}" arg2="foo.value" />
+ </au:assertTrue>
+ </target>
+
+ <target name="testMultiNested" depends="setUp">
+ <property name="foo" value="foo.value" />
+ <property name="var1" value="f" />
+ <property name="var2" value="oo" />
+ <au:assertTrue>
+ <equals arg1="${${var1}${var2}}" arg2="foo.value" />
+ </au:assertTrue>
+ </target>
+
+ <target name="testDoubleNested" depends="setUp">
+ <property name="foo" value="foo.value" />
+ <property name="var" value="foo" />
+ <property name="var.var" value="var" />
+ <au:assertTrue>
+ <equals arg1="${${${var.var}}}" arg2="foo.value" />
+ </au:assertTrue>
+ </target>
+
+ <target name="testMixedNested" depends="setUp">
+ <property name="foo" value="foo.value" />
+ <property name="var" value="f" />
+ <property name="var.var" value="v" />
+ <au:assertTrue>
+ <equals arg1="${${${var.var}ar}oo}" arg2="foo.value" />
+ </au:assertTrue>
+ </target>
+
+ <target name="testUnbalanced" depends="setUp">
+ <property name="foo" value="foo.value" />
+ <property name="var" value="foo" />
+ <property name="var.var" value="var" />
+ <au:assertTrue>
+ <equals arg1="${${${var.var}}" arg2="${${${var.var}}" />
+ </au:assertTrue>
+ </target>
+
+</project>
Propchange: ant/sandbox/antlibs/props/src/tests/antunit/nested-test.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: ant/sandbox/antlibs/props/src/tests/antunit/refs-test.xml
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/props/src/tests/antunit/refs-test.xml?view=auto&rev=550589
==============================================================================
--- ant/sandbox/antlibs/props/src/tests/antunit/refs-test.xml (added)
+++ ant/sandbox/antlibs/props/src/tests/antunit/refs-test.xml Mon Jun 25 12:55:16 2007
@@ -0,0 +1,18 @@
+<project xmlns:au="antlib:org.apache.ant.antunit"
+ xmlns:props="antlib:org.apache.ant.props">
+ <target name="setUp">
+ <propertyhelper>
+ <props:refs />
+ <props:nested />
+ </propertyhelper>
+ </target>
+
+ <target name="testPath" depends="setUp">
+ <path id="cp" path="${java.class.path}" />
+ <whichresource property="control" class="org.apache.tools.ant.Project" classpathref="cp" />
+ <whichresource property="test" class="org.apache.tools.ant.Project" classpath="${ref:cp}" />
+ <au:assertTrue>
+ <equals arg1="${control}" arg2="${test}" />
+ </au:assertTrue>
+ </target>
+</project>
Propchange: ant/sandbox/antlibs/props/src/tests/antunit/refs-test.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: ant/sandbox/antlibs/props/src/tests/antunit/stringops-test.xml
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/props/src/tests/antunit/stringops-test.xml?view=auto&rev=550589
==============================================================================
--- ant/sandbox/antlibs/props/src/tests/antunit/stringops-test.xml (added)
+++ ant/sandbox/antlibs/props/src/tests/antunit/stringops-test.xml Mon Jun 25 12:55:16 2007
@@ -0,0 +1,161 @@
+<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"
+ xmlns:props="antlib:org.apache.ant.props">
+
+ <target name="antunit">
+ <au:antunit>
+ <fileset file="${ant.file}" />
+ </au:antunit>
+ </target>
+
+ <target name="setUp" unless="setUp">
+ <propertyhelper>
+ <props:stringops />
+ </propertyhelper>
+ <property name="setUp" value="true" />
+ </target>
+
+ <target name="testSubstring" depends="setUp">
+ <property name="testSubstring" value="testSubstring.value" />
+ <au:assertTrue>
+ <equals arg1="${testSubstring:14:5}" arg2="value" />
+ </au:assertTrue>
+ </target>
+
+ <target name="testDefaultValue" depends="setUp">
+ <property name="testDefaultValue" value="testDefaultValue.value" />
+ <au:assertTrue>
+ <equals arg1="${testDefaultValue:-MISSING VALUE}" arg2="${testDefaultValue}" />
+ </au:assertTrue>
+ <au:assertTrue>
+ <equals arg1="${testDefaultValueUnset:-MISSING VALUE}" arg2="MISSING VALUE" />
+ </au:assertTrue>
+ </target>
+
+ <target name="testSetDefaultValue" depends="setUp">
+ <property name="testSetDefaultValue" value="testSetDefaultValue.value" />
+ <au:assertTrue>
+ <equals arg1="${testSetDefaultValue:=MISSING VALUE}" arg2="${testSetDefaultValue}" />
+ </au:assertTrue>
+ <au:assertTrue>
+ <equals arg1="${testSetDefaultValueUnset:=MISSING VALUE}" arg2="MISSING VALUE" />
+ </au:assertTrue>
+ <au:assertTrue>
+ <equals arg1="${testSetDefaultValueUnset}" arg2="MISSING VALUE" />
+ </au:assertTrue>
+ </target>
+
+ <target name="testTranslate" depends="setUp">
+ <property name="testTranslate" value="anything" />
+ <echo>$${testTranslate:+Formatted Value}=${testTranslate:+Formatted Value}</echo>
+ <echo>$${testTranslateUnset:+Formatted Value}=${testTranslateUnset:+Formatted Value}</echo>
+ <au:assertTrue>
+ <equals arg1="${testTranslate:+Formatted Value}" arg2="Formatted Value" />
+ </au:assertTrue>
+ <au:assertTrue>
+ <equals arg1="${testTranslateUnset:+Formatted Value}"
+ arg2="${testTranslateUnset:+Formatted Value}" />
+ </au:assertTrue>
+ </target>
+
+ <target name="testRequireProperty" depends="setUp">
+ <property name="testRequireProperty" value="testRequireProperty.value" />
+ <au:assertTrue>
+ <equals arg1="${testRequireProperty:?}" arg2="${testRequireProperty}" />
+ </au:assertTrue>
+ <au:assertTrue>
+ <equals arg1="${testRequireProperty:?ERROR MESSAGE}" arg2="${testRequireProperty}" />
+ </au:assertTrue>
+ <au:expectfailure expectedMessage="Missing required property testRequirePropertyUnset">
+ <echo>${testRequirePropertyUnset:?}</echo>
+ </au:expectfailure>
+ <au:expectfailure expectedMessage="ERROR MESSAGE">
+ <echo>${testRequirePropertyUnset:?ERROR MESSAGE}</echo>
+ </au:expectfailure>
+ </target>
+
+ <target name="setUpDelete" depends="setUp">
+ <property name="testDeletePart" value="foo/bar/baz.ext" />
+ <echo level="debug">$${testDeletePart}=${testDeletePart}</echo>
+ </target>
+
+ <target name="testDeleteFromStartGreedy" depends="setUpDelete">
+ <echo level="debug">$${testDeletePart##*/}=${testDeletePart##*/}</echo>
+ <au:assertTrue>
+ <equals arg1="${testDeletePart##*/}" arg2="baz.ext" />
+ </au:assertTrue>
+ </target>
+
+ <target name="testDeleteFromStartReluctant" depends="setUpDelete">
+ <au:assertTrue>
+ <equals arg1="${testDeletePart#*.}" arg2="ext" />
+ </au:assertTrue>
+ <au:assertTrue>
+ <equals arg1="${testDeletePart#*/}" arg2="bar/baz.ext" />
+ </au:assertTrue>
+ </target>
+
+ <target name="testDeleteFromEndGreedy" depends="setUpDelete">
+ <echo level="debug">$${testDeletePart%%/*}=${testDeletePart%%/*}</echo>
+ <au:assertTrue>
+ <equals arg1="${testDeletePart%%/*}" arg2="foo" />
+ </au:assertTrue>
+ </target>
+
+ <target name="testDeleteFromEndReluctant" depends="setUpDelete">
+ <echo level="debug">$${testDeletePart%/*}=${testDeletePart%/*}</echo>
+ <au:assertTrue>
+ <equals arg1="${testDeletePart%/*}" arg2="foo/bar" />
+ </au:assertTrue>
+ </target>
+
+ <target name="testDeleteExtension" depends="setUpDelete">
+ <echo level="debug">$${testDeletePart%.*}=${testDeletePart%.*}</echo>
+ <au:assertTrue>
+ <equals arg1="${testDeletePart%.*}" arg2="foo/bar/baz" />
+ </au:assertTrue>
+ </target>
+
+ <target name="testRetainExtension" depends="setUpDelete">
+ <echo level="debug">$${testDeletePart##*.}=${testDeletePart##*.}</echo>
+ <au:assertTrue>
+ <equals arg1="${testDeletePart##*.}" arg2="ext" />
+ </au:assertTrue>
+ </target>
+
+ <target name="setUpReplace" depends="setUp">
+ <property name="testReplace" value="xoxoxoxoxox" />
+ </target>
+
+ <target name="testReplaceFirst" depends="setUpReplace">
+ <echo level="debug">$${testReplace/xox/-}=${testReplace/xox/-}</echo>
+ <au:assertTrue>
+ <equals arg1="${testReplace/xox/-}" arg2="-oxoxoxox" />
+ </au:assertTrue>
+ </target>
+
+ <target name="testReplaceAll" depends="setUpReplace">
+ <echo level="debug">$${testReplace//xox/-}=${testReplace//xox/-}</echo>
+ <au:assertTrue>
+ <equals arg1="${testReplace//xox/-}" arg2="-o-o-" />
+ </au:assertTrue>
+ </target>
+
+ <target name="testPackageMapping" depends="setUp">
+ <property name="path" value="org/apache/ant/props" />
+ <echo level="debug">$${path}=${path}</echo>
+ <echo level="debug">$${path//\//.}=${path//\//.}</echo>
+ <au:assertTrue>
+ <equals arg1="${path//\//.}" arg2="org.apache.ant.props" />
+ </au:assertTrue>
+ </target>
+
+ <target name="testBackslashPackageMapping" depends="setUp">
+ <property name="backpath" value="org\apache\ant\props" />
+ <echo level="debug">$${backpath}=${backpath}</echo>
+ <echo level="debug">$${backpath//\//.}=${backpath//\//.}</echo>
+ <au:assertTrue>
+ <equals arg1="${backpath//\//.}" arg2="org.apache.ant.props" />
+ </au:assertTrue>
+ </target>
+
+</project>
Propchange: ant/sandbox/antlibs/props/src/tests/antunit/stringops-test.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: ant/sandbox/antlibs/props/src/tests/antunit/types-test.xml
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/props/src/tests/antunit/types-test.xml?view=auto&rev=550589
==============================================================================
--- ant/sandbox/antlibs/props/src/tests/antunit/types-test.xml (added)
+++ ant/sandbox/antlibs/props/src/tests/antunit/types-test.xml Mon Jun 25 12:55:16 2007
@@ -0,0 +1,19 @@
+<project xmlns:au="antlib:org.apache.ant.antunit"
+ xmlns:props="antlib:org.apache.ant.props">
+ <target name="setUp">
+ <propertyhelper>
+ <props:types />
+ <props:nested />
+ </propertyhelper>
+ </target>
+
+ <target name="testPath" depends="setUp">
+ <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}}" />
+ <au:assertTrue>
+ <equals arg1="${control}" arg2="${test}" />
+ </au:assertTrue>
+ </target>
+</project>
Propchange: ant/sandbox/antlibs/props/src/tests/antunit/types-test.xml
------------------------------------------------------------------------------
svn:eol-style = native
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org