AspectJ fixes for Spring IO

This commit is contained in:
Rob Winch 2017-01-04 13:27:37 -06:00
parent b5e0886bde
commit b54d350e54
1 changed files with 29 additions and 26 deletions

View File

@ -4,12 +4,13 @@ import org.gradle.api.Project
import org.gradle.api.Plugin import org.gradle.api.Plugin
import org.gradle.api.tasks.TaskAction import org.gradle.api.tasks.TaskAction
import org.gradle.api.logging.LogLevel import org.gradle.api.logging.LogLevel
import org.gradle.api.file.FileCollection import org.gradle.api.file.*
import org.gradle.api.tasks.SourceSet import org.gradle.api.tasks.SourceSet
import org.gradle.api.DefaultTask import org.gradle.api.DefaultTask
import org.gradle.api.GradleException import org.gradle.api.GradleException
import org.gradle.api.plugins.JavaPlugin import org.gradle.api.plugins.JavaPlugin
import org.gradle.api.tasks.compile.JavaCompile
import org.gradle.plugins.ide.eclipse.GenerateEclipseProject import org.gradle.plugins.ide.eclipse.GenerateEclipseProject
import org.gradle.plugins.ide.eclipse.GenerateEclipseClasspath import org.gradle.plugins.ide.eclipse.GenerateEclipseClasspath
import org.gradle.plugins.ide.eclipse.EclipsePlugin import org.gradle.plugins.ide.eclipse.EclipsePlugin
@ -41,28 +42,25 @@ class AspectJPlugin implements Plugin<Project> {
project.configurations.create('aspectpath') project.configurations.create('aspectpath')
} }
project.tasks.create(name: 'compileAspect', overwrite: true, description: 'Compiles AspectJ Source', type: Ajc) { project.tasks.withType(JavaCompile) { javaCompileTask ->
dependsOn project.configurations*.getTaskDependencyFromProjectDependency(true, "compileJava") def javaCompileTaskName = javaCompileTask.name
def ajCompileTask = project.tasks.create(name: javaCompileTaskName + 'Aspect', overwrite: true, description: 'Compiles AspectJ Source', type: Ajc) {
inputs.files(javaCompileTask.inputs.files)
inputs.properties(javaCompileTask.inputs.properties)
dependsOn project.processResources sourceRoots.addAll(project.sourceSets.main.java.srcDirs)
sourceSet = project.sourceSets.main if(javaCompileTaskName.contains("Test")) {
inputs.files(sourceSet.allSource) sourceRoots.addAll(project.sourceSets.test.java.srcDirs)
outputs.dir(sourceSet.output.classesDir) }
compileClasspath = javaCompileTask.classpath
destinationDir = javaCompileTask.destinationDir
aspectPath = project.configurations.aspectpath aspectPath = project.configurations.aspectpath
} }
project.tasks.compileJava.deleteAllActions()
project.tasks.compileJava.dependsOn project.tasks.compileAspect
javaCompileTask.deleteAllActions()
javaCompileTask.dependsOn ajCompileTask
project.tasks.create(name: 'compileTestAspect', overwrite: true, description: 'Compiles AspectJ Test Source', type: Ajc) {
dependsOn project.processTestResources, project.compileJava, project.jar
sourceSet = project.sourceSets.test
inputs.files(sourceSet.allSource)
outputs.dir(sourceSet.output.classesDir)
aspectPath = project.files(project.configurations.aspectpath, project.jar.archivePath)
} }
project.tasks.compileTestJava.deleteAllActions()
project.tasks.compileTestJava.dependsOn project.tasks.compileTestAspect
project.tasks.withType(GenerateEclipseProject) { project.tasks.withType(GenerateEclipseProject) {
project.eclipse.project.file.whenMerged { p -> project.eclipse.project.file.whenMerged { p ->
@ -91,7 +89,9 @@ class AspectJPlugin implements Plugin<Project> {
} }
class Ajc extends DefaultTask { class Ajc extends DefaultTask {
SourceSet sourceSet Set<File> sourceRoots = []
FileCollection compileClasspath
File destinationDir
FileCollection aspectPath FileCollection aspectPath
Ajc() { Ajc() {
@ -103,15 +103,18 @@ class Ajc extends DefaultTask {
logger.info("="*30) logger.info("="*30)
logger.info("="*30) logger.info("="*30)
logger.info("Running ajc ...") logger.info("Running ajc ...")
logger.info("classpath: ${sourceSet.compileClasspath.asPath}") logger.info("classpath: ${compileClasspath?.files}")
logger.info("srcDirs $sourceSet.java.srcDirs") logger.info("srcDirs ${sourceRoots}")
ant.taskdef(resource: "org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties", classpath: project.configurations.ajtools.asPath) ant.taskdef(resource: "org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties", classpath: project.configurations.ajtools.asPath)
ant.iajc(classpath: sourceSet.compileClasspath.asPath, fork: 'true', destDir: sourceSet.output.classesDir.absolutePath, if(sourceRoots.empty) {
return
}
ant.iajc(classpath: compileClasspath.asPath, fork: 'true', destDir: destinationDir.absolutePath,
source: project.convention.plugins.java.sourceCompatibility, source: project.convention.plugins.java.sourceCompatibility,
target: project.convention.plugins.java.targetCompatibility, target: project.convention.plugins.java.targetCompatibility,
aspectPath: aspectPath.asPath, sourceRootCopyFilter: '**/*.java', showWeaveInfo: 'true') { aspectPath: aspectPath.asPath, sourceRootCopyFilter: '**/*.java', showWeaveInfo: 'true') {
sourceroots { sourceroots {
sourceSet.java.srcDirs.each { sourceRoots.each {
logger.info(" sourceRoot $it") logger.info(" sourceRoot $it")
pathelement(location: it.absolutePath) pathelement(location: it.absolutePath)
} }