Skip to content

Commit

Permalink
code hygiene, javadoc
Browse files Browse the repository at this point in the history
  • Loading branch information
plaird committed Jan 22, 2020
1 parent a03a8d3 commit eb2a226
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/**
* Bazel generally requires BUILD file authors to list all dependencies explicitly.
* However, there are a few legacy cases in which dependencies are implied.
* For example, java_test implicitly brings in junit and hamcrest libraries.
* For example, java_test implicitly brings in junit, hamcrest, javax.annotation libraries.
* <p>
* This is unfortunate because external tools that need to construct the dependency
* graph (ahem, that's us, for JDT) we need to know to append the implicit dependencies
Expand Down Expand Up @@ -57,9 +57,9 @@ private Set<IClasspathEntry> computeImplicitJavaTestDependencies(IProject eclips
return deps;
}

// HAMCREST and JUNIT
// These implicit deps come from the test runner.
// Ultimately we need to get this jar onto the classpath:
// HAMCREST, JUNIT, JAVAX.ANNOTATION
// These implicit deps are leaked into the classpath by the java_test test runner.
// To faithfully declare the classpath for Eclipse JDT, we ultimately we need to get this jar onto the JDT classpath:
// bazel-bin/external/bazel_tools/tools/jdk/_ijar/TestRunner/external/remote_java_tools_darwin/java_tools/Runner_deploy-ijar.jar
// which comes in from the transitive graph (not sure how the toolchain points to the TestRunner though):
// java_test => @bazel_tools//tools/jdk:current_java_toolchain => @remote_java_tools_darwin//:toolchain ?=> TestRunner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ public void testClasspath_BazelJavaProject_implicitdeps() throws Exception {
// SETUP
// javalib0 is the base Java library created by our test harness
// javalib1 is the second Java library created by our test harness, and it is made to depend on javalib0
setupMockEnvironmentForClasspathTest("tcpbjp_im", false);
boolean explicitJavaTestDeps = false;
setupMockEnvironmentForClasspathTest("tcpbjp_im", explicitJavaTestDeps);
JavaCoreHelper javaHelper = BazelPluginActivator.getJavaCoreHelper();

// NOTE: classpath entries are ordered lists so they should always be in the same positions
Expand All @@ -102,21 +103,22 @@ public void testClasspath_BazelJavaProject_implicitdeps() throws Exception {
//printClasspathEntries(entries);

// SECOND check that the resolved classpath has 3 entries for javalib0: (TestRunner comes from implicit deps)
// bazel-output-base/execroot/test_workspace/bazel-out/darwin-fastbuild/bin/external/bazel_tools/tools/jdk/_ijar/TestRunner/external/remote_java_tools_linux/java_tools/Runner_deploy-ijar.jar
// bazel-output-base/execroot/mock_workspace/external/com_google_guava_guava/jar/guava-20.0.jar
// bazel-output-base/execroot/mock_workspace/external/org_slf4j_slf4j_api/jar/slf4j-api-1.7.25.jar
// bazel-output-base/execroot/test_workspace/bazel-out/darwin-fastbuild/bin/external/bazel_tools/tools/jdk/_ijar/TestRunner/external/remote_java_tools_linux/java_tools/Runner_deploy-ijar.jar
entries = javaHelper.getResolvedClasspath(javalib0_IJavaProject, false);
assertNotNull(entries);
//printClasspathEntries("tcpbjp_im", entries);
assertEquals(3, entries.length);
assertTrue(entries[0].getPath().toString().contains("guava"));
assertTrue(entries[1].getPath().toString().contains("slf4j"));
assertTrue(entries[2].getPath().toString().contains("Runner")); // this is the magical implicit dep TestRunner jar that adds hamcrest, junit, javax.annotation to cp

// THIRD check that the resolved classpath has 3 entries for javalib1: (TestRunner comes from implicit deps)
// bazel-output-base/execroot/test_workspace/bazel-out/darwin-fastbuild/bin/external/bazel_tools/tools/jdk/_ijar/TestRunner/external/remote_java_tools_linux/java_tools/Runner_deploy-ijar.jar
// bazel-output-base/execroot/mock_workspace/external/com_google_guava_guava/jar/guava-20.0.jar
// bazel-output-base/execroot/mock_workspace/external/org_slf4j_slf4j_api/jar/slf4j-api-1.7.25.jar
// javalib0
// bazel-output-base/execroot/test_workspace/bazel-out/darwin-fastbuild/bin/external/bazel_tools/tools/jdk/_ijar/TestRunner/external/remote_java_tools_linux/java_tools/Runner_deploy-ijar.jar
entries = javaHelper.getResolvedClasspath(javalib1_IJavaProject, false);
assertNotNull(entries);
// printClasspathEntries(entries);
Expand All @@ -129,14 +131,16 @@ public void testClasspath_BazelJavaProject_implicitdeps() throws Exception {
* We create an Eclipse project for the Bazel Workspace with a Java project.
* <p>
* Variant: explicit deps are enabled in the .bazelrc (explicit_java_test_deps=true) which is the best practice
* but not default setting.
* but not default setting. This config requires the BUILD file to specifically add junit/hamcrest to the deps
* for the java_test rules
*/
@Test
public void testClasspath_BazelJavaProject_explicitdeps() throws Exception {
// SETUP
// javalib0 is the base Java library created by our test harness
// javalib1 is the second Java library created by our test harness, and it is made to depend on javalib0
setupMockEnvironmentForClasspathTest("tcpbjp_ex", true);
boolean explicitJavaTestDeps = true;
setupMockEnvironmentForClasspathTest("tcpbjp_ex", explicitJavaTestDeps);
JavaCoreHelper javaHelper = BazelPluginActivator.getJavaCoreHelper();

// NOTE: classpath entries are ordered lists so they should always be in the same positions
Expand Down Expand Up @@ -179,11 +183,13 @@ public void testClasspath_BazelJavaProject_explicitdeps() throws Exception {
}

/**
* We create an Eclipse project for the Bazel Workspace as a container, make sure we return empty results for classpath entries.
* We create an Eclipse project for the Bazel Workspace as a container, make sure we return empty results for
* classpath entries for the Workspace project.
*/
@Test
public void testClasspath_BazelWorkspaceProject() throws Exception {
setupMockEnvironmentForClasspathTest("tcpbwp", false);
boolean explicitJavaTestDeps = false;
setupMockEnvironmentForClasspathTest("tcpbwp", explicitJavaTestDeps);

BazelClasspathContainer classpathContainer = new BazelClasspathContainer(workspace_IProject, workspace_JavaIProject);
IClasspathEntry[] entries = classpathContainer.getClasspathEntries();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private static String createJavaTestRule(String projectName, Map<String, String>
sb.append(" visibility = [\"//visibility:public\"],\n");
if (explicitJavaTestDeps) {
// see ImplicitDependencyHelper.java for more details about this block
sb.append(" deps = [ \"@junit_junit//jar\", \"@org_hamcrest_hamcrest_core//jar\", \"@ch_qos_logback_logback_core//jar\", ],\n");
sb.append(" deps = [ \"@junit_junit//jar\", \"@org_hamcrest_hamcrest_core//jar\", ],\n");
}
sb.append(")");
return sb.toString();
Expand Down

0 comments on commit eb2a226

Please sign in to comment.