• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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.libraries.pcc.chronicle.api.policy.builder
18 
19 import com.android.libraries.pcc.chronicle.api.ChronicleHost
20 import com.android.libraries.pcc.chronicle.api.Flavor
21 import com.android.libraries.pcc.chronicle.api.error.PolicyNotFound
22 import com.android.libraries.pcc.chronicle.api.policy.Policy
23 
24 /** A set of [Policy] for all the flavors this policy is shipped on. */
25 data class FlavoredPolicies(val name: String, val flavorPolicies: Map<Flavor, Policy>) {
26   // Allows us to use the flavoredPolicies[flavor] on the top level [FlavoredPolicies] instance.
getnull27   operator fun get(flavor: Flavor): Policy? = flavorPolicies[flavor]
28 
29   fun getOrThrow(chronicleHost: ChronicleHost): Policy {
30     val flavor = chronicleHost.flavor
31     return this[flavor]
32       ?: throw PolicyNotFound(
33         "$name not allowed for use on build flavor=${flavor.name}. Missing " + "flavor() block?"
34       )
35   }
36 }
37