Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

HHH-8733 - General build cleanup

  • Loading branch information...
commit 055a750a53f24324dad9a7fe84e5aae2806c0c43 1 parent 5acd232
@sebersole sebersole authored
View
731 build.gradle
@@ -36,6 +36,7 @@ buildscript {
classpath 'org.hibernate.build.gradle:gradle-maven-publish-auth:2.0.1'
classpath 'org.hibernate.build.gradle:hibernate-matrix-testing:1.0.0-SNAPSHOT'
classpath 'org.hibernate.build.gradle:version-injection-plugin:1.0.0'
+ classpath 'org.hibernate.build.gradle:gradle-apt:1.0.0-SNAPSHOT'
}
}
@@ -81,6 +82,16 @@ def osgiDescription() {
// by default just reuse the pomDescription
return pomDescription()
}
+
+def boolean needsLoggingGeneration() {
+ // by default
+ return true;
+}
+
+def SourceSet getMetaGenTargetSourceSet() {
+ return null;
+}
+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
subprojects { subProject ->
@@ -95,376 +106,358 @@ subprojects { subProject ->
// minimize changes, at least for now (gradle uses 'build' by default)..
buildDir = "target"
- if ( ! subProject.name.startsWith( 'release' ) && ! subProject.name.startsWith( 'documentation' ) ) {
- apply plugin: 'java'
- apply plugin: 'maven-publish'
- apply plugin: 'maven-publish-auth'
- apply plugin: 'maven' // temporary, still needed for install task until bug with publishToMavenLocal task is fixed
- apply plugin: 'osgi'
-
- apply from: "${rootProject.projectDir}/utilities.gradle"
-
- apply plugin: 'findbugs'
- apply plugin: 'checkstyle'
- apply plugin: 'build-dashboard'
- apply plugin: 'project-report'
-
- configurations {
- provided {
- // todo : need to make sure these are non-exported
- description = 'Non-exported compile-time dependencies.'
- }
- jbossLoggingTool {
- description = "Dependencies for running the JBoss logging AnnotationProcessor tool"
- }
- jaxb {
- description = 'Dependencies for running ant xjc (jaxb class generation)'
- }
- configurations {
- all*.exclude group: 'xml-apis', module: 'xml-apis'
- }
- animalSniffer
- javaApiSignature
- }
-
- // appropriately inject the common dependencies into each sub-project
- dependencies {
- compile( libraries.logging )
- compile( libraries.logging_annotations )
-
- testCompile( libraries.junit )
- testCompile( libraries.byteman )
- testCompile( libraries.byteman_install )
- testCompile( libraries.byteman_bmunit )
-
- testRuntime( libraries.log4j )
- testRuntime( libraries.javassist )
- testRuntime( libraries.h2 )
-
- jbossLoggingTool( libraries.logging_processor )
-
- jaxb( libraries.jaxb ){
- exclude group: "javax.xml.stream"
- }
- jaxb( libraries.jaxb2_basics )
- jaxb( libraries.jaxb2_ant )
-
- animalSniffer ( libraries.animal_sniffer )
- javaApiSignature ( libraries.java16_signature )
- }
-
- // mac-specific stuff ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- ext.toolsJar = file("${System.getProperty('java.home')}/../lib/tools.jar")
- if ( ext.toolsJar.exists() ) {
- dependencies{
- testCompile files( toolsJar )
- }
- }
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
- targetCompatibility = rootProject.javaLanguageLevel
- sourceCompatibility = rootProject.javaLanguageLevel
-
- task compile
- compile.dependsOn compileJava, processResources, compileTestJava, processTestResources
-
- sourceSets.main {
- compileClasspath += configurations.provided
- }
-
- sourceSets.all {
- ext.aptGeneratedSourceDir = file( "${buildDir}/generated-src/apt/${name}" )
- }
-
- ext.standardJavacOptions = [
- "-nowarn",
- "-encoding", "UTF-8",
- "-source", rootProject.javaLanguageLevel,
- "-target", rootProject.javaLanguageLevel
- ]
-
- tasks.withType( JavaCompile.class ).all { task->
- task.options.define(
- compilerArgs: standardJavacOptions
- )
- }
-
- ext.jbossLoggingToolClass = "org.jboss.logging.processor.apt.LoggingToolsProcessor"
-
- // alter the compileJava (src/main/java javac task) to add JBoss Logging AP hooks
- compileJava {
- classpath += configurations.jbossLoggingTool
-
- options.compilerArgs += [
- "-processor", jbossLoggingToolClass,
- "-s", "$sourceSets.main.aptGeneratedSourceDir.absolutePath",
- "-Adebug=true",
- "-AskipTranslations=true",
- "-AtranslationFilesPath=${project.rootDir}/src/main/resources"
- ]
-
- doFirst {
- if ( !sourceSets.main.aptGeneratedSourceDir.exists() ) {
- sourceSets.main.aptGeneratedSourceDir.mkdirs()
- }
- }
- }
-
- task generateSources(type: Task)
-
- jar {
- manifest = osgiManifest {
- // GRADLE-1411: Even if we override Imports and Exports
- // auto-generation with instructions, classesDir and classpath
- // need to be here (temporarily).
- classesDir = sourceSets.main.output.classesDir
- classpath = configurations.runtime
-
- instruction 'Import-Package',
- // 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)"',
- // Tell Gradle OSGi to still dynamically import the other packages.
- // IMPORTANT: Do not include the * in the modules' .gradle files.
- // If it exists more than once, the manifest will physically contain a *.
- '*'
-
- instruction 'Bundle-Vendor', 'Hibernate.org'
- instruction 'Bundle-Description', osgiDescription()
- instruction 'Implementation-Url', 'http://hibernate.org'
- instruction 'Implementation-Version', version
- instruction 'Implementation-Vendor', 'Hibernate.org'
- instruction 'Implementation-Vendor-Id', 'org.hibernate'
- }
- }
-
- test {
- systemProperties['hibernate.test.validatefailureexpected'] = true
- systemProperties += System.properties.findAll { it.key.startsWith( "hibernate.") }
- maxHeapSize = "1024m"
- // Not strictly needed but useful to attach a profiler:
- jvmArgs '-XX:MaxPermSize=256m'
- }
-
- processTestResources.doLast( {
- copy {
- from( sourceSets.test.java.srcDirs ) {
- include '**/*.properties'
- include '**/*.xml'
- }
- into sourceSets.test.output.classesDir
- }
- } )
-
- idea {
- module {
- iml {
- beforeMerged { module ->
- module.dependencies.clear()
- module.excludeFolders.clear()
- }
- whenMerged { module ->
- module.dependencies*.exported = true
- module.excludeFolders += module.pathFactory.path(file(".gradle"))
- module.excludeFolders += module.pathFactory.path(file("$buildDir/bundles"))
- module.excludeFolders += module.pathFactory.path(file("$buildDir/classes"))
- module.excludeFolders += module.pathFactory.path(file("$buildDir/dependency-cache"))
- module.excludeFolders += module.pathFactory.path(file("$buildDir/libs"))
- module.excludeFolders += module.pathFactory.path(file("$buildDir/reports"))
- module.excludeFolders += module.pathFactory.path(file("$buildDir/test-results"))
- module.excludeFolders += module.pathFactory.path(file("$buildDir/tmp"))
- module.excludeFolders += module.pathFactory.path(file("$buildDir/matrix"))
- module.excludeFolders += module.pathFactory.path(file("$buildDir/resources"))
- module.excludeFolders -= module.pathFactory.path(file("$buildDir"))
- }
- }
- downloadSources = true
- scopes.COMPILE.plus += configurations.provided
- }
- }
-
- eclipse {
- classpath {
- plusConfigurations.add( configurations.provided )
- }
- }
-
- // eclipseClasspath will not add sources to classpath unless the dirs actually exist.
- // 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("testClasses")
-
-
- // Animal Sniffer ~~~~~~~~~~~~~~~~~~
- // add animal sniffer Java API checking to the main compile tasks
-
- // copy the resolved Animal Sniffer signature dependency artifact to a known location and name
- task copyJavaApiSignature(type: Copy) {
- from configurations.javaApiSignature
- into "$buildDir/javaApiSignature/"
- rename '.*signature', 'javaApi.signature'
- }
-
- // prepare the Animal Sniffer signature copy every time (before) we compile
- compileJava.dependsOn copyJavaApiSignature
-
- // and then after compilation, run the Animal Sniffer tool
- compileJava.doLast {
- ant.taskdef(
- name: 'animalSniffer',
- classname: 'org.codehaus.mojo.animal_sniffer.ant.CheckSignatureTask',
- classpath: configurations.animalSniffer.asPath
- )
-
- ant.animalSniffer(
- signature: "$buildDir/javaApiSignature/javaApi.signature",
- classpath: sourceSets.main.compileClasspath.asPath) {
- path( path: sourceSets.main.output.classesDir )
- }
- }
-
- // specialized API/SPI checkstyle tasks ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- task checkstylePublicSources(type: Checkstyle) {
- checkstyleClasspath = checkstyleMain.checkstyleClasspath
- classpath = checkstyleMain.classpath
- configFile = rootProject.file( 'shared/config/checkstyle/checkstyle.xml' )
- source subProject.sourceSets.main.java.srcDirs
- // exclude generated sources
- exclude '**/generated-src/**'
- // because cfg package is a mess mainly from annotation stuff
- exclude '**/org/hibernate/cfg/**'
- exclude '**/org/hibernate/cfg/*'
- // because this should only report on api/spi
- exclude '**/internal/**'
- exclude '**/internal/*'
- ignoreFailures = false
- showViolations = true
- reports {
- xml {
- destination "$buildDir/reports/checkstyle/public.xml"
- }
- }
- }
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
- // Report configs ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- checkstyle {
- sourceSets = [ subProject.sourceSets.main ]
- configFile = rootProject.file( 'shared/config/checkstyle/checkstyle.xml' )
- showViolations = false
- ignoreFailures = true
- }
- // exclude generated sources
- // unfortunately this nice easy approach does not seem to work : http://forums.gradle.org/gradle/topics/specify_excludes_to_checkstyle_task
- //checkstyleMain.exclude '**/generated-src/**'
- checkstyleMain.exclude '**/org/hibernate/hql/internal/antlr/**'
- checkstyleMain.exclude '**/org/hibernate/hql/internal/antlr/*'
- checkstyleMain.exclude '**/org/hibernate/sql/ordering/antlr/*'
- checkstyleMain.exclude '**/*_$logger*'
- checkstyleMain.exclude '**/org/hibernate/internal/jaxb/**'
- // because cfg package is a mess mainly from annotation stuff
- checkstyleMain.exclude '**/org/hibernate/cfg/**'
- checkstyleMain.exclude '**/org/hibernate/cfg/*'
-
- findbugs {
- sourceSets = [ subProject.sourceSets.main, subProject.sourceSets.test ]
- ignoreFailures = true
- }
- // exclude generated sources
- // unfortunately this nice easy approach does not seem to work : http://forums.gradle.org/gradle/topics/specify_excludes_to_checkstyle_task
- //findbugsMain.exclude '**/generated-src/**'
- findbugsMain.exclude '**/org/hibernate/hql/internal/antlr/**'
- findbugsMain.exclude '**/org/hibernate/hql/internal/antlr/*'
- findbugsMain.exclude '**/org/hibernate/sql/ordering/antlr/*'
- findbugsMain.exclude '**/*_$logger*'
- findbugsMain.exclude '**/org/hibernate/internal/jaxb/**'
-
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-
- publishing {
- publications {
- mavenJava(MavenPublication) {
- from components.java
-
- artifact sourcesJar {
- classifier "sources"
- }
-
- pom.withXml {
- // append additional metadata
- asNode().children().last() + {
- resolveStrategy = Closure.DELEGATE_FIRST
-
- name subProject.pomName()
- description subProject.pomDescription()
- url 'http://hibernate.org'
- organization {
- name 'Hibernate.org'
- url 'http://hibernate.org'
- }
- issueManagement {
- system 'jira'
- url 'https://hibernate.atlassian.net/browse/HHH'
- }
- scm {
- url 'http://github.com/hibernate/hibernate-orm'
- connection 'scm:git:http://github.com/hibernate/hibernate-orm.git'
- developerConnection 'scm:git:git@github.com:hibernate/hibernate-orm.git'
- }
- licenses {
- license {
- name 'GNU Lesser General Public License'
- url 'http://www.gnu.org/licenses/lgpl-2.1.html'
- comments 'See discussion at http://hibernate.org/license for more details.'
- distribution 'repo'
- }
- }
- developers {
- developer {
- id 'hibernate-team'
- name 'The Hibernate Development Team'
- organization 'Hibernate.org'
- organizationUrl 'http://hibernate.org'
- }
- }
- }
-
- // TEMPORARY : currently Gradle Publishing feature is exporting dependencies as 'runtime' scope,
- // rather than 'compile'; fix that.
- asNode().dependencies[0].dependency.each {
- it.scope[0].value = 'compile'
- }
- }
- }
- }
-
- repositories {
- maven {
- if ( subProject.version.endsWith( 'SNAPSHOT' ) ) {
- name 'jboss-snapshots-repository'
- url 'https://repository.jboss.org/nexus/content/repositories/snapshots'
- }
- else {
- name 'jboss-releases-repository'
- url 'https://repository.jboss.org/nexus/service/local/staging/deploy/maven2/'
- }
- }
- }
- }
-
- model {
- tasks.generatePomFileForMavenJavaPublication {
- destination = file( "$project.buildDir/generated-pom.xml" )
- }
- }
-
- task sourcesJar(type: Jar, dependsOn: compileJava) {
- from sourceSets.main.allSource
- classifier = 'sources'
- }
- }
+ if ( subProject.name.startsWith( 'release' ) || subProject.name.startsWith( 'documentation' ) ) {
+ return;
+ }
+
+ // everything below here in the closure applies to java projects
+ apply plugin: 'java'
+ apply plugin: 'maven-publish'
+ apply plugin: 'maven-publish-auth'
+ apply plugin: 'osgi'
+
+ apply from: "${rootProject.projectDir}/source-generation.gradle"
+// apply from: "${rootProject.projectDir}/utilities.gradle"
+
+ apply plugin: 'findbugs'
+ apply plugin: 'checkstyle'
+ apply plugin: 'build-dashboard'
+ apply plugin: 'project-report'
+
+ configurations {
+ provided {
+ // todo : need to make sure these are non-exported
+ description = 'Non-exported compile-time dependencies.'
+ }
+ jbossLoggingTool {
+ description = "Dependencies for running the JBoss logging AnnotationProcessor tool"
+ }
+ jaxb {
+ description = 'Dependencies for running ant xjc (jaxb class generation)'
+ }
+ configurations {
+ all*.exclude group: 'xml-apis', module: 'xml-apis'
+ }
+ animalSniffer
+ javaApiSignature
+ }
+
+ // appropriately inject the common dependencies into each sub-project
+ dependencies {
+ compile( libraries.logging )
+ compile( libraries.logging_annotations )
+
+ testCompile( libraries.junit )
+ testCompile( libraries.byteman )
+ testCompile( libraries.byteman_install )
+ testCompile( libraries.byteman_bmunit )
+
+ testRuntime( libraries.log4j )
+ testRuntime( libraries.javassist )
+ testRuntime( libraries.h2 )
+
+ jbossLoggingTool( libraries.logging_processor )
+
+ jaxb( libraries.jaxb ){
+ exclude group: "javax.xml.stream"
+ }
+ jaxb( libraries.jaxb2_basics )
+ jaxb( libraries.jaxb2_ant )
+
+ animalSniffer ( libraries.animal_sniffer )
+ javaApiSignature ( libraries.java16_signature )
+ }
+
+ // mac-specific stuff ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ext.toolsJar = file("${System.getProperty('java.home')}/../lib/tools.jar")
+ if ( ext.toolsJar.exists() ) {
+ dependencies{
+ testCompile files( toolsJar )
+ }
+ }
+ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ targetCompatibility = rootProject.javaLanguageLevel
+ sourceCompatibility = rootProject.javaLanguageLevel
+
+ task compile
+ compile.dependsOn compileJava, processResources, compileTestJava, processTestResources
+
+ sourceSets.main {
+ compileClasspath += configurations.provided
+ }
+
+ tasks.withType( JavaCompile.class ).all { task->
+ task.options.compilerArgs += [
+ "-nowarn",
+ "-proc:none",
+ "-encoding", "UTF-8",
+ "-source", rootProject.javaLanguageLevel,
+ "-target", rootProject.javaLanguageLevel
+ ]
+ }
+
+ if ( subProject.needsLoggingGeneration() ) {
+ addLoggingProcessor( sourceSets.main )
+ }
+
+ final SourceSet metaGenSourceSet = subProject.getMetaGenTargetSourceSet();
+ if ( metaGenSourceSet != null ) {
+ addMetaGenProcessor( metaGenSourceSet )
+ }
+
+ jar {
+ manifest = osgiManifest {
+ // GRADLE-1411: Even if we override Imports and Exports
+ // auto-generation with instructions, classesDir and classpath
+ // need to be here (temporarily).
+ classesDir = sourceSets.main.output.classesDir
+ classpath = configurations.runtime
+
+ instruction 'Import-Package',
+ // 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)"',
+ // Tell Gradle OSGi to still dynamically import the other packages.
+ // IMPORTANT: Do not include the * in the modules' .gradle files.
+ // If it exists more than once, the manifest will physically contain a *.
+ '*'
+
+ instruction 'Bundle-Vendor', 'Hibernate.org'
+ instruction 'Bundle-Description', subProject.osgiDescription()
+ instruction 'Implementation-Url', 'http://hibernate.org'
+ instruction 'Implementation-Version', version
+ instruction 'Implementation-Vendor', 'Hibernate.org'
+ instruction 'Implementation-Vendor-Id', 'org.hibernate'
+ }
+ }
+
+ test {
+ systemProperties['hibernate.test.validatefailureexpected'] = true
+ systemProperties += System.properties.findAll { it.key.startsWith( "hibernate.") }
+ maxHeapSize = "1024m"
+ // Not strictly needed but useful to attach a profiler:
+ jvmArgs '-XX:MaxPermSize=256m'
+ }
+
+ processTestResources.doLast( {
+ copy {
+ from( sourceSets.test.java.srcDirs ) {
+ include '**/*.properties'
+ include '**/*.xml'
+ }
+ into sourceSets.test.output.classesDir
+ }
+ } )
+
+ idea {
+ module {
+ iml {
+ beforeMerged { module ->
+ module.dependencies.clear()
+ module.excludeFolders.clear()
+ }
+ whenMerged { module ->
+ module.dependencies*.exported = true
+ module.excludeFolders += module.pathFactory.path(file(".gradle"))
+ module.excludeFolders += module.pathFactory.path(file("$buildDir/bundles"))
+ module.excludeFolders += module.pathFactory.path(file("$buildDir/classes"))
+ module.excludeFolders += module.pathFactory.path(file("$buildDir/dependency-cache"))
+ module.excludeFolders += module.pathFactory.path(file("$buildDir/libs"))
+ module.excludeFolders += module.pathFactory.path(file("$buildDir/reports"))
+ module.excludeFolders += module.pathFactory.path(file("$buildDir/test-results"))
+ module.excludeFolders += module.pathFactory.path(file("$buildDir/tmp"))
+ module.excludeFolders += module.pathFactory.path(file("$buildDir/matrix"))
+ module.excludeFolders += module.pathFactory.path(file("$buildDir/resources"))
+ module.excludeFolders -= module.pathFactory.path(file("$buildDir"))
+ }
+ }
+ downloadSources = true
+ scopes.COMPILE.plus += configurations.provided
+ }
+ }
+
+ eclipse {
+ classpath {
+ plusConfigurations.add( configurations.provided )
+ }
+ }
+
+ // eclipseClasspath will not add sources to classpath unless the dirs actually exist.
+ // 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 generateSources
+
+
+ // Animal Sniffer ~~~~~~~~~~~~~~~~~~
+ // add animal sniffer Java API checking to the main compile tasks
+
+ // copy the resolved Animal Sniffer signature dependency artifact to a known location and name
+ task copyJavaApiSignature(type: Copy) {
+ from configurations.javaApiSignature
+ into "$buildDir/javaApiSignature/"
+ rename '.*signature', 'javaApi.signature'
+ }
+
+ // prepare the Animal Sniffer signature copy every time (before) we compile
+ compileJava.dependsOn copyJavaApiSignature
+
+ // and then after compilation, run the Animal Sniffer tool
+ compileJava.doLast {
+ ant.taskdef(
+ name: 'animalSniffer',
+ classname: 'org.codehaus.mojo.animal_sniffer.ant.CheckSignatureTask',
+ classpath: configurations.animalSniffer.asPath
+ )
+
+ ant.animalSniffer(
+ signature: "$buildDir/javaApiSignature/javaApi.signature",
+ classpath: sourceSets.main.compileClasspath.asPath) {
+ path( path: sourceSets.main.output.classesDir )
+ }
+ }
+
+ // specialized API/SPI checkstyle tasks ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ task checkstylePublicSources(type: Checkstyle) {
+ checkstyleClasspath = checkstyleMain.checkstyleClasspath
+ classpath = checkstyleMain.classpath
+ configFile = rootProject.file( 'shared/config/checkstyle/checkstyle.xml' )
+ source subProject.sourceSets.main.java.srcDirs
+ // exclude generated sources
+ exclude '**/generated-src/**'
+ // because cfg package is a mess mainly from annotation stuff
+ exclude '**/org/hibernate/cfg/**'
+ exclude '**/org/hibernate/cfg/*'
+ // because this should only report on api/spi
+ exclude '**/internal/**'
+ exclude '**/internal/*'
+ ignoreFailures = false
+ showViolations = true
+ reports {
+ xml {
+ destination "$buildDir/reports/checkstyle/public.xml"
+ }
+ }
+ }
+ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ // Report configs ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ checkstyle {
+ sourceSets = [ subProject.sourceSets.main ]
+ configFile = rootProject.file( 'shared/config/checkstyle/checkstyle.xml' )
+ showViolations = false
+ ignoreFailures = true
+ }
+ // exclude generated sources
+ // unfortunately this nice easy approach does not seem to work : http://forums.gradle.org/gradle/topics/specify_excludes_to_checkstyle_task
+ //checkstyleMain.exclude '**/generated-src/**'
+ checkstyleMain.exclude '**/org/hibernate/hql/internal/antlr/**'
+ checkstyleMain.exclude '**/org/hibernate/hql/internal/antlr/*'
+ checkstyleMain.exclude '**/org/hibernate/sql/ordering/antlr/*'
+ checkstyleMain.exclude '**/*_$logger*'
+ checkstyleMain.exclude '**/org/hibernate/internal/jaxb/**'
+ // because cfg package is a mess mainly from annotation stuff
+ checkstyleMain.exclude '**/org/hibernate/cfg/**'
+ checkstyleMain.exclude '**/org/hibernate/cfg/*'
+
+ findbugs {
+ sourceSets = [ subProject.sourceSets.main, subProject.sourceSets.test ]
+ ignoreFailures = true
+ }
+ // exclude generated sources
+ // unfortunately this nice easy approach does not seem to work : http://forums.gradle.org/gradle/topics/specify_excludes_to_checkstyle_task
+ //findbugsMain.exclude '**/generated-src/**'
+ findbugsMain.exclude '**/org/hibernate/hql/internal/antlr/**'
+ findbugsMain.exclude '**/org/hibernate/hql/internal/antlr/*'
+ findbugsMain.exclude '**/org/hibernate/sql/ordering/antlr/*'
+ findbugsMain.exclude '**/*_$logger*'
+ findbugsMain.exclude '**/org/hibernate/internal/jaxb/**'
+
+ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+
+ publishing {
+ publications {
+ mavenJava(MavenPublication) {
+ from components.java
+
+ artifact sourcesJar {
+ classifier "sources"
+ }
+
+ pom.withXml {
+ // append additional metadata
+ asNode().children().last() + {
+ resolveStrategy = Closure.DELEGATE_FIRST
+
+ name subProject.pomName()
+ description subProject.pomDescription()
+ url 'http://hibernate.org'
+ organization {
+ name 'Hibernate.org'
+ url 'http://hibernate.org'
+ }
+ issueManagement {
+ system 'jira'
+ url 'https://hibernate.atlassian.net/browse/HHH'
+ }
+ scm {
+ url 'http://github.com/hibernate/hibernate-orm'
+ connection 'scm:git:http://github.com/hibernate/hibernate-orm.git'
+ developerConnection 'scm:git:git@github.com:hibernate/hibernate-orm.git'
+ }
+ licenses {
+ license {
+ name 'GNU Lesser General Public License'
+ url 'http://www.gnu.org/licenses/lgpl-2.1.html'
+ comments 'See discussion at http://hibernate.org/license for more details.'
+ distribution 'repo'
+ }
+ }
+ developers {
+ developer {
+ id 'hibernate-team'
+ name 'The Hibernate Development Team'
+ organization 'Hibernate.org'
+ organizationUrl 'http://hibernate.org'
+ }
+ }
+ }
+
+ // TEMPORARY : currently Gradle Publishing feature is exporting dependencies as 'runtime' scope,
+ // rather than 'compile'; fix that.
+ asNode().dependencies[0].dependency.each {
+ it.scope[0].value = 'compile'
+ }
+ }
+ }
+ }
+
+ repositories {
+ maven {
+ if ( subProject.version.endsWith( 'SNAPSHOT' ) ) {
+ name 'jboss-snapshots-repository'
+ url 'https://repository.jboss.org/nexus/content/repositories/snapshots'
+ }
+ else {
+ name 'jboss-releases-repository'
+ url 'https://repository.jboss.org/nexus/service/local/staging/deploy/maven2/'
+ }
+ }
+ }
+ }
+
+ model {
+ tasks.generatePomFileForMavenJavaPublication {
+ destination = file( "$project.buildDir/generated-pom.xml" )
+ }
+ }
+
+ task sourcesJar(type: Jar, dependsOn: compileJava) {
+ from sourceSets.main.allSource
+ classifier = 'sources'
+ }
}
task release(type: Task, dependsOn: 'release:release')
View
62 documentation/documentation.gradle
@@ -20,7 +20,7 @@ buildscript {
apply plugin: "java"
apply plugin: "jdocbook"
-apply from: "../utilities.gradle"
+apply from: "${rootProject.projectDir}/utilities.gradle"
defaultTasks 'buildDocs'
@@ -74,37 +74,35 @@ task aggregateJavadocs(type: Javadoc) {
Set<String> internalPackages = new HashSet<String>()
parent.subprojects.each{ Project subProject->
// skip certain sub-projects
- if ( ! ['release','documentation'].contains( subProject.name ) ) {
- subProject.sourceSets.each { sourceSet ->
- // skip certain source sets
- if ( ! ['test','matrix'].contains( sourceSet.name ) ) {
- source sourceSet.java
-
- if( classpath ) {
- classpath += sourceSet.output + sourceSet.compileClasspath
- }
- else {
- classpath = sourceSet.output + sourceSet.compileClasspath
- }
-
- sourceSet.java.each { javaFile ->
- final String packageName = determinePackageName( sourceSet.java, javaFile );
- if ( packageName.endsWith( ".internal" ) || packageName.contains( ".internal." ) ) {
- internalPackages.add( packageName );
- }
- else if ( packageName.endsWith( ".spi" ) || packageName.contains( ".spi." ) ) {
- spiPackages.add( packageName );
- }
- else if ( packageName.startsWith( "org.hibernate.testing" ) ) {
- // do nothing as testing support is already handled...
- }
- else {
- apiPackages.add( packageName );
- }
- }
- }
- }
- }
+ if ( ['release','documentation'].contains( subProject.name ) ) {
+ return;
+ }
+
+ // we only care about the main SourceSet...
+ source subProject.sourceSets.main.java
+
+ if( classpath ) {
+ classpath += subProject.sourceSets.main.output + subProject.sourceSets.main.compileClasspath
+ }
+ else {
+ classpath = subProject.sourceSets.main.output + subProject.sourceSets.main.compileClasspath
+ }
+
+ subProject.sourceSets.main.java.each { javaFile ->
+ final String packageName = determinePackageName( subProject.sourceSets.main.java, javaFile );
+ if ( packageName.endsWith( ".internal" ) || packageName.contains( ".internal." ) ) {
+ internalPackages.add( packageName );
+ }
+ else if ( packageName.endsWith( ".spi" ) || packageName.contains( ".spi." ) ) {
+ spiPackages.add( packageName );
+ }
+ else if ( packageName.startsWith( "org.hibernate.testing" ) ) {
+ // do nothing as testing support is already handled...
+ }
+ else {
+ apiPackages.add( packageName );
+ }
+ }
}
// apply standard config
View
4 hibernate-c3p0/hibernate-c3p0.gradle
@@ -17,3 +17,7 @@ def pomName() {
def pomDescription() {
return 'Integration for c3p0 Connection pooling into Hibernate O/RM'
}
+
+def osgiDescription() {
+ return pomDescription()
+}
View
22 hibernate-core/hibernate-core.gradle
@@ -49,6 +49,10 @@ def pomDescription() {
return 'The core O/RM functionality as provided by Hibernate'
}
+def osgiDescription() {
+ return pomDescription()
+}
+
jar {
manifest {
mainAttributes( 'Main-Class': 'org.hibernate.Version' )
@@ -83,8 +87,11 @@ jar {
}
}
+ext {
+ jaxbTargetDir = file( "${buildDir}/generated-src/jaxb/main" )
+}
+
sourceSets.main {
- ext.jaxbTargetDir = file( "${buildDir}/generated-src/jaxb/main" )
java.srcDir jaxbTargetDir
}
@@ -101,9 +108,6 @@ idea {
task jaxb {
ext {
- // output directory
- jaxbTargetDir = file( "${buildDir}/generated-src/jaxb/main" )
-
// input schemas
cfgXsd = file( 'src/main/resources/org/hibernate/hibernate-configuration-4.0.xsd')
hbmXsd = file( 'src/main/resources/org/hibernate/hibernate-mapping-4.0.xsd' )
@@ -156,12 +160,6 @@ task jaxb {
}
-//generateMainLoggingClasses.dependsOn jaxb
-//generateMainLoggingClasses.dependsOn generateGrammarSource
-
-generateSources.dependsOn jaxb
-generateSources.dependsOn generateGrammarSource
-
-compileJava.dependsOn jaxb
-
+runSourceGenerators.dependsOn jaxb
+runSourceGenerators.dependsOn generateGrammarSource
View
28 hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/BasicConnectionCreator.java
@@ -30,6 +30,7 @@
import org.hibernate.HibernateException;
import org.hibernate.JDBCException;
import org.hibernate.engine.jdbc.spi.JdbcServices;
+import org.hibernate.exception.JDBCConnectionException;
import org.hibernate.exception.internal.SQLStateConversionDelegate;
import org.hibernate.exception.spi.ConversionContext;
import org.hibernate.exception.spi.SQLExceptionConversionDelegate;
@@ -101,15 +102,28 @@ public Connection createConnection() {
new ValueHolder.DeferredInitializer<SQLExceptionConversionDelegate>() {
@Override
public SQLExceptionConversionDelegate initialize() {
- return new SQLStateConversionDelegate(
- new ConversionContext() {
- @Override
- public ViolatedConstraintNameExtracter getViolatedConstraintNameExtracter() {
- // this should never happen...
- throw new HibernateException( "Unexpected call to org.hibernate.exception.spi.ConversionContext.getViolatedConstraintNameExtracter" );
+ return new SQLExceptionConversionDelegate() {
+ private final SQLStateConversionDelegate sqlStateDelegate = new SQLStateConversionDelegate(
+ new ConversionContext() {
+ @Override
+ public ViolatedConstraintNameExtracter getViolatedConstraintNameExtracter() {
+ // this should never happen...
+ throw new HibernateException( "Unexpected call to org.hibernate.exception.spi.ConversionContext.getViolatedConstraintNameExtracter" );
+ }
}
+ );
+
+ @Override
+ public JDBCException convert(SQLException sqlException, String message, String sql) {
+ JDBCException exception = sqlStateDelegate.convert( sqlException, message, sql );
+ if ( exception == null ) {
+ // assume this is either a set-up problem or a problem connecting, which we will
+ // categorize the same here.
+ exception = new JDBCConnectionException( message, sqlException, sql );
}
- );
+ return exception;
+ }
+ };
}
}
);
View
2  hibernate-core/src/test/java/org/hibernate/connection/ConnectionCreatorTest.java
@@ -70,7 +70,7 @@ public void testBadUrl() throws Exception {
return super.getService( serviceRole );
}
},
- "jdbc:h2:???:bad-url",
+ "jdbc:h2:mem:test-bad-urls;nosuchparam=saywhat",
new Properties(),
false,
null
View
4 hibernate-ehcache/hibernate-ehcache.gradle
@@ -12,3 +12,7 @@ def pomName() {
def pomDescription() {
return 'Integration for Ehcache into Hibernate as a second-level caching service'
}
+
+def osgiDescription() {
+ return pomDescription()
+}
View
25 hibernate-entitymanager/hibernate-entitymanager.gradle
@@ -43,6 +43,14 @@ def pomDescription() {
return 'Hibernate O/RM implementation of the JPA specification'
}
+def osgiDescription() {
+ return pomDescription()
+}
+
+def getMetaGenTargetSourceSet() {
+ return sourceSets.test;
+}
+
jar {
manifest {
// A cdi-api OSGi bundle does not currently exist. For now, explicitly
@@ -67,23 +75,6 @@ jar {
}
-// alter the compileTestJava (src/test/java javac task) to add AP hooks
-compileTestJava {
- classpath += configurations.hibernateJpaModelGenTool
-
- options.compilerArgs += [
- "-processor", "org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor",
- "-s", "$sourceSets.test.aptGeneratedSourceDir.absolutePath"
- ]
-
- doFirst {
- if ( !sourceSets.test.aptGeneratedSourceDir.exists() ) {
- sourceSets.test.aptGeneratedSourceDir.mkdirs()
- }
- }
-}
-
-
////////////////////////////////////////////////////////////////////////////////////////////////////////
// Process 'bundle resources' for the packaging tests
////////////////////////////////////////////////////////////////////////////////////////////////////////
View
15 hibernate-envers/hibernate-envers.gradle
@@ -29,6 +29,13 @@ def pomDescription() {
return 'Entity versioning support'
}
+def osgiDescription() {
+ return pomDescription()
+}
+
+def getMetaGenTargetSourceSet() {
+ return sourceSets.main;
+}
sourceSets {
test {
@@ -45,14 +52,6 @@ sourceSets {
}
}
-compileJava {
- classpath += configurations.hibernateJpaModelGenTool
-
-
- options.compilerArgs += [
- "-processor", "$jbossLoggingToolClass,org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor"
- ]
-}
jar {
manifest {
View
4 hibernate-infinispan/hibernate-infinispan.gradle
@@ -24,6 +24,10 @@ def pomDescription() {
return 'Integration for Infinispan into Hibernate as a second-level caching service'
}
+def osgiDescription() {
+ return pomDescription()
+}
+
test {
systemProperties['java.net.preferIPv4Stack'] = true
systemProperties['jgroups.ping.timeout'] = 500
View
8 hibernate-osgi/hibernate-osgi.gradle
@@ -69,6 +69,14 @@ def pomDescription() {
return 'Support for running Hibernate O/RM in OSGi environments'
}
+def osgiDescription() {
+ return pomDescription()
+}
+
+def boolean needsLoggingGeneration() {
+ return false;
+}
+
jar {
manifest {
instruction 'Bundle-Activator', 'org.hibernate.osgi.HibernateBundleActivator'
View
4 hibernate-proxool/hibernate-proxool.gradle
@@ -11,3 +11,7 @@ def pomName() {
def pomDescription() {
return 'Integration for Proxool Connection pooling into Hibernate O/RM'
}
+
+def osgiDescription() {
+ return pomDescription()
+}
View
4 hibernate-testing/hibernate-testing.gradle
@@ -25,4 +25,8 @@ def pomDescription() {
def osgiDescription() {
return pomDescription()
+}
+
+def boolean needsLoggingGeneration() {
+ return false;
}
View
385 source-generation.gradle
@@ -0,0 +1,385 @@
+import java.nio.charset.Charset
+import java.util.concurrent.Callable
+import javax.tools.Diagnostic
+import javax.tools.DiagnosticListener
+import javax.tools.JavaCompiler
+import javax.tools.JavaFileObject
+import javax.tools.StandardJavaFileManager
+import javax.tools.ToolProvider
+
+import org.gradle.api.internal.project.ProjectInternal
+import org.gradle.api.internal.tasks.SimpleWorkResult
+import org.gradle.api.internal.tasks.compile.CompilationFailedException
+import org.gradle.api.internal.tasks.compile.Compiler
+import org.gradle.api.internal.tasks.compile.DefaultJavaCompileSpec
+import org.gradle.api.internal.tasks.compile.DefaultJavaCompilerFactory
+import org.gradle.api.internal.tasks.compile.DelegatingJavaCompiler
+import org.gradle.api.internal.tasks.compile.JavaCompileSpec
+import org.gradle.api.internal.tasks.compile.JavaCompilerArgumentsBuilder
+import org.gradle.api.internal.tasks.compile.JavaCompilerFactory
+import org.gradle.api.internal.tasks.compile.daemon.CompilerDaemonManager
+import org.gradle.api.internal.tasks.compile.jdk6.Jdk6JavaCompiler
+import org.gradle.internal.jvm.Jvm
+
+apply plugin: SourceGenerationPlugin
+
+class SourceGenerationPlugin implements Plugin<Project> {
+ public static final String GROUP = "sourceGeneration";
+
+ public static final String GENERATE_SOURCES_TASK_NAME = "generateSources";
+
+ @Override
+ public void apply(Project project) {
+ final JavaPluginConvention javaPluginConvention = project.getConvention().findPlugin( JavaPluginConvention.class );
+ if ( javaPluginConvention == null ) {
+ // something seriously awry
+ return;
+ }
+
+ project.convention.plugins[GROUP] = new SourceGenerationPluginConvention( project );
+
+ // first set up the overall generateSources task
+ Task generateSourcesTask = project.getTasks().findByName( GENERATE_SOURCES_TASK_NAME );
+ if ( generateSourcesTask == null ) {
+ generateSourcesTask = project.getTasks().create( GENERATE_SOURCES_TASK_NAME );
+ generateSourcesTask.setGroup( GROUP );
+ generateSourcesTask.setDescription( "Grouping task for all source generation tasks" );
+ }
+
+ // for each source set, define the specific grouping tasks (and associate with the generateSources as a
+ // task dependency)
+ for ( SourceSet sourceSet : javaPluginConvention.getSourceSets() ) {
+ final ExtraPropertiesExtension extProps = ( (ExtensionAware) sourceSet ).getExtensions().getExtraProperties();
+
+ // find the main javac task for this sourceSet (so we can add dependsOn to it)
+ final JavaCompile javaCompileTask = (JavaCompile) project.getTasks().getByName( sourceSet.getCompileJavaTaskName() );
+
+ // create the pre-apt generation grouping task
+ final String sourceGeneratorsTaskName = sourceSet.getTaskName( "run", "sourceGenerators" );
+ final Task sourceGeneratorsTask = project.getTasks().create( sourceGeneratorsTaskName );
+ sourceGeneratorsTask.setGroup( GROUP );
+ sourceGeneratorsTask.setDescription(
+ String.format(
+ "Grouping task for running all source generation tasks for the %s source-set of the %s project",
+ sourceSet.getName(),
+ project.getName()
+ )
+ );
+ generateSourcesTask.dependsOn( sourceGeneratorsTask );
+ javaCompileTask.dependsOn( sourceGeneratorsTask );
+
+ extProps.set( "sourceGeneratorsTask", sourceGeneratorsTask );
+ }
+ }
+}
+
+class SourceGenerationPluginConvention {
+ public static final String LOGGING_DEPENDENCY_CONFIG_NAME = "jbossLoggingTool";
+ public static final String LOGGING_PROCESSOR_NAME = "org.jboss.logging.processor.apt.LoggingToolsProcessor";
+
+ public static final String METAGEN_DEPENDENCY_CONFIG_NAME = "hibernateJpaModelGenTool";
+ public static final String METAGEN_PROCESSOR_NAME = "org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor";
+
+ private final Project project;
+
+ // practicality says we only ever deal with 2 source-sets:
+ private AnnotationProcessorOnlyTask mainProcOnlyTask;
+ private AnnotationProcessorOnlyTask testProcOnlyTask;
+
+ SourceGenerationPluginConvention(Project project) {
+ this.project = project
+ }
+
+ public void addLoggingProcessor(SourceSet sourceSet) {
+ AnnotationProcessorOnlyTask task = getLocateProcessorOnlyTask( sourceSet )
+ task.processors += LOGGING_PROCESSOR_NAME
+ task.classpath += project.configurations[LOGGING_DEPENDENCY_CONFIG_NAME];
+ }
+
+ private AnnotationProcessorOnlyTask getLocateProcessorOnlyTask(SourceSet sourceSet) {
+ if ( sourceSet.name.equals( "main" ) ) {
+ if ( mainProcOnlyTask == null ) {
+ mainProcOnlyTask = generateProcessorOnlyTask( sourceSet )
+ }
+ return mainProcOnlyTask;
+ }
+ else if ( sourceSet.name.equals( "test" ) ) {
+ if ( testProcOnlyTask == null ) {
+ testProcOnlyTask = generateProcessorOnlyTask( sourceSet )
+ }
+ return testProcOnlyTask;
+ }
+ else {
+ throw new IllegalArgumentException( "SourceSet (" + sourceSet.name + ") not valid for source generation" )
+ }
+ }
+
+ private AnnotationProcessorOnlyTask generateProcessorOnlyTask(SourceSet sourceSet) {
+ // find the main javac task for this sourceSet (we will alter it a bit later on)
+ final JavaCompile javaCompileTask = (JavaCompile) project.getTasks().getByName( sourceSet.getCompileJavaTaskName() );
+
+ final ExtraPropertiesExtension extProps = ( (ExtensionAware) sourceSet ).getExtensions().getExtraProperties();
+
+ // Obtain the output dir reference: generated-src/apt/{sourceSet.name}
+ final File outputDir = new File(
+ new File( project.getBuildDir(), "generated-src/apt/" ),
+ sourceSet.getName()
+ );
+
+ final String aptTaskName = sourceSet.getTaskName( "run", "annotationProcessors" );
+ final AnnotationProcessorOnlyTask aptTask = project.getTasks().create( aptTaskName, AnnotationProcessorOnlyTask.class );
+ aptTask.setGroup( SourceGenerationPlugin.GROUP );
+ aptTask.setDescription(
+ String.format(
+ "Grouping task for running all AnnotationProcessors (javac -proc:only) for the %s sourceSet of the %s project",
+ sourceSet.getName(),
+ project.getName()
+ )
+ );
+
+ // sourceSet.getAllJava() returns a SourceDirectorySet which is a "live view" meaning it keeps expanding
+ // even as we add to it. The problem is that later on here we will add the output directory of this task
+ // to this SourceDirectorySet; we need to make sure that we use the view of the SourceDirectorySet *before* that
+ // happens as the source for this task. getSrcDirs() does that
+ aptTask.source( sourceSet.getAllJava().getSrcDirs() )
+ aptTask.destinationDir = outputDir
+ // again for JBoss Logging...
+ aptTask.classesDir = outputDir
+
+ aptTask.setSourceCompatibility( javaCompileTask.getSourceCompatibility() );
+ aptTask.setTargetCompatibility( javaCompileTask.getTargetCompatibility() );
+ aptTask.setDependencyCacheDir( javaCompileTask.getDependencyCacheDir() );
+
+ aptTask.getConventionMapping().map(
+ "classpath",
+ new Callable<FileCollection>() {
+ public FileCollection call() throws Exception {
+ return javaCompileTask.getClasspath()
+ }
+ }
+ );
+
+ aptTask.mustRunAfter( extProps.get( "sourceGeneratorsTask" ) );
+ javaCompileTask.dependsOn( aptTask );
+ project.tasks.findByName( SourceGenerationPlugin.GENERATE_SOURCES_TASK_NAME ).dependsOn( aptTask )
+
+
+ // create a FileTree representation of the APT output dir and add it to the JavaCompile task (so they get compiled)
+ final ConfigurableFileTree outputDirFileTree = project.fileTree( outputDir );
+ outputDirFileTree.builtBy( aptTask );
+ javaCompileTask.getSource().plus( outputDirFileTree );
+
+ // Add the APT output dir to the source set
+ sourceSet.getJava().srcDir( outputDir );
+ return aptTask
+ }
+
+ public void addMetaGenProcessor(SourceSet sourceSet) {
+ AnnotationProcessorOnlyTask task = getLocateProcessorOnlyTask( sourceSet )
+ task.processors += METAGEN_PROCESSOR_NAME
+ task.classpath += project.configurations[METAGEN_DEPENDENCY_CONFIG_NAME]
+ }
+}
+
+class AnnotationProcessorOnlyTask extends AbstractCompile {
+ @Input
+ def List<String> processors = new ArrayList<String>();
+ // todo : support for this? really only "used" for logging and its use is questionable
+ //private Map<String,String> processorSettings = new HashMap<String, String>();
+
+ def File dependencyCacheDir;
+ def File classesDir;
+
+ private Compiler<JavaCompileSpec> javaCompiler;
+
+ AnnotationProcessorOnlyTask() {
+ // Stolen from Gradle's Compile/JavaCompile
+ org.gradle.internal.Factory<org.gradle.api.AntBuilder> antBuilderFactory = getServices().getFactory( org.gradle.api.AntBuilder.class );
+ JavaCompilerFactory inProcessCompilerFactory = new ExpandedJavaCompilerFactory( getLogger() );
+ ProjectInternal projectInternal = (ProjectInternal) getProject();
+ CompilerDaemonManager compilerDaemonManager = getServices().get( CompilerDaemonManager.class );
+ JavaCompilerFactory defaultCompilerFactory = new DefaultJavaCompilerFactory(
+ projectInternal,
+ antBuilderFactory,
+ inProcessCompilerFactory,
+ compilerDaemonManager
+ );
+
+ // The Gradle IncrementalJavaCompiler cant be used here for various reasons
+ javaCompiler = new DelegatingJavaCompiler( defaultCompilerFactory );
+ }
+
+ @OutputDirectory
+ public File getDependencyCacheDir() {
+ return dependencyCacheDir;
+ }
+
+ public void setDependencyCacheDir(File dependencyCacheDir) {
+ this.dependencyCacheDir = dependencyCacheDir;
+ }
+
+ @Override
+ protected void compile() {
+ // see if the output dir exists
+ if ( !getDestinationDir().exists() ) {
+ // its does not - create it (javac will complain if its not there)
+ makeDirectory( getDestinationDir() );
+ }
+ else {
+ // it does - clean it
+ project.delete( getDestinationDir() )
+ makeDirectory( getDestinationDir() );
+ }
+
+ if ( !getClassesDir().exists() ) {
+ // create classes dir if not there (again, javac will complain if its not there)
+ makeDirectory( getClassesDir() );
+ }
+
+ CompileOptions compileOptions = new CompileOptions();
+
+ Collections.addAll(
+ compileOptions.getCompilerArgs(),
+ "-nowarn",
+ "-proc:only",
+ "-encoding", "UTF-8",
+ "-s", getDestinationDir().getAbsolutePath(),
+ "-processor", processors.join( "," )
+
+ );
+
+ DefaultJavaCompileSpec spec = new DefaultJavaCompileSpec();
+ spec.setSource( getSource() );
+ // jboss logging needs this :(
+ spec.setDestinationDir( getClassesDir() );
+ spec.setClasspath( getClasspath() );
+ spec.setDependencyCacheDir( dependencyCacheDir );
+ spec.setSourceCompatibility( getSourceCompatibility() );
+ spec.setTargetCompatibility( getTargetCompatibility() );
+ spec.setCompileOptions( compileOptions );
+
+ WorkResult result = javaCompiler.execute( spec );
+ setDidWork( result.getDidWork() );
+ }
+
+ @SuppressWarnings("ResultOfMethodCallIgnored")
+ private static void makeDirectory(File directory) {
+ directory.mkdirs();
+ }
+}
+
+/**
+ * Implementation of the Gradle JavaCompilerFactory contract generating {@link ExpandedJdk6JavaCompiler} instances
+ */
+class ExpandedJavaCompilerFactory implements JavaCompilerFactory {
+ private final Logger logger;
+
+ public ExpandedJavaCompilerFactory(Logger logger) {
+ //To change body of created methods use File | Settings | File Templates.
+ this.logger = logger;
+ }
+
+ @Override
+ public Compiler<JavaCompileSpec> create(CompileOptions options) {
+ return new ExpandedJdk6JavaCompiler( logger );
+ }
+}
+
+/**
+ * Extension of Gradle's Jdk6JavaCompiler to add DiagnosticListener for diagnostic message mapping and APT support
+ */
+public class ExpandedJdk6JavaCompiler extends Jdk6JavaCompiler {
+ private final Logger logger;
+
+ public ExpandedJdk6JavaCompiler(Logger logger) {
+ this.logger = logger;
+ }
+
+ public WorkResult execute(JavaCompileSpec spec) {
+ logger.info( "Compiling with JDK Java compiler API." );
+
+ final DiagnosticListenerImpl diagnosticListener = new DiagnosticListenerImpl( logger );
+ final JavaCompiler.CompilationTask task = createCompileTask( spec, diagnosticListener );
+ boolean success = task.call();
+ if ( !success || diagnosticListener.sawError() ) {
+ throw new CompilationFailedException();
+ }
+
+ return new SimpleWorkResult( true );
+ }
+
+ private static JavaCompiler.CompilationTask createCompileTask(
+ JavaCompileSpec spec,
+ DiagnosticListenerImpl diagnosticListener) {
+ List<String> options = new JavaCompilerArgumentsBuilder(spec).build();
+ JavaCompiler compiler = findCompiler();
+ if ( compiler == null ) {
+ throw new RuntimeException("Cannot find System Java Compiler. Ensure that you have installed a JDK (not just a JRE) and configured your JAVA_HOME system variable to point to the according directory.");
+ }
+ CompileOptions compileOptions = spec.getCompileOptions();
+ StandardJavaFileManager fileManager = compiler.getStandardFileManager(
+ null,
+ null,
+ compileOptions.getEncoding() != null
+ ? Charset.forName( compileOptions.getEncoding() )
+ : null
+ );
+ Iterable<? extends JavaFileObject> compilationUnits = fileManager.getJavaFileObjectsFromFiles(spec.getSource());
+ return compiler.getTask(null, null, diagnosticListener, options, null, compilationUnits);
+ }
+
+
+ private static class DiagnosticListenerImpl implements DiagnosticListener<JavaFileObject> {
+ private final Logger logger;
+
+ public DiagnosticListenerImpl(Logger logger) {
+ this.logger = logger;
+ }
+
+ @Override
+ public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
+ switch ( diagnostic.getKind() ) {
+ case Diagnostic.Kind.ERROR:
+ logger.debug( "[ERROR] : " + diagnostic.toString() );
+ break;
+ case Diagnostic.Kind.WARNING:
+ logger.debug( "[WARNING] : " + diagnostic.toString() );
+ break;
+ case Diagnostic.Kind.MANDATORY_WARNING:
+ logger.debug( "[MANDATORY_WARNING] : " + diagnostic.toString() );
+ break;
+ case Diagnostic.Kind.NOTE:
+ logger.debug( "[NOTE] : " + diagnostic.toString() );
+ break;
+ case Diagnostic.Kind.OTHER:
+ logger.debug( "[OTHER] : " + diagnostic.toString() );
+ break
+ default:
+ logger.debug( "[UNKNOWN] : " + diagnostic.toString() );
+ break;
+ }
+ }
+
+ public boolean sawError() {
+ // technically ERROR diagnostics should end the compile cycle, but since we are just generating
+ // sources here we ignore errors for now (expecting the later compilation task to report them
+ // if still valid)
+ return false;
+ }
+ }
+
+ private static JavaCompiler findCompiler() {
+ File realJavaHome = Jvm.current().getJavaHome();
+ File javaHomeFromToolProvidersPointOfView = new File(System.getProperty("java.home"));
+ if (realJavaHome.equals(javaHomeFromToolProvidersPointOfView)) {
+ return ToolProvider.getSystemJavaCompiler();
+ }
+
+ System.setProperty("java.home", realJavaHome.getAbsolutePath());
+ try {
+ return ToolProvider.getSystemJavaCompiler();
+ } finally {
+ System.setProperty("java.home", javaHomeFromToolProvidersPointOfView.getAbsolutePath());
+ }
+ }
+}
View
4 tooling/hibernate-gradle-plugin/hibernate-gradle-plugin.gradle
@@ -8,4 +8,8 @@ dependencies {
compile( libraries.javassist )
compile gradleApi()
compile localGroovy()
+}
+
+def boolean needsLoggingGeneration() {
+ return false;
}
View
4 tooling/hibernate-maven-plugin/hibernate-maven-plugin.gradle
@@ -12,3 +12,7 @@ dependencies {
compile( libraries.jpa )
compile( libraries.javassist )
}
+
+def boolean needsLoggingGeneration() {
+ return false;
+}
View
7 tooling/metamodel-generator/hibernate-jpamodelgen.gradle
@@ -64,10 +64,11 @@ task jaxb {
}
}
}
-compileJava.dependsOn jaxb
+runSourceGenerators.dependsOn jaxb
checkstyleMain.exclude '**/jaxb/**'
-
-
+def boolean needsLoggingGeneration() {
+ return false;
+}
View
30 utilities.gradle
@@ -1,32 +1,8 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2013, Red Hat Inc. or third-party contributors as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Inc.
- *
- * This copyrighted material is made available to anyone wishing to use, modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA 02110-1301 USA
- */
-
apply plugin: UtilitiesPlugin
-class UtilitiesPlugin implements Plugin {
- def void apply(Object project) {
+class UtilitiesPlugin implements Plugin<Project> {
+ def void apply(Project project) {
project.convention.plugins.utilities = new UtilitiesPluginDef()
}
}
@@ -46,4 +22,4 @@ class UtilitiesPluginDef {
}
throw new RuntimeException( "ugh" );
}
-}
+}
Please sign in to comment.
Something went wrong with that request. Please try again.