Using ant from within Eclipse Plugin [message #305107] |
Thu, 22 June 2006 21:41 |
Eclipse User |
|
|
|
Originally posted by: peyush_jain.hotmail.com
Hi,
I want to create an action delegate which will create and copy some
folders/files from my plugin to the project. Is there any other way to
do this besides going through the ant route?
I have the following build.xml file and the calling code:
<project name="HelloWorld" default="create" basedir=".">
<property name="test" location="TEST"/>
<target name="create">
<echo>Making dir...</echo>
<mkdir dir="${test}"/>
<eclipse.refreshLocal resource="HelloWorld" depth="infinite"/>
</target>
</project>
-------------------------
private static final String ANT_LOGGER_CLASS =
" org.eclipse.ant.internal.ui.antsupport.logger.AntProcessBuil dLogger ";
AntRunner runner = new AntRunner();
runner.setBuildFileLocation("C:/Eclipse3.1/workspace/Plugin/resources/ant/build.xml ");
runner.setArguments("-Dmessage=Building -verbose");
runner.addBuildLogger(ANT_LOGGER_CLASS);
try{
runner.run(monitor);
}
catch (CoreException e){
e.printStackTrace();
}
------------------------------
Questions:
1) I know build.xml is getting processed but the new directory is not
created. Any ideas why? How can I display the echo message on console?
2) Do I have to add org.eclipse.ant.core.antTasks extension and create a
Task class in order to do this or can I simply run mkdir task in
build.xml by calling the script?
3) Can you please explain the classloader issue between plugin and ant?
PJ
|
|
|
|
Re: Using ant from within Eclipse Plugin [message #305151 is a reply to message #305129] |
Fri, 23 June 2006 22:14 |
Eclipse User |
|
|
|
Originally posted by: peyush_jain.hotmail.com
Thanks Paul. That worked. I did the following to get it to work (for
someone who might want to solve the same problem)
I am still curious about the ant route. If anyone knows how to do it,
please let me know.
------------------------------------------------------------ ----------
IProject project = ...;
URL url =
CfePlugin.getDefault().getBundle().getEntry("/templates/setvars.sh ");
InputStream is = url.openStream();
IFolder folder = project.getFolder("/templates");
if(!folder.exists()){
try{
folder.create(true, true, null);
}
catch (CoreException e){
e.printStackTrace();
}
}
IFile f = folder.getFile("temp.xml");
f.create(is, true, null);
is.close();
------------------------------------------------------------ ----------
Paul Webster wrote:
> Peyush Jain wrote:
>> Hi,
>>
>> I want to create an action delegate which will create and copy some
>> folders/files from my plugin to the project. Is there any other way to
>> do this besides going through the ant route?
>
> Assuming your action can get the IProject from the ISelection somehow:
>
> Use
> MyPlugin.getDefault().getBundle().getEntry("/templates/file.template ")
> to get a URL to your file in your plugin.
>
> Use IFolder/IFile to create your project resources.
>
> Use IFile#setContents(*) and give it the InputStream from the URL.
>
> Later,
> PW
|
|
|
Powered by
FUDForum. Page generated in 0.02983 seconds