From eb0426eb76494aa439ec7297ade9a1ec40ed47ee Mon Sep 17 00:00:00 2001 From: cpovirk Date: Wed, 10 Jan 2024 07:22:36 -0800 Subject: [PATCH] Move `truth-java8-extension` classes into the main `truth` artifact. While there, make some minor changes to prepare for moving the `Truth8` methods into `Truth`. This is the first step of https://github.com/google/truth/issues/746. RELNOTES=Moved the `truth-java8-extension` classes into the main `truth` artifact. There is no longer any need to depend on `truth-java8-extension`, which is now empty. (We've also removed the `Truth8` [GWT](https://www.gwtproject.org/) module.) PiperOrigin-RevId: 597243015 --- .../common/truth/IgnoreJRERequirement.java | 29 +++++++++++++++ .../google/common/truth/IntStreamSubject.java | 8 +++-- .../common/truth/LongStreamSubject.java | 8 +++-- .../common/truth/OptionalDoubleSubject.java | 2 ++ .../common/truth/OptionalIntSubject.java | 2 ++ .../common/truth/OptionalLongSubject.java | 2 ++ .../google/common/truth/OptionalSubject.java | 2 ++ .../com/google/common/truth/PathSubject.java | 3 +- .../common/truth/StandardSubjectBuilder.java | 3 +- .../google/common/truth/StreamSubject.java | 8 +++-- .../java/com/google/common/truth/Truth.java | 4 +-- .../java/com/google/common/truth/Truth8.java | 3 ++ .../google/common/truth/gwt/Inventory.java | 16 +++++++++ .../google/common/truth/gwt/TruthTest.gwt.xml | 1 - .../com/google/common/truth/Truth8.gwt.xml | 35 ------------------- pom.xml | 1 + 16 files changed, 80 insertions(+), 47 deletions(-) create mode 100644 core/src/main/java/com/google/common/truth/IgnoreJRERequirement.java rename {extensions/java8 => core}/src/main/java/com/google/common/truth/IntStreamSubject.java (96%) rename {extensions/java8 => core}/src/main/java/com/google/common/truth/LongStreamSubject.java (96%) rename {extensions/java8 => core}/src/main/java/com/google/common/truth/OptionalDoubleSubject.java (96%) rename {extensions/java8 => core}/src/main/java/com/google/common/truth/OptionalIntSubject.java (95%) rename {extensions/java8 => core}/src/main/java/com/google/common/truth/OptionalLongSubject.java (95%) rename {extensions/java8 => core}/src/main/java/com/google/common/truth/OptionalSubject.java (96%) rename {extensions/java8 => core}/src/main/java/com/google/common/truth/PathSubject.java (92%) rename {extensions/java8 => core}/src/main/java/com/google/common/truth/StreamSubject.java (97%) rename {extensions/java8 => core}/src/main/java/com/google/common/truth/Truth8.java (95%) delete mode 100644 extensions/java8/src/main/java/com/google/common/truth/Truth8.gwt.xml diff --git a/core/src/main/java/com/google/common/truth/IgnoreJRERequirement.java b/core/src/main/java/com/google/common/truth/IgnoreJRERequirement.java new file mode 100644 index 0000000000..a2d4842727 --- /dev/null +++ b/core/src/main/java/com/google/common/truth/IgnoreJRERequirement.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2019 Google, Inc. + * + * 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.common.truth; + +import static java.lang.annotation.ElementType.CONSTRUCTOR; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Target; + +/** + * Disables Animal Sniffer's checking of compatibility with older versions of Java/Android. + */ +@Target({METHOD, CONSTRUCTOR, TYPE}) +@interface IgnoreJRERequirement {} diff --git a/extensions/java8/src/main/java/com/google/common/truth/IntStreamSubject.java b/core/src/main/java/com/google/common/truth/IntStreamSubject.java similarity index 96% rename from extensions/java8/src/main/java/com/google/common/truth/IntStreamSubject.java rename to core/src/main/java/com/google/common/truth/IntStreamSubject.java index 45699bce8b..95270b61fa 100644 --- a/extensions/java8/src/main/java/com/google/common/truth/IntStreamSubject.java +++ b/core/src/main/java/com/google/common/truth/IntStreamSubject.java @@ -40,12 +40,16 @@ * * @author Kurt Alfred Kluever */ -@SuppressWarnings("deprecation") // TODO(b/134064106): design an alternative to no-arg check() +@SuppressWarnings({ + "deprecation", // TODO(b/134064106): design an alternative to no-arg check() + "Java7ApiChecker", // used only from APIs with Java 8 in their signatures +}) +@IgnoreJRERequirement public final class IntStreamSubject extends Subject { private final List actualList; - private IntStreamSubject(FailureMetadata failureMetadata, @Nullable IntStream stream) { + IntStreamSubject(FailureMetadata failureMetadata, @Nullable IntStream stream) { super(failureMetadata, stream); this.actualList = (stream == null) ? null : stream.boxed().collect(toCollection(ArrayList::new)); diff --git a/extensions/java8/src/main/java/com/google/common/truth/LongStreamSubject.java b/core/src/main/java/com/google/common/truth/LongStreamSubject.java similarity index 96% rename from extensions/java8/src/main/java/com/google/common/truth/LongStreamSubject.java rename to core/src/main/java/com/google/common/truth/LongStreamSubject.java index 0a5c22557c..70213a5cd8 100644 --- a/extensions/java8/src/main/java/com/google/common/truth/LongStreamSubject.java +++ b/core/src/main/java/com/google/common/truth/LongStreamSubject.java @@ -40,12 +40,16 @@ * * @author Kurt Alfred Kluever */ -@SuppressWarnings("deprecation") // TODO(b/134064106): design an alternative to no-arg check() +@SuppressWarnings({ + "deprecation", // TODO(b/134064106): design an alternative to no-arg check() + "Java7ApiChecker", // used only from APIs with Java 8 in their signatures +}) +@IgnoreJRERequirement public final class LongStreamSubject extends Subject { private final List actualList; - private LongStreamSubject(FailureMetadata failureMetadata, @Nullable LongStream stream) { + LongStreamSubject(FailureMetadata failureMetadata, @Nullable LongStream stream) { super(failureMetadata, stream); this.actualList = (stream == null) ? null : stream.boxed().collect(toCollection(ArrayList::new)); diff --git a/extensions/java8/src/main/java/com/google/common/truth/OptionalDoubleSubject.java b/core/src/main/java/com/google/common/truth/OptionalDoubleSubject.java similarity index 96% rename from extensions/java8/src/main/java/com/google/common/truth/OptionalDoubleSubject.java rename to core/src/main/java/com/google/common/truth/OptionalDoubleSubject.java index 4a9aa5f88b..7265fcac8a 100644 --- a/extensions/java8/src/main/java/com/google/common/truth/OptionalDoubleSubject.java +++ b/core/src/main/java/com/google/common/truth/OptionalDoubleSubject.java @@ -26,6 +26,8 @@ * * @author Ben Douglass */ +@SuppressWarnings("Java7ApiChecker") // used only from APIs with Java 8 in their signatures +@IgnoreJRERequirement public final class OptionalDoubleSubject extends Subject { private final OptionalDouble actual; diff --git a/extensions/java8/src/main/java/com/google/common/truth/OptionalIntSubject.java b/core/src/main/java/com/google/common/truth/OptionalIntSubject.java similarity index 95% rename from extensions/java8/src/main/java/com/google/common/truth/OptionalIntSubject.java rename to core/src/main/java/com/google/common/truth/OptionalIntSubject.java index 957594f720..cafdd5aff0 100644 --- a/extensions/java8/src/main/java/com/google/common/truth/OptionalIntSubject.java +++ b/core/src/main/java/com/google/common/truth/OptionalIntSubject.java @@ -26,6 +26,8 @@ * * @author Ben Douglass */ +@SuppressWarnings("Java7ApiChecker") // used only from APIs with Java 8 in their signatures +@IgnoreJRERequirement public final class OptionalIntSubject extends Subject { private final OptionalInt actual; diff --git a/extensions/java8/src/main/java/com/google/common/truth/OptionalLongSubject.java b/core/src/main/java/com/google/common/truth/OptionalLongSubject.java similarity index 95% rename from extensions/java8/src/main/java/com/google/common/truth/OptionalLongSubject.java rename to core/src/main/java/com/google/common/truth/OptionalLongSubject.java index 9b57b9a4a9..ab770a3237 100644 --- a/extensions/java8/src/main/java/com/google/common/truth/OptionalLongSubject.java +++ b/core/src/main/java/com/google/common/truth/OptionalLongSubject.java @@ -26,6 +26,8 @@ * * @author Ben Douglass */ +@SuppressWarnings("Java7ApiChecker") // used only from APIs with Java 8 in their signatures +@IgnoreJRERequirement public final class OptionalLongSubject extends Subject { private final OptionalLong actual; diff --git a/extensions/java8/src/main/java/com/google/common/truth/OptionalSubject.java b/core/src/main/java/com/google/common/truth/OptionalSubject.java similarity index 96% rename from extensions/java8/src/main/java/com/google/common/truth/OptionalSubject.java rename to core/src/main/java/com/google/common/truth/OptionalSubject.java index 65ca4dae95..8fa39adffa 100644 --- a/extensions/java8/src/main/java/com/google/common/truth/OptionalSubject.java +++ b/core/src/main/java/com/google/common/truth/OptionalSubject.java @@ -26,6 +26,8 @@ * * @author Christian Gruber */ +@SuppressWarnings("Java7ApiChecker") // used only from APIs with Java 8 in their signatures +@IgnoreJRERequirement public final class OptionalSubject extends Subject { private final @Nullable Optional actual; diff --git a/extensions/java8/src/main/java/com/google/common/truth/PathSubject.java b/core/src/main/java/com/google/common/truth/PathSubject.java similarity index 92% rename from extensions/java8/src/main/java/com/google/common/truth/PathSubject.java rename to core/src/main/java/com/google/common/truth/PathSubject.java index 0be8532e05..f98c60093e 100644 --- a/extensions/java8/src/main/java/com/google/common/truth/PathSubject.java +++ b/core/src/main/java/com/google/common/truth/PathSubject.java @@ -22,8 +22,9 @@ /** Assertions for {@link Path} instances. */ @GwtIncompatible @J2ObjCIncompatible +@J2ktIncompatible public final class PathSubject extends Subject { - private PathSubject(FailureMetadata failureMetadata, Path actual) { + PathSubject(FailureMetadata failureMetadata, Path actual) { super(failureMetadata, actual); } diff --git a/core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java b/core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java index f41fb486f3..0d90808b75 100644 --- a/core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java +++ b/core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java @@ -18,7 +18,6 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.annotations.GwtIncompatible; -import com.google.common.base.Optional; import com.google.common.collect.ImmutableList; import com.google.common.collect.Multimap; import com.google.common.collect.Multiset; @@ -149,7 +148,7 @@ public final PrimitiveDoubleArraySubject that(double @Nullable [] actual) { return new PrimitiveDoubleArraySubject(metadata(), actual, "array"); } - public final GuavaOptionalSubject that(@Nullable Optional actual) { + public final GuavaOptionalSubject that(com.google.common.base.@Nullable Optional actual) { return new GuavaOptionalSubject(metadata(), actual, "optional"); } diff --git a/extensions/java8/src/main/java/com/google/common/truth/StreamSubject.java b/core/src/main/java/com/google/common/truth/StreamSubject.java similarity index 97% rename from extensions/java8/src/main/java/com/google/common/truth/StreamSubject.java rename to core/src/main/java/com/google/common/truth/StreamSubject.java index f3e90cd6e4..45ed8f5f21 100644 --- a/extensions/java8/src/main/java/com/google/common/truth/StreamSubject.java +++ b/core/src/main/java/com/google/common/truth/StreamSubject.java @@ -40,12 +40,16 @@ * * @author Kurt Alfred Kluever */ -@SuppressWarnings("deprecation") // TODO(b/134064106): design an alternative to no-arg check() +@SuppressWarnings({ + "deprecation", // TODO(b/134064106): design an alternative to no-arg check() + "Java7ApiChecker", // used only from APIs with Java 8 in their signatures +}) +@IgnoreJRERequirement public final class StreamSubject extends Subject { private final List actualList; - private StreamSubject(FailureMetadata failureMetadata, @Nullable Stream stream) { + StreamSubject(FailureMetadata failureMetadata, @Nullable Stream stream) { super(failureMetadata, stream); this.actualList = (stream == null) ? null : stream.collect(toCollection(ArrayList::new)); } diff --git a/core/src/main/java/com/google/common/truth/Truth.java b/core/src/main/java/com/google/common/truth/Truth.java index 1afbccaa17..6cf4ca7e89 100644 --- a/core/src/main/java/com/google/common/truth/Truth.java +++ b/core/src/main/java/com/google/common/truth/Truth.java @@ -18,7 +18,6 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.annotations.GwtIncompatible; -import com.google.common.base.Optional; import com.google.common.collect.Multimap; import com.google.common.collect.Multiset; import com.google.common.collect.Table; @@ -229,7 +228,8 @@ public static PrimitiveDoubleArraySubject assertThat(double @Nullable [] actual) return assert_().that(actual); } - public static GuavaOptionalSubject assertThat(@Nullable Optional actual) { + public static GuavaOptionalSubject assertThat( + com.google.common.base.@Nullable Optional actual) { return assert_().that(actual); } diff --git a/extensions/java8/src/main/java/com/google/common/truth/Truth8.java b/core/src/main/java/com/google/common/truth/Truth8.java similarity index 95% rename from extensions/java8/src/main/java/com/google/common/truth/Truth8.java rename to core/src/main/java/com/google/common/truth/Truth8.java index c156c54b86..c34a975130 100644 --- a/extensions/java8/src/main/java/com/google/common/truth/Truth8.java +++ b/core/src/main/java/com/google/common/truth/Truth8.java @@ -43,6 +43,8 @@ * How do I specify a custom message/failure * behavior/{@code Subject} type? in the Truth FAQ. */ +// The methods here are no more dangerous that wherever the user got the (e.g.) Stream. +@SuppressWarnings("Java7ApiChecker") public final class Truth8 { @SuppressWarnings("AssertAboutOptionals") // suggests infinite recursion public static OptionalSubject assertThat(@Nullable Optional target) { @@ -79,6 +81,7 @@ public static LongStreamSubject assertThat(@Nullable LongStream target) { // to support Java environments without java.nio.file such as Android and J2CL. @GwtIncompatible @J2ObjCIncompatible + @J2ktIncompatible public static PathSubject assertThat(@Nullable Path target) { return assertAbout(PathSubject.paths()).that(target); } diff --git a/core/src/test/java/com/google/common/truth/gwt/Inventory.java b/core/src/test/java/com/google/common/truth/gwt/Inventory.java index 63e2fbcc1f..96ce5e1ebe 100644 --- a/core/src/test/java/com/google/common/truth/gwt/Inventory.java +++ b/core/src/test/java/com/google/common/truth/gwt/Inventory.java @@ -23,13 +23,19 @@ import com.google.common.truth.FailureStrategy; import com.google.common.truth.FloatSubject; import com.google.common.truth.GuavaOptionalSubject; +import com.google.common.truth.IntStreamSubject; import com.google.common.truth.IntegerSubject; import com.google.common.truth.IterableSubject; +import com.google.common.truth.LongStreamSubject; import com.google.common.truth.LongSubject; import com.google.common.truth.MapSubject; import com.google.common.truth.MultimapSubject; import com.google.common.truth.MultisetSubject; import com.google.common.truth.ObjectArraySubject; +import com.google.common.truth.OptionalDoubleSubject; +import com.google.common.truth.OptionalIntSubject; +import com.google.common.truth.OptionalLongSubject; +import com.google.common.truth.OptionalSubject; import com.google.common.truth.Ordered; import com.google.common.truth.PrimitiveBooleanArraySubject; import com.google.common.truth.PrimitiveByteArraySubject; @@ -39,11 +45,13 @@ import com.google.common.truth.PrimitiveIntArraySubject; import com.google.common.truth.PrimitiveLongArraySubject; import com.google.common.truth.PrimitiveShortArraySubject; +import com.google.common.truth.StreamSubject; import com.google.common.truth.StringSubject; import com.google.common.truth.Subject; import com.google.common.truth.TableSubject; import com.google.common.truth.ThrowableSubject; import com.google.common.truth.Truth; +import com.google.common.truth.Truth8; import com.google.common.truth.TruthJUnit; /** @@ -59,12 +67,18 @@ public class Inventory { FloatSubject floatSubject; GuavaOptionalSubject guavaOptionalSubject; IntegerSubject integerSubject; + IntStreamSubject intStreamSubject; IterableSubject iterableSubject; LongSubject longSubject; + LongStreamSubject longStreamSubject; MapSubject mapSubject; MultimapSubject multimapSubject; MultisetSubject multisetSubject; ObjectArraySubject objectArraySubject; + OptionalSubject optionalSubject; + OptionalDoubleSubject optionalDoubleSubject; + OptionalIntSubject optionalIntSubject; + OptionalLongSubject optionalLongSubject; Ordered ordered; PrimitiveBooleanArraySubject primitiveBooleanArraySubject; PrimitiveByteArraySubject primitiveByteArraySubject; @@ -74,11 +88,13 @@ public class Inventory { PrimitiveIntArraySubject primitiveIntArraySubject; PrimitiveLongArraySubject primitiveLongArraySubject; PrimitiveShortArraySubject primitiveShortArraySubject; + StreamSubject streamSubject; StringSubject stringSubject; Subject.Factory subjectFactory; Subject subject; TableSubject tableSubject; ThrowableSubject throwableSubject; Truth truth; + Truth8 truth8; TruthJUnit truthJUnit; } diff --git a/core/src/test/java/com/google/common/truth/gwt/TruthTest.gwt.xml b/core/src/test/java/com/google/common/truth/gwt/TruthTest.gwt.xml index ee9caccb99..a0362fbd8b 100644 --- a/core/src/test/java/com/google/common/truth/gwt/TruthTest.gwt.xml +++ b/core/src/test/java/com/google/common/truth/gwt/TruthTest.gwt.xml @@ -3,6 +3,5 @@ - diff --git a/extensions/java8/src/main/java/com/google/common/truth/Truth8.gwt.xml b/extensions/java8/src/main/java/com/google/common/truth/Truth8.gwt.xml deleted file mode 100644 index f9aa5adff7..0000000000 --- a/extensions/java8/src/main/java/com/google/common/truth/Truth8.gwt.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - - - - diff --git a/pom.xml b/pom.xml index 0962f1d433..d66034df07 100644 --- a/pom.xml +++ b/pom.xml @@ -263,6 +263,7 @@ animal-sniffer-maven-plugin 1.23 + com.google.common.truth.IgnoreJRERequirement com.toasttab.android gummy-bears-api-19