Skip to content
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
9 changes: 5 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ plugins {
repositories {
jcenter()
mavenLocal()
maven {
url = 'https://repo.maven.apache.org/maven2'
}
maven { url = 'https://repo.maven.apache.org/maven2' }
maven { url = 'https://repo.gradle.org/gradle/libs-releases' }
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
compile files("${System.getProperty('java.home')}/../lib/tools.jar")
compile 'com.google.code.gson:gson:2.8.6'
compile 'commons-cli:commons-cli:1.4'
Expand All @@ -23,8 +23,9 @@ dependencies {
compile 'org.slf4j:slf4j-nop:1.7.30'
implementation 'org.eclipse.lsp4j:org.eclipse.lsp4j:0.9.0'
implementation 'com.google.guava:guava:29.0-jre'
implementation "org.gradle:gradle-tooling-api:6.6.1"

testImplementation 'junit:junit:4.13'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
}

application {
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/lsifjava/ProjectIndexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ public void index() throws IOException {

var indexers = new HashMap<Path, DocumentIndexer>();
var collector = new FileCollector(projectId, arguments, emitter, indexers);
Files.walkFileTree(Paths.get(arguments.projectRoot), collector);

try(GradleInterface gradleInterface = new GradleInterface(arguments.projectRoot)) {
for (Path it : gradleInterface.sourceDirectories()) {
Files.walkFileTree(it, collector);
}
}

var fileManager = new SourceFileManager(indexers.keySet());

for(var indexer : indexers.values()) {
Expand Down
31 changes: 31 additions & 0 deletions src/main/kotlin/lsifjava/GradleInterface.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package lsifjava

import org.gradle.tooling.GradleConnector
import org.gradle.tooling.model.GradleProject
import org.gradle.tooling.model.eclipse.EclipseProject
import org.gradle.tooling.model.idea.IdeaProject
import java.nio.file.Path
import java.nio.file.Paths

// TODO(nsc) exclusions? subprojects? inter-project dependencies? fml
class GradleInterface(private val projectDir: String): AutoCloseable {
private val projectConnection by lazy {
GradleConnector.newConnector().forProjectDirectory(Paths.get(projectDir).toFile()).connect()
}

private val eclipseModel by lazy {
projectConnection.getModel(EclipseProject::class.java)
}

fun classpath() = Classpath(eclipseModel.classpath.map { it.file.canonicalPath })

fun sourceDirectories() = eclipseModel.sourceDirectories.map {
Paths.get(eclipseModel.projectDirectory.path, it.path)
}

override fun close() = projectConnection.close()
}

class Classpath(private val classpaths: Iterable<String>): Iterable<String> by classpaths {
override fun toString() = classpaths.joinToString(":")
}