Browse Source

Make sure <touch> and <waitfor> reset their state.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@272408 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 23 years ago
parent
commit
b7443f2b77
6 changed files with 96 additions and 55 deletions
  1. +1
    -1
      src/main/org/apache/tools/ant/taskdefs/ExecuteOn.java
  2. +11
    -6
      src/main/org/apache/tools/ant/taskdefs/Expand.java
  3. +31
    -16
      src/main/org/apache/tools/ant/taskdefs/Touch.java
  4. +22
    -11
      src/main/org/apache/tools/ant/taskdefs/Tstamp.java
  5. +3
    -4
      src/main/org/apache/tools/ant/taskdefs/Untar.java
  6. +28
    -17
      src/main/org/apache/tools/ant/taskdefs/WaitFor.java

+ 1
- 1
src/main/org/apache/tools/ant/taskdefs/ExecuteOn.java View File

@@ -77,7 +77,7 @@ import java.io.IOException;
* *
* @since Ant 1.2 * @since Ant 1.2
* *
* @ant.task name="apply" category="control"
* @ant.task category="control" name="execon" name="apply"
*/ */
public class ExecuteOn extends ExecTask { public class ExecuteOn extends ExecTask {




+ 11
- 6
src/main/org/apache/tools/ant/taskdefs/Expand.java View File

@@ -78,6 +78,8 @@ import java.util.zip.ZipEntry;
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
* @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a> * @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a>
* *
* @since Ant 1.1
*
* @ant.task category="packaging" * @ant.task category="packaging"
* name="unzip" * name="unzip"
* name="unjar" * name="unjar"
@@ -101,7 +103,8 @@ public class Expand extends MatchingTask {
} }


if (source == null && filesets.size() == 0) { 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) { if (dest == null) {
@@ -151,14 +154,14 @@ public class Expand extends MatchingTask {


while ((ze = zis.getNextEntry()) != null) { while ((ze = zis.getNextEntry()) != null) {
extractFile(fileUtils, srcF, dir, zis, extractFile(fileUtils, srcF, dir, zis,
ze.getName(),
new Date(ze.getTime()),
ze.getName(), new Date(ze.getTime()),
ze.isDirectory()); ze.isDirectory());
} }


log("expand complete", Project.MSG_VERBOSE ); log("expand complete", Project.MSG_VERBOSE );
} catch (IOException ioe) { } catch (IOException ioe) {
throw new BuildException("Error while expanding " + srcF.getPath(), ioe);
throw new BuildException("Error while expanding " + srcF.getPath(),
ioe);
} finally { } finally {
if (zis != null) { if (zis != null) {
try { try {
@@ -183,7 +186,8 @@ public class Expand extends MatchingTask {
String[] incls = p.getIncludePatterns(project); String[] incls = p.getIncludePatterns(project);
if (incls != null) { if (incls != null) {
for (int w = 0; w < incls.length; w++) { for (int w = 0; w < incls.length; w++) {
boolean isIncl = DirectoryScanner.match(incls[w], name);
boolean isIncl =
DirectoryScanner.match(incls[w], name);
if (isIncl) { if (isIncl) {
included = true; included = true;
break; break;
@@ -193,7 +197,8 @@ public class Expand extends MatchingTask {
String[] excls = p.getExcludePatterns(project); String[] excls = p.getExcludePatterns(project);
if (excls != null) { if (excls != null) {
for (int w = 0; w < excls.length; w++) { for (int w = 0; w < excls.length; w++) {
boolean isExcl = DirectoryScanner.match(excls[w], name);
boolean isExcl =
DirectoryScanner.match(excls[w], name);
if (isExcl) { if (isExcl) {
included = false; included = false;
break; break;


+ 31
- 16
src/main/org/apache/tools/ant/taskdefs/Touch.java View File

@@ -85,6 +85,8 @@ import java.util.Vector;
* @author <a href="mailto:mj@servidium.com">Michael J. Sikorsky</a> * @author <a href="mailto:mj@servidium.com">Michael J. Sikorsky</a>
* @author <a href="mailto:shaw@servidium.com">Robert Shaw</a> * @author <a href="mailto:shaw@servidium.com">Robert Shaw</a>
* *
* @since Ant 1.1
*
* @ant.task category="filesystem" * @ant.task category="filesystem"
*/ */
public class Touch extends Task { 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 * 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) { public void setFile(File file) {
this.file = file; this.file = file;
@@ -132,31 +134,43 @@ public class Touch extends Task {
* Execute the touch operation. * Execute the touch operation.
*/ */
public void execute() throws BuildException { public void execute() throws BuildException {
long savedMillis = millis;

if (file == null && filesets.size() == 0) { if (file == null && filesets.size() == 0) {
throw 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()) { if (file != null && file.exists() && file.isDirectory()) {
throw new BuildException("Use a fileset to touch directories."); 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 { protected void touch(File file) throws BuildException {
if (!file.canWrite()) { 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) { if (Project.getJavaVersion() == Project.JAVA_1_1) {


+ 22
- 11
src/main/org/apache/tools/ant/taskdefs/Tstamp.java View File

@@ -79,7 +79,7 @@ import java.text.SimpleDateFormat;
* @author roxspring@yahoo.com * @author roxspring@yahoo.com
* @author Conor MacNeill * @author Conor MacNeill
* @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a> * @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a>
*
* @since Ant 1.1
* @ant.task category="utility" * @ant.task category="utility"
*/ */
public class Tstamp extends Task { public class Tstamp extends Task {
@@ -87,6 +87,9 @@ public class Tstamp extends Task {
private Vector customFormats = new Vector(); private Vector customFormats = new Vector();
private String prefix = ""; private String prefix = "";


/**
* @since Ant 1.5
*/
public void setPrefix(String prefix) { public void setPrefix(String prefix) {
this.prefix = prefix; this.prefix = prefix;
if (!this.prefix.endsWith(".")) { if (!this.prefix.endsWith(".")) {
@@ -162,7 +165,8 @@ public class Tstamp extends Task {
if (st.hasMoreElements()) { if (st.hasMoreElements()) {
variant = st.nextToken(); variant = st.nextToken();
if (st.hasMoreElements()) { 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) { 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 * @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) { public void setUnit(String unit) {
log("DEPRECATED - The setUnit(String) method has been deprecated." 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) public void execute(Project project, Date date, Location location)
{ {
if (propertyName == null) { if (propertyName == null) {
throw new BuildException("property attribute must be provided", location);
throw new BuildException("property attribute must be provided",
location);
} }


if (pattern == null) { if (pattern == null) {
throw new BuildException("pattern attribute must be provided", location);
throw new BuildException("pattern attribute must be provided",
location);
} }


SimpleDateFormat sdf; SimpleDateFormat sdf;
@@ -216,10 +224,13 @@ public class Tstamp extends Task {
sdf = new SimpleDateFormat(pattern); sdf = new SimpleDateFormat(pattern);
} }
else if (variant == null) { else if (variant == null) {
sdf = new SimpleDateFormat(pattern, new Locale(language, country));
sdf = new SimpleDateFormat(pattern,
new Locale(language, country));
} }
else { else {
sdf = new SimpleDateFormat(pattern, new Locale(language, country, variant));
sdf = new SimpleDateFormat(pattern,
new Locale(language, country,
variant));
} }
if (offset != 0) { if (offset != 0) {
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
@@ -260,7 +271,7 @@ public class Tstamp extends Task {


public Unit() { public Unit() {
calendarFields.put(MILLISECOND, calendarFields.put(MILLISECOND,
new Integer(Calendar.MILLISECOND));
new Integer(Calendar.MILLISECOND));
calendarFields.put(SECOND, new Integer(Calendar.SECOND)); calendarFields.put(SECOND, new Integer(Calendar.SECOND));
calendarFields.put(MINUTE, new Integer(Calendar.MINUTE)); calendarFields.put(MINUTE, new Integer(Calendar.MINUTE));
calendarFields.put(HOUR, new Integer(Calendar.HOUR_OF_DAY)); calendarFields.put(HOUR, new Integer(Calendar.HOUR_OF_DAY));


+ 3
- 4
src/main/org/apache/tools/ant/taskdefs/Untar.java View File

@@ -67,11 +67,11 @@ import java.io.IOException;
/** /**
* Untar a file. * Untar a file.
* *
* Heavily based on the Expand task.
*
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
* @author <a href="mailto:umagesh@rediffmail.com">Magesh Umasankar</a> * @author <a href="mailto:umagesh@rediffmail.com">Magesh Umasankar</a>
* *
* @since Ant 1.1
*
* @ant.task category="packaging" * @ant.task category="packaging"
*/ */
public class Untar extends Expand { public class Untar extends Expand {
@@ -86,8 +86,7 @@ public class Untar extends Expand {


while ((te = tis.getNextEntry()) != null) { while ((te = tis.getNextEntry()) != null) {
extractFile(fileUtils, srcF, dir, tis, extractFile(fileUtils, srcF, dir, tis,
te.getName(),
te.getModTime(), te.isDirectory());
te.getName(), te.getModTime(), te.isDirectory());
} }
log("expand complete", Project.MSG_VERBOSE ); log("expand complete", Project.MSG_VERBOSE );




+ 28
- 17
src/main/org/apache/tools/ant/taskdefs/WaitFor.java View File

@@ -83,6 +83,8 @@ import java.util.Hashtable;
* @author <a href="mailto:denis@network365.com">Denis Hennessy</a> * @author <a href="mailto:denis@network365.com">Denis Hennessy</a>
* @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a> * @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a>
* *
* @since Ant 1.5
*
* @ant.task category="control" * @ant.task category="control"
*/ */


@@ -134,30 +136,39 @@ public class WaitFor extends ConditionBase {
*/ */
public void execute() throws BuildException { public void execute() throws BuildException {
if (countConditions() > 1) { if (countConditions() > 1) {
throw new BuildException("You must not nest more than one condition into <waitfor>");
throw new BuildException("You must not nest more than one "
+ "condition into <waitfor>");
} }
if (countConditions() < 1) { if (countConditions() < 1) {
throw new BuildException("You must nest a condition into <waitfor>");
throw new BuildException("You must nest a condition into "
+ "<waitfor>");
} }
Condition c = (Condition) getConditions().nextElement(); 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;
} }
} }




Loading…
Cancel
Save