Browse Source

some assertions on dependset's logging

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@722967 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 16 years ago
parent
commit
163e6b921c
4 changed files with 83 additions and 7 deletions
  1. +4
    -0
      WHATSNEW
  2. +13
    -3
      docs/manual/CoreTasks/dependset.html
  3. +44
    -4
      src/main/org/apache/tools/ant/taskdefs/DependSet.java
  4. +22
    -0
      src/tests/antunit/taskdefs/dependset-test.xml

+ 4
- 0
WHATSNEW View File

@@ -586,6 +586,10 @@ Other changes:
as nested element of <zip> and friends.
Bugzilla Report 46257.

* <dependset> has a new verbose attribute that makes the task list
all deleted targets and give a hint as to why it deleted them.
Bugzilla Report 13681.

Changes from Ant 1.7.0 TO Ant 1.7.1
=============================================



+ 13
- 3
docs/manual/CoreTasks/dependset.html View File

@@ -59,9 +59,19 @@ well as other stylesheets imported by the main stylesheet.

<h3>Parameters</h3>

<p>
(none)
</p>
<table border="1" cellpadding="2" cellspacing="0">
<tr>
<td valign="top"><b>Attribute</b></td>
<td valign="top"><b>Description</b></td>
<td valign="top" align="center"><b>Required</b></td>
</tr>
<tr>
<td valign="top">verbose</td>
<td valign="top">Makes the task list all deleted targets files
and the reason why they get deleted.</td>
<td align="center" valign="top" rowspan="2">No</td>
</tr>
</table>

<h3>Parameters Specified as Nested Elements</h3>



+ 44
- 4
src/main/org/apache/tools/ant/taskdefs/DependSet.java View File

@@ -19,6 +19,7 @@
package org.apache.tools.ant.taskdefs;

import java.io.File;
import java.util.Date;
import java.util.Iterator;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
@@ -119,6 +120,8 @@ public class DependSet extends MatchingTask {
private Union sources = null;
private Path targets = null;

private boolean verbose;

/**
* Create a nested sources element.
* @return a Union instance.
@@ -169,6 +172,19 @@ public class DependSet extends MatchingTask {
createTargets().add(fl);
}

/**
* In verbose mode missing targets and sources as well as the
* modification times of the newest source and latest target will
* be logged as info.
*
* <p>All deleted files will be logged as well.</p>
*
* @since Ant 1.8.0
*/
public void setVerbose(boolean b) {
verbose = b;
}

/**
* Execute the task.
* @throws BuildException if errors occur.
@@ -185,6 +201,12 @@ public class DependSet extends MatchingTask {
//no sources = nothing to compare; no targets = nothing to delete:
if (sources.size() > 0 && targets.size() > 0 && !uptodate(sources, targets)) {
log("Deleting all target files.", Project.MSG_VERBOSE);
if (verbose) {
String[] t = targets.list();
for (int i = 0; i < t.length; i++) {
log("Deleting " + t[i]);
}
}
Delete delete = new Delete();
delete.bindToOwner(this);
delete.add(targets);
@@ -202,23 +224,27 @@ public class DependSet extends MatchingTask {
datesel.setGranularity(0);
logFuture(targets, datesel);

int neTargets = new NonExistent(targets).size();
NonExistent missingTargets = new NonExistent(targets);
int neTargets = missingTargets.size();
if (neTargets > 0) {
log(neTargets + " nonexistent targets", Project.MSG_VERBOSE);
logMissing(missingTargets, "target");
return false;
}
Resource oldestTarget = getOldest(targets);
log(oldestTarget + " is oldest target file", Project.MSG_VERBOSE);
logWithModificationTime(oldestTarget, "oldest target file");

logFuture(sources, datesel);

int neSources = new NonExistent(sources).size();
NonExistent missingSources = new NonExistent(sources);
int neSources = missingSources.size();
if (neSources > 0) {
log(neSources + " nonexistent sources", Project.MSG_VERBOSE);
logMissing(missingSources, "source");
return false;
}
Resource newestSource = (Resource) getNewest(sources);
log(newestSource.toLongString() + " is newest source", Project.MSG_VERBOSE);
logWithModificationTime(newestSource, "newest source");
return oldestTarget.getLastModified() >= newestSource.getLastModified();
}

@@ -255,4 +281,18 @@ public class DependSet extends MatchingTask {
return getXest(rc, DATE);
}

private void logWithModificationTime(Resource r, String what) {
log(r.toLongString() + " is " + what + ", modified at "
+ new Date(r.getLastModified()),
verbose ? Project.MSG_INFO : Project.MSG_VERBOSE);
}

private void logMissing(ResourceCollection missing, String what) {
if (verbose) {
for (Iterator i = missing.iterator(); i.hasNext(); ) {
Resource r = (Resource) i.next();
log("Expected " + what + " " + r.toLongString() + " is missing.");
}
}
}
}

+ 22
- 0
src/tests/antunit/taskdefs/dependset-test.xml View File

@@ -54,6 +54,8 @@
<srcfilelist dir="${input}" files="test4.tmp" />
<targetfileset id="targetfs" dir="${output}" includes="i-do-not-exist" />
</dependset>
<au:assertLogDoesntContain text="Deleting all target files."
level="verbose"/>
</target>

<target name="testMoreRecentSourceFile" depends="setUp">
@@ -64,6 +66,12 @@
<srcfilelist dir="${input}" files="newer.tmp" />
<targetfilelist dir="${output}" files="older.tmp" />
</dependset>
<!--au:assertLogContains text="older.tmp&quot; is oldest target file"
level="verbose"/-->
<au:assertLogContains text="newer.tmp&quot; is newest source"
level="verbose"/>
<au:assertLogContains text="Deleting all target files."
level="verbose"/>
<au:assertFileDoesntExist file="${output}/older.tmp"/>
</target>

@@ -82,6 +90,12 @@
<filelist dir="${output}/" files="targetset_1.tmp,targetset_2.tmp" />
</targets>
</dependset>
<!--au:assertLogContains text="targetset_1&quot; is oldest target file"
level="verbose"/-->
<au:assertLogContains text="sourceset_2.tmp&quot; is newest source"
level="verbose"/>
<au:assertLogContains text="Deleting all target files."
level="verbose"/>
<au:assertFileDoesntExist file="${output}/targetset_1.tmp" />
<au:assertFileDoesntExist file="${output}/targetset_2.tmp" />
</target>
@@ -96,6 +110,10 @@
<filelist dir="${output}" files="older.tmp" />
</targets>
</dependset>
<au:assertLogContains text="1 nonexistent sources"
level="verbose"/>
<au:assertLogContains text="Deleting all target files."
level="verbose"/>
<au:assertFileDoesntExist file="${output}/older.tmp" />
</target>

@@ -110,6 +128,8 @@
<filelist dir="${output}" files="older.tmp" />
</targets>
</dependset>
<au:assertLogDoesntContain text="Deleting all target files."
level="verbose"/>
<au:assertFileExists file="${output}/older.tmp" />
</target>

@@ -122,6 +142,8 @@
<srcfileset dir="." includes="test9.tmp" />
<targetfileset dir="${output}/test9dir" />
</dependset>
<au:assertLogDoesntContain text="Deleting all target files."
level="verbose"/>
</target>

</project>

Loading…
Cancel
Save