From 9cffbe5017dd5d3f82bf81a06c0df5b00e2f6635 Mon Sep 17 00:00:00 2001 From: cpovirk Date: Tue, 23 Mar 2021 12:11:50 -0700 Subject: [PATCH] Set `-source 8 -target 8` in the open-source build, and remove Java8Usage. This is largely a rollback of the original Java8Usage change, but I've modified it in a few ways: - I set `-source 8 -target 8` in the backport. - I kept the code to make includes/excludes fully work with maven-compiler-plugin, since that could save us some confusion down the line. - I incorporated a rollback of the changes to Preconditions from CL 361700569, in which I moved the warning from MoreObjects to Preconditions. - I added errors to our internal release scripts so that we don't accidentally make a release that drops Java 7 support before we're ready. Fixes https://github.com/google/guava/issues/5269 PiperOrigin-RevId: 364614257 --- android/guava/pom.xml | 36 --------------- .../com/google/common/base/Java8Usage.java | 45 ------------------- .../com/google/common/base/Preconditions.java | 19 -------- android/pom.xml | 4 +- guava/pom.xml | 36 --------------- .../com/google/common/base/Java8Usage.java | 45 ------------------- .../com/google/common/base/Preconditions.java | 19 -------- 7 files changed, 2 insertions(+), 202 deletions(-) delete mode 100755 android/guava/src/com/google/common/base/Java8Usage.java delete mode 100644 guava/src/com/google/common/base/Java8Usage.java diff --git a/android/guava/pom.xml b/android/guava/pom.xml index 2997108a20e2..ed15b827e213 100644 --- a/android/guava/pom.xml +++ b/android/guava/pom.xml @@ -90,42 +90,6 @@ maven-compiler-plugin - - - - default-compile - compile - - compile - - - - **/Java8Usage.java - - - 8 - 8 - - - - main-compile - compile - - compile - - - - **/Java8Usage.java - - - - maven-source-plugin diff --git a/android/guava/src/com/google/common/base/Java8Usage.java b/android/guava/src/com/google/common/base/Java8Usage.java deleted file mode 100755 index 78130cf676d9..000000000000 --- a/android/guava/src/com/google/common/base/Java8Usage.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (C) 2020 The Guava Authors - * - * 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.base; - -import com.google.errorprone.annotations.CanIgnoreReturnValue; - -/** - * A class that uses a couple Java 8 features but doesn't really do anything. This lets us attempt - * to load it and log a warning if that fails, giving users advance notice of our dropping Java 8 - * support. - */ -/* - * This class should be annotated @GwtCompatible. But if we annotate it @GwtCompatible, then we need - * to build GwtCompatible.java (-source 7 -target 7 in the Android flavor) before we build - * Java8Usage.java (-source 8 target 8, which we already need to build before the rest of - * common.base). We could configure Maven to do that, but it's easier to just skip the annotation. - */ -final class Java8Usage { - @java.lang.annotation.Target(java.lang.annotation.ElementType.TYPE_USE) - @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME) - private @interface SomeTypeAnnotation {} - - @CanIgnoreReturnValue - static @SomeTypeAnnotation String performCheck() { - Runnable r = () -> {}; - r.run(); - return ""; - } - - private Java8Usage() {} -} diff --git a/android/guava/src/com/google/common/base/Preconditions.java b/android/guava/src/com/google/common/base/Preconditions.java index 38f665463f7a..995d3945e59b 100644 --- a/android/guava/src/com/google/common/base/Preconditions.java +++ b/android/guava/src/com/google/common/base/Preconditions.java @@ -15,11 +15,9 @@ package com.google.common.base; import static com.google.common.base.Strings.lenientFormat; -import static java.util.logging.Level.WARNING; import com.google.common.annotations.GwtCompatible; import com.google.errorprone.annotations.CanIgnoreReturnValue; -import java.util.logging.Logger; import org.checkerframework.checker.nullness.compatqual.NonNullDecl; import org.checkerframework.checker.nullness.compatqual.NullableDecl; @@ -1490,21 +1488,4 @@ private static String badPositionIndexes(int start, int end, int size) { // end < start return lenientFormat("end index (%s) must not be less than start index (%s)", end, start); } - - static { - try { - Java8Usage.performCheck(); - } catch (Throwable underlying) { - Exception toLog = - new Exception( - "Guava will drop support for Java 7 in 2021. Please let us know if this will cause" - + " you problems: https://github.com/google/guava/issues/5269", - underlying); - Logger.getLogger(Preconditions.class.getName()) - .log( - WARNING, - "Java 7 compatibility warning: See https://github.com/google/guava/issues/5269", - toLog); - } - } } diff --git a/android/pom.xml b/android/pom.xml index 96d2bd7a6f0a..c802ca337186 100644 --- a/android/pom.xml +++ b/android/pom.xml @@ -132,8 +132,8 @@ maven-compiler-plugin 3.8.1 - 1.7 - 1.7 + 1.8 + 1.8 - default-compile - compile - - compile - - - - **/Java8Usage.java - - - 8 - 8 - - - - main-compile - compile - - compile - - - - **/Java8Usage.java - - - - maven-source-plugin diff --git a/guava/src/com/google/common/base/Java8Usage.java b/guava/src/com/google/common/base/Java8Usage.java deleted file mode 100644 index 78130cf676d9..000000000000 --- a/guava/src/com/google/common/base/Java8Usage.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (C) 2020 The Guava Authors - * - * 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.base; - -import com.google.errorprone.annotations.CanIgnoreReturnValue; - -/** - * A class that uses a couple Java 8 features but doesn't really do anything. This lets us attempt - * to load it and log a warning if that fails, giving users advance notice of our dropping Java 8 - * support. - */ -/* - * This class should be annotated @GwtCompatible. But if we annotate it @GwtCompatible, then we need - * to build GwtCompatible.java (-source 7 -target 7 in the Android flavor) before we build - * Java8Usage.java (-source 8 target 8, which we already need to build before the rest of - * common.base). We could configure Maven to do that, but it's easier to just skip the annotation. - */ -final class Java8Usage { - @java.lang.annotation.Target(java.lang.annotation.ElementType.TYPE_USE) - @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME) - private @interface SomeTypeAnnotation {} - - @CanIgnoreReturnValue - static @SomeTypeAnnotation String performCheck() { - Runnable r = () -> {}; - r.run(); - return ""; - } - - private Java8Usage() {} -} diff --git a/guava/src/com/google/common/base/Preconditions.java b/guava/src/com/google/common/base/Preconditions.java index 3dd679ddeacf..30cc374d21d2 100644 --- a/guava/src/com/google/common/base/Preconditions.java +++ b/guava/src/com/google/common/base/Preconditions.java @@ -15,11 +15,9 @@ package com.google.common.base; import static com.google.common.base.Strings.lenientFormat; -import static java.util.logging.Level.WARNING; import com.google.common.annotations.GwtCompatible; import com.google.errorprone.annotations.CanIgnoreReturnValue; -import java.util.logging.Logger; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; @@ -1433,21 +1431,4 @@ private static String badPositionIndexes(int start, int end, int size) { // end < start return lenientFormat("end index (%s) must not be less than start index (%s)", end, start); } - - static { - try { - Java8Usage.performCheck(); - } catch (Throwable underlying) { - Exception toLog = - new Exception( - "Guava will drop support for Java 7 in 2021. Please let us know if this will cause" - + " you problems: https://github.com/google/guava/issues/5269", - underlying); - Logger.getLogger(Preconditions.class.getName()) - .log( - WARNING, - "Java 7 compatibility warning: See https://github.com/google/guava/issues/5269", - toLog); - } - } }