@@ -11,6 +11,8 @@ import scala.util.control.NonFatal
1111import scala .collection .mutable
1212import scala .jdk .CollectionConverters ._
1313
14+ import javax .tools .ToolProvider
15+
1416import org .junit .Assert ._
1517import org .junit .Test
1618import org .junit .experimental .categories .Category
@@ -25,11 +27,12 @@ import dotty.tools.dotc.util.SourceFile
2527
2628@ Category (Array (classOf [BootstrappedOnlyTests ]))
2729class SemanticdbTests with
30+ val javaFile = FileSystems .getDefault.getPathMatcher(" glob:**.java" )
2831 val scalaFile = FileSystems .getDefault.getPathMatcher(" glob:**.scala" )
2932 val expectFile = FileSystems .getDefault.getPathMatcher(" glob:**.expect.scala" )
30- // val semanticdbFile = FileSystems.getDefault.getPathMatcher("glob:**.scala.semanticdb")
3133 val rootSrc = Paths .get(System .getProperty(" dotty.tools.dotc.semanticdb.test" ))
3234 val expectSrc = rootSrc.resolve(" expect" )
35+ val javaRoot = rootSrc.resolve(" javacp" )
3336 val metacExpectFile = rootSrc.resolve(" metac.expect" )
3437
3538 @ Category (Array (classOf [dotty.SlowTests ]))
@@ -87,8 +90,20 @@ class SemanticdbTests with
8790 require(files.nonEmpty, s " No input files! $expectSrc" )
8891 files.toList
8992
93+ def javaFiles (): List [Path ] =
94+ val ls = Files .walk(javaRoot)
95+ val files =
96+ try ls.filter(p => javaFile.matches(p)).collect(Collectors .toList).asScala
97+ finally ls.close()
98+ require(files.nonEmpty, s " No input files! $expectSrc" )
99+ files.toList
100+
90101 def generateSemanticdb (): Path =
91102 val target = Files .createTempDirectory(" semanticdb" )
103+ val javaArgs = Array (" -d" , target.toString) ++ javaFiles().map(_.toString)
104+ val javac = ToolProvider .getSystemJavaCompiler
105+ val exitJava = javac.run(null , null , null , javaArgs:_* )
106+ assert(exitJava == 0 , " java compiler has errors" )
92107 val args = Array (
93108 " -Ysemanticdb" ,
94109 " -d" , target.toString,
@@ -97,7 +112,8 @@ class SemanticdbTests with
97112 // "-Ydebug-flags",
98113 // "-Xprint:extractSemanticDB",
99114 " -sourceroot" , expectSrc.toString,
100- " -usejavacp" ,
115+ " -classpath" , target.toString,
116+ " -usejavacp"
101117 ) ++ inputFiles().map(_.toString)
102118 val exit = Main .process(args)
103119 assertFalse(s " dotc errors: ${exit.errorCount}" , exit.hasErrors)
0 commit comments