git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@722967 13f79535-47bb-0310-9956-ffa450edef68master
@@ -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 | |||
============================================= | |||
@@ -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> | |||
@@ -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."); | |||
} | |||
} | |||
} | |||
} |
@@ -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" is oldest target file" | |||
level="verbose"/--> | |||
<au:assertLogContains text="newer.tmp" 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" is oldest target file" | |||
level="verbose"/--> | |||
<au:assertLogContains text="sourceset_2.tmp" 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> |