-
Notifications
You must be signed in to change notification settings - Fork 3.5k
/
hibernate-osgi.gradle
357 lines (318 loc) · 11.6 KB
/
hibernate-osgi.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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
apply plugin: 'karaf-featuresgen'
sourceSets {
test {
// send javac output and resource copying to the same output directory for test
// so Pax Exam can more easily find it without explicit TinyBundle hooks
output.classesDir = "${buildDir}/classes/test"
output.resourcesDir = output.classesDir
}
}
configurations {
karafDistro {
description = 'Configuration used to isolate the dependency on the Karaf distro'
transitive = false
}
aries {
description = 'Runtime dependencies for Aries for the hibernate-jpa-aries Karaf feature'
}
hibernateEntityManager {
description = 'Used in Karaf feature generation to define the Hibernate JPA dependencies'
transitive = false
}
hibernateEnvers {
description = 'Used in Karaf feature generation to define the Hibernate Envers dependencies'
transitive = false
}
hibernateEhcache {
description = 'Used in Karaf feature generation to define the Hibernate Ehcache dependencies'
transitive = false
}
hibernateInfinispan {
description = 'Used in Karaf feature generation to define the Hibernate Infinispan dependencies'
transitive = false
}
}
ext {
// MUST use 4.3.1! 4.3.0 was compiled with "-target jsr14".
// http://blog.osgi.org/2012/10/43-companion-code-for-java-7.html
osgiCoreVersion = '4.3.1'
karafVersion = '3.0.3'
paxExamVersion = '4.4.0'
paxUrlVersion = '2.4.1'
}
dependencies {
ext {
paxExamVersion = '4.4.0'
paxExamUrlVersion = '2.4.1'
karafVersion = '3.0.3'
}
compile( project( ':hibernate-core' ) )
compile( project( ':hibernate-entitymanager' ) )
// MUST use 4.3.1! 4.3.0 was compiled with "-target jsr14".
// http://blog.osgi.org/2012/10/43-companion-code-for-java-7.html
compile "org.osgi:org.osgi.core:${osgiCoreVersion}"
compile "org.osgi:org.osgi.compendium:${osgiCoreVersion}"
testCompile "org.ops4j.pax.exam:pax-exam:${paxExamVersion}"
testCompile "org.ops4j.pax.exam:pax-exam-junit4:${paxExamVersion}"
testCompile "org.ops4j.pax.exam:pax-exam-container-karaf:${paxExamVersion}"
// Need this explicitly in order to use @Inject -> shouldn't this be a transtive dep of pax-exam?
// is there ever a pax exam test that *does not* use this?
testCompile 'javax.inject:javax.inject:1'
testCompile( "org.apache.karaf:apache-karaf:${karafVersion}" ) {
// having trouble finding this one locally
exclude group: 'org.eclipse', module: 'org.eclipse.osgi'
}
karafDistro "org.apache.karaf:apache-karaf:${karafVersion}@tar.gz"
hibernateEntityManager project( ':hibernate-entitymanager' )
hibernateEnvers project( ':hibernate-envers' )
hibernateEhcache project( ':hibernate-ehcache' )
hibernateInfinispan project( ':hibernate-infinispan' )
aries 'org.apache.aries.transaction:org.apache.aries.transaction.blueprint:1.0.0'
aries 'org.apache.aries.transaction:org.apache.aries.transaction.manager:1.0.1'
}
mavenPom {
name = 'Hibernate OSGi Support'
description = 'Support for running Hibernate O/RM in OSGi environments'
}
def osgiDescription() {
return mavenPom.description
}
jar {
manifest {
instruction 'Bundle-Activator', 'org.hibernate.osgi.HibernateBundleActivator'
instructionFirst 'Import-Package',
// TODO: Shouldn't have to explicitly list this, but the plugin
// generates it with a [1.0,2) version.
'javax.persistence;version="2.1.0"',
'javax.persistence.spi;version="2.1.0"'
}
}
task generateVersionFile {
File outputFileDir = project.file( "${buildDir}/classes/test/META-INF/hibernate-osgi/" )
File outputFile = new File( outputFileDir, 'Version.txt' )
inputs.property( "version", project.version )
outputs.file outputFile
doFirst {
outputFileDir.mkdirs()
def writer = new FileWriter( outputFile )
try {
writer.write( "${project.version}" )
writer.flush()
}
finally {
writer.close()
}
}
}
karafFeatures {
features {
hibernateBase {
name = 'hibernate-base'
description = 'Isolates all Hibernate core dependencies into a single feature'
projects = [
rootProject.childProjects.'hibernate-core',
project
]
bundle {
match {
group = 'org.jboss.logging'
module = 'jboss-logging-annotations'
}
include = false
}
bundle {
match group: 'org.jboss.logging', module: 'jboss-logging-processor'
include = false
}
bundle {
match group: 'antlr', module: 'antlr'
remap group: 'org.apache.servicemix.bundles', module: 'org.apache.servicemix.bundles.antlr', version: '2.7.7_5'
}
bundle {
match group: 'dom4j', module: 'dom4j'
remap group: 'org.apache.servicemix.bundles', module: 'org.apache.servicemix.bundles.dom4j', version: '1.6.1_5'
}
}
hibernateNative {
name = 'hibernate-native'
description = 'Defines support for using Hibernate native APIs (SessionFactory, Session) in user applications/bundles'
dependencyFeatureNames = ['hibernate-base']
projects = []
}
hibernateJpa {
name = 'hibernate-jpa'
description = 'Defines support for using Hibernate JPA implementation in user applications/bundles in an unmanaged manner'
bundleDependencies = [project.configurations.hibernateEntityManager]
dependencyFeatureNames = ['hibernate-base']
projects = []
}
hibernateJpaAries {
name = 'hibernate-jpa-aries'
description = 'Defines support for using Hibernate JPA implementation in user applications/bundles in an managed manner using Aries for OSGi JPA support'
bundleDependencies = [project.configurations.aries, project.configurations.hibernateEntityManager]
dependencyFeatureNames = ['hibernate-base']
projects = []
}
// NOTE : would like to include spatial as well, but we need to wait for
// it to not define dependency on postgresql driver
hibernateEnvers {
name = 'hibernate-envers'
description = 'Feature for easily adding Envers support to hibernate-native, hibernate-jpa or hibernate-jpa-aries'
dependencyFeatureNames = ['hibernate-base']
projects = [rootProject.childProjects.'hibernate-envers']
bundle {
match group: 'org.hibernate', module: 'hibernate-core'
include = false
}
bundle {
match group: 'org.hibernate', module: 'hibernate-osgi'
include = false
}
bundle {
match group: 'org.hibernate', module: 'hibernate-entitymanager'
include = false
}
bundle {
match group: 'org.jboss.logging', module: 'jboss-logging'
include = false
}
bundle {
match group: 'org.jboss.logging', module: 'jboss-logging-annotations'
include = false
}
bundle {
match group: 'org.jboss.logging', module: 'jboss-logging-processor'
include = false
}
}
hibernateInfinispan {
name = 'hibernate-infinispan'
description = 'Feature for easily adding Infinispan-based caching support to hibernate-native, hibernate-jpa or hibernate-jpa-aries'
dependencyFeatureNames = ['hibernate-base']
projects = [rootProject.childProjects.'hibernate-infinispan']
bundle {
match group: 'org.hibernate', module: 'hibernate-core'
include = false
}
bundle {
match group: 'org.hibernate', module: 'hibernate-osgi'
include = false
}
bundle {
match group: 'org.jboss.logging', module: 'jboss-logging'
include = false
}
bundle {
match group: 'org.jboss.logging', module: 'jboss-logging-annotations'
include = false
}
bundle {
match group: 'org.jboss.logging', module: 'jboss-logging-processor'
include = false
}
bundle {
match group: 'org.jboss.spec.javax.transaction', module: 'jboss-transaction-api_1.1_spec'
include = false
}
}
hibernateEhcache {
name = 'hibernate-ehcache'
description = 'Feature for easily adding Ehcache-based caching support to hibernate-native, hibernate-jpa or hibernate-jpa-aries'
dependencyFeatureNames = ['hibernate-base']
projects = [rootProject.childProjects.'hibernate-ehcache']
bundle {
match group: 'org.hibernate', module: 'hibernate-core'
include = false
}
bundle {
match group: 'org.hibernate', module: 'hibernate-osgi'
include = false
}
bundle {
match group: 'org.jboss.logging', module: 'jboss-logging'
include = false
}
bundle {
match group: 'org.jboss.logging', module: 'jboss-logging-annotations'
include = false
}
bundle {
match group: 'org.jboss.logging', module: 'jboss-logging-processor'
include = false
}
}
}
}
task generateDependsFile {
// In order to fully use org.ops4j.pax.exam.CoreOptions.maven() stuff
// we need to generate a META-INF/maven/dependencies.properties file
// just like the generate-depends-file Maven goal from ServiceMix/Karaf
File outputFileDir = project.file( 'target/classes/test/META-INF/maven/' )
File outputFile = new File( outputFileDir, 'dependencies.properties' )
outputs.file outputFile
doFirst {
outputFileDir.mkdirs()
Properties properties = new Properties();
// first we add our GAV info
properties.setProperty( "groupId", "${project.group}" );
properties.setProperty( "artifactId", project.name );
properties.setProperty( "version", "${project.version}" );
properties.setProperty( "${project.group}/${project.name}/version", "${project.version}" );
// then for all our deps
project.configurations.testRuntime.resolvedConfiguration.resolvedArtifacts.each {
final String keyBase = it.moduleVersion.id.group + '/' + it.moduleVersion.id.name;
properties.setProperty( "${keyBase}/scope", "compile" )
properties.setProperty( "${keyBase}/type", it.extension )
properties.setProperty( "${keyBase}/version", it.moduleVersion.id.version )
}
FileOutputStream outputStream = new FileOutputStream( outputFile );
try {
properties.store( outputStream, "Generated from Gradle by Hibernate build for PaxExam testing of hibernate-osgi module" )
}
finally {
outputStream.close()
}
}
}
task generatePaxExamEnvironmentFile {
// I found this better/easier than duplicating information...
description = 'Generates a Properties file that the Pax Exam test can access to know information about the test environment'
File outputFile = new File( sourceSets.test.output.resourcesDir, 'pax-exam-environment.properties' )
File karafUnpackDirectory = file( "${buildDir}/karaf-unpack" )
// set up up-to-date checks
inputs.files( configurations.testRuntime )
inputs.property( 'karafUnpackDirectory', karafUnpackDirectory )
outputs.file( outputFile )
doFirst {
// should only be one artifacts..
File karafDistroFile = configurations.karafDistro.resolvedConfiguration.resolvedArtifacts[0].file
Properties properties = new Properties();
properties.setProperty( 'org.ops4j.pax.exam.container.karaf.distroUrl', karafDistroFile.toURI().toURL().toExternalForm() )
properties.setProperty( 'org.ops4j.pax.exam.container.karaf.unpackDir', karafUnpackDirectory.absolutePath )
properties.setProperty( 'org.ops4j.pax.exam.container.karaf.version', karafVersion as String )
properties.setProperty( 'org.ops4j.pax.exam.container.karaf.probe.classesDir', sourceSets.test.output.classesDir.absolutePath )
properties.setProperty( 'org.ops4j.pax.exam.container.karaf.probe.resourcesDir', sourceSets.test.output.resourcesDir.absolutePath )
properties.setProperty( 'org.hibernate.osgi.test.karafFeatureFile', karafFeatures.featuresXmlFile.absolutePath )
outputFile.parentFile.mkdirs()
FileOutputStream outputStream = new FileOutputStream( outputFile );
try {
properties.store( outputStream, "Generated from Gradle by Hibernate build for PaxExam testing of hibernate-osgi module" )
}
finally {
outputStream.close()
}
}
}
tasks.test.dependsOn tasks.generateKarafFeatures
tasks.test.dependsOn tasks.jar
tasks.test.dependsOn tasks.generateDependsFile
tasks.test.dependsOn tasks.generatePaxExamEnvironmentFile
publishing {
publications {
mavenJava( MavenPublication ) {
artifact( project.extensions.karafFeatures.featuresXmlFile ) {
classifier 'karaf'
}
}
}
}