forked from FenixEdu/fenixedu-canvas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
214 lines (182 loc) · 5.7 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
// Repository and build configuration
repositories {
mavenCentral()
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "com.github.houbie:lesscss-gradle-plugin:1.0.3-less-1.7.0"
}
}
apply plugin: 'java'
apply plugin: 'lesscss'
apply plugin: 'maven'
project.group = 'org.fenixedu'
configurations {
bootstrap
}
// Variables
def bootstrapVersion = '3.3.5'
def showcaseCssFile = "${buildDir}/showcase/bootstrap-${bootstrapVersion}/_gh_pages/dist/css/bootstrap.css"
def minShowcaseCssFile = showcaseCssFile.replace(".css", ".min.css")
dependencies {
bootstrap "org.webjars:bootstrap:$bootstrapVersion"
}
// Task Configurations
lessc {
sourceDir "$buildDir/bootstrap/META-INF/resources/webjars/bootstrap/$bootstrapVersion/less", "src/main/less"
include "canvas.less"
destinationDir = "$buildDir/css"
options.sourceMap = true
options.minify = true
dependsOn 'unzipBootstrap'
}
lesscDaemon {
interval = 100
doFirst {
project.getTasksByName("lessc", false).each {
it.options.minify = false
it.preCompile { src, unit ->
unit.destination = project.file(showcaseCssFile)
}
}
}
dependsOn 'unzipBootstrap'
mustRunAfter 'spawnJekyll'
}
jar {
from ("src/main/assets") {
into "META-INF/resources/fenixedu-canvas"
}
from ("$buildDir/bootstrap/META-INF/resources/webjars/bootstrap/${bootstrapVersion}") {
into "META-INF/resources/fenixedu-canvas"
}
from ("${buildDir}/css") {
into "META-INF/resources/fenixedu-canvas/css"
}
dependsOn 'unzipBootstrap' , 'lessc'
}
// Tasks
task unzipBootstrap(type: Copy) {
dependsOn configurations.bootstrap
into file("${buildDir}/bootstrap")
from {
configurations.bootstrap.asFileTree.each {
from zipTree(it)
}
null
}
}
task downloadShowcase {
ext.target = new File(buildDir, "showcase.zip")
outputs.upToDateWhen {
target.exists()
}
doLast {
target.parentFile.mkdirs()
println "Downloading Bootstrap v${bootstrapVersion} from GitHub..."
target.withOutputStream { out ->
new URL ("https://github.com/twbs/bootstrap/archive/v${bootstrapVersion}.zip").openConnection().inputStream.with { input ->
out << input
input.close()
}
out.close()
}
println "Download finished, extracting..."
copy {
from zipTree(target)
into file("${buildDir}/showcase")
}
}
}
task copyAssets(dependsOn: 'downloadShowcase') << {
copy {
from "src/main/assets"
into "${buildDir}/showcase/bootstrap-${bootstrapVersion}/docs/dist"
}
copy {
from "src/main/showcase"
into "${buildDir}/showcase/bootstrap-${bootstrapVersion}/docs"
}
}
task jekyll(dependsOn: 'copyAssets') << {
exec {
workingDir "${buildDir}/showcase/bootstrap-${bootstrapVersion}/"
executable "sh"
args "-c", "jekyll serve"
}
}
task site(dependsOn: ['copyAssets', 'lessc']) << {
exec {
workingDir "${buildDir}/showcase/bootstrap-${bootstrapVersion}/"
executable "sh"
args "-c", "jekyll build --destination ${buildDir}/site"
}
// Site built, copy Canvas CSS
file("${buildDir}/site/dist/css/bootstrap.css").text =
file("${buildDir}/css/canvas.css").text
}
task spawnJekyll(dependsOn: 'copyAssets') << {
def builder = new ProcessBuilder("sh", "-c", "jekyll serve")
builder.redirectErrorStream(true)
builder.directory(file("${buildDir}/showcase/bootstrap-${bootstrapVersion}/"))
Process process = builder.start()
InputStream stdout = process.getInputStream()
BufferedReader reader = new BufferedReader(new InputStreamReader(stdout))
def line
while ((line = reader.readLine()) != null) {
println line
if (line.contains("Server running")) {
break;
}
}
def timer = new Timer()
timer.scheduleAtFixedRate({
if(file(showcaseCssFile).lastModified() > file(minShowcaseCssFile).lastModified()) {
file(minShowcaseCssFile).text = file(showcaseCssFile).text
logger.info("Copied ${showcaseCssFile} into ${minShowcaseCssFile}")
}
} as TimerTask, 5000, 5000);
// Delete the original file, so lesscDaemon will re-create it
file(showcaseCssFile).delete()
gradle.buildFinished {
println "Done. Killing jekyll..."
timer.cancel()
process.destroy()
}
Runtime.getRuntime().addShutdownHook(new Thread({
if(process.isAlive()) {
println "Forcibly killing Jekyll"
process.destroyForcibly()
}
}));
}
task showcase(dependsOn: ['lesscDaemon', 'spawnJekyll'])
// Maven deployment
uploadArchives {
repositories {
mavenDeployer {
repository(url: 'https://repo.fenixedu.org/fenixedu-releases') {
authentication(userName: project.hasProperty('username') ? project.username : "",
password: project.hasProperty('password') ? project.password : "")
}
pom.project {
licenses {
license {
name 'GNU Lesser General Public License v3.0'
url 'https://www.gnu.org/licenses/lgpl-3.0.txt'
distribution 'repo'
}
}
repositories {
repository {
id 'fenixedu-maven-repository'
url 'https://repo.fenixedu.org/fenixedu-maven-repository'
}
}
}
}
}
}