📄 modifiedselector.java
字号:
public ClassLoader getClassLoader() { if (myClassLoader == null) { myClassLoader = (classpath == null) // the usual classloader ? getClass().getClassLoader() // additional use the provided classpath : getProject().createClassLoader(classpath); } return myClassLoader; } /** * Set the used ClassLoader. * If you invoke this selector by API (e.g. inside some testcases) the selector * will use a different classloader for loading the interface implementations than * the caller. Therefore you will get a ClassCastException if you get the * implementations from the selector and cast them. * @param loader the ClassLoader to use */ public void setClassLoader(ClassLoader loader) { myClassLoader = loader; } /** * Support for nested <param> tags. * @param key the key of the parameter * @param value the value of the parameter */ public void addParam(String key, Object value) { Parameter par = new Parameter(); par.setName(key); par.setValue(String.valueOf(value)); configParameter.add(par); } /** * Support for nested <param> tags. * @param parameter the parameter object */ public void addParam(Parameter parameter) { configParameter.add(parameter); } /** * Defined in org.apache.tools.ant.types.Parameterizable. * Overwrite implementation in superclass because only special * parameters are valid. * @see #addParam(String,Object). * @param parameters the parameters to set. */ public void setParameters(Parameter[] parameters) { if (parameters != null) { for (int i = 0; i < parameters.length; i++) { configParameter.add(parameters[i]); } } } /** * Support for nested <param name="" value=""/> tags. * Parameter named <i>cache</i>, <i>algorithm</i>, * <i>comparator</i> or <i>update</i> are mapped to * the respective set-Method. * Parameter which names starts with <i>cache.</i> or * <i>algorithm.</i> or <i>comparator.</i> are tried * to set on the appropriate object via its set-methods. * Other parameters are invalid and an BuildException will * be thrown. * * @param parameter Key and value as parameter object */ public void useParameter(Parameter parameter) { String key = parameter.getName(); String value = parameter.getValue(); if ("cache".equals(key)) { CacheName cn = new CacheName(); cn.setValue(value); setCache(cn); } else if ("algorithm".equals(key)) { AlgorithmName an = new AlgorithmName(); an.setValue(value); setAlgorithm(an); } else if ("comparator".equals(key)) { ComparatorName cn = new ComparatorName(); cn.setValue(value); setComparator(cn); } else if ("update".equals(key)) { boolean updateValue = ("true".equalsIgnoreCase(value)) ? true : false; setUpdate(updateValue); } else if ("delayupdate".equals(key)) { boolean updateValue = ("true".equalsIgnoreCase(value)) ? true : false; setDelayUpdate(updateValue); } else if ("seldirs".equals(key)) { boolean sdValue = ("true".equalsIgnoreCase(value)) ? true : false; setSeldirs(sdValue); } else if (key.startsWith(CACHE_START)) { String name = key.substring(CACHE_START.length()); tryToSetAParameter(cache, name, value); } else if (key.startsWith(ALGORITHM_START)) { String name = key.substring(ALGORITHM_START.length()); tryToSetAParameter(algorithm, name, value); } else if (key.startsWith(COMPARATOR_START)) { String name = key.substring(COMPARATOR_START.length()); tryToSetAParameter(comparator, name, value); } else { setError("Invalid parameter " + key); } } /** * Try to set a value on an object using reflection. * Helper method for easier access to IntrospectionHelper.setAttribute(). * @param obj the object on which the attribute should be set * @param name the attributename * @param value the new value */ protected void tryToSetAParameter(Object obj, String name, String value) { Project prj = (getProject() != null) ? getProject() : new Project(); IntrospectionHelper iHelper = IntrospectionHelper.getHelper(prj, obj.getClass()); try { iHelper.setAttribute(prj, obj, name, value); } catch (org.apache.tools.ant.BuildException e) { // no-op } } // ----- 'beautiful' output ----- /** * Override Object.toString(). * @return information about this selector */ public String toString() { StringBuffer buf = new StringBuffer("{modifiedselector"); buf.append(" update=").append(update); buf.append(" seldirs=").append(selectDirectories); buf.append(" cache=").append(cache); buf.append(" algorithm=").append(algorithm); buf.append(" comparator=").append(comparator); buf.append("}"); return buf.toString(); } // ----- BuildListener interface methods ----- /** * Signals that the last target has finished. * @param event recieved BuildEvent */ public void buildFinished(BuildEvent event) { if (getDelayUpdate()) { saveCache(); } } /** * Signals that a target has finished. * @param event recieved BuildEvent */ public void targetFinished(BuildEvent event) { if (getDelayUpdate()) { saveCache(); } } /** * Signals that a task has finished. * @param event recieved BuildEvent */ public void taskFinished(BuildEvent event) { if (getDelayUpdate()) { saveCache(); } } /** * Signals that a build has started. * @param event recieved BuildEvent */ public void buildStarted(BuildEvent event) { // no-op } /** * Signals that a target is starting. * @param event received BuildEvent */ public void targetStarted(BuildEvent event) { // no-op } /** * Signals that a task is starting. * @param event recieved BuildEvent */ public void taskStarted(BuildEvent event) { // no-op } /** * Signals a message logging event. * @param event recieved BuildEvent */ public void messageLogged(BuildEvent event) { // no-op } // The EnumeratedAttributes for the three interface implementations. // Name-Classname mapping is done in the configure() method. /** * Get the cache type to use. * @return the enumerated cache type */ public Cache getCache() { return cache; } /** * Set the cache type to use. * @param name an enumerated cache type. */ public void setCache(CacheName name) { cacheName = name; } /** * The enumerated type for cache. * The values are "propertyfile". */ public static class CacheName extends EnumeratedAttribute { /** @see EnumeratedAttribute#getValues() */ /** {@inheritDoc} */ public String[] getValues() { return new String[] {"propertyfile" }; } } /** * Get the algorithm type to use. * @return the enumerated algorithm type */ public Algorithm getAlgorithm() { return algorithm; } /** * Set the algorithm type to use. * @param name an enumerated algorithm type. */ public void setAlgorithm(AlgorithmName name) { algoName = name; } /** * The enumerated type for algorithm. * The values are "hashValue", "digest" and "checksum". */ public static class AlgorithmName extends EnumeratedAttribute { /** @see EnumeratedAttribute#getValues() */ /** {@inheritDoc} */ public String[] getValues() { return new String[] {"hashvalue", "digest", "checksum" }; } } /** * Get the comparator type to use. * @return the enumerated comparator type */ public Comparator getComparator() { return comparator; } /** * Set the comparator type to use. * @param name an enumerated comparator type. */ public void setComparator(ComparatorName name) { compName = name; } /** * The enumerated type for algorithm. * The values are "equal" and "rule". */ public static class ComparatorName extends EnumeratedAttribute { /** @see EnumeratedAttribute#getValues() */ /** {@inheritDoc} */ public String[] getValues() { return new String[] {"equal", "rule" }; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -