11package tests
22
3+ import java .io .ByteArrayOutputStream
4+ import java .io .PrintStream
35import java .nio .charset .StandardCharsets
46import java .nio .file .FileSystems
7+ import java .nio .file .FileVisitResult
58import java .nio .file .Files
69import java .nio .file .Path
7- import java .util .concurrent .atomic .AtomicInteger
10+ import java .nio .file .SimpleFileVisitor
11+ import java .nio .file .attribute .BasicFileAttributes
812
913import scala .util .Properties
1014
11- import scala .meta .inputs .Input
12- import scala .meta .internal .io .FileIO
13- import scala .meta .io .AbsolutePath
14-
15- import com .sourcegraph .io .DeleteVisitor
16- import com .sourcegraph .lsif_java .Dependencies
17- import com .sourcegraph .lsif_java .SemanticdbPrinters
1815import com .sourcegraph .lsif_java .LsifJava
19- import java .nio .file .SimpleFileVisitor
20- import java .nio .file .FileVisitResult
21- import java .nio .file .attribute .BasicFileAttributes
22- import java .io .PrintStream
23- import java .io .ByteArrayOutputStream
2416import moped .reporters .ConsoleReporter
2517
2618class LibrarySnapshotGenerator extends SnapshotGenerator {
2719 val scalaPattern = FileSystems .getDefault.getPathMatcher(" glob:**.scala" )
2820 val javaPattern = FileSystems .getDefault.getPathMatcher(" glob:**.java" )
29- private case class IndexMetrics (occurrenceCount : Int , linesOfCode : Int )
3021 def runLsifJava (arguments : List [String ]): Unit = {
3122 val baos = new ByteArrayOutputStream
3223 val exitCode = LsifJava
@@ -48,11 +39,7 @@ class LibrarySnapshotGenerator extends SnapshotGenerator {
4839
4940 override def run (context : SnapshotContext , handler : SnapshotHandler ): Unit = {
5041 val gen = new Gen (context, handler)
51- gen.checkLibrary(
52- " com.airbnb.android:epoxy:4.3.1"
53- // isIncluded = jar => jar.contains("epoxy")
54- )
55- // gen.checkLibrary("org.jetbrains.kotlin:kotlin-allopen:1.4.32")
42+ gen.checkLibrary(" com.airbnb.android:epoxy:4.3.1" )
5643 gen.checkLibrary(
5744 " com.lihaoyi:ujson_2.13:1.4.0" ,
5845 provided = List (
@@ -93,67 +80,6 @@ class LibrarySnapshotGenerator extends SnapshotGenerator {
9380 }
9481 }
9582 )
96- // Files.walkFileTree(indexDir, new DeleteVisitor())
97- // Files.walkFileTree(snapshotDir, new DeleteVisitor())
98- // val deps = Dependencies.resolveDependencies(name :: provided)
99- // val counter = new AtomicInteger()
100-
101- // val compiler =
102- // new TestCompiler(
103- // deps.classpathSyntax,
104- // javacOptions = List("-Xlint:none"),
105- // scalacOptions = Nil,
106- // targetroot
107- // )
108- // val timer = new Timer()
109- // val toIndex = deps.sources.filter(p => isIncluded(p.getFileName.toString))
110- // toIndex.foreach { source =>
111- // val metrics = compileSourcesJar(source, compiler)
112- // val i = counter.incrementAndGet()
113- // val message =
114- // f"$i%3s/${toIndex.size} jars; $timer%6s; " +
115- // f"${metrics.occurrenceCount}%,.0f occurrences; " +
116- // f"${metrics.linesOfCode}%,.0f loc; " + f"${source.getFileName}"
117- // println(message)
118- // }
119- }
120-
121- private def compileSourcesJar (
122- source : Path ,
123- compiler : TestCompiler
124- ): IndexMetrics = {
125- var occurrenceCount, linesOfCode = 0
126- FileIO
127- .withJarFileSystem(AbsolutePath (source), create = false , close = true ) {
128- root =>
129- val inputs =
130- FileIO
131- .listAllFilesRecursively(root)
132- .iterator
133- .filter(file =>
134- javaPattern.matches(file.toNIO) ||
135- scalaPattern.matches(file.toNIO)
136- )
137- .map { file =>
138- val relpath = file.toRelative(root).toString()
139- val text = FileIO .slurp(file, StandardCharsets .UTF_8 )
140- linesOfCode += text.linesIterator.size
141- Input .VirtualFile (relpath, text)
142- }
143- .toArray
144-
145- val result = compiler.compileSemanticdb(inputs)
146- result
147- .textDocuments
148- .getDocumentsList
149- .forEach { textDocument =>
150- occurrenceCount += textDocument.getOccurrencesCount
151- val print = SemanticdbPrinters .printTextDocument(textDocument)
152- val out = context.expectDirectory.resolve(textDocument.getUri)
153- handler.onSnapshotTest(context, out, () => print)
154- }
155- }
156- IndexMetrics (occurrenceCount, linesOfCode)
15783 }
15884 }
15985}
0 commit comments