diff options
author | android-build-prod (mdb) <android-build-team-robot@google.com> | 2019-06-24 15:37:19 +0000 |
---|---|---|
committer | android-build-prod (mdb) <android-build-team-robot@google.com> | 2019-06-24 15:37:19 +0000 |
commit | bc078d80eebe42ed85f5a6ce274e9ef04bf9254b (patch) | |
tree | 314b1be5fef136fad99911f4124d6634bc186b42 | |
parent | 54cc4f9ccfa07267d800c143edc640960e278bc7 (diff) | |
parent | 67a44258af1d12bb5f68127c33402b1c8f141d7c (diff) | |
download | support-bc078d80eebe42ed85f5a6ce274e9ef04bf9254b.tar.gz |
Merge cherrypicks of [987861] into androidx-concurrent-release
Change-Id: Ie50470551e9d164d076bfb2f9e1ebc2d9cba7b51
5 files changed, 146 insertions, 12 deletions
diff --git a/buildSrc/jetpad-integration/src/main/java/androidx/build/jetpad/LibraryBuildInfoFile.java b/buildSrc/jetpad-integration/src/main/java/androidx/build/jetpad/LibraryBuildInfoFile.java index f188945b01a..e23bf0f98cb 100644 --- a/buildSrc/jetpad-integration/src/main/java/androidx/build/jetpad/LibraryBuildInfoFile.java +++ b/buildSrc/jetpad-integration/src/main/java/androidx/build/jetpad/LibraryBuildInfoFile.java @@ -26,6 +26,8 @@ import java.util.ArrayList; * DO NOT TOUCH. */ public class LibraryBuildInfoFile { + public String groupId; + public String artifactId; public String version; public ArrayList<Dependency> dependencies; public ArrayList<Check> checks; diff --git a/buildSrc/src/main/kotlin/androidx/build/AndroidXPlugin.kt b/buildSrc/src/main/kotlin/androidx/build/AndroidXPlugin.kt index bda8f7e1b46..05a209079f7 100644 --- a/buildSrc/src/main/kotlin/androidx/build/AndroidXPlugin.kt +++ b/buildSrc/src/main/kotlin/androidx/build/AndroidXPlugin.kt @@ -237,6 +237,9 @@ class AndroidXPlugin : Plugin<Project> { if (isRunningOnBuildServer()) { gradle.startParameter.showStacktrace = ShowStacktrace.ALWAYS } + val createAggregateBuildInfoFilesTask = + tasks.register(CREATE_AGGREGATE_BUILD_INFO_FILES_TASK, + CreateAggregateLibraryBuildInfoFileTask::class.java) val createLibraryBuildInfoFilesTask = tasks.register(CREATE_LIBRARY_BUILD_INFO_FILES_TASK) @@ -245,6 +248,7 @@ class AndroidXPlugin : Plugin<Project> { val buildOnServerTask = tasks.create(BUILD_ON_SERVER_TASK, BuildOnServer::class.java) buildOnServerTask.dependsOn(createArchiveTask) + buildOnServerTask.dependsOn(createAggregateBuildInfoFilesTask) buildOnServerTask.dependsOn(createLibraryBuildInfoFilesTask) val partiallyDejetifyArchiveTask = partiallyDejetifyArchiveTask( @@ -578,15 +582,33 @@ class AndroidXPlugin : Plugin<Project> { if (extension.publish.shouldRelease()) { // Only generate build info files for published libraries. val task = project.tasks.register( - "createLibraryBuildInfoFile", + CREATE_LIBRARY_BUILD_INFO_FILES_TASK, CreateLibraryBuildInfoFileTask::class.java - ) - project.rootProject.tasks.getByName(CREATE_LIBRARY_BUILD_INFO_FILES_TASK) - .dependsOn(task) + ) { + it.outputFile.set(File(project.getDistributionDirectory(), + "${project.group}_${project.name}_build_info.txt")) + } + project.rootProject.tasks.named(CREATE_LIBRARY_BUILD_INFO_FILES_TASK).configure { + it.dependsOn(task) + } + addTaskToAggregateBuildInfoFileTask(task) } } } + private fun Project.addTaskToAggregateBuildInfoFileTask( + task: TaskProvider<CreateLibraryBuildInfoFileTask> + ) { + project.rootProject.tasks.named(CREATE_AGGREGATE_BUILD_INFO_FILES_TASK).configure { + var aggregateLibraryBuildInfoFileTask: CreateAggregateLibraryBuildInfoFileTask = it + as CreateAggregateLibraryBuildInfoFileTask + aggregateLibraryBuildInfoFileTask.dependsOn(task) + aggregateLibraryBuildInfoFileTask.libraryBuildInfoFiles.add( + task.flatMap { it.outputFile } + ) + } + } + private fun Project.configureJacoco() { project.apply(plugin = "jacoco") project.configure<JacocoPluginExtension> { @@ -612,6 +634,7 @@ class AndroidXPlugin : Plugin<Project> { const val CHECK_NO_WARNINGS_TASK = "checkNoWarnings" const val CHECK_SAME_VERSION_LIBRARY_GROUPS = "checkSameVersionLibraryGroups" const val CREATE_LIBRARY_BUILD_INFO_FILES_TASK = "createLibraryBuildInfoFiles" + const val CREATE_AGGREGATE_BUILD_INFO_FILES_TASK = "createAggregateBuildInfoFiles" } } diff --git a/buildSrc/src/main/kotlin/androidx/build/BuildOnServer.kt b/buildSrc/src/main/kotlin/androidx/build/BuildOnServer.kt index 9e5623bc663..4d8a494d0b3 100644 --- a/buildSrc/src/main/kotlin/androidx/build/BuildOnServer.kt +++ b/buildSrc/src/main/kotlin/androidx/build/BuildOnServer.kt @@ -47,7 +47,7 @@ open class BuildOnServer : DefaultTask() { // "dokkaPublicDocs-$buildId.zip", "android-support-tipOfTree-docs-$buildId.zip", "dokkaTipOfTreeDocs-$buildId.zip", - + "androidx_aggregate_build_info.txt", "gmaven-diff-all-$buildId.zip", "top-of-tree-m2repository-all-$buildId.zip") diff --git a/buildSrc/src/main/kotlin/androidx/build/CreateAggregateLibraryBuildInfoFileTask.kt b/buildSrc/src/main/kotlin/androidx/build/CreateAggregateLibraryBuildInfoFileTask.kt new file mode 100644 index 00000000000..5b2ef1699a6 --- /dev/null +++ b/buildSrc/src/main/kotlin/androidx/build/CreateAggregateLibraryBuildInfoFileTask.kt @@ -0,0 +1,105 @@ +/* + * Copyright 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package androidx.build + +import androidx.build.jetpad.LibraryBuildInfoFile +import com.google.gson.Gson +import org.gradle.api.DefaultTask +import org.gradle.api.provider.ListProperty +import org.gradle.api.tasks.Input +import org.gradle.api.tasks.OutputFile +import org.gradle.api.tasks.TaskAction +import java.io.File +import java.util.ArrayList + +/** + * Task for a json file of all dependencies for each artifactId + */ +abstract class CreateAggregateLibraryBuildInfoFileTask : DefaultTask() { + init { + group = "Help" + description = "Generates a file containing library build information serialized to json" + } + + /** List of each build_info.txt file for each project. */ + @get:Input + abstract val libraryBuildInfoFiles: ListProperty<File> + + @OutputFile + val outputFile = File( + project.getDistributionDirectory(), + getAndroidxAggregateBuildInfoFilename() + ) + + private fun getAndroidxAggregateBuildInfoFilename(): String { + return "androidx_aggregate_build_info.txt" + } + + private data class AllLibraryBuildInfoFiles( + val Artifacts: ArrayList<LibraryBuildInfoFile> + ) + + /** + * Reads in file and checks that json is valid + */ + private fun jsonFileIsValid(jsonFile: File, artifactList: MutableList<String>): Boolean { + if (!jsonFile.exists()) { + return false + } + val gson = Gson() + val jsonString: String = jsonFile.readText(Charsets.UTF_8) + val aggregateBuildInfoFile = gson.fromJson(jsonString, AllLibraryBuildInfoFiles::class.java) + aggregateBuildInfoFile.Artifacts.forEach { artifact -> + if (!artifactList.contains("${artifact.groupId}_${artifact.artifactId}")) { + println("Failed to find ${artifact.artifactId} in artifact list!") + return false + } + } + return true + } + + /** + * Create the output file to contain the final complete AndroidX project build info graph + * file. Iterate through the list of project-specific build info files, and collects + * all dependencies as a JSON string. Finally, write this complete dependency graph to a text + * file as a json list of every project's build information + */ + @TaskAction + fun createAndroidxAggregateBuildInfoFile() { + // Loop through each file in the list of libraryBuildInfoFiles and collect all build info + // data from each of these $groupId-$artifactId-_build_info.txt files + var output = StringBuilder() + output.append("{ \"Artifacts\": [\n") + var artifactList = mutableListOf<String>() + for (infoFile in libraryBuildInfoFiles.get()) { + if ((infoFile.isFile and (infoFile.name != outputFile.name)) + and (infoFile.name.contains("_build_info.txt")) + ) { + var fileText: String = infoFile.readText(Charsets.UTF_8) + output.append("$fileText,") + artifactList.add(infoFile.name.replace("_build_info.txt", "")) + } + } + // Remove final ',' from list (so a null object doesn't get added to the end of the list) + output.setLength(output.length - 1) + output.append("]}") + outputFile.writeText(output.toString(), Charsets.UTF_8) + if (!jsonFileIsValid(outputFile, artifactList)) { + throw RuntimeException("JSON written to $outputFile was invalid.") + } + } +} diff --git a/buildSrc/src/main/kotlin/androidx/build/CreateLibraryBuildInfoFileTask.kt b/buildSrc/src/main/kotlin/androidx/build/CreateLibraryBuildInfoFileTask.kt index 966529066a7..83a390678ae 100644 --- a/buildSrc/src/main/kotlin/androidx/build/CreateLibraryBuildInfoFileTask.kt +++ b/buildSrc/src/main/kotlin/androidx/build/CreateLibraryBuildInfoFileTask.kt @@ -22,13 +22,14 @@ import org.gradle.api.artifacts.ProjectDependency import org.gradle.api.artifacts.ExternalModuleDependency import org.gradle.api.tasks.OutputFile import org.gradle.api.tasks.TaskAction +import org.gradle.api.provider.Property import com.google.gson.GsonBuilder import java.io.File import java.util.ArrayList /** - * This task generates a library build information file containing the version, - * public androidx dependencies and release checklist of the library for consumption + * This task generates a library build information file containing the artifactId, groupId, and + * version of public androidx dependencies and release checklist of the library for consumption * by the Jetpack Release Service (JetPad). */ open class CreateLibraryBuildInfoFileTask : DefaultTask() { @@ -38,7 +39,7 @@ open class CreateLibraryBuildInfoFileTask : DefaultTask() { } @OutputFile - val outputFile = File(project.getDistributionDirectory(), getLibraryBuildInfoFilename()) + val outputFile: Property<File> = project.objects.property(File::class.java) private fun getLibraryBuildInfoFilename(): String { return "${project.group}_${project.name}_build_info.txt" @@ -51,8 +52,9 @@ open class CreateLibraryBuildInfoFileTask : DefaultTask() { "output directory: ${project.getDistributionDirectory()}") } } - if (!outputFile.exists()) { - if (!outputFile.createNewFile()) { + var resolvedOutputFile: File = outputFile.get() + if (!resolvedOutputFile.exists()) { + if (!resolvedOutputFile.createNewFile()) { throw RuntimeException("Failed to create " + "output dependency dump file: $outputFile") } @@ -61,11 +63,13 @@ open class CreateLibraryBuildInfoFileTask : DefaultTask() { // Create json object from the artifact instance val gson = GsonBuilder().setPrettyPrinting().create() val serializedInfo: String = gson.toJson(info) - outputFile.writeText(serializedInfo) + resolvedOutputFile.writeText(serializedInfo) } private fun resolveAndCollectDependencies(): LibraryBuildInfoFile { val libraryBuildInfoFile = LibraryBuildInfoFile() + libraryBuildInfoFile.artifactId = project.name.toString() + libraryBuildInfoFile.groupId = project.group.toString() libraryBuildInfoFile.version = project.version.toString() val libraryDependencies = ArrayList<LibraryBuildInfoFile.Dependency>() val checks = ArrayList<LibraryBuildInfoFile.Check>() @@ -111,7 +115,7 @@ open class CreateLibraryBuildInfoFileTask : DefaultTask() { } /** - * Task: dumpDependencies + * Task: createLibraryBuildInfoFile * Iterates through each configuration of the project and builds the set of all dependencies. * Then adds each dependency to the Artifact class as a project or prebuilt dependency. Finally, * writes these dependencies to a json file as a json object. |