File: binaryCompatibility.gradle

package info (click to toggle)
jayway-jsonpath 2.0.0-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, forky, sid, trixie
  • size: 2,680 kB
  • sloc: java: 8,148; makefile: 4
file content (138 lines) | stat: -rw-r--r-- 4,846 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
 * Copyright 2003-2014 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.
 */

import groovy.text.markup.MarkupTemplateEngine
import groovy.text.markup.TemplateConfiguration


buildscript {
    // this block should not be necessary, but for some reason it fails without!
    repositories {
        jcenter()
    }

    dependencies {
        classpath 'me.champeau.gradle:japicmp-gradle-plugin:0.1.0'
    }
}


task checkBinaryCompatibility {
    description = 'Generates binary compatibility reports'
}


if (JavaVersion.current().isJava7Compatible()) {
    apply plugin: 'me.champeau.gradle.japicmp'

    def referenceMinorVersion = '1.1.0'

    def reportGenerator = { model ->
        outputProcessor {

            def skipClass = { c -> c.fullyQualifiedName.startsWith('com.jayway.jsonpath.internal') || c.fullyQualifiedName.contains('$')}
            def skipMethod = { c, m -> skipClass(c) || m.name =~ /access\$[0-9]+/ }
            def violations = [:].withDefault {
                // key = class name
                // value = map of violations
                [:].withDefault { [] }
            }
            removedMethod { c, m ->
                if (!skipMethod(c, m)) {
                    def level = m.name.startsWith('super$') ? 'warning' : 'error'
                    violations[c.fullyQualifiedName][level] << "Method ${m.name} has been removed"
                }
            }
            removedClass { c ->
                if (!skipClass(c)) {
                    violations[c.fullyQualifiedName].error << "Class has been removed"
                }
            }

            modifiedMethod { c, m ->
                if (!skipMethod(c, m)) {
                    violations[c.fullyQualifiedName].warning << """<p>Method ${m.name} has been modified</p>
<p>From <pre>${m.oldMethod.get()?.longName}</pre> to <pre>${m.newMethod.get()?.longName}</pre></p>"""
                }
            }

            newClass { c ->
                if (!skipClass(c)) {
                    violations[c.fullyQualifiedName].info << "Class has been added"
                }
            }
            newMethod { c, m ->
                if (!skipMethod(c, m)) {
                    violations[c.fullyQualifiedName].info << """<p>Method ${m.name} has been added</p>
<p>Signature: <pre>${m.newMethod.get()?.longName}</pre></p>"""
                }
            }
            after {
                model.violations = violations
            }
        }
    }

// using a global engine for all tasks in order to increase performance
    def configDir = file("$rootDir/gradle")
    def templateFile = 'binarycompat-report.groovy'
    def templateConfiguration = new TemplateConfiguration()
    templateConfiguration.with {
        autoIndent = true
        autoNewLine = true
    }
    def engine = new MarkupTemplateEngine(this.class.classLoader, configDir, templateConfiguration)


    subprojects {

        task japicmp(type: me.champeau.gradle.ArtifactJapicmpTask) {
            dependsOn jar
            //baseline = "com.jayway.jsonpath:${project.name}:${referenceMinorVersion}@jar"
            baseline = "com.jayway.jsonpath:${project.name}:+@jar"
            to = jar.archivePath
            accessModifier = 'protected'
            onlyModified = true
            failOnModification = false
            txtOutputFile = file("$buildDir/reports/japi.txt")

            def htmlReportFile = file("${buildDir}/reports/binary-compat-${project.name}.html")
            inputs.file file("$configDir/$templateFile")
            inputs.file templateFile
            outputs.file htmlReportFile

            def model = [title   : "Binary compatibility report for ${project.name}",
                         project : project,
                         baseline: baseline,
                         archive : to.name]
            outputProcessor(reportGenerator.curry(model))

            doLast {
                htmlReportFile.withWriter('utf-8') { wrt ->
                    engine.createTemplateByPath(templateFile).make(model).writeTo(wrt)
                }
            }

        }
    }

    subprojects {
        check.dependsOn(checkBinaryCompatibility)
        tasks.withType(me.champeau.gradle.ArtifactJapicmpTask) { task ->
            checkBinaryCompatibility.dependsOn(task)
        }
    }
}