From e60ee6dc55943e0252cc3dbb66a5ffcc453d4b78 Mon Sep 17 00:00:00 2001 From: George Fraser Date: Sun, 16 Sep 2018 10:30:38 -0700 Subject: Revive externalDependencies and classPath --- src/test/java/org/javacs/InferBazelConfigTest.java | 4 +- src/test/java/org/javacs/InferConfigTest.java | 62 ++++++++++++++++++---- 2 files changed, 55 insertions(+), 11 deletions(-) (limited to 'src/test') diff --git a/src/test/java/org/javacs/InferBazelConfigTest.java b/src/test/java/org/javacs/InferBazelConfigTest.java index d3e04fc..f5dcd80 100644 --- a/src/test/java/org/javacs/InferBazelConfigTest.java +++ b/src/test/java/org/javacs/InferBazelConfigTest.java @@ -7,6 +7,7 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.Collections; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -15,7 +16,8 @@ public class InferBazelConfigTest { private Path bazelWorkspace = Paths.get("src/test/test-project/bazel-workspace"), bazelTemp = Paths.get("src/test/test-project/bazel-temp"); - private InferConfig bazel = new InferConfig(bazelWorkspace, Paths.get("nowhere")); + private InferConfig bazel = + new InferConfig(bazelWorkspace, Collections.emptySet(), 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(), bazelGenfiles = bazelWorkspace.resolve("bazel-genfiles"), diff --git a/src/test/java/org/javacs/InferConfigTest.java b/src/test/java/org/javacs/InferConfigTest.java index 2a951cc..debd6db 100644 --- a/src/test/java/org/javacs/InferConfigTest.java +++ b/src/test/java/org/javacs/InferConfigTest.java @@ -5,40 +5,82 @@ 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; public class InferConfigTest { private Path workspaceRoot = Paths.get("src/test/test-project/workspace"); private Path mavenHome = Paths.get("src/test/test-project/home/.m2"); - private Artifact externalArtifact = new Artifact("com.external", "external-library", "1.2"); - private InferConfig infer = new InferConfig(workspaceRoot, mavenHome); + private Path gradleHome = Paths.get("src/test/test-project/home/.gradle"); + private Set 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")); @Test public void mavenClassPath() { - var found = infer.findMavenJar(externalArtifact, false); - assertTrue(found.isPresent()); assertThat( - found.get(), - equalTo(mavenHome.resolve("repository/com/external/external-library/1.2/external-library-1.2.jar"))); + both.buildClassPath(), + contains(mavenHome.resolve("repository/com/external/external-library/1.2/external-library-1.2.jar"))); + // v1.1 should be ignored + } + + @Test + public void gradleClasspath() { + assertThat( + gradle.buildClassPath(), + contains( + gradleHome.resolve( + "caches/modules-2/files-2.1/com.external/external-library/1.2/xxx/external-library-1.2.jar"))); // v1.1 should be ignored } @Test public void mavenDocPath() { - var found = infer.findMavenJar(externalArtifact, true); - assertTrue(found.isPresent()); assertThat( - found.get(), - equalTo( + both.buildDocPath(), + contains( mavenHome.resolve( "repository/com/external/external-library/1.2/external-library-1.2-sources.jar"))); // v1.1 should be ignored } + @Test + public void gradleDocPath() { + assertThat( + gradle.buildDocPath(), + contains( + gradleHome.resolve( + "caches/modules-2/files-2.1/com.external/external-library/1.2/yyy/external-library-1.2-sources.jar"))); + // v1.1 should be ignored + } + @Test public void dependencyList() { assertThat( InferConfig.dependencyList(Paths.get("pom.xml")), hasItem(new Artifact("org.hamcrest", "hamcrest-all", "1.3"))); } + + @Test + public void onlyPomXmlClassPath() { + assertThat( + onlyPomXml.buildClassPath(), + contains(mavenHome.resolve("repository/com/external/external-library/1.2/external-library-1.2.jar"))); + } + + @Test + public void onlyPomXmlDocPath() { + assertThat( + onlyPomXml.buildDocPath(), + contains( + mavenHome.resolve( + "repository/com/external/external-library/1.2/external-library-1.2-sources.jar"))); + } } -- cgit v1.2.3