1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.tools.metalava 18 19 import com.android.tools.metalava.cli.common.newDir 20 import com.android.tools.metalava.model.PackageFilter 21 import com.github.ajalt.clikt.parameters.groups.OptionGroup 22 import com.github.ajalt.clikt.parameters.options.convert 23 import com.github.ajalt.clikt.parameters.options.flag 24 import com.github.ajalt.clikt.parameters.options.option 25 26 private const val STUB_GENERATION_GROUP = "Stub Generation" 27 28 const val ARG_INCLUDE_ANNOTATIONS = "--include-annotations" 29 const val ARG_EXCLUDE_ALL_ANNOTATIONS = "--exclude-all-annotations" 30 const val ARG_STUBS = "--stubs" 31 const val ARG_FORCE_CONVERT_TO_WARNING_NULLABILITY_ANNOTATIONS = 32 "--force-convert-to-warning-nullability-annotations" 33 34 class StubGenerationOptions : 35 OptionGroup( 36 name = STUB_GENERATION_GROUP, 37 help = "Options controlling the generation of stub files.", 38 ) { 39 40 val stubsDir by 41 option( 42 ARG_STUBS, 43 metavar = "<dir>", 44 help = 45 """ 46 Base directory to output the generated stub source files for the API, if 47 specified. 48 """ 49 .trimIndent(), 50 ) 51 .newDir() 52 53 val includeAnnotations by 54 option( 55 ARG_INCLUDE_ANNOTATIONS, 56 help = "Include/exclude annotations such as @Nullable in/from the stub files.", 57 ) 58 .flag( 59 ARG_EXCLUDE_ALL_ANNOTATIONS, 60 default = false, 61 defaultForHelp = "exclude", 62 ) 63 64 val forceConvertToWarningNullabilityAnnotations by 65 option( 66 ARG_FORCE_CONVERT_TO_WARNING_NULLABILITY_ANNOTATIONS, 67 metavar = "<package1:-package2:...>", 68 help = 69 """ 70 On every API declared in a class referenced by the given filter, makes 71 nullability issues appear to callers as warnings rather than errors by 72 replacing @Nullable/@NonNull in these APIs with 73 @RecentlyNullable/@RecentlyNonNull. 74 75 See `metalava help package-filters` for more information. 76 """ 77 .trimIndent() 78 ) <lambda>null79 .convert { PackageFilter.parse(it) } 80 } 81