-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathbuild.gradle
270 lines (232 loc) · 7.09 KB
/
build.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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
// Plugins {{{
plugins {
id "com.github.kt3k.coveralls" version "2.6.3"
}
// }}}
// Java Plugin {{{
apply plugin: 'java'
archivesBaseName = 'tailor'
def props = new Properties()
def config = file('src/main/resources/config.properties')
props.load(new FileInputStream(config))
version = props.getProperty('version')
// Add ANTLR output as sourceSet
sourceSets {
gen {
java {
srcDir file('src/gen/java')
}
}
}
test {
// Restrict heap size for the test JVM(s)
maxHeapSize = "2g"
// Display useful test events and output on the console
testLogging {
events "skipped", "failed", "standardOut", "standardError"
}
}
// JaCoCo Plugin {{{
apply plugin: 'jacoco'
// Ensure both XML and HTML reports are generated
jacocoTestReport {
reports {
xml.enabled = true
html.enabled = true
}
}
// Generate a test coverage report
test.finalizedBy jacocoTestReport
jacocoTestReport.dependsOn test
// }}}
compileJava {
// Enable compilation in a separate daemon process
options.fork = true
// Enable incremental compilation
options.incremental = true
}
// Ensure main JAR includes ANTLR output
jar {
from sourceSets.gen.output
}
// Ensure ANTLR output is generated before compilation
compileGenJava.dependsOn 'generateGrammarSource'
// }}}
// ANTLR Plugin {{{
// Generate ANTLR output based on Swift grammar
apply plugin: 'antlr'
generateGrammarSource {
outputDirectory = file('src/gen/java')
}
// }}}
// Application Plugin {{{
// Add run task
apply plugin: 'application'
applicationName = 'tailor'
mainClassName = 'com.sleekbyte.tailor.Tailor'
// Allow arguments: `gradle run -Pargs="args"`
run {
if (project.hasProperty('args')) {
args project.args.split('\\s+')
}
}
// Exclude unnecessary compile/runtime dependencies from distribution
distributions.main.contents {
exclude(
'antlr4-4.5.3.jar',
'com/',
)
}
// }}}
// Code Style Plugins {{{
// Use [Checkstyle](http://checkstyle.sourceforge.net) Plugin
apply plugin: 'checkstyle'
checkstyle {
toolVersion = "6.7"
// Exclude generated code from Checkstyle checks
sourceSets -= sourceSets.gen
}
// Fail the build if checkstyleMain or checkstyleTest have warnings
task verifyNoCheckstyleWarnings << {
def checkstyleMainWarningsFile = 'build/reports/checkstyle/main.xml'
def checkstyleTestWarningsFile = 'build/reports/checkstyle/test.xml'
File mainWarningsFile = file(checkstyleMainWarningsFile)
File testWarningsFile = file(checkstyleTestWarningsFile)
if (mainWarningsFile.exists() && mainWarningsFile.text.contains("<error ")) {
throw new GradleException("There were Checkstyle warnings! For more info check $mainWarningsFile")
}
if (testWarningsFile.exists() && testWarningsFile.text.contains("<error ")) {
throw new GradleException("There were Checkstyle warnings! For more info check $testWarningsFile")
}
}
checkstyleMain {
configFile = file('config/checkstyle/google_checks.xml')
// Always execute verifyNoCheckstyleWarnings task after this task
finalizedBy verifyNoCheckstyleWarnings
}
checkstyleTest {
configFile = file('config/checkstyle/google_test_checks.xml')
// Always execute verifyNoCheckstyleWarnings task after this task
finalizedBy verifyNoCheckstyleWarnings
}
// Use [FindBugs](http://findbugs.sourceforge.net/) Plugin
apply plugin: 'findbugs'
findbugs {
// Exclude generated code from FindBugs checks
sourceSets -= sourceSets.gen
}
tasks.withType(FindBugs) {
reports {
// Use HTML reports instead of XML
xml.enabled = false
html.enabled = true
}
}
// Use [PMD](http://pmd.sourceforge.net/) Plugin
apply plugin: 'pmd'
pmd {
// Exclude generated code from PMD checks
sourceSets -= sourceSets.gen
// Disable default ruleSets
ruleSets = []
// Use custom ruleSet file
ruleSetFiles = files('config/pmd/tailorRuleSet.xml')
}
tasks.withType(Pmd) {
reports {
// Use HTML reports instead of XML
xml.enabled = false
html.enabled = true
}
}
// }}}
// RubyGems {{{
task gems(type: Exec) {
inputs.file file('src/dist/gems/Gemfile')
outputs.dir file('src/dist/gems/vendor/')
workingDir 'src/dist/gems'
executable 'sh'
args '-c', 'bundle package --no-install'
}
// Ensure gems are packaged into distribution
distZip.dependsOn 'gems'
distTar.dependsOn 'gems'
installDist.dependsOn 'gems'
// }}}
// Update Version Number {{{
task setVersion {
doFirst {
println "Enter new version number:"
def writer = new FileWriter(config)
version = "${System.in.newReader().readLine()}"
try {
props.setProperty("version", "${version}")
props.store(writer, null)
writer.flush()
} finally {
writer.close()
}
updateInstallScripts.execute()
}
}
task updateInstallScripts(type: Exec) {
doFirst {
commandLine "sed", "-i", "", "s/[0-9]\\{1,\\}\\.[0-9]\\{1,\\}\\.[0-9]\\{1,\\}/${version}/g", "script/install.sh", "script/install.ps1", "script/uninstall.ps1"
}
}
// }}}
// Generate man page {{{
task manpage(type: Exec) {
inputs.files files('man/Gemfile', 'man/tailor.1.ronn')
outputs.files files('man/vendor/', 'src/dist/tailor.1')
workingDir 'man'
executable 'sh'
args '-c', "bundle install --path vendor/bundle" +
" && bundle exec ronn --manual='Tailor Manual' --organization='Sleekbyte' --roff tailor.1.ronn" +
" && mv tailor.1 ../src/dist/"
}
// Ensure man page is packaged into distribution
distZip.dependsOn 'manpage'
distTar.dependsOn 'manpage'
installDist.dependsOn 'manpage'
// }}}
// Install Globally {{{
task extractGlobally(type: Sync) {
from zipTree("${buildDir}/distributions/tailor-${version}.zip")
into '/usr/local/tailor'
}
task installMan(type: Exec) {
commandLine "ln", "-fs", "/usr/local/tailor/tailor-${version}/tailor.1", "/usr/local/share/man/man1/tailor.1"
}
task install(type: Exec) {
commandLine "ln", "-fs", "/usr/local/tailor/tailor-${version}/bin/tailor", "/usr/local/bin/tailor"
}
extractGlobally.dependsOn distZip
installMan.dependsOn extractGlobally
install.dependsOn installMan
// }}}
// Ensure ANTLR output, generated man page, and Ruby gems are deleted via clean
clean {
delete file('src/gen/')
delete files('src/dist/tailor.1')
delete files('src/dist/gems/.bundle/', 'src/dist/gems/Gemfile.lock', 'src/dist/gems/vendor/')
}
repositories {
jcenter()
}
dependencies {
antlr 'org.antlr:antlr4:4.6'
genCompileOnly 'org.antlr:antlr4-runtime:4.6'
// Ensure ANTLR output is compiled before main sourceSet
compile sourceSets.gen.output
compile 'commons-cli:commons-cli:1.4'
compile 'org.antlr:antlr4-runtime:4.6'
compile 'org.fusesource.jansi:jansi:1.15'
compile 'org.yaml:snakeyaml:1.18'
compile 'com.google.code.gson:gson:2.8.0'
compile 'com.github.spullara.mustache.java:compiler:0.9.4'
testCompile 'junit:junit:4.12'
testCompile 'org.hamcrest:hamcrest-all:1.3'
testCompile 'org.mockito:mockito-core:2.7.18'
testCompile 'com.github.stefanbirkner:system-rules:1.16.1'
}