Skip to content

Commit

Permalink
Handle javac warning messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthur McGibbon committed Jul 27, 2023
1 parent f55b5b5 commit 97595c9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -243,14 +243,24 @@ class JavaErrorParser(relativeDir: File = new File(new File(".").getAbsolutePath
s"javac:$error"
)
}
val javacWarning: Parser[Problem] =
WARNING ~ SEMICOLON ~ restOfLine ^^ {
case _ ~ _ ~ warning =>
new JavaProblem(
JavaNoPosition,
Severity.Warn,
s"javac:$warning"
)
}

val outputSumamry: Parser[Unit] =
"""(\s*)(\d+) (\w+)""".r ~ restOfLine ^^ {
case a ~ b =>
()
}

val potentialProblem: Parser[Problem] = warningMessage | errorMessage | noteMessage | javacError
val potentialProblem: Parser[Problem] =
warningMessage | errorMessage | noteMessage | javacError | javacWarning

val javacOutput: Parser[Seq[Problem]] = rep(potentialProblem) <~ opt(outputSumamry)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ package javac

import sbt.internal.util.ConsoleLogger
import org.scalatest.diagrams.Diagrams
import xsbti.Severity

class JavaErrorParserSpec extends UnitSpec with Diagrams {

"The JavaErrorParser" should "be able to parse Linux errors" in parseSampleLinux()
it should "be able to parse windows file names" in parseWindowsFile()
it should "be able to parse windows errors" in parseSampleWindows()
it should "be able to parse javac warnings" in parseJavacWarning()
it should "be able to parse javac errors" in parseSampleJavac()
it should "register the position of errors" in parseErrorPosition()
it should "be able to parse multiple errors" in parseMultipleErrors()
Expand All @@ -43,7 +45,6 @@ class JavaErrorParserSpec extends UnitSpec with Diagrams {

assert(problems.size == 1)
problems(0).position.sourcePath.get shouldBe (windowsFile)

}

def parseWindowsFile() = {
Expand All @@ -57,6 +58,15 @@ class JavaErrorParserSpec extends UnitSpec with Diagrams {
}
}

def parseJavacWarning() = {
val parser = new JavaErrorParser()
val logger = ConsoleLogger()
val problems = parser.parseProblems(sampleJavacWarning, logger)
assert(problems.size == 1)
problems(0).severity shouldBe Severity.Warn
problems(0).position.offset.isPresent shouldBe false
}

def parseSampleJavac() = {
val parser = new JavaErrorParser()
val logger = ConsoleLogger()
Expand Down Expand Up @@ -124,6 +134,9 @@ class JavaErrorParserSpec extends UnitSpec with Diagrams {
|return baz();
""".stripMargin

def sampleJavacWarning =
"warning: [options] system modules path not set in conjunction with -source 17"

def windowsFile = """C:\Projects\sample\src\main\java\Test.java"""
def windowsFileAndLine = s"""$windowsFile:4"""

Expand Down

0 comments on commit 97595c9

Please sign in to comment.