Browse Source

deal with read-only dest files in echo and concat.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@943068 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 15 years ago
parent
commit
c83bf3257f
6 changed files with 85 additions and 13 deletions
  1. +7
    -2
      WHATSNEW
  2. +18
    -1
      docs/manual/CoreTasks/concat.html
  3. +6
    -0
      docs/manual/CoreTasks/echo.html
  4. +1
    -1
      src/etc/testcases/taskdefs/concat.xml
  5. +35
    -6
      src/main/org/apache/tools/ant/taskdefs/Concat.java
  6. +18
    -3
      src/main/org/apache/tools/ant/taskdefs/Echo.java

+ 7
- 2
WHATSNEW View File

@@ -9,8 +9,9 @@ Changes that could break older environments:
would only do so if under special circumstances. Ant 1.8.2 now
consistently won't replace a read-only file by default. The same is
true for a number of other tasks.
The <copy> and <move> task now have a new force attribute that can
be used to make the task overwrite read-only destinations.
The <copy>, <move> and <echo> tasks now have a new force attribute
and <concat> has a new forceReadonly attribute that can be used to
make the task overwrite read-only destinations.
Bugzilla Report 49261.

Fixed bugs:
@@ -19,6 +20,10 @@ Fixed bugs:
Other changes:
--------------

* <concat>'s force attribute has been deprecated in favor of a new
overwrite attribute that is consistent with <copy>'s attribute
names.

Changes from Ant 1.8.0 TO Ant 1.8.1
===================================



+ 18
- 1
docs/manual/CoreTasks/concat.html View File

@@ -83,12 +83,29 @@ Resource Collection</a>s are used to
<td valign="top">
Specifies whether or not the file specified by 'destfile'
should be written to even if it is newer than all source files.
<em>since Ant 1.6</em>.
<strong>deprecated, use the overwrite attribute instead</strong>
Defaults to &quot;yes&quot;.
</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">overwrite</td>
<td valign="top">
Specifies whether or not the file specified by 'destfile'
should be written to even if it is newer than all source files.
<em>since Ant 1.8.2</em>.
Defaults to &quot;yes&quot;.
</td>
<td valign="top" align="center">No</td>
</tr>

<tr>
<td valign="top">forceReadOnly</td>
<td valign="top">Overwrite read-only destination
files. <em>since Ant 1.8.2</em></td>
<td valign="top" align="center">No; defaults to false.</td>
</tr>

<tr>
<td valign="top">encoding</td>
<td valign="top">


+ 6
- 0
docs/manual/CoreTasks/echo.html View File

@@ -79,6 +79,12 @@ ignored</p>
<td valign="top">encoding to use, default is ""; the local system encoding. <em>since Ant 1.7</em></td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">force</td>
<td valign="top">Overwrite read-only destination
files. <em>since Ant 1.8.2</em></td>
<td valign="top" align="center">No; defaults to false.</td>
</tr>
</table>

<h3>Examples</h3>


+ 1
- 1
src/etc/testcases/taskdefs/concat.xml View File

@@ -110,7 +110,7 @@
<touch file="${tmp.file.2}"/>
<!-- concat.xml is now older than tmp.file.2
so the following should not do anything -->
<concat destfile="${tmp.file.2}" force="false">
<concat destfile="${tmp.file.2}" overwrite="false">
<path path="concat.xml"/>
</concat>
</target>


+ 35
- 6
src/main/org/apache/tools/ant/taskdefs/Concat.java View File

@@ -471,6 +471,8 @@ public class Concat extends Task implements ResourceCollection {
private Vector filterChains;
/** ignore dates on input files */
private boolean forceOverwrite = true;
/** overwrite read-only files */
private boolean force = false;
/** String to place at the start of the concatented stream */
private TextElement footer;
/** String to place at the end of the concatented stream */
@@ -526,6 +528,7 @@ public class Concat extends Task implements ResourceCollection {
eolString = StringUtils.LINE_SEP;
rc = null;
ignoreEmpty = true;
force = false;
}

// Attribute setters.
@@ -581,14 +584,38 @@ public class Concat extends Task implements ResourceCollection {

/**
* Force overwrite existing destination file
* @param force if true always overwrite, otherwise only overwrite
* if the output file is older any of the input files.
* @param forceOverwrite if true always overwrite, otherwise only
* overwrite if the output file is older any of the
* input files.
* @since Ant 1.6
* @deprecated use #setOverwrite instead
*/
public void setForce(boolean force) {
public void setForce(boolean forceOverwrite) {
this.forceOverwrite = force;
}

/**
* Force overwrite existing destination file
* @param forceOverwrite if true always overwrite, otherwise only
* overwrite if the output file is older any of the
* input files.
* @since Ant 1.8.2
*/
public void setOverwrite(boolean forceOverwrite) {
setForce(forceOverwrite);
}

/**
* Whether read-only destinations will be overwritten.
*
* <p>Defaults to false</p>
*
* @since Ant 1.8.2
*/
public void setForceReadOnly(boolean f) {
force = f;
}

/**
* Sets the behavior when no source resource files are available. If set to
* <code>false</code> the destination file will always be created.
@@ -761,9 +788,11 @@ public class Concat extends Task implements ResourceCollection {
}
try {
//most of these are defaulted because the concat-as-a-resource code hijacks a lot:
ResourceUtils.copyResource(new ConcatResource(c), dest == null ? new LogOutputResource(
this, Project.MSG_WARN) : dest, null, null, true, false, append, null, null,
getProject());
ResourceUtils.copyResource(new ConcatResource(c), dest == null
? new LogOutputResource(this, Project.MSG_WARN)
: dest,
null, null, true, false, append, null,
null, getProject(), force);
} catch (IOException e) {
throw new BuildException("error concatenating content to " + dest, e);
}


+ 18
- 3
src/main/org/apache/tools/ant/taskdefs/Echo.java View File

@@ -47,6 +47,7 @@ public class Echo extends Task {
protected boolean append = false;
/** encoding; set to null or empty means 'default' */
private String encoding = "";
private boolean force = false;

// by default, messages are always displayed
protected int logLevel = Project.MSG_WARN;
@@ -63,9 +64,12 @@ public class Echo extends Task {
final String msg = "".equals(message) ? StringUtils.LINE_SEP : message;
try {
ResourceUtils
.copyResource(new StringResource(msg), output == null ? new LogOutputResource(
this, logLevel) : output, null, null, false, false, append, null, ""
.equals(encoding) ? null : encoding, getProject());
.copyResource(new StringResource(msg), output == null
? new LogOutputResource(this, logLevel)
: output,
null, null, false, false, append, null,
"".equals(encoding) ? null : encoding,
getProject(), force);
} catch (IOException ioe) {
throw new BuildException(ioe, getLocation());
}
@@ -147,6 +151,17 @@ public class Echo extends Task {
this.encoding = encoding;
}

/**
* Whether read-only destinations will be overwritten.
*
* <p>Defaults to false</p>
*
* @since Ant 1.8.2
*/
public void setForce(boolean f) {
force = f;
}

/**
* The enumerated values for the level attribute.
*/


Loading…
Cancel
Save