Browse Source

Don't add newlines in <concat> that haven't been in the files

originally - no matter what encoding.

PR: 12511


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@273553 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 22 years ago
parent
commit
de06c1b597
6 changed files with 46 additions and 17 deletions
  1. +4
    -0
      WHATSNEW
  2. +1
    -0
      src/etc/testcases/taskdefs/concat-input/A
  3. +1
    -0
      src/etc/testcases/taskdefs/concat-input/B
  4. +12
    -0
      src/etc/testcases/taskdefs/concat.xml
  5. +21
    -17
      src/main/org/apache/tools/ant/taskdefs/Concat.java
  6. +7
    -0
      src/testcases/org/apache/tools/ant/taskdefs/ConcatTest.java

+ 4
- 0
WHATSNEW View File

@@ -55,6 +55,10 @@ Fixed bugs:

* <cvschangelog> could miss today's changes.

* entity includes would cause exceptions if path names included spaces.

* <concat> could append newline characters between concatenated files.

Other changes:
--------------
* <setproxy> lets you set the username and password for proxies that want authentication


+ 1
- 0
src/etc/testcases/taskdefs/concat-input/A View File

@@ -0,0 +1 @@
a

+ 1
- 0
src/etc/testcases/taskdefs/concat-input/B View File

@@ -0,0 +1 @@
b

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

@@ -40,4 +40,16 @@
if="TESTDEST.was.created"/>
</target>

<target name="testConcatNoNewline">
<concat>
<fileset dir="concat-input"/>
</concat>
</target>

<target name="testConcatNoNewlineEncoding">
<concat encoding="ASCII">
<fileset dir="concat-input"/>
</concat>
</target>

</project>

+ 21
- 17
src/main/org/apache/tools/ant/taskdefs/Concat.java View File

@@ -63,8 +63,8 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StringReader;
import java.io.Writer;
import java.util.Enumeration;
import java.util.Vector;
import org.apache.tools.ant.BuildException;
@@ -360,7 +360,7 @@ public class Concat extends Task {
}

is = new FileInputStream(input[i]);
byte[] buffer = new byte[8096];
byte[] buffer = new byte[8192];
while (true) {
int bytesRead = is.read(buffer);
if (bytesRead == -1) { // EOF
@@ -390,24 +390,22 @@ public class Concat extends Task {
}
}

} else { // user specified encoding, assume line oriented input
} else { // user specified encoding

PrintWriter out = null;
Writer out = null;
BufferedReader in = null;

try {
if (destinationFile == null) {
// Log using WARN so it displays in 'quiet' mode.
out = new PrintWriter(
new OutputStreamWriter(
new LogOutputStream(this, Project.MSG_WARN)));
out = new OutputStreamWriter(
new LogOutputStream(this, Project.MSG_WARN));
} else {
out = new PrintWriter(
new OutputStreamWriter(
new FileOutputStream(destinationFile
.getAbsolutePath(),
append),
encoding));
out = new OutputStreamWriter(
new FileOutputStream(destinationFile
.getAbsolutePath(),
append),
encoding);
// This flag should only be recognized for the first
// file. In the context of a single 'cat', we always
@@ -421,11 +419,17 @@ public class Concat extends Task {
encoding));

String line;
while ((line = in.readLine()) != null) {
// Log the line, using WARN so it displays in
// 'quiet' mode.
out.println(line);
char[] buffer = new char[4096];
while (true) {
int charsRead = in.read(buffer);
if (charsRead == -1) { // EOF
break;
}
// Write the read data.
out.write(buffer, 0, charsRead);
}
out.flush();
in.close();
in = null;
}


+ 7
- 0
src/testcases/org/apache/tools/ant/taskdefs/ConcatTest.java View File

@@ -166,4 +166,11 @@ public class ConcatTest
"src/etc/testcases/taskdefs/thisfiledoesnotexist does not exist.");
}

public void testConcatNoNewline() {
expectLog("testConcatNoNewline", "ab");
}

public void testConcatNoNewlineEncoding() {
expectLog("testConcatNoNewlineEncoding", "ab");
}
}

Loading…
Cancel
Save