[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
|
[news.eclipse.tools] Re: getBuildSpec() seems not working as described
|
The description returned from IProject#getDescription is a copy of the
original so the changes that you made weren't reflected in the project. Try
re-setting the description on the project using IProject#setDescription,
passing the modified description with your new build spec. Then the next
time you call IProject#getDescription, it should be the modified description
with your changes.
dj
"Lun Xiao" <xiao@xxxxxxxxxx> wrote in message
news:9bf48e$24r$1@xxxxxxxxxxxxxxxx
> I use the following code to set a builder to a project and then retrieve
> the builder immediately. However, the buildSpec returned in empty. This
> code worked on previous driver. So can someone please tell me why?
> private void addToBuildSpec(IProject project) throws CoreException {
>
> IProjectDescription desp = project.getDescription();
> ICommand[] commands = desp.getBuildSpec();
>
> boolean found = false;
>
> for (int i = 0; i < commands.length; ++i) {
> if (commands[i].getBuilderName().equals(BUILDER_ID)) {
> found = true;
> break;
> }
> }
>
> if (!found) { //add builder to project
> ICommand command = desp.newCommand();
> command.setBuilderName(BUILDER_ID);
> ICommand[] newCommands = new ICommand[commands.length + 1];
>
> // Add it before other builders.
> System.arraycopy(commands, 0, newCommands, 1, commands.length);
> newCommands[0] = command;
> desp.setBuildSpec(newCommands);
> System.out.println("< + Readme Builder Added ----------->");
> }
>
> //SUPPOSELY THE BUILDER IS ADDED. THE FOLLOWING CODE RETRIEVE IT
> //BUT THE oldcommands RETURNED IS OF LENGHT 0.
> ICommand[] oldcommands = project.getDescription().getBuildSpec();
>
> // Show current Project
> System.out.println("> Selection: " + project);
>
> // List existing builders
> for (int i = 0; i < oldcommands.length; ++i) {
> System.out.println("> Builder: " + oldcommands[i].getBuilderName());
> }
> }
>
>