📄 projecthelper.java
字号:
* @return the current context class loader, or <code>null</code> * if the context class loader is unavailable. */ public static ClassLoader getContextClassLoader() { return LoaderUtils.isContextLoaderAvailable() ? LoaderUtils.getContextClassLoader() : null; } // -------------------- Static utils, used by most helpers ---------------- /** * Configures an object using an introspection handler. * * @param target The target object to be configured. * Must not be <code>null</code>. * @param attrs A list of attributes to configure within the target. * Must not be <code>null</code>. * @param project The project containing the target. * Must not be <code>null</code>. * * @deprecated since 1.6.x. * Use IntrospectionHelper for each property. * * @exception BuildException if any of the attributes can't be handled by * the target */ 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; } } } } /** * Adds the content of #PCDATA sections to an element. * * @param project The project containing the target. * Must not be <code>null</code>. * @param target The target object to be configured. * Must not be <code>null</code>. * @param buf A character array of the text within the element. * Will not be <code>null</code>. * @param start The start element in the array. * @param count The number of characters to read from the array. * * @exception BuildException if the target object doesn't accept text */ 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. * * @param project The project containing the target. * Must not be <code>null</code>. * @param target The target object to be configured. * Must not be <code>null</code>. * @param text Text to add to the target. * May be <code>null</code>, in which case this * method call is a no-op. * * @exception BuildException if the target object doesn't accept text */ 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); } /** * Stores a configured child element within its parent object. * * @param project Project containing the objects. * May be <code>null</code>. * @param parent Parent object to add child to. * Must not be <code>null</code>. * @param child Child object to store in parent. * Should not be <code>null</code>. * @param tag Name of element which generated the child. * May be <code>null</code>, in which case * the child is not stored. */ 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); } /** * Replaces <code>${xxx}</code> style constructions in the given value with * the string value of the corresponding properties. * * @param project The project containing the properties to replace. * Must not be <code>null</code>. * * @param value The string to be scanned for property references. * May be <code>null</code>. * * @exception BuildException if the string contains an opening * <code>${</code> without a closing * <code>}</code> * @return the original string with the properties replaced, or * <code>null</code> if the original string is <code>null</code>. * * @deprecated since 1.6.x. * Use project.replaceProperties(). * @since 1.5 */ public static String replaceProperties(Project project, String value) throws BuildException { // needed since project properties are not accessible return project.replaceProperties(value); } /** * Replaces <code>${xxx}</code> style constructions in the given value * with the string value of the corresponding data types. * * @param project The container project. This is used solely for * logging purposes. Must not be <code>null</code>. * @param value The string to be scanned for property references. * May be <code>null</code>, in which case this * method returns immediately with no effect. * @param keys Mapping (String to String) of property names to their * values. Must not be <code>null</code>. * * @exception BuildException if the string contains an opening * <code>${</code> without a closing * <code>}</code> * @return the original string with the properties replaced, or * <code>null</code> if the original string is <code>null</code>. * @deprecated since 1.6.x. * Use PropertyHelper. */ public static String replaceProperties(Project project, String value, Hashtable keys) throws BuildException { PropertyHelper ph = PropertyHelper.getPropertyHelper(project); return ph.replaceProperties(null, value, keys); } /** * Parses a string containing <code>${xxx}</code> 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. * <code>null</code> entries in the first list indicate a property * reference from the second list. * * @param value Text to parse. Must not be <code>null</code>. * @param fragments List to add text fragments to. * Must not be <code>null</code>. * @param propertyRefs List to add property names to. * Must not be <code>null</code>. * * @deprecated since 1.6.x. * Use PropertyHelper. * @exception BuildException if the string contains an opening * <code>${</code> without a closing <code>}</code> */ public static void parsePropertyString(String value, Vector fragments, Vector propertyRefs) throws BuildException { PropertyHelper.parsePropertyStringDefault(value, fragments, propertyRefs); } /** * 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. * @param uri The namepace URI * @param name The localname * @return The stringified form of the ns name */ public static String genComponentName(String uri, String name) { if (uri == null || uri.equals("") || uri.equals(ANT_CORE_URI)) { return name; } return uri + ":" + name; } /** * extract a uri from a component name * * @param componentName The stringified form for {uri, name} * @return The uri or "" if not present */ public static String extractUriFromComponentName(String componentName) { if (componentName == null) { return ""; } int index = componentName.lastIndexOf(':'); if (index == -1) { return ""; } return componentName.substring(0, index); } /** * extract the element name from a component name * * @param componentName The stringified form for {uri, name} * @return The element name of the component */ public static String extractNameFromComponentName(String componentName) { int index = componentName.lastIndexOf(':'); if (index == -1) { return componentName; } return componentName.substring(index + 1); } /** * Add location to build exception. * @param ex the build exception, if the build exception * does not include * @param newLocation the location of the calling task (may be null) * @return a new build exception based in the build exception with * location set to newLocation. If the original exception * did not have a location, just return the build exception */ 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); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -