-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbuild.gradle
296 lines (267 loc) · 9.91 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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
import groovy.json.JsonOutput
buildscript {
repositories {
maven {
url 'https://plugins.gradle.org/m2/'
}
mavenCentral()
}
dependencies {
classpath 'com.gradle.publish:plugin-publish-plugin:0.9.1'
classpath 'com.moowork.gradle:gradle-node-plugin:0.10'
classpath 'net.rdrei.android.buildtimetracker:gradle-plugin:0.5.0'
}
}
plugins {
id 'maven'
id 'maven-publish'
id 'com.jfrog.bintray' version '1.2'
id 'net.saliman.cobertura' version '2.2.8'
id 'com.github.kt3k.coveralls' version '2.3.1'
id 'com.github.ksoichiro.web.resource' version '1.7.3'
id 'com.github.ksoichiro.console.reporter' version '0.5.0'
}
apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'com.moowork.node'
apply plugin: 'idea'
apply plugin: 'build-time-tracker'
apply plugin: 'com.gradle.plugin-publish'
apply plugin: 'signing'
apply from: "${rootDir}/gradle/version.gradle"
group = GROUP
version = PLUGIN_VERSION
archivesBaseName = POM_ARTIFACT_ID
sourceCompatibility = 1.6
targetCompatibility = 1.6
repositories {
mavenCentral()
jcenter()
}
dependencies {
// Thanks to a workaround in https://issues.gradle.org/browse/GRADLE-1715,
// using additional build script to exclude Rhino that is bundled with Gradle distribution,
// we can avoid the error that occurs when executing Trireme on tests:
// java.lang.NoSuchMethodError: org.mozilla.javascript.ScriptRuntime.setObjectProp
// Gradle distribution has an older Rhino (1.7R3) and causing conflict.
// In 1.7R3, ScriptRuntime does not have setObjectProp() method, which causes the above error.
compile new GradleDist(project, GRADLE_VERSION).asFileTree
compile localGroovy()
compile 'io.apigee.trireme:trireme-jar:0.8.8'
testCompile ('org.spockframework:spock-core:1.0-groovy-2.4') {
exclude module: 'groovy-all'
}
}
node {
version = '0.12.7'
npmVersion = '3.3.9'
download = true
workDir = file("${project.buildDir}/nodejs")
nodeModulesDir = file("${project.buildDir}/js")
}
idea.module.excludeDirs += [
file('.vagrant'),
file('src/main/resources/node_modules'),
file('samples/repo'),
]
fileTree(dir: "samples").visit { details ->
if (details.name in ['.gradle', 'build']) {
idea.module.excludeDirs << details.file
}
}
test {
maxParallelForks = 1
if (System.env.CI) {
maxHeapSize = '512m'
}
testLogging {
events 'failed', 'passed', 'skipped', 'started', 'standard_out', 'standard_error'
}
}
cobertura {
coverageFormats = ['html', 'xml']
coverageSourceDirs = sourceSets.main.groovy.srcDirs
}
buildtimetracker {
reporters {
summary {
ordered true
threshold 50
barstyle 'unicode'
}
}
}
apply from: "${rootDir}/gradle/npm-packages.gradle"
webResource {
coffeeScript {
dest '../../js'
minify false
logLevel LogLevel.INFO
}
testCoffeeScript {
logLevel LogLevel.INFO
}
}
task generatePackageJson(dependsOn: webResourceCompileCoffeeScript) {
def destPackageJson = project.file("${project.buildDir}/js/package.json")
inputs.property 'packageInfo', packageInfo
outputs.file destPackageJson
doLast {
project.file("${project.buildDir}/js").mkdirs()
destPackageJson.text = JsonOutput.prettyPrint(JsonOutput.toJson(packageInfo))
}
}
task applyPatch(dependsOn: 'npmInstall') {
inputs.dir project.file("${project.buildDir}/js/node_modules")
outputs.dir project.file("${project.buildDir}/js/node_modules")
doLast {
// Resolving cache while installing dependency in bower fails when executing with Trireme,
// so apply a patch for it
File f = new File("${project.buildDir}/js/node_modules/bower/lib/lib/core/ResolveCache.js")
def replaced = f.text.replaceAll(
"if \\(err\\.code === 'ENOENT'\\) \\{",
"if (err.code === 'ENOENT' || err.code === 'ENOTDIR') {")
f.text = replaced
// When using browserify, bower's internal function commandFactory is not handled
// because it uses require with variables.
// To solve this problem, we pass module path directly to require().
f = new File("${project.buildDir}/js/node_modules/bower/lib/lib/commands/index.js")
replaced = f.text.replaceAll(/commandFactory\('([^']*)'\)/) { all, path ->
"commandFactory(require('${path}'))"
}.replaceAll("var command = require\\(id\\)", "var command = id")
f.text = replaced
// bower 1.7.6 includes git avialability check with `which` module,
// but `which` doesn't work with node 0.12 on trireme.
// So if we use bower 1.7.6 and node 0.12 included in trireme 0.8.8 together,
// we must skip this check to execute bower.
// I confirmed this behavior with a simple, small index.js:
// var which = require('which');
// try {
// which.sync('git');
// console.log('git is installed');
// } catch(ex) {
// console.log(ex);
// }
// This produces different result in node 0.10 and 0.12:
// $ trireme --node-version=0.12 index.js
// { [Error: not found: git]
// message: 'not found: git',
// fileName: '/Users/dev/.nvm/v5.3.0/lib/node_modules/which/which.js',
// lineNumber: 120 }
// $ trireme --node-version=0.10 index.js
// git is installed
//
//f = new File("${projectDir}/src/main/resources/node_modules/bower/lib/lib/core/resolvers/GitResolver.js")
//replaced = f.text.replaceAll(
// "hasGit = false;",
// "hasGit = true;")
//f.text = replaced
// Remove unused features for browserify to work
f = new File("${project.buildDir}/js/node_modules/bower/lib/lib/version.js")
replaced = f.text.replaceAll("module.exports = .*", "module.exports = '1.7.6';")
f.text = replaced
f = new File("${project.buildDir}/js/node_modules/mocha/lib/mocha.js")
replaced = f.text.replaceAll("if \\(!process\\.browser\\) \\{", "if (false && !process.browser) {")
f.text = replaced
[
'node_modules/bower/lib/node_modules/hawk/lib/utils.js',
'node_modules/bower/lib/node_modules/tough-cookie/lib/cookie.js',
'node_modules/elliptic/lib/elliptic.js',
'node_modules/hawk/lib/utils.js',
'node_modules/npm/node_modules/request/node_modules/hawk/lib/utils.js',
'node_modules/npm/node_modules/request/node_modules/tough-cookie/lib/cookie.js',
'node_modules/npm/scripts/publish-tag.js',
'node_modules/tough-cookie/lib/cookie.js',
].each { String path ->
f = new File("${project.buildDir}/js/${path}")
replaced = f.text.replaceAll("require\\('../package.json'\\).version", "0")
f.text = replaced
}
}
}
task browserifyBuild(type: NpmTask, dependsOn: 'applyPatch') {
def dest = project.file("${project.buildDir}/js/outputs/build.tmp.js")
inputs.files project.fileTree(dir: project.buildDir).include('*.js')
outputs.file dest
args = ['run', 'browserify']
execOverrides {
it.workingDir = project.file("${project.buildDir}/js")
}
doFirst {
project.file("${project.buildDir}/js/outputs").mkdirs()
}
doLast {
if (!dest.exists()) {
throw new GradleException("browserifyBuild failed")
}
}
}
// Skip uglify for debug
//task uglifyBuild(dependsOn: 'browserifyBuild') {
// def src = project.file("${project.buildDir}/js/outputs/build.tmp.js")
// doLast {
// copy {
// from src
// into src.parentFile.absolutePath
// rename "build.tmp.js", "build.js"
// }
// }
//}
task uglifyBuild(type: NpmTask, dependsOn: 'browserifyBuild') {
def src = project.file("${project.buildDir}/js/outputs/build.tmp.js")
def dest = project.file("${project.buildDir}/js/outputs/build.js")
inputs.file src
outputs.file dest
args = ['run', 'uglify']
execOverrides {
it.workingDir = project.file("${project.buildDir}/js")
}
doFirst {
project.file("${project.buildDir}/js/outputs").mkdirs()
}
doLast {
if (!dest.exists()) {
throw new GradleException("uglifyBuild failed")
}
}
}
task browserify(dependsOn: ['processResources', 'uglifyBuild']) {
inputs.file project.file("${project.buildDir}/js/outputs/build.js")
inputs.dir project.file("${project.buildDir}/js/node_modules/uglify-js/lib")
outputs.file project.file("${project.buildDir}/resources/main/build.js")
outputs.file project.file("${project.buildDir}/resources/main/uglifyjs-lib.js")
doLast {
def resDir = project.file("${project.buildDir}/resources/main")
if (!resDir.exists()) {
resDir.mkdirs()
}
copy {
// Copy only 1 file
from "${project.buildDir}/js/outputs/build.js"
into "${project.buildDir}/resources/main"
}
// UglifyJS reads external files on runtime.
// To copy less files, we merge those files into 1 file on build time.
File f = new File("${project.buildDir}/resources/main/uglifyjs-lib.js")
f.text = ""
[
'utils.js',
'ast.js',
'parse.js',
'transform.js',
'scope.js',
'output.js',
'compress.js',
'sourcemap.js',
'mozilla-ast.js',
].each { String fileName ->
f.text += new File("${project.buildDir}/js/node_modules/uglify-js/lib/${fileName}").text
}
}
}
npmInstall.dependsOn('generatePackageJson')
classes.dependsOn('browserify')
check.dependsOn('cobertura')
check.dependsOn('webResourceTestCoffeeScript')
webResourceTestCoffeeScript.mustRunAfter('cobertura')
apply from: "${rootDir}/gradle/release.gradle"