throw new IllegalArgumentException("Wizard with id '" + id + "' not found.");
}
}
public static void addBuilder(IProject project, String id) throws CoreException {
final IProject fProject = project;
final String fId = id;
IWorkspaceRunnable operation = new IWorkspaceRunnable() {
public void run(IProgressMonitor monitor) throws CoreException {
if (fProject.isAccessible()) {
ResourceAttributes attribs = fProject.getResourceAttributes();
if (attribs != null && attribs.isReadOnly()) {
attribs.setReadOnly(false);
fProject.setResourceAttributes(attribs);
}
IProjectDescription desc = fProject.getDescription();
ICommand[] commands = desc.getBuildSpec();
for (int i = 0; i < commands.length; ++i) {
if (commands[i].getBuilderName().equals(fId))
return;
}
//add builder to project
ICommand command = desc.newCommand();
command.setBuilderName(fId);
ICommand[] nc = new ICommand[commands.length + 1];
// Add it after all other builders.
System.arraycopy(commands, 0, nc, 0, commands.length);
nc[commands.length] = command;
desc.setBuildSpec(nc);
fProject.setDescription(desc, null);
}
}
};
ResourcesPlugin.getWorkspace().run(operation, null);