aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/java_tools
diff options
context:
space:
mode:
authorGravatar Irina Iancu <elenairina@google.com>2016-08-31 09:27:43 +0000
committerGravatar Klaus Aehlig <aehlig@google.com>2016-08-31 14:51:28 +0000
commit4d144f4fced4c8972b88ffc111f8486896a47e5f (patch)
treefc6e6b3158d1b9aa371d9a022d5cfac39878cdd5 /src/java_tools
parentced6b3765fb6a540f70984043e98304b8fd7d7b0 (diff)
Removing GUAVA Suppliers and Supplier as dependency from junitrunner.
Bazel users that are using a different Guava version than the one in the junitrunner jar are getting an IncompatibleClassChangeError. Rewriting parts of junitrunner code so it won't depend on Guava anymore. Continuing progress on issue #1150. -- MOS_MIGRATED_REVID=131807036
Diffstat (limited to 'src/java_tools')
-rw-r--r--src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4Runner.java3
-rw-r--r--src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4RunnerBaseModule.java7
-rw-r--r--src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4TestModelBuilder.java2
-rw-r--r--src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4TestXmlListener.java3
-rw-r--r--src/java_tools/junitrunner/java/com/google/testing/junit/runner/util/MemoizingSupplier.java49
-rw-r--r--src/java_tools/junitrunner/java/com/google/testing/junit/runner/util/Supplier.java31
6 files changed, 86 insertions, 9 deletions
diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4Runner.java b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4Runner.java
index 1c67697eab..b288298363 100644
--- a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4Runner.java
+++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4Runner.java
@@ -14,12 +14,11 @@
package com.google.testing.junit.runner.junit4;
-import com.google.common.base.Supplier;
import com.google.testing.junit.junit4.runner.SuiteTrimmingFilter;
import com.google.testing.junit.runner.internal.Stdout;
import com.google.testing.junit.runner.model.TestSuiteModel;
import com.google.testing.junit.runner.util.GoogleTestSecurityManager;
-
+import com.google.testing.junit.runner.util.Supplier;
import org.junit.internal.runners.ErrorReportingRunner;
import org.junit.runner.Description;
import org.junit.runner.JUnitCore;
diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4RunnerBaseModule.java b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4RunnerBaseModule.java
index 2da89af2bd..395daaffe0 100644
--- a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4RunnerBaseModule.java
+++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4RunnerBaseModule.java
@@ -16,14 +16,13 @@ package com.google.testing.junit.runner.junit4;
import static com.google.testing.junit.runner.sharding.ShardingFilters.DEFAULT_SHARDING_STRATEGY;
-import com.google.common.base.Supplier;
-import com.google.common.base.Suppliers;
import com.google.testing.junit.junit4.runner.MemoizingRequest;
import com.google.testing.junit.runner.internal.Stdout;
import com.google.testing.junit.runner.junit4.JUnit4InstanceModules.SuiteClass;
import com.google.testing.junit.runner.model.TestSuiteModel;
import com.google.testing.junit.runner.sharding.api.ShardingFilterFactory;
-
+import com.google.testing.junit.runner.util.MemoizingSupplier;
+import com.google.testing.junit.runner.util.Supplier;
import dagger.Module;
import dagger.Multibindings;
import dagger.Provides;
@@ -70,7 +69,7 @@ public final class JUnit4RunnerBaseModule {
@Provides
@Singleton
static Supplier<TestSuiteModel> provideTestSuiteModelSupplier(JUnit4TestModelBuilder builder) {
- return Suppliers.memoize(builder);
+ return new MemoizingSupplier<>(builder);
}
@Provides
diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4TestModelBuilder.java b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4TestModelBuilder.java
index c0b50e989d..56d57c1d86 100644
--- a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4TestModelBuilder.java
+++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4TestModelBuilder.java
@@ -14,9 +14,9 @@
package com.google.testing.junit.runner.junit4;
-import com.google.common.base.Supplier;
import com.google.testing.junit.runner.model.TestSuiteModel;
import com.google.testing.junit.runner.model.TestSuiteModel.Builder;
+import com.google.testing.junit.runner.util.Supplier;
import org.junit.runner.Description;
import org.junit.runner.Request;
diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4TestXmlListener.java b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4TestXmlListener.java
index d76c7f6f0c..5ff9dc24f1 100644
--- a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4TestXmlListener.java
+++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4TestXmlListener.java
@@ -14,11 +14,10 @@
package com.google.testing.junit.runner.junit4;
-import com.google.common.base.Supplier;
import com.google.testing.junit.runner.internal.SignalHandlers;
import com.google.testing.junit.runner.internal.Stderr;
import com.google.testing.junit.runner.model.TestSuiteModel;
-
+import com.google.testing.junit.runner.util.Supplier;
import org.junit.Ignore;
import org.junit.runner.Description;
import org.junit.runner.Result;
diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/util/MemoizingSupplier.java b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/util/MemoizingSupplier.java
new file mode 100644
index 0000000000..5f01d20ad3
--- /dev/null
+++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/util/MemoizingSupplier.java
@@ -0,0 +1,49 @@
+// Copyright 2016 The Bazel Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.testing.junit.runner.util;
+
+/**
+ * Returns a {@link Supplier} which caches the instance retrieved during the first call to
+ * {@code get()} and returns that value on subsequent calls to {@code get()}. See:
+ * <a href="http://en.wikipedia.org/wiki/Memoization">memoization</a>.
+ *
+ * <p>The returned supplier is thread-safe. The delegate's {@code get()} method will be invoked at
+ * most once.
+ *
+ * <p>The returned supplier is not serializable.
+ */
+public class MemoizingSupplier<T> implements Supplier<T> {
+ private final Supplier<T> delegate;
+ private volatile boolean initialized;
+ private T instance;
+
+ public MemoizingSupplier(Supplier<T> delegate) {
+ this.delegate = delegate;
+ }
+
+ @Override
+ public T get() {
+ if (!initialized) {
+ synchronized (this) {
+ if (!initialized) {
+ initialized = true;
+ instance = delegate.get();
+ }
+ }
+ }
+ return instance;
+ }
+}
+
diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/util/Supplier.java b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/util/Supplier.java
new file mode 100644
index 0000000000..97de3fdb7c
--- /dev/null
+++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/util/Supplier.java
@@ -0,0 +1,31 @@
+// Copyright 2016 The Bazel Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.testing.junit.runner.util;
+
+
+/**
+ * A class that can supply objects of a single type. Semantically, this could be a factory,
+ * generator, builder, closure, or something else entirely. No guarantees are implied by this
+ * interface.
+ */
+public interface Supplier<T> {
+ /**
+ * Retrieves an instance of the appropriate type. The returned object may or may not be a new
+ * instance, depending on the implementation.
+ *
+ * @return an instance of the appropriate type
+ */
+ T get();
+} \ No newline at end of file