From a380e3ceb0605ea9a18072237207d3ed8f4e2e80 Mon Sep 17 00:00:00 2001 From: Brett Leslie Porter Date: Mon, 21 Mar 2005 06:06:42 +0000 Subject: [PATCH] no need to throw an exception every time there is a compiler error, however make sure to process lines starting with "error: " as a compile error git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163633 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/main/java/compile/JavacCompiler.java | 39 ++++++++++++------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/maven-mboot2/src/main/java/compile/JavacCompiler.java b/maven-mboot2/src/main/java/compile/JavacCompiler.java index 64775e9473..60494bab17 100644 --- a/maven-mboot2/src/main/java/compile/JavacCompiler.java +++ b/maven-mboot2/src/main/java/compile/JavacCompiler.java @@ -68,11 +68,6 @@ public class JavacCompiler List args = new ArrayList( sources.length + 5 + compilerOptions.size() * 2 ); - if ( config.isDebug() ) - { - args.add( "-g" ); - } - args.add( "-d" ); args.add( destinationDir.getAbsolutePath() ); @@ -83,6 +78,11 @@ public class JavacCompiler args.add( getClasspathString( config.getClasspathEntries() ) ); + if ( config.isDebug() ) + { + args.add( "-g" ); + } + Iterator it = compilerOptions.entrySet().iterator(); while ( it.hasNext() ) @@ -116,13 +116,14 @@ public class JavacCompiler Boolean ok = (Boolean) compile.invoke( compiler, new Object[] { args.toArray( new String[0] ) } ); - if ( !ok.booleanValue() ) - { - throw new Exception( "Failure executing javac: \n\n'javac " + args + "'\n\n" + err.toString() ); - } - List messages = parseModernStream( new BufferedReader( new InputStreamReader( new ByteArrayInputStream( err.toByteArray() ) ) ) ); + if ( !ok.booleanValue() && messages.isEmpty() ) + { + // TODO: don't throw exception + throw new Exception( "Failure executing javac, but could not parse the error:\n\n" + err.toString() ); + } + return messages; } @@ -147,10 +148,18 @@ public class JavacCompiler return errors; } - buffer.append( line ); + if ( buffer.length() == 0 && line.startsWith( "error: " ) ) + { + errors.add( new CompilerError( line ) ); + } + else + { + buffer.append( line ); - buffer.append( '\n' ); - } while ( !line.endsWith( "^" ) ); + buffer.append( '\n' ); + } + } + while ( !line.endsWith( "^" ) ); // add the error bean errors.add( parseModernError( buffer.toString() ) ); @@ -187,7 +196,7 @@ public class JavacCompiler endcolumn = context.length(); } - return new CompilerError( file, false, line, startcolumn, line, endcolumn, message ); + return new CompilerError( file, true, line, startcolumn, line, endcolumn, message ); } catch ( NoSuchElementException nse ) { @@ -203,4 +212,4 @@ public class JavacCompiler { return "Sun Javac Compiler"; } -} +} \ No newline at end of file