-
Notifications
You must be signed in to change notification settings - Fork 58
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. * Eclipse compiler updated to 3.15.0 * Unit tests refactored * Output emitted as "INFO" are reported as Kind.NOTE * Column count adjusted to be 1-based index
- Loading branch information
Jason Faust
committed
Oct 18, 2018
1 parent
acbb668
commit a42abc8
Showing
25 changed files
with
1,704 additions
and
265 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
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
26 changes: 26 additions & 0 deletions
26
...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,26 @@ | ||
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.8.6 | ||
*/ | ||
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 |
---|---|---|
|
@@ -16,16 +16,19 @@ | |
import java.util.List; | ||
|
||
/** | ||
* Created on 2018-03-31. | ||
* | ||
* @author <a href="mailto:[email protected]">Frits Jalvingh</a> | ||
* Created on 31-3-18. | ||
* @author <a href="mailto:[email protected]">Jason Faust</a> | ||
*/ | ||
public class EcjResponseParser { | ||
public class EcjResponseParser implements EcjLogParser { | ||
/*--------------------------------------------------------------*/ | ||
/* CODING: Decode ECJ -log format results. */ | ||
/*--------------------------------------------------------------*/ | ||
/** | ||
* Scan the specified response file for compilation messages. | ||
*/ | ||
@Override | ||
public List<CompilerMessage> parse(File xmltf, boolean errorsAsWarnings) throws Exception { | ||
//if(xmltf.length() < 80) | ||
// return; | ||
|
@@ -87,18 +90,32 @@ private void decodeProblems(List<CompilerMessage> list, String sourcePath, XMLSt | |
private void decodeProblem(List<CompilerMessage> list, String sourcePath, XMLStreamReader xsr, boolean errorsAsWarnings) 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 += 2; // Offset to 1-based index with one-after counting | ||
} else { | ||
endCol = 0; | ||
} | ||
} | ||
ignoreTillEnd(xsr); | ||
|
||
} else if(type == XMLStreamConstants.END_ELEMENT) { | ||
|
105 changes: 105 additions & 0 deletions
105
...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,105 @@ | ||
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.8.6 | ||
*/ | ||
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('^') + 1; | ||
} | ||
|
||
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; | ||
} | ||
|
||
} |
Oops, something went wrong.