ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r810060 - in /ant/core/trunk: WHATSNEW docs/manual/CoreTypes/resources.html src/main/org/apache/tools/ant/types/resources/AbstractClasspathResource.java src/tests/antunit/types/resources/javaresource-test.xml
Date Tue, 01 Sep 2009 14:00:17 GMT
Author: bodewig
Date: Tue Sep  1 14:00:17 2009
New Revision: 810060

URL: http://svn.apache.org/viewvc?rev=810060&view=rev
Log:
add a parentFirst attribute to javaresource so you can load resources from the specified classpath
instead of the system classpath.  PR 41369

Added:
    ant/core/trunk/src/tests/antunit/types/resources/javaresource-test.xml   (with props)
Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/docs/manual/CoreTypes/resources.html
    ant/core/trunk/src/main/org/apache/tools/ant/types/resources/AbstractClasspathResource.java

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=810060&r1=810059&r2=810060&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Tue Sep  1 14:00:17 2009
@@ -939,6 +939,11 @@
  * <property> can now specify values as nested text.
    Bugzilla Report 32917.
 
+ * a new parentFirst attribute on <javaresource> allows resources to
+   be loaded from the specified classpath rather than the system
+   classloader.
+   Bugzilla Report 41369.
+
 Changes from Ant 1.7.0 TO Ant 1.7.1
 =============================================
 

Modified: ant/core/trunk/docs/manual/CoreTypes/resources.html
URL: http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/CoreTypes/resources.html?rev=810060&r1=810059&r2=810060&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/CoreTypes/resources.html (original)
+++ ant/core/trunk/docs/manual/CoreTypes/resources.html Tue Sep  1 14:00:17 2009
@@ -149,6 +149,15 @@
       used to load the resource, constructed from the specified classpath.</td>
     <td align="center" valign="top">No</td>
   </tr>
+  <tr>
+    <td valign="top">parentFirst</td>
+    <td valign="top">Whether to consult the parent classloader first -
+      the parent classloader most likely is the system classloader -
+      when using a nested classpath.  Defaults
+      to <code>true</code>.<br/>
+      <em>Since Ant 1.8.0</em></td>
+    <td align="center" valign="top">No</td>
+  </tr>
 </table>
 
 <p>The classpath can also be specified as nested classpath element,

Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/resources/AbstractClasspathResource.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/resources/AbstractClasspathResource.java?rev=810060&r1=810059&r2=810060&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/resources/AbstractClasspathResource.java
(original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/resources/AbstractClasspathResource.java
Tue Sep  1 14:00:17 2009
@@ -17,6 +17,7 @@
  */
 package org.apache.tools.ant.types.resources;
 
+import org.apache.tools.ant.AntClassLoader;
 import org.apache.tools.ant.Project;
 import org.apache.tools.ant.types.Resource;
 import org.apache.tools.ant.types.Path;
@@ -31,13 +32,14 @@
  *
  * A Resource representation of anything that is accessed via a Java classloader.
  * The core methods to set/resolve the classpath are provided.
- * @since Ant 1.8
+ * @since Ant 1.8.0
  *
  */
 
 public abstract class AbstractClasspathResource extends Resource {
     private Path classpath;
     private Reference loader;
+    private boolean parentFirst = true;
 
     /**
      * Set the classpath to use when looking up a resource.
@@ -117,6 +119,17 @@
     }
 
     /**
+     * Whether to consult the parent classloader first.
+     *
+     * <p>Only relevant if a classpath has been specified.</p>
+     *
+     * @since Ant 1.8.0
+     */
+    public void setParentFirst(boolean b) {
+        parentFirst = b;
+    }
+
+    /**
      * Overrides the super version.
      * @param r the Reference to set.
      */
@@ -165,7 +178,14 @@
         if (cl == null) {
             if (getClasspath() != null) {
                 Path p = getClasspath().concatSystemClasspath();
-                cl = getProject().createClassLoader(p);
+                if (parentFirst) {
+                    cl = getProject().createClassLoader(p);
+                } else {
+                    cl = AntClassLoader.newAntClassLoader(getProject()
+                                                          .getCoreLoader(),
+                                                          getProject(),
+                                                          p, false);
+                }
             } else {
                 cl = JavaResource.class.getClassLoader();
             }

Added: ant/core/trunk/src/tests/antunit/types/resources/javaresource-test.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/types/resources/javaresource-test.xml?rev=810060&view=auto
==============================================================================
--- ant/core/trunk/src/tests/antunit/types/resources/javaresource-test.xml (added)
+++ ant/core/trunk/src/tests/antunit/types/resources/javaresource-test.xml Tue Sep  1 14:00:17
2009
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+   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">
+
+  <import file="../../antunit-base.xml"/>
+
+  <target name="setUp">
+    <mkdir dir="${output}"/>
+  </target>
+
+  <target name="testUsesSystemClasspath" depends="setUp">
+    <copy todir="${output}">
+      <javaresource name="org/apache/tools/ant/antlib.xml"/>
+    </copy>
+    <au:assertFileExists file="${output}/org/apache/tools/ant/antlib.xml"/>
+  </target>
+
+  <target name="-setUpAntlibXmlInInput" depends="setUp">
+    <mkdir dir="${input}/org/apache/tools/ant"/>
+    <echo file="${input}/org/apache/tools/ant/antlib.xml">Hello, world!</echo>
+  </target>
+
+  <target name="testParentFirstIsDefault" depends="-setUpAntlibXmlInInput">
+    <copy todir="${output}">
+      <javaresource name="org/apache/tools/ant/antlib.xml">
+        <classpath location="${input}"/>
+      </javaresource>
+    </copy>
+    <au:assertFileExists file="${output}/org/apache/tools/ant/antlib.xml"/>
+    <au:assertFilesDiffer
+       expected="${input}/org/apache/tools/ant/antlib.xml"
+       actual="${output}/org/apache/tools/ant/antlib.xml"/>
+  </target>
+
+  <target name="testParentFirstFalse" depends="-setUpAntlibXmlInInput">
+    <copy todir="${output}">
+      <javaresource name="org/apache/tools/ant/antlib.xml"
+                    parentFirst="false">
+        <classpath location="${input}"/>
+      </javaresource>
+    </copy>
+    <au:assertFileExists file="${output}/org/apache/tools/ant/antlib.xml"/>
+    <au:assertFilesMatch
+       expected="${input}/org/apache/tools/ant/antlib.xml"
+       actual="${output}/org/apache/tools/ant/antlib.xml"/>
+  </target>
+</project>

Propchange: ant/core/trunk/src/tests/antunit/types/resources/javaresource-test.xml
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message