ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r880590 - in /ant/core/trunk: docs/manual/CoreTasks/ docs/manual/CoreTypes/ src/main/org/apache/tools/ant/helper/ src/main/org/apache/tools/ant/types/resources/ src/tests/antunit/taskdefs/
Date Mon, 16 Nov 2009 05:32:44 GMT
Author: bodewig
Date: Mon Nov 16 05:32:43 2009
New Revision: 880590

URL: http://svn.apache.org/viewvc?rev=880590&view=rev
Log:
support creating url resources relative to other URLs

Modified:
    ant/core/trunk/docs/manual/CoreTasks/import.html
    ant/core/trunk/docs/manual/CoreTasks/include.html
    ant/core/trunk/docs/manual/CoreTypes/resources.html
    ant/core/trunk/src/main/org/apache/tools/ant/helper/AntXMLContext.java
    ant/core/trunk/src/main/org/apache/tools/ant/helper/ProjectHelper2.java
    ant/core/trunk/src/main/org/apache/tools/ant/types/resources/URLResource.java
    ant/core/trunk/src/tests/antunit/taskdefs/import-url-test.xml

Modified: ant/core/trunk/docs/manual/CoreTasks/import.html
URL: http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/CoreTasks/import.html?rev=880590&r1=880589&r2=880590&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/CoreTasks/import.html (original)
+++ ant/core/trunk/docs/manual/CoreTasks/import.html Mon Nov 16 05:32:43 2009
@@ -150,9 +150,9 @@
   To create a relative resource you'd use something like:</p>
 
 <pre>
-  &lt;url id="imported.basedir" url="${ant.file.imported}/."/&gt;
   &lt;loadproperties&gt;
-    &lt;url url="${toString:imported.basedir}/imported.properties"/&gt;
+    &lt;url baseUrl="${ant.file.imported}"
+         relativePath="imported.properties"/&gt;
   &lt;/loadproperties&gt;
 </pre>
 

Modified: ant/core/trunk/docs/manual/CoreTasks/include.html
URL: http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/CoreTasks/include.html?rev=880590&r1=880589&r2=880590&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/CoreTasks/include.html (original)
+++ ant/core/trunk/docs/manual/CoreTasks/include.html Mon Nov 16 05:32:43 2009
@@ -153,9 +153,9 @@
   To create a relative resource you'd use something like:</p>
 
 <pre>
-  &lt;url id="included.basedir" url="${ant.file.included}/."/&gt;
   &lt;loadproperties&gt;
-    &lt;url url="${toString:included.basedir}/included.properties"/&gt;
+    &lt;url baseUrl="${ant.file.included}"
+         relativePath="included.properties"/&gt;
   &lt;/loadproperties&gt;
 </pre>
 

Modified: ant/core/trunk/docs/manual/CoreTypes/resources.html
URL: http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/CoreTypes/resources.html?rev=880590&r1=880589&r2=880590&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/CoreTypes/resources.html (original)
+++ ant/core/trunk/docs/manual/CoreTypes/resources.html Mon Nov 16 05:32:43 2009
@@ -254,6 +254,16 @@
     <td valign="top">file</td>
     <td valign="top">The file to expose as a file: url</td>
   </tr>
+  <tr>
+    <td valign="top">baseUrl</td>
+    <td valign="top">The base URL which must be combined with relativePath</td>
+ </tr>
+  <tr>
+    <td valign="top">relativePath</td>
+    <td valign="top">Relative path that defines the url combined with
+      baseUrl</td>
+    <td align="center" valign="top">If using baseUrl</td>
+  </tr>
 </table>
 
 <h4><a name="string">string</a></h4>

Modified: ant/core/trunk/src/main/org/apache/tools/ant/helper/AntXMLContext.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/helper/AntXMLContext.java?rev=880590&r1=880589&r2=880590&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/helper/AntXMLContext.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/helper/AntXMLContext.java Mon Nov 16 05:32:43
2009
@@ -124,12 +124,16 @@
      */
     public void setBuildFile(File buildFile) {
         this.buildFile = buildFile;
-        this.buildFileParent = new File(buildFile.getParent());
-        implicitTarget.setLocation(new Location(buildFile.getAbsolutePath()));
-        try {
-            setBuildFile(FileUtils.getFileUtils().getFileURL(buildFile));
-        } catch (MalformedURLException ex) {
-            throw new BuildException(ex);
+        if (buildFile != null) {
+            this.buildFileParent = new File(buildFile.getParent());
+            implicitTarget.setLocation(new Location(buildFile.getAbsolutePath()));
+            try {
+                setBuildFile(FileUtils.getFileUtils().getFileURL(buildFile));
+            } catch (MalformedURLException ex) {
+                throw new BuildException(ex);
+            }
+        } else {
+            this.buildFileParent = null;
         }
     }
 

Modified: ant/core/trunk/src/main/org/apache/tools/ant/helper/ProjectHelper2.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/helper/ProjectHelper2.java?rev=880590&r1=880589&r2=880590&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/helper/ProjectHelper2.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/helper/ProjectHelper2.java Mon Nov 16 05:32:43
2009
@@ -219,6 +219,7 @@
             buildFileName = buildFile.toString();
         } else if (url != null) {
             try {
+                context.setBuildFile((File) null);
                 context.setBuildFile(url);
             } catch (java.net.MalformedURLException ex) {
                 throw new BuildException(ex);

Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/resources/URLResource.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/resources/URLResource.java?rev=880590&r1=880589&r2=880590&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/resources/URLResource.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/resources/URLResource.java Mon Nov
16 05:32:43 2009
@@ -46,6 +46,8 @@
 
     private URL url;
     private URLConnection conn;
+    private URL baseURL;
+    private String relPath;
 
     /**
      * Default constructor.
@@ -108,6 +110,34 @@
     }
 
     /**
+     * Base URL which combined with the relativePath attribute defines
+     * the URL.
+     * @since Ant 1.8.0
+     */
+    public synchronized void setBaseURL(URL base) {
+        checkAttributesAllowed();
+        if (url != null) {
+            throw new BuildException("can't define URL and baseURL attribute");
+        }
+        baseURL = base;
+    }
+
+    /**
+     * Relative path which combined with the baseURL attribute defines
+     * the URL.
+     * @since Ant 1.8.0
+     */
+    public synchronized void setRelativePath(String r) {
+        checkAttributesAllowed();
+        if (url != null) {
+            throw new BuildException("can't define URL and relativePath"
+                                     + " attribute");
+        }
+        relPath = r;
+    }
+
+
+    /**
      * Get the URL used by this URLResource.
      * @return a URL object.
      */
@@ -115,6 +145,19 @@
         if (isReference()) {
             return ((URLResource) getCheckedRef()).getURL();
         }
+        if (url == null) {
+            if (baseURL != null) {
+                if (relPath == null) {
+                    throw new BuildException("must provide relativePath"
+                                             + " attribute when using baseURL.");
+                }
+                try {
+                    url = new URL(baseURL, relPath);
+                } catch (MalformedURLException e) {
+                    throw new BuildException(e);
+                }
+            }
+        }
         return url;
      }
 
@@ -124,7 +167,7 @@
      */
     public synchronized void setRefid(Reference r) {
         //not using the accessor in this case to avoid side effects
-        if (url != null) {
+        if (url != null || baseURL != null || relPath != null) {
             throw tooManyAttributes();
         }
         super.setRefid(r);

Modified: ant/core/trunk/src/tests/antunit/taskdefs/import-url-test.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/taskdefs/import-url-test.xml?rev=880590&r1=880589&r2=880590&view=diff
==============================================================================
--- ant/core/trunk/src/tests/antunit/taskdefs/import-url-test.xml (original)
+++ ant/core/trunk/src/tests/antunit/taskdefs/import-url-test.xml Mon Nov 16 05:32:43 2009
@@ -21,16 +21,25 @@
   <mkdir dir="${input}/a/b"/>
   <mkdir dir="${input}/a/c"/>
   <echo file="${input}/a/b/outer.xml"><![CDATA[
-<project>
+<project name="outer">
   <import file="../c/inner.xml"/>
 </project>
 ]]></echo>
   <echo file="${input}/a/c/inner.xml"><![CDATA[
-<project>
+<project name="inner">
   <target name="foo">
     <echo>In inner</echo>
+    <echo>ant.file.inner is ${ant.file.inner}</echo>
+    <echo>type is ${ant.file.type.inner}</echo>
+    <loadproperties>
+      <url baseUrl="${ant.file.inner}" relativePath="test.properties"/>
+    </loadproperties>
+    <echo>foo is ${foo}</echo>
   </target>
 </project>]]></echo>
+  <echo file="${input}/a/c/test.properties"><![CDATA[
+foo=bar
+]]></echo>
   <mkdir dir="${output}"/>
   <jar destfile="${output}/test.jar">
     <fileset dir="${input}"/>
@@ -45,5 +54,7 @@
 
   <target name="testImportOfNestedFile" depends="foo">
     <au:assertLogContains text="In inner"/>
+    <au:assertLogContains text="type is url"/>
+    <au:assertLogContains text="foo is bar"/>
   </target>
 </project>



Mime
View raw message