ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r695865 - in /ant/core/trunk: WHATSNEW src/main/org/apache/tools/ant/ProjectHelper.java src/main/org/apache/tools/ant/helper/ProjectHelper2.java src/main/org/apache/tools/ant/taskdefs/Antlib.java
Date Tue, 16 Sep 2008 13:21:02 GMT
Author: bodewig
Date: Tue Sep 16 06:21:01 2008
New Revision: 695865

URL: http://svn.apache.org/viewvc?rev=695865&view=rev
Log:
use the configured ProjectHelper to parse antlib descriptors, if possible,  PR 42208.

Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/src/main/org/apache/tools/ant/ProjectHelper.java
    ant/core/trunk/src/main/org/apache/tools/ant/helper/ProjectHelper2.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Antlib.java

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=695865&r1=695864&r2=695865&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Tue Sep 16 06:21:01 2008
@@ -364,6 +364,13 @@
  * <patch> has a new optional failOnError attribute.
    Bugzilla Report 44772.
 
+ * Antlib descriptors will now be parsed by the configured
+   ProjectHelper if the implementation overrides the new
+   canParseAntlibDescriptor and parseAntlibDescriptor methods.  If the
+   configured helper doesn't override the methods, a new instance of
+   ProjectHelper2 will be used just like in ant 1.7.1.
+   Bugzilla Report 42208.
+
 Changes from Ant 1.7.0 TO Ant 1.7.1
 =============================================
 

Modified: ant/core/trunk/src/main/org/apache/tools/ant/ProjectHelper.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/ProjectHelper.java?rev=695865&r1=695864&r2=695865&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/ProjectHelper.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/ProjectHelper.java Tue Sep 16 06:21:01 2008
@@ -21,6 +21,7 @@
 import java.io.File;
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.net.URL;
 import java.util.Hashtable;
 import java.util.Locale;
 import java.util.Vector;
@@ -507,4 +508,37 @@
         }
         return new BuildException(errorMessage, ex, newLocation);
     }
+
+    /**
+     * Whether this instance of ProjectHelper can parse an Antlib
+     * descriptor given by the URL and return its content as an
+     * UnknownElement ready to be turned into an Antlib task.
+     *
+     * <p>This method should not try to parse the content of the
+     * descriptor, the URL is only given as an argument to allow
+     * subclasses to decide whether they can support a given URL
+     * scheme or not.</p>
+     *
+     * <p>Subclasses that return true in this method must also
+     * override {@link #parseAntlibDescriptor
+     * parseAntlibDescriptor}.</p>
+     *
+     * <p>This implementation returns false.</p>
+     *
+     * @since Ant 1.8.0
+     */
+    public boolean canParseAntlibDescriptor(URL url) {
+        return false;
+    }
+
+    /**
+     * Parse the given URL as an antlib descriptor an return the
+     * content as something that can be turned into an Antlib task.
+     *
+     * @since ant 1.8.0
+     */
+    public UnknownElement parseAntlibDescriptor(Project containingProject,
+                                                URL source) {
+        throw new BuildException("can't parse antlib descriptors");
+    }
 }

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=695865&r1=695864&r2=695865&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 Tue Sep 16 06:21:01
2008
@@ -73,6 +73,33 @@
     private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
 
     /**
+     * Whether this instance of ProjectHelper can parse an Antlib
+     * descriptor given by the URL and return its content as an
+     * UnknownElement ready to be turned into an Antlib task.
+     *
+     * <p>This implementation returns true.</p>
+     *
+     * @since Ant 1.8.0
+     */
+    public boolean canParseAntlibDescriptor(URL url) {
+        return true;
+    }
+
+    /**
+     * Parse the given URL as an antlib descriptor an return the
+     * content as something that can be turned into an Antlib task.
+     *
+     * <p>simply delegates to {@link #parseUnknownElement
+     * parseUnknownElement}.</p>
+     *
+     * @since ant 1.8.0
+     */
+    public UnknownElement parseAntlibDescriptor(Project containingProject,
+                                                URL source) {
+        return parseUnknownElement(containingProject, source);
+    }
+
+    /**
      * Parse an unknown element from a url
      *
      * @param project the current project
@@ -80,7 +107,8 @@
      * @return a configured task
      * @exception BuildException if an error occurs
      */
-    public UnknownElement parseUnknownElement(Project project, URL source) throws BuildException
{
+    public UnknownElement parseUnknownElement(Project project, URL source)
+        throws BuildException {
         Target dummyTarget = new Target();
         dummyTarget.setProject(project);
 

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Antlib.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Antlib.java?rev=695865&r1=695864&r2=695865&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Antlib.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Antlib.java Tue Sep 16 06:21:01
2008
@@ -24,13 +24,14 @@
 import java.util.Iterator;
 import java.util.List;
 
-import org.apache.tools.ant.TaskContainer;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.ComponentHelper;
 import org.apache.tools.ant.Project;
+import org.apache.tools.ant.ProjectHelper;
 import org.apache.tools.ant.Task;
-import org.apache.tools.ant.helper.ProjectHelper2;
+import org.apache.tools.ant.TaskContainer;
 import org.apache.tools.ant.UnknownElement;
+import org.apache.tools.ant.helper.ProjectHelper2;
 
 
 /**
@@ -71,9 +72,23 @@
         helper.enterAntLib(uri);
         try {
             // Should be safe to parse
-            ProjectHelper2 parser = new ProjectHelper2();
+            ProjectHelper parser = null;
+            Object p =
+                project.getReference(ProjectHelper.PROJECTHELPER_REFERENCE);
+            if (p instanceof ProjectHelper) {
+                parser = (ProjectHelper) p;
+                if (!parser.canParseAntlibDescriptor(antlibUrl)) {
+                    project.log("ProjectHelper class " + p.getClass().getName()
+                                + " can't parse Antlib descriptors, falling back"
+                                + " to ProjectHelper2.");
+                    parser = null;
+                }
+            }
+            if (parser == null) {
+                parser = new ProjectHelper2();
+            }
             UnknownElement ue =
-                parser.parseUnknownElement(project, antlibUrl);
+                parser.parseAntlibDescriptor(project, antlibUrl);
             // Check name is "antlib"
             if (!(ue.getTag().equals(TAG))) {
                 throw new BuildException(



Mime
View raw message