| Method from org.apache.tools.ant.ProjectHelper Detail: |
public static BuildException addLocationToBuildException(BuildException ex,
Location newLocation) {
if (ex.getLocation() == null || ex.getMessage() == null) {
return ex;
}
String errorMessage
= "The following error occurred while executing this line:"
+ System.getProperty("line.separator")
+ ex.getLocation().toString()
+ ex.getMessage();
if (newLocation == null) {
return new BuildException(errorMessage, ex);
}
return new BuildException(errorMessage, ex, newLocation);
}
Add location to build exception. |
public static void addText(Project project,
Object target,
String text) throws BuildException {
if (text == null) {
return;
}
if (target instanceof TypeAdapter) {
target = ((TypeAdapter) target).getProxy();
}
IntrospectionHelper.getHelper(project, target.getClass()).addText(project, target, text);
}
Adds the content of #PCDATA sections to an element. |
public static void addText(Project project,
Object target,
char[] buf,
int start,
int count) throws BuildException {
addText(project, target, new String(buf, start, count));
}
Adds the content of #PCDATA sections to an element. |
public static void configure(Object target,
AttributeList attrs,
Project project) throws BuildException {
if (target instanceof TypeAdapter) {
target = ((TypeAdapter) target).getProxy();
}
IntrospectionHelper ih = IntrospectionHelper.getHelper(project, target.getClass());
for (int i = 0, length = attrs.getLength(); i < length; i++) {
// reflect these into the target
String value = replaceProperties(project, attrs.getValue(i), project.getProperties());
try {
ih.setAttribute(project, target, attrs.getName(i).toLowerCase(Locale.US), value);
} catch (BuildException be) {
// id attribute must be set externally
if (!attrs.getName(i).equals("id")) {
throw be;
}
}
}
} Deprecated! since - 1.6.x.
Use IntrospectionHelper for each property.
Configures an object using an introspection handler. |
public static void configureProject(Project project,
File buildFile) throws BuildException {
ProjectHelper helper = ProjectHelper.getProjectHelper();
project.addReference(PROJECTHELPER_REFERENCE, helper);
helper.parse(project, buildFile);
}
Configures the project with the contents of the specified XML file. |
public static String extractNameFromComponentName(String componentName) {
int index = componentName.lastIndexOf(':");
if (index == -1) {
return componentName;
}
return componentName.substring(index + 1);
}
extract the element name from a component name |
public static String extractUriFromComponentName(String componentName) {
if (componentName == null) {
return "";
}
int index = componentName.lastIndexOf(':");
if (index == -1) {
return "";
}
return componentName.substring(0, index);
}
extract a uri from a component name |
public static String genComponentName(String uri,
String name) {
if (uri == null || uri.equals("") || uri.equals(ANT_CORE_URI)) {
return name;
}
return uri + ":" + name;
}
Map a namespaced {uri,name} to an internal string format.
For BC purposes the names from the ant core uri will be
mapped to "name", other names will be mapped to
uri + ":" + name. |
public static ClassLoader getContextClassLoader() {
return LoaderUtils.isContextLoaderAvailable() ? LoaderUtils.getContextClassLoader() : null;
} Deprecated! since - 1.6.x.
Use LoaderUtils.getContextClassLoader()
JDK1.1 compatible access to the context class loader. Cut & paste from JAXP. |
public Vector getImportStack() {
// Temporary - until we figure a better API
// public Hashtable getProcessedFiles() {
// return processedFiles;
// }
return importStack;
}
EXPERIMENTAL WILL_CHANGE
Import stack.
Used to keep track of imported files. Error reporting should
display the import path. |
public static ProjectHelper getProjectHelper() throws BuildException {
// Identify the class loader we will be using. Ant may be
// in a webapp or embedded in a different app
ProjectHelper helper = null;
// First, try the system property
String helperClass = System.getProperty(HELPER_PROPERTY);
try {
if (helperClass != null) {
helper = newHelper(helperClass);
}
} catch (SecurityException e) {
System.out.println("Unable to load ProjectHelper class \""
+ helperClass + " specified in system property "
+ HELPER_PROPERTY);
}
// A JDK1.3 'service' ( like in JAXP ). That will plug a helper
// automatically if in CLASSPATH, with the right META-INF/services.
if (helper == null) {
try {
ClassLoader classLoader = LoaderUtils.getContextClassLoader();
InputStream is = null;
if (classLoader != null) {
is = classLoader.getResourceAsStream(SERVICE_ID);
}
if (is == null) {
is = ClassLoader.getSystemResourceAsStream(SERVICE_ID);
}
if (is != null) {
// This code is needed by EBCDIC and other strange systems.
// It's a fix for bugs reported in xerces
InputStreamReader isr;
try {
isr = new InputStreamReader(is, "UTF-8");
} catch (java.io.UnsupportedEncodingException e) {
isr = new InputStreamReader(is);
}
BufferedReader rd = new BufferedReader(isr);
String helperClassName = rd.readLine();
rd.close();
if (helperClassName != null && !"".equals(helperClassName)) {
helper = newHelper(helperClassName);
}
}
} catch (Exception ex) {
System.out.println("Unable to load ProjectHelper from service " + SERVICE_ID);
}
}
return helper == null ? new ProjectHelper2() : helper;
}
Discovers a project helper instance. Uses the same patterns
as JAXP, commons-logging, etc: a system property, a JDK1.3
service discovery, default. |
public void parse(Project project,
Object source) throws BuildException {
throw new BuildException("ProjectHelper.parse() must be implemented "
+ "in a helper plugin " + this.getClass().getName());
}
Parses the project file, configuring the project as it goes. |
public static void parsePropertyString(String value,
Vector fragments,
Vector propertyRefs) throws BuildException {
PropertyHelper.parsePropertyStringDefault(value, fragments, propertyRefs);
} Deprecated! since - 1.6.x.
Use PropertyHelper.
Parses a string containing ${xxx} style property
references into two lists. The first list is a collection
of text fragments, while the other is a set of string property names.
null entries in the first list indicate a property
reference from the second list. |
public static String replaceProperties(Project project,
String value) throws BuildException {
// needed since project properties are not accessible
return project.replaceProperties(value);
} Deprecated! since - 1.6.x.
Use project.replaceProperties().
Replaces ${xxx} style constructions in the given value with
the string value of the corresponding properties. |
public static String replaceProperties(Project project,
String value,
Hashtable keys) throws BuildException {
PropertyHelper ph = PropertyHelper.getPropertyHelper(project);
return ph.replaceProperties(null, value, keys);
} Deprecated! since - 1.6.x.
Use PropertyHelper.
Replaces ${xxx} style constructions in the given value
with the string value of the corresponding data types. |
public static void storeChild(Project project,
Object parent,
Object child,
String tag) {
IntrospectionHelper ih = IntrospectionHelper.getHelper(project, parent.getClass());
ih.storeElement(project, parent, child, tag);
}
Stores a configured child element within its parent object. |