1 /* 2 * Copyright (C) 2025 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 package com.android.platform.test.ravenwood.ravenhelper.policytoannot 17 18 import com.android.hoststubgen.ArgumentsException 19 import com.android.hoststubgen.utils.ArgIterator 20 import com.android.hoststubgen.utils.BaseOptions 21 import com.android.hoststubgen.utils.SetOnce 22 import com.android.hoststubgen.utils.ensureFileExists 23 24 /** 25 * Options for the "ravenhelper pta" subcommand. 26 */ 27 class PtaOptions( 28 /** Text policy files */ 29 var policyOverrideFiles: MutableList<String> = mutableListOf(), 30 31 /** Annotation allowed list file. */ 32 var annotationAllowedClassesFile: SetOnce<String?> = SetOnce(null), 33 34 /** Source files or directories. */ 35 var sourceFilesOrDirectories: MutableList<String> = mutableListOf(), 36 37 /** Output script file. */ 38 var outputScriptFile: SetOnce<String?> = SetOnce(null), 39 40 /** Dump the operations (for debugging) */ 41 var dumpOperations: SetOnce<Boolean> = SetOnce(false), 42 ) : BaseOptions() { 43 parseOptionnull44 override fun parseOption(option: String, args: ArgIterator): Boolean { 45 fun nextArg(): String = args.nextArgRequired(option) 46 47 when (option) { 48 // TODO: Write help 49 "-h", "--help" -> TODO("Help is not implemented yet") 50 51 "-p", "--policy-override-file" -> 52 policyOverrideFiles.add(nextArg().ensureFileExists()) 53 54 "-a", "--annotation-allowed-classes-file" -> 55 annotationAllowedClassesFile.set(nextArg().ensureFileExists()) 56 57 "-s", "--src" -> sourceFilesOrDirectories.add(nextArg().ensureFileExists()) 58 "--dump" -> dumpOperations.set(true) 59 "-o", "--output-script" -> outputScriptFile.set(nextArg()) 60 61 else -> return false 62 } 63 64 return true 65 } 66 checkArgsnull67 override fun checkArgs() { 68 if (policyOverrideFiles.size == 0) { 69 throw ArgumentsException("Must specify at least one policy file") 70 } 71 72 if (sourceFilesOrDirectories.size == 0) { 73 throw ArgumentsException("Must specify at least one source path") 74 } 75 } 76 dumpFieldsnull77 override fun dumpFields(): String { 78 return """ 79 policyOverrideFiles=$policyOverrideFiles 80 annotationAllowedClassesFile=$annotationAllowedClassesFile 81 sourceFilesOrDirectories=$sourceFilesOrDirectories 82 outputScriptFile=$outputScriptFile 83 dumpOperations=$dumpOperations 84 """.trimIndent() 85 } 86 } 87