forked from gboissinot/gradleplugins
/
aspectJ.gradle
55 lines (44 loc) · 1.83 KB
/
aspectJ.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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")
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:"512m", fork:"true",
aspectPath:configurations.aspects.asPath, inpath:configurations.ajInpath.asPath, sourceRootCopyFilter:"**/.svn/*,**/*.java",classpath:configurations.compile.asPath){
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)
}