Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Guava to 28.1 #10394

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions third_party/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ distrib_java_import(
enable_distributions = ["debian"],
jars = [
"android_common/com.android.tools.layoutlib_layoutlib_26.1.2-stripped.jar",
"android_common/com.android.tools_sdk-common_25.0.0-stripped.jar",
"android_common/com.android.tools_sdk-common_25.0.0-patched-stripped.jar",
"android_common/com.android.tools_repository_25.0.0.jar",
],
deps = [
Expand Down Expand Up @@ -103,7 +103,7 @@ java_import(
"android_common/com.android.tools_common_25.0.0.jar",
"android_common/com.android.tools_dvlib_25.0.0.jar",
"android_common/com.android.tools_repository_25.0.0.jar",
"android_common/com.android.tools_sdk-common_25.0.0.jar",
"android_common/com.android.tools_sdk-common_25.0.0-patched.jar",
"android_common/com.android.tools_sdklib_25.0.0.jar",
],
runtime_deps = [
Expand Down Expand Up @@ -455,7 +455,10 @@ filegroup(
distrib_java_import(
name = "guava",
enable_distributions = ["debian"],
jars = ["guava/guava-25.1-jre.jar"],
jars = [
"guava/failureaccess-1.0.1.jar",
"guava/guava-29.0-jre.jar",
],
exports = [
":error_prone_annotations",
":jcip_annotations",
Expand Down Expand Up @@ -503,7 +506,7 @@ distrib_java_import(
# For bootstrapping JavaBuilder
distrib_jar_filegroup(
name = "guava-jars",
srcs = ["guava/guava-25.1-jre.jar"],
srcs = ["guava/guava-29.0-jre.jar"],
enable_distributions = ["debian"],
)

Expand Down Expand Up @@ -620,7 +623,7 @@ java_import(

java_import(
name = "guava-testlib",
jars = ["guava/guava-testlib-25.1-jre.jar"],
jars = ["guava/guava-testlib-29.0-jre.jar"],
)

java_import(
Expand Down
43 changes: 42 additions & 1 deletion third_party/android_common/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,51 @@ For more information, see <https://github.com/bazelbuild/bazel/issues/6645>.

--

To avoid using symbols which were removed in modern Guava versions,
`com.android.tools_sdk-common_25.0.0-patched.jar` contains several patched
classes. Steps to create the patched jar:

1. `git clone https://android.googlesource.com/platform/tools/base`
2. `git checkout 3882fb8c9281a33c56377f20e865c8a858ee50d9`

This commit corresponds to the `studio-2.0` tag, which corresponds to the
`sdk-common:25.0.0` artifact (apparently undocumented, but determined by
diffing against the sources.jar).

3. `git am $BAZEL/third_party/android_common/sdk-common-guava.patch`

This fixes the use of symbols removed in modern Guava versions
(`CharMatcher.JAVA_LETTER`, `Objects.firstNonNull`, and
`Objects.toStringHelper`).

4. `git am $BAZEL/third_party/android_common/sdk-common-maven.patch`

This adds a usable pom.xml to allow rebuilding `sdk-common` using Maven
(instead of Gradle with a specific version of the `sdk-java-lib` plugin,
which is not easy to use/obtain) and fixes a build failure with modern JDKs.

5. `mvn compile`
6. ```shell
curl -L -o sdk-common-25.0.0-patched.jar \
https://repo1.maven.org/maven2/com/android/tools/sdk-common/25.0.0/sdk-common-25.0.0.jar
```
7. ```shell
cd target/classes && \
jar ufv ../../sdk-common-25.0.0-patched.jar \
com/android/ide/common/res2/DataSet*.class \
com/android/ide/common/res2/MergeConsumer*.class \
com/android/ide/common/res2/MergingException*.class \
com/android/ide/common/res2/ResourceFile*.class \
com/android/ide/common/res2/ResourceSet*.class \
com/android/ide/common/resources/configuration/LocaleQualifier.class
```

--

The following jars contain the same contents as their versions without
-stripped, except that we removed some classes from them.
* com.android.tools.layoutlib_layoutlib_26.1.2-stripped.jar
* com.android.tools_sdk-common_25.0.0-stripped.jar
* com.android.tools_sdk-common_25.0.0-patched-stripped.jar

Classes removed:
com/android/ide/common/util/AssetUtil.class
Expand Down
Binary file not shown.
Binary file not shown.
157 changes: 157 additions & 0 deletions third_party/android_common/sdk-common-guava.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
From ef147e98b0f59abea189a1d9ece3171f0442fa90 Mon Sep 17 00:00:00 2001
From: Alexandre Rostovtsev <[email protected]>
Date: Wed, 15 Jul 2020 13:05:56 -0400
Subject: [PATCH 1/2] Fix compatibility with Guava 26 and higher

Objects.firstNonNull() and toStringHelper() were moved to MoreObjects in
Guava 18 and the Objects.* aliases were removed in Guava 21; see
https://github.com/google/guava/commit/39534cb20b1ae63e5a516ceacd9ba71fddeaa8c5 and
https://github.com/google/guava/commit/f67ab864bde63fa6602b5688de0440957ffeaa2e

CharMatcher.JAVA_LETTER was removed in Guava 26;
CharMatcher.javaLetter() is exactly equivalent (but also deprecated).
See https://github.com/google/guava/commit/f1249c4f0449260ff123e8da6b921a37fc058147
---
.../src/main/java/com/android/ide/common/res2/DataSet.java | 4 ++--
.../java/com/android/ide/common/res2/MergeConsumer.java | 4 ++--
.../java/com/android/ide/common/res2/MergingException.java | 6 +++---
.../main/java/com/android/ide/common/res2/ResourceFile.java | 4 ++--
.../main/java/com/android/ide/common/res2/ResourceSet.java | 2 +-
.../ide/common/resources/configuration/LocaleQualifier.java | 4 ++--
6 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/sdk-common/src/main/java/com/android/ide/common/res2/DataSet.java b/sdk-common/src/main/java/com/android/ide/common/res2/DataSet.java
index 8d662a0f67..5975bcb4ba 100644
--- a/sdk-common/src/main/java/com/android/ide/common/res2/DataSet.java
+++ b/sdk-common/src/main/java/com/android/ide/common/res2/DataSet.java
@@ -20,7 +20,7 @@ import com.android.annotations.NonNull;
import com.android.annotations.Nullable;
import com.android.ide.common.blame.Message;
import com.android.utils.ILogger;
-import com.google.common.base.Objects;
+import com.google.common.base.MoreObjects;
import com.google.common.base.Splitter;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ListMultimap;
@@ -515,7 +515,7 @@ abstract class DataSet<I extends DataItem<F>, F extends DataFile<I>> implements

@Override
public String toString() {
- return Objects.toStringHelper(getClass())
+ return MoreObjects.toStringHelper(getClass())
.addValue(mConfigName)
.add("sources", Arrays.toString(mSourceFiles.toArray()))
.toString();
diff --git a/sdk-common/src/main/java/com/android/ide/common/res2/MergeConsumer.java b/sdk-common/src/main/java/com/android/ide/common/res2/MergeConsumer.java
index 71a3bbfdbb..cd074dc816 100644
--- a/sdk-common/src/main/java/com/android/ide/common/res2/MergeConsumer.java
+++ b/sdk-common/src/main/java/com/android/ide/common/res2/MergeConsumer.java
@@ -22,7 +22,7 @@ import com.android.ide.common.blame.Message;
import com.android.ide.common.blame.SourceFile;
import com.android.ide.common.blame.SourceFilePosition;
import com.android.ide.common.blame.SourcePosition;
-import com.google.common.base.Objects;
+import com.google.common.base.MoreObjects;
import com.google.common.base.Throwables;

import java.io.File;
@@ -51,7 +51,7 @@ public interface MergeConsumer<I extends DataItem> {
private ConsumerException(@NonNull Throwable cause, @NonNull SourceFile file) {
super(cause, new Message(
Message.Kind.ERROR,
- Objects.firstNonNull(
+ MoreObjects.firstNonNull(
cause.getLocalizedMessage(),
cause.getClass().getCanonicalName()),
Throwables.getStackTraceAsString(cause),
diff --git a/sdk-common/src/main/java/com/android/ide/common/res2/MergingException.java b/sdk-common/src/main/java/com/android/ide/common/res2/MergingException.java
index c805c71358..820772afce 100644
--- a/sdk-common/src/main/java/com/android/ide/common/res2/MergingException.java
+++ b/sdk-common/src/main/java/com/android/ide/common/res2/MergingException.java
@@ -24,7 +24,7 @@ import com.android.ide.common.blame.SourceFile;
import com.android.ide.common.blame.SourceFilePosition;
import com.android.ide.common.blame.SourcePosition;
import com.google.common.base.Joiner;
-import com.google.common.base.Objects;
+import com.google.common.base.MoreObjects;
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
@@ -108,7 +108,7 @@ public class MergingException extends Exception {
public MergingException build() {
if (mCause != null) {
if (mMessageText == null) {
- mMessageText = Objects.firstNonNull(
+ mMessageText = MoreObjects.firstNonNull(
mCause.getLocalizedMessage(), mCause.getClass().getCanonicalName());
}
if (mPosition == SourcePosition.UNKNOWN && mCause instanceof SAXParseException) {
@@ -131,7 +131,7 @@ public class MergingException extends Exception {
new Message(
Kind.ERROR,
mMessageText,
- Objects.firstNonNull(mOriginalMessageText, mMessageText),
+ MoreObjects.firstNonNull(mOriginalMessageText, mMessageText),
RESOURCE_ASSET_MERGER_TOOL_NAME,
new SourceFilePosition(mFile, mPosition)));
}
diff --git a/sdk-common/src/main/java/com/android/ide/common/res2/ResourceFile.java b/sdk-common/src/main/java/com/android/ide/common/res2/ResourceFile.java
index 48d865edf4..5a6b2cbb9b 100644
--- a/sdk-common/src/main/java/com/android/ide/common/res2/ResourceFile.java
+++ b/sdk-common/src/main/java/com/android/ide/common/res2/ResourceFile.java
@@ -18,7 +18,7 @@ package com.android.ide.common.res2;

import com.android.SdkConstants;
import com.android.annotations.NonNull;
-import com.google.common.base.Objects;
+import com.google.common.base.MoreObjects;

import org.w3c.dom.Document;
import org.w3c.dom.Node;
@@ -114,7 +114,7 @@ public class ResourceFile extends DataFile<ResourceItem> {

@Override
public String toString() {
- return Objects.toStringHelper(getClass())
+ return MoreObjects.toStringHelper(getClass())
.add("mFile", mFile)
.add("mQualifiers", mQualifiers)
.toString();
diff --git a/sdk-common/src/main/java/com/android/ide/common/res2/ResourceSet.java b/sdk-common/src/main/java/com/android/ide/common/res2/ResourceSet.java
index d9c8be621f..58237ea10c 100644
--- a/sdk-common/src/main/java/com/android/ide/common/res2/ResourceSet.java
+++ b/sdk-common/src/main/java/com/android/ide/common/res2/ResourceSet.java
@@ -17,7 +17,7 @@
package com.android.ide.common.res2;

import static com.android.ide.common.res2.ResourceFile.ATTR_QUALIFIER;
-import static com.google.common.base.Objects.firstNonNull;
+import static com.google.common.base.MoreObjects.firstNonNull;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;

diff --git a/sdk-common/src/main/java/com/android/ide/common/resources/configuration/LocaleQualifier.java b/sdk-common/src/main/java/com/android/ide/common/resources/configuration/LocaleQualifier.java
index 389f5c47f9..c0c09df17a 100644
--- a/sdk-common/src/main/java/com/android/ide/common/resources/configuration/LocaleQualifier.java
+++ b/sdk-common/src/main/java/com/android/ide/common/resources/configuration/LocaleQualifier.java
@@ -102,7 +102,7 @@ public final class LocaleQualifier extends ResourceQualifier {
* @return is it valid?
*/
private static boolean isValidAlpha2Code(@NonNull String str) {
- return str.length() == 2 && CharMatcher.JAVA_LETTER.matchesAllOf(str);
+ return str.length() == 2 && CharMatcher.javaLetter().matchesAllOf(str);
}

/**
@@ -111,7 +111,7 @@ public final class LocaleQualifier extends ResourceQualifier {
* @return is it valid?
*/
private static boolean isValidAlpha3Code(@NonNull String str) {
- return str.length() == 3 && CharMatcher.JAVA_LETTER.matchesAllOf(str);
+ return str.length() == 3 && CharMatcher.javaLetter().matchesAllOf(str);
}

/**
--
2.28.0.rc0.105.gf9edc3c819-goog

Loading