From b7443f2b77a8daeba5f4b36a14ef34d1fb7fe931 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Fri, 12 Apr 2002 14:10:19 +0000 Subject: [PATCH] Make sure and reset their state. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@272408 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/tools/ant/taskdefs/ExecuteOn.java | 2 +- .../org/apache/tools/ant/taskdefs/Expand.java | 17 ++++--- .../org/apache/tools/ant/taskdefs/Touch.java | 47 ++++++++++++------- .../org/apache/tools/ant/taskdefs/Tstamp.java | 33 ++++++++----- .../org/apache/tools/ant/taskdefs/Untar.java | 7 ++- .../apache/tools/ant/taskdefs/WaitFor.java | 45 +++++++++++------- 6 files changed, 96 insertions(+), 55 deletions(-) diff --git a/src/main/org/apache/tools/ant/taskdefs/ExecuteOn.java b/src/main/org/apache/tools/ant/taskdefs/ExecuteOn.java index 487c4a29e..c6944b006 100644 --- a/src/main/org/apache/tools/ant/taskdefs/ExecuteOn.java +++ b/src/main/org/apache/tools/ant/taskdefs/ExecuteOn.java @@ -77,7 +77,7 @@ import java.io.IOException; * * @since Ant 1.2 * - * @ant.task name="apply" category="control" + * @ant.task category="control" name="execon" name="apply" */ public class ExecuteOn extends ExecTask { diff --git a/src/main/org/apache/tools/ant/taskdefs/Expand.java b/src/main/org/apache/tools/ant/taskdefs/Expand.java index 31d35b495..f7e1f0311 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Expand.java +++ b/src/main/org/apache/tools/ant/taskdefs/Expand.java @@ -78,6 +78,8 @@ import java.util.zip.ZipEntry; * @author Stefan Bodewig * @author Magesh Umasankar * + * @since Ant 1.1 + * * @ant.task category="packaging" * name="unzip" * name="unjar" @@ -101,7 +103,8 @@ public class Expand extends MatchingTask { } if (source == null && filesets.size() == 0) { - throw new BuildException("src attribute and/or filesets must be specified"); + throw new BuildException("src attribute and/or filesets must be " + + "specified"); } if (dest == null) { @@ -151,14 +154,14 @@ public class Expand extends MatchingTask { while ((ze = zis.getNextEntry()) != null) { extractFile(fileUtils, srcF, dir, zis, - ze.getName(), - new Date(ze.getTime()), + ze.getName(), new Date(ze.getTime()), ze.isDirectory()); } log("expand complete", Project.MSG_VERBOSE ); } catch (IOException ioe) { - throw new BuildException("Error while expanding " + srcF.getPath(), ioe); + throw new BuildException("Error while expanding " + srcF.getPath(), + ioe); } finally { if (zis != null) { try { @@ -183,7 +186,8 @@ public class Expand extends MatchingTask { String[] incls = p.getIncludePatterns(project); if (incls != null) { for (int w = 0; w < incls.length; w++) { - boolean isIncl = DirectoryScanner.match(incls[w], name); + boolean isIncl = + DirectoryScanner.match(incls[w], name); if (isIncl) { included = true; break; @@ -193,7 +197,8 @@ public class Expand extends MatchingTask { String[] excls = p.getExcludePatterns(project); if (excls != null) { for (int w = 0; w < excls.length; w++) { - boolean isExcl = DirectoryScanner.match(excls[w], name); + boolean isExcl = + DirectoryScanner.match(excls[w], name); if (isExcl) { included = false; break; diff --git a/src/main/org/apache/tools/ant/taskdefs/Touch.java b/src/main/org/apache/tools/ant/taskdefs/Touch.java index 6d0bfaebb..494e1e0c4 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Touch.java +++ b/src/main/org/apache/tools/ant/taskdefs/Touch.java @@ -85,6 +85,8 @@ import java.util.Vector; * @author Michael J. Sikorsky * @author Robert Shaw * + * @since Ant 1.1 + * * @ant.task category="filesystem" */ public class Touch extends Task { @@ -101,7 +103,7 @@ public class Touch extends Task { /** * Sets a single source file to touch. If the file does not exist - * an empty file will be created. + * an empty file will be created. */ public void setFile(File file) { this.file = file; @@ -132,31 +134,43 @@ public class Touch extends Task { * Execute the touch operation. */ public void execute() throws BuildException { + long savedMillis = millis; + if (file == null && filesets.size() == 0) { throw - new BuildException("Specify at least one source - a file or a fileset."); + new BuildException("Specify at least one source - a file or " + + "a fileset."); } if (file != null && file.exists() && file.isDirectory()) { throw new BuildException("Use a fileset to touch directories."); } - if (dateTime != null) { - DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, - DateFormat.SHORT, - Locale.US); - try { - setMillis(df.parse(dateTime).getTime()); - if (millis < 0) { - throw new BuildException("Date of " + dateTime - + " results in negative milliseconds value relative to epoch (January 1, 1970, 00:00:00 GMT)."); + try { + if (dateTime != null) { + DateFormat df = + DateFormat.getDateTimeInstance(DateFormat.SHORT, + DateFormat.SHORT, + Locale.US); + try { + setMillis(df.parse(dateTime).getTime()); + if (millis < 0) { + throw new BuildException("Date of " + dateTime + + " results in negative " + + "milliseconds value " + + "relative to epoch " + + "(January 1, 1970, " + + "00:00:00 GMT)."); + } + } catch (ParseException pe) { + throw new BuildException(pe.getMessage(), pe, location); } - } catch (ParseException pe) { - throw new BuildException(pe.getMessage(), pe, location); } - } - touch(); + touch(); + } finally { + millis = savedMillis; + } } /** @@ -216,7 +230,8 @@ public class Touch extends Task { protected void touch(File file) throws BuildException { if (!file.canWrite()) { - throw new BuildException("Can not change modification date of read-only file " + file); + throw new BuildException("Can not change modification date of " + + "read-only file " + file); } if (Project.getJavaVersion() == Project.JAVA_1_1) { diff --git a/src/main/org/apache/tools/ant/taskdefs/Tstamp.java b/src/main/org/apache/tools/ant/taskdefs/Tstamp.java index 5ff37446e..c57653315 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Tstamp.java +++ b/src/main/org/apache/tools/ant/taskdefs/Tstamp.java @@ -79,7 +79,7 @@ import java.text.SimpleDateFormat; * @author roxspring@yahoo.com * @author Conor MacNeill * @author Magesh Umasankar - * + * @since Ant 1.1 * @ant.task category="utility" */ public class Tstamp extends Task { @@ -87,6 +87,9 @@ public class Tstamp extends Task { private Vector customFormats = new Vector(); private String prefix = ""; + /** + * @since Ant 1.5 + */ public void setPrefix(String prefix) { this.prefix = prefix; if (!this.prefix.endsWith(".")) { @@ -162,7 +165,8 @@ public class Tstamp extends Task { if (st.hasMoreElements()) { variant = st.nextToken(); if (st.hasMoreElements()) { - throw new BuildException( "bad locale format", getLocation()); + throw new BuildException( "bad locale format", + getLocation()); } } } @@ -171,7 +175,8 @@ public class Tstamp extends Task { } } catch (NoSuchElementException e) { - throw new BuildException( "bad locale format", e, getLocation()); + throw new BuildException( "bad locale format", e, + getLocation()); } } @@ -185,9 +190,10 @@ public class Tstamp extends Task { /** * @deprecated setUnit(String) is deprecated and is replaced with - * setUnit(Tstamp.Unit) to make Ant's Introspection - * mechanism do the work and also to encapsulate operations on - * the unit in its own class. + * setUnit(Tstamp.Unit) to make Ant's + * Introspection mechanism do the work and also to + * encapsulate operations on the unit in its own + * class. */ public void setUnit(String unit) { log("DEPRECATED - The setUnit(String) method has been deprecated." @@ -204,11 +210,13 @@ public class Tstamp extends Task { public void execute(Project project, Date date, Location location) { if (propertyName == null) { - throw new BuildException("property attribute must be provided", location); + throw new BuildException("property attribute must be provided", + location); } if (pattern == null) { - throw new BuildException("pattern attribute must be provided", location); + throw new BuildException("pattern attribute must be provided", + location); } SimpleDateFormat sdf; @@ -216,10 +224,13 @@ public class Tstamp extends Task { sdf = new SimpleDateFormat(pattern); } else if (variant == null) { - sdf = new SimpleDateFormat(pattern, new Locale(language, country)); + sdf = new SimpleDateFormat(pattern, + new Locale(language, country)); } else { - sdf = new SimpleDateFormat(pattern, new Locale(language, country, variant)); + sdf = new SimpleDateFormat(pattern, + new Locale(language, country, + variant)); } if (offset != 0) { Calendar calendar = Calendar.getInstance(); @@ -260,7 +271,7 @@ public class Tstamp extends Task { public Unit() { calendarFields.put(MILLISECOND, - new Integer(Calendar.MILLISECOND)); + new Integer(Calendar.MILLISECOND)); calendarFields.put(SECOND, new Integer(Calendar.SECOND)); calendarFields.put(MINUTE, new Integer(Calendar.MINUTE)); calendarFields.put(HOUR, new Integer(Calendar.HOUR_OF_DAY)); diff --git a/src/main/org/apache/tools/ant/taskdefs/Untar.java b/src/main/org/apache/tools/ant/taskdefs/Untar.java index 902b3c99b..bf2ee4109 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Untar.java +++ b/src/main/org/apache/tools/ant/taskdefs/Untar.java @@ -67,11 +67,11 @@ import java.io.IOException; /** * Untar a file. * - * Heavily based on the Expand task. - * * @author Stefan Bodewig * @author Magesh Umasankar * + * @since Ant 1.1 + * * @ant.task category="packaging" */ public class Untar extends Expand { @@ -86,8 +86,7 @@ public class Untar extends Expand { while ((te = tis.getNextEntry()) != null) { extractFile(fileUtils, srcF, dir, tis, - te.getName(), - te.getModTime(), te.isDirectory()); + te.getName(), te.getModTime(), te.isDirectory()); } log("expand complete", Project.MSG_VERBOSE ); diff --git a/src/main/org/apache/tools/ant/taskdefs/WaitFor.java b/src/main/org/apache/tools/ant/taskdefs/WaitFor.java index 8ba323062..b7483d7ce 100644 --- a/src/main/org/apache/tools/ant/taskdefs/WaitFor.java +++ b/src/main/org/apache/tools/ant/taskdefs/WaitFor.java @@ -83,6 +83,8 @@ import java.util.Hashtable; * @author Denis Hennessy * @author Magesh Umasankar * + * @since Ant 1.5 + * * @ant.task category="control" */ @@ -134,30 +136,39 @@ public class WaitFor extends ConditionBase { */ public void execute() throws BuildException { if (countConditions() > 1) { - throw new BuildException("You must not nest more than one condition into "); + throw new BuildException("You must not nest more than one " + + "condition into "); } if (countConditions() < 1) { - throw new BuildException("You must nest a condition into "); + throw new BuildException("You must nest a condition into " + + ""); } Condition c = (Condition) getConditions().nextElement(); - maxWaitMillis *= maxWaitMultiplier; - checkEveryMillis *= checkEveryMultiplier; - long start = System.currentTimeMillis(); - long end = start + maxWaitMillis; - - while (System.currentTimeMillis() < end) { - if (c.eval()) { - return; - } - try { - Thread.sleep(checkEveryMillis); - } catch (InterruptedException e) { + long savedMaxWaitMillis = maxWaitMillis; + long savedCheckEveryMillis = checkEveryMillis; + try { + maxWaitMillis *= maxWaitMultiplier; + checkEveryMillis *= checkEveryMultiplier; + long start = System.currentTimeMillis(); + long end = start + maxWaitMillis; + + while (System.currentTimeMillis() < end) { + if (c.eval()) { + return; + } + try { + Thread.sleep(checkEveryMillis); + } catch (InterruptedException e) { + } } - } - if (timeoutProperty != null) { - project.setNewProperty(timeoutProperty, "true"); + if (timeoutProperty != null) { + project.setNewProperty(timeoutProperty, "true"); + } + } finally { + maxWaitMillis = savedMaxWaitMillis; + checkEveryMillis = savedCheckEveryMillis; } }