ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r899468 - in /ant/antlibs/props/trunk: docs/index.html src/main/org/apache/ant/props/EncodeURLEvaluator.java src/main/org/apache/ant/props/antlib.xml src/tests/antunit/encodeURL-test.xml
Date Thu, 14 Jan 2010 23:26:48 GMT
Author: mbenson
Date: Thu Jan 14 23:26:47 2010
New Revision: 899468

URL: http://svn.apache.org/viewvc?rev=899468&view=rev
Log:
add EncodeURLEvaluator

Added:
    ant/antlibs/props/trunk/src/main/org/apache/ant/props/EncodeURLEvaluator.java   (with
props)
    ant/antlibs/props/trunk/src/tests/antunit/encodeURL-test.xml   (with props)
Modified:
    ant/antlibs/props/trunk/docs/index.html
    ant/antlibs/props/trunk/src/main/org/apache/ant/props/antlib.xml

Modified: ant/antlibs/props/trunk/docs/index.html
URL: http://svn.apache.org/viewvc/ant/antlibs/props/trunk/docs/index.html?rev=899468&r1=899467&r2=899468&view=diff
==============================================================================
--- ant/antlibs/props/trunk/docs/index.html (original)
+++ ant/antlibs/props/trunk/docs/index.html Thu Jan 14 23:26:47 2010
@@ -129,6 +129,14 @@
             <code><em>type</em></code> constructor <code>(Project,
<em>arg</em>)</code>,
             then <code>(<em>arg</em>)</code>.</td>
       </tr>
+      <tr>
+        <a name="encodeURL" />
+        <td align="center">encodeURL</td>
+        <td align="center">PropertyEvaluator</td>
+        <td>Given <code>encodeURL:<em>arg</em></code>, attempts
to encode <em>arg</em>
+            as a URL per the suggested approach in the javadoc API of <code>java.net.URL</code>.
+        </td>
+      </tr>
     </table>
     <hr/>
   </body>

Added: ant/antlibs/props/trunk/src/main/org/apache/ant/props/EncodeURLEvaluator.java
URL: http://svn.apache.org/viewvc/ant/antlibs/props/trunk/src/main/org/apache/ant/props/EncodeURLEvaluator.java?rev=899468&view=auto
==============================================================================
--- ant/antlibs/props/trunk/src/main/org/apache/ant/props/EncodeURLEvaluator.java (added)
+++ ant/antlibs/props/trunk/src/main/org/apache/ant/props/EncodeURLEvaluator.java Thu Jan
14 23:26:47 2010
@@ -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;
+
+import java.net.URI;
+import java.net.URL;
+
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.PropertyHelper;
+
+/**
+ * PropertyEvaluator that resolves a reference against the current project.
+ */
+public class EncodeURLEvaluator extends StaticPrefixedEvaluator {
+    /** Default prefix */
+    public static final String DEFAULT_PREFIX = "encodeURL";
+
+    /**
+     * Create a new EncodeURLEvaluator.
+     */
+    public EncodeURLEvaluator() {
+        super(DEFAULT_PREFIX);
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.apache.ant.props.PrefixedEvaluator#evaluatePrefixed(java.lang.String,
+     *      java.lang.String, org.apache.tools.ant.PropertyHelper)
+     */
+    protected Object evaluate(String property, String prefix, PropertyHelper propertyHelper)
{
+        try {
+            URL url = new URL(property);
+            URI uri = new URI(url.getProtocol(), url.getUserInfo(),
+                     url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef());
+            return uri.toASCIIString();
+        } catch (Exception e) {
+            propertyHelper.getProject().log("Encountered exception encoding URL text \""
+                    + property + "\"; aborting", e, Project.MSG_ERR);
+            return null;
+        }
+    }
+}

Propchange: ant/antlibs/props/trunk/src/main/org/apache/ant/props/EncodeURLEvaluator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: ant/antlibs/props/trunk/src/main/org/apache/ant/props/antlib.xml
URL: http://svn.apache.org/viewvc/ant/antlibs/props/trunk/src/main/org/apache/ant/props/antlib.xml?rev=899468&r1=899467&r2=899468&view=diff
==============================================================================
--- ant/antlibs/props/trunk/src/main/org/apache/ant/props/antlib.xml (original)
+++ ant/antlibs/props/trunk/src/main/org/apache/ant/props/antlib.xml Thu Jan 14 23:26:47 2010
@@ -22,4 +22,5 @@
   <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" />
+  <typedef name="encodeURL" classname="org.apache.ant.props.EncodeURLEvaluator" />
 </antlib>

Added: ant/antlibs/props/trunk/src/tests/antunit/encodeURL-test.xml
URL: http://svn.apache.org/viewvc/ant/antlibs/props/trunk/src/tests/antunit/encodeURL-test.xml?rev=899468&view=auto
==============================================================================
--- ant/antlibs/props/trunk/src/tests/antunit/encodeURL-test.xml (added)
+++ ant/antlibs/props/trunk/src/tests/antunit/encodeURL-test.xml Thu Jan 14 23:26:47 2010
@@ -0,0 +1,52 @@
+<?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="antunit" xmlns:au="antlib:org.apache.ant.antunit"
+         xmlns:props="antlib:org.apache.ant.props">
+  <target name="setUp">
+    <propertyhelper>
+      <props:encodeURL />
+      <props:encodeURL delimiter="," />
+      <props:nested />
+    </propertyhelper>
+    <path id="cp" path="${java.class.path}" />
+  </target>
+
+  <target name="testBasic" depends="setUp">
+    <au:assertTrue>
+      <equals arg1="${encodeURL:http://ant.apache.org}" arg2="http://ant.apache.org" />
+    </au:assertTrue>
+    <au:assertTrue>
+      <equals arg1="${encodeURL:http://ant.apache.org/foo bar}"
+              arg2="http://ant.apache.org/foo%20bar" />
+    </au:assertTrue>
+  </target>
+
+  <target name="testDelimiter" depends="setUp">
+    <au:assertTrue>
+      <equals arg1="${encodeURL,http://ant.apache.org/foo bar?baz}"
+              arg2="http://ant.apache.org/foo%20bar?baz" />
+    </au:assertTrue>
+  </target>
+
+  <target name="antunit">
+    <au:antunit>
+      <fileset file="${ant.file}" />
+    </au:antunit>
+  </target>
+
+</project>

Propchange: ant/antlibs/props/trunk/src/tests/antunit/encodeURL-test.xml
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message