mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-11 02:55:23 +02:00
Fix removing of targets. Make sure we clear their attributes.
Change-Id: Ie2c6e4bd6168fae95db1680143d4c4cafc159369
This commit is contained in:
parent
77fda006a5
commit
c3f9546a47
2 changed files with 41 additions and 24 deletions
|
@ -12,7 +12,6 @@ import java.util.LinkedHashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IConfigurationElement;
|
import org.eclipse.core.runtime.IConfigurationElement;
|
||||||
|
@ -66,7 +65,6 @@ public class LaunchTargetManager implements ILaunchTargetManager {
|
||||||
targets = new LinkedHashMap<>();
|
targets = new LinkedHashMap<>();
|
||||||
Preferences prefs = getTargetsPref();
|
Preferences prefs = getTargetsPref();
|
||||||
try {
|
try {
|
||||||
// For backwards compat pre-attributes, load targets from type keys
|
|
||||||
for (String childName : prefs.childrenNames()) {
|
for (String childName : prefs.childrenNames()) {
|
||||||
String[] segments = childName.split(DELIMETER1);
|
String[] segments = childName.split(DELIMETER1);
|
||||||
if (segments.length == 2) {
|
if (segments.length == 2) {
|
||||||
|
@ -79,26 +77,30 @@ public class LaunchTargetManager implements ILaunchTargetManager {
|
||||||
targets.put(typeId, type);
|
targets.put(typeId, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creates the node. Will flush when attributes are added
|
|
||||||
type.put(name, new LaunchTarget(typeId, name, prefs.node(childName)));
|
type.put(name, new LaunchTarget(typeId, name, prefs.node(childName)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String typeId : prefs.keys()) {
|
// convert old type keys
|
||||||
Map<String, ILaunchTarget> type = targets.get(typeId);
|
if (prefs.keys().length > 0) {
|
||||||
if (type == null) {
|
for (String typeId : prefs.keys()) {
|
||||||
type = new LinkedHashMap<>();
|
Map<String, ILaunchTarget> type = targets.get(typeId);
|
||||||
targets.put(typeId, type);
|
if (type == null) {
|
||||||
}
|
type = new LinkedHashMap<>();
|
||||||
|
targets.put(typeId, type);
|
||||||
for (String name : prefs.get(typeId, "").split(DELIMETER1)) { //$NON-NLS-1$
|
|
||||||
if (!type.containsKey(name)) {
|
|
||||||
type.put(name, new LaunchTarget(typeId, name, prefs.node(typeId + DELIMETER1 + name)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (String name : prefs.get(typeId, "").split(DELIMETER1)) { //$NON-NLS-1$
|
||||||
|
if (!type.containsKey(name)) {
|
||||||
|
type.put(name, new LaunchTarget(typeId, name, prefs.node(typeId + DELIMETER1 + name)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use children going forward
|
||||||
|
prefs.remove(typeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use children going forward
|
prefs.flush();
|
||||||
prefs.remove(typeId);
|
|
||||||
}
|
}
|
||||||
} catch (BackingStoreException e) {
|
} catch (BackingStoreException e) {
|
||||||
Activator.log(e);
|
Activator.log(e);
|
||||||
|
@ -209,15 +211,19 @@ public class LaunchTargetManager implements ILaunchTargetManager {
|
||||||
@Override
|
@Override
|
||||||
public void removeLaunchTarget(ILaunchTarget target) {
|
public void removeLaunchTarget(ILaunchTarget target) {
|
||||||
initTargets();
|
initTargets();
|
||||||
Map<String, ILaunchTarget> type = targets.get(target.getTypeId());
|
String typeId = target.getTypeId();
|
||||||
|
Map<String, ILaunchTarget> type = targets.get(typeId);
|
||||||
if (type != null) {
|
if (type != null) {
|
||||||
type.remove(target.getId());
|
type.remove(target);
|
||||||
if (type.isEmpty()) {
|
if (type.isEmpty()) {
|
||||||
targets.remove(target.getTypeId());
|
targets.remove(target.getTypeId());
|
||||||
getTargetsPref().remove(target.getTypeId());
|
}
|
||||||
} else {
|
|
||||||
getTargetsPref().put(target.getTypeId(),
|
// Remove the attribute node
|
||||||
type.values().stream().map(t -> t.getId()).collect(Collectors.joining(DELIMETER1)));
|
try {
|
||||||
|
getTargetsPref().node(typeId + DELIMETER1 + target.getId()).removeNode();
|
||||||
|
} catch (BackingStoreException e) {
|
||||||
|
Activator.log(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ILaunchTargetListener listener : listeners) {
|
for (ILaunchTargetListener listener : listeners) {
|
||||||
|
|
|
@ -17,20 +17,31 @@ public class TargetAttributesTest {
|
||||||
ILaunchTargetManager manager = Activator.getLaunchTargetManager();
|
ILaunchTargetManager manager = Activator.getLaunchTargetManager();
|
||||||
String targetType = "testType";
|
String targetType = "testType";
|
||||||
String targetId = "testTarget";
|
String targetId = "testTarget";
|
||||||
|
String attributeKey = "testKey";
|
||||||
|
String attributeValue = "testValue";
|
||||||
|
// Make sure the target doesn't exist
|
||||||
ILaunchTarget target = manager.getLaunchTarget(targetType, targetId);
|
ILaunchTarget target = manager.getLaunchTarget(targetType, targetId);
|
||||||
if (target != null) {
|
if (target != null) {
|
||||||
manager.removeLaunchTarget(target);
|
manager.removeLaunchTarget(target);
|
||||||
}
|
}
|
||||||
|
// Add the target
|
||||||
target = manager.addLaunchTarget(targetType, targetId);
|
target = manager.addLaunchTarget(targetType, targetId);
|
||||||
String attributeKey = "testKey";
|
// Attribute should be empty
|
||||||
String attributeValue = "testValue";
|
|
||||||
assertEquals(target.getAttribute(attributeKey, ""), "");
|
assertEquals(target.getAttribute(attributeKey, ""), "");
|
||||||
|
// Set the attribute and make sure it's set
|
||||||
ILaunchTargetWorkingCopy wc = target.getWorkingCopy();
|
ILaunchTargetWorkingCopy wc = target.getWorkingCopy();
|
||||||
assertNotEquals(target, wc);
|
assertNotEquals(target, wc);
|
||||||
wc.setAttribute(attributeKey, attributeValue);
|
wc.setAttribute(attributeKey, attributeValue);
|
||||||
assertEquals(wc.getAttribute(attributeKey, ""), attributeValue);
|
assertEquals(wc.getAttribute(attributeKey, ""), attributeValue);
|
||||||
ILaunchTarget savedTarget = wc.save();
|
ILaunchTarget savedTarget = wc.save();
|
||||||
|
// Make sure we get our original back
|
||||||
assertEquals(target, savedTarget);
|
assertEquals(target, savedTarget);
|
||||||
assertEquals(target.getAttribute(attributeKey, ""), attributeValue);
|
assertEquals(target.getAttribute(attributeKey, ""), attributeValue);
|
||||||
|
// Make sure remove removes the attribute
|
||||||
|
manager.removeLaunchTarget(target);
|
||||||
|
target = manager.addLaunchTarget(targetType, targetId);
|
||||||
|
assertEquals(target.getAttribute(attributeKey, ""), "");
|
||||||
|
// Cleanup
|
||||||
|
manager.removeLaunchTarget(target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue