Skip to content

Commit

Permalink
fix project creation over existing cmake4eclipse project of versions <
Browse files Browse the repository at this point in the history
4.x
  • Loading branch information
15knots committed Oct 6, 2023
1 parent 00aab09 commit 38b405d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ private IProject createIProject(final String name, final URI location, IProgress
newProject.open(subMonitor.split(25));
}
IProgressMonitor continueCreationMonitor = subMonitor.split(25);
C4ENature.addNature(newProject, SubMonitor.convert(continueCreationMonitor, "Add Project Nature", 1).split(1));
C4ENature.setNatures(newProject, SubMonitor.convert(continueCreationMonitor, "Add Project Nature", 1).split(1));

return newProject;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import org.eclipse.cdt.core.CCProjectNature;
import org.eclipse.cdt.core.CProjectNature;
import org.eclipse.cdt.managedbuilder.core.ManagedCProjectNature;
import org.eclipse.core.resources.ICommand;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
Expand All @@ -37,14 +38,15 @@ public class C4ENature implements IProjectNature {
private IProject project;

/**
* Adds the natures to the specified project.
* Sets the natures of the specified project.
*
* @throws CoreException
*/
public static void addNature(IProject project, IProgressMonitor monitor) throws CoreException {
CProjectNature.addNature(project, NATURE_ID, monitor);
CProjectNature.addCNature(project, monitor);
CCProjectNature.addCCNature(project, monitor);
public static void setNatures(IProject project, IProgressMonitor monitor) throws CoreException {
IProjectDescription description = project.getDescription();
String[] newNatures = { NATURE_ID, CProjectNature.C_NATURE_ID, CCProjectNature.CC_NATURE_ID };
description.setNatureIds(newNatures);
project.setDescription(description, monitor);
}

@Override
Expand All @@ -63,7 +65,7 @@ private void addBuilders(IProgressMonitor monitor) throws CoreException {
List<ICommand> commands = new ArrayList<>(Arrays.asList(description.getBuildSpec()));
commands.add(0, bldrCommand);

ICommand[] cmds = commands.stream().distinct().toArray(ICommand[]::new);
ICommand[] cmds = commands.stream().filter(c -> !ManagedCProjectNature.BUILDER_ID.equals(c.getBuilderName()) ). distinct().toArray(ICommand[]::new);
description.setBuildSpec(cmds);
project.setDescription(description, monitor);
}
Expand All @@ -74,7 +76,7 @@ public void deconfigure() throws CoreException {
List<ICommand> commands = new ArrayList<>(Arrays.asList(description.getBuildSpec()));
for (Iterator<ICommand> iter = commands.iterator(); iter.hasNext();) {
ICommand iCommand = iter.next();
if(Activator.BUILDER_ID.equals(iCommand.getBuilderName())) {
if (Activator.BUILDER_ID.equals(iCommand.getBuilderName())) {
iter.remove();
break;
}
Expand Down

0 comments on commit 38b405d

Please sign in to comment.