/* Headless build files */
HeadlessBuildManager headlessBuildManager = Plugin.getDefault().getHeadlessBuildManager();
Set<String> enabledPlugins = new BndPreferences().getHeadlessBuildPluginsEnabled(headlessBuildManager, null);
IProject iProject = project.getProject();
IProjectDescription description = iProject.getDescription();
String[] natures = description.getNatureIds();
for (int i = 0; i < natures.length; ++i) {
if (BndtoolsConstants.NATURE_ID.equals(natures[i])) {
// Remove the nature
String[] newNatures = new String[natures.length - 1];
System.arraycopy(natures, 0, newNatures, 0, i);
System.arraycopy(natures, i + 1, newNatures, i, natures.length - i - 1);
description.setNatureIds(newNatures);
iProject.setDescription(description, null);
/* Remove the headless build files */
headlessBuildManager.setup(enabledPlugins, false, iProject.getLocation().toFile(), false, enabledIgnorePlugins);
/* refresh the project; files were created outside of Eclipse API */
iProject.refreshLocal(IResource.DEPTH_INFINITE, null);
return;
}
}
/* Add the headless build files */
headlessBuildManager.setup(enabledPlugins, false, iProject.getLocation().toFile(), true, enabledIgnorePlugins);
// Add the nature
ensureBndBndExists(iProject);
String[] newNatures = new String[natures.length + 1];
System.arraycopy(natures, 0, newNatures, 0, natures.length);
newNatures[natures.length] = BndtoolsConstants.NATURE_ID;
description.setNatureIds(newNatures);
iProject.setDescription(description, null);
/* refresh the project; files were created outside of Eclipse API */
iProject.refreshLocal(IResource.DEPTH_INFINITE, null);