You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by bo...@apache.org on 2001/07/27 08:52:51 UTC
cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs Expand.java Untar.java
bodewig 01/07/26 23:52:51
Modified: . WHATSNEW
docs/manual/CoreTasks untar.html unzip.html
src/main/org/apache/tools/ant/taskdefs Expand.java
Untar.java
Log:
Add overwrite attribute to unjar/war/zip and untar - if set to false,
files newer than the entries in the archive will not be replaced.
Default is true for backwards compatibility.
PR: 1667
Revision Changes Path
1.133 +4 -0 jakarta-ant/WHATSNEW
Index: WHATSNEW
===================================================================
RCS file: /home/cvs/jakarta-ant/WHATSNEW,v
retrieving revision 1.132
retrieving revision 1.133
diff -u -r1.132 -r1.133
--- WHATSNEW 2001/07/18 08:06:35 1.132
+++ WHATSNEW 2001/07/27 06:52:50 1.133
@@ -127,6 +127,10 @@
* <taskdef> can now define several tasks at once, reading the
name/classname pairs from a property file or resource.
+* <unzip/unjar/unwar> and <untar> now have an overwrite attribute that
+ defaults to true. If set to false, files that are newer than the
+ files in the archive will not be replaced.
+
Fixed bugs:
-----------
1.3 +7 -0 jakarta-ant/docs/manual/CoreTasks/untar.html
Index: untar.html
===================================================================
RCS file: /home/cvs/jakarta-ant/docs/manual/CoreTasks/untar.html,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- untar.html 2001/02/13 12:31:52 1.2
+++ untar.html 2001/07/27 06:52:50 1.3
@@ -35,6 +35,13 @@
<td valign="top">directory where to store the expanded files.</td>
<td align="center" valign="top">Yes</td>
</tr>
+ <tr>
+ <td valign="top">overwrite</td>
+ <td valign="top"> Overwrite files, even if they are newer than the
+ corresponding entries in the archive (true or false, default is
+ true).</td>
+ <td align="center" valign="top">No</td>
+ </tr>
</table>
<h3>Examples</h3>
<blockquote>
1.3 +7 -0 jakarta-ant/docs/manual/CoreTasks/unzip.html
Index: unzip.html
===================================================================
RCS file: /home/cvs/jakarta-ant/docs/manual/CoreTasks/unzip.html,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- unzip.html 2001/02/13 12:31:52 1.2
+++ unzip.html 2001/07/27 06:52:50 1.3
@@ -30,6 +30,13 @@
<td valign="top">directory where to store the expanded files.</td>
<td align="center" valign="top">Yes</td>
</tr>
+ <tr>
+ <td valign="top">overwrite</td>
+ <td valign="top">Overwrite files, even if they are newer than the
+ corresponding entries in the archive (true or false, default is
+ true).</td>
+ <td align="center" valign="top">No</td>
+ </tr>
</table>
<h3>Examples</h3>
<blockquote>
1.15 +20 -3 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Expand.java
Index: Expand.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Expand.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- Expand.java 2001/05/23 16:57:35 1.14
+++ Expand.java 2001/07/27 06:52:51 1.15
@@ -66,6 +66,8 @@
public class Expand extends MatchingTask {
private File dest; // req
private File source; // req
+
+ private boolean overwrite = true;
/**
* Do the work.
@@ -104,8 +106,6 @@
else {
expandFile(touch, source, dest);
}
-
-
}
private void expandFile(Touch touch, File srcF, File dir) {
@@ -119,7 +119,15 @@
while ((ze = zis.getNextEntry()) != null) {
File f = new File(dir, project.translatePath(ze.getName()));
try {
- log("expand-file " + ze.getName() , Project.MSG_VERBOSE );
+ if (!overwrite && f.exists()
+ && f.lastModified() >= ze.getTime()) {
+ log("Skipping " + f + " as it is up-to-date",
+ Project.MSG_DEBUG);
+ continue;
+ }
+
+ log("expanding " + ze.getName() + " to "+ f,
+ Project.MSG_VERBOSE);
// create intermediary directories - sometimes zip don't add them
File dirF=new File(f.getParent());
dirF.mkdirs();
@@ -179,4 +187,13 @@
public void setSrc(File s) {
this.source = s;
}
+
+ /**
+ * Should we overwrite files in dest, even if they are newer than
+ * the corresponding entries in the archive?
+ */
+ public void setOverwrite(boolean b) {
+ overwrite = b;
+ }
+
}
1.13 +20 -2 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Untar.java
Index: Untar.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Untar.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- Untar.java 2001/07/07 13:51:11 1.12
+++ Untar.java 2001/07/27 06:52:51 1.13
@@ -69,6 +69,8 @@
private File dest; // req
private File source; // req
+ private boolean overwrite = true;
+
/**
* Do the work.
*
@@ -105,8 +107,15 @@
while ((te = tis.getNextEntry()) != null) {
try {
File f = new File(dir, project.translatePath(te.getName()));
- log("expand-file " + te.getName(), Project.MSG_VERBOSE );
- // create intermediary directories - sometimes tar don't add them
+ if (!overwrite && f.exists()
+ && f.lastModified() >= te.getModTime().getTime()) {
+ log("Skipping " + f + " as it is up-to-date",
+ Project.MSG_DEBUG);
+ continue;
+ }
+
+ log("expanding " + te.getName() + " to "+ f,
+ Project.MSG_VERBOSE);
File dirF=new File(f.getParent());
dirF.mkdirs();
@@ -166,4 +175,13 @@
public void setSrc(File s) {
this.source = s;
}
+
+ /**
+ * Should we overwrite files in dest, even if they are newer than
+ * the corresponding entries in the archive?
+ */
+ public void setOverwrite(boolean b) {
+ overwrite = b;
+ }
+
}