249 lines
8.6 KiB
Groovy
249 lines
8.6 KiB
Groovy
/*
|
|
* 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>.
|
|
*/
|
|
|
|
apply from: rootProject.file( 'gradle/published-java-module.gradle' )
|
|
apply plugin: 'com.github.lburgazzoli.karaf'
|
|
|
|
description = 'Support for running Hibernate O/RM in OSGi environments'
|
|
|
|
ext {
|
|
osgiCoreVersion = '6.0.0'
|
|
osgiCompediumVersion = '5.0.0'
|
|
karafVersion = '4.2.1'
|
|
paxExamVersion = '4.12.0'
|
|
}
|
|
|
|
test.enabled = true
|
|
|
|
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
|
|
}
|
|
hibernateEnvers {
|
|
description = 'Feature for easily adding Envers support to hibernate-orm'
|
|
transitive = false
|
|
}
|
|
hibernateInfinispan {
|
|
description = 'Feature for easily adding Infinispan-based caching support to hibernate-orm'
|
|
transitive = false
|
|
}
|
|
}
|
|
|
|
dependencies {
|
|
compile( project( ':hibernate-core' ) ) {
|
|
// having javax.activation-api as a dependency requires us to have com.sun.activation:javax.activation
|
|
// this dependency wasn't there in the 5.2.x bundles so ignoring it for now
|
|
// we might reintroduce it at some point if users complain about it
|
|
exclude module: 'javax.activation-api'
|
|
// TODO HHH-13022 Find a way to include JAXB in the OSGi feature
|
|
exclude module: 'jaxb-api'
|
|
exclude module: 'jaxb-runtime'
|
|
}
|
|
testCompile( project( ':hibernate-envers' ) )
|
|
|
|
compile "org.osgi:org.osgi.core:${osgiCoreVersion}"
|
|
compile "org.osgi:org.osgi.compendium:${osgiCompediumVersion}"
|
|
compile "net.bytebuddy:byte-buddy:${byteBuddyVersion}"
|
|
|
|
// Needed by JBoss JTA
|
|
runtime( libraries.interceptor )
|
|
|
|
testCompile "org.ops4j.pax.exam:pax-exam:${project.paxExamVersion}"
|
|
testCompile "org.ops4j.pax.exam:pax-exam-junit4:${project.paxExamVersion}"
|
|
testCompile "org.ops4j.pax.exam:pax-exam-container-karaf:${project.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:${project.karafVersion}" ) {
|
|
// having trouble finding this one locally
|
|
exclude group: 'org.eclipse', module: 'org.eclipse.osgi'
|
|
}
|
|
|
|
karafDistro "org.apache.karaf:apache-karaf:${project.karafVersion}@tar.gz"
|
|
|
|
hibernateEnvers( project( ':hibernate-envers' ) )
|
|
}
|
|
|
|
jar {
|
|
manifest {
|
|
instruction 'Bundle-Activator', 'org.hibernate.osgi.HibernateBundleActivator'
|
|
instruction 'Provide-Capability', 'osgi.service;effective:=active;objectClass=javax.persistence.spi.PersistenceProvider'
|
|
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=\"${project.jpaVersion.osgiName}\"",
|
|
"javax.persistence.spi;version=\"${project.jpaVersion.osgiName}\""
|
|
}
|
|
}
|
|
|
|
|
|
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()
|
|
}
|
|
}
|
|
}
|
|
|
|
karaf {
|
|
features {
|
|
xsdVersion = '1.4.0'
|
|
feature {
|
|
name = 'hibernate-orm'
|
|
description = 'Combines all Hibernate core dependencies and required modules into a single feature'
|
|
includeProject = true
|
|
feature ('wrap') {
|
|
prerequisite = true
|
|
}
|
|
feature 'transaction-api'
|
|
// Most Hibernate modules declare OSGi metadata through blueprints, so we need this feature
|
|
feature 'aries-blueprint'
|
|
}
|
|
// NOTE : would like to include spatial as well, but we need to wait for
|
|
// it to not define dependency on postgresql driver
|
|
feature {
|
|
name = 'hibernate-envers'
|
|
description = 'Feature for easily adding Envers support to hibernate-orm'
|
|
includeProject = false
|
|
configurations 'hibernateEnvers'
|
|
feature('hibernate-orm') {
|
|
version = project.version
|
|
}
|
|
}
|
|
feature {
|
|
name = 'hibernate-infinispan'
|
|
description = 'Feature for easily adding Infinispan-based caching support to hibernate-orm'
|
|
includeProject = false
|
|
configurations 'hibernateInfinispan'
|
|
feature('hibernate-orm') {
|
|
version = project.version
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
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', karaf.features.outputFile.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.generateFeatures
|
|
tasks.test.dependsOn tasks.jar
|
|
tasks.test.dependsOn tasks.generateDependsFile
|
|
tasks.test.dependsOn tasks.generatePaxExamEnvironmentFile
|
|
|
|
// we also need to make sure that hibernate-core, hibernate-entitymanager and hibernate-osgi
|
|
// are published to maven-local before running tests
|
|
tasks.test.dependsOn rootProject.childProjects.'hibernate-core'.tasks.publishToMavenLocal
|
|
tasks.test.dependsOn rootProject.childProjects.'hibernate-envers'.tasks.publishToMavenLocal
|
|
tasks.test.dependsOn tasks.publishToMavenLocal
|
|
|
|
publishing {
|
|
publications {
|
|
publishedArtifacts( MavenPublication ) {
|
|
artifact( project.extensions.karaf.features.outputFile ) {
|
|
classifier 'karaf'
|
|
builtBy generateFeatures
|
|
}
|
|
}
|
|
}
|
|
}
|