HHH-10812 Adding module ZIP and integration test for using Hibernate ORM 5.1 on WildFly 10

This commit is contained in:
Gunnar Morling 2016-06-27 14:07:08 +02:00 committed by Steve Ebersole
parent fe632bc09a
commit 9ec9399ac4
13 changed files with 469 additions and 2 deletions

View File

@ -97,7 +97,7 @@ class HibernateBuildPlugin implements Plugin<Project> {
// 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'
}

View File

@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
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
}
}
}

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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>.
-->
<module-alias xmlns="urn:jboss:module:1.3"
name="org.hibernate" slot="${minorSlot}"
target-name="org.hibernate" target-slot="${slot}"
/>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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>.
-->
<module-alias xmlns="urn:jboss:module:1.3"
name="org.hibernate.infinispan" slot="${minorSlot}"
target-name="org.hibernate.infinispan" target-slot="${slot}"
/>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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>.
-->
<module-alias xmlns="urn:jboss:module:1.3"
name="org.hibernate.jipijapa-hibernate5" slot="${minorSlot}"
target-name="org.hibernate.jipijapa-hibernate5" target-slot="${slot}"
/>

View File

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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>.
-->
<module xmlns="urn:jboss:module:1.3" name="org.hibernate" slot="${slot}">
<resources>
<resource-root path="hibernate-core-${version}.jar"/>
<resource-root path="hibernate-envers-${version}.jar"/>
<resource-root path="hibernate-entitymanager-${version}.jar"/>
<resource-root path="hibernate-java8-${version}.jar"/>
</resources>
<dependencies>
<module name="asm.asm"/>
<module name="com.fasterxml.classmate"/>
<module name="javax.api"/>
<module name="javax.annotation.api"/>
<module name="javax.enterprise.api"/>
<module name="javax.persistence.api"/>
<module name="javax.transaction.api"/>
<module name="javax.validation.api"/>
<module name="javax.xml.bind.api"/>
<module name="org.antlr"/>
<module name="org.dom4j"/>
<module name="org.javassist"/>
<module name="org.jboss.as.jpa.spi"/>
<module name="org.jboss.jandex"/>
<module name="org.jboss.logging"/>
<module name="org.jboss.vfs"/>
<module name="org.hibernate.commons-annotations"/>
<module name="org.hibernate.infinispan" services="import" optional="true" slot="${slot}"/>
<module name="org.hibernate.jipijapa-hibernate5" services="import" slot="${slot}"/>
</dependencies>
</module>

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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>.
-->
<module xmlns="urn:jboss:module:1.3" name="org.hibernate.infinispan" slot="${slot}">
<properties>
<property name="jboss.api" value="private"/>
</properties>
<resources>
<resource-root path="hibernate-infinispan-${version}.jar"/>
</resources>
<dependencies>
<module name="org.hibernate" slot="${slot}"/>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
<module name="org.infinispan" services="import"/>
<module name="org.infinispan.commons"/>
<module name="org.jboss.logging"/>
</dependencies>
</module>

View File

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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>.
-->
<module xmlns="urn:jboss:module:1.3" name="org.hibernate.jipijapa-hibernate5" slot="${slot}">
<properties>
<property name="jboss.api" value="private"/>
</properties>
<resources>
<resource-root path="jipijapa-hibernate5-${wildflyVersion}.jar"/>
</resources>
<dependencies>
<module name="org.hibernate" slot="${slot}"/>
<module name="asm.asm"/>
<module name="com.fasterxml.classmate"/>
<module name="javax.api"/>
<module name="javax.annotation.api"/>
<module name="javax.enterprise.api"/>
<module name="javax.persistence.api"/>
<module name="javax.transaction.api"/>
<module name="javax.validation.api"/>
<module name="javax.xml.bind.api"/>
<module name="org.antlr"/>
<module name="org.dom4j"/>
<module name="org.javassist"/>
<module name="org.jboss.as.jpa.spi"/>
<module name="org.jboss.jandex"/>
<module name="org.jboss.logging"/>
<module name="org.jboss.vfs"/>
<module name="org.hibernate.commons-annotations"/>
<module name="org.hibernate.infinispan" services="import" slot="${slot}"/>
<module name="org.infinispan" services="import"/>
</dependencies>
</module>

View File

@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
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.
* <p>
* 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<Kryptonite> loaded = session.byMultipleIds( Kryptonite.class )
.multiLoad( 1L, 2L );
assertThat( loaded.size(), equalTo( 2 ) );
}
}

View File

@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
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;
}

View File

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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>.
-->
<arquillian
xmlns="http://jboss.org/schema/arquillian"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
<defaultProtocol type="Servlet 3.0" />
<!-- Uncomment in order to inspect deployments -->
<!--
<engine>
<property name="deploymentExportPath">target/deployments</property>
</engine>
-->
<group qualifier="Grid" default="true">
<container qualifier="container.active-1" mode="suite" default="true">
<configuration>
<property name="jbossHome">${buildDir}/wildfly-${wildflyVersion}</property>
<property name="javaVmArguments">-Djava.net.preferIPv4Stack=true -Djgroups.bind_addr=127.0.0.1</property>
<!-- Uncomment for Remote debugging Wildfly -->
<!--
<property name="javaVmArguments">-Djava.net.preferIPv4Stack=true -Djgroups.bind_addr=127.0.0.1 -Xrunjdwp:transport=dt_socket,address=5005,server=y,suspend=y</property>
-->
</configuration>
</container>
</group>
</arquillian>

View File

@ -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}"
]
}

View File

@ -26,6 +26,8 @@ include 'hibernate-jcache'
include 'hibernate-ehcache'
include 'hibernate-infinispan'
include 'hibernate-orm-modules'
include 'documentation'
include 'release'