summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/org/javacs/InferConfig.java52
-rw-r--r--src/test/java/org/javacs/InferBazelConfigTest.java24
-rw-r--r--src/test/test-project/bazel-temp/xyz/execroot/test/bazel-out/local-fastbuild/genfiles/external/com_external_external_library/jar/_ijar/jar/external/com_external_external_library/jar/external-library-1.2.jarbin0 -> 676 bytes
3 files changed, 63 insertions, 13 deletions
diff --git a/src/main/java/org/javacs/InferConfig.java b/src/main/java/org/javacs/InferConfig.java
index b962db2..630600a 100644
--- a/src/main/java/org/javacs/InferConfig.java
+++ b/src/main/java/org/javacs/InferConfig.java
@@ -99,18 +99,38 @@ class InferConfig {
}
/**
- * Find .jar files for `externalDependencies` in local maven / gradle repository.
+ * Find .jar files for external dependencies, for examples settings `externalDependencies` in local maven / gradle repository.
*/
Set<Path> buildClassPath() {
- return externalDependencies.stream()
- .flatMap(artifact -> stream(findAnyJar(artifact, false)))
- .collect(Collectors.toSet());
+ // Settings `externalDependencies`
+ Stream<Path> result = externalDependencies.stream().flatMap(artifact -> stream(findAnyJar(artifact, false)));
+
+ // Bazel
+ if (Files.exists(workspaceRoot.resolve("WORKSPACE"))) {
+ Path bazelGenFiles = workspaceRoot.resolve("bazel-genfiles");
+
+ if (Files.exists(bazelGenFiles) && Files.isSymbolicLink(bazelGenFiles)) {
+ result = Stream.concat(result, bazelJars(bazelGenFiles));
+ }
+ }
+
+ return result.collect(Collectors.toSet());
}
/**
* Find directories that contain java .class files in the workspace, for example files generated by maven in target/classes
*/
Set<Path> workspaceClassPath() {
+ // Bazel
+ if (Files.exists(workspaceRoot.resolve("WORKSPACE"))) {
+ Path bazelBin = workspaceRoot.resolve("bazel-bin");
+
+ if (Files.exists(bazelBin) && Files.isSymbolicLink(bazelBin)) {
+ return bazelOutputDirectories(bazelBin).collect(Collectors.toSet());
+ }
+ }
+
+ // Maven
try {
return Files.walk(workspaceRoot)
.flatMap(this::outputDirectory)
@@ -121,7 +141,7 @@ class InferConfig {
}
/**
- * Recognize build root files like pom.xml and WORKSPACE and return compiler output directories
+ * Recognize build root files like pom.xml and return compiler output directories
*/
private Stream<Path> outputDirectory(Path file) {
if (file.getFileName().toString().equals("pom.xml")) {
@@ -135,13 +155,7 @@ class InferConfig {
}
}
- if (file.getFileName().toString().equals("WORKSPACE")) {
- Path bazelBin = file.resolveSibling("bazel-bin");
-
- if (Files.exists(bazelBin) && Files.isSymbolicLink(bazelBin)) {
- return bazelOutputDirectories(bazelBin);
- }
- }
+ // TODO gradle
return Stream.empty();
}
@@ -165,6 +179,20 @@ class InferConfig {
}
/**
+ * Search bazel-genfiles for jars
+ */
+ private Stream<Path> bazelJars(Path bazelGenFiles) {
+ try {
+ Path target = Files.readSymbolicLink(bazelGenFiles);
+
+ return Files.walk(target)
+ .filter(file -> file.getFileName().toString().endsWith(".jar"));
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
* Find source .jar files for `externalDependencies` in local maven / gradle repository.
*/
Set<Path> buildDocPath() {
diff --git a/src/test/java/org/javacs/InferBazelConfigTest.java b/src/test/java/org/javacs/InferBazelConfigTest.java
index 0635165..f50a6c1 100644
--- a/src/test/java/org/javacs/InferBazelConfigTest.java
+++ b/src/test/java/org/javacs/InferBazelConfigTest.java
@@ -18,7 +18,9 @@ public class InferBazelConfigTest {
bazelTemp = Paths.get("src/test/test-project/bazel-temp");
private InferConfig bazel = new InferConfig(bazelWorkspace, Collections.emptyList(), Paths.get("nowhere"), Paths.get("nowhere"));
private Path bazelBin = bazelWorkspace.resolve("bazel-bin"),
- bazelBinTarget = bazelTemp.resolve("xyz/execroot/test/bazel-out/local-fastbuild/bin").toAbsolutePath();
+ bazelBinTarget = bazelTemp.resolve("xyz/execroot/test/bazel-out/local-fastbuild/bin").toAbsolutePath(),
+ bazelGenfiles = bazelWorkspace.resolve("bazel-genfiles"),
+ bazelGenfilesTarget = bazelTemp.resolve("xyz/execroot/test/bazel-out/local-fastbuild/genfiles").toAbsolutePath();
@Before
public void createBazelBinLink() throws IOException {
@@ -32,6 +34,18 @@ public class InferBazelConfigTest {
Files.deleteIfExists(bazelBin);
}
+ @Before
+ public void createBazelGenfilesLink() throws IOException {
+ assertTrue(Files.exists(bazelGenfilesTarget));
+
+ Files.createSymbolicLink(bazelGenfiles, bazelGenfilesTarget);
+ }
+
+ @After
+ public void deleteBazelGenfilesLink() throws IOException {
+ Files.deleteIfExists(bazelGenfiles);
+ }
+
@Test
public void bazelWorkspaceClassPath() {
assertThat(
@@ -39,4 +53,12 @@ public class InferBazelConfigTest {
hasItem(bazelBinTarget.resolve("module/_javac/main/libmain_classes"))
);
}
+
+ @Test
+ public void bazelBuildClassPath() {
+ assertThat(
+ bazel.buildClassPath(),
+ hasItem(bazelGenfilesTarget.resolve("external/com_external_external_library/jar/_ijar/jar/external/com_external_external_library/jar/external-library-1.2.jar"))
+ );
+ }
} \ No newline at end of file
diff --git a/src/test/test-project/bazel-temp/xyz/execroot/test/bazel-out/local-fastbuild/genfiles/external/com_external_external_library/jar/_ijar/jar/external/com_external_external_library/jar/external-library-1.2.jar b/src/test/test-project/bazel-temp/xyz/execroot/test/bazel-out/local-fastbuild/genfiles/external/com_external_external_library/jar/_ijar/jar/external/com_external_external_library/jar/external-library-1.2.jar
new file mode 100644
index 0000000..ecbd3dc
--- /dev/null
+++ b/src/test/test-project/bazel-temp/xyz/execroot/test/bazel-out/local-fastbuild/genfiles/external/com_external_external_library/jar/_ijar/jar/external/com_external_external_library/jar/external-library-1.2.jar
Binary files differ