blob: a0744927faeb4ad10fcbc7903a1b31f6b6353837 [file] [log] [blame]
Sergey Vasilinetscb306422018-05-22 14:39:17 -07001/*
2 * Copyright 2018 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
17package androidx.build
18
Sergey Vasilinetsf38083e2018-05-29 17:10:15 -070019import androidx.build.ArtifactsPredicate.All
Sergey Vasilinetsaed74042018-08-21 17:34:32 -070020import androidx.build.ArtifactsPredicate.Benchmark
Sergey Vasilinetsf38083e2018-05-29 17:10:15 -070021import androidx.build.ArtifactsPredicate.Exact
22import androidx.build.ArtifactsPredicate.Group
Sergey Vasilinetsf38083e2018-05-29 17:10:15 -070023import androidx.build.Strategy.Ignore
Roberto Pereze2ce75f2018-07-27 13:14:34 -070024import androidx.build.Strategy.Prebuilts
25import androidx.build.Strategy.TipOfTree
Sergey Vasilinetscb306422018-05-22 14:39:17 -070026
Jeff Gaston9c31ae52018-07-25 15:22:32 -040027val RELEASE_RULE = docsRules("public", false) {
Nick Anthonyba7da7a2018-09-26 10:49:24 -040028 prebuilts(LibraryGroups.ANNOTATION, "1.0.0")
29 prebuilts(LibraryGroups.APPCOMPAT, "1.0.0")
30 prebuilts(LibraryGroups.ASYNCLAYOUTINFLATER, "1.0.0")
Kevin Chyn73d6d732018-09-11 19:48:20 -070031 prebuilts(LibraryGroups.BIOMETRIC, "biometric", "1.0.0-alpha01")
Nick Anthonyba7da7a2018-09-26 10:49:24 -040032 prebuilts(LibraryGroups.BROWSER, "1.0.0")
Anthony Chen6c090632018-09-07 16:24:50 -070033 ignore(LibraryGroups.CAR, "car-moderator")
Roberto Perez77fe64e2018-10-05 16:30:46 -070034 prebuilts(LibraryGroups.CAR, "car-cluster", "1.0.0-alpha5")
35 prebuilts(LibraryGroups.CAR, "car", "1.0.0-alpha5")
Roberto Perez022a7192018-08-01 19:57:17 -070036 .addStubs("car/stubs/android.car.jar")
Nick Anthonyba7da7a2018-09-26 10:49:24 -040037 prebuilts(LibraryGroups.CARDVIEW, "1.0.0")
38 prebuilts(LibraryGroups.COLLECTION, "1.0.0")
39 prebuilts(LibraryGroups.CONTENTPAGER, "1.0.0")
40 prebuilts(LibraryGroups.COORDINATORLAYOUT, "1.0.0")
41 prebuilts(LibraryGroups.CORE, "1.0.0")
42 prebuilts(LibraryGroups.CURSORADAPTER, "1.0.0")
43 prebuilts(LibraryGroups.CUSTOMVIEW, "1.0.0")
44 prebuilts(LibraryGroups.DOCUMENTFILE, "1.0.0")
45 prebuilts(LibraryGroups.DRAWERLAYOUT, "1.0.0")
46 prebuilts(LibraryGroups.DYNAMICANIMATION, "1.0.0")
47 prebuilts(LibraryGroups.EMOJI, "1.0.0")
48 prebuilts(LibraryGroups.EXIFINTERFACE, "1.0.0")
49 prebuilts(LibraryGroups.FRAGMENT, "1.0.0")
50 prebuilts(LibraryGroups.GRIDLAYOUT, "1.0.0")
51 prebuilts(LibraryGroups.HEIFWRITER, "1.0.0")
52 prebuilts(LibraryGroups.INTERPOLATOR, "1.0.0")
53 prebuilts(LibraryGroups.LEANBACK, "1.0.0")
54 prebuilts(LibraryGroups.LEGACY, "1.0.0")
55 prebuilts(LibraryGroups.LOADER, "1.0.0")
56 prebuilts(LibraryGroups.LOCALBROADCASTMANAGER, "1.0.0")
57 prebuilts(LibraryGroups.MEDIA, "media", "1.0.0")
Aurimas Liutikas518ffe32018-08-06 18:42:13 -070058 prebuilts(LibraryGroups.MEDIA, "media-widget", "1.0.0-alpha5")
Andrew Lewis51999562018-07-24 11:03:01 +010059 ignore(LibraryGroups.MEDIA2, "media2-exoplayer")
Alan Viverette36092a52018-09-17 14:37:13 -040060 prebuilts(LibraryGroups.MEDIA2, "1.0.0-alpha03")
Nick Anthonyba7da7a2018-09-26 10:49:24 -040061 prebuilts(LibraryGroups.MEDIAROUTER, "1.0.0")
62 prebuilts(LibraryGroups.PALETTE, "1.0.0")
63 prebuilts(LibraryGroups.PERCENTLAYOUT, "1.0.0")
64 prebuilts(LibraryGroups.PREFERENCE, "1.0.0")
65 prebuilts(LibraryGroups.PRINT, "1.0.0")
66 prebuilts(LibraryGroups.RECOMMENDATION, "1.0.0")
67 prebuilts(LibraryGroups.RECYCLERVIEW, "1.0.0")
68 prebuilts(LibraryGroups.SLICE, "slice-builders", "1.0.0")
Alan Viverette36092a52018-09-17 14:37:13 -040069 prebuilts(LibraryGroups.SLICE, "slice-builders-ktx", "1.0.0-alpha6")
Nick Anthonyba7da7a2018-09-26 10:49:24 -040070 prebuilts(LibraryGroups.SLICE, "slice-core", "1.0.0")
Sergey Vasilinets82887932018-07-24 16:30:59 -070071 // TODO: land prebuilts
Nick Anthonyba7da7a2018-09-26 10:49:24 -040072// prebuilts(LibraryGroups.SLICE, "slice-test", "1.0.0")
Sergey Vasilinets82887932018-07-24 16:30:59 -070073 ignore(LibraryGroups.SLICE, "slice-test")
Nick Anthonyba7da7a2018-09-26 10:49:24 -040074 prebuilts(LibraryGroups.SLICE, "slice-view", "1.0.0")
75 prebuilts(LibraryGroups.SLIDINGPANELAYOUT, "1.0.0")
76 prebuilts(LibraryGroups.SWIPEREFRESHLAYOUT, "1.0.0")
77 prebuilts(LibraryGroups.TRANSITION, "1.0.0")
78 prebuilts(LibraryGroups.TVPROVIDER, "1.0.0")
79 prebuilts(LibraryGroups.VECTORDRAWABLE, "1.0.0")
80 prebuilts(LibraryGroups.VIEWPAGER, "1.0.0")
81 prebuilts(LibraryGroups.WEAR, "1.0.0")
Sergey Vasilinetscb306422018-05-22 14:39:17 -070082 .addStubs("wear/wear_stubs/com.google.android.wearable-stubs.jar")
Nick Anthonyba7da7a2018-09-26 10:49:24 -040083 prebuilts(LibraryGroups.WEBKIT, "1.0.0")
Daniel Santiago Riveraf4a4cd12018-10-03 10:09:51 -070084 prebuilts(LibraryGroups.ROOM, "2.1.0-alpha01")
85 prebuilts(LibraryGroups.PERSISTENCE, "2.0.0")
Sergey Vasilinets82887932018-07-24 16:30:59 -070086 ignore(LibraryGroups.LIFECYCLE, "lifecycle-savedstate-core")
87 ignore(LibraryGroups.LIFECYCLE, "lifecycle-savedstate-fragment")
88 ignore(LibraryGroups.LIFECYCLE, "lifecycle-viewmodel-savedstate")
89 ignore(LibraryGroups.LIFECYCLE, "lifecycle-viewmodel-fragment")
Nick Anthony50a39ca2018-09-19 17:56:49 -070090 prebuilts(LibraryGroups.LIFECYCLE, "2.0.0")
91 prebuilts(LibraryGroups.ARCH_CORE, "2.0.0")
Sergey Vasilinets2112cda2018-06-06 23:23:26 -070092 ignore(LibraryGroups.PAGING, "paging-common-ktx")
93 ignore(LibraryGroups.PAGING, "paging-runtime-ktx")
94 ignore(LibraryGroups.PAGING, "paging-rxjava2-ktx")
Daniel Santiago Riveraf4a4cd12018-10-03 10:09:51 -070095 prebuilts(LibraryGroups.PAGING, "2.0.0")
Ian Lake9045c0a2018-09-19 21:54:17 -070096 prebuilts(LibraryGroups.NAVIGATION, "1.0.0-alpha06")
Sumir Kataria78f0eb82018-09-18 15:57:19 -070097 prebuilts(LibraryGroups.WORKMANAGER, "1.0.0-alpha09")
Sergey Vasilinetscb306422018-05-22 14:39:17 -070098 default(Ignore)
99}
100
Jeff Gaston9c31ae52018-07-25 15:22:32 -0400101val TIP_OF_TREE = docsRules("tipOfTree", true) {
Sergey Vasilinets4a92ec62018-08-28 01:28:10 -0700102 // TODO: remove once we'll figure out our strategy about it
103 ignore(LibraryGroups.CONCURRENT)
Sergey Vasilinetsc74c7fb52018-05-29 14:50:22 -0700104 default(TipOfTree)
105}
106
Sergey Vasilinetscb306422018-05-22 14:39:17 -0700107/**
108 * Rules are resolved in addition order. So if you have two rules that specify how docs should be
109 * built for a module, first defined rule wins.
110 */
Aurimas Liutikas518ffe32018-08-06 18:42:13 -0700111fun docsRules(
112 name: String,
113 offline: Boolean,
114 init: PublishDocsRulesBuilder.() -> Unit
115): PublishDocsRules {
Jeff Gaston9c31ae52018-07-25 15:22:32 -0400116 val f = PublishDocsRulesBuilder(name, offline)
Sergey Vasilinetscb306422018-05-22 14:39:17 -0700117 f.init()
118 return f.build()
119}
120
Jeff Gaston9c31ae52018-07-25 15:22:32 -0400121class PublishDocsRulesBuilder(private val name: String, private val offline: Boolean) {
Sergey Vasilinetscb306422018-05-22 14:39:17 -0700122
Sergey Vasilinetsaed74042018-08-21 17:34:32 -0700123 private val rules: MutableList<DocsRule> = mutableListOf(DocsRule(Benchmark, Ignore))
Sergey Vasilinetscb306422018-05-22 14:39:17 -0700124 /**
125 * docs for projects within [groupName] will be built from sources.
126 */
127 fun tipOfTree(groupName: String) {
Sergey Vasilinetsf38083e2018-05-29 17:10:15 -0700128 rules.add(DocsRule(Group(groupName), TipOfTree))
Sergey Vasilinetscb306422018-05-22 14:39:17 -0700129 }
130
131 /**
132 * docs for a project with the given [groupName] and [name] will be built from sources.
133 */
134 fun tipOfTree(groupName: String, name: String) {
Sergey Vasilinetsf38083e2018-05-29 17:10:15 -0700135 rules.add(DocsRule(Exact(groupName, name), TipOfTree))
Sergey Vasilinetscb306422018-05-22 14:39:17 -0700136 }
137
138 /**
139 * docs for a project with the given [groupName] and [name] will be built from a prebuilt with
140 * the given [version].
141 */
Roberto Perez77fe64e2018-10-05 16:30:46 -0700142 fun prebuilts(groupName: String, moduleName: String, version: String): Prebuilts {
143 val strategy = Prebuilts(Version(version))
144 rules.add(DocsRule(Exact(groupName, moduleName), strategy))
145 return strategy
Sergey Vasilinetscb306422018-05-22 14:39:17 -0700146 }
147
148 /**
149 * docs for projects within [groupName] will be built from prebuilts with the given [version]
150 */
151 fun prebuilts(groupName: String, version: String) = prebuilts(groupName, Version(version))
152
153 /**
154 * docs for projects within [groupName] will be built from prebuilts with the given [version]
155 */
156 fun prebuilts(groupName: String, version: Version): Prebuilts {
157 val strategy = Prebuilts(version)
Sergey Vasilinetsf38083e2018-05-29 17:10:15 -0700158 rules.add(DocsRule(Group(groupName), strategy))
Sergey Vasilinetscb306422018-05-22 14:39:17 -0700159 return strategy
160 }
161
162 /**
163 * defines a default strategy for building docs
164 */
Sergey Vasilinetsf38083e2018-05-29 17:10:15 -0700165 fun default(strategy: Strategy) {
166 rules.add(DocsRule(All, strategy))
Sergey Vasilinetscb306422018-05-22 14:39:17 -0700167 }
168
169 /**
170 * docs for projects within [groupName] won't be built
171 */
172 fun ignore(groupName: String) {
Sergey Vasilinetsf38083e2018-05-29 17:10:15 -0700173 rules.add(DocsRule(Group(groupName), Ignore))
Sergey Vasilinetscb306422018-05-22 14:39:17 -0700174 }
175
176 /**
177 * docs for a specified project won't be built
178 */
179 fun ignore(groupName: String, name: String) {
Sergey Vasilinetsf38083e2018-05-29 17:10:15 -0700180 rules.add(DocsRule(Exact(groupName, name), Ignore))
Sergey Vasilinetscb306422018-05-22 14:39:17 -0700181 }
182
Jeff Gaston9c31ae52018-07-25 15:22:32 -0400183 fun build() = PublishDocsRules(name, offline, rules)
Sergey Vasilinetscb306422018-05-22 14:39:17 -0700184}
185
Sergey Vasilinetsf38083e2018-05-29 17:10:15 -0700186sealed class ArtifactsPredicate {
187 abstract fun apply(inGroup: String, inName: String): Boolean
188 object All : ArtifactsPredicate() {
189 override fun apply(inGroup: String, inName: String) = true
190 }
191 class Group(val group: String) : ArtifactsPredicate() {
192 override fun apply(inGroup: String, inName: String) = inGroup == group
193 override fun toString() = "\"$group\""
194 }
195 class Exact(val group: String, val name: String) : ArtifactsPredicate() {
196 override fun apply(inGroup: String, inName: String) = group == inGroup && name == inName
197 override fun toString() = "\"$group\", \"$name\""
198 }
Sergey Vasilinetsaed74042018-08-21 17:34:32 -0700199
200 object Benchmark : ArtifactsPredicate() {
201 override fun apply(inGroup: String, inName: String) = inName.endsWith("-benchmark")
202 }
Sergey Vasilinetsf38083e2018-05-29 17:10:15 -0700203}
204
205data class DocsRule(val predicate: ArtifactsPredicate, val strategy: Strategy) {
206 override fun toString(): String {
207 if (predicate is All) {
208 return "default($strategy)"
209 }
210 return when (strategy) {
211 is Prebuilts -> "prebuilts($predicate, \"${strategy.version}\")"
212 is Ignore -> "ignore($predicate)"
213 is TipOfTree -> "tipOfTree($predicate)"
Sergey Vasilinetscb306422018-05-22 14:39:17 -0700214 }
215 }
Sergey Vasilinetsf38083e2018-05-29 17:10:15 -0700216}
Sergey Vasilinetscb306422018-05-22 14:39:17 -0700217
Sergey Vasilinetsf38083e2018-05-29 17:10:15 -0700218sealed class Strategy {
219 object TipOfTree : Strategy()
220 object Ignore : Strategy()
221 class Prebuilts(val version: Version) : Strategy() {
222 var stubs: MutableList<String>? = null
223 fun addStubs(path: String) {
224 if (stubs == null) {
225 stubs = mutableListOf()
226 }
227 stubs!!.add(path)
228 }
229
230 override fun toString() = "Prebuilts(\"$version\")"
231 }
232}
233
Jeff Gaston9c31ae52018-07-25 15:22:32 -0400234class PublishDocsRules(val name: String, val offline: Boolean, private val rules: List<DocsRule>) {
Sergey Vasilinetsf38083e2018-05-29 17:10:15 -0700235 fun resolve(groupName: String, moduleName: String): DocsRule {
236 return rules.find { it.predicate.apply(groupName, moduleName) } ?: throw Error()
Sergey Vasilinetscb306422018-05-22 14:39:17 -0700237 }
Chris Craik51f6bc22018-05-23 18:11:26 -0700238}