configurations { osgiRuntime osgiRuntimeBnd } sourceSets { testResult testClientBundle } sourceSets.test { compileClasspath += sourceSets.testResult.output runtimeClasspath += sourceSets.testResult.output } sourceSets.testClientBundle { compileClasspath += sourceSets.testResult.output runtimeClasspath += sourceSets.testResult.output } dependencies { 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:4.3.1" ) compile( "org.osgi:org.osgi.compendium:4.3.1" ) testCompile( libraries.shrinkwrap_api ) testCompile( libraries.shrinkwrap ) testCompile( "org.jboss.arquillian.junit:arquillian-junit-container:1.0.3.Final" ) testCompile( "org.jboss.osgi.metadata:jbosgi-metadata:3.0.0.CR1" ) testRuntime( "org.jboss.arquillian.container:arquillian-osgi-felix:2.0.0.CR4" ) testRuntime( "org.apache.felix:org.apache.felix.framework:4.0.3" ) testRuntime( "org.apache.felix:org.apache.felix.main:4.0.3" ) testRuntime( "org.jboss.logmanager:jboss-logmanager:1.4.1.Final" ) // Local copies of all jars needed fur the OSGi runtime. Ignore the transitive dependencies. // ORDER DEPENDENT!!! osgiRuntime( "org.jboss.arquillian.osgi:arquillian-osgi-bundle:1.0.3.Final" ) { transitive = false } osgiRuntime( libraries.jpa ) { transitive = false } osgiRuntime( "org.jboss.spec.javax.interceptor:jboss-interceptors-api_1.2_spec:1.0.0.Alpha1" ) { transitive = false } osgiRuntime( libraries.jta ) { transitive = false } osgiRuntime( "com.h2database:h2:1.3.170" ) { transitive = false } osgiRuntime( "org.apache.servicemix.bundles:org.apache.servicemix.bundles.antlr:2.7.7_5" ) { transitive = false } osgiRuntime( libraries.javassist ) { transitive = false } osgiRuntime( "org.apache.servicemix.specs:org.apache.servicemix.specs.stax-api-1.2:2.2.0" ) { transitive = false } osgiRuntime( "org.apache.servicemix.bundles:org.apache.servicemix.bundles.dom4j:1.6.1_5" ) { transitive = false } osgiRuntime( libraries.commons_annotations ) { transitive = false } osgiRuntime( libraries.classmate ) { transitive = false } osgiRuntime( libraries.logging ) { transitive = false } // needed for BND osgiRuntimeBnd( libraries.jandex ) { transitive = false } osgiRuntimeBnd( "javax.enterprise:cdi-api:1.1" ) { transitive = false } osgiRuntimeBnd( "javax.el:el-api:2.2" ) { transitive = false } testClientBundleCompile( project( ':hibernate-core' ) ) testClientBundleCompile( 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 testClientBundleCompile( "org.osgi:org.osgi.core:4.3.1" ) } def pomName() { return 'Hibernate OSGi Support' } def pomDescription() { return 'Support for running Hibernate O/RM in OSGi environments' } jar { manifest { instruction 'Bundle-Activator', 'org.hibernate.osgi.HibernateBundleActivator' instruction 'Bundle-Description', 'Hibernate ORM OSGi' 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 copyBnd(type: Copy) { from "src/test/resources/bnd" into "$buildDir/osgi-lib/bnd" } task runBnd(type: JavaExec){ main = "-jar" args "$buildDir/osgi-lib/bnd/bnd-2.1.0.jar", "$buildDir/osgi-lib/bnd/cdi-api.bnd", "$buildDir/osgi-lib/bnd/el-api.bnd", "$buildDir/osgi-lib/bnd/jandex.bnd" } task copyToLib(type: Copy) { from configurations.osgiRuntime from configurations.osgiRuntimeBnd into "$buildDir/osgi-lib" } task felixProperties << { copy { from "src/test/resources/felix-framework.properties-ORIGINAL" into "$buildDir/osgi-lib" rename { String fileName -> fileName.replace("-ORIGINAL", "") } } propertiesFile = file("$buildDir/osgi-lib/felix-framework.properties") // append jars wrapped using BND FileTree tree = fileTree(dir: "$buildDir/osgi-lib/bnd") tree.exclude "*bnd*" tree.each {File file -> propertiesFile << " \\\nfile:target/osgi-lib/bnd/" + file.name } // append all jars in osgiRuntime configuration configurations.osgiRuntime.each { File file -> propertiesFile << " \\\nfile:target/osgi-lib/" + file.name } // append ORM jars // TODO: Is there a better, dynamic way of doing this? propertiesFile << " \\\nfile:../hibernate-core/target/libs/hibernate-core-" + hibernateTargetVersion + ".jar" propertiesFile << " \\\nfile:../hibernate-entitymanager/target/libs/hibernate-entitymanager-" + hibernateTargetVersion + ".jar" propertiesFile << " \\\nfile:target/libs/hibernate-osgi-" + hibernateTargetVersion + ".jar" } task testClientBundleJar(type: Jar) { from sourceSets.testClientBundle.output, sourceSets.testResult.output destinationDir new File("$buildDir/osgi-lib") archiveName "testClientBundle.jar" // The OSGi plugin acts up when we need to export multiple source sets. Just do it manually. manifest { attributes("Export-Package" : "org.hibernate.osgi.test.client,org.hibernate.osgi.test.result", "Bundle-Name" : "testClientBundle", "Bundle-Activator" : "org.hibernate.osgi.test.client.OsgiTestActivator", "Bundle-ManifestVersion" : "2", "Bundle-SymbolicName" : "testClientBundle", "Import-Package" : "javassist.util.proxy,javax.persistence,javax.persistence.spi,org.h2,org.hibernate,org.hibernate.proxy,org.osgi.framework") } } runBnd.dependsOn copyToLib runBnd.dependsOn copyBnd felixProperties.dependsOn runBnd test.dependsOn felixProperties test.dependsOn testClientBundleJar test.dependsOn jar