git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@471552 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -27,31 +27,28 @@ import org.apache.tools.ant.util.DeweyDecimal; | |||
| * @since Ant 1.7 | |||
| */ | |||
| public class AntVersion implements Condition { | |||
| private String atLeast = null; | |||
| private String exactly = null; | |||
| /** | |||
| * Evalute the condition. | |||
| * @return true if the condition is true. | |||
| * @throws BuildException if an error occurs. | |||
| */ | |||
| public boolean eval() throws BuildException { | |||
| validate(); | |||
| DeweyDecimal actual = getVersion(); | |||
| if (null != atLeast) { | |||
| if (actual.isGreaterThanOrEqual(new DeweyDecimal(atLeast))) { | |||
| return true; | |||
| } else { | |||
| return false; | |||
| } | |||
| return actual.isGreaterThanOrEqual(new DeweyDecimal(atLeast)); | |||
| } | |||
| if (null != exactly) { | |||
| if (actual.isEqual(new DeweyDecimal(exactly))) { | |||
| return true; | |||
| } else { | |||
| return false; | |||
| } | |||
| return actual.isEqual(new DeweyDecimal(exactly)); | |||
| } | |||
| //default | |||
| return false; | |||
| } | |||
| private void validate() throws BuildException { | |||
| if (atLeast != null && exactly != null) { | |||
| throw new BuildException("Only one of atleast or exactly may be set."); | |||
| @@ -69,19 +66,19 @@ public class AntVersion implements Condition { | |||
| throw new BuildException("The argument is not a Dewey Decimal eg 1.1.0"); | |||
| } | |||
| } | |||
| private DeweyDecimal getVersion() { | |||
| Project p = new Project(); | |||
| p.init(); | |||
| char[] versionString = p.getProperty("ant.version").toCharArray(); | |||
| StringBuffer sb = new StringBuffer(); | |||
| boolean foundFirstDigit = false; | |||
| for (int i=0; i<versionString.length; i++) { | |||
| for (int i = 0; i < versionString.length; i++) { | |||
| if (Character.isDigit(versionString[i])) { | |||
| sb.append(versionString[i]); | |||
| foundFirstDigit = true; | |||
| } | |||
| if (versionString[i]=='.' && foundFirstDigit) { | |||
| if (versionString[i] == '.' && foundFirstDigit) { | |||
| sb.append(versionString[i]); | |||
| } | |||
| if (Character.isLetter(versionString[i]) && foundFirstDigit) { | |||
| @@ -90,20 +87,40 @@ public class AntVersion implements Condition { | |||
| } | |||
| return new DeweyDecimal(sb.toString()); | |||
| } | |||
| /** | |||
| * Get the atleast attribute. | |||
| * @return the atleast attribute. | |||
| */ | |||
| public String getAtLeast() { | |||
| return atLeast; | |||
| } | |||
| /** | |||
| * Set the atleast attribute. | |||
| * This is of the form major.minor.point. | |||
| * For example 1.7.0. | |||
| * @param atLeast the version to check against. | |||
| */ | |||
| public void setAtLeast(String atLeast) { | |||
| this.atLeast = atLeast; | |||
| } | |||
| /** | |||
| * Get the exactly attribute. | |||
| * @return the exactly attribute. | |||
| */ | |||
| public String getExactly() { | |||
| return exactly; | |||
| } | |||
| /** | |||
| * Set the exactly attribute. | |||
| * This is of the form major.minor.point. | |||
| * For example 1.7.0. | |||
| * @param exactly the version to check against. | |||
| */ | |||
| public void setExactly(String exactly) { | |||
| this.exactly = exactly; | |||
| } | |||
| } | |||
| } | |||
| @@ -44,7 +44,7 @@ public abstract class ConditionBase extends ProjectComponent | |||
| /** | |||
| * name of the component | |||
| */ | |||
| private String taskName="condition"; | |||
| private String taskName = "condition"; | |||
| /** | |||
| * | |||
| @@ -60,7 +60,7 @@ public abstract class ConditionBase extends ProjectComponent | |||
| /** | |||
| * Constructor that takes the name of the task in the task name. | |||
| * @param taskName | |||
| * @param taskName the name of the task. | |||
| * @since Ant 1.7 | |||
| */ | |||
| protected ConditionBase(String taskName) { | |||
| @@ -289,6 +289,7 @@ public abstract class ConditionBase extends ProjectComponent | |||
| * be discovered from the org.apache.tools.ant.taskdefs.condition | |||
| * antlib. | |||
| * @param name the condition to create. | |||
| * @return the dynamic condition if found, null otherwise. | |||
| */ | |||
| public Object createDynamicElement(String name) { | |||
| Object cond = ComponentHelper.getComponentHelper(getProject()) | |||
| @@ -69,18 +69,34 @@ public class HasMethod extends ProjectComponent implements Condition { | |||
| createClasspath().setRefid(r); | |||
| } | |||
| /** | |||
| * Set the classname attribute. | |||
| * @param classname the name of the class to check. | |||
| */ | |||
| public void setClassname(String classname) { | |||
| this.classname = classname; | |||
| } | |||
| /** | |||
| * Set the name of the method. | |||
| * @param method the name of the method to check. | |||
| */ | |||
| public void setMethod(String method) { | |||
| this.method = method; | |||
| } | |||
| /** | |||
| * Set the name of the field. | |||
| * @param field the name of the field to check. | |||
| */ | |||
| public void setField(String field) { | |||
| this.field = field; | |||
| } | |||
| /** | |||
| * Set whether to ignore system classes when looking for the class. | |||
| * @param ignoreSystemClasses a <code>boolean</code> value. | |||
| */ | |||
| public void setIgnoreSystemClasses(boolean ignoreSystemClasses) { | |||
| this.ignoreSystemClasses = ignoreSystemClasses; | |||
| } | |||
| @@ -127,15 +143,16 @@ public class HasMethod extends ProjectComponent implements Condition { | |||
| } | |||
| /** {@inheritDoc}. */ | |||
| public boolean eval() throws BuildException { | |||
| if(classname==null) { | |||
| if (classname == null) { | |||
| throw new BuildException("No classname defined"); | |||
| } | |||
| Class clazz=loadClass(classname); | |||
| if (method!=null) { | |||
| Class clazz = loadClass(classname); | |||
| if (method != null) { | |||
| return isMethodFound(clazz); | |||
| } | |||
| if(field!=null) { | |||
| if (field != null) { | |||
| return isFieldFound(clazz); | |||
| } | |||
| throw new BuildException("Neither method nor field defined"); | |||
| @@ -143,9 +160,9 @@ public class HasMethod extends ProjectComponent implements Condition { | |||
| private boolean isFieldFound(Class clazz) { | |||
| Field[] fields = clazz.getDeclaredFields(); | |||
| for(int i=0;i<fields.length;i++) { | |||
| Field fieldEntry=fields[i]; | |||
| if(fieldEntry.getName().equals(field)) { | |||
| for (int i = 0; i < fields.length; i++) { | |||
| Field fieldEntry = fields[i]; | |||
| if (fieldEntry.getName().equals(field)) { | |||
| return true; | |||
| } | |||
| } | |||
| @@ -154,9 +171,9 @@ public class HasMethod extends ProjectComponent implements Condition { | |||
| private boolean isMethodFound(Class clazz) { | |||
| Method[] methods = clazz.getDeclaredMethods(); | |||
| for(int i=0;i<methods.length;i++) { | |||
| Method methodEntry =methods[i]; | |||
| if(methodEntry.getName().equals(method)) { | |||
| for (int i = 0; i < methods.length; i++) { | |||
| Method methodEntry = methods[i]; | |||
| if (methodEntry.getName().equals(method)) { | |||
| return true; | |||
| } | |||
| } | |||
| @@ -33,6 +33,7 @@ import org.apache.tools.ant.ProjectComponent; | |||
| * @since Ant 1.5 | |||
| */ | |||
| public class Http extends ProjectComponent implements Condition { | |||
| private static final int ERROR_BEGINS = 400; | |||
| private String spec = null; | |||
| /** | |||
| @@ -43,7 +44,7 @@ public class Http extends ProjectComponent implements Condition { | |||
| spec = url; | |||
| } | |||
| private int errorsBeginAt = 400; | |||
| private int errorsBeginAt = ERROR_BEGINS; | |||
| /** | |||
| * Set the errorsBeginAt attribute | |||
| @@ -74,7 +75,7 @@ public class Http extends ProjectComponent implements Condition { | |||
| Project.MSG_VERBOSE); | |||
| if (code > 0 && code < errorsBeginAt) { | |||
| return true; | |||
| } | |||
| } | |||
| return false; | |||
| } | |||
| } catch (java.io.IOException e) { | |||
| @@ -85,4 +86,4 @@ public class Http extends ProjectComponent implements Condition { | |||
| } | |||
| return true; | |||
| } | |||
| } | |||
| } | |||
| @@ -53,6 +53,7 @@ import java.net.UnknownHostException; | |||
| */ | |||
| public class IsReachable extends ProjectComponent implements Condition { | |||
| private static final int SECOND = 1000; // millis per second | |||
| private String host; | |||
| private String url; | |||
| @@ -64,24 +65,25 @@ public class IsReachable extends ProjectComponent implements Condition { | |||
| /** | |||
| * Error when no hostname is defined | |||
| */ | |||
| public static final String ERROR_NO_HOSTNAME = "No hostname defined"; | |||
| private static final String ERROR_NO_HOSTNAME = "No hostname defined"; | |||
| /** | |||
| * Error when invalid timeout value is defined | |||
| */ | |||
| public static final String ERROR_BAD_TIMEOUT = "Invalid timeout value"; | |||
| private static final String ERROR_BAD_TIMEOUT = "Invalid timeout value"; | |||
| /** | |||
| * Unknown host message is seen. | |||
| */ | |||
| public static final String WARN_UNKNOWN_HOST = "Unknown host: "; | |||
| private static final String WARN_UNKNOWN_HOST = "Unknown host: "; | |||
| /** | |||
| * Network error message is seen. | |||
| */ | |||
| public static final String ERROR_ON_NETWORK = "network error to "; | |||
| public static final String ERROR_BOTH_TARGETS = "Both url and host have been specified"; | |||
| public static final String MSG_NO_REACHABLE_TEST | |||
| private static final String ERROR_ON_NETWORK = "network error to "; | |||
| private static final String ERROR_BOTH_TARGETS | |||
| = "Both url and host have been specified"; | |||
| private static final String MSG_NO_REACHABLE_TEST | |||
| = "cannot do a proper reachability test on this Java version"; | |||
| public static final String ERROR_BAD_URL = "Bad URL "; | |||
| public static final String ERROR_NO_HOST_IN_URL = "No hostname in URL "; | |||
| private static final String ERROR_BAD_URL = "Bad URL "; | |||
| private static final String ERROR_NO_HOST_IN_URL = "No hostname in URL "; | |||
| private static final String METHOD_NAME = "isReachable"; | |||
| /** | |||
| @@ -172,7 +174,7 @@ public class IsReachable extends ProjectComponent implements Condition { | |||
| reachableMethod = InetAddress.class.getMethod(METHOD_NAME, | |||
| parameterTypes); | |||
| Object[] params = new Object[1]; | |||
| params[0] = new Integer(timeout * 1000); | |||
| params[0] = new Integer(timeout * SECOND); | |||
| try { | |||
| reachable = ((Boolean) reachableMethod.invoke(address, params)) | |||
| .booleanValue(); | |||
| @@ -37,11 +37,12 @@ public class IsSigned extends DataType implements Condition { | |||
| private static final String SIG_START = "META-INF/"; | |||
| private static final String SIG_END = ".SF"; | |||
| private static final int SHORT_SIG_LIMIT = 8; | |||
| private String name; | |||
| private File file; | |||
| /** | |||
| /** | |||
| * The jarfile that is to be tested for the presence | |||
| * of a signature. | |||
| * @param file jarfile to be tested. | |||
| @@ -82,18 +83,18 @@ public class IsSigned extends DataType implements Condition { | |||
| } | |||
| } | |||
| return false; | |||
| } | |||
| } | |||
| boolean shortSig = jarFile.getEntry(SIG_START | |||
| + name.toUpperCase() | |||
| + SIG_END) != null; | |||
| boolean longSig = false; | |||
| if (name.length() > 8) { | |||
| longSig = | |||
| jarFile.getEntry(SIG_START | |||
| + name.substring(0, 8).toUpperCase() | |||
| + SIG_END) != null; | |||
| if (name.length() > SHORT_SIG_LIMIT) { | |||
| longSig = jarFile.getEntry( | |||
| SIG_START | |||
| + name.substring(0, SHORT_SIG_LIMIT).toUpperCase() | |||
| + SIG_END) != null; | |||
| } | |||
| return shortSig || longSig; | |||
| } finally { | |||
| ZipFile.closeQuietly(jarFile); | |||
| @@ -19,7 +19,6 @@ package org.apache.tools.ant.taskdefs.condition; | |||
| import org.apache.tools.ant.BuildException; | |||
| import org.apache.tools.ant.ProjectComponent; | |||
| import org.apache.tools.ant.filters.TokenFilter; | |||
| import org.apache.tools.ant.util.regexp.Regexp; | |||
| import org.apache.tools.ant.types.RegularExpression; | |||
| import org.apache.tools.ant.util.regexp.RegexpMatcher; | |||
| @@ -168,6 +168,8 @@ public class Os implements Condition { | |||
| /** | |||
| * Determines if the OS on which Ant is executing matches the type of | |||
| * that set in setFamily. | |||
| * @return true if the os matches. | |||
| * @throws BuildException if there is an error. | |||
| * @see Os#setFamily(String) | |||
| */ | |||
| public boolean eval() throws BuildException { | |||
| @@ -35,23 +35,23 @@ public class ParserSupports extends ProjectComponent implements Condition { | |||
| private String feature; | |||
| private String property; | |||
| private String value; | |||
| public static final String ERROR_BOTH_ATTRIBUTES = | |||
| private static final String ERROR_BOTH_ATTRIBUTES = | |||
| "Property and feature attributes are exclusive"; | |||
| public static final String FEATURE="feature"; | |||
| public static final String PROPERTY = "property"; | |||
| private static final String FEATURE = "feature"; | |||
| private static final String PROPERTY = "property"; | |||
| public static final String NOT_RECOGNIZED = | |||
| private static final String NOT_RECOGNIZED = | |||
| " not recognized: "; | |||
| private static final String NOT_SUPPORTED = | |||
| " not supported: "; | |||
| public static final String ERROR_NO_ATTRIBUTES = | |||
| private static final String ERROR_NO_ATTRIBUTES = | |||
| "Neither feature or property are set"; | |||
| public static final String ERROR_NO_VALUE = | |||
| private static final String ERROR_NO_VALUE = | |||
| "A value is needed when testing for property support"; | |||
| /** | |||
| * Feature to probe for. | |||
| * @param feature | |||
| * @param feature the feature to probe for. | |||
| */ | |||
| public void setFeature(String feature) { | |||
| this.feature = feature; | |||
| @@ -59,7 +59,7 @@ public class ParserSupports extends ProjectComponent implements Condition { | |||
| /** | |||
| * Property to probe for | |||
| * @param property | |||
| * @param property the property to probe for. | |||
| */ | |||
| public void setProperty(String property) { | |||
| this.property = property; | |||
| @@ -68,12 +68,13 @@ public class ParserSupports extends ProjectComponent implements Condition { | |||
| /** | |||
| * Optional value to set. | |||
| * Converted to a boolean value when setting a property | |||
| * @param value | |||
| * @param value the value to set. | |||
| */ | |||
| public void setValue(String value) { | |||
| this.value = value; | |||
| } | |||
| /** {@inheritDoc}. */ | |||
| public boolean eval() throws BuildException { | |||
| if (feature != null && property != null) { | |||
| throw new BuildException(ERROR_BOTH_ATTRIBUTES); | |||
| @@ -109,14 +110,14 @@ public class ParserSupports extends ProjectComponent implements Condition { | |||
| if (value == null) { | |||
| value = "true"; | |||
| } | |||
| boolean v= Project.toBoolean(value); | |||
| boolean v = Project.toBoolean(value); | |||
| try { | |||
| reader.setFeature(feature, v); | |||
| } catch (SAXNotRecognizedException e) { | |||
| log(FEATURE+NOT_RECOGNIZED+feature,Project.MSG_VERBOSE); | |||
| log(FEATURE + NOT_RECOGNIZED + feature, Project.MSG_VERBOSE); | |||
| return false; | |||
| } catch (SAXNotSupportedException e) { | |||
| log(FEATURE+NOT_SUPPORTED + feature, Project.MSG_VERBOSE); | |||
| log(FEATURE + NOT_SUPPORTED + feature, Project.MSG_VERBOSE); | |||
| return false; | |||
| } | |||
| return true; | |||
| @@ -139,4 +140,4 @@ public class ParserSupports extends ProjectComponent implements Condition { | |||
| } | |||
| return true; | |||
| } | |||
| } | |||
| } | |||
| @@ -68,8 +68,8 @@ public class TypeFound extends ProjectComponent implements Condition { | |||
| } | |||
| //now verify that the class has an implementation | |||
| boolean found = def.getExposedClass(getProject()) != null; | |||
| if(!found) { | |||
| String text= helper.diagnoseCreationFailure(componentName,"type"); | |||
| if (!found) { | |||
| String text = helper.diagnoseCreationFailure(componentName, "type"); | |||
| log(text, Project.MSG_VERBOSE); | |||
| } | |||
| return found; | |||