From 47f189c1e4728977bbecac5905c8bcc58c67c07e Mon Sep 17 00:00:00 2001 From: Sorin Basca Date: Mon, 9 May 2022 13:24:51 +0100 Subject: Add option to strip annotations from jar Bug: 222743634 Test: m Change-Id: I095140c52959965ed28f82a9bb689aec191458d2 --- res/com/tonicsystems/jarjar/help.txt | 4 + .../com/android/jarjar/StripAnnotation.java | 26 +++++ .../jarjar/StripAnnotationsJarTransformer.java | 121 +++++++++++++++++++++ .../com/tonicsystems/jarjar/MainProcessor.java | 14 +++ .../com/tonicsystems/jarjar/RulesFileParser.java | 6 + 5 files changed, 171 insertions(+) create mode 100644 src/android/com/android/jarjar/StripAnnotation.java create mode 100644 src/android/com/android/jarjar/StripAnnotationsJarTransformer.java diff --git a/res/com/tonicsystems/jarjar/help.txt b/res/com/tonicsystems/jarjar/help.txt index 8410909..6f14db6 100644 --- a/res/com/tonicsystems/jarjar/help.txt +++ b/res/com/tonicsystems/jarjar/help.txt @@ -49,6 +49,7 @@ Rules file format: rule zap keep + strip-annotations The standard rule ("rule") is used to rename classes. All references to the renamed classes will also be updated. If a class name is @@ -73,3 +74,6 @@ Rules file format: via dependency analysis are discarded when writing the output jar. This is the last step in the process, after renaming and zapping. + The "strip-annotations" rule will remove all the references to a certain + annotation from a jar file. As no pattern matching is performed, the + annotations have to be provided as one per line. diff --git a/src/android/com/android/jarjar/StripAnnotation.java b/src/android/com/android/jarjar/StripAnnotation.java new file mode 100644 index 0000000..debd469 --- /dev/null +++ b/src/android/com/android/jarjar/StripAnnotation.java @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2022 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. + */ + +package com.android.jarjar; + +import com.tonicsystems.jarjar.PatternElement; + +/** + * Configuration element for stripping annotations in a jar file. + */ +public class StripAnnotation extends PatternElement +{ +} diff --git a/src/android/com/android/jarjar/StripAnnotationsJarTransformer.java b/src/android/com/android/jarjar/StripAnnotationsJarTransformer.java new file mode 100644 index 0000000..260cb30 --- /dev/null +++ b/src/android/com/android/jarjar/StripAnnotationsJarTransformer.java @@ -0,0 +1,121 @@ +/* + * Copyright (C) 2022 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. + */ + +package com.android.jarjar; + +import com.tonicsystems.jarjar.util.JarTransformer; + +import org.objectweb.asm.AnnotationVisitor; +import org.objectweb.asm.ClassVisitor; +import org.objectweb.asm.FieldVisitor; +import org.objectweb.asm.MethodVisitor; +import org.objectweb.asm.Opcodes; + +import java.util.List; +import java.util.function.Supplier; +import java.util.stream.Collectors; + +/** + * A transformer that strips annotations from all classes based on custom rules. + */ +public final class StripAnnotationsJarTransformer extends JarTransformer { + + private static int ASM_VERSION = Opcodes.ASM7; + + private final List stripAnnotationList; + + public StripAnnotationsJarTransformer(List stripAnnotationList) { + this.stripAnnotationList = getAnnotationList(stripAnnotationList); + } + + private static List getAnnotationList(List stripAnnotationList) { + return stripAnnotationList.stream().map(el -> getClassName(el)).collect(Collectors.toList()); + } + + private static String getClassName(StripAnnotation element) { + return "L" + element.getPattern().replace('.', '/') + ";"; + } + + @Override + protected ClassVisitor transform(ClassVisitor classVisitor) { + return new AnnotationRemover(classVisitor); + } + + private class AnnotationRemover extends ClassVisitor { + + AnnotationRemover(ClassVisitor cv) { + super(ASM_VERSION, cv); + } + + @Override + public AnnotationVisitor visitAnnotation(String descriptor, boolean visible) { + return visitAnnotationCommon(descriptor, + () -> super.visitAnnotation(descriptor, visible)); + } + + @Override + public FieldVisitor visitField(int access, String name, String descriptor, String signature, + Object value) { + FieldVisitor superVisitor = + super.visitField(access, name, descriptor, signature, value); + return new FieldVisitor(ASM_VERSION, superVisitor) { + @Override + public AnnotationVisitor visitAnnotation(String descriptor, boolean visible) { + return visitAnnotationCommon(descriptor, + () -> super.visitAnnotation(descriptor, visible)); + + } + }; + } + + @Override + public MethodVisitor visitMethod(int access, String name, String descriptor, + String signature, String[] exceptions) { + MethodVisitor superVisitor = + super.visitMethod(access, name, descriptor, signature, exceptions); + return new MethodVisitor(ASM_VERSION, superVisitor) { + @Override + public AnnotationVisitor visitAnnotation(String descriptor, boolean visible) { + return visitAnnotationCommon(descriptor, + () -> super.visitAnnotation(descriptor, visible)); + } + + @Override + public AnnotationVisitor visitParameterAnnotation(int parameter, + String descriptor, boolean visible) { + return visitAnnotationCommon(descriptor, + () -> super.visitParameterAnnotation(parameter, descriptor, visible)); + } + }; + } + + /** + * Create an {@link AnnotationVisitor} that removes any annotations from {@link + * #stripAnnotationList}. + */ + private AnnotationVisitor visitAnnotationCommon(String annotation, + Supplier defaultVisitorSupplier) { + if (stripAnnotationList.contains(annotation)) { + return null; + } + // Only get() the default AnnotationVisitor if the annotation is to be included. + // Invoking super.visitAnnotation(descriptor, visible) causes the annotation to be + // included in the output even if the resulting AnnotationVisitor is not returned or + // used. + return defaultVisitorSupplier.get(); + } + } +} diff --git a/src/main/com/tonicsystems/jarjar/MainProcessor.java b/src/main/com/tonicsystems/jarjar/MainProcessor.java index 2778cc5..a0ef4c7 100644 --- a/src/main/com/tonicsystems/jarjar/MainProcessor.java +++ b/src/main/com/tonicsystems/jarjar/MainProcessor.java @@ -16,12 +16,14 @@ package com.tonicsystems.jarjar; +import com.android.jarjar.StripAnnotation; import com.tonicsystems.jarjar.util.*; import java.io.File; import java.io.IOException; import java.util.*; import com.android.jarjar.RemoveAndroidCompatAnnotationsJarTransformer; +import com.android.jarjar.StripAnnotationsJarTransformer; class MainProcessor implements JarProcessor { @@ -42,6 +44,9 @@ class MainProcessor implements JarProcessor List zapList = new ArrayList(); List ruleList = new ArrayList(); List keepList = new ArrayList(); + // ANDROID-BEGIN: b/222743634 Strip annotations from system module stubs + List stripAnnotationList = new ArrayList(); + // ANDROID-END: b/222743634 Strip annotations from system module stubs for (PatternElement pattern : patterns) { if (pattern instanceof Zap) { zapList.add((Zap) pattern); @@ -49,7 +54,11 @@ class MainProcessor implements JarProcessor ruleList.add((Rule) pattern); } else if (pattern instanceof Keep) { keepList.add((Keep) pattern); + // ANDROID-BEGIN: b/222743634 Strip annotations from system module stubs + } else if (pattern instanceof StripAnnotation) { + stripAnnotationList.add((StripAnnotation) pattern); } + // ANDROID-END: b/222743634 Strip annotations from system module stubs } PackageRemapper pr = new PackageRemapper(ruleList, verbose); @@ -65,6 +74,11 @@ class MainProcessor implements JarProcessor if (removeAndroidCompatAnnotations) processors.add(new RemoveAndroidCompatAnnotationsJarTransformer(pr)); // ANDROID-END: b/146418363 Add an Android-specific transformer to strip compat annotation + // ANDROID-BEGIN: b/222743634 Strip annotations from system module stubs + if (!stripAnnotationList.isEmpty()) { + processors.add(new StripAnnotationsJarTransformer(stripAnnotationList)); + } + // ANDROID-END: b/222743634 Strip annotations from system module stubs processors.add(new JarTransformerChain(new RemappingClassTransformer[]{ new RemappingClassTransformer(pr) })); processors.add(new ResourceProcessor(pr)); chain = new JarProcessorChain(processors.toArray(new JarProcessor[processors.size()])); diff --git a/src/main/com/tonicsystems/jarjar/RulesFileParser.java b/src/main/com/tonicsystems/jarjar/RulesFileParser.java index f54f3b9..c8c6ea4 100644 --- a/src/main/com/tonicsystems/jarjar/RulesFileParser.java +++ b/src/main/com/tonicsystems/jarjar/RulesFileParser.java @@ -16,6 +16,8 @@ package com.tonicsystems.jarjar; +import com.android.jarjar.StripAnnotation; + import java.io.*; import java.util.*; @@ -62,6 +64,10 @@ class RulesFileParser element = new Zap(); } else if (type.equals("keep")) { element = new Keep(); + // ANDROID-BEGIN: b/222743634 Strip annotations from system module stubs + } else if (type.equals("strip-annotation")) { + element = new StripAnnotation(); + // ANDROID-END: b/222743634 Strip annotations from system module stubs } else { error(c, parts); } -- cgit v1.2.3 From e3db807ac093f42e2bf3d6ad3979a4a500cd4e49 Mon Sep 17 00:00:00 2001 From: Remi NGUYEN VAN Date: Fri, 20 May 2022 11:34:32 +0900 Subject: Speed up jarjar with prefix matches A common use-case for jarjar is to have rule with the format my.package.name.**, or even my.package.name.MyClass with no wildcards. Jarjar will convert that pattern to a regular expression and do regular expression matching on every symbol it scans to determine if the rule matches. This is very inefficient as most symbols will not match, and a simple prefix match can rule out the match in most cases. When parsing rules, extract the plain-text prefix of each rule, which is everything before the first wildcard. Then index all rules by their prefix in a prefix trie. This allows: - Avoiding slow regular expression matches in most cases, as jarjar can immediately observe that there is no matching prefix in the map. - Scaling in O(log(n)) with the number of rules when they have distinct prefixes (instead of O(n), as a matching prefix can be found from the trie instead of looping through all rules. This makes jarjar faster in current builds (running all jarjar rules to build a device back-to-back goes from 295s to 270s). For example: With FrameworksNetTests (not part of device build): real 0m48.580s -> 0m24.507s user 1m10.767s -> 0m39.251s sys 0m12.029s -> 0m12.099s With service-wifi: real 0m12.887s -> 0m7.061s user 0m26.274s -> 0m20.519s sys 0m3.806s -> 0m3.478s With NetworkStack: real 0m2.081s -> 0m1.870s user 0m7.119s -> 0m6.230s sys 0m1.157s -> 0m1.049s All jars jarjared as part of a device build were checked to remain byte-identical after this change. Test: m clean, m, grep out/verbose.log.gz for jarjar commands, run all commands with/without updated jarjar and check output is byte-identical. Bug: 217129444 Bug: 233081774 Change-Id: I3b7c1a7215ea8378b819ab0fe1f74b2b6fe8dcb5 --- .../com/tonicsystems/jarjar/PackageRemapper.java | 7 +- .../com/tonicsystems/jarjar/PatternElement.java | 4 +- src/main/com/tonicsystems/jarjar/Wildcard.java | 21 ++++- src/main/com/tonicsystems/jarjar/WildcardTrie.java | 91 ++++++++++++++++++++++ 4 files changed, 117 insertions(+), 6 deletions(-) create mode 100644 src/main/com/tonicsystems/jarjar/WildcardTrie.java diff --git a/src/main/com/tonicsystems/jarjar/PackageRemapper.java b/src/main/com/tonicsystems/jarjar/PackageRemapper.java index 4d102be..e281f24 100644 --- a/src/main/com/tonicsystems/jarjar/PackageRemapper.java +++ b/src/main/com/tonicsystems/jarjar/PackageRemapper.java @@ -16,7 +16,6 @@ package com.tonicsystems.jarjar; -import org.objectweb.asm.*; import org.objectweb.asm.commons.*; import java.util.*; import java.util.regex.Pattern; @@ -28,7 +27,7 @@ class PackageRemapper extends Remapper private static final Pattern ARRAY_FOR_NAME_PATTERN = Pattern.compile("\\[L[\\p{javaJavaIdentifierPart}\\.]+?;"); - private final List wildcards; + private final WildcardTrie wildcards; private final Map typeCache = new HashMap(); private final Map pathCache = new HashMap(); private final Map valueCache = new HashMap(); @@ -36,7 +35,7 @@ class PackageRemapper extends Remapper public PackageRemapper(List ruleList, boolean verbose) { this.verbose = verbose; - wildcards = PatternElement.createWildcards(ruleList); + wildcards = new WildcardTrie(PatternElement.createWildcards(ruleList)); } // also used by KeepProcessor @@ -118,7 +117,7 @@ class PackageRemapper extends Remapper } private String replaceHelper(String value) { - for (Wildcard wildcard : wildcards) { + for (Wildcard wildcard : wildcards.getPossibleMatches(value)) { String test = wildcard.replace(value); if (test != null) return test; diff --git a/src/main/com/tonicsystems/jarjar/PatternElement.java b/src/main/com/tonicsystems/jarjar/PatternElement.java index 6ccd9ea..6b852d7 100644 --- a/src/main/com/tonicsystems/jarjar/PatternElement.java +++ b/src/main/com/tonicsystems/jarjar/PatternElement.java @@ -32,12 +32,14 @@ abstract public class PatternElement static List createWildcards(List patterns) { List wildcards = new ArrayList(); + int ruleIndex = 0; for (PatternElement pattern : patterns) { String result = (pattern instanceof Rule) ? ((Rule)pattern).getResult() : ""; String expr = pattern.getPattern(); if (expr.indexOf('/') >= 0) throw new IllegalArgumentException("Patterns cannot contain slashes"); - wildcards.add(new Wildcard(expr.replace('.', '/'), result)); + wildcards.add(new Wildcard(expr.replace('.', '/'), result, ruleIndex)); + ruleIndex++; } return wildcards; } diff --git a/src/main/com/tonicsystems/jarjar/Wildcard.java b/src/main/com/tonicsystems/jarjar/Wildcard.java index 5cc486f..c92e0fb 100644 --- a/src/main/com/tonicsystems/jarjar/Wildcard.java +++ b/src/main/com/tonicsystems/jarjar/Wildcard.java @@ -27,14 +27,18 @@ class Wildcard private static Pattern star = Pattern.compile("\\*"); private static Pattern estar = Pattern.compile("\\+\\??\\)\\Z"); private static Pattern dollar = Pattern.compile("\\$"); + // Apart from stars and dollar signs, wildcards are plain-text full matches + private static Pattern plainTextPrefixPattern = Pattern.compile("^[^*$]*"); private final Pattern pattern; + private final String plainTextPrefix; + private final int ruleIndex; private final int count; private final ArrayList parts = new ArrayList(16); // kept for debugging private final String[] strings; private final int[] refs; - public Wildcard(String pattern, String result) { + public Wildcard(String pattern, String result, int ruleIndex) { if (pattern.equals("**")) throw new IllegalArgumentException("'**' is not a valid pattern"); if (!checkIdentifierChars(pattern, "/*")) @@ -47,6 +51,13 @@ class Wildcard regex = replaceAllLiteral(star, regex, "([^/]+)"); regex = replaceAllLiteral(estar, regex, "*)"); regex = replaceAllLiteral(dollar, regex, "\\$"); + Matcher prefixMatcher = plainTextPrefixPattern.matcher(pattern); + // prefixMatcher will always match, but may match an empty string + if (!prefixMatcher.find()) { + throw new IllegalArgumentException(plainTextPrefixPattern + " not found in " + pattern); + } + this.plainTextPrefix = prefixMatcher.group(); + this.ruleIndex = ruleIndex; this.pattern = Pattern.compile("\\A" + regex + "\\Z"); this.count = this.pattern.matcher("foo").groupCount(); @@ -95,6 +106,14 @@ class Wildcard // System.err.println(this); } + public String getPlainTextPrefix() { + return plainTextPrefix; + } + + public int getRuleIndex() { + return ruleIndex; + } + public boolean matches(String value) { return getMatcher(value) != null; } diff --git a/src/main/com/tonicsystems/jarjar/WildcardTrie.java b/src/main/com/tonicsystems/jarjar/WildcardTrie.java new file mode 100644 index 0000000..e80dbc9 --- /dev/null +++ b/src/main/com/tonicsystems/jarjar/WildcardTrie.java @@ -0,0 +1,91 @@ +/* + * Copyright (C) 2022 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. + */ + +package com.tonicsystems.jarjar; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import java.util.TreeMap; + +/** + * A prefix trie of {@link Wildcard}, where the prefix is obtained from + * {@link Wildcard#getPlainTextPrefix()}. + * + * This allows quick lookup of applicable wildcards in the common case where wildcards have a + * non-empty plain-text prefix. + */ +public class WildcardTrie { + private final TreeMap subTries = new TreeMap<>(); + private final List wildcards = new ArrayList<>(); + private final String prefix; + + public WildcardTrie(List wildcards) { + this(""); + final ArrayList lst = new ArrayList<>(wildcards); + // Sort values to ensure that wildcards that prefix others are added first + lst.sort(Comparator.comparing(Wildcard::getPlainTextPrefix)); + for (Wildcard w : lst) { + final String prefix = w.getPlainTextPrefix(); + final WildcardTrie prefixTrie = findSubTrieWhichPrefixes(prefix, this); + if (prefixTrie.prefix.equals(prefix)) { + prefixTrie.wildcards.add(w); + } else { + final WildcardTrie newTrie = new WildcardTrie(prefix); + newTrie.wildcards.add(w); + prefixTrie.subTries.put(prefix, newTrie); + } + } + } + + private WildcardTrie(String prefix) { + this.prefix = prefix; + } + + private static WildcardTrie findSubTrieWhichPrefixes(String value, WildcardTrie baseTrie) { + final String possiblePrefix = baseTrie.subTries.floorKey(value); + // Because each level of the trie does not contain keys that are prefixes of each other, + // there can be at most one prefix of the value at that level, and that prefix will be the + // highest key ordered before the value (any non-prefix key would have a character + // difference with the prefix and so be ordered before the prefix or after the value). + if (possiblePrefix != null && value.startsWith(possiblePrefix)) { + return findSubTrieWhichPrefixes(value, baseTrie.subTries.get(possiblePrefix)); + } + return baseTrie; + } + + public List getPossibleMatches(String value) { + WildcardTrie baseTrie = this; + List prefixMatches = wildcards.isEmpty() + // If there's no match, don't even allocate a list and use the singleton emptyList + ? Collections.emptyList() : new ArrayList<>(wildcards); + while (true) { + final String possiblePrefix = baseTrie.subTries.floorKey(value); + if (possiblePrefix != null && value.startsWith(possiblePrefix)) { + baseTrie = baseTrie.subTries.get(possiblePrefix); + if (prefixMatches.isEmpty()) { + prefixMatches = new ArrayList<>(baseTrie.wildcards); + } else { + prefixMatches.addAll(baseTrie.wildcards); + } + } else { + prefixMatches.sort(Comparator.comparing(Wildcard::getRuleIndex)); + return prefixMatches; + } + } + } +} -- cgit v1.2.3 From 019476e4b5d29ee94831b3dee47d35199be51758 Mon Sep 17 00:00:00 2001 From: Sorin Basca Date: Tue, 24 May 2022 12:22:49 +0100 Subject: Update ASM usage to ASM9 Bug: 233029164 Test: EXPERIMENTAL_TARGET_JAVA_VERSION_17=true \ EXPERIMENTAL_USE_OPENJDK17_TOOLCHAIN=true m Change-Id: Iabc9d129fddf919f7e06f82cc8133be30d9a733b --- .../jarjar/RemoveAndroidCompatAnnotationsJarTransformer.java | 8 +++++--- src/main/com/tonicsystems/jarjar/EmptyClassVisitor.java | 10 +++++----- src/main/com/tonicsystems/jarjar/StringReader.java | 8 ++++---- src/main/com/tonicsystems/jarjar/util/GetNameClassWriter.java | 2 +- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/android/com/android/jarjar/RemoveAndroidCompatAnnotationsJarTransformer.java b/src/android/com/android/jarjar/RemoveAndroidCompatAnnotationsJarTransformer.java index f9e5e14..052e358 100644 --- a/src/android/com/android/jarjar/RemoveAndroidCompatAnnotationsJarTransformer.java +++ b/src/android/com/android/jarjar/RemoveAndroidCompatAnnotationsJarTransformer.java @@ -33,6 +33,8 @@ import java.util.function.Supplier; */ public final class RemoveAndroidCompatAnnotationsJarTransformer extends JarTransformer { + private static int ASM_VERSION = Opcodes.ASM9; + private static final Set REMOVE_ANNOTATIONS = Set.of( "Landroid/compat/annotation/UnsupportedAppUsage;"); @@ -51,7 +53,7 @@ public final class RemoveAndroidCompatAnnotationsJarTransformer extends JarTrans private boolean isClassRemapped; AnnotationRemover(ClassVisitor cv) { - super(Opcodes.ASM7, cv); + super(ASM_VERSION, cv); } @Override @@ -74,7 +76,7 @@ public final class RemoveAndroidCompatAnnotationsJarTransformer extends JarTrans Object value) { FieldVisitor superVisitor = super.visitField(access, name, descriptor, signature, value); - return new FieldVisitor(Opcodes.ASM7, superVisitor) { + return new FieldVisitor(ASM_VERSION, superVisitor) { @Override public AnnotationVisitor visitAnnotation(String descriptor, boolean visible) { return visitAnnotationCommon(descriptor, @@ -89,7 +91,7 @@ public final class RemoveAndroidCompatAnnotationsJarTransformer extends JarTrans String signature, String[] exceptions) { MethodVisitor superVisitor = super.visitMethod(access, name, descriptor, signature, exceptions); - return new MethodVisitor(Opcodes.ASM7, superVisitor) { + return new MethodVisitor(ASM_VERSION, superVisitor) { @Override public AnnotationVisitor visitAnnotation(String descriptor, boolean visible) { return visitAnnotationCommon(descriptor, diff --git a/src/main/com/tonicsystems/jarjar/EmptyClassVisitor.java b/src/main/com/tonicsystems/jarjar/EmptyClassVisitor.java index c7614a1..9a05516 100644 --- a/src/main/com/tonicsystems/jarjar/EmptyClassVisitor.java +++ b/src/main/com/tonicsystems/jarjar/EmptyClassVisitor.java @@ -22,29 +22,29 @@ import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.Opcodes; /** - * An ASM3 EmptyVisitor replacement + * An EmptyVisitor replacement * @author Jochen "blackdrag" Theodorou */ public class EmptyClassVisitor extends ClassVisitor { public EmptyClassVisitor() { - super(Opcodes.ASM7); + super(Opcodes.ASM9); } @Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { - return new MethodVisitor(Opcodes.ASM7) {}; + return new MethodVisitor(Opcodes.ASM9) {}; } @Override public AnnotationVisitor visitAnnotation(String desc, boolean visible) { - return new AnnotationVisitor(Opcodes.ASM7) {}; + return new AnnotationVisitor(Opcodes.ASM9) {}; } @Override public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) { - return new FieldVisitor(Opcodes.ASM7) {}; + return new FieldVisitor(Opcodes.ASM9) {}; } } diff --git a/src/main/com/tonicsystems/jarjar/StringReader.java b/src/main/com/tonicsystems/jarjar/StringReader.java index 164b0a2..c3cc273 100644 --- a/src/main/com/tonicsystems/jarjar/StringReader.java +++ b/src/main/com/tonicsystems/jarjar/StringReader.java @@ -24,7 +24,7 @@ abstract class StringReader extends ClassVisitor private String className; public StringReader() { - super(Opcodes.ASM7); + super(Opcodes.ASM9); } abstract public void visitString(String className, String value, int line); @@ -42,7 +42,7 @@ abstract class StringReader extends ClassVisitor public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) { handleObject(value); - return new FieldVisitor(Opcodes.ASM7){ + return new FieldVisitor(Opcodes.ASM9){ @Override public AnnotationVisitor visitAnnotation(String desc, boolean visible) { return StringReader.this.visitAnnotation(desc, visible); @@ -52,7 +52,7 @@ abstract class StringReader extends ClassVisitor @Override public AnnotationVisitor visitAnnotation(String desc, boolean visible) { - return new AnnotationVisitor(Opcodes.ASM7) { + return new AnnotationVisitor(Opcodes.ASM9) { @Override public void visit(String name, Object value) { handleObject(value); @@ -71,7 +71,7 @@ abstract class StringReader extends ClassVisitor @Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { - MethodVisitor mv = new MethodVisitor(Opcodes.ASM7){ + MethodVisitor mv = new MethodVisitor(Opcodes.ASM9){ @Override public void visitLdcInsn(Object cst) { handleObject(cst); diff --git a/src/main/com/tonicsystems/jarjar/util/GetNameClassWriter.java b/src/main/com/tonicsystems/jarjar/util/GetNameClassWriter.java index db6ec4f..cd2cc9b 100644 --- a/src/main/com/tonicsystems/jarjar/util/GetNameClassWriter.java +++ b/src/main/com/tonicsystems/jarjar/util/GetNameClassWriter.java @@ -25,7 +25,7 @@ public class GetNameClassWriter extends ClassVisitor private String className; public GetNameClassWriter(int flags) { - super(Opcodes.ASM7,new ClassWriter(flags)); + super(Opcodes.ASM9,new ClassWriter(flags)); } public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) { -- cgit v1.2.3 From 9e6a26cd7316d38fd7cbe1b86def3ed77dc3eac4 Mon Sep 17 00:00:00 2001 From: Sorin Basca Date: Wed, 25 May 2022 12:27:24 +0100 Subject: Update ASM usage to ASM9 for StripAnnotationsJarTransformer Bug: 233029164 Test: EXPERIMENTAL_TARGET_JAVA_VERSION_17=true \ EXPERIMENTAL_USE_OPENJDK17_TOOLCHAIN=true m Change-Id: I393954478fbad657b85417e2a7344bb7dbe11b3d --- src/android/com/android/jarjar/StripAnnotationsJarTransformer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/android/com/android/jarjar/StripAnnotationsJarTransformer.java b/src/android/com/android/jarjar/StripAnnotationsJarTransformer.java index 260cb30..d547fac 100644 --- a/src/android/com/android/jarjar/StripAnnotationsJarTransformer.java +++ b/src/android/com/android/jarjar/StripAnnotationsJarTransformer.java @@ -33,7 +33,7 @@ import java.util.stream.Collectors; */ public final class StripAnnotationsJarTransformer extends JarTransformer { - private static int ASM_VERSION = Opcodes.ASM7; + private static int ASM_VERSION = Opcodes.ASM9; private final List stripAnnotationList; -- cgit v1.2.3 From 8771f310aa9a23d058de07dccaebf41117ae7b16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Kosi=C5=84ski?= Date: Wed, 16 Nov 2022 19:06:19 +0000 Subject: Use asm built from source. Bug: 259136464 Test: presubmit Change-Id: Ibcd4d98adf602194e3e8fc7cbb6135361f3d6af1 --- Android.bp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Android.bp b/Android.bp index be83e4b..b75f82b 100644 --- a/Android.bp +++ b/Android.bp @@ -47,8 +47,8 @@ java_library_host { java_resource_dirs: ["res"], static_libs: [ - "asm-9.2", - "asm-commons-9.2", + "ow2-asm", + "ow2-asm-commons", ], libs: [ -- cgit v1.2.3 From f93f14149c87ee61675e4f6ba24a8d1f8fcd6ddd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Kosi=C5=84ski?= Date: Fri, 18 Nov 2022 19:06:17 +0000 Subject: Add LICENSE symbolic link. Required by Android third-party code policy. Test: ComplianceLint Change-Id: I4f13b2783a368947e4c20151620ac39d42e3b080 --- LICENSE | 1 + 1 file changed, 1 insertion(+) create mode 120000 LICENSE diff --git a/LICENSE b/LICENSE new file mode 120000 index 0000000..85de3d4 --- /dev/null +++ b/LICENSE @@ -0,0 +1 @@ +LICENSE.txt \ No newline at end of file -- cgit v1.2.3 From 7f7c4e8ce2c5b07d6f2649206c3a7ce701b046c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Kosi=C5=84ski?= Date: Fri, 18 Nov 2022 19:17:34 +0000 Subject: Add information to METADATA file. Test: ComplianceLint Change-Id: Ia9e77a75142af332f726e59b57a9b0b4784064ce --- METADATA | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/METADATA b/METADATA index d97975c..11534d0 100644 --- a/METADATA +++ b/METADATA @@ -1,3 +1,14 @@ +name: "jarjar" +description: + "Utility that makes it easy to repackage Java libraries and embed them into " + "your own distribution" + third_party { + url { + type: GIT + value: "https://github.com/google/jarjar.git" + } + version: "1.4" + last_upgrade_date { year: 2014 month: 6 day: 17 } license_type: NOTICE } -- cgit v1.2.3