HHH-10664 - Prep 6.0 feature branch - baseline Java 8

This commit is contained in:
Steve Ebersole 2016-03-31 12:04:10 -05:00
parent 9570f110a1
commit 8ddd61b061
5 changed files with 94 additions and 302 deletions

View File

@ -54,16 +54,17 @@ allprojects {
}
ext {
expectedGradleVersion = '2.10'
hibernateTargetVersion = '5.1.1-SNAPSHOT'
hibernateTargetVersion = '5.1.1-SNAPSHOT'
expectedGradleVersion = '2.10'
baselineJavaVersion = '1.8'
osgiExportVersion = hibernateTargetVersion.replaceAll( '-SNAPSHOT', '.SNAPSHOT' )
}
idea {
project {
jdkName = '1.6'
languageLevel = '1.6'
jdkName = baselineJavaVersion
languageLevel = baselineJavaVersion
vcs = 'Git'
}
@ -110,6 +111,9 @@ subprojects { subProject ->
apply plugin: org.hibernate.build.HibernateBuildPlugin
sourceCompatibility = rootProject.baselineJavaVersion
targetCompatibility = rootProject.baselineJavaVersion
configurations {
provided {
// todo : need to make sure these are non-exported
@ -159,6 +163,8 @@ subprojects { subProject ->
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// compilation
task compile
compile.dependsOn compileJava, processResources, compileTestJava, processTestResources
@ -167,6 +173,70 @@ subprojects { subProject ->
compileClasspath += configurations.jbossLoggingTool
}
subProject.getConvention().findPlugin( JavaPluginConvention.class ).sourceSets.each { sourceSet ->
JavaCompile javaCompileTask = project.tasks.findByName( sourceSet.compileJavaTaskName ) as JavaCompile
// NOTE : this aptDir stuff is needed until we can have IntelliJ run annotation processors for us
// which cannot happen until we can fold hibernate-testing back into hibernate-core/src/test
// which cannot happen until... ugh
File aptDir = subProject.file( "${subProject.buildDir}/generated-src/apt/${sourceSet.name}" )
sourceSet.allJava.srcDir( aptDir )
javaCompileTask.options.compilerArgs += [
"-nowarn",
"-encoding", "UTF-8",
"-s", "${aptDir.absolutePath}"
]
javaCompileTask.doFirst {
aptDir.mkdirs()
}
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// testing
subProject.tasks.withType( Test.class ).all { task ->
task.jvmArgs += [
'-XX:+HeapDumpOnOutOfMemoryError',
"-XX:HeapDumpPath=${project.file( "${project.buildDir}/OOM-dump.hprof" ).absolutePath}",
'-XX:MetaspaceSize=512M'
]
task.maxHeapSize = '2G'
task.systemProperties['hibernate.test.validatefailureexpected'] = true
task.systemProperties += System.properties.findAll { it.key.startsWith( "hibernate.") }
// uncomment to help identify pauses in test executions : where they occur
// task.beforeTest { descriptor ->
// println "Starting test: " + descriptor
// }
// task.afterTest { descriptor ->
// println "Completed test: " + descriptor
// }
}
processTestResources.doLast( {
copy {
from( sourceSets.test.java.srcDirs ) {
include '**/*.properties'
include '**/*.xml'
}
into sourceSets.test.output.classesDir
}
copy {
ext.targetDir = file( "${buildDir}/resources/test" )
from file('src/test/resources')
into targetDir
filter( ReplaceTokens, tokens: dbBundle[db] );
}
} )
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// artifact
jar {
manifest = osgiManifest {
// GRADLE-1411: Even if we override Imports and Exports
@ -197,38 +267,23 @@ subprojects { subProject ->
}
}
test {
systemProperties['hibernate.test.validatefailureexpected'] = true
systemProperties += System.properties.findAll { it.key.startsWith( "hibernate.") }
// beforeTest { descriptor ->
// println "Starting test: " + descriptor
// }
// afterTest { descriptor ->
// println "Completed test: " + descriptor
// }
task sourcesJar(type: Jar, dependsOn: compileJava) {
from sourceSets.main.allSource
classifier = 'sources'
}
processTestResources.doLast( {
copy {
from( sourceSets.test.java.srcDirs ) {
include '**/*.properties'
include '**/*.xml'
}
into sourceSets.test.output.classesDir
}
copy {
ext.targetDir = file( "${buildDir}/resources/test" )
from file('src/test/resources')
into targetDir
filter( ReplaceTokens, tokens: dbBundle[db] );
}
} )
sourcesJar {
manifest = jar.manifest
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// IDE options
idea {
module {
jdkName = javaTarget.version
jdkName = subProject.sourceCompatibility
excludeDirs = [file( ".gradle" )]
excludeDirs += file( "$buildDir/classes" )
@ -249,8 +304,8 @@ subprojects { subProject ->
eclipse {
jdt {
sourceCompatibility = javaTarget.version
targetCompatibility = javaTarget.version
sourceCompatibility = subProject.sourceCompatibility
targetCompatibility = subProject.targetCompatibility
}
classpath {
plusConfigurations.add( configurations.provided )
@ -261,9 +316,11 @@ subprojects { subProject ->
// TODO: Eclipse's annotation processor handling is also fairly stupid (and completely lacks in the
// Gradle plugin). For now, just compile first in order to get the logging classes.
eclipseClasspath.dependsOn compile
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Report configs ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Report configs
checkstyle {
sourceSets = [ subProject.sourceSets.main ]
configFile = rootProject.file( 'shared/config/checkstyle/checkstyle.xml' )
@ -303,6 +360,8 @@ subprojects { subProject ->
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Publishing
publishing {
publications {
mavenJava(MavenPublication) {
@ -327,15 +386,8 @@ subprojects { subProject ->
destination = file( "$subProject.buildDir/generated-pom.xml" )
}
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
task sourcesJar(type: Jar, dependsOn: compileJava) {
from sourceSets.main.allSource
classifier = 'sources'
}
sourcesJar {
manifest = jar.manifest
}
}
task release(type: Task, dependsOn: 'release:release')

View File

@ -10,14 +10,8 @@ import org.gradle.api.GradleException
import org.gradle.api.JavaVersion
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.plugins.JavaPluginConvention
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.tasks.compile.JavaCompile
import org.gradle.api.tasks.testing.Test
import org.gradle.internal.jvm.Jvm
import org.hibernate.build.gradle.animalsniffer.AnimalSnifferExtension
/**
* @author Steve Ebersole
@ -29,177 +23,13 @@ class HibernateBuildPlugin implements Plugin<Project> {
throw new GradleException( "Gradle must be run with Java 8" )
}
project.apply( plugin: 'org.hibernate.build.gradle.animalSniffer' )
final Jvm java6Home;
if ( project.rootProject.extensions.extraProperties.has( 'java6Home' ) ) {
java6Home = project.rootProject.extensions.extraProperties.get( 'java6Home' ) as Jvm
}
else {
String java6HomeDirSetting = null;
if ( project.hasProperty( "JAVA6_HOME" ) ) {
java6HomeDirSetting = project.property( "JAVA6_HOME" ) as String;
}
if ( java6HomeDirSetting == null ) {
java6HomeDirSetting = System.getProperty( "JAVA6_HOME" );
}
if ( java6HomeDirSetting == null ) {
java6HomeDirSetting = System.getenv( "JAVA6_HOME" );
}
if ( java6HomeDirSetting != null ) {
project.logger.info( "Using JAVA6_HOME setting [${java6HomeDirSetting}]" )
final File specifiedJava6Home = project.file( java6HomeDirSetting );
if ( specifiedJava6Home == null ) {
throw new GradleException( "Could not resolve specified java home ${java6HomeDirSetting}" )
}
if ( !specifiedJava6Home.exists() ) {
throw new GradleException( "Specified java home [${java6HomeDirSetting}] does not exist" )
}
if ( !specifiedJava6Home.isDirectory() ) {
throw new GradleException( "Specified java home [${java6HomeDirSetting}] is not a directory" )
}
java6Home = Jvm.forHome( specifiedJava6Home ) as Jvm;
if ( java6Home == null ) {
throw new GradleException( "Could not resolve JAVA6_HOME [${java6HomeDirSetting}] to proper JAVA_HOME" );
}
project.rootProject.extensions.extraProperties.set( 'java6Home', java6Home )
}
else {
project.logger.warn( "JAVA6_HOME setting not specified, some build features will be disabled" )
java6Home = null;
}
}
JavaTargetExtension javaTargetExtension = project.extensions.create( "javaTarget", JavaTargetExtension, project )
MavenPublishingExtension publishingExtension = project.extensions.create( "mavenPom", MavenPublishingExtension )
project.afterEvaluate {
applyJavaTarget( javaTargetExtension, project, java6Home )
applyPublishing( publishingExtension, project )
}
}
def applyJavaTarget(JavaTargetExtension javaTargetExtension, Project project, Jvm java6Home) {
project.logger.info( "Setting target Java version : ${javaTargetExtension.version} (${project.name})" )
project.properties.put( 'sourceCompatibility', "${javaTargetExtension.version}" )
project.properties.put( 'targetCompatibility', "${javaTargetExtension.version}" )
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// apply AnimalSniffer
if ( javaTargetExtension.version.java8Compatible ) {
AnimalSnifferExtension animalSnifferExtension = project.extensions.findByType( AnimalSnifferExtension )
if ( animalSnifferExtension == null ) {
throw new GradleException( "Unable to locate AnimalSniffer extension" )
}
animalSnifferExtension.skip = true
}
else {
// todo : we could really disable this if we set executable/bootClasspath below
def sigConfig = project.configurations.animalSnifferSignature
sigConfig.incoming.beforeResolve {
sigConfig.dependencies.add( project.dependencies.create( 'org.codehaus.mojo.signature:java16:1.0@signature' ) )
}
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Apply to compile task
project.getConvention().findPlugin( JavaPluginConvention.class ).sourceSets.each { sourceSet ->
JavaCompile javaCompileTask = project.tasks.findByName( sourceSet.compileJavaTaskName ) as JavaCompile
// NOTE : this aptDir stuff is needed until we can have IntelliJ run annotation processors for us
// which cannot happen until we can fold hibernate-testing back into hibernate-core/src/test
// which cannot happen until... ugh
File aptDir = project.file( "${project.buildDir}/generated-src/apt/${sourceSet.name}" )
sourceSet.allJava.srcDir( aptDir )
javaCompileTask.options.compilerArgs += [
"-nowarn",
"-encoding", "UTF-8",
"-s", "${aptDir.absolutePath}"
]
javaCompileTask.doFirst {
aptDir.mkdirs()
}
if ( sourceSet.name == 'main' ) {
if ( javaTargetExtension.version.java8Compatible ) {
javaCompileTask.options.compilerArgs += [
"-source", '1.8',
"-target", '1.8'
]
}
else {
javaCompileTask.options.compilerArgs += [
"-source", '1.6',
"-target", '1.6'
]
if ( java6Home != null ) {
if ( javaTargetExtension.shouldApplyTargetToCompile ) {
// Technically we need only one here between:
// 1) setting the javac executable
// 2) setting the bootClasspath
// However, (1) requires fork=true whereas (2) does not.
// javaCompileTask.options.fork = true
// javaCompileTask.options.forkOptions.executable = java6Home.javacExecutable
javaCompileTask.options.bootClasspath = java6Home.runtimeJar.absolutePath
}
}
}
}
}
//
//
// // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// // Apply to test compile task
//
// SourceSet testSourceSet = project.getConvention().findPlugin( JavaPluginConvention.class ).sourceSets.findByName( "test" )
// JavaCompile compileTestTask = project.tasks.findByName( testSourceSet.compileJavaTaskName ) as JavaCompile
//
// // NOTE : see the note above wrt aptDir
// File testAptDir = project.file( "${project.buildDir}/generated-src/apt/test" )
// testSourceSet.allJava.srcDir( testAptDir )
//
// compileTestTask.options.compilerArgs += [
// "-nowarn",
// "-encoding", "UTF-8",
// "-s", "${testAptDir.absolutePath}"
// ]
// compileTestTask.doFirst {
// testAptDir.mkdirs()
// }
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Apply to test tasks
project.tasks.withType( Test.class ).all { task->
task.jvmArgs += ['-XX:+HeapDumpOnOutOfMemoryError', "-XX:HeapDumpPath=${project.file("${project.buildDir}/OOM-dump.hprof").absolutePath}"]
// if ( !javaTargetExtension.version.java8Compatible && javaTargetExtension.shouldApplyTargetToTest ) {
// // use Java 6 settings
// task.executable = java6Home.javaExecutable
// task.maxHeapSize = '2G'
// task.jvmArgs += ['-XX:MaxPermGen=512M']
// }
// else {
// use Java 8 settings
task.maxHeapSize = '2G'
task.jvmArgs += ['-XX:MetaspaceSize=512M']
// }
}
}
def applyPublishing(MavenPublishingExtension publishingExtension, Project project) {
PublishingExtension gradlePublishingExtension = project.extensions.getByType( PublishingExtension )

View File

@ -1,84 +0,0 @@
/*
* 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.build
import org.gradle.api.GradleException
import org.gradle.api.JavaVersion
import org.gradle.api.Project
import org.gradle.internal.jvm.Jvm
/**
* Defines a Gradle Project extension to hold information pertaining to the targeted Java version
* for the project. This information can then be used to configure tasks (JavaCompile, etc).
*
* @author Steve Ebersole
*/
class JavaTargetExtension {
private final Project project
JavaVersion version = JavaVersion.VERSION_1_6
boolean shouldApplyTargetToCompile = true
boolean shouldApplyTargetToTest = true
JavaTargetExtension(Project project) {
this.project = project
}
JavaVersion getVersion() {
return version
}
void setVersion(Object version) {
this.version = JavaVersion.toVersion( version );
if ( this.version == null ) {
this.version = JavaVersion.VERSION_1_6
}
}
Jvm getJavaHome() {
return javaHome
}
void setJavaHome(Object javaHome) {
if ( javaHome == null ) {
this.javaHome = null
}
else if ( javaHome instanceof Jvm ) {
this.javaHome = javaHome as Jvm
}
else {
final File specifiedJavaHome = project.file( javaHome );
if ( specifiedJavaHome == null ) {
throw new GradleException( "Could not resolve specified java home ${javaHome}" )
}
if ( !specifiedJavaHome.exists() ) {
throw new GradleException( "Specified java home [${javaHome}] does not exist" )
}
if ( !specifiedJavaHome.isDirectory() ) {
throw new GradleException( "Specified java home [${javaHome}] is not a directory" )
}
this.javaHome = Jvm.forHome( specifiedJavaHome ) as Jvm
}
}
boolean getShouldApplyTargetToCompile() {
return shouldApplyTargetToCompile
}
void setShouldApplyTargetToCompile(boolean shouldApplyTargetToCompile) {
this.shouldApplyTargetToCompile = shouldApplyTargetToCompile
}
boolean getShouldApplyTargetToTest() {
return shouldApplyTargetToTest
}
void setShouldApplyTargetToTest(boolean shouldApplyTargetToTest) {
this.shouldApplyTargetToTest = shouldApplyTargetToTest
}
}

View File

@ -15,8 +15,6 @@ if ( project.hasProperty( 'overrideInfinispanVersionForTesting' ) ) {
apply plugin: 'java'
project.javaTarget.version '1.8'
dependencies {
compile project( ':hibernate-core' )
compile( libraries.infinispan )

View File

@ -9,10 +9,6 @@ dependencies {
testCompile( project(':hibernate-testing') )
}
javaTarget {
version = '1.8'
}
mavenPom {
name = 'Java8-specific Hibernate O/RM functionality'
description = 'Support for Java8-specific features - mainly Java8 Date/Time (JSR 310)'