diff --git a/tools/gen_jarjar.py b/tools/gen_jarjar.py index 4c2cf54057..2ff53fa732 100755 --- a/tools/gen_jarjar.py +++ b/tools/gen_jarjar.py @@ -115,7 +115,8 @@ def make_jarjar_rules(args): jar_classes = _list_jar_classes(jar) jar_classes.sort() for clazz in jar_classes: - if (_get_toplevel_class(clazz) not in excluded_classes and + if (not clazz.startswith(args.prefix + '.') and + _get_toplevel_class(clazz) not in excluded_classes and not any(r.fullmatch(clazz) for r in exclude_regexes)): outfile.write(f'rule {clazz} {args.prefix}.@0\n') # Also include jarjar rules for unit tests of the class, so the package matches diff --git a/tools/testdata/java/jarjar/prefix/AlreadyInTargetPackageClass.java b/tools/testdata/java/jarjar/prefix/AlreadyInTargetPackageClass.java new file mode 100644 index 0000000000..6859020562 --- /dev/null +++ b/tools/testdata/java/jarjar/prefix/AlreadyInTargetPackageClass.java @@ -0,0 +1,25 @@ +/* + * 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 jarjar.prefix; + +/** + * Sample class to test jarjar rules, already in the "jarjar.prefix" package. + */ +public class AlreadyInTargetPackageClass { + /** Test inner class that should not be jarjared either */ + public static class TestInnerClass {} +}