ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hi...@apache.org
Subject svn commit: r829947 - in /ant/core/trunk/src/main/org/apache/tools/ant: ProjectHelper.java ProjectHelperRepository.java helper/ProjectHelper2.java taskdefs/Antlib.java
Date Mon, 26 Oct 2009 20:43:59 GMT
Author: hibou
Date: Mon Oct 26 20:43:58 2009
New Revision: 829947

URL: http://svn.apache.org/viewvc?rev=829947&view=rev
Log:
- use the project helper repository for antlib too
- change the ProjectHelper API to start using Resource instead of URL or File

Modified:
    ant/core/trunk/src/main/org/apache/tools/ant/ProjectHelper.java
    ant/core/trunk/src/main/org/apache/tools/ant/ProjectHelperRepository.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/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=829947&r1=829946&r2=829947&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 Mon Oct 26 20:43:58 2009
@@ -18,11 +18,12 @@
 package org.apache.tools.ant;
 
 import java.io.File;
-import java.net.URL;
 import java.util.Hashtable;
 import java.util.Locale;
 import java.util.Vector;
 
+import org.apache.tools.ant.types.Resource;
+import org.apache.tools.ant.types.resources.FileResource;
 import org.apache.tools.ant.util.LoaderUtils;
 import org.xml.sax.AttributeList;
 
@@ -64,16 +65,17 @@
     public static final String PROJECTHELPER_REFERENCE = MagicNames.REFID_PROJECT_HELPER;
 
     /**
-     * Configures the project with the contents of the specified XML file.
+     * Configures the project with the contents of the specified build file.
      *
      * @param project The project to configure. Must not be <code>null</code>.
-     * @param buildFile An XML file giving the project's configuration.
+     * @param buildFile A build file giving the project's configuration.
      *                  Must not be <code>null</code>.
      *
      * @exception BuildException if the configuration is invalid or cannot be read
      */
     public static void configureProject(Project project, File buildFile) throws BuildException
{
-        ProjectHelper helper = ProjectHelperRepository.getInstance().getProjectHelper(buildFile);
+        FileResource resource = new FileResource(buildFile);
+        ProjectHelper helper = ProjectHelperRepository.getInstance().getProjectHelperForBuildFile(resource);
         project.addReference(PROJECTHELPER_REFERENCE, helper);
         helper.parse(project, buildFile);
     }
@@ -498,7 +500,7 @@
      *
      * @since Ant 1.8.0
      */
-    public boolean canParseAntlibDescriptor(URL url) {
+    public boolean canParseAntlibDescriptor(Resource r) {
         return false;
     }
 
@@ -509,7 +511,7 @@
      * @since ant 1.8.0
      */
     public UnknownElement parseAntlibDescriptor(Project containingProject,
-                                                URL source) {
+                                                Resource source) {
         throw new BuildException("can't parse antlib descriptors");
     }
 
@@ -522,7 +524,7 @@
      * @return true if the helper supports it
      * @since Ant 1.8.0
      */
-    public boolean supportsBuildFile(File buildFile) {
+    public boolean canParseBuildFile(Resource buildFile) {
         return true;
     }
 

Modified: ant/core/trunk/src/main/org/apache/tools/ant/ProjectHelperRepository.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/ProjectHelperRepository.java?rev=829947&r1=829946&r2=829947&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/ProjectHelperRepository.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/ProjectHelperRepository.java Mon Oct 26 20:43:58
2009
@@ -18,7 +18,6 @@
 package org.apache.tools.ant;
 
 import java.io.BufferedReader;
-import java.io.File;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.lang.reflect.Constructor;
@@ -29,6 +28,7 @@
 import java.util.List;
 
 import org.apache.tools.ant.helper.ProjectHelper2;
+import org.apache.tools.ant.types.Resource;
 import org.apache.tools.ant.util.LoaderUtils;
 
 /**
@@ -206,20 +206,20 @@
     }
 
     /**
-     * Get the helper that will be able to parse the specified file. The helper
+     * Get the helper that will be able to parse the specified build file. The helper
      * will be chosen among the ones found in the classpath
      * 
      * @return the first ProjectHelper that fit the requirement (never <code>null</code>).
      */
-    public ProjectHelper getProjectHelper(File buildFile) throws BuildException {
+    public ProjectHelper getProjectHelperForBuildFile(Resource buildFile) throws BuildException
{
         Iterator it = getHelpers();
         while (it.hasNext()) {
             ProjectHelper helper = (ProjectHelper) it.next();
-            if (helper.supportsBuildFile(buildFile)) {
+            if (helper.canParseBuildFile(buildFile)) {
                 if (DEBUG) {
                     System.out.println("ProjectHelper "
                                        + helper.getClass().getName()
-                                       + " selected for the file "
+                                       + " selected for the build file "
                                        + buildFile);
                 }
                 return helper;
@@ -230,6 +230,30 @@
     }
 
     /**
+     * Get the helper that will be able to parse the specified antlib. The helper
+     * will be chosen among the ones found in the classpath
+     * 
+     * @return the first ProjectHelper that fit the requirement (never <code>null</code>).
+     */
+    public ProjectHelper getProjectHelperForAntlib(Resource antlib) throws BuildException
{
+        Iterator it = getHelpers();
+        while (it.hasNext()) {
+            ProjectHelper helper = (ProjectHelper) it.next();
+            if (helper.canParseAntlibDescriptor(antlib)) {
+                if (DEBUG) {
+                    System.out.println("ProjectHelper "
+                                       + helper.getClass().getName()
+                                       + " selected for the antlib "
+                                       + antlib);
+                }
+                return helper;
+            }
+        }
+        throw new RuntimeException("BUG: at least the ProjectHelper2 should "
+                                   + "have supported the file " + antlib);
+    }
+
+    /**
      * Get an iterator on the list of project helpers configured. The iterator
      * will always return at least one element as there will always be the
      * default project helper configured.

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=829947&r1=829946&r2=829947&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 Oct 26 20:43:58
2009
@@ -27,6 +27,8 @@
 import org.apache.tools.ant.TargetGroup;
 import org.apache.tools.ant.Task;
 import org.apache.tools.ant.UnknownElement;
+import org.apache.tools.ant.types.Resource;
+import org.apache.tools.ant.types.resources.URLResource;
 import org.apache.tools.ant.util.FileUtils;
 import org.apache.tools.ant.util.JAXPUtils;
 import org.xml.sax.Attributes;
@@ -83,7 +85,7 @@
      *
      * @since Ant 1.8.0
      */
-    public boolean canParseAntlibDescriptor(URL url) {
+    public boolean canParseAntlibDescriptor(Resource resource) {
         return true;
     }
 
@@ -97,8 +99,11 @@
      * @since ant 1.8.0
      */
     public UnknownElement parseAntlibDescriptor(Project containingProject,
-                                                URL source) {
-        return parseUnknownElement(containingProject, source);
+                                                Resource resource) {
+        if (!(resource instanceof URLResource)) {
+            throw new BuildException("Unsupported resource type: " + resource);
+        }
+        return parseUnknownElement(containingProject, ((URLResource)resource).getURL());
     }
 
     /**

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=829947&r1=829946&r2=829947&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 Mon Oct 26 20:43:58
2009
@@ -28,10 +28,11 @@
 import org.apache.tools.ant.ComponentHelper;
 import org.apache.tools.ant.Project;
 import org.apache.tools.ant.ProjectHelper;
+import org.apache.tools.ant.ProjectHelperRepository;
 import org.apache.tools.ant.Task;
 import org.apache.tools.ant.TaskContainer;
 import org.apache.tools.ant.UnknownElement;
-import org.apache.tools.ant.helper.ProjectHelper2;
+import org.apache.tools.ant.types.resources.URLResource;
 
 
 /**
@@ -70,6 +71,7 @@
         ComponentHelper helper =
             ComponentHelper.getComponentHelper(project);
         helper.enterAntLib(uri);
+        URLResource antlibResource = new URLResource(antlibUrl);
         try {
             // Should be safe to parse
             ProjectHelper parser = null;
@@ -77,18 +79,17 @@
                 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.");
+                if (!parser.canParseAntlibDescriptor(antlibResource)) {
                     parser = null;
                 }
             }
             if (parser == null) {
-                parser = new ProjectHelper2();
+                ProjectHelperRepository helperRepository =
+                    ProjectHelperRepository.getInstance();
+                parser = helperRepository.getProjectHelperForAntlib(antlibResource);
             }
             UnknownElement ue =
-                parser.parseAntlibDescriptor(project, antlibUrl);
+                parser.parseAntlibDescriptor(project, antlibResource);
             // Check name is "antlib"
             if (!(ue.getTag().equals(TAG))) {
                 throw new BuildException(



Mime
View raw message