This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 57
/
build.gradle
103 lines (92 loc) · 3.29 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
defaultTasks 'package'
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
runtime "mysql:mysql-connector-java:5.1.34"
runtime "org.codehaus.groovy:groovy-all:2.1.5"
}
final def BUILD_DIR = "target"
task 'package'(dependsOn: 'copyToLib') << {
def distros = findAvailableDistros()
def zanataVersion = readProjectVersion()
distros.each { distro ->
def distroName = "zanata-$zanataVersion-$distro"
def distroDir = "$BUILD_DIR/$distroName"
// Make a build directory fro the distribution
ant.mkdir(dir: distroDir)
// Copy the common files for all distributions
ant.copy(todir: distroDir) {
fileset(dir: "common")
}
// Make sure executable files have the right permissions
ant.chmod(dir: "$distroDir/", perm: "ug+x", includes: "**/*.sh")
// Copy specific distribution files
ant.copy(todir: distroDir) {
fileset(dir: "distros/$distro")
}
// Copy extra needed files
ant.copy(todir: "$distroDir/standalone/deployments") {
fileset(dir: "$BUILD_DIR/deps") {
include(name: "mysql-connector-java-*.jar")
}
globmapper(from: "mysql-connector-java-*.jar",
to: "mysql-connector-java.jar")
}
ant.copy(todir: "$distroDir/bin/zanata-installer") {
fileset(dir: "$BUILD_DIR/deps") {
include(name: "groovy-all-*.jar")
}
}
// Download remote dependencies
downloadRemoteDeps(distro, distroDir)
// Replace templates
replaceTemplates(distroDir, zanataVersion)
// Zip it up
ant.zip(destfile: "$BUILD_DIR/${distroName}.zip", basedir: distroDir)
// Cleanup
//ant.delete(dir: "$BUILD_DIR/deps")
ant.delete(dir: distroDir)
}
}
task copyToLib(type: Copy) {
into "$BUILD_DIR/deps"
from configurations.runtime
}
List findAvailableDistros() {
new File("distros").listFiles()
.findAll { !it.name.startsWith(".") && it.isDirectory() }
.collect { it.name }
}
String readProjectVersion() {
(new groovy.util.XmlParser()).parse(new File("../pom.xml")).version.text()
}
def replaceTemplates(String distroDir, String zanataVersion) {
def engine = new groovy.text.SimpleTemplateEngine()
def templateFile = new File(distroDir,
"bin/zanata-installer/installer.properties")
def template = engine.createTemplate(templateFile)
def result = template.make(['version': zanataVersion])
templateFile.newWriter() << result
}
def downloadRemoteDeps(String distro, String distroDir) {
def config = new groovy.util.ConfigSlurper().
parse(new File('config/remote-deps.groovy').toURL())
config."$distro"?.each { depName, value ->
def dep = config."$distro"."$depName"
def destFile = new File("$distroDir/${dep.toFile}")
download(dep.url, destFile)
if (dep.extract) {
ant.unzip(src: "${destFile.absolutePath}",
dest: "${destFile.parent}")
ant.delete(file: "${destFile.absolutePath}")
}
}
}
def download(String url, File destFile) {
def file = new FileOutputStream(destFile)
def out = new BufferedOutputStream(file)
out << new URL(url).openStream()
out.close()
}