-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow -log argument for Eclipse compiler
If the -log argument is used, the resulting log file is scanned for compiler output, both text and xml formatting supported. Otherwise a temporary log file is used to capture compiler output. * Unit tests refactored * Output emitted as "INFO" are reported as Kind.NOTE * Column count adjusted to be 1-based index
- Loading branch information
Showing
27 changed files
with
2,060 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...xus-compiler-eclipse/src/main/java/org/codehaus/plexus/compiler/eclipse/EcjLogParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright (c) 2005, The Codehaus | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
* this software and associated documentation files (the "Software"), to deal in | ||
* the Software without restriction, including without limitation the rights to | ||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | ||
* of the Software, and to permit persons to whom the Software is furnished to do | ||
* so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package org.codehaus.plexus.compiler.eclipse; | ||
|
||
import java.io.File; | ||
import java.util.List; | ||
|
||
import org.codehaus.plexus.compiler.CompilerMessage; | ||
|
||
/** | ||
* Log parser interface. | ||
* | ||
* @author <a href="mailto:[email protected]">Jason Faust</a> | ||
* @since 2.14.0 | ||
*/ | ||
public interface EcjLogParser { | ||
|
||
/** | ||
* Pares an Eclipse Compiler log file. | ||
* | ||
* @param logFile file to parse. | ||
* @param errorsAsWarnings if errors should be down-graded to warnings. | ||
* @return the messages. | ||
* @throws Exception on parse errors. | ||
*/ | ||
List<CompilerMessage> parse(File logFile, boolean errorsAsWarnings) throws Exception; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,9 +18,10 @@ | |
|
||
/** | ||
* @author <a href="mailto:[email protected]">Frits Jalvingh</a> | ||
* @author <a href="mailto:[email protected]">Jason Faust</a> | ||
* Created on 31-3-18. | ||
*/ | ||
public class EcjResponseParser { | ||
public class EcjResponseParser implements EcjLogParser { | ||
/*--------------------------------------------------------------*/ | ||
/* CODING: Decode ECJ -log format results. */ | ||
/*--------------------------------------------------------------*/ | ||
|
@@ -40,6 +41,7 @@ private static XMLInputFactory getStreamFactory() { | |
* @param errorsAsWarnings should we treat errors as warnings | ||
* Scan the specified response file for compilation messages. | ||
*/ | ||
@Override | ||
public List<CompilerMessage> parse(File xmltf, boolean errorsAsWarnings) throws Exception { | ||
// if(xmltf.length() < 80) | ||
// return; | ||
|
@@ -106,20 +108,33 @@ private void decodeProblem( | |
throws Exception { | ||
String id = xsr.getAttributeValue(null, "optionKey"); // Key for the problem | ||
int startline = getInt(xsr, "line"); | ||
int column = getInt(xsr, "charStart"); | ||
int endCol = getInt(xsr, "charEnd"); | ||
int column = 0; | ||
int endCol = 0; | ||
String sev = xsr.getAttributeValue(null, "severity"); | ||
String message = "Unknown message?"; | ||
|
||
// -- Go watch for "message" | ||
// -- Go watch for "message" and "source_context" | ||
while (xsr.hasNext()) { | ||
int type = xsr.nextTag(); | ||
if (type == XMLStreamConstants.START_ELEMENT) { | ||
if ("message".equals(xsr.getLocalName())) { | ||
message = xsr.getAttributeValue(null, "value"); | ||
} | ||
if ("source_context".equals(xsr.getLocalName())) { | ||
column = getInt(xsr, "sourceStart"); | ||
if (column != -1) { | ||
column += 1; // Offset to 1-based index | ||
} else { | ||
column = 0; | ||
} | ||
endCol = getInt(xsr, "sourceEnd"); | ||
if (endCol != -1) { | ||
endCol += 1; // Offset to 1-based index | ||
} else { | ||
endCol = 0; | ||
} | ||
} | ||
ignoreTillEnd(xsr); | ||
|
||
} else if (type == XMLStreamConstants.END_ELEMENT) { | ||
break; | ||
} | ||
|
127 changes: 127 additions & 0 deletions
127
...compiler-eclipse/src/main/java/org/codehaus/plexus/compiler/eclipse/EcjTextLogParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright (c) 2005, The Codehaus | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
* this software and associated documentation files (the "Software"), to deal in | ||
* the Software without restriction, including without limitation the rights to | ||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | ||
* of the Software, and to permit persons to whom the Software is furnished to do | ||
* so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package org.codehaus.plexus.compiler.eclipse; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.InputStreamReader; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.ArrayList; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
import org.codehaus.plexus.compiler.CompilerMessage; | ||
import org.codehaus.plexus.compiler.CompilerMessage.Kind; | ||
|
||
/** | ||
* Parser for non-XML Eclipse Compiler output. | ||
* | ||
* @author <a href="mailto:[email protected]">Jason Faust</a> | ||
* @since 2.14.0 | ||
*/ | ||
public class EcjTextLogParser implements EcjLogParser { | ||
|
||
private static final String TEN_DASH = "----------"; | ||
private static final String PATTERN_LEVEL_FILE = "^\\d+\\.\\s+(\\w+)\\s+in\\s+(.*)\\s+\\(at line (\\d+)\\)$"; | ||
|
||
private Pattern levelFile = Pattern.compile(PATTERN_LEVEL_FILE); | ||
|
||
@Override | ||
public List<CompilerMessage> parse(File logFile, boolean errorsAsWarnings) throws Exception { | ||
List<CompilerMessage> ret = new ArrayList<>(); | ||
try (BufferedReader in = | ||
new BufferedReader(new InputStreamReader(new FileInputStream(logFile), StandardCharsets.UTF_8))) { | ||
String line; | ||
List<String> buffer = new LinkedList<>(); | ||
boolean header = true; | ||
|
||
while ((line = in.readLine()) != null) { | ||
if (header) { | ||
if (!line.startsWith(TEN_DASH)) { | ||
continue; | ||
} | ||
header = false; | ||
} | ||
if (line.startsWith(TEN_DASH)) { | ||
if (!buffer.isEmpty()) { | ||
ret.add(parse(buffer, errorsAsWarnings)); | ||
} | ||
buffer.clear(); | ||
} else { | ||
buffer.add(line); | ||
} | ||
} | ||
} | ||
return ret; | ||
} | ||
|
||
private CompilerMessage parse(List<String> buffer, boolean errorsAsWarnings) { | ||
|
||
Kind kind = null; | ||
String file = null; | ||
int lineNum = 0; | ||
int startCol = 0; | ||
int endCol = 0; | ||
String message = null; | ||
|
||
// First line, kind, file, lineNum | ||
if (buffer.size() > 1) { | ||
String str = buffer.get(0); | ||
Matcher matcher = levelFile.matcher(str); | ||
if (matcher.find()) { | ||
file = matcher.group(2); | ||
kind = decodeKind(matcher.group(1), errorsAsWarnings); | ||
lineNum = Integer.parseInt(matcher.group(3)); | ||
} | ||
} | ||
|
||
// Last line, message | ||
if (buffer.size() >= 2) { | ||
String str = buffer.get(buffer.size() - 1); | ||
message = str.trim(); | ||
} | ||
|
||
// 2nd to last line, columns | ||
if (buffer.size() >= 3) { | ||
String str = buffer.get(buffer.size() - 2); | ||
startCol = str.indexOf('^'); | ||
endCol = str.lastIndexOf('^'); | ||
} | ||
|
||
return new CompilerMessage(file, kind, lineNum, startCol, lineNum, endCol, message); | ||
} | ||
|
||
private Kind decodeKind(String str, boolean errorsAsWarnings) { | ||
if (str.equals("ERROR")) { | ||
return errorsAsWarnings ? Kind.WARNING : Kind.ERROR; | ||
} | ||
if (str.equals("INFO")) { | ||
return Kind.NOTE; | ||
} | ||
return Kind.WARNING; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
plexus-compilers/plexus-compiler-eclipse/src/test-input/src/main/org/codehaus/foo/Info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.codehaus.foo; | ||
|
||
public class Info { | ||
{ | ||
"".equals(Integer.valueOf(1)); | ||
} | ||
} |
Oops, something went wrong.