Browse Source

allow control over whether <concat> creates a file when there are no resources. Submitted by Mark Salter. PR 46010.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@705626 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 16 years ago
parent
commit
ae202f6ff1
6 changed files with 82 additions and 4 deletions
  1. +1
    -0
      CONTRIBUTORS
  2. +6
    -0
      WHATSNEW
  3. +5
    -1
      contributors.xml
  4. +13
    -2
      docs/manual/CoreTasks/concat.html
  5. +16
    -1
      src/main/org/apache/tools/ant/taskdefs/Concat.java
  6. +41
    -0
      src/tests/antunit/taskdefs/concat-test.xml

+ 1
- 0
CONTRIBUTORS View File

@@ -173,6 +173,7 @@ Marcus B&ouml;rger
Mario Frasca
Mariusz Nowostawski
Mark Hecker
Mark Salter
Mark R. Diggory
Martijn Kruithof
Martin Landers


+ 6
- 0
WHATSNEW View File

@@ -463,6 +463,12 @@ Other changes:
* <cvs> and friends now support modules with spaces in their names
via nested <module> elements.

* A new attribute "ignoreEmpty" controls how <concat> deals when
there are no resources to concatenate. If it is set to false, the
destination file will be created regardless, which reinstates the
behavior of Ant 1.7.0.
Bugzilla Report 46010.

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



+ 5
- 1
contributors.xml View File

@@ -704,7 +704,7 @@
</name>
<name>
<first>Marcus</first>
<last>B&amp;ouml;rger</last>
<last>Börger</last>
</name>
<name>
<first>Mario</first>
@@ -718,6 +718,10 @@
<first>Mark</first>
<last>Hecker</last>
</name>
<name>
<first>Mark</first>
<last>Salter</last>
</name>
<name>
<first>Mark</first>
<middle>R.</middle>


+ 13
- 2
docs/manual/CoreTasks/concat.html View File

@@ -32,7 +32,8 @@
Concatenates one or more
<a href="../CoreTypes/resources.html">resource</a>s
to a single file or to the console. The destination
file will be created if it does not exist.
file will be created if it does not exist unless the resource
list is empty and ignoreempty is true.
</p>

<p><strong>Since Ant 1.7.1</strong>, this task can be used as a
@@ -158,7 +159,17 @@ Resource Collection</a>s are used to
set, and the task cannot used nested text.
Also the attributes encoding, outputencoding, filelastline
cannot be used.
The default is false.
The default is &quot;false&quot;.
</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">ignoreempty</td>
<td valign="top">
<em>Since Ant 1.8.0</em>
Specifies whether or not the file specified by 'destfile'
should be created if the source resource list is
empty. Defaults to &quot;true&quot;.
</td>
<td valign="top" align="center">No</td>
</tr>


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

@@ -479,6 +479,9 @@ public class Concat extends Task implements ResourceCollection {
private String eolString;
/** outputwriter */
private Writer outputWriter = null;
/** whether to not create destinationfile if no source files are
* available */
private boolean ignoreEmpty = true;

private ReaderFactory resourceReaderFactory = new ReaderFactory() {
public Reader getReader(Object o) throws IOException {
@@ -520,6 +523,7 @@ public class Concat extends Task implements ResourceCollection {
textBuffer = null;
eolString = StringUtils.LINE_SEP;
rc = null;
ignoreEmpty = true;
}

// Attribute setters.
@@ -574,6 +578,17 @@ public class Concat extends Task implements ResourceCollection {
this.forceOverwrite = force;
}

/**
* Sets the behavior when no source resource files are available. If set to
* <code>false</code> the destination file will always be created.
* Defaults to <code>true</code>.
* @param ignoreEmpty if false honour destinationfile creation.
* @since Ant 1.8.0
*/
public void setIgnoreEmpty(boolean ignoreEmpty) {
this.ignoreEmpty = ignoreEmpty;
}

// Nested element creators.

/**
@@ -733,7 +748,7 @@ public class Concat extends Task implements ResourceCollection {
log(destinationFile + " is up-to-date.", Project.MSG_VERBOSE);
return;
}
if (c.size() == 0) {
if (c.size() == 0 && ignoreEmpty) {
return;
}
OutputStream out;


+ 41
- 0
src/tests/antunit/taskdefs/concat-test.xml View File

@@ -74,4 +74,45 @@
</au:assertTrue>
</target>

<target name="testIgnoreEmptyFalseFileIsCreated">
<mkdir dir="${input}"/>
<mkdir dir="${output}"/>
<concat destfile="${output}/TESTDEST" append="true" ignoreEmpty="false">
<filelist dir="${input}" files="thisfiledoesnotexist"/>
</concat>
<au:assertFileExists file="${output}/TESTDEST"/>
</target>
<target name="testIgnoreEmptyTrueFileIsNotCreated">
<mkdir dir="${input}"/>
<mkdir dir="${output}"/>
<concat destfile="${output}/TESTDEST" append="true" ignoreEmpty="true">
<filelist dir="${input}" files="thisfiledoesnotexist"/>
</concat>
<au:assertFileDoesntExist file="${output}/TESTDEST"/>
</target>
<target name="testIgnoreEmptyFalseFileIsCreatedIncludesHeader">
<mkdir dir="${input}"/>
<mkdir dir="${output}"/>
<concat destfile="${output}/TESTDEST" ignoreEmpty="false">
<filelist dir="${input}" files="thisfiledoesnotexist"/>
<header filtering="false" trim="yes">
header
</header>
</concat>
<au:assertFileExists file="${output}/TESTDEST"/>
<au:assertResourceContains resource="${output}/TESTDEST" value="header"/>
</target>
<target name="testIgnoreEmptyFalseFileIsCreatedIncludesFooter">
<mkdir dir="${input}"/>
<mkdir dir="${output}"/>
<concat destfile="${output}/TESTDEST" ignoreEmpty="false">
<filelist dir="${input}" files="thisfiledoesnotexist"/>
<footer filtering="no">footer</footer>
</concat>
<au:assertFileExists file="${output}/TESTDEST"/>
<au:assertResourceContains resource="${output}/TESTDEST" value="footer"/>
</target>
</project>

Loading…
Cancel
Save