HHH-8733 - General build cleanup

This commit is contained in:
Steve Ebersole 2013-12-02 20:53:19 -06:00
parent 5acd232e10
commit 055a750a53
18 changed files with 821 additions and 430 deletions

View File

@ -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,14 +106,19 @@ subprojects { subProject ->
// minimize changes, at least for now (gradle uses 'build' by default)..
buildDir = "target"
if ( ! subProject.name.startsWith( 'release' ) && ! subProject.name.startsWith( 'documentation' ) ) {
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: 'maven' // temporary, still needed for install task until bug with publishToMavenLocal task is fixed
apply plugin: 'osgi'
apply from: "${rootProject.projectDir}/utilities.gradle"
apply from: "${rootProject.projectDir}/source-generation.gradle"
// apply from: "${rootProject.projectDir}/utilities.gradle"
apply plugin: 'findbugs'
apply plugin: 'checkstyle'
@ -172,45 +188,24 @@ subprojects { subProject ->
compileClasspath += configurations.provided
}
sourceSets.all {
ext.aptGeneratedSourceDir = file( "${buildDir}/generated-src/apt/${name}" )
}
ext.standardJavacOptions = [
tasks.withType( JavaCompile.class ).all { task->
task.options.compilerArgs += [
"-nowarn",
"-proc:none",
"-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()
}
}
if ( subProject.needsLoggingGeneration() ) {
addLoggingProcessor( sourceSets.main )
}
task generateSources(type: Task)
final SourceSet metaGenSourceSet = subProject.getMetaGenTargetSourceSet();
if ( metaGenSourceSet != null ) {
addMetaGenProcessor( metaGenSourceSet )
}
jar {
manifest = osgiManifest {
@ -230,7 +225,7 @@ subprojects { subProject ->
'*'
instruction 'Bundle-Vendor', 'Hibernate.org'
instruction 'Bundle-Description', osgiDescription()
instruction 'Bundle-Description', subProject.osgiDescription()
instruction 'Implementation-Url', 'http://hibernate.org'
instruction 'Implementation-Version', version
instruction 'Implementation-Vendor', 'Hibernate.org'
@ -292,7 +287,7 @@ subprojects { subProject ->
// 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")
eclipseClasspath.dependsOn generateSources
// Animal Sniffer ~~~~~~~~~~~~~~~~~~
@ -463,8 +458,6 @@ subprojects { subProject ->
from sourceSets.main.allSource
classifier = 'sources'
}
}
}
task release(type: Task, dependsOn: 'release:release')

View File

@ -20,7 +20,7 @@ buildscript {
apply plugin: "java"
apply plugin: "jdocbook"
apply from: "../utilities.gradle"
apply from: "${rootProject.projectDir}/utilities.gradle"
defaultTasks 'buildDocs'
@ -74,21 +74,22 @@ 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 ( ['release','documentation'].contains( subProject.name ) ) {
return;
}
// we only care about the main SourceSet...
source subProject.sourceSets.main.java
if( classpath ) {
classpath += sourceSet.output + sourceSet.compileClasspath
classpath += subProject.sourceSets.main.output + subProject.sourceSets.main.compileClasspath
}
else {
classpath = sourceSet.output + sourceSet.compileClasspath
classpath = subProject.sourceSets.main.output + subProject.sourceSets.main.compileClasspath
}
sourceSet.java.each { javaFile ->
final String packageName = determinePackageName( sourceSet.java, javaFile );
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 );
}
@ -103,9 +104,6 @@ task aggregateJavadocs(type: Javadoc) {
}
}
}
}
}
}
// apply standard config
maxMemory = '512m'

View File

@ -17,3 +17,7 @@ def pomName() {
def pomDescription() {
return 'Integration for c3p0 Connection pooling into Hibernate O/RM'
}
def osgiDescription() {
return pomDescription()
}

View File

@ -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 File

@ -30,6 +30,7 @@ import java.util.Properties;
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,7 +102,8 @@ public abstract class BasicConnectionCreator implements ConnectionCreator {
new ValueHolder.DeferredInitializer<SQLExceptionConversionDelegate>() {
@Override
public SQLExceptionConversionDelegate initialize() {
return new SQLStateConversionDelegate(
return new SQLExceptionConversionDelegate() {
private final SQLStateConversionDelegate sqlStateDelegate = new SQLStateConversionDelegate(
new ConversionContext() {
@Override
public ViolatedConstraintNameExtracter getViolatedConstraintNameExtracter() {
@ -110,6 +112,18 @@ public abstract class BasicConnectionCreator implements ConnectionCreator {
}
}
);
@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 File

@ -70,7 +70,7 @@ public class ConnectionCreatorTest extends BaseUnitTestCase {
return super.getService( serviceRole );
}
},
"jdbc:h2:???:bad-url",
"jdbc:h2:mem:test-bad-urls;nosuchparam=saywhat",
new Properties(),
false,
null

View File

@ -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 File

@ -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 File

@ -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 File

@ -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 File

@ -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 File

@ -11,3 +11,7 @@ def pomName() {
def pomDescription() {
return 'Integration for Proxool Connection pooling into Hibernate O/RM'
}
def osgiDescription() {
return pomDescription()
}

View File

@ -26,3 +26,7 @@ def pomDescription() {
def osgiDescription() {
return pomDescription()
}
def boolean needsLoggingGeneration() {
return false;
}

385
source-generation.gradle Normal file
View File

@ -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 File

@ -9,3 +9,7 @@ dependencies {
compile gradleApi()
compile localGroovy()
}
def boolean needsLoggingGeneration() {
return false;
}

View File

@ -12,3 +12,7 @@ dependencies {
compile( libraries.jpa )
compile( libraries.javassist )
}
def boolean needsLoggingGeneration() {
return false;
}

View File

@ -64,10 +64,11 @@ task jaxb {
}
}
}
compileJava.dependsOn jaxb
runSourceGenerators.dependsOn jaxb
checkstyleMain.exclude '**/jaxb/**'
def boolean needsLoggingGeneration() {
return false;
}

View File

@ -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()
}
}