[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[news.eclipse.tools] getBuildSpec() seems not working as described

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());
	}
}