2011-02-16 15:57:22 +00:00
|
|
|
package aspectj
|
|
|
|
|
|
|
|
import org.gradle.api.Project
|
|
|
|
import org.gradle.api.Plugin
|
|
|
|
import org.gradle.api.tasks.TaskAction
|
|
|
|
import org.gradle.api.logging.LogLevel
|
|
|
|
import org.gradle.api.file.FileCollection
|
|
|
|
import org.gradle.api.tasks.SourceSet
|
|
|
|
import org.gradle.api.DefaultTask
|
|
|
|
import org.gradle.api.GradleException
|
|
|
|
|
2013-06-20 11:40:54 -05:00
|
|
|
import org.gradle.api.plugins.JavaPlugin
|
2011-04-27 20:21:33 -05:00
|
|
|
import org.gradle.plugins.ide.eclipse.GenerateEclipseProject
|
2011-04-27 16:21:46 +01:00
|
|
|
import org.gradle.plugins.ide.eclipse.GenerateEclipseClasspath
|
2012-11-01 16:12:41 -05:00
|
|
|
import org.gradle.plugins.ide.eclipse.EclipsePlugin
|
2011-04-27 16:21:46 +01:00
|
|
|
import org.gradle.plugins.ide.eclipse.model.BuildCommand
|
2012-06-29 12:59:22 -05:00
|
|
|
import org.gradle.plugins.ide.eclipse.model.ProjectDependency
|
2011-03-12 18:46:17 -06:00
|
|
|
|
2011-02-16 15:57:22 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @author Luke Taylor
|
|
|
|
*/
|
|
|
|
class AspectJPlugin implements Plugin<Project> {
|
|
|
|
|
2015-03-23 11:14:26 -05:00
|
|
|
void apply(Project project) {
|
|
|
|
project.plugins.apply(JavaPlugin)
|
|
|
|
|
|
|
|
if (!project.hasProperty('aspectjVersion')) {
|
|
|
|
throw new GradleException("You must set the property 'aspectjVersion' before applying the aspectj plugin")
|
|
|
|
}
|
|
|
|
|
|
|
|
if (project.configurations.findByName('ajtools') == null) {
|
|
|
|
project.configurations.create('ajtools')
|
|
|
|
project.dependencies {
|
|
|
|
ajtools "org.aspectj:aspectjtools:${project.aspectjVersion}"
|
|
|
|
optional "org.aspectj:aspectjrt:${project.aspectjVersion}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (project.configurations.findByName('aspectpath') == null) {
|
|
|
|
project.configurations.create('aspectpath')
|
|
|
|
}
|
|
|
|
|
|
|
|
project.tasks.create(name: 'compileAspect', overwrite: true, description: 'Compiles AspectJ Source', type: Ajc) {
|
|
|
|
dependsOn project.configurations*.getTaskDependencyFromProjectDependency(true, "compileJava")
|
|
|
|
|
|
|
|
dependsOn project.processResources
|
|
|
|
sourceSet = project.sourceSets.main
|
|
|
|
inputs.files(sourceSet.allSource)
|
|
|
|
outputs.dir(sourceSet.output.classesDir)
|
|
|
|
aspectPath = project.configurations.aspectpath
|
|
|
|
}
|
|
|
|
project.tasks.compileJava.deleteAllActions()
|
|
|
|
project.tasks.compileJava.dependsOn project.tasks.compileAspect
|
|
|
|
|
|
|
|
|
|
|
|
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.eclipse.project.file.whenMerged { p ->
|
|
|
|
p.natures.add(0, 'org.eclipse.ajdt.ui.ajnature')
|
|
|
|
p.buildCommands = [new BuildCommand('org.eclipse.ajdt.core.ajbuilder')]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
project.tasks.withType(GenerateEclipseClasspath) {
|
|
|
|
project.eclipse.classpath.file.whenMerged { classpath ->
|
|
|
|
def entries = classpath.entries.findAll { it instanceof ProjectDependency}.findAll { entry ->
|
|
|
|
def projectPath = entry.path.replaceAll('/','')
|
|
|
|
project.rootProject.allprojects.find{ p->
|
|
|
|
if(p.plugins.findPlugin(EclipsePlugin)) {
|
|
|
|
return p.eclipse.project.name == projectPath && p.plugins.findPlugin(AspectJPlugin)
|
|
|
|
}
|
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
entries.each { entry->
|
|
|
|
entry.entryAttributes.put('org.eclipse.ajdt.aspectpath','org.eclipse.ajdt.aspectpath')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-02-16 15:57:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class Ajc extends DefaultTask {
|
2015-03-23 11:14:26 -05:00
|
|
|
SourceSet sourceSet
|
|
|
|
FileCollection aspectPath
|
|
|
|
|
|
|
|
Ajc() {
|
|
|
|
logging.captureStandardOutput(LogLevel.INFO)
|
|
|
|
}
|
|
|
|
|
|
|
|
@TaskAction
|
|
|
|
def compile() {
|
|
|
|
logger.info("="*30)
|
|
|
|
logger.info("="*30)
|
|
|
|
logger.info("Running ajc ...")
|
|
|
|
logger.info("classpath: ${sourceSet.compileClasspath.asPath}")
|
|
|
|
logger.info("srcDirs $sourceSet.java.srcDirs")
|
|
|
|
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,
|
|
|
|
source: project.convention.plugins.java.sourceCompatibility,
|
|
|
|
target: project.convention.plugins.java.targetCompatibility,
|
|
|
|
aspectPath: aspectPath.asPath, sourceRootCopyFilter: '**/*.java', showWeaveInfo: 'true') {
|
|
|
|
sourceroots {
|
|
|
|
sourceSet.java.srcDirs.each {
|
|
|
|
logger.info(" sourceRoot $it")
|
|
|
|
pathelement(location: it.absolutePath)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-02-16 15:57:22 +00:00
|
|
|
}
|