Browse Source

use the configured ProjectHelper to parse antlib descriptors, if possible, PR 42208.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@695865 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 17 years ago
parent
commit
6a02f44830
4 changed files with 89 additions and 5 deletions
  1. +7
    -0
      WHATSNEW
  2. +34
    -0
      src/main/org/apache/tools/ant/ProjectHelper.java
  3. +29
    -1
      src/main/org/apache/tools/ant/helper/ProjectHelper2.java
  4. +19
    -4
      src/main/org/apache/tools/ant/taskdefs/Antlib.java

+ 7
- 0
WHATSNEW View File

@@ -364,6 +364,13 @@ Other changes:
* <patch> has a new optional failOnError attribute. * <patch> has a new optional failOnError attribute.
Bugzilla Report 44772. 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 Changes from Ant 1.7.0 TO Ant 1.7.1
============================================= =============================================




+ 34
- 0
src/main/org/apache/tools/ant/ProjectHelper.java View File

@@ -21,6 +21,7 @@ import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.URL;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.Locale; import java.util.Locale;
import java.util.Vector; import java.util.Vector;
@@ -507,4 +508,37 @@ public class ProjectHelper {
} }
return new BuildException(errorMessage, ex, newLocation); 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");
}
} }

+ 29
- 1
src/main/org/apache/tools/ant/helper/ProjectHelper2.java View File

@@ -72,6 +72,33 @@ public class ProjectHelper2 extends ProjectHelper {
*/ */
private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); 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 * Parse an unknown element from a url
* *
@@ -80,7 +107,8 @@ public class ProjectHelper2 extends ProjectHelper {
* @return a configured task * @return a configured task
* @exception BuildException if an error occurs * @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(); Target dummyTarget = new Target();
dummyTarget.setProject(project); dummyTarget.setProject(project);




+ 19
- 4
src/main/org/apache/tools/ant/taskdefs/Antlib.java View File

@@ -24,13 +24,14 @@ import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;


import org.apache.tools.ant.TaskContainer;
import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.ComponentHelper; import org.apache.tools.ant.ComponentHelper;
import org.apache.tools.ant.Project; import org.apache.tools.ant.Project;
import org.apache.tools.ant.ProjectHelper;
import org.apache.tools.ant.Task; 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.UnknownElement;
import org.apache.tools.ant.helper.ProjectHelper2;




/** /**
@@ -71,9 +72,23 @@ public class Antlib extends Task implements TaskContainer {
helper.enterAntLib(uri); helper.enterAntLib(uri);
try { try {
// Should be safe to parse // 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 = UnknownElement ue =
parser.parseUnknownElement(project, antlibUrl);
parser.parseAntlibDescriptor(project, antlibUrl);
// Check name is "antlib" // Check name is "antlib"
if (!(ue.getTag().equals(TAG))) { if (!(ue.getTag().equals(TAG))) {
throw new BuildException( throw new BuildException(


Loading…
Cancel
Save