diff --git a/src/main/org/apache/tools/ant/taskdefs/condition/AntVersion.java b/src/main/org/apache/tools/ant/taskdefs/condition/AntVersion.java index e0bffa2c4..9cc8f4fae 100644 --- a/src/main/org/apache/tools/ant/taskdefs/condition/AntVersion.java +++ b/src/main/org/apache/tools/ant/taskdefs/condition/AntVersion.java @@ -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; iboolean 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 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; } -} \ No newline at end of file +} diff --git a/src/main/org/apache/tools/ant/taskdefs/condition/IsReachable.java b/src/main/org/apache/tools/ant/taskdefs/condition/IsReachable.java index dc99744bb..099f56390 100644 --- a/src/main/org/apache/tools/ant/taskdefs/condition/IsReachable.java +++ b/src/main/org/apache/tools/ant/taskdefs/condition/IsReachable.java @@ -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(); diff --git a/src/main/org/apache/tools/ant/taskdefs/condition/IsSigned.java b/src/main/org/apache/tools/ant/taskdefs/condition/IsSigned.java index 9c8900cc4..c163fa9e2 100644 --- a/src/main/org/apache/tools/ant/taskdefs/condition/IsSigned.java +++ b/src/main/org/apache/tools/ant/taskdefs/condition/IsSigned.java @@ -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); diff --git a/src/main/org/apache/tools/ant/taskdefs/condition/Matches.java b/src/main/org/apache/tools/ant/taskdefs/condition/Matches.java index 808a66c26..9a9744149 100644 --- a/src/main/org/apache/tools/ant/taskdefs/condition/Matches.java +++ b/src/main/org/apache/tools/ant/taskdefs/condition/Matches.java @@ -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; diff --git a/src/main/org/apache/tools/ant/taskdefs/condition/Os.java b/src/main/org/apache/tools/ant/taskdefs/condition/Os.java index 0c39f687d..5059185f4 100644 --- a/src/main/org/apache/tools/ant/taskdefs/condition/Os.java +++ b/src/main/org/apache/tools/ant/taskdefs/condition/Os.java @@ -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 { diff --git a/src/main/org/apache/tools/ant/taskdefs/condition/ParserSupports.java b/src/main/org/apache/tools/ant/taskdefs/condition/ParserSupports.java index db9926c05..99a9a2f6c 100644 --- a/src/main/org/apache/tools/ant/taskdefs/condition/ParserSupports.java +++ b/src/main/org/apache/tools/ant/taskdefs/condition/ParserSupports.java @@ -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; } -} \ No newline at end of file +} diff --git a/src/main/org/apache/tools/ant/taskdefs/condition/TypeFound.java b/src/main/org/apache/tools/ant/taskdefs/condition/TypeFound.java index 08fb06ddb..b69b8527a 100644 --- a/src/main/org/apache/tools/ant/taskdefs/condition/TypeFound.java +++ b/src/main/org/apache/tools/ant/taskdefs/condition/TypeFound.java @@ -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;