From 7e34dc8052b895a06cfddba589cc30a39bf7b0ce Mon Sep 17 00:00:00 2001 From: Friendseeker <66892505+Friendseeker@users.noreply.github.com> Date: Fri, 11 Oct 2024 17:11:24 -0700 Subject: [PATCH 1/3] Handle specific javac emitted output --- .../scala/sbt/internal/inc/javac/JavaErrorParser.scala | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/internal/zinc-compile-core/src/main/scala/sbt/internal/inc/javac/JavaErrorParser.scala b/internal/zinc-compile-core/src/main/scala/sbt/internal/inc/javac/JavaErrorParser.scala index cb8c86058..cbb1ad3a0 100644 --- a/internal/zinc-compile-core/src/main/scala/sbt/internal/inc/javac/JavaErrorParser.scala +++ b/internal/zinc-compile-core/src/main/scala/sbt/internal/inc/javac/JavaErrorParser.scala @@ -270,10 +270,17 @@ class JavaErrorParser(relativeDir: File = new File(new File(".").getAbsolutePath () } + val nonProblem: Parser[Unit] = { + val skipLine = + ("Loading source file" | "Constructing Javadoc information") ~ """[^\r\n]*(\r\n|\n)?""".r + rep(skipLine) ^^ (_ => ()) + } + val potentialProblem: Parser[Problem] = warningMessage | errorMessage | noteMessage | javacError | javacWarning - val javacOutput: Parser[Seq[Problem]] = rep(potentialProblem) <~ opt(outputSumamry) + val javacOutput: Parser[Seq[Problem]] = + nonProblem ~> rep(potentialProblem) <~ opt(outputSumamry) /** * Example: From 8c4a5397146af0d6a02b339d7a424b7b6cd6d8b1 Mon Sep 17 00:00:00 2001 From: Friendseeker <66892505+Friendseeker@users.noreply.github.com> Date: Fri, 11 Oct 2024 17:59:46 -0700 Subject: [PATCH 2/3] Add extra opt() --- .../src/main/scala/sbt/internal/inc/javac/JavaErrorParser.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/zinc-compile-core/src/main/scala/sbt/internal/inc/javac/JavaErrorParser.scala b/internal/zinc-compile-core/src/main/scala/sbt/internal/inc/javac/JavaErrorParser.scala index cbb1ad3a0..6692f3ef5 100644 --- a/internal/zinc-compile-core/src/main/scala/sbt/internal/inc/javac/JavaErrorParser.scala +++ b/internal/zinc-compile-core/src/main/scala/sbt/internal/inc/javac/JavaErrorParser.scala @@ -280,7 +280,7 @@ class JavaErrorParser(relativeDir: File = new File(new File(".").getAbsolutePath warningMessage | errorMessage | noteMessage | javacError | javacWarning val javacOutput: Parser[Seq[Problem]] = - nonProblem ~> rep(potentialProblem) <~ opt(outputSumamry) + opt(nonProblem) ~> rep(potentialProblem) <~ opt(outputSumamry) /** * Example: From 980b91d8d176f9f918d63234a53a8867ea962439 Mon Sep 17 00:00:00 2001 From: Friendseeker <66892505+Friendseeker@users.noreply.github.com> Date: Fri, 11 Oct 2024 18:11:26 -0700 Subject: [PATCH 3/3] Add test case to JavaErrorParserSpec --- ...erSpec.scala => JavaErrorParserSpec.scala} | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) rename internal/zinc-compile-core/src/test/scala/sbt/internal/inc/javac/{javaErrorParserSpec.scala => JavaErrorParserSpec.scala} (89%) diff --git a/internal/zinc-compile-core/src/test/scala/sbt/internal/inc/javac/javaErrorParserSpec.scala b/internal/zinc-compile-core/src/test/scala/sbt/internal/inc/javac/JavaErrorParserSpec.scala similarity index 89% rename from internal/zinc-compile-core/src/test/scala/sbt/internal/inc/javac/javaErrorParserSpec.scala rename to internal/zinc-compile-core/src/test/scala/sbt/internal/inc/javac/JavaErrorParserSpec.scala index 5e4d8244f..b092adfff 100644 --- a/internal/zinc-compile-core/src/test/scala/sbt/internal/inc/javac/javaErrorParserSpec.scala +++ b/internal/zinc-compile-core/src/test/scala/sbt/internal/inc/javac/JavaErrorParserSpec.scala @@ -23,6 +23,7 @@ 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 non-problems" in parseSampleNonProblem() 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() @@ -47,6 +48,14 @@ class JavaErrorParserSpec extends UnitSpec with Diagrams { problems(0).position.sourcePath.get shouldBe (windowsFile) } + def parseSampleNonProblem() = { + val parser = new JavaErrorParser() + val logger = ConsoleLogger() + val problems = parser.parseProblems(sampleNonProblemMessage, logger) + + assert(problems.size == 2) + } + def parseWindowsFile() = { val parser = new JavaErrorParser() parser.parse(parser.fileAndLineNo, sampleWindowsMessage) match { @@ -198,6 +207,21 @@ class JavaErrorParserSpec extends UnitSpec with Diagrams { |return baz(); """.stripMargin + def sampleNonProblemMessage = + raw""" + |Loading source file D:\Repos\zinc\internal\zinc-compile-core\target\jvm-2.13\test-classes\sbt\internal\inc\javac\test1.java... + |Constructing Javadoc information... + |D:\Repos\zinc\internal\zinc-compile-core\target\jvm-2.13\test-classes\sbt\internal\inc\javac\test1.java:14: error: class Test is public, should be declared in a file named Test.java + |public class Test { + | ^ + |D:\Repos\zinc\internal\zinc-compile-core\target\jvm-2.13\test-classes\sbt\internal\inc\javac\test1.java:15: error: cannot find symbol + | public NotFound foo() { return 5; } + | ^ + | symbol: class NotFound + | location: class Test + |2 errors + """.stripMargin.trim + def sampleJavacWarning = "warning: [options] system modules path not set in conjunction with -source 17"