Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle javac warning messages #1228

Merged
merged 1 commit into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading