1 /*
<lambda>null2  * Copyright 2019 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 androidx.build
18 
19 import java.io.File
20 import java.io.FileNotFoundException
21 import org.gradle.api.DefaultTask
22 import org.gradle.api.tasks.CacheableTask
23 import org.gradle.api.tasks.InputFiles
24 import org.gradle.api.tasks.Internal
25 import org.gradle.api.tasks.PathSensitive
26 import org.gradle.api.tasks.PathSensitivity
27 import org.gradle.api.tasks.TaskAction
28 
29 /**
30  * Task for building all of Androidx libraries and documentation
31  *
32  * AndroidXImplPlugin configuration adds dependencies to BuildOnServer for all of the tasks that
33  * produce artifacts that we want to build on server builds When BuildOnServer executes, it
34  * double-checks that all expected artifacts were built
35  */
36 @CacheableTask
37 open class BuildOnServerTask : DefaultTask() {
38 
39     init {
40         group = "Build"
41         description = "Builds all of the Androidx libraries and documentation"
42     }
43 
44     @Internal lateinit var distributionDirectory: File
45 
46     @InputFiles
47     @PathSensitive(PathSensitivity.RELATIVE)
48     fun getRequiredFiles(): List<File> {
49         return mutableListOf(
50                 "androidx_aggregate_build_info.txt",
51             )
52             .map { fileName -> File(distributionDirectory, fileName) }
53     }
54 
55     @TaskAction
56     fun checkAllBuildOutputs() {
57         val missingFiles = mutableListOf<String>()
58         getRequiredFiles().forEach { file ->
59             if (!file.exists()) {
60                 missingFiles.add(file.path)
61             }
62         }
63 
64         if (missingFiles.isNotEmpty()) {
65             val missingFileString = missingFiles.reduce { acc, s -> "$acc, $s" }
66             throw FileNotFoundException("buildOnServer required output missing: $missingFileString")
67         }
68     }
69 }
70