More GWT build cleanup

- Use pre-jarjar targets in more places for better build parallelism.

- Since I was having trouble remembering which targets to use, I started
a naming convention: pre-jarjar targets have names ending with
"-bare".

- Started setting testonly in some places.

- Added a test to make sure we don't export the v3 servlet API

Change-Id: Ica431959242d12caf30df6fdc5f3d60e21c182b1
diff --git a/dev/BUILD b/dev/BUILD
index cdeeb2b..5624e69 100644
--- a/dev/BUILD
+++ b/dev/BUILD
@@ -98,7 +98,7 @@
     name = "gwt-dev-deps",
     srcs = [],
     added_jars = [
-        "//third_party/java_src/gwt/legacy:libdev.jar",
+        "//third_party/java_src/gwt/legacy:libdev-bare.jar",
         "//third_party/java_src/gwt/legacy:dev-resources.jar",
         "//third_party/java_src/gwt/svn/tools:dev_jars",
         "//third_party/java_src/gwt/svn/tools:legacy_dev_jars",
@@ -114,7 +114,7 @@
     name = "gwt-dev-only",
     srcs = [],
     added_jars = [
-        ":libgwt-dev-classes.jar",
+        ":libgwt-dev-bare.jar",
         ":gwt-dev-resources.jar",
         ":libcompiler.standalone.jar",
         ":libcompiler.standalone.super.jar",
@@ -126,14 +126,10 @@
     wrap_javalibrary = 0,
 )
 
-# All the dev classes before jarjaring.
-# This should only be used in code that will itself be jarjar-ed
-# or in internal tests.
-# (Exposed because it helps other targets build faster than
-# if they waited for gwt-dev to be jarjar-ed.)
-# TODO: split up.
+# The gwt-dev classes for GWT internal use only.
+# They must be jarjar-ed and dependencies stripped before exposing to google3.
 java_library(
-    name = "gwt-dev-classes",
+    name = "gwt-dev-bare",
     srcs = glob(
         ["core/src/**/*.java"],
         exclude = ["**/package-info.java"],
@@ -146,7 +142,6 @@
     deps = [
         ":compiler.standalone.super",
         "//third_party/java_src/gwt/svn/tools:dev_deps",
-        # Safe to depend on servlet_api_3 because no body directly depends on gwt-dev-classes
         "//third_party/java_src/gwt/svn/tools:servlet_api_3",
     ],
 )
@@ -289,28 +284,39 @@
 # TODO: split up.
 AugmentedJar(
     name = "dev-test-code",
-    srcs = glob([
-        "core/test/**/*.java",
-    ]),
+    testonly = 1,
+    srcs = [],
     added_jars = [
+        ":libdev-test-code-bare.jar",
         # for soycTest
         "//third_party/java_src/gwt/svn/trunk/samples:hello-src.jar",
     ],
     added_roots = [
         "core/test",
     ],
-    build_deps = [
-        ":gwt-dev-classes",
-        ":compiler.standalone.super",
-        "//third_party/java_src/gwt/svn/tools:dev_deps",  # for pre-jarjar imports
-    ],
     constraints = [],
     dojarjar = 1,
     export_deps = [
         ":dev",  # for the post-jarjar names
+        "//third_party/java/junit",
     ],
+)
+
+# The gwt-dev tests for GWT internal use only.
+# They must be jarjar-ed and dependencies stripped before exposing to google3.
+# TODO(skybrian): we should have a separate jar for test infrastructure and
+# and remove dependencies on this library in gwt-user and google3.
+java_library(
+    name = "dev-test-code-bare",
+    testonly = 1,
+    srcs = glob([
+        "core/test/**/*.java",
+    ]),
     deps = [
-        "//third_party/java/junit:not-testonly",
+        ":compiler.standalone.super",
+        ":gwt-dev-bare",
+        "//third_party/java/junit",
+        "//third_party/java_src/gwt/svn/tools:dev_deps",
     ],
 )
 
diff --git a/user/BUILD b/user/BUILD
index 1dd9061..03f6ed3 100644
--- a/user/BUILD
+++ b/user/BUILD
@@ -33,28 +33,15 @@
 # depend on this without also touching the compiler and shell internals.
 AugmentedJar(
     name = "gwt-user-classes-src",
-    srcs = glob(
-        ["src/**/*.java"],
-        exclude = [
-            "src/com/google/gwt/junit/**/*.java",  # see gwt-testing
-            "**/super/**",
-            "**/RunStyleSelenium.java",
-        ],
-    ),
-    added_jars = ["//third_party/java_src/gwt/svn/tools:user_jars"],
+    srcs = [],
+    added_jars = [
+        ":libgwt-user-bare.jar",
+        "//third_party/java_src/gwt/svn/tools:user_jars",
+    ],
     added_roots = [
         "src",
         "super",
     ],
-    # We only need the Java classes so don't wait for the rest of :gwt-dev.
-    build_deps = [
-        "//third_party/java_src/gwt/svn/tools:dev_deps",
-        # Safe to depend on servlet_api_3 because build_deps doesn't leak
-        "//third_party/java_src/gwt/svn/tools:servlet_api_3",
-        "//third_party/java_src/gwt/svn/trunk/dev:compiler.standalone.super",
-        "//third_party/java_src/gwt/svn/trunk/dev:gwt-dev-classes",
-        "//third_party/java/junit",
-    ],
     constraints = [],
     dojarjar = 1,
     exclude_glob = [
@@ -68,6 +55,27 @@
     wrap_javalibrary = 0,
 )
 
+# The gwt-user classes for GWT internal use only.
+# They must be jarjar-ed and dependencies stripped before exposing to google3.
+java_library(
+    name = "gwt-user-bare",
+    srcs = glob(
+        ["src/**/*.java"],
+        exclude = [
+            "src/com/google/gwt/junit/**/*.java",  # see gwt-testing
+            "**/super/**",
+            "**/RunStyleSelenium.java",
+        ],
+    ),
+    deps = [
+        "//third_party/java_src/gwt/svn/tools:dev_deps",
+        "//third_party/java_src/gwt/svn/tools:servlet_api_3",
+        "//third_party/java_src/gwt/svn/tools:user_deps",
+        "//third_party/java_src/gwt/svn/trunk/dev:compiler.standalone.super",
+        "//third_party/java_src/gwt/svn/trunk/dev:gwt-dev-bare",
+    ],
+)
+
 # This target is used by a java_plugin over in java/gwt/BUILD. It's
 # a pretty simple annotation processor, so in order to keep it from being a
 # build bottleneck, it's simply built from scratch.
@@ -107,7 +115,7 @@
         "//third_party/java_src/gwt:gwt-user-full",
         "//third_party/java_src/gwt/svn/tools:dev_deps",
         "//third_party/java_src/gwt/svn/trunk/dev:compiler.standalone.super",
-        "//third_party/java_src/gwt/svn/trunk/dev:gwt-dev-classes",
+        "//third_party/java_src/gwt/svn/trunk/dev:gwt-dev-bare",
     ],
     constraints = [],
     dojarjar = 1,
@@ -406,26 +414,14 @@
 # Instead we assume it will be added by a wrapper rule.)
 AugmentedJar(
     name = "gwt-testing",
-    srcs = glob(
-        ["src/com/google/gwt/junit/**/*.java"],
-        exclude = [
-            "**/super/**",
-            "**/RunStyleSelenium.java",
-        ],
-    ),
+    srcs = [],
+    added_jars = [
+        ":libgwt-testing-bare.jar",
+    ],
     added_root_globs = {
         "src": ["src/com/google/gwt/junit/**"],
         "super": ["super/com/google/gwt/junit/**"],
     },
-    build_deps = [
-        ":gwt-user-classes-src",
-        "//third_party/java_src/gwt/svn/tools:dev_deps",
-        # Safe to depend on servlet_api_3 because build_deps doesn't leak
-        "//third_party/java_src/gwt/svn/tools:servlet_api_3",
-        "//third_party/java_src/gwt/svn/trunk/dev:compiler.standalone.super",
-        "//third_party/java_src/gwt/svn/trunk/dev:gwt-dev-classes",
-        "//third_party/java/junit",
-    ],
     dojarjar = 1,
     exclude_glob = [
         "**/package.html",
@@ -434,10 +430,33 @@
     ],
 )
 
+# The gwt-testing classes for GWT internal use only.
+# They must be jarjar-ed and dependencies stripped before exposing to google3.
+java_library(
+    name = "gwt-testing-bare",
+    testonly = 1,
+    srcs = glob(
+        ["src/com/google/gwt/junit/**/*.java"],
+        exclude = [
+            "**/super/**",
+            "**/RunStyleSelenium.java",
+        ],
+    ),
+    deps = [
+        ":gwt-user-bare",
+        "//third_party/java/junit",
+        "//third_party/java_src/gwt/svn/tools:dev_deps",
+        "//third_party/java_src/gwt/svn/tools:servlet_api_3",
+        "//third_party/java_src/gwt/svn/trunk/dev:compiler.standalone.super",
+        "//third_party/java_src/gwt/svn/trunk/dev:gwt-dev-bare",
+    ],
+)
+
 # === TESTS ===
 
 AugmentedJar(
     name = "user-test-code",
+    testonly = 1,
     srcs = glob(
         [
             "test/**/*.java",
@@ -453,16 +472,17 @@
         "test-super",
         "test_i18n_bar",
     ],
+    # For build_deps we should use pre-jarjar dependencies (-bare)
     build_deps = [
-        ":gwt-user-classes",
-        ":gwt-user-classes_jardeps",
-        ":gwt-testing",
+        ":gwt-user-bare",
+        ":gwt-testing-bare",
         "//third_party/java_src/gwt/svn/tools:dev_deps",
-        # Safe to depend on servlet_api_3 because build_deps doesn't leak
+        "//third_party/java_src/gwt/svn/tools:user_deps",
         "//third_party/java_src/gwt/svn/tools:servlet_api_3",
-        "//third_party/java_src/gwt/svn/trunk/dev",
-        # for pre-jarjar imports
-        "//third_party/java_src/gwt/svn/trunk/dev:gwt-dev-classes",
+        "//third_party/java_src/gwt/svn/trunk/dev:gwt-dev-bare",
+        "//third_party/java_src/gwt/svn/trunk/dev:dev-test-code-bare",
+        # for @GwtScriptOnly
+        "//third_party/java_src/gwt/svn/trunk/dev:compiler.standalone.super",
     ],
     constraints = [
         "gwt",
@@ -472,15 +492,14 @@
     export_deps = [
         "//third_party/java_src/gwt:gwt-dev",  # for the post-jarjar names
         "//third_party/java_src/gwt:gwt",
+        "//third_party/java_src/gwt/svn/trunk/dev:dev-test-code",
     ],
-    # visibility = ["//third_party/java_src/gwt:friends"],
     deps = [
         "//third_party/java/jsr305_annotations",
         "//third_party/java/junit",
         "//third_party/java_src/gwt/svn/tools:testtool_deps",
         "//third_party/java_src/gwt/svn/tools:validator_deps",
         "//third_party/java_src/gwt/svn/tools:validator_tck_deps",
-        "//third_party/java_src/gwt/svn/trunk/dev:dev-test-code",
     ],
 )