-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
221 lines (167 loc) · 5.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
// build script is based on http://paulonjava.blogspot.de/2013/11/building-bndtools-projects-with-gradle.html
import aQute.bnd.build.Workspace
import org.osgi.service.indexer.ResourceIndexer
import org.osgi.service.indexer.impl.RepoIndex
import java.nio.file.Files
defaultTasks 'clean', 'build', 'release'
ext.SRC_DIR = "main/src"
ext.XTEND_GEN_DIR = "main/xtend-gen"
ext.TEST_SRC_DIR = "test/src"
ext.TEST_XTEND_GEN_DIR = "test/xtend-gen"
//Add bnd as a build dependency
buildscript {
repositories { mavenCentral() }
dependencies {
classpath files('cnf/plugins/biz.aQute.bnd/biz.aQute.bnd-2.4.0.jar')
classpath 'org.xtend:xtend-gradle-plugin:0.1.+'
classpath files('cnf/buildrepo/org.osgi.impl.bundle.repoindex.lib/org.osgi.impl.bundle.repoindex.lib-2.1.2.jar')
}
}
// Setup the workspace
def parentDir = project.projectDir
Workspace workspace = Workspace.getWorkspace(parentDir)
subprojects { p ->
apply plugin: 'xtend' // applies plugin 'java'
// set explicitly encoding for java sources
// xtend sources have UTF-8 as default
compileJava.options.encoding = 'UTF-8'
compileJava.options.fork (memoryMaximumSize: '1024m')
// Each 'build' task should create OSGi bundles from compiled classes
p.tasks.getByName("build").configure {
inputs.dir "build/classes"
outputs.dir "build/osgi-bundles"
}
// Incremental Java compilation should speed-up the build.
// It is currently an incubating feature in the new Gradle version
// but seems to be working fine for FOAM so far.
tasks.withType(JavaCompile) {
// temporarily disabled due to cloudbees
//options.incremental = true
}
dependencies {
compile 'org.eclipse.xtend:org.eclipse.xtend.lib:2.7.2'
}
repositories { mavenCentral() }
//Setup source and target directories
sourceCompatibility = 1.6
targetCompatibility = 1.6
sourceSets {
main {
java.srcDirs = [SRC_DIR, XTEND_GEN_DIR]
// IMPORTANT: we want to achieve the same behaviour as the Eclipse build system
// which copies all files from source folders to bin folders
resources.srcDirs = [SRC_DIR]
//resources.exclude '**/*.xtend'
resources.exclude '**/*.java'
resources.exclude '**/packageinfo'
resources.exclude '**/*.xtext'
output.resourcesDir = output.classesDir
// output.classesDir property is somehow overriden by
// xtend gradle plugin and classes are always generated into
// build/classes/main directory. This is probably bug.
// output.classesDir = 'build/classes/main'
xtendOutputDir = XTEND_GEN_DIR
}
// TODO
test {
java.srcDirs = [TEST_SRC_DIR, TEST_XTEND_GEN_DIR]
resources.srcDirs = [TEST_SRC_DIR]
//resources.exclude '**/*.xtend'
resources.exclude '**/*.java'
resources.exclude '**/packageinfo'
output.resourcesDir = output.classesDir
xtendOutputDir = TEST_XTEND_GEN_DIR
}
}
testResultsDirName = 'generated/test-reports'
compileXtend.doFirst {
file(XTEND_GEN_DIR).mkdir()
}
compileTestXtend.doFirst {
file(TEST_XTEND_GEN_DIR).mkdir()
}
//Setup project dependencies
aQute.bnd.build.Project bndProject = workspace.getProject(p.projectDir)
bndProject.dependson.each {
compileXtend.dependsOn(":${it.name}:build")
}
bndProject.getBuildpath().each {
def f = files(it.file)
dependencies.add('compile', f)
// to allow use of external libs in build script (e.g. mwe libs)
buildscript.dependencies.add('classpath', f)
}
//Add junit as a default dependency
dependencies.add('testCompile', 'junit:junit:4.+')
//Perform the actual bnd build
build << { task ->
bndProject.build()
//Report errors and warnings to the Gradle output
bndProject.warnings.each { logger.warn it }
bndProject.errors.each { logger.error it }
//Fail the build if there are build errors
if(bndProject.errors) {
throw new GradleException("Bnd build failure. Check build logs for error messages")
}
// now, we need to delete all temporary files that are needed only during the build
// note: they are not intended as output artefacts
//project.delete "build/tmp", "build/xtend-temp", "build/libs", "build/dependency-cache"
}
//Run integration tests - commented as no integration tests are present yet
// task bndtest << { task ->
// if(bndProject.getProperty("Test-Cases")) {
// bndProject.test()
// }
// }
clean << {
project.delete XTEND_GEN_DIR, TEST_XTEND_GEN_DIR
}
}
//Collect generated and external bundles for deployment
task release << {
delete "release"
// place jars into "repository" directory
file("release/repository").mkdirs()
file('release/distribution').mkdirs()
ant.taskdef(name: 'bndrelease', classname: 'aQute.bnd.ant.RunconfigToDistributionTask', classpath: 'cnf/plugins/biz.aQute.bnd/biz.aQute.bnd-2.4.0.jar')
def tree = fileTree(dir:"org.foam.cli", include:"**/*.bndrun")
tree.each { File bndrunFile ->
println bndrunFile.name
def tmpdir = Files.createTempDirectory("tmprelease").toFile().getAbsolutePath()
// export required bundles
ant.bndrelease(
allowsnapshots: true,
bndfile: "org.foam.cli/" + bndrunFile.name,
rootdir: './',
outputdir: tmpdir
)
copy {
from tmpdir
into "release/repository"
include "**/*.jar"
}
delete tmpdir
// generate runnable .jar
def jarName = 'release/distribution/' + bndrunFile.name.replace(".bndrun", ".jar")
workspace.getProject('org.foam.cli').export(
bndrunFile.name,
false,
file(jarName)
)
file(jarName).setExecutable(true)
}
// generate index
def indexer = new RepoIndex()
def config = [(ResourceIndexer.ROOT_URL): "release/repository", (ResourceIndexer.REPOSITORY_NAME): "FOAM tool repository"]
def inputs = fileTree(dir: 'release/repository', include: '*.jar') as Set
def output = new FileOutputStream("release/repository/index.xml.gz")
indexer.index(inputs, output, config)
///
def vserverJarName = 'release/distribution/foam-vserver.jar'
workspace.getProject('org.foam.orion.server').export(
"run-equinox.bndrun",
false,
file(vserverJarName)
)
file(vserverJarName).setExecutable(true)
}