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 @file:JvmName("RavenHelperMain") 17 package com.android.platform.test.ravenwood.ravenhelper 18 19 /* 20 * This file contains the main entry point for the "ravenhelper" command, which 21 * contains subcommands to help various tasks. 22 */ 23 24 import com.android.hoststubgen.GeneralUserErrorException 25 import com.android.hoststubgen.LogLevel 26 import com.android.hoststubgen.executableName 27 import com.android.hoststubgen.log 28 import com.android.hoststubgen.runMainWithBoilerplate 29 import com.android.platform.test.ravenwood.ravenhelper.policytoannot.PtaProcessor 30 import com.android.platform.test.ravenwood.ravenhelper.sourcemap.MarkMethodHandler 31 32 interface SubcommandHandler { handlenull33 fun handle(args: List<String>) 34 } 35 36 fun usage() { 37 System.out.println(""" 38 Usage: 39 ravenhelper SUBCOMMAND options... 40 41 Subcommands: 42 pta: "policy-to-annotations" Convert policy file to annotations. 43 (See the pta-framework.sh script for usage.) 44 45 mm: "mark methods" Used to add annotations (such as @DisabledOnRavenwood) 46 to methods. 47 48 """.trimIndent()) 49 } 50 mainnull51fun main(args: Array<String>) { 52 executableName = "RavenHelper" 53 log.setConsoleLogLevel(LogLevel.Info) 54 55 runMainWithBoilerplate { 56 log.i("$executableName started") 57 58 if (args.size == 0) { 59 usage() 60 return 61 } 62 63 // Find the subcommand handler. 64 val subcommand = args[0] 65 val handler: SubcommandHandler = when (subcommand) { 66 "pta" -> PtaProcessor() 67 "mm" -> MarkMethodHandler() 68 else -> { 69 usage() 70 throw GeneralUserErrorException("Unknown subcommand '$subcommand'") 71 } 72 } 73 74 // Run the subcommand. 75 handler.handle(args.copyOfRange(1, args.size).toList()) 76 } 77 } 78