Skip to content

Commit

Permalink
MavenTargetLocation: use serialize for equals and hashCode
Browse files Browse the repository at this point in the history
In the TargetPlatformPreferencePage, upon the Apply button, some target
definition containing some MavenTargetLocation always was rewritten to
it's .target file. This was because MavenTargetLocation.equals never
returned true for multiple reasons, starting with MavenTargetDependency
lacking an impl of equals().
Using serialize(), we can be sure to perform the equals check on any
relevant attribute, including deeply nested ones.

Beyond that, also use serialize() to implement hashCode().
  • Loading branch information
haubi committed Feb 5, 2024
1 parent c3fa2ed commit e8ced44
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion org.eclipse.m2e.pde.target/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: M2E PDE Integration
Bundle-SymbolicName: org.eclipse.m2e.pde.target;singleton:=true
Bundle-Version: 2.0.500.qualifier
Bundle-Version: 2.0.600.qualifier
Automatic-Module-Name: org.eclipse.m2e.pde.target
Bundle-RequiredExecutionEnvironment: JavaSE-17
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.27.0,4.0.0)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ public String getLocation(boolean resolve) throws CoreException {

@Override
public int hashCode() {
return Objects.hash(roots, dependencyScopes, failedArtifacts, metadataMode);
return serialize().hashCode();
}

@Override
Expand All @@ -523,9 +523,8 @@ public boolean equals(Object obj) {
return true;
}
return obj instanceof MavenTargetLocation other //
&& Objects.equals(roots, other.roots)//
&& Objects.equals(dependencyScopes, other.dependencyScopes)
&& Objects.equals(failedArtifacts, other.failedArtifacts);
// check each and every relevant attribute, including nested ones
&& serialize().equals(other.serialize());
}

public boolean isIncludeSource() {
Expand Down

0 comments on commit e8ced44

Please sign in to comment.