Skip to content

Commit ff15efc

Browse files
committed
Also update location attributes when reusing an element
Fix #1255
1 parent d0a2e22 commit ff15efc

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/TargetDefinition.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,6 +1269,7 @@ private void updateIUContainerElements(Element containersElement, List<Element>
12691269
} else {
12701270
oldContainersByRepo.get(repoURL).remove(0);
12711271
}
1272+
TargetDefinitionDocumentTools.updateAttributes(oldContainer, container);
12721273
} else {
12731274
Node movedContainer = fDocument.importNode(container, true);
12741275
TargetDefinitionDocumentTools.addChildWithIndent(containersElement, movedContainer);

ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/TargetDefinitionDocumentTools.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
import java.util.ArrayList;
1717
import java.util.Arrays;
1818
import java.util.Comparator;
19+
import java.util.HashMap;
20+
import java.util.HashSet;
1921
import java.util.List;
22+
import java.util.Map;
2023

2124
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
2225
import org.eclipse.core.runtime.preferences.InstanceScope;
@@ -85,6 +88,33 @@ public static void addChildWithIndent(Node parent, Node child) {
8588
appendTextNode(parent, false);
8689
}
8790

91+
public static void updateAttributes(Element oldElement, Element newElement) {
92+
Map<String, String> previous = asMap(oldElement.getAttributes());
93+
Map<String, String> current = asMap(newElement.getAttributes());
94+
HashSet<String> all = new HashSet<>();
95+
all.addAll(previous.keySet());
96+
all.addAll(current.keySet());
97+
for (String attr : all) {
98+
if (current.containsKey(attr)) {
99+
// if the current element contains the attribute then set it to
100+
// the current value
101+
oldElement.setAttribute(attr, current.get(attr));
102+
} else {
103+
// otherwise remove the attribute
104+
oldElement.removeAttribute(attr);
105+
}
106+
}
107+
}
108+
109+
private static Map<String,String> asMap(NamedNodeMap attributes) {
110+
HashMap<String, String> map = new HashMap<>();
111+
for (int i = 0; i < attributes.getLength(); i++) {
112+
Node item = attributes.item(i);
113+
map.put(item.getNodeName(), item.getNodeValue());
114+
}
115+
return map;
116+
}
117+
88118
/**
89119
* For all the children of the parentElement, if any of the oldElements are not
90120
* found in the newElements list then they are removed. All newElements that are

0 commit comments

Comments
 (0)