From 9ec9399ac484938451bd7b8e0dabba19cef79769 Mon Sep 17 00:00:00 2001 From: Gunnar Morling Date: Mon, 27 Jun 2016 14:07:08 +0200 Subject: [PATCH] HHH-10812 Adding module ZIP and integration test for using Hibernate ORM 5.1 on WildFly 10 --- .../build/HibernateBuildPlugin.groovy | 2 +- .../hibernate-orm-modules.gradle | 166 ++++++++++++++++++ .../aliases/org/hibernate/core/module.xml | 11 ++ .../org/hibernate/infinispan/module.xml | 11 ++ .../hibernate/jipijapa-hibernate5/module.xml | 11 ++ .../modules/org/hibernate/core/module.xml | 37 ++++ .../org/hibernate/infinispan/module.xml | 26 +++ .../hibernate/jipijapa-hibernate5/module.xml | 39 ++++ .../HibernateModulesOnWildflyTest.java | 93 ++++++++++ .../wildfly/integrationtest/Kryptonite.java | 22 +++ .../src/test/resources/arquillian.xml | 35 ++++ libraries.gradle | 16 +- settings.gradle | 2 + 13 files changed, 469 insertions(+), 2 deletions(-) create mode 100644 hibernate-orm-modules/hibernate-orm-modules.gradle create mode 100644 hibernate-orm-modules/src/main/aliases/org/hibernate/core/module.xml create mode 100644 hibernate-orm-modules/src/main/aliases/org/hibernate/infinispan/module.xml create mode 100644 hibernate-orm-modules/src/main/aliases/org/hibernate/jipijapa-hibernate5/module.xml create mode 100644 hibernate-orm-modules/src/main/modules/org/hibernate/core/module.xml create mode 100644 hibernate-orm-modules/src/main/modules/org/hibernate/infinispan/module.xml create mode 100644 hibernate-orm-modules/src/main/modules/org/hibernate/jipijapa-hibernate5/module.xml create mode 100644 hibernate-orm-modules/src/test/java/org/hibernate/wildfly/integrationtest/HibernateModulesOnWildflyTest.java create mode 100644 hibernate-orm-modules/src/test/java/org/hibernate/wildfly/integrationtest/Kryptonite.java create mode 100644 hibernate-orm-modules/src/test/resources/arquillian.xml diff --git a/buildSrc/src/main/groovy/org/hibernate/build/HibernateBuildPlugin.groovy b/buildSrc/src/main/groovy/org/hibernate/build/HibernateBuildPlugin.groovy index 22dd04297c..e5ae38ffef 100644 --- a/buildSrc/src/main/groovy/org/hibernate/build/HibernateBuildPlugin.groovy +++ b/buildSrc/src/main/groovy/org/hibernate/build/HibernateBuildPlugin.groovy @@ -97,7 +97,7 @@ class HibernateBuildPlugin implements Plugin { // TEMPORARY : currently Gradle Publishing feature is exporting dependencies as 'runtime' scope, // rather than 'compile'; fix that. - if ( asNode().dependencies != null ) { + if ( asNode().dependencies != null && asNode().dependencies.size() > 0 ) { asNode().dependencies[0].dependency.each { it.scope[0].value = 'compile' } diff --git a/hibernate-orm-modules/hibernate-orm-modules.gradle b/hibernate-orm-modules/hibernate-orm-modules.gradle new file mode 100644 index 0000000000..d254485fcf --- /dev/null +++ b/hibernate-orm-modules/hibernate-orm-modules.gradle @@ -0,0 +1,166 @@ +/* + * 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 . + */ +apply plugin: 'base' +apply plugin: 'maven' + +ext { + // Exact ORM version, e.g. "5.1.1.Final" + slot = rootProject.hibernateTargetVersion + + // Just the minor ORM version, e.g. "5.1"; Is used as an alias for the exact version + minorSlot = slot.substring( 0, slot.indexOf( ".", slot.indexOf( "." ) + 1) ) + + majorWildflyVersion = wildflyVersion.substring( 0, wildflyVersion.indexOf( "." ) ) + + // directory for building the ZIP file from + modulesDirectory = "$buildDir/hibernate-orm-modules" +} + +configurations { + jipijapa + wildflyDist +} + +dependencies { + jipijapa "org.wildfly:jipijapa-hibernate5:${wildflyVersion}" + wildflyDist "org.wildfly:wildfly-dist:${wildflyVersion}@zip" + + testCompile project( ":hibernate-core" ) + testCompile libraries.junit + testCompile libraries.arquillian_junit_container + testCompile libraries.arquillian_protocol_servlet + testCompile libraries.shrinkwrap_descriptors_api_javaee + testCompile libraries.shrinkwrap_descriptors_impl_javaee + testCompile libraries.wildfly_arquillian_container_managed +} + +/*************************/ +/* Main */ +/*************************/ + +// Copies all the module.xml descriptors into the output directory +task copyModuleXmls(type: Copy) { + into( modulesDirectory ) + expand( slot: slot, minorSlot: minorSlot, version: rootProject.hibernateTargetVersion, wildflyVersion: wildflyVersion ) + + // Actual module.xml files + into( 'org/hibernate/' + slot ) { + from 'src/main/modules/org/hibernate/core' + } + + into( 'org/hibernate/infinispan/' + slot ) { + from 'src/main/modules/org/hibernate/infinispan' + } + + into( 'org/hibernate/jipijapa-hibernate5/' + slot ) { + from 'src/main/modules/org/hibernate/jipijapa-hibernate5' + } + + // Aliases + into( 'org/hibernate/' + minorSlot ) { + from 'src/main/aliases/org/hibernate/core' + } + + into( 'org/hibernate/infinispan/' + minorSlot ) { + from 'src/main/aliases/org/hibernate/infinispan' + } + + into( 'org/hibernate/jipijapa-hibernate5/' + minorSlot ) { + from 'src/main/aliases/org/hibernate/jipijapa-hibernate5' + } +} + +// Copies all the ORM JARs and the JipiJapa JAR into the output directory +task copyJars(dependsOn: copyModuleXmls, type: Copy) { + into( modulesDirectory ) + + into( 'org/hibernate/' + slot ) { + from parent.project( 'hibernate-core' ).configurations.archives.allArtifacts.files + from parent.project( 'hibernate-envers' ).configurations.archives.allArtifacts.files + from parent.project( 'hibernate-entitymanager' ).configurations.archives.allArtifacts.files + from parent.project( 'hibernate-java8' ).configurations.archives.allArtifacts.files + } + + into( 'org/hibernate/infinispan/' + slot ) { + from parent.project( 'hibernate-infinispan' ).configurations.archives.allArtifacts.files.filter{ file -> !file.name.endsWith('-sources.jar') && !file.name.endsWith('-tests.jar') } + } + + into( 'org/hibernate/jipijapa-hibernate5/' + slot ) { + from configurations.jipijapa.copy().setTransitive( false ) + } +} + +// Creates a ZIP from the output directory +task createModulesZip(dependsOn: copyJars, type: Zip) { + classifier = "wildfly${majorWildflyVersion}-dist" + from modulesDirectory +} + +/*************************/ +/* Testing */ +/*************************/ + +// Unzip Wildfly Dist +task extractWildFly(type: Copy) { + from { + configurations.wildflyDist.collect { zipTree(it) } + } + into "$buildDir/" +} + +// Unzip Hibernate ORM Modules ZIP into the server's "modules" dir +task extractModules(dependsOn: [extractWildFly, createModulesZip], type: Copy) { + duplicatesStrategy DuplicatesStrategy.EXCLUDE + from zipTree( createModulesZip.archivePath ) + into "$buildDir/wildfly-${wildflyVersion}/modules" +} + +task filterArquillianXml(type: Copy) { + into( buildDir.getName() + '/resources/test' ) + expand( buildDir: buildDir.getName(), wildflyVersion: wildflyVersion ) + from 'src/test/resources' +} + +test.dependsOn extractModules +test.dependsOn filterArquillianXml + +build.dependsOn createModulesZip + +// Exclude JAR creation/publication inherited from parent +afterEvaluate { + tasks.withType(PublishToMavenLocal) { task -> + if (task.publication.name.equals( 'mavenJava') ) { + task.enabled = false + task.group = null + } + } + + tasks.withType(PublishToMavenRepository) { task -> + if (task.publication.name.equals( 'mavenJava') ) { + task.enabled = false + task.group = null + } + } + + tasks.withType(Jar) { task -> + task.enabled = false + task.group = null + } +} + +mavenPom { + name = "Hibernate ORM modules for WildFly ${majorWildflyVersion}" + description = "Hibernate ORM modules for WildFly ${majorWildflyVersion}" +} + +publishing { + publications { + mavenZip( MavenPublication ) { + artifact createModulesZip + } + } +} diff --git a/hibernate-orm-modules/src/main/aliases/org/hibernate/core/module.xml b/hibernate-orm-modules/src/main/aliases/org/hibernate/core/module.xml new file mode 100644 index 0000000000..3c2b9eff0e --- /dev/null +++ b/hibernate-orm-modules/src/main/aliases/org/hibernate/core/module.xml @@ -0,0 +1,11 @@ + + + diff --git a/hibernate-orm-modules/src/main/aliases/org/hibernate/infinispan/module.xml b/hibernate-orm-modules/src/main/aliases/org/hibernate/infinispan/module.xml new file mode 100644 index 0000000000..d50a4393ab --- /dev/null +++ b/hibernate-orm-modules/src/main/aliases/org/hibernate/infinispan/module.xml @@ -0,0 +1,11 @@ + + + diff --git a/hibernate-orm-modules/src/main/aliases/org/hibernate/jipijapa-hibernate5/module.xml b/hibernate-orm-modules/src/main/aliases/org/hibernate/jipijapa-hibernate5/module.xml new file mode 100644 index 0000000000..25b9f93a83 --- /dev/null +++ b/hibernate-orm-modules/src/main/aliases/org/hibernate/jipijapa-hibernate5/module.xml @@ -0,0 +1,11 @@ + + + diff --git a/hibernate-orm-modules/src/main/modules/org/hibernate/core/module.xml b/hibernate-orm-modules/src/main/modules/org/hibernate/core/module.xml new file mode 100644 index 0000000000..9be2661073 --- /dev/null +++ b/hibernate-orm-modules/src/main/modules/org/hibernate/core/module.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/hibernate-orm-modules/src/main/modules/org/hibernate/infinispan/module.xml b/hibernate-orm-modules/src/main/modules/org/hibernate/infinispan/module.xml new file mode 100644 index 0000000000..95fb69b4c9 --- /dev/null +++ b/hibernate-orm-modules/src/main/modules/org/hibernate/infinispan/module.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/hibernate-orm-modules/src/main/modules/org/hibernate/jipijapa-hibernate5/module.xml b/hibernate-orm-modules/src/main/modules/org/hibernate/jipijapa-hibernate5/module.xml new file mode 100644 index 0000000000..88cc9e22d0 --- /dev/null +++ b/hibernate-orm-modules/src/main/modules/org/hibernate/jipijapa-hibernate5/module.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/hibernate-orm-modules/src/test/java/org/hibernate/wildfly/integrationtest/HibernateModulesOnWildflyTest.java b/hibernate-orm-modules/src/test/java/org/hibernate/wildfly/integrationtest/HibernateModulesOnWildflyTest.java new file mode 100644 index 0000000000..5d4f532840 --- /dev/null +++ b/hibernate-orm-modules/src/test/java/org/hibernate/wildfly/integrationtest/HibernateModulesOnWildflyTest.java @@ -0,0 +1,93 @@ +/* + * 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 . + */ +package org.hibernate.wildfly.integrationtest; + +import static org.hamcrest.core.IsEqual.equalTo; +import static org.junit.Assert.assertThat; + +import java.util.List; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; + +import org.hibernate.Session; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.shrinkwrap.descriptor.api.Descriptors; +import org.jboss.shrinkwrap.descriptor.api.persistence21.PersistenceDescriptor; +import org.jboss.shrinkwrap.descriptor.api.persistence21.PersistenceUnitTransactionType; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * Integration test for using the current Hibernate ORM version on WildFly. + *

+ * Gradle will unzip the targeted WildFly version and unpack the module ZIP created by this build into the server's + * module directory. Arquillian is used to start this WildFly instance, run this test on the server and stop the server + * again. + * + * @author Gunnar Morling + */ +@RunWith(Arquillian.class) +public class HibernateModulesOnWildflyTest { + + private static final String ORM_VERSION = Session.class.getPackage().getImplementationVersion(); + private static final String ORM_MINOR_VERSION = ORM_VERSION.substring( 0, ORM_VERSION.indexOf( ".", ORM_VERSION.indexOf( "." ) + 1) ); + + @Deployment + public static WebArchive createDeployment() { + return ShrinkWrap.create( WebArchive.class ) + .addClass( Kryptonite.class ) + .addAsWebInfResource( EmptyAsset.INSTANCE, "beans.xml" ) + .addAsResource( new StringAsset( persistenceXml().exportAsString() ), "META-INF/persistence.xml" ); + } + + private static PersistenceDescriptor persistenceXml() { + return Descriptors.create( PersistenceDescriptor.class ) + .version( "2.1" ) + .createPersistenceUnit() + .name( "primary" ) + .transactionType( PersistenceUnitTransactionType._JTA ) + .jtaDataSource( "java:jboss/datasources/ExampleDS" ) + .getOrCreateProperties() + // We want to use the ORM from this build instead of the one coming with WildFly + .createProperty().name( "jboss.as.jpa.providerModule" ).value( "org.hibernate:" + ORM_MINOR_VERSION ).up() + .createProperty().name( "hibernate.hbm2ddl.auto" ).value( "create-drop" ).up() + .up().up(); + } + + @PersistenceContext + private EntityManager entityManager; + + @Test + public void shouldUseHibernateOrm51() { + Session session = entityManager.unwrap( Session.class ); + + Kryptonite kryptonite1 = new Kryptonite(); + kryptonite1.id = 1L; + kryptonite1.description = "Some Kryptonite"; + session.persist( kryptonite1 ); + + Kryptonite kryptonite2 = new Kryptonite(); + kryptonite2.id = 2L; + kryptonite2.description = "Some more Kryptonite"; + session.persist( kryptonite2 ); + + session.flush(); + session.clear(); + + // multiLoad only introduced in 5.1 + List loaded = session.byMultipleIds( Kryptonite.class ) + .multiLoad( 1L, 2L ); + + assertThat( loaded.size(), equalTo( 2 ) ); + } +} diff --git a/hibernate-orm-modules/src/test/java/org/hibernate/wildfly/integrationtest/Kryptonite.java b/hibernate-orm-modules/src/test/java/org/hibernate/wildfly/integrationtest/Kryptonite.java new file mode 100644 index 0000000000..7b073fe6f3 --- /dev/null +++ b/hibernate-orm-modules/src/test/java/org/hibernate/wildfly/integrationtest/Kryptonite.java @@ -0,0 +1,22 @@ +/* + * 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 . + */ +package org.hibernate.wildfly.integrationtest; + +import javax.persistence.Entity; +import javax.persistence.Id; + +/** + * @author Gunnar Morling + */ +@Entity +public class Kryptonite { + + @Id + public long id; + + public String description; +} diff --git a/hibernate-orm-modules/src/test/resources/arquillian.xml b/hibernate-orm-modules/src/test/resources/arquillian.xml new file mode 100644 index 0000000000..0c87c1a0a9 --- /dev/null +++ b/hibernate-orm-modules/src/test/resources/arquillian.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + ${buildDir}/wildfly-${wildflyVersion} + -Djava.net.preferIPv4Stack=true -Djgroups.bind_addr=127.0.0.1 + + + + + + + diff --git a/libraries.gradle b/libraries.gradle index e0436c06e5..e493024bf5 100644 --- a/libraries.gradle +++ b/libraries.gradle @@ -17,6 +17,12 @@ ext { jnpVersion = '5.0.6.CR1' elVersion = '2.2.4' + // Wildfly version targeted by module ZIP; Arquillian/Shrinkwrap versions used for testing the module ZIP + wildflyVersion = '10.0.0.Final' + arquillianVersion = '1.1.10.Final' + shrinkwrapVersion = '2.0.0-alpha-8' + wildflyArquillianContainerVersion = '2.0.0.Final' + libraries = [ // Ant ant: 'org.apache.ant:ant:1.8.2', @@ -114,7 +120,15 @@ ext { ehcache3: "org.ehcache:ehcache:3.0.0", jcache: "javax.cache:cache-api:1.0.0", proxool: "proxool:proxool:0.8.3", - hikaricp: "com.zaxxer:HikariCP-java6:2.3.9" + hikaricp: "com.zaxxer:HikariCP-java6:2.3.9", + // Arquillian etc. + arquillian_junit_container: "org.jboss.arquillian.junit:arquillian-junit-container:${arquillianVersion}", + arquillian_protocol_servlet: "org.jboss.arquillian.protocol:arquillian-protocol-servlet:${arquillianVersion}", + + shrinkwrap_descriptors_api_javaee: "org.jboss.shrinkwrap.descriptors:shrinkwrap-descriptors-api-javaee:${shrinkwrapVersion}", + shrinkwrap_descriptors_impl_javaee: "org.jboss.shrinkwrap.descriptors:shrinkwrap-descriptors-impl-javaee:${shrinkwrapVersion}", + + wildfly_arquillian_container_managed: "org.wildfly.arquillian:wildfly-arquillian-container-managed:${wildflyArquillianContainerVersion}" ] } diff --git a/settings.gradle b/settings.gradle index eee0b0ab55..cf2b21a829 100644 --- a/settings.gradle +++ b/settings.gradle @@ -26,6 +26,8 @@ include 'hibernate-jcache' include 'hibernate-ehcache' include 'hibernate-infinispan' +include 'hibernate-orm-modules' + include 'documentation' include 'release'