1 /*
<lambda>null2  * 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.cli.internal
18 
19 import com.android.tools.metalava.cli.common.MetalavaCliException
20 import com.android.tools.metalava.cli.common.existingDir
21 import com.android.tools.metalava.cli.common.newDir
22 import com.github.ajalt.clikt.core.CliktCommand
23 import com.github.ajalt.clikt.parameters.arguments.argument
24 import java.io.File
25 
26 /** See [RewriteAnnotations] for more details. */
27 class MakeAnnotationsPackagePrivateCommand :
28     CliktCommand(
29         printHelpOnEmptyArgs = true,
30         hidden = true,
31         help =
32             """
33                 For a source directory full of annotation sources, generates corresponding package
34                 private versions of the same annotations in the target directory.
35             """
36                 .trimIndent(),
37     ) {
38 
39     private val sourceDir by
40         argument(
41                 "<source-dir>",
42                 help = "Source directory containing annotation sources.",
43             )
44             .existingDir()
45     private val targetDir by
46         argument(
47                 "<target-dir>",
48                 help = "Target directory into which the rewritten sources will be written",
49             )
50             .newDir()
51 
52     override fun run() {
53         val rewrite = RewriteAnnotations()
54         sourceDir.listFiles()?.forEach { file ->
55             try {
56                 rewrite.modifyAnnotationSources(null, file, File(targetDir, file.name))
57             } catch (e: IllegalStateException) {
58                 throw MetalavaCliException(e.message!!)
59             }
60         }
61     }
62 }
63