Browse Source

Import updates

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@273783 13f79535-47bb-0310-9956-ffa450edef68
master
Conor MacNeill 22 years ago
parent
commit
d1019d39f4
2 changed files with 72 additions and 67 deletions
  1. +63
    -64
      src/main/org/apache/tools/ant/ProjectHelper.java
  2. +9
    -3
      src/main/org/apache/tools/ant/helper/ProjectHelper2.java

+ 63
- 64
src/main/org/apache/tools/ant/ProjectHelper.java View File

@@ -62,7 +62,6 @@ import java.util.Enumeration;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.Locale; import java.util.Locale;
import java.util.Vector; import java.util.Vector;
import org.apache.tools.ant.helper.ProjectHelperImpl;
import org.apache.tools.ant.helper.ProjectHelper2; import org.apache.tools.ant.helper.ProjectHelper2;
import org.apache.tools.ant.util.LoaderUtils; import org.apache.tools.ant.util.LoaderUtils;
import org.xml.sax.AttributeList; import org.xml.sax.AttributeList;
@@ -88,15 +87,15 @@ import org.xml.sax.Attributes;
* @author duncan@x180.com * @author duncan@x180.com
*/ */
public class ProjectHelper { public class ProjectHelper {
/**
* Name of JVM system property which provides the name of the
/**
* Name of JVM system property which provides the name of the
* ProjectHelper class to use. * ProjectHelper class to use.
*/ */
public static final String HELPER_PROPERTY = public static final String HELPER_PROPERTY =
"org.apache.tools.ant.ProjectHelper"; "org.apache.tools.ant.ProjectHelper";
/** /**
* The service identifier in jars which provide Project Helper
* The service identifier in jars which provide Project Helper
* implementations. * implementations.
*/ */
public static final String SERVICE_ID = public static final String SERVICE_ID =
@@ -104,16 +103,16 @@ public class ProjectHelper {


/** /**
* Configures the project with the contents of the specified XML file. * Configures the project with the contents of the specified XML file.
*
*
* @param project The project to configure. Must not be <code>null</code>. * @param project The project to configure. Must not be <code>null</code>.
* @param buildFile An XML file giving the project's configuration. * @param buildFile An XML file giving the project's configuration.
* Must not be <code>null</code>. * Must not be <code>null</code>.
* *
* @deprecated Use the non-statuc parse method * @deprecated Use the non-statuc parse method
* @exception BuildException if the configuration is invalid or cannot
* @exception BuildException if the configuration is invalid or cannot
* be read * be read
*/ */
public static void configureProject(Project project, File buildFile)
public static void configureProject(Project project, File buildFile)
throws BuildException { throws BuildException {
ProjectHelper helper = ProjectHelper.getProjectHelper(); ProjectHelper helper = ProjectHelper.getProjectHelper();
project.addReference("ant.projectHelper", helper); project.addReference("ant.projectHelper", helper);
@@ -159,14 +158,14 @@ public class ProjectHelper {
/** /**
* Parses the project file, configuring the project as it goes. * Parses the project file, configuring the project as it goes.
* *
* @param project The project for the resulting ProjectHelper to configure.
* @param project The project for the resulting ProjectHelper to configure.
* Must not be <code>null</code>. * Must not be <code>null</code>.
* @param source The source for XML configuration. A helper must support * @param source The source for XML configuration. A helper must support
* at least File, for backward compatibility. Helpers may * at least File, for backward compatibility. Helpers may
* support URL, InputStream, etc or specialized types. * support URL, InputStream, etc or specialized types.
* *
* @since Ant1.5 * @since Ant1.5
* @exception BuildException if the configuration is invalid or cannot
* @exception BuildException if the configuration is invalid or cannot
* be read * be read
*/ */
public void parse(Project project, Object source) throws BuildException { public void parse(Project project, Object source) throws BuildException {
@@ -175,24 +174,24 @@ public class ProjectHelper {
} }




/**
/**
* Discovers a project helper instance. Uses the same patterns * Discovers a project helper instance. Uses the same patterns
* as JAXP, commons-logging, etc: a system property, a JDK1.3 * as JAXP, commons-logging, etc: a system property, a JDK1.3
* service discovery, default. * service discovery, default.
*
*
* @return a ProjectHelper, either a custom implementation * @return a ProjectHelper, either a custom implementation
* if one is available and configured, or the default implementation * if one is available and configured, or the default implementation
* otherwise. * otherwise.
*
*
* @exception BuildException if a specified helper class cannot * @exception BuildException if a specified helper class cannot
* be loaded/instantiated. * be loaded/instantiated.
*/ */
public static ProjectHelper getProjectHelper()
public static ProjectHelper getProjectHelper()
throws BuildException { throws BuildException {
// Identify the class loader we will be using. Ant may be // Identify the class loader we will be using. Ant may be
// in a webapp or embeded in a different app // in a webapp or embeded in a different app
ProjectHelper helper = null; ProjectHelper helper = null;
// First, try the system property // First, try the system property
String helperClass = System.getProperty(HELPER_PROPERTY); String helperClass = System.getProperty(HELPER_PROPERTY);
try { try {
@@ -200,8 +199,8 @@ public class ProjectHelper {
helper = newHelper(helperClass); helper = newHelper(helperClass);
} }
} catch (SecurityException e) { } catch (SecurityException e) {
System.out.println("Unable to load ProjectHelper class \""
+ helperClass + " specified in system property "
System.out.println("Unable to load ProjectHelper class \""
+ helperClass + " specified in system property "
+ HELPER_PROPERTY); + HELPER_PROPERTY);
} }


@@ -217,7 +216,7 @@ public class ProjectHelper {
if (is == null) { if (is == null) {
is = ClassLoader.getSystemResourceAsStream(SERVICE_ID); is = ClassLoader.getSystemResourceAsStream(SERVICE_ID);
} }
if (is != null) { if (is != null) {
// This code is needed by EBCDIC and other strange systems. // This code is needed by EBCDIC and other strange systems.
// It's a fix for bugs reported in xerces // It's a fix for bugs reported in xerces
@@ -228,19 +227,19 @@ public class ProjectHelper {
isr = new InputStreamReader(is); isr = new InputStreamReader(is);
} }
BufferedReader rd = new BufferedReader(isr); BufferedReader rd = new BufferedReader(isr);
String helperClassName = rd.readLine(); String helperClassName = rd.readLine();
rd.close(); rd.close();
if (helperClassName != null && if (helperClassName != null &&
!"".equals(helperClassName)) { !"".equals(helperClassName)) {
helper = newHelper(helperClassName); helper = newHelper(helperClassName);
} }
} }
} catch (Exception ex) { } catch (Exception ex) {
System.out.println("Unable to load ProjectHelper "
+ "from service \"" + SERVICE_ID);
System.out.println("Unable to load ProjectHelper "
+ "from service \"" + SERVICE_ID);
} }
} }


@@ -259,16 +258,16 @@ public class ProjectHelper {
} }
} }


/**
* Creates a new helper instance from the name of the class.
* It'll first try the thread class loader, then Class.forName()
/**
* Creates a new helper instance from the name of the class.
* It'll first try the thread class loader, then Class.forName()
* will load from the same loader that loaded this class. * will load from the same loader that loaded this class.
*
*
* @param helperClass The name of the class to create an instance * @param helperClass The name of the class to create an instance
* of. Must not be <code>null</code>. * of. Must not be <code>null</code>.
*
*
* @return a new instance of the specified class. * @return a new instance of the specified class.
*
*
* @exception BuildException if the class cannot be found or * @exception BuildException if the class cannot be found or
* cannot be appropriate instantiated. * cannot be appropriate instantiated.
*/ */
@@ -305,43 +304,43 @@ public class ProjectHelper {
if (!LoaderUtils.isContextLoaderAvailable()) { if (!LoaderUtils.isContextLoaderAvailable()) {
return null; return null;
} }
return LoaderUtils.getContextClassLoader(); return LoaderUtils.getContextClassLoader();
} }


// -------------------- Static utils, used by most helpers ----------------
// -------------------- Static utils, used by most helpers ----------------


/** /**
* Configures an object using an introspection handler. * Configures an object using an introspection handler.
*
*
* @param target The target object to be configured. * @param target The target object to be configured.
* Must not be <code>null</code>. * Must not be <code>null</code>.
* @param attrs A list of attributes to configure within the target. * @param attrs A list of attributes to configure within the target.
* Must not be <code>null</code>. * Must not be <code>null</code>.
* @param project The project containing the target.
* @param project The project containing the target.
* Must not be <code>null</code>. * Must not be <code>null</code>.
* *
* @deprecated Use IntrospectionHelper for each property * @deprecated Use IntrospectionHelper for each property
* @exception BuildException if any of the attributes can't be handled by * @exception BuildException if any of the attributes can't be handled by
* the target * the target
*/ */
public static void configure(Object target, AttributeList attrs,
public static void configure(Object target, AttributeList attrs,
Project project) throws BuildException { Project project) throws BuildException {
if (target instanceof TaskAdapter) { if (target instanceof TaskAdapter) {
target = ((TaskAdapter) target).getProxy(); target = ((TaskAdapter) target).getProxy();
} }


IntrospectionHelper ih =
IntrospectionHelper ih =
IntrospectionHelper.getHelper(target.getClass()); IntrospectionHelper.getHelper(target.getClass());


project.addBuildListener(ih); project.addBuildListener(ih);


for (int i = 0; i < attrs.getLength(); i++) { for (int i = 0; i < attrs.getLength(); i++) {
// reflect these into the target // reflect these into the target
String value = replaceProperties(project, attrs.getValue(i),
String value = replaceProperties(project, attrs.getValue(i),
project.getProperties()); project.getProperties());
try { try {
ih.setAttribute(project, target,
ih.setAttribute(project, target,
attrs.getName(i).toLowerCase(Locale.US), value); attrs.getName(i).toLowerCase(Locale.US), value);


} catch (BuildException be) { } catch (BuildException be) {
@@ -355,8 +354,8 @@ public class ProjectHelper {


/** /**
* Adds the content of #PCDATA sections to an element. * Adds the content of #PCDATA sections to an element.
*
* @param project The project containing the target.
*
* @param project The project containing the target.
* Must not be <code>null</code>. * Must not be <code>null</code>.
* @param target The target object to be configured. * @param target The target object to be configured.
* Must not be <code>null</code>. * Must not be <code>null</code>.
@@ -364,25 +363,25 @@ public class ProjectHelper {
* Will not be <code>null</code>. * Will not be <code>null</code>.
* @param start The start element in the array. * @param start The start element in the array.
* @param count The number of characters to read from the array. * @param count The number of characters to read from the array.
*
*
* @exception BuildException if the target object doesn't accept text * @exception BuildException if the target object doesn't accept text
*/ */
public static void addText(Project project, Object target, char[] buf,
public static void addText(Project project, Object target, char[] buf,
int start, int count) throws BuildException { int start, int count) throws BuildException {
addText(project, target, new String(buf, start, count)); addText(project, target, new String(buf, start, count));
} }


/** /**
* Adds the content of #PCDATA sections to an element. * Adds the content of #PCDATA sections to an element.
*
* @param project The project containing the target.
*
* @param project The project containing the target.
* Must not be <code>null</code>. * Must not be <code>null</code>.
* @param target The target object to be configured. * @param target The target object to be configured.
* Must not be <code>null</code>. * Must not be <code>null</code>.
* @param text Text to add to the target. * @param text Text to add to the target.
* May be <code>null</code>, in which case this * May be <code>null</code>, in which case this
* method call is a no-op. * method call is a no-op.
*
*
* @exception BuildException if the target object doesn't accept text * @exception BuildException if the target object doesn't accept text
*/ */
public static void addText(Project project, Object target, String text) public static void addText(Project project, Object target, String text)
@@ -396,13 +395,13 @@ public class ProjectHelper {
target = ((TaskAdapter) target).getProxy(); target = ((TaskAdapter) target).getProxy();
} }


IntrospectionHelper.getHelper(target.getClass()).addText(project,
IntrospectionHelper.getHelper(target.getClass()).addText(project,
target, text); target, text);
} }


/** /**
* Stores a configured child element within its parent object. * Stores a configured child element within its parent object.
*
*
* @param project Project containing the objects. * @param project Project containing the objects.
* May be <code>null</code>. * May be <code>null</code>.
* @param parent Parent object to add child to. * @param parent Parent object to add child to.
@@ -413,25 +412,25 @@ public class ProjectHelper {
* May be <code>null</code>, in which case * May be <code>null</code>, in which case
* the child is not stored. * the child is not stored.
*/ */
public static void storeChild(Project project, Object parent,
public static void storeChild(Project project, Object parent,
Object child, String tag) { Object child, String tag) {
IntrospectionHelper ih
IntrospectionHelper ih
= IntrospectionHelper.getHelper(parent.getClass()); = IntrospectionHelper.getHelper(parent.getClass());
ih.storeElement(project, parent, child, tag); ih.storeElement(project, parent, child, tag);
} }


/** /**
* Replaces <code>${xxx}</code> style constructions in the given value with
* Replaces <code>${xxx}</code> style constructions in the given value with
* the string value of the corresponding properties. * the string value of the corresponding properties.
* *
* @param project The project containing the properties to replace. * @param project The project containing the properties to replace.
* Must not be <code>null</code>. * Must not be <code>null</code>.
*
*
* @param value The string to be scanned for property references. * @param value The string to be scanned for property references.
* May be <code>null</code>. * May be <code>null</code>.
* *
* @exception BuildException if the string contains an opening
* <code>${</code> without a closing
* @exception BuildException if the string contains an opening
* <code>${</code> without a closing
* <code>}</code> * <code>}</code>
* @return the original string with the properties replaced, or * @return the original string with the properties replaced, or
* <code>null</code> if the original string is <code>null</code>. * <code>null</code> if the original string is <code>null</code>.
@@ -446,7 +445,7 @@ public class ProjectHelper {
} }


/** /**
* Replaces <code>${xxx}</code> style constructions in the given value
* Replaces <code>${xxx}</code> style constructions in the given value
* with the string value of the corresponding data types. * with the string value of the corresponding data types.
* *
* @param project The container project. This is used solely for * @param project The container project. This is used solely for
@@ -454,17 +453,17 @@ public class ProjectHelper {
* @param value The string to be scanned for property references. * @param value The string to be scanned for property references.
* May be <code>null</code>, in which case this * May be <code>null</code>, in which case this
* method returns immediately with no effect. * method returns immediately with no effect.
* @param keys Mapping (String to String) of property names to their
* @param keys Mapping (String to String) of property names to their
* values. Must not be <code>null</code>. * values. Must not be <code>null</code>.
*
* @exception BuildException if the string contains an opening
* <code>${</code> without a closing
*
* @exception BuildException if the string contains an opening
* <code>${</code> without a closing
* <code>}</code> * <code>}</code>
* @return the original string with the properties replaced, or * @return the original string with the properties replaced, or
* <code>null</code> if the original string is <code>null</code>. * <code>null</code> if the original string is <code>null</code>.
* @deprecated Use PropertyHelper * @deprecated Use PropertyHelper
*/ */
public static String replaceProperties(Project project, String value,
public static String replaceProperties(Project project, String value,
Hashtable keys) throws BuildException Hashtable keys) throws BuildException
{ {
PropertyHelper ph=PropertyHelper.getPropertyHelper(project); PropertyHelper ph=PropertyHelper.getPropertyHelper(project);
@@ -475,21 +474,21 @@ public class ProjectHelper {
* Parses a string containing <code>${xxx}</code> style property * Parses a string containing <code>${xxx}</code> style property
* references into two lists. The first list is a collection * references into two lists. The first list is a collection
* of text fragments, while the other is a set of string property names. * of text fragments, while the other is a set of string property names.
* <code>null</code> entries in the first list indicate a property
* <code>null</code> entries in the first list indicate a property
* reference from the second list. * reference from the second list.
*
*
* @param value Text to parse. Must not be <code>null</code>. * @param value Text to parse. Must not be <code>null</code>.
* @param fragments List to add text fragments to.
* @param fragments List to add text fragments to.
* Must not be <code>null</code>. * Must not be <code>null</code>.
* @param propertyRefs List to add property names to. * @param propertyRefs List to add property names to.
* Must not be <code>null</code>. * Must not be <code>null</code>.
* *
* @deprecated Use PropertyHelper * @deprecated Use PropertyHelper
* @exception BuildException if the string contains an opening
* <code>${</code> without a closing
* @exception BuildException if the string contains an opening
* <code>${</code> without a closing
* <code>}</code> * <code>}</code>
*/ */
public static void parsePropertyString(String value, Vector fragments,
public static void parsePropertyString(String value, Vector fragments,
Vector propertyRefs) Vector propertyRefs)
throws BuildException throws BuildException
{ {


+ 9
- 3
src/main/org/apache/tools/ant/helper/ProjectHelper2.java View File

@@ -54,8 +54,6 @@


package org.apache.tools.ant.helper; package org.apache.tools.ant.helper;


import org.apache.tools.ant.*;

import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
@@ -76,6 +74,14 @@ import org.xml.sax.helpers.DefaultHandler;
import org.apache.tools.ant.util.JAXPUtils; import org.apache.tools.ant.util.JAXPUtils;
import org.apache.tools.ant.util.FileUtils; import org.apache.tools.ant.util.FileUtils;


import org.apache.tools.ant.ProjectHelper;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Target;
import org.apache.tools.ant.RuntimeConfigurable;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Location;
import org.apache.tools.ant.UnknownElement;

/** /**
* Sax2 based project reader * Sax2 based project reader
* *
@@ -629,7 +635,7 @@ public class ProjectHelper2 extends ProjectHelper {
String dup = project.getProperty(antFileProp); String dup = project.getProperty(antFileProp);
if (dup != null) { if (dup != null) {
File dupFile = new File(dup); File dupFile = new File(dup);
if( context.ignoreProjectTag &&
if( context.ignoreProjectTag &&
!dupFile.equals(context.buildFile)) { !dupFile.equals(context.buildFile)) {
project.log("Duplicated project name in import. Project "+ project.log("Duplicated project name in import. Project "+
context.currentProjectName + " defined first in " + context.currentProjectName + " defined first in " +


Loading…
Cancel
Save