diff options
-rw-r--r-- | src/main/java/org/javacs/InferConfig.java | 56 | ||||
-rw-r--r-- | src/test/java/org/javacs/InferBazelConfigTest.java | 9 | ||||
-rw-r--r-- | src/test/java/org/javacs/InferConfigTest.java | 13 |
3 files changed, 6 insertions, 72 deletions
diff --git a/src/main/java/org/javacs/InferConfig.java b/src/main/java/org/javacs/InferConfig.java index 2e8f82c..f52884b 100644 --- a/src/main/java/org/javacs/InferConfig.java +++ b/src/main/java/org/javacs/InferConfig.java @@ -19,7 +19,6 @@ import java.util.Set; import java.util.logging.Logger; import java.util.regex.Pattern; import java.util.stream.Collectors; -import java.util.stream.Stream; class InferConfig { private static final Logger LOG = Logger.getLogger("main"); @@ -56,15 +55,8 @@ class InferConfig { return Paths.get(System.getProperty("user.home")).resolve(".gradle"); } - Set<Path> classPath() { - var result = new HashSet<Path>(); - result.addAll(buildClassPath()); - result.addAll(workspaceClassPath()); - return result; - } - /** Find .jar files for external dependencies, for examples maven dependencies in ~/.m2 or jars in bazel-genfiles */ - Set<Path> buildClassPath() { + Set<Path> classPath() { // externalDependencies if (!externalDependencies.isEmpty()) { var result = new HashSet<Path>(); @@ -100,52 +92,6 @@ class InferConfig { return Collections.emptySet(); } - /** - * Find directories that contain java .class files in the workspace, for example files generated by maven in - * target/classes - */ - Set<Path> workspaceClassPath() { - // externalDependencies - if (!externalDependencies.isEmpty()) { - return Collections.emptySet(); - } - - // Maven - if (Files.exists(workspaceRoot.resolve("pom.xml"))) { - try { - return Files.walk(workspaceRoot).flatMap(this::outputDirectory).collect(Collectors.toSet()); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - // Bazel - if (Files.exists(workspaceRoot.resolve("WORKSPACE"))) { - var bazelBin = workspaceRoot.resolve("bazel-bin"); - - if (Files.exists(bazelBin) && Files.isSymbolicLink(bazelBin)) { - return bazelOutputDirectories(bazelBin); - } - } - - return Collections.emptySet(); - } - - /** 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")) { - var target = file.resolveSibling("target"); - - if (Files.exists(target) && Files.isDirectory(target)) { - return Stream.of(target.resolve("classes"), target.resolve("test-classes")); - } - } - - // TODO gradle - - return Stream.empty(); - } - private void findBazelJavac(File bazelRoot, File workspaceRoot, Set<Path> acc) { // If _javac directory exists, search it for dirs with names like lib*_classes var javac = new File(bazelRoot, "_javac"); diff --git a/src/test/java/org/javacs/InferBazelConfigTest.java b/src/test/java/org/javacs/InferBazelConfigTest.java index f5dcd80..b652d19 100644 --- a/src/test/java/org/javacs/InferBazelConfigTest.java +++ b/src/test/java/org/javacs/InferBazelConfigTest.java @@ -49,14 +49,9 @@ public class InferBazelConfigTest { } @Test - public void bazelWorkspaceClassPath() { - assertThat(bazel.workspaceClassPath(), hasItem(bazelBinTarget.resolve("module/_javac/main/libmain_classes"))); - } - - @Test - public void bazelBuildClassPath() { + public void bazelClassPath() { assertThat( - bazel.buildClassPath(), + bazel.classPath(), hasItem( bazelGenfilesTarget.resolve( "external/com_external_external_library/jar/_ijar/jar/external/com_external_external_library/jar/external-library-1.2.jar"))); diff --git a/src/test/java/org/javacs/InferConfigTest.java b/src/test/java/org/javacs/InferConfigTest.java index d49ebb8..ac660d0 100644 --- a/src/test/java/org/javacs/InferConfigTest.java +++ b/src/test/java/org/javacs/InferConfigTest.java @@ -5,7 +5,6 @@ import static org.junit.Assert.*; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.Collections; import java.util.Set; import org.junit.Test; @@ -16,18 +15,12 @@ public class InferConfigTest { private Set<String> externalDependencies = Set.of("com.external:external-library:1.2"); private InferConfig both = new InferConfig(workspaceRoot, externalDependencies, mavenHome, gradleHome); private InferConfig gradle = new InferConfig(workspaceRoot, externalDependencies, Paths.get("nowhere"), gradleHome); - private InferConfig onlyPomXml = - new InferConfig( - Paths.get("src/test/test-project/only-pom-xml"), - Collections.emptySet(), - mavenHome, - Paths.get("nowhere")); private InferConfig thisProject = new InferConfig(Paths.get("."), Set.of()); @Test public void mavenClassPath() { assertThat( - both.buildClassPath(), + both.classPath(), contains(mavenHome.resolve("repository/com/external/external-library/1.2/external-library-1.2.jar"))); // v1.1 should be ignored } @@ -35,7 +28,7 @@ public class InferConfigTest { @Test public void gradleClasspath() { assertThat( - gradle.buildClassPath(), + gradle.classPath(), contains( gradleHome.resolve( "caches/modules-2/files-2.1/com.external/external-library/1.2/xxx/external-library-1.2.jar"))); @@ -70,7 +63,7 @@ public class InferConfigTest { @Test public void thisProjectClassPath() { assertThat( - thisProject.buildClassPath(), + thisProject.classPath(), hasItem(hasToString(endsWith(".m2/repository/junit/junit/4.12/junit-4.12.jar")))); } |