• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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.testing
18 
19 import com.android.tools.lint.checks.infrastructure.TestFile
20 
21 private val standardClasspath = getKotlinStdlibPaths() + getAndroidJar()
22 val standardProjectXmlClasspath =
<lambda>null23     standardClasspath.joinToString("\n") { "<classpath file=\"$it\"/>" }
24 
25 /** The XML string for one module of a project (using the [standardProjectXmlClasspath]). */
createModuleDescriptionnull26 fun createModuleDescription(
27     moduleName: String,
28     android: Boolean,
29     sourceFiles: Array<TestFile>,
30     dependsOn: List<String> = listOf("commonMain"),
31 ): String {
32     val sourceLines = sourceFiles.joinToString("\n") { "<src file=\"${it.targetRelativePath}\" />" }
33     val dependsOnLines = dependsOn.joinToString("\n") { "<dep module=\"$it\" kind=\"dependsOn\"/>" }
34     return """
35         <module name="$moduleName" android="$android">
36           $dependsOnLines
37           $sourceLines
38           $standardProjectXmlClasspath
39         </module>
40         """
41 }
42 
43 /** The XML string for the common module of a project. */
createCommonModuleDescriptionnull44 fun createCommonModuleDescription(sourceFiles: Array<TestFile>): String {
45     return createModuleDescription("commonMain", false, sourceFiles, emptyList())
46 }
47 
48 /** The XML string for the android module of a project. */
createAndroidModuleDescriptionnull49 fun createAndroidModuleDescription(
50     sourceFiles: Array<TestFile>,
51     dependsOn: List<String> = listOf("commonMain"),
52 ): String {
53     return createModuleDescription("androidMain", true, sourceFiles, dependsOn)
54 }
55 
56 /** The XML string for a project, with no root dir set (so the file location is the root dir). */
createProjectDescriptionnull57 fun createProjectDescription(vararg modules: String): TestFile {
58     return xml(
59         "project.xml",
60         """
61         <project>
62           ${modules.joinToString("\n")}
63         </project>
64         """
65     )
66 }
67