Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Using ant from within Eclipse Plugin
Using ant from within Eclipse Plugin [message #305107] Thu, 22 June 2006 21:41 Go to next message
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 #305129 is a reply to message #305107] Fri, 23 June 2006 11:22 Go to previous messageGo to next message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

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


Re: Using ant from within Eclipse Plugin [message #305151 is a reply to message #305129] Fri, 23 June 2006 22:14 Go to previous message
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
Previous Topic:No notification of PRE_BUILD for INCREMENTAL_BUILD
Next Topic:selectionChanged and lazy loading
Goto Forum:
  


Current Time: Wed Sep 24 04:49:15 GMT 2014

Powered by FUDForum. Page generated in 0.02194 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software