-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
251 lines (213 loc) · 5.99 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
/*******************************************************************************
*
* MIT License
* Copyright (c) 2015-2016 NetIQ Corporation, a Micro Focus company
*
******************************************************************************/
defaultTasks 'extractGromitJS', 'appRun'
apply plugin: 'war'
apply plugin: 'maven'
group = 'org.gromitsoft'
version = '1.0.5-SNAPSHOT'
repositories {
mavenCentral()
mavenLocal()
jcenter()
maven {
url 'http://oss.sonatype.org/content/groups/public'
}
}
configurations {
api
}
dependencies {
providedCompile 'org.apache.tomcat:tomcat-servlet-api:7.0.37'
api 'org.gromitsoft:gromit:1.0.5-SNAPSHOT'
}
/*
* This section deals with processing and combining JavaScript files. Our JavaScript files have some specific
* dependencies where we must load some files ahead of others. This section specifies the file tree in a specific
* order so our JavaScript dependencies are loaded properly in the index.html file.
*/
FileCollection jsFiles = files('src/main/app/js/main.js')
jsFiles = jsFiles + fileTree(
dir: 'src/main/app/js',
includes: ['*.js'],
excludes: ['main.js'])
jsFiles = jsFiles + fileTree(
dir: 'src/main/app/js',
includes: ['directives/**', 'services/**', 'controllers/**'],
excludes: ['**/services/i18n/*'])
buildscript {
repositories {
mavenCentral()
mavenLocal()
jcenter()
maven {
url 'http://oss.sonatype.org/content/groups/public'
}
}
dependencies {
classpath 'org.akhikhl.gretty:gretty:+'
classpath 'com.eriwen:gradle-js-plugin:1.12.0'
classpath 'com.eriwen:gradle-css-plugin:1.11.1'
}
}
apply plugin: 'org.akhikhl.gretty'
apply plugin: "com.eriwen.gradle.js"
apply plugin: 'css'
minifyJs {
source = jsFiles
dest = file("${buildDir}/js/gromit-sample-min.js")
closure {
warningLevel = 'DEFAULT'
compilationLevel = 'WHITESPACE_ONLY'
}
}
gzipJs {
doFirst() {
println ':gzipJs'
}
source = file("${buildDir}/js/gromit-sample-all-min.js")
dest = file("${buildDir}/js/gromit-sample-all-min.js.gz")
}
/*
* This is a little class and task that can concatenate files. We use it to bundle all
* of our JavaScript libraries into a single file. Ideally we should be GZIPing the bundle
* as well, but I haven't had time for that part yet.
*/
class ConcatFiles extends DefaultTask {
@InputFiles
FileCollection files
@OutputFile
File target
@TaskAction
void concat() {
target.withWriter { writer ->
files.each { file ->
file.withReader { reader ->
writer << reader << '\n'
}
}
}
}
}
task concatLibFiles(type: ConcatFiles) {
files = files(
'build/js/gromit-sample-min.js')
target = file('build/js/gromit-sample-all-min.js')
}
/*
* This section minimizes and combines our CSS files
*/
FileCollection cssSourceFiles = files('src/main/app/css/reset.css')
FileTree cssSourceFilesTree = fileTree(dir: 'src/main/app/css')
cssSourceFilesTree.include '*.css'
cssSourceFilesTree.exclude 'reset.css'
cssSourceFiles = cssSourceFiles + cssSourceFilesTree
combineCss {
source = cssSourceFiles
dest = "${buildDir}/css/gromit-sample-all.css"
}
minifyCss {
source = "${buildDir}/css/gromit-sample-all.css"
dest = "${buildDir}/css/gromit-sample-all-min.css"
yuicompressor { // Optional
lineBreakPos = -1
}
}
gzipCss {
doFirst() {
println ':gzipCss'
}
source = "${buildDir}/css/gromit-sample-all-min.css"
dest = "${buildDir}/css/gromit-sample-all-min.css.gz"
}
/*
* We want to call JSHint on the command line so we can use the NodeJS version
* of it.
*/
task jsHint(type:Exec) {
doFirst() {
println ':jsHint'
}
description = 'This task handles calling JSHint for the JavaScript files in the project.'
ignoreExitValue = true
if (org.apache.tools.ant.taskdefs.condition.Os.isFamily(org.apache.tools.ant.taskdefs.condition.Os.FAMILY_WINDOWS)) {
commandLine 'cmd', '/c', 'jshint'
} else {
workingDir '.'
executable 'jshint'
}
args jsFiles
logger.info('jsHint commandLine: ' + commandLine)
doLast {
if (execResult.exitValue != 0) {
throw new GradleScriptException("There were JSHint errors. Look above and fix the issues.", null);
}
}
}
task extractGromit(type: Copy) {
doFirst() {
println ':extractGromit'
}
description = 'This task extracts files from the Gromit artifact'
from {
configurations.api.collect { zipTree(it) }
}
into "$buildDir/gromit/"
}
task extractGromitCSS(dependsOn: 'extractGromit', type: Copy) {
doFirst() {
println ':extractGromitCSS'
}
description = 'This task extracts files from the Gromit artifact'
from "$buildDir/gromit/css"
into "src/main/app/gromit/css"
}
task extractGromitHTML(dependsOn: 'extractGromitCSS', type: Copy) {
doFirst() {
println ':extractGromitHTML'
}
description = 'This task extracts files from the Gromit artifact'
from "$buildDir/gromit/html"
into "src/main/app/"
}
task extractGromitJS(dependsOn: 'extractGromitHTML', type: Copy) {
doFirst() {
println ':extractGromitJS'
}
description = 'This task extracts files from the Gromit artifact'
from "$buildDir/gromit/js"
into "src/main/app/gromit/js"
}
clean {
delete new File(project.projectDir, 'src/main/app/gromit')
delete new File(project.projectDir, 'src/main/app/oauth.html')
}
war {
from 'src/main/app'
from('build/js') {
include '*'
into('js')
}
from('build/css') {
include '*'
into('css')
}
}
war.doFirst {
tasks.jsHint.execute()
tasks.minifyJs.execute()
tasks.concatLibFiles.execute()
tasks.gzipJs.execute()
tasks.combineCss.execute()
tasks.minifyCss.execute()
tasks.gzipCss.execute()
}
gretty {
httpPort = 8081
contextPath = '/'
servletContainer = 'jetty9'
extraResourceBase 'src/main/app'
}