Home » Eclipse Projects » Eclipse Platform » create ANT builder programmatically
create ANT builder programmatically [message #329829] |
Mon, 07 July 2008 10:37  |
Eclipse User |
|
|
|
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 #330525 is a reply to message #330443] |
Thu, 31 July 2008 09:34  |
Eclipse User |
|
|
|
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
|
|
|
Goto Forum:
Current Time: Sun May 04 16:04:50 EDT 2025
Powered by FUDForum. Page generated in 0.04363 seconds
|