Hi guys,
I'm facing an issue when I run a plugin in Eclipse Indigo/Helios.
This plugin works perfectly in Eclipse Galileo.
The plugin itself just call an ant build that is in the local box filesystem thru AntRunner class. This build file uses a custom task that create in runtime other tasks. I worked in a simple example in order to exemplify better the situation:
Custom Task:
package com.test;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.RuntimeConfigurable;
import org.apache.tools.ant.Target;
import org.apache.tools.ant.Task;
public class Ant extends Task {
@Override
public void execute() throws BuildException {
Task task = this.getProject().createTask("copy");
RuntimeConfigurable rc = new RuntimeConfigurable(task, task.getTaskName());
rc.setAttribute("file", "/temp/file1.txt");
rc.setAttribute("todir", "/temp/folder1");
Target target = new Target();
target.addTask(task);
target.execute();
super.execute();
}
}
The code above is used to generate the jar file used by build.xml below as custom a task:
Build.xml
<?xml version="1.0"?>
<project name="SimpleAntTask" default="test" basedir=".">
<taskdef name="test" classname="com.test.Ant">
<classpath>
<pathelement location="${file.separator}temp${file.separator}simple_ant_test_1.0.0.jar"/>
</classpath>
</taskdef>
<target name="test">
<test/>
</target>
</project>
So far so good. Both Build.xml and simple_ant_test_1.0.0.jar are in temp folder and working fine.
The issue started when I tried to run it thru an Eclipse Plugin. The caller build.xml code is described below:
package com.test;
import java.util.HashMap;
import org.eclipse.ant.core.AntRunner;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.CoreException;
public class SimpleAntTestHandler extends AbstractHandler {
private static String CUSTOM_BUILD_XML_FILE = "/temp/build.xml";
private static String BUILD_XML_TARGET = "test";
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
try {
AntRunner runner = new AntRunner();
runner.setBuildFileLocation(CUSTOM_BUILD_XML_FILE);
runner.setExecutionTargets(new String[] { BUILD_XML_TARGET });
runner.run();
} catch (CoreException e) {
e.printStackTrace();
}
return null;
}
}
When this plugin is executed (in a simple eclipse menu) a NullPointerExcpetion is thrown. In order to go deeper debuging the code I've included the Ant source code and I figured out that the real exception is an InvocationTargetException.
Does someone know what was the changes on Eclipse that can be caused such different behavior on it?
Any help will be extremely appreciated.
Merry Christimas and Happy New 2012
--
Raphael Moita