Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » create ANT builder programmatically
create ANT builder programmatically [message #329829] Mon, 07 July 2008 14:37 Go to next message
Eclipse UserFriend
Originally posted by: aurelrunner.hotmail.com

Hello,

I want to create programmatically an ANT builder.
The same as right click on project node-> properties -> builders -> new...
-> ANT builder

I can add a builder with :
private void addBuilder(IProject project, String id) {

IProjectDescription desc;
try {
desc = project.getDescription();

ICommand[] commands = desc.getBuildSpec();
for (int i = 0; i < commands.length; ++i)
if (commands[i].getBuilderName().equals(id))
return;
//add builder to project
ICommand command = desc.newCommand();
command.setBuilderName(id);
ICommand[] nc = new ICommand[commands.length + 1];
// Add it before other builders.
System.arraycopy(commands, 0, nc, 1, commands.length);
nc[0] = command;
desc.setBuildSpec(nc);
project.setDescription(desc, null);
} catch (CoreException e) {
e.printStackTrace();
}

but i've a missing builder when I look at right click on project node->
properties -> builders

thanks for any help
Re: create ANT builder programmatically [message #330243 is a reply to message #329829] Tue, 22 July 2008 18:28 Go to previous messageGo to next message
Darin Swanson is currently offline Darin SwansonFriend
Messages: 2386
Registered: July 2009
Senior Member
See the implementation details within
org.eclipse.ui.externaltools.internal.ui.BuilderPropertyPage which is part
of the org.eclipse.ui.externaltools plug-in.

Sorry for the delay in a response.
Darins
http://runnerwhocodes.blogspot.com

"Aurelien P." <aurelrunner@hotmail.com> wrote in message
news:e71c419c29662dabd1e799539e5ea642$1@www.eclipse.org...
> Hello,
>
> I want to create programmatically an ANT builder. The same as right click
> on project node-> properties -> builders -> new... -> ANT builder
>
> I can add a builder with :
> private void addBuilder(IProject project, String id) {
>
> IProjectDescription desc;
> try {
> desc = project.getDescription();
>
> ICommand[] commands = desc.getBuildSpec();
> for (int i = 0; i < commands.length; ++i)
> if (commands[i].getBuilderName().equals(id))
> return;
> //add builder to project
> ICommand command = desc.newCommand();
> command.setBuilderName(id);
> ICommand[] nc = new ICommand[commands.length + 1];
> // Add it before other builders.
> System.arraycopy(commands, 0, nc, 1, commands.length);
> nc[0] = command;
> desc.setBuildSpec(nc);
> project.setDescription(desc, null);
> } catch (CoreException e) {
> e.printStackTrace();
> }
>
> but i've a missing builder when I look at right click on project node->
> properties -> builders
>
> thanks for any help
>
Re: create ANT builder programmatically [message #330443 is a reply to message #330243] Tue, 29 July 2008 09:46 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: aurelrunner.hotmail.com

Hi,

So I'm here :

AntLaunchShortcut antLS = new AntLaunchShortcut();
ILaunchConfiguration ilct = antLS
createDefaultLaunchConfiguration(iPathOfBuildFile, iProject);
ICommand commandToAdd;
commandToAdd = BuilderUtils.toBuildCommand(project, ilct, commandToAdd);


and I have this error :

java.lang.NullPointerException
at
org.eclipse.ui.externaltools.internal.model.BuilderUtils.toB uildCommand(BuilderUtils.java:222)
at
org.eclipse.ui.externaltools.internal.model.BuilderUtils.com mandFromLaunchConfig(BuilderUtils.java:134)


So I look in the source code :
the error is at this line (config is an ILaunchConfiguration):
buffer.append('/').append(config.getFile().getFullPath().rem oveFirstSegments(1));

and in facts, config.getFile() return null and why?
When we look at the specification of getFile() from ILaunchConfiguration
interface, we can read :

@return the file this launch configuration is stored
in, or <code>null</code> if this configuration is stored
locally with the workspace

... it seems that my file is stored in the workspace...
But what is exactly this file?
I'm not sure, is it the buildfile?

So I don't know how to create the command correctly...

thanks for your help
Re: create ANT builder programmatically [message #330525 is a reply to message #330443] Thu, 31 July 2008 13:34 Go to previous message
Eclipse UserFriend
Originally posted by: aurelrunner.hotmail.com

Hi again,

I can add builder!! (youpi)
But I have issues with classpath.

So, first I add a builder with the following code:


/*create a ILaunchConfigurationWorkingCopy*/
ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
ILaunchConfigurationType antType =
launchManager.getLaunchConfigurationType(IAntLaunchConfigura tionConstants.ID_ANT_LAUNCH_CONFIGURATION_TYPE);
String name = launchManager
.generateUniqueLaunchConfigurationNameFrom(
aProject.getName());
ILaunchConfigurationWorkingCopy workingCopy =
antType.newInstance(BuilderUtils.getBuilderFolder(aProject, true), name);

/*add it parameters, all are not needed*/

workingCopy.setAttribute( DebugPlugin.ATTR_CAPTURE_OUTPUT, true);
workingCopy.setAttribute( IExternalToolConstants.ATTR_SHOW_CONSOLE,
true);
workingCopy.setAttribute(IAntLaunchConfigurationConstants.AT TR_TARGETS_UPDATED,
true);
workingCopy.setAttribute("org.eclipse.ant.ui.DEFAULT_VM_INSTALL ", true);
workingCopy.setAttribute(IExternalToolConstants.ATTR_RUN_BUI LD_KINDS,
"auto,full,incremental");
workingCopy.setAttribute(IExternalToolConstants.BUILD_TYPE_A UTO, true);
workingCopy.setAttribute(IExternalToolConstants.BUILD_TYPE_F ULL, true);
workingCopy.setAttribute(IExternalToolConstants.BUILD_TYPE_I NCREMENTAL,
true);

workingCopy.setAttribute( IExternalToolConstants.ATTR_LOCATION,
aProject.getLocation().append("build.xml").toOSString());

workingCopy.setAttribute( IExternalToolConstants.ATTR_WORKING_DIRECTORY,
aProject.getLocation().toOSString());


workingCopy.setAttribute( IDebugUIConstants.ATTR_LAUNCH_IN_BACKGROUND,
false);

workingCopy.setAttribute(IAntLaunchConfigurationConstants.AT TR_ANT_PROPERTIES,
new Properties()/*userProperties*/);
workingCopy.setAttribute(IJavaLaunchConfigurationConstants.A TTR_DEFAULT_CLASSPATH,
true);

/**
*and add the classpath that is taken from the project classpath
**/
/*get the classpath project*/
ArrayList<String> array = new ArrayList();
IClasspathEntry[] ices = JavaCore.create(aProject).getRawClasspath();
/*I add only libraries coz I know that only libraries are needed*/
for(IClasspathEntry ice : ices){
IRuntimeClasspathEntry irce = null;
int kind = ice.getEntryKind();
if(kind == IClasspathEntry.CPE_LIBRARY && ice.getPath() != null){
irce = JavaRuntime
.newArchiveRuntimeClasspathEntry(ice.getPath().makeAbsolute( ));
}
array.add(irce.getMemento());
workingCopy.setAttribute(IJavaLaunchConfigurationConstants.A TTR_CLASSPATH,array);

/*save the ILaunchConfiguration*/
ILaunchConfiguration ilc = workingCopy.doSave();


/*create associate ICommand*/
IProjectDescription desc;
desc = aProject.getDescription();
ICommand[] commands = desc.getBuildSpec();
ICommand command = desc.newCommand();
command.setBuilderName("org.eclipse.ant.AntBuilderLaunchConfigurationType ");
Map<String,String> map = command.getArguments();
map.put("LaunchConfigHandle",
"<project>/.externalToolBuilders/"+name
+".launch");
command.setArguments(map);
command.setBuilderName(ilc.getName());
command.setBuilding(IncrementalProjectBuilder.FULL_BUILD, true);
command.setBuilding(IncrementalProjectBuilder.INCREMENTAL_BU ILD, true);
ICommand[] nc = new ICommand[commands.length + 1];
// Add it before other builders.
System.arraycopy(commands, 0, nc, 1, commands.length);
nc[0] = command;
desc.setBuildSpec(nc);
aProject.setDescription(desc, null);



With that, the builder is correctly create... Except for the classpath....
I can edit it with the BuilderPropertyPage.
The file .metadata/<generateName>.launch contains the good listEntry for
the archive that I want to add in the classpath listAttribute. (The same
as if I add it by the BuilderPropertyPage) but in the
BuildeerPropertyPage, there is only the default classpath...

So when I launch it, there are errors because it doesn't know the Class
that are in the archive that I want to add to his classpath... so How can
I add it?

And why it doesn't take directly the classpath of the project which launch
the ant build file??>

thanks in advance


A. Pupier wrote:

> Hi,

> So I'm here :

> AntLaunchShortcut antLS = new AntLaunchShortcut();
> ILaunchConfiguration ilct = antLS
> createDefaultLaunchConfiguration(iPathOfBuildFile, iProject);
> ICommand commandToAdd;
> commandToAdd = BuilderUtils.toBuildCommand(project, ilct, commandToAdd);


> and I have this error :

> java.lang.NullPointerException
> at
>
org.eclipse.ui.externaltools.internal.model.BuilderUtils.toB uildCommand(BuilderUtils.java:222)
> at
>
org.eclipse.ui.externaltools.internal.model.BuilderUtils.com mandFromLaunchConfig(BuilderUtils.java:134)


> So I look in the source code :
> the error is at this line (config is an ILaunchConfiguration):
>
buffer.append('/').append(config.getFile().getFullPath().rem oveFirstSegments(1));

> and in facts, config.getFile() return null and why?
> When we look at the specification of getFile() from ILaunchConfiguration
> interface, we can read :

> @return the file this launch configuration is stored
> in, or <code>null</code> if this configuration is stored
> locally with the workspace

> ... it seems that my file is stored in the workspace...
> But what is exactly this file?
> I'm not sure, is it the buildfile?

> So I don't know how to create the command correctly...

> thanks for your help
Previous Topic:Extension point validation
Next Topic:Key Binding confilicts in 3.4
Goto Forum:
  


Current Time: Sun Sep 01 06:31:29 GMT 2024

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

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

Back to the top