From 5540c75ce090057faa5dda65fc78a1988e4bfd98 Mon Sep 17 00:00:00 2001 From: Doug Schaefer Date: Mon, 17 Oct 2016 21:59:41 -0400 Subject: [PATCH] Fixes to remove duplicates and invalid CMake toolchain entries. Change-Id: I1a8212945428b00d332b9f78c5a3eb81091f3fe6 --- .../core/internal/CMakeToolChainManager.java | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeToolChainManager.java b/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeToolChainManager.java index 15c42839b5d..98582f0de2c 100644 --- a/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeToolChainManager.java +++ b/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeToolChainManager.java @@ -7,6 +7,7 @@ *******************************************************************************/ package org.eclipse.cdt.cmake.core.internal; +import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; @@ -54,15 +55,21 @@ public class CMakeToolChainManager implements ICMakeToolChainManager { try { for (String childName : prefs.childrenNames()) { Preferences tcNode = prefs.node(childName); - String path = tcNode.get(PATH, "/"); //$NON-NLS-1$ - ICMakeToolChainFile file = new CMakeToolChainFile(childName, Paths.get(path)); - for (String key : tcNode.keys()) { - String value = tcNode.get(key, ""); //$NON-NLS-1$ - if (!value.isEmpty()) { - file.setProperty(key, value); + String pathStr = tcNode.get(PATH, "/"); //$NON-NLS-1$ + Path path = Paths.get(pathStr); + if (Files.exists(path) && !files.containsKey(path)) { + ICMakeToolChainFile file = new CMakeToolChainFile(childName, path); + for (String key : tcNode.keys()) { + String value = tcNode.get(key, ""); //$NON-NLS-1$ + if (!value.isEmpty()) { + file.setProperty(key, value); + } } + files.put(path, file); + } else { + tcNode.removeNode(); + prefs.flush(); } - files.put(file.getPath(), file); } } catch (BackingStoreException e) { Activator.log(e); @@ -93,6 +100,9 @@ public class CMakeToolChainManager implements ICMakeToolChainManager { @Override public void addToolChainFile(ICMakeToolChainFile file) { init(); + if (files.containsKey(file.getPath())) { + removeToolChainFile(file); + } files.put(file.getPath(), file); // save it