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>.
|
|
|
|
*/
|
2018-01-10 16:06:58 -05:00
|
|
|
|
2020-04-06 13:21:11 -04:00
|
|
|
description = 'Support for running Hibernate O/RM in OSGi environments'
|
|
|
|
|
2018-01-10 16:06:58 -05:00
|
|
|
apply from: rootProject.file( 'gradle/published-java-module.gradle' )
|
2018-06-26 14:05:24 -04:00
|
|
|
apply plugin: 'com.github.lburgazzoli.karaf'
|
2015-04-29 23:10:49 -04:00
|
|
|
|
2018-01-10 16:06:58 -05:00
|
|
|
|
2018-01-16 16:45:06 -05:00
|
|
|
ext {
|
2018-07-11 09:41:25 -04:00
|
|
|
osgiCoreVersion = '6.0.0'
|
|
|
|
osgiCompediumVersion = '5.0.0'
|
2018-10-10 07:40:41 -04:00
|
|
|
karafVersion = '4.2.1'
|
2018-07-11 09:41:25 -04:00
|
|
|
paxExamVersion = '4.12.0'
|
2018-01-16 16:45:06 -05:00
|
|
|
}
|
|
|
|
|
2019-05-27 09:03:31 -04:00
|
|
|
/*
|
|
|
|
* With the current karaf/pax-exam versions and with JDK11.0.3,
|
|
|
|
* we get errors like "java.lang.IllegalStateException: Unknown protocol: jrt".
|
|
|
|
*
|
|
|
|
* This is suspiciously similar to the problems we had on Hibernate Search,
|
|
|
|
* and we gave up the idea of fixing those after a few hours.
|
|
|
|
*
|
|
|
|
* Copy-pasting the explanation from Search (not sure it applies here, but it's likely):
|
|
|
|
* > Upgrading to Karaf 4.2.5 fixes that, but then we get errors about "/karaf.log" not being accessible.
|
|
|
|
* > Upgrading once again to Pax-exam 4.13.1 fixes that, but then startup looks stuck at some point,
|
|
|
|
* > without any particular error even if we raise all the different log levels to "trace".
|
|
|
|
* > Upgrading pax-url to 2.6.1 to be in line with the versions in the Karaf pom doesn't change anything.
|
|
|
|
* > Strangely, with these upgrades, everything still works fine with JDK8,
|
|
|
|
* > but we get in trouble with JDK11.0.0 and above.
|
|
|
|
* > A bit ironic since the problems we were trying to solve initially only affected JDK11.0.3,
|
|
|
|
* > not JDK11.0.0.
|
|
|
|
*/
|
2019-05-29 13:44:00 -04:00
|
|
|
if ( JavaVersion.current().isJava11Compatible() ) {
|
|
|
|
logger.warn( '[WARN] Skipping all tests for hibernate-osgi due to Karaf/Pax-Exam issues with latest JDK 11' )
|
|
|
|
test.enabled = false
|
|
|
|
}
|
2018-01-16 16:45:06 -05:00
|
|
|
|
2019-05-27 09:03:31 -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
|
2019-10-21 12:29:06 -04:00
|
|
|
java.outputDir = file( "${buildDir}/classes/test" )
|
|
|
|
output.resourcesDir = java.outputDir
|
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
|
|
|
|
}
|
2018-06-26 14:05:24 -04:00
|
|
|
hibernateEnvers {
|
|
|
|
description = 'Feature for easily adding Envers support to hibernate-orm'
|
|
|
|
transitive = false
|
|
|
|
}
|
2013-06-12 16:50:06 -04:00
|
|
|
}
|
|
|
|
|
2013-01-23 18:22:03 -05:00
|
|
|
dependencies {
|
2018-07-11 09:41:25 -04:00
|
|
|
compile( project( ':hibernate-core' ) ) {
|
2018-07-12 06:09:35 -04:00
|
|
|
// 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
|
2018-07-11 09:41:25 -04:00
|
|
|
exclude module: 'javax.activation-api'
|
2018-10-15 09:17:27 -04:00
|
|
|
// JAXB is included in the Karaf distribution
|
2018-10-15 06:15:41 -04:00
|
|
|
exclude module: 'jaxb-api'
|
|
|
|
exclude module: 'jaxb-runtime'
|
2018-07-11 09:41:25 -04:00
|
|
|
}
|
2016-05-26 16:38:24 -04:00
|
|
|
testCompile( project( ':hibernate-envers' ) )
|
2015-05-08 16:31:41 -04:00
|
|
|
|
|
|
|
compile "org.osgi:org.osgi.core:${osgiCoreVersion}"
|
2018-07-11 09:41:25 -04:00
|
|
|
compile "org.osgi:org.osgi.compendium:${osgiCompediumVersion}"
|
2017-01-26 09:33:03 -05:00
|
|
|
compile "net.bytebuddy:byte-buddy:${byteBuddyVersion}"
|
2015-04-29 23:10:49 -04:00
|
|
|
|
2017-02-01 19:52:59 -05:00
|
|
|
// Needed by JBoss JTA
|
|
|
|
runtime( libraries.interceptor )
|
|
|
|
|
2018-01-16 16:45:06 -05:00
|
|
|
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}"
|
2015-05-08 16:31:41 -04:00
|
|
|
// 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'
|
|
|
|
|
2018-01-16 16:45:06 -05:00
|
|
|
testCompile( "org.apache.karaf:apache-karaf:${project.karafVersion}" ) {
|
2015-05-08 16:31:41 -04:00
|
|
|
// having trouble finding this one locally
|
|
|
|
exclude group: 'org.eclipse', module: 'org.eclipse.osgi'
|
|
|
|
}
|
|
|
|
|
2018-01-16 16:45:06 -05:00
|
|
|
karafDistro "org.apache.karaf:apache-karaf:${project.karafVersion}@tar.gz"
|
2018-06-26 14:05:24 -04:00
|
|
|
|
|
|
|
hibernateEnvers( project( ':hibernate-envers' ) )
|
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 {
|
2019-10-23 04:03:00 -04:00
|
|
|
attributes(
|
|
|
|
// BND Plugin instructions (for OSGi):
|
|
|
|
'Bundle-Activator': 'org.hibernate.osgi.HibernateBundleActivator',
|
|
|
|
'Provide-Capability': 'osgi.service;effective:=active;objectClass=javax.persistence.spi.PersistenceProvider',
|
|
|
|
'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}\"",
|
|
|
|
// Temporarily support JTA 1.1 -- Karaf and other frameworks still
|
|
|
|
// use it. Without this, the plugin generates [1.2,2).
|
|
|
|
'javax.transaction;version="[1.1,2)"',
|
|
|
|
// Also import every package referenced in the code
|
|
|
|
'*'
|
|
|
|
].join( ',' )
|
|
|
|
)
|
2013-06-12 16:50:06 -04:00
|
|
|
}
|
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()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-26 14:05:24 -04:00
|
|
|
karaf {
|
2015-05-01 09:54:47 -04:00
|
|
|
features {
|
2018-07-12 06:10:45 -04:00
|
|
|
xsdVersion = '1.4.0'
|
|
|
|
feature {
|
|
|
|
name = 'hibernate-orm'
|
|
|
|
description = 'Combines all Hibernate core dependencies and required modules into a single feature'
|
2018-06-27 07:02:00 -04:00
|
|
|
includeProject = true
|
2018-07-11 09:41:25 -04:00
|
|
|
feature ('wrap') {
|
|
|
|
prerequisite = true
|
|
|
|
}
|
|
|
|
feature 'transaction-api'
|
2018-10-10 07:40:41 -04:00
|
|
|
// Most Hibernate modules declare OSGi metadata through blueprints, so we need this feature
|
|
|
|
feature 'aries-blueprint'
|
2018-10-10 07:43:37 -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
|
2018-06-26 14:05:24 -04:00
|
|
|
feature {
|
2015-05-08 16:31:41 -04:00
|
|
|
name = 'hibernate-envers'
|
2015-08-20 11:37:35 -04:00
|
|
|
description = 'Feature for easily adding Envers support to hibernate-orm'
|
2018-06-27 07:02:00 -04:00
|
|
|
includeProject = false
|
2018-06-26 14:05:24 -04:00
|
|
|
configurations 'hibernateEnvers'
|
2018-10-16 04:19:32 -04:00
|
|
|
feature('hibernate-orm') {
|
|
|
|
version = project.version
|
|
|
|
}
|
2015-05-08 16:31:41 -04:00
|
|
|
}
|
2018-07-31 05:12:07 -04:00
|
|
|
// The hibernate-infinispan feature is now provided by the Infinispan project.
|
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 )
|
2019-10-21 12:29:06 -04:00
|
|
|
properties.setProperty( 'org.ops4j.pax.exam.container.karaf.probe.classesDir', sourceSets.test.java.outputDir.absolutePath )
|
2015-05-08 16:31:41 -04:00
|
|
|
properties.setProperty( 'org.ops4j.pax.exam.container.karaf.probe.resourcesDir', sourceSets.test.output.resourcesDir.absolutePath )
|
2018-06-26 14:05:24 -04:00
|
|
|
properties.setProperty( 'org.hibernate.osgi.test.karafFeatureFile', karaf.features.outputFile.absolutePath )
|
2015-05-08 16:31:41 -04:00
|
|
|
|
|
|
|
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
|
|
|
|
2018-06-26 14:05:24 -04:00
|
|
|
tasks.test.dependsOn tasks.generateFeatures
|
2015-05-08 16:31:41 -04:00
|
|
|
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
|
2016-05-26 16:38:24 -04:00
|
|
|
tasks.test.dependsOn rootProject.childProjects.'hibernate-envers'.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 {
|
2018-01-10 16:06:58 -05:00
|
|
|
publishedArtifacts( MavenPublication ) {
|
2018-06-26 14:05:24 -04:00
|
|
|
artifact( project.extensions.karaf.features.outputFile ) {
|
2015-05-12 14:57:40 -04:00
|
|
|
classifier 'karaf'
|
2018-06-26 14:05:24 -04:00
|
|
|
builtBy generateFeatures
|
2015-05-12 14:57:40 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-06-17 20:15:08 -04:00
|
|
|
}
|