1*e07d83d3SAndroid Build Coastguard Worker#!/usr/bin/env python3 2*e07d83d3SAndroid Build Coastguard Worker 3*e07d83d3SAndroid Build Coastguard Worker# Copyright (C) 2020 The Android Open Source Project 4*e07d83d3SAndroid Build Coastguard Worker# 5*e07d83d3SAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License"); 6*e07d83d3SAndroid Build Coastguard Worker# you may not use this file except in compliance with the License. 7*e07d83d3SAndroid Build Coastguard Worker# You may obtain a copy of the License at 8*e07d83d3SAndroid Build Coastguard Worker# 9*e07d83d3SAndroid Build Coastguard Worker# http://www.apache.org/licenses/LICENSE-2.0 10*e07d83d3SAndroid Build Coastguard Worker# 11*e07d83d3SAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software 12*e07d83d3SAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS, 13*e07d83d3SAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14*e07d83d3SAndroid Build Coastguard Worker# See the License for the specific language governing permissions and 15*e07d83d3SAndroid Build Coastguard Worker# limitations under the License. 16*e07d83d3SAndroid Build Coastguard Worker"""Generates stubs for annotations that aren't in the Android source tree.""" 17*e07d83d3SAndroid Build Coastguard Worker 18*e07d83d3SAndroid Build Coastguard Workerimport pathlib 19*e07d83d3SAndroid Build Coastguard Workerimport string 20*e07d83d3SAndroid Build Coastguard Workerimport sys 21*e07d83d3SAndroid Build Coastguard Worker 22*e07d83d3SAndroid Build Coastguard Worker_ANNOTATIONS_CLASSES = ['org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement'] 23*e07d83d3SAndroid Build Coastguard Worker 24*e07d83d3SAndroid Build Coastguard Worker_CLASS_TEMPLATE = string.Template(""" 25*e07d83d3SAndroid Build Coastguard Workerpackage ${package_name}; 26*e07d83d3SAndroid Build Coastguard Worker 27*e07d83d3SAndroid Build Coastguard Workerimport java.lang.annotation.ElementType; 28*e07d83d3SAndroid Build Coastguard Workerimport java.lang.annotation.Retention; 29*e07d83d3SAndroid Build Coastguard Workerimport java.lang.annotation.RetentionPolicy; 30*e07d83d3SAndroid Build Coastguard Workerimport java.lang.annotation.Target; 31*e07d83d3SAndroid Build Coastguard Worker 32*e07d83d3SAndroid Build Coastguard Worker@Target({ 33*e07d83d3SAndroid Build Coastguard Worker ElementType.ANNOTATION_TYPE, 34*e07d83d3SAndroid Build Coastguard Worker ElementType.CONSTRUCTOR, 35*e07d83d3SAndroid Build Coastguard Worker ElementType.FIELD, 36*e07d83d3SAndroid Build Coastguard Worker ElementType.LOCAL_VARIABLE, 37*e07d83d3SAndroid Build Coastguard Worker ElementType.METHOD, 38*e07d83d3SAndroid Build Coastguard Worker ElementType.PACKAGE, 39*e07d83d3SAndroid Build Coastguard Worker ElementType.PARAMETER, 40*e07d83d3SAndroid Build Coastguard Worker ElementType.TYPE, 41*e07d83d3SAndroid Build Coastguard Worker ElementType.TYPE_PARAMETER, 42*e07d83d3SAndroid Build Coastguard Worker ElementType.TYPE_USE}) 43*e07d83d3SAndroid Build Coastguard Worker@Retention(RetentionPolicy.SOURCE) 44*e07d83d3SAndroid Build Coastguard Workerpublic @interface ${class_name} {} 45*e07d83d3SAndroid Build Coastguard Worker""") 46*e07d83d3SAndroid Build Coastguard Worker 47*e07d83d3SAndroid Build Coastguard Workerif __name__ == '__main__': 48*e07d83d3SAndroid Build Coastguard Worker out_dir = pathlib.Path(sys.argv[1]) 49*e07d83d3SAndroid Build Coastguard Worker 50*e07d83d3SAndroid Build Coastguard Worker for c in _ANNOTATIONS_CLASSES: 51*e07d83d3SAndroid Build Coastguard Worker parts = c.split('.') 52*e07d83d3SAndroid Build Coastguard Worker src_path = out_dir.joinpath(*parts).with_suffix('.java') 53*e07d83d3SAndroid Build Coastguard Worker src_path.parent.mkdir(parents=True) 54*e07d83d3SAndroid Build Coastguard Worker src_path.write_text( 55*e07d83d3SAndroid Build Coastguard Worker _CLASS_TEMPLATE.substitute( 56*e07d83d3SAndroid Build Coastguard Worker package_name='.'.join(parts[:-1]), class_name=parts[-1])) 57