Posted By:
Avian
Posted On:
Saturday, December 22, 2012 07:06 AM
Hello, I have some problems with ANT. First a short description of my project. I've written a programm to analyse sourcecode and I'm using the CompilationUnitTree given by the Java lib tools.jar. Everything works fine, so I thought about an ant task. Here is my build.xml: <?xml version="1.0"?> <project default="main"> <taskdef name="banElements" classname="com.tools.scs.routines.BanElements"/> <target name="main"> <banElements banned="IF,FOR,SWITCH,WHILE,VARIABLE[type!=int]" filename="D:/Studium/Bachelor-Thesis/src/Farbe.java" /> </target>
More>>
Hello,
I have some problems with ANT.
First a short description of my project.
I've written a programm to analyse sourcecode and I'm using the CompilationUnitTree given by the Java lib tools.jar.
Everything works fine, so I thought about an ant task.
Here is my build.xml:
<?xml version="1.0"?>
<project default="main">
<taskdef name="banElements" classname="com.tools.scs.routines.BanElements"/>
<target name="main">
<banElements banned="IF,FOR,SWITCH,WHILE,VARIABLE[type!=int]" filename="D:/Studium/Bachelor-Thesis/src/Farbe.java" />
</target>
</project>
banElements should print a message if one the banned Elements appears in the sourcecode.
Works fine without using ant.
Here is the error I get with ant:
D:\Studium\Bachelor-Thesis\Project\buildtest.xml:8: java.lang.ClassCastException
: com.sun.tools.javac.api.JavacTaskImpl cannot be cast to com.sun.tools.javac.ap
i.JavacTaskImpl
at com.tools.scs.SourceCodeSelector.generateTree(SourceCodeSelector.java
:146)
at com.tools.scs.SourceCodeSelector.<init>(SourceCodeSelector.java:32)
at com.tools.scs.routines.BanElements.setFilename(BanElements.java:50)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.tools.ant.IntrospectionHelper$AttributeSetter.setObject(In
trospectionHelper.java:1498)
at org.apache.tools.ant.IntrospectionHelper.setAttribute(IntrospectionHe
lper.java:405)
at org.apache.tools.ant.RuntimeConfigurable.maybeConfigure(RuntimeConfig
urable.java:403)
at org.apache.tools.ant.RuntimeConfigurable.maybeConfigure(RuntimeConfig
urable.java:346)
at org.apache.tools.ant.Task.maybeConfigure(Task.java:202)
at org.apache.tools.ant.UnknownElement.configure(UnknownElement.java:196
)
at org.apache.tools.ant.UnknownElement.maybeConfigure(UnknownElement.jav
a:163)
at org.apache.tools.ant.Task.perform(Task.java:347)
at org.apache.tools.ant.Target.execute(Target.java:392)
at org.apache.tools.ant.Target.performTasks(Target.java:413)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExe
cutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
at org.apache.tools.ant.Main.runBuild(Main.java:811)
at org.apache.tools.ant.Main.startAnt(Main.java:217)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
Total time: 0 seconds
Here is the method were the error occurs:
private void generateTree() throws IOException {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
Iterable<? extends JavaFileObject> fileObjects = fileManager
.getJavaFileObjectsFromStrings(Arrays.asList(this.srcFile));
JavacTaskImpl javacTask = (JavacTaskImpl) compiler.getTask(null, null, null, null, null, fileObjects);
SourcePositions sourcePositions = Trees.instance(javacTask).getSourcePositions();
for (CompilationUnitTree tree : javacTask.parse()) {
this.srcCodeTree = new SourceScanner(sourcePositions).scan(tree);
}
}
Hope there is someone how can help me with this problem, thanks!!!
<<Less