Author: bodewig
Date: Tue May 6 20:11:49 2014
New Revision: 1592860
URL: http://svn.apache.org/r1592860
Log:
PR 56470 - merge messages in logContent only when asked to
Modified:
ant/antlibs/antunit/trunk/docs/assertions.html
ant/antlibs/antunit/trunk/docs/logcontent.html
ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/LogContains.java
ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/LogContent.java
ant/antlibs/antunit/trunk/src/tests/junit/org/apache/ant/antunit/LogContentTest.java
Modified: ant/antlibs/antunit/trunk/docs/assertions.html
URL:
http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/docs/assertions.html?rev=1592860&r1=1592859&r2=1592860&view=diff
==============================================================================
--- ant/antlibs/antunit/trunk/docs/assertions.html (original)
+++ ant/antlibs/antunit/trunk/docs/assertions.html Tue May 6 20:11:49 2014
@@ -921,7 +921,8 @@
<tr>
<td valign="top">mergeLines</td>
<td valign="top">Whether to merge messages into a single
- line or split them into multiple lines.</td>
+ line or split them into multiple lines. <em>since AntUnit
+ 1.3</em></td>
<td valign="top" align="center">No, defaults
to <code>true</code></td>
</tr>
@@ -954,7 +955,8 @@
<tr>
<td valign="top">mergeLines</td>
<td valign="top">Whether to merge messages into a single
- line or split them into multiple lines.</td>
+ line or split them into multiple lines. <em>since AntUnit
+ 1.3</em></td>
<td valign="top" align="center">No, defaults
to <code>true</code></td>
</tr>
Modified: ant/antlibs/antunit/trunk/docs/logcontent.html
URL:
http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/docs/logcontent.html?rev=1592860&r1=1592859&r2=1592860&view=diff
==============================================================================
--- ant/antlibs/antunit/trunk/docs/logcontent.html (original)
+++ ant/antlibs/antunit/trunk/docs/logcontent.html Tue May 6 20:11:49 2014
@@ -49,6 +49,14 @@ under the License.
Defaults to "info".</td>
<td align="center">No.</td>
</tr>
+ <tr>
+ <td valign="top">mergeLines</td>
+ <td valign="top">Whether to merge messages into a single line
+ or split them into multiple lines. <em>since AntUnit
+ 1.3</em></td>
+ <td valign="top" align="center">No, defaults
+ to <code>true</code></td>
+ </tr>
</table>
</body>
</html>
Modified:
ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/LogContains.java
URL:
http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/LogContains.java?rev=1592860&r1=1592859&r2=1592860&view=diff
==============================================================================
--- ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/LogContains.java
(original)
+++ ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/LogContains.java
Tue May 6 20:11:49 2014
@@ -56,6 +56,7 @@ public class LogContains extends Project
/**
* Whether to merge messages into a single line or split them into
* multiple lines.
+ * @since AntUnit 1.3
*/
public void setMergeLines(boolean b) {
mergeLines = b;
Modified:
ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/LogContent.java
URL:
http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/LogContent.java?rev=1592860&r1=1592859&r2=1592860&view=diff
==============================================================================
--- ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/LogContent.java
(original)
+++ ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/LogContent.java
Tue May 6 20:11:49 2014
@@ -34,12 +34,13 @@ import org.apache.tools.ant.types.Resour
public class LogContent extends Resource {
private LogLevel level;
+ private boolean mergeLines;
/**
* Create a new LogContent resource.
*/
public LogContent() {
- setLevel(LogLevel.INFO);
+ this(null, LogLevel.INFO);
}
/**
@@ -49,19 +50,42 @@ public class LogContent extends Resource
* @param level the LogLevel.
*/
public LogContent(Project p, LogLevel level) {
+ this(p, level, true);
+ }
+
+ /**
+ * Create a new LogContent resource, specifying Project and log level.
+ * This constructor is provided primarily for convenience during
+ * programmatic usage.
+ * @param level the LogLevel.
+ * @param mergeLines whether to merge messages into a single line
+ * or split them into multiple lines
+ * @since AntUnit 1.3
+ */
+ public LogContent(Project p, LogLevel level, boolean mergeLines) {
setProject(p);
setLevel(level);
+ setMergeLines(mergeLines);
}
/**
* Set the desired log level.
* @param level a LogLevel enumerated attribute.
*/
- public void setLevel(LogLevel level) {
+ public final void setLevel(LogLevel level) {
this.level = level;
setName(level.getValue());
}
+ /**
+ * Whether to merge messages into a single line or split them into
+ * multiple lines.
+ * @since AntUnit 1.3
+ */
+ public final void setMergeLines(boolean b) {
+ mergeLines = b;
+ }
+
//inherit doc
public InputStream getInputStream() throws IOException {
if (isReference()) {
@@ -101,19 +125,19 @@ public class LogContent extends Resource
String log = null;
switch (level.getLevel()) {
case Project.MSG_ERR:
- log = lc.getErrLog();
+ log = lc.getErrLog(mergeLines);
break;
case Project.MSG_WARN:
- log = lc.getWarnLog();
+ log = lc.getWarnLog(mergeLines);
break;
case Project.MSG_INFO:
- log = lc.getInfoLog();
+ log = lc.getInfoLog(mergeLines);
break;
case Project.MSG_VERBOSE:
- log = lc.getVerboseLog();
+ log = lc.getVerboseLog(mergeLines);
break;
case Project.MSG_DEBUG:
- log = lc.getDebugLog();
+ log = lc.getDebugLog(mergeLines);
break;
default:
throw new IllegalStateException("how possible?");
Modified:
ant/antlibs/antunit/trunk/src/tests/junit/org/apache/ant/antunit/LogContentTest.java
URL:
http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/src/tests/junit/org/apache/ant/antunit/LogContentTest.java?rev=1592860&r1=1592859&r2=1592860&view=diff
==============================================================================
---
ant/antlibs/antunit/trunk/src/tests/junit/org/apache/ant/antunit/LogContentTest.java
(original)
+++
ant/antlibs/antunit/trunk/src/tests/junit/org/apache/ant/antunit/LogContentTest.java
Tue May 6 20:11:49 2014
@@ -26,6 +26,7 @@ import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.LogLevel;
import org.apache.tools.ant.types.resources.StringResource;
import org.apache.tools.ant.util.ResourceUtils;
+import org.apache.tools.ant.util.StringUtils;
import junit.framework.Assert;
import junit.framework.TestCase;
@@ -70,6 +71,60 @@ public class LogContentTest extends Test
Project.MSG_DEBUG);
}
+ public void testWithoutMerge() throws IOException {
+ Project p = new Project();
+ LogCapturer c = new LogCapturer(p);
+
+ for (int i = 0; i < 2; i++) {
+ BuildEvent be = new BuildEvent(p);
+ be.setMessage(String.valueOf(i), 0);
+ c.messageLogged(be);
+ }
+
+ LogContent content = new LogContent(p, LogLevel.ERR, false);
+ StringResource s = new StringResource();
+ ResourceUtils.copyResource(content, s);
+
+ Assert.assertEquals(s.getValue(),
+ "0" + StringUtils.LINE_SEP
+ + "1" + StringUtils.LINE_SEP);
+ }
+
+ public void testWithExplicitMerge() throws IOException {
+ Project p = new Project();
+ LogCapturer c = new LogCapturer(p);
+
+ for (int i = 0; i < 2; i++) {
+ BuildEvent be = new BuildEvent(p);
+ be.setMessage(String.valueOf(i), 0);
+ c.messageLogged(be);
+ }
+
+ LogContent content = new LogContent(p, LogLevel.ERR, true);
+ StringResource s = new StringResource();
+ ResourceUtils.copyResource(content, s);
+
+ Assert.assertEquals(s.getValue(), "01");
+ }
+
+ public void testWithImplicitMerge() throws IOException {
+ Project p = new Project();
+ LogCapturer c = new LogCapturer(p);
+
+ for (int i = 0; i < 2; i++) {
+ BuildEvent be = new BuildEvent(p);
+ be.setMessage(String.valueOf(i), 0);
+ c.messageLogged(be);
+ }
+
+ LogContent content = new LogContent();
+ content.setProject(p);
+ StringResource s = new StringResource();
+ ResourceUtils.copyResource(content, s);
+
+ Assert.assertEquals(s.getValue(), "01");
+ }
+
private static void assertMessages(LogContent content, String[] messages,
int upTo) throws IOException {
StringResource s = new StringResource();