• 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.cli.common
18 
19 import com.android.tools.metalava.Options
20 import com.android.tools.metalava.model.Codebase
21 import com.android.tools.metalava.model.ModelOptions
22 import com.android.tools.metalava.model.source.SourceModelProvider
23 
24 /**
25  * Contains information provided by the tests.
26  *
27  * This is used to avoid having to add command line options that are only intended for use by the
28  * tests but which could be supplied on an actual command line.
29  */
30 class TestEnvironment(
31     /**
32      * Packages to skip emitting signatures/stubs for even if public. Typically used for unit tests
33      * referencing to classpath classes that aren't part of the definitions and shouldn't be part of
34      * the test output; e.g. a test may reference java.lang.Enum but we don't want to start
35      * reporting all the public APIs in the java.lang package just because it's indirectly
36      * referenced via the "enum" superclass
37      */
38     val skipEmitPackages: List<String>,
39     val sourceModelProvider: SourceModelProvider,
40     val modelOptions: ModelOptions,
41 
42     /**
43      * An optional lambda that is called on the [CheckerContext] after the analysis phase has
44      * completed.
45      *
46      * This is set by tests to check the state of the objects referenced from [CheckerContext] like
47      * [Codebase] and [Options] that are not easily verifiable through other means.
48      */
49     val postAnalysisChecker: CheckerFunction? = null,
50 )
51 
52 /**
53  * Encapsulates some internal state of the main metalava command for checking in
54  * [TestEnvironment.postAnalysisChecker] lambda.
55  */
56 class CheckerContext(
57     val options: Options,
58     val codebase: Codebase,
59 )
60 
61 /** Alias for a lambda that is invoked on [CheckerContext] to check its state as part of a test. */
62 typealias CheckerFunction = CheckerContext.() -> Unit
63