Merge changes I449d903b,I31bb2339
* changes:
Add a test for jarjar with Java 9 language features.
Move Java9LanguageFeaturesTest into its own directory.
diff --git a/JavaLibrary.bp b/JavaLibrary.bp
index b85a861..b229c2f 100644
--- a/JavaLibrary.bp
+++ b/JavaLibrary.bp
@@ -145,6 +145,7 @@
"//external/icu/android_icu4j",
"//external/okhttp",
"//libcore/benchmarks",
+ "//libcore/luni/src/test/java9language",
"//libcore/mmodules/intracoreapi",
]
@@ -490,6 +491,14 @@
system_modules: "core-all-system-modules",
}
+// A filegroup that provides access to a source file for a toolchain test that
+// checks Java 9 language features are handled properly by JarJar.
+filegroup {
+ name: "core-java-9-language-features-source",
+ srcs: ["luni/src/main/java/libcore/internal/Java9LanguageFeatures.java"],
+ visibility: ["//libcore/luni/src/test/java9language"],
+}
+
// Builds the core-tests library.
java_test {
name: "core-tests",
@@ -535,6 +544,7 @@
static_libs: [
"archive-patcher",
+ "core-java-9-language-tests",
"core-test-rules",
"core-tests-support",
"junit-params",
diff --git a/luni/src/test/java9language/Android.bp b/luni/src/test/java9language/Android.bp
new file mode 100644
index 0000000..a04eda6f
--- /dev/null
+++ b/luni/src/test/java9language/Android.bp
@@ -0,0 +1,78 @@
+// Copyright (C) 2019 The Android Open Source Project
+//
+// 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.
+
+// Android tests related to Java 9 language features.
+
+// Use jarjar to repackage Java9LanguageFeatures, to be used in tests below.
+java_library {
+ name: "core-java-9-language-features-repackaged-for-test",
+ defaults: ["libcore_java_defaults"],
+ hostdex: true,
+
+ srcs: [":core-java-9-language-features-source"],
+ jarjar_rules: "jarjar_rules_java9_language_features.txt",
+ java_version: "1.9",
+
+ sdk_version: "none",
+ libs: ["core-all"],
+ system_modules: "core-all-system-modules",
+ patch_module: "java.base",
+
+ visibility: ["//visibility:private"],
+}
+
+// Generate a clone of Java9LanguageFeaturesTest which uses a version of
+// Java9LanguageFeatures repackaged by jarjar. This ensures that jarjar is able
+// to handle a class file which must be at least v53 and includes bytecode
+// compiled from Java 9 language features.
+filegroup {
+ name: "core-rewrite-test-for-jarjar-sed-script",
+ srcs: ["rewrite-test-for-jarjar.sed"],
+ visibility: ["//visibility:private"],
+}
+filegroup {
+ name: "core-java-9-language-features-test-src",
+ srcs: ["java/libcore/internal/Java9LanguageFeaturesTest.java"],
+ visibility: ["//visibility:private"],
+}
+genrule {
+ name: "core-gen-test-repackaged-java-9-language-features",
+ srcs: [
+ ":core-rewrite-test-for-jarjar-sed-script",
+ ":core-java-9-language-features-test-src",
+ ],
+ out: ["libcore/libcore/internal/Java9LanguageFeaturesJarjarTest.java"],
+ cmd: "sed -r -f $(location :core-rewrite-test-for-jarjar-sed-script) $(location :core-java-9-language-features-test-src) > $(out)",
+ visibility: ["//visibility:private"],
+}
+
+java_library {
+ name: "core-java-9-language-tests",
+ defaults: ["libcore_java_defaults"],
+ hostdex: true,
+ srcs: [
+ "java/**/*.java",
+ ":core-gen-test-repackaged-java-9-language-features",
+ ],
+ sdk_version: "none",
+ libs: [
+ "core-all",
+ ],
+ static_libs: [
+ "core-java-9-language-features-repackaged-for-test",
+ "junit",
+ ],
+ system_modules: "core-all-system-modules",
+ visibility: ["//libcore"],
+}
diff --git a/luni/src/test/java9language/jarjar_rules_java9_language_features.txt b/luni/src/test/java9language/jarjar_rules_java9_language_features.txt
new file mode 100644
index 0000000..dee72bc
--- /dev/null
+++ b/luni/src/test/java9language/jarjar_rules_java9_language_features.txt
@@ -0,0 +1 @@
+rule libcore.internal.** libcore.internal.repackaged.@1
diff --git a/luni/src/test/java/libcore/libcore/internal/Java9LanguageFeaturesTest.java b/luni/src/test/java9language/java/libcore/internal/Java9LanguageFeaturesTest.java
similarity index 100%
rename from luni/src/test/java/libcore/libcore/internal/Java9LanguageFeaturesTest.java
rename to luni/src/test/java9language/java/libcore/internal/Java9LanguageFeaturesTest.java
diff --git a/luni/src/test/java9language/rewrite-test-for-jarjar.sed b/luni/src/test/java9language/rewrite-test-for-jarjar.sed
new file mode 100644
index 0000000..525a14a
--- /dev/null
+++ b/luni/src/test/java9language/rewrite-test-for-jarjar.sed
@@ -0,0 +1,21 @@
+# Copyright (C) 2019 The Android Open Source Project
+#
+# 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.
+
+# This is a sed script that modifies Java source code in two ways.
+
+# Replace libcore.internal with libcore.internal.repackaged in imports:
+s/import libcore.internal/import libcore.internal.repackaged/
+
+# Replace Test with JarjarTest in class declarations.
+s/class ([A-Za-z0-9_]+)Test/class \1JarjarTest/