-
Notifications
You must be signed in to change notification settings - Fork 180
/
jdiff.gradle
177 lines (147 loc) · 5.91 KB
/
jdiff.gradle
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/*
* Copyright 2015 Netflix, Inc.
*
* 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.
*/
plugins {
id 'org.ajoberstar.github-pages' version '1.4.2'
}
githubPages {
repoUri = Grgit.open().remote.list().first().url
deleteExistingFiles = false
pages {
final olderVersion = project.hasProperty('jDiff.olderVersion') ? project.getProperty('jDiff.olderVersion') : rootProject.version
final newerVersion = project.hasProperty('jDiff.newerVersion') ? project.getProperty('jDiff.newerVersion') : rootProject.version
from("${rootProject.buildDir}/reports/jDiff/${olderVersion}-to-${newerVersion}") {
include('**')
into("jDiff/${olderVersion}-to-${newerVersion}")
}
from("${rootProject.buildDir}/gh-pages/${rootProject.name}") {
include('jdiff.js')
}
}
}
prepareGhPages.dependsOn('generateJDiffJs')
import org.ajoberstar.grgit.Grgit
subprojects {
apply plugin: 'java'
repositories {
mavenLocal()
mavenCentral()
}
group = "com.netflix.governator"
dependencies {
testCompile 'org.slf4j:slf4j-log4j12:1.7.2'
}
}
/**
* Generate a JDiff report between a newer version and an older version.
*
* Usage:
* gradle -PjDiff.olderVersion=2.1312.0 [-PjDiff.newerVersion=2.1716.0] generateJDiffReport
*
* View generated report at:
* build/reports/jDiff/${olderVersion}-to-${newerVersion}/changes.html
*/
task generateJDiffReport(dependsOn: '_jDiff_cloneOldVersion') {
description = "Generates a JDiff report"
group = "Documentation"
final jDiffHome = "${rootProject.rootDir}/buildSrc/lib/jdiff-1.1.1/"
ant.taskdef(
name: 'jDiff',
classname: 'jdiff.JDiffAntTask',
classpath: "${jDiffHome}/antjdiff.jar")
doLast {
final olderVersion = project.getProperty('jDiff.olderVersion')
final olderVersionRoot = new File("${rootProject.buildDir}/jDiff/${rootProject.name}-${olderVersion}")
if (olderVersion == null)
throw new IllegalArgumentException(
'Set `jDiff.olderVersion` property to indicate older of the two versions being compared')
final newerVersion = project.hasProperty('jDiff.newerVersion') ? project.getProperty('jDiff.newerVersion') : rootProject.version
final newerVersionRoot = rootProject.rootDir
final outputDir = "${rootProject.buildDir}/reports/jDiff/${olderVersion}-to-${newerVersion}"
mkdir(outputDir)
ant.metaClass.jDiff_getSrcDirSets = { root ->
root.eachDirMatch({ dir ->
new File("${dir}/src/main/java").exists()
}) { dir ->
dirset(dir: "${dir}/src/main/java")
}
}
ant.property(name: "JDIFF_HOME", value: jDiffHome)
ant.jDiff(
destdir: outputDir,
verbose: 'off',
stats: 'on',
docchanges: 'off',
source: '1.8') {
old(name: "${rootProject.name}-${olderVersion}") {
jDiff_getSrcDirSets(olderVersionRoot)
}
'new'(name: "${rootProject.name}-${newerVersion}") {
jDiff_getSrcDirSets(newerVersionRoot)
}
}
}
}
task jDiffJar(type: Jar) << {
final olderVersion = project.getProperty('jDiff.olderVersion')
final newerVersion = project.hasProperty('jDiff.newerVersion') ? project.getProperty('jDiff.newerVersion') : rootProject.version
classifier = 'jdiff'
extension = 'jar'
destinationDir = file("${rootProject.buildDir}/libs")
from "${rootProject.buildDir}/reports/jDiff/${olderVersion}-to-${newerVersion}/changes"
}
task _jDiff_cloneOldVersion << {
final olderVersion = project.getProperty('jDiff.olderVersion')
final olderVersionRoot = new File("${rootProject.buildDir}/jDiff/${rootProject.name}-${olderVersion}")
final newerVersionRoot = rootProject.rootDir
if (!olderVersionRoot.isDirectory()) {
Grgit.clone(
uri: "file://${newerVersionRoot.path}/.git",
dir: olderVersionRoot.path,
refToCheckout: "refs/tags/v${olderVersion}")
}
}
task generateJDiffJs(dependsOn: ['_githubPages_cloneGhPages', 'generateJDiffReport']) << {
final jdiffJs = new File("${rootProject.buildDir}/gh-pages/${rootProject.name}/jdiff.js")
final indentation = '| '
final jDiffParents = [jdiffJs.parent, "${rootProject.buildDir}/reports"]
final jDiffReports = jDiffParents.collect {
new File(it, 'jDiff').listFiles()
}.flatten().findAll {
it?.isDirectory()
}.collect {
"${indentation}'${it.name}'"
}.sort().unique().reverse().join(',\n')
final jdiffJsContents = """
|// This file was automatically generated by the `generateJDiffJs` Gradle task. Do not manually edit.
|angular.module('Index', [])
| .controller('JDiff', ['\$scope', function (\$scope) {
| \$scope['j-diff-reports'] = [
${jDiffReports}].map(function (jDiffReport) {
| return [jDiffReport.replace(/.*-to-/, ''), jDiffReport];
| });
| }]);
""".stripMargin().trim()
jdiffJs.write(jdiffJsContents)
}
task _githubPages_cloneGhPages << {
final ghPagesRoot = new File("${rootProject.buildDir}/gh-pages/${rootProject.name}")
if (!ghPagesRoot.isDirectory()) {
Grgit.clone(
uri: githubPages.repoUri,
dir: ghPagesRoot.path,
refToCheckout: 'gh-pages')
}
}