Skip to content

Commit

Permalink
TargetDefinition: compare target locations along serialized value
Browse files Browse the repository at this point in the history
Implementations of ITargetLocation may have an equals() implementation
that does not compare all their serialized attributes. In particular,
this is true for MavenTargetLocation, causing any check for redundancy
upon the 'Apply' button in the Target Platform Preferences Editor to
fail, causing each time:
- the .target file to be rewritten
- the Target Platform State to be re-evaluated

Instead, we compare along the serialized value of ITargetLocation, if
available, ignoring any particular order of target locations as well.
  • Loading branch information
haubi authored and HannesWell committed Feb 8, 2024
1 parent 4457f2e commit c9790c6
Showing 1 changed file with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.ParserConfigurationException;
Expand Down Expand Up @@ -879,7 +880,7 @@ public boolean isContentEqual(ITargetDefinition definition) {
Objects.equals(getVMArguments(), definition.getVMArguments()) && //
Objects.equals(getJREContainer(), definition.getJREContainer()) && //
Arrays.equals(getIncluded(), definition.getIncluded()) && //
Arrays.equals(getTargetLocations(), definition.getTargetLocations()) && //
unorderedArraysEqualsSerialized(getTargetLocations(), definition.getTargetLocations()) && //
Arrays.equals(getImplicitDependencies(), definition.getImplicitDependencies());
}

Expand All @@ -899,10 +900,24 @@ public boolean isContentEquivalent(ITargetDefinition definition) {
isArgsNullOrEqual(getVMArguments(), definition.getVMArguments()) && //
Objects.equals(getJREContainer(), definition.getJREContainer()) && //
Arrays.equals(getIncluded(), definition.getIncluded()) && //
Arrays.equals(getTargetLocations(), definition.getTargetLocations()) && //
unorderedArraysEqualsSerialized(getTargetLocations(), definition.getTargetLocations()) && //
Arrays.equals(getImplicitDependencies(), definition.getImplicitDependencies());
}

private static boolean unorderedArraysEqualsSerialized(ITargetLocation[] one, ITargetLocation[] two) {
if (one == two) {
return true;
}
if (one == null || two == null || one.length != two.length) {
return false;
}
Set<Object> oneXml = Arrays.stream(one).filter(Objects::nonNull)
.map(l -> Objects.requireNonNullElse(l.serialize(), l)).collect(Collectors.toSet());
Set<Object> twoXml = Arrays.stream(two).filter(Objects::nonNull)
.map(l -> Objects.requireNonNullElse(l.serialize(), l)).collect(Collectors.toSet());
return oneXml.equals(twoXml);
}

private boolean isArgsNullOrEqual(String args1, String args2) {
return (args1 == null && args2 == null)
|| Arrays.equals(DebugPlugin.parseArguments(args1), DebugPlugin.parseArguments(args2));
Expand Down

0 comments on commit c9790c6

Please sign in to comment.