From 77a4c3e52e3b1a369ba8031dcce8e3ea7f7b7e11 Mon Sep 17 00:00:00 2001 From: Gunnar Morling Date: Fri, 3 May 2013 12:33:40 +0200 Subject: [PATCH] HHH-8219 - Adding Animal Sniffer plug-in to make sure only Java 6 APIs are used --- build.gradle | 26 ++++++++++++++++++++++++-- libraries.gradle | 6 ++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 8788526015..1b254557ae 100644 --- a/build.gradle +++ b/build.gradle @@ -105,6 +105,8 @@ subprojects { subProject -> configurations { all*.exclude group: 'xml-apis', module: 'xml-apis' } + animalSniffer + javaApiSignature } // appropriately inject the common dependencies into each sub-project @@ -133,6 +135,9 @@ subprojects { subProject -> } jaxb( libraries.jaxb2_basics ) jaxb( libraries.jaxb2_ant ) + + animalSniffer ( libraries.animal_sniffer ) + javaApiSignature ( libraries.java16_signature ) } // mac-specific stuff ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -308,8 +313,25 @@ subprojects { subProject -> } } - // eclipseClasspath will not add sources to classpath unless the dirs actually exist. - eclipseClasspath.dependsOn("generateSources") + // eclipseClasspath will not add sources to classpath unless the dirs actually exist. + eclipseClasspath.dependsOn("generateSources") + + task copyJavaApiSignature(type: Copy) { + from configurations.javaApiSignature + into "$buildDir/javaApiSignature/" + rename '.*signature', 'javaApi.signature' + } + + // checks that only types of the target Java version are used + task checkJavaApiSignature << { + ant.taskdef(name: 'animalSniffer', classname: 'org.codehaus.mojo.animal_sniffer.ant.CheckSignatureTask', classpath: configurations.animalSniffer.asPath) + ant.animalSniffer(signature: "$buildDir/javaApiSignature/javaApi.signature", classpath: configurations.compile.asPath + System.properties.'path.separator' + configurations.provided.asPath) { + path(path: "$buildDir/classes/main") + } + } + checkJavaApiSignature.dependsOn compileJava + checkJavaApiSignature.dependsOn copyJavaApiSignature + check.dependsOn checkJavaApiSignature // specialized API/SPI checkstyle tasks ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ task checkstylePublicSources(type: Checkstyle) { diff --git a/libraries.gradle b/libraries.gradle index b08e0eefb8..62da4c0b02 100644 --- a/libraries.gradle +++ b/libraries.gradle @@ -67,6 +67,12 @@ ext { jaxb: 'com.sun.xml.bind:jaxb-xjc:2.1.6', jaxb2_basics: 'org.jvnet.jaxb2_commons:jaxb2-basics:0.6.0', jaxb2_ant: 'org.jvnet.jaxb2_commons:jaxb2-basics-ant:0.6.0', + + // Animal Sniffer Ant Task and Java 1.6 API signature file + // not using 1.9 for the time being due to MANIMALSNIFFER-34 + animal_sniffer: 'org.codehaus.mojo:animal-sniffer-ant-tasks:1.8', + java16_signature: 'org.codehaus.mojo.signature:java16:1.0@signature', + // ~~~~~~~~~~~~~~~~~~~~~~~~~~ testing // logging for testing