From 5ea51f42fb97bcf51320467d2f9ea0490b4bfced Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Sat, 21 Jan 2012 13:27:14 +0100 Subject: [PATCH] Fix and refactor spring-aspects build - Fix compileTestJava issue in which test classes were not being compiled or run - Use built-in eclipse.project DSL instead of withXml closure to add AspectJ nature and builder - Rename {aspectJ=>aspects}.gradle and format source --- build.gradle | 6 ++- spring-aspects/aspectJ.gradle | 81 ----------------------------------- spring-aspects/aspects.gradle | 66 ++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 82 deletions(-) delete mode 100644 spring-aspects/aspectJ.gradle create mode 100644 spring-aspects/aspects.gradle diff --git a/build.gradle b/build.gradle index 973f38232d..b94550ebfe 100644 --- a/build.gradle +++ b/build.gradle @@ -432,7 +432,7 @@ project('spring-struts') { project('spring-aspects') { description = 'Spring Aspects' - apply from: 'aspectJ.gradle' + apply from: 'aspects.gradle' dependencies { compile project(":spring-orm") aspects project(":spring-orm") @@ -440,6 +440,10 @@ project('spring-aspects') { compile "org.aspectj:aspectjrt:1.6.8" testCompile project(":spring-test") } + eclipse.project { + natures += 'org.eclipse.ajdt.ui.ajnature' + buildCommand 'org.eclipse.ajdt.core.ajbuilder' + } } configure(rootProject) { diff --git a/spring-aspects/aspectJ.gradle b/spring-aspects/aspectJ.gradle deleted file mode 100644 index fd7e77a716..0000000000 --- a/spring-aspects/aspectJ.gradle +++ /dev/null @@ -1,81 +0,0 @@ -// Original source: https://raw.github.com/cbeams/gradleplugins/0.9-upgrade/aspectjPlugin/aspectJ.gradle -// Included locally here to avoid failure when not connected to the network. -// See http://issues.gradle.org/browse/GRADLE-1768 -apply plugin:'java' -apply plugin:'eclipse' - -configurations { - ajc - aspects - ajInpath -} - -task compileJava(dependsOn: JavaPlugin.PROCESS_RESOURCES_TASK_NAME, overwrite: true) { - dependsOn configurations.ajc.getTaskDependencyFromProjectDependency(true, "compileJava") - inputs.files(project.sourceSets.main.allSource + project.sourceSets.main.compileClasspath) - outputs.files(project.sourceSets.main.classesDir) - - doLast{ - ant.taskdef( resource:"org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties", classpath: configurations.ajc.asPath) - ant.iajc(source:sourceCompatibility, target:targetCompatibility, destDir:sourceSets.main.classesDir.absolutePath, maxmem:"1024m", fork:"true", - aspectPath:configurations.aspects.asPath, inpath:configurations.ajInpath.asPath, sourceRootCopyFilter:"**/.svn/*,**/*.java",classpath:configurations.compile.asPath, - Xlint:"ignore"){ - - sourceroots{ - sourceSets.main.java.srcDirs.each{ - pathelement(location:it.absolutePath) - } - } - } - } -} - -task compileTestJava(dependsOn: JavaPlugin.PROCESS_TEST_RESOURCES_TASK_NAME, overwrite: true) { - dependsOn configurations.ajc.getTaskDependencyFromProjectDependency(true, "compileTestJava") - inputs.files(project.sourceSets.test.allSource + project.sourceSets.test.compileClasspath) - outputs.files(project.sourceSets.test.classesDir) - - doLast{ - ant.taskdef( resource:"org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties", classpath: configurations.ajc.asPath) - ant.iajc(source:sourceCompatibility, target:targetCompatibility, destDir:sourceSets.main.classesDir.absolutePath, maxmem:"1024m", fork:"true", - aspectPath:configurations.aspects.asPath, inpath:configurations.ajInpath.asPath, sourceRootCopyFilter:"**/.svn/*,**/*.java",classpath:configurations.compile.asPath, - Xlint:"ignore"){ - - sourceroots{ - sourceSets.main.java.srcDirs.each{ - pathelement(location:it.absolutePath) - } - } - } - } - -} - -//add aspectj support for eclipse plugin -eclipseClasspath.withXml { xmlProvider -> - def classpath = xmlProvider.asNode() - def xmlparser = new XmlParser() - - configurations.aspects.files.each{ aspectsLib -> - classpath.children().findAll{ it['@path'] == aspectsLib.absolutePath }.each { - def attrs = xmlparser.createNode(it, 'attributes', [:]) - xmlparser.createNode(attrs, 'attribute', [name: 'org.eclipse.ajdt.aspectpath', value: 'true']); - } - } -} - - -eclipseProject.withXml { xmlProvider-> - def projectDescription = xmlProvider.asNode() - def xmlparser = new XmlParser() - - def builders = projectDescription.buildSpec[0] - def ajbuilder = xmlparser.createNode(builders, 'buildCommand', [:]) - xmlparser.createNode(ajbuilder, 'name', [:]).setValue('org.eclipse.ajdt.core.ajbuilder') - xmlparser.createNode(ajbuilder, 'arguments', [:]); - - def natures = projectDescription.natures[0] - def ajnature = xmlparser.createNode(null, 'nature', [:]) - ajnature.setValue('org.eclipse.ajdt.ui.ajnature'); - natures.children().add(0, ajnature) -} diff --git a/spring-aspects/aspects.gradle b/spring-aspects/aspects.gradle new file mode 100644 index 0000000000..3024a01ae6 --- /dev/null +++ b/spring-aspects/aspects.gradle @@ -0,0 +1,66 @@ +// redefine the compileJava and compileTestJava tasks in order to +// compile sources with ajc instead of javac + +configurations { + ajc + aspects + ajInpath +} + +task compileJava(overwrite: true) { + dependsOn JavaPlugin.PROCESS_RESOURCES_TASK_NAME + dependsOn configurations.ajc.getTaskDependencyFromProjectDependency(true, "compileJava") + + def outputDir = project.sourceSets.main.output.classesDir + + inputs.files(project.sourceSets.main.allSource + project.sourceSets.main.compileClasspath) + outputs.dir outputDir + + doLast{ + ant.taskdef(resource: "org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties", + classpath: configurations.ajc.asPath) + + ant.iajc(source: sourceCompatibility, target: targetCompatibility, + maxmem: "1024m", fork: "true", Xlint: "ignore", + destDir: outputDir.absolutePath, + aspectPath: configurations.aspects.asPath, + inpath: configurations.ajInpath.asPath, + sourceRootCopyFilter: "**/*.java", + classpath: configurations.compile.asPath) { + sourceroots { + sourceSets.main.java.srcDirs.each { + pathelement(location:it.absolutePath) + } + } + } + } +} + +task compileTestJava(overwrite: true) { + dependsOn JavaPlugin.PROCESS_TEST_RESOURCES_TASK_NAME + dependsOn configurations.ajc.getTaskDependencyFromProjectDependency(true, "compileTestJava") + dependsOn jar + + def outputDir = project.sourceSets.test.output.classesDir + + inputs.files(project.sourceSets.test.allSource + project.sourceSets.test.compileClasspath) + outputs.dir outputDir + + doLast{ + ant.taskdef(resource: "org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties", + classpath: configurations.ajc.asPath) + + ant.iajc(source: sourceCompatibility, target: targetCompatibility, + maxmem: "1024m", fork: "true", Xlint: "ignore", + destDir: outputDir.absolutePath, + aspectPath: jar.archivePath, + inpath: configurations.ajInpath.asPath, + classpath: configurations.testRuntime.asPath + configurations.compile.asPath + jar.archivePath) { + sourceroots { + sourceSets.test.java.srcDirs.each { + pathelement(location:it.absolutePath) + } + } + } + } +}