From 8ab49a70e99b1cdb157d1e6b340b3c57f1681d75 Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Mon, 14 May 2018 23:09:40 +0300 Subject: [PATCH] Make dexMethodCount task incremental unless teamcity output is required Declare details file as output, circumvent task up-to-date check if teamcity statistics output is required. --- .../src/main/kotlin/plugins/DexMethodCount.kt | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/buildSrc/src/main/kotlin/plugins/DexMethodCount.kt b/buildSrc/src/main/kotlin/plugins/DexMethodCount.kt index 9182acc4b9c..b0ea324030c 100644 --- a/buildSrc/src/main/kotlin/plugins/DexMethodCount.kt +++ b/buildSrc/src/main/kotlin/plugins/DexMethodCount.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2017 JetBrains s.r.o. - * - * 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. + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. */ import com.jakewharton.dex.* @@ -30,6 +19,10 @@ open class DexMethodCount : DefaultTask() { val byClass: Map ) + init { + outputs.upToDateWhen { !shouldPrintTeamCityStatistics } // always execute when teamCityStatistics output is required + } + @InputFile lateinit var jarFile: File @@ -42,6 +35,9 @@ open class DexMethodCount : DefaultTask() { @Optional var teamCityStatistics: Boolean? = null + private val shouldPrintTeamCityStatistics = teamCityStatistics ?: project.hasProperty("teamcity") + + @Input @Optional var artifactName: String? = null @@ -54,8 +50,12 @@ open class DexMethodCount : DefaultTask() { dependsOn(jar) } + @Internal // plain output properties are not supported, mark as internal to suppress warning from validateTaskProperties lateinit var counts: Counts + @get:OutputFile + val detailOutputFile: File get() = project.buildDir.resolve("$artifactOrArchiveName-method-count.txt") + @TaskAction fun invoke() { val methods = dexMethods(jarFile) @@ -96,7 +96,7 @@ open class DexMethodCount : DefaultTask() { } private fun printTCStats(counts: Counts) { - if (teamCityStatistics ?: project.hasProperty("teamcity")) { + if (shouldPrintTeamCityStatistics) { println("##teamcity[buildStatisticValue key='DexMethodCount_${artifactOrArchiveName}' value='${counts.total}']") counts.totalOwnPackages?.let { value -> println("##teamcity[buildStatisticValue key='DexMethodCount_${artifactOrArchiveName}_OwnPackages' value='$value']") @@ -108,8 +108,7 @@ open class DexMethodCount : DefaultTask() { } private fun outputDetails(counts: Counts) { - val detailFile = project.buildDir.resolve("$artifactOrArchiveName-method-count.txt") - detailFile.printWriter().use { writer -> + detailOutputFile.printWriter().use { writer -> writer.println("${counts.total.padRight()}\tTotal methods") ownPackages?.let { packages -> writer.println("${counts.totalOwnPackages?.padRight()}\tTotal methods from packages ${packages.joinToString { "$it.*" }}")