Return-Path: Delivered-To: apmail-ant-notifications-archive@minotaur.apache.org Received: (qmail 78788 invoked from network); 12 Aug 2009 20:29:33 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 12 Aug 2009 20:29:33 -0000 Received: (qmail 48223 invoked by uid 500); 12 Aug 2009 20:29:40 -0000 Delivered-To: apmail-ant-notifications-archive@ant.apache.org Received: (qmail 48157 invoked by uid 500); 12 Aug 2009 20:29:39 -0000 Mailing-List: contact notifications-help@ant.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ant.apache.org Delivered-To: mailing list notifications@ant.apache.org Received: (qmail 48148 invoked by uid 99); 12 Aug 2009 20:29:39 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 12 Aug 2009 20:29:39 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 12 Aug 2009 20:29:37 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id DA9BC23888E5; Wed, 12 Aug 2009 20:29:17 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r803701 - in /ant/core/trunk/src: main/org/apache/tools/ant/DefaultLogger.java tests/junit/org/apache/tools/ant/DefaultLoggerTest.java Date: Wed, 12 Aug 2009 20:29:17 -0000 To: notifications@ant.apache.org From: jglick@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090812202917.DA9BC23888E5@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: jglick Date: Wed Aug 12 20:29:17 2009 New Revision: 803701 URL: http://svn.apache.org/viewvc?rev=803701&view=rev Log: Writing test for #43398, which is not satisfactorily fixed. Added: ant/core/trunk/src/tests/junit/org/apache/tools/ant/DefaultLoggerTest.java (with props) Modified: ant/core/trunk/src/main/org/apache/tools/ant/DefaultLogger.java Modified: ant/core/trunk/src/main/org/apache/tools/ant/DefaultLogger.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/DefaultLogger.java?rev=803701&r1=803700&r2=803701&view=diff ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/ant/DefaultLogger.java (original) +++ ant/core/trunk/src/main/org/apache/tools/ant/DefaultLogger.java Wed Aug 12 20:29:17 2009 @@ -130,6 +130,22 @@ startTime = System.currentTimeMillis(); } + static void throwableMessage(StringBuffer m, Throwable error, boolean verbose) { + while (error instanceof BuildException) { // #43398 + Throwable cause = ((BuildException) error).getCause(); + if (cause != null && cause.toString().equals(error.getMessage())) { + error = cause; + } else { + break; + } + } + if (verbose || !(error instanceof BuildException)) { + m.append(StringUtils.getStackTrace(error)); + } else { + m.append(error).append(lSep); + } + } + /** * Prints whether the build succeeded or failed, * any errors the occurred during the build, and @@ -148,22 +164,7 @@ message.append(StringUtils.LINE_SEP); message.append(getBuildFailedMessage()); message.append(StringUtils.LINE_SEP); - - while (error instanceof BuildException) { // #43398 - Throwable cause = ((BuildException) error).getCause(); - if (cause != null && cause.toString().equals(error.getMessage())) { - error = cause; - } else { - break; - } - } - - if (Project.MSG_VERBOSE <= msgOutputLevel - || !(error instanceof BuildException)) { - message.append(StringUtils.getStackTrace(error)); - } else { - message.append(error.toString()).append(lSep); - } + throwableMessage(message, error, Project.MSG_VERBOSE <= msgOutputLevel); } message.append(StringUtils.LINE_SEP); message.append("Total time: "); Added: ant/core/trunk/src/tests/junit/org/apache/tools/ant/DefaultLoggerTest.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/DefaultLoggerTest.java?rev=803701&view=auto ============================================================================== --- ant/core/trunk/src/tests/junit/org/apache/tools/ant/DefaultLoggerTest.java (added) +++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/DefaultLoggerTest.java Wed Aug 12 20:29:17 2009 @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.tools.ant; + +import java.io.PrintWriter; +import junit.framework.TestCase; + +public class DefaultLoggerTest extends TestCase { + + public DefaultLoggerTest(String n) { + super(n); + } + + private static String msg(Throwable error, boolean verbose) { + StringBuffer m = new StringBuffer(); + DefaultLogger.throwableMessage(m, error, verbose); + return m.toString(); + } + + public void testThrowableMessage() throws Exception { // #43398 + BuildException be = new BuildException("oops", new Location("build.xml", 1, 0)); + assertEquals( + "build.xml:1: oops\n", + msg(be, false)); + be = ProjectHelper.addLocationToBuildException(be, new Location("build.xml", 2, 0)); + assertEquals( + "build.xml:2: The following error occurred while executing this line:\n" + + "build.xml:1: oops\n", + msg(be, false)); + be = ProjectHelper.addLocationToBuildException(be, new Location("build.xml", 3, 0)); + assertEquals( + "build.xml:3: The following error occurred while executing this line:\n" + + "build.xml:2: The following error occurred while executing this line:\n" + + "build.xml:1: oops\n", + msg(be, false)); + Exception x = new Exception("problem") { + public void printStackTrace(PrintWriter w) { + w.println("problem"); + w.println(" at p.C.m"); + } + }; + be = new BuildException(x); + assertEquals( + "problem\n" + + " at p.C.m\n", + msg(be, false)); + /* XXX still broken: + be = ProjectHelper.addLocationToBuildException(be, new Location("build.xml", 1, 0)); + assertEquals( + "The following error occurred while executing this line:\n" + + "build.xml:1: problem\n" + + " at p.C.m\n", + msg(be, false)); + */ + } + +} Propchange: ant/core/trunk/src/tests/junit/org/apache/tools/ant/DefaultLoggerTest.java ------------------------------------------------------------------------------ svn:eol-style = native