2015-05-19 00:23:35 -04:00
/ *
* Hibernate , Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License ( LGPL ) , version 2.1 or later .
* See the lgpl . txt file in the root directory or < http: //www.gnu.org/licenses/lgpl-2.1.html>.
* /
2015-05-01 09:54:47 -04:00
apply plugin: 'karaf-featuresgen'
2015-04-29 23:10:49 -04:00
2015-05-08 16:31:41 -04:00
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
2015-05-01 09:54:47 -04:00
}
2015-05-08 16:31:41 -04:00
}
configurations {
karafDistro {
description = 'Configuration used to isolate the dependency on the Karaf distro'
2015-03-19 13:40:29 -04:00
transitive = false
}
2015-05-08 16:31:41 -04:00
aries {
description = 'Runtime dependencies for Aries for the hibernate-jpa-aries Karaf feature'
2015-03-19 13:40:29 -04:00
}
2015-05-12 14:57:40 -04:00
hibernateEntityManager {
description = 'Used in Karaf feature generation to define the Hibernate JPA dependencies'
transitive = false
}
2013-06-12 16:50:06 -04:00
}
2015-05-08 16:31:41 -04:00
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'
}
2015-04-10 12:58:22 -04:00
2013-01-23 18:22:03 -05:00
dependencies {
2015-05-05 18:18:16 -04:00
ext {
paxExamVersion = '4.4.0'
paxExamUrlVersion = '2.4.1'
karafVersion = '3.0.3'
}
2013-06-12 16:50:06 -04:00
compile ( project ( ':hibernate-core' ) )
compile ( project ( ':hibernate-entitymanager' ) )
2015-05-08 16:31:41 -04:00
2013-06-12 16:50:06 -04:00
// 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
2015-05-08 16:31:41 -04:00
compile "org.osgi:org.osgi.core:${osgiCoreVersion}"
compile "org.osgi:org.osgi.compendium:${osgiCoreVersion}"
2015-04-29 23:10:49 -04:00
testCompile "org.ops4j.pax.exam:pax-exam:${paxExamVersion}"
testCompile "org.ops4j.pax.exam:pax-exam-junit4:${paxExamVersion}"
2015-05-08 16:31:41 -04:00
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?
2015-05-05 18:18:16 -04:00
testCompile 'javax.inject:javax.inject:1'
2015-05-08 16:31:41 -04:00
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"
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'
2013-01-23 18:22:03 -05:00
}
2015-04-10 12:58:22 -04:00
mavenPom {
name = 'Hibernate OSGi Support'
description = 'Support for running Hibernate O/RM in OSGi environments'
2013-04-16 19:25:20 -04:00
}
2013-12-02 21:53:19 -05:00
def osgiDescription ( ) {
2015-04-10 12:58:22 -04:00
return mavenPom . description
2013-12-02 21:53:19 -05:00
}
2013-01-23 18:22:03 -05:00
jar {
2013-06-12 16:50:06 -04:00
manifest {
instruction 'Bundle-Activator' , 'org.hibernate.osgi.HibernateBundleActivator'
2013-04-08 18:53:44 -04:00
2013-09-06 15:47:47 -04:00
instructionFirst 'Import-Package' ,
2013-06-12 16:50:06 -04:00
// 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"'
}
2013-01-23 18:22:03 -05:00
}
2013-06-12 16:50:06 -04:00
2015-04-29 23:10:49 -04:00
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 ( )
}
}
}
2015-05-01 09:54:47 -04:00
karafFeatures {
features {
2015-05-12 14:57:40 -04:00
hibernateBase {
name = 'hibernate-base'
description = 'Isolates all Hibernate core dependencies into a single feature'
2015-05-01 09:54:47 -04:00
projects = [
rootProject . childProjects . 'hibernate-core' ,
2015-05-12 15:31:40 -04:00
rootProject . childProjects . 'hibernate-entitymanager' ,
2015-05-01 09:54:47 -04:00
project
]
2015-05-28 17:46:15 -04:00
// According to Christian Schneider, these should not be needed
bundle {
match {
group = 'org.osgi'
module = 'org.osgi.core'
}
include = false
}
bundle {
match {
group = 'org.osgi'
module = 'org.osgi.compendium'
}
include = false
}
2015-05-12 14:57:40 -04:00
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 = [ ]
2015-04-29 23:10:49 -04:00
}
2015-05-01 09:54:47 -04:00
hibernateJpa {
name = 'hibernate-jpa'
2015-05-12 14:57:40 -04:00
description = 'Defines support for using Hibernate JPA implementation in user applications/bundles in an unmanaged manner'
dependencyFeatureNames = [ 'hibernate-base' ]
projects = [ ]
2015-04-29 23:10:49 -04:00
}
2015-05-01 09:54:47 -04:00
hibernateJpaAries {
name = 'hibernate-jpa-aries'
2015-05-12 14:57:40 -04:00
description = 'Defines support for using Hibernate JPA implementation in user applications/bundles in an managed manner using Aries for OSGi JPA support'
2015-05-12 15:31:40 -04:00
bundleDependencies = [ project . configurations . aries ]
2015-05-12 14:57:40 -04:00
dependencyFeatureNames = [ 'hibernate-base' ]
projects = [ ]
2015-04-29 23:10:49 -04:00
}
2015-05-12 14:57:40 -04:00
// NOTE : would like to include spatial as well, but we need to wait for
// it to not define dependency on postgresql driver
2015-05-08 16:31:41 -04:00
hibernateEnvers {
name = 'hibernate-envers'
2015-05-12 14:57:40 -04:00
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
}
2015-05-08 16:31:41 -04:00
}
2015-05-01 09:54:47 -04:00
hibernateInfinispan {
name = 'hibernate-infinispan'
2015-05-12 14:57:40 -04:00
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
}
2015-04-29 23:10:49 -04:00
}
2015-05-01 09:54:47 -04:00
hibernateEhcache {
name = 'hibernate-ehcache'
2015-05-12 14:57:40 -04:00
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
}
2015-04-29 23:10:49 -04:00
}
}
}
2015-05-08 16:31:41 -04:00
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 ( ) ;
2015-04-29 23:10:49 -04:00
2015-05-08 16:31:41 -04:00
// 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 ( )
}
}
}
2015-05-05 18:18:16 -04:00
2015-05-08 16:31:41 -04:00
tasks . test . dependsOn tasks . generateKarafFeatures
tasks . test . dependsOn tasks . jar
tasks . test . dependsOn tasks . generateDependsFile
tasks . test . dependsOn tasks . generatePaxExamEnvironmentFile
2015-05-12 14:57:40 -04:00
2015-05-13 00:00:50 -04:00
// we also need to make sure that hibernate-core, hibernate-entitymanager and hibernate-osgi
// are published to maven-local before running tests
2015-05-12 15:31:40 -04:00
tasks . test . dependsOn rootProject . childProjects . 'hibernate-core' . tasks . publishToMavenLocal
tasks . test . dependsOn rootProject . childProjects . 'hibernate-entitymanager' . tasks . publishToMavenLocal
2015-05-13 00:00:50 -04:00
tasks . test . dependsOn tasks . publishToMavenLocal
2015-05-12 15:31:40 -04:00
2015-05-12 14:57:40 -04:00
publishing {
publications {
mavenJava ( MavenPublication ) {
artifact ( project . extensions . karafFeatures . featuresXmlFile ) {
classifier 'karaf'
2015-07-06 10:25:13 -04:00
builtBy generateKarafFeatures
2015-05-12 14:57:40 -04:00
}
}
}
}