File: ciReporting.gradle

package info (click to toggle)
gradle 4.4.1-6
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 85,104 kB
  • sloc: java: 319,724; xml: 14,356; cpp: 4,200; ansic: 1,025; sh: 300; makefile: 60; asm: 17; jsp: 17; objc: 10
file content (52 lines) | stat: -rw-r--r-- 3,173 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
 * Copyright 2017 the original author or authors.
 *
 * 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.
 */

if (isCiServer) {
    /*
     * When run from a Continuous Integration environment, we only want to archive a subset of reports, mostly for
     * failing tasks only, to not use up unnecessary disk space on Team City. This also improves the performance of
     * artifact publishing by reducing the artifacts and packaging reports that consist of multiple files.
     *
     * Reducing the number of reports also makes it easier to find the important ones when analysing a failed build in
     * Team City.
     */
    gradle.buildFinished { buildResult ->
        allprojects { buildSrcOrSubProject ->
            tasks.withType(Reporting).find { it.state.failure }.collect { it.reports.html.destination }.unique().each { prepareReportForCIPublishing(buildSrcOrSubProject.name, it)}
        }
        subprojects { subproject ->
            tasks.withType(ValidateTaskProperties).find { it.state.failure }.collect { it.outputFile }.unique().each { prepareReportForCIPublishing(subproject.name, it) }
            tasks.withType(org.gradle.plugins.classycle.Classycle).find { it.state.failure }.collect { it.reportFile }.unique().each { prepareReportForCIPublishing(subproject.name, it) }
            tasks.withType(me.champeau.gradle.japicmp.JapicmpTask).collect { new File(it.richReport.destinationDir, it.richReport.reportName) }.unique().each { prepareReportForCIPublishing(subproject.name, it) }
            tasks.withType(org.gradle.testing.DistributedPerformanceTest).collect { it.scenarioReport.parentFile }.unique().each { prepareReportForCIPublishing(subproject.name, it) }
            tasks.withType(org.gradle.testing.DistributionTest).find { it.state.failure }.collect { it.daemonRegistry }.unique().each { prepareReportForCIPublishing("all-logs", it) } //daemons are shared by all subprojects
            tasks.withType(org.gradle.testing.DistributionTest).find { it.state.failure }.collect { new File(it.gradleUserHomeDir, "worker-1/test-kit-daemon") }.unique().each { prepareReportForCIPublishing("all-logs", it) } //test-kit daemons are shared by all subprojects
        }
    }
}

def prepareReportForCIPublishing(projectName, report) {
    if (report.directory) {
        def destFile = new File("${rootProject.buildDir}/report-${projectName}-${report.name}.zip")
        ant.zip(destfile: destFile) { fileset(dir: report) }
    } else if (report.file) {
        copy {
            from report
            into rootProject.buildDir
            rename { "report-${projectName}-${report.parentFile.name}-${report.name}" }
        }
    }
}