diff --git a/updater/src/com/intellij/updater/BaseUpdateAction.java b/updater/src/com/intellij/updater/BaseUpdateAction.java index f5173f4964a0..a3925788c9e3 100644 --- a/updater/src/com/intellij/updater/BaseUpdateAction.java +++ b/updater/src/com/intellij/updater/BaseUpdateAction.java @@ -20,6 +20,7 @@ import ie.wombat.jbdiff.JBDiff; import ie.wombat.jbdiff.JBPatch; import java.io.*; +import java.util.Objects; import java.util.zip.ZipOutputStream; /** @@ -176,4 +177,25 @@ public abstract class BaseUpdateAction extends PatchAction { } return text; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!super.equals(o)) return false; + + BaseUpdateAction that = (BaseUpdateAction)o; + + if (myIsMove != that.myIsMove) return false; + if (!Objects.equals(mySource, that.mySource)) return false; + + return true; + } + + @Override + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + (myIsMove ? 1 : 0); + result = 31 * result + Objects.hashCode(mySource); + return result; + } } \ No newline at end of file diff --git a/updater/src/com/intellij/updater/PatchAction.java b/updater/src/com/intellij/updater/PatchAction.java index 02e09370414e..12ef8889861f 100644 --- a/updater/src/com/intellij/updater/PatchAction.java +++ b/updater/src/com/intellij/updater/PatchAction.java @@ -21,6 +21,7 @@ import java.nio.channels.FileLock; import java.nio.channels.OverlappingFileLockException; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.stream.Collectors; import java.util.zip.ZipFile; import java.util.zip.ZipOutputStream; @@ -227,14 +228,14 @@ public abstract class PatchAction { if (myFlags != that.myFlags) return false; if (myChecksum != that.myChecksum) return false; - if (myPath != null ? !myPath.equals(that.myPath) : that.myPath != null) return false; + if (!Objects.equals(myPath, that.myPath)) return false; return true; } @Override public int hashCode() { - int result = myPath != null ? myPath.hashCode() : 0; + int result = Objects.hashCode(myPath); result = 31 * result + (int)(myChecksum ^ (myChecksum >>> 32)); result = 31 * result + myFlags; return result; diff --git a/updater/src/com/intellij/updater/UpdateZipAction.java b/updater/src/com/intellij/updater/UpdateZipAction.java index 4521a6fa4c8f..b79a965634be 100644 --- a/updater/src/com/intellij/updater/UpdateZipAction.java +++ b/updater/src/com/intellij/updater/UpdateZipAction.java @@ -30,18 +30,6 @@ public class UpdateZipAction extends BaseUpdateAction { super(patch, path, source, checksum, false); } - // test support - public UpdateZipAction(Patch patch, String path, - Collection filesToCreate, - Collection filesToUpdate, - Collection filesToDelete, - long checksum) { - super(patch, path, path, checksum, false); - myFilesToCreate = new HashSet<>(filesToCreate); - myFilesToUpdate = new HashSet<>(filesToUpdate); - myFilesToDelete = new HashSet<>(filesToDelete); - } - public UpdateZipAction(Patch patch, DataInputStream in) throws IOException { super(patch, in); @@ -64,6 +52,19 @@ public class UpdateZipAction extends BaseUpdateAction { } } + /* for tests */ + UpdateZipAction(Patch patch, String path, Collection toCreate, Collection toUpdate, Collection toDelete, long checksum) { + this(patch, path, path, toCreate, toUpdate, toDelete, checksum); + } + + /* for tests */ + UpdateZipAction(Patch patch, String path, String source, Collection toCreate, Collection toUpdate, Collection toDelete, long checksum) { + super(patch, path, source, checksum, false); + myFilesToCreate = new HashSet<>(toCreate); + myFilesToUpdate = new HashSet<>(toUpdate); + myFilesToDelete = new HashSet<>(toDelete); + } + @Override public void write(DataOutputStream out) throws IOException { super.write(out); @@ -201,14 +202,13 @@ public class UpdateZipAction extends BaseUpdateAction { @Override public boolean equals(Object o) { if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; if (!super.equals(o)) return false; UpdateZipAction that = (UpdateZipAction)o; - if (myFilesToCreate != null ? !myFilesToCreate.equals(that.myFilesToCreate) : that.myFilesToCreate != null) return false; - if (myFilesToUpdate != null ? !myFilesToUpdate.equals(that.myFilesToUpdate) : that.myFilesToUpdate != null) return false; - if (myFilesToDelete != null ? !myFilesToDelete.equals(that.myFilesToDelete) : that.myFilesToDelete != null) return false; + if (!Objects.equals(myFilesToCreate, that.myFilesToCreate)) return false; + if (!Objects.equals(myFilesToUpdate, that.myFilesToUpdate)) return false; + if (!Objects.equals(myFilesToDelete, that.myFilesToDelete)) return false; return true; } @@ -216,9 +216,9 @@ public class UpdateZipAction extends BaseUpdateAction { @Override public int hashCode() { int result = super.hashCode(); - result = 31 * result + (myFilesToCreate != null ? myFilesToCreate.hashCode() : 0); - result = 31 * result + (myFilesToUpdate != null ? myFilesToUpdate.hashCode() : 0); - result = 31 * result + (myFilesToDelete != null ? myFilesToDelete.hashCode() : 0); + result = 31 * result + Objects.hashCode(myFilesToCreate); + result = 31 * result + Objects.hashCode(myFilesToDelete); + result = 31 * result + Objects.hashCode(myFilesToUpdate); return result; } } \ No newline at end of file diff --git a/updater/testSrc/com/intellij/updater/PatchTest.java b/updater/testSrc/com/intellij/updater/PatchTest.java index 0edf2a49eb20..9196415d73fb 100644 --- a/updater/testSrc/com/intellij/updater/PatchTest.java +++ b/updater/testSrc/com/intellij/updater/PatchTest.java @@ -204,7 +204,7 @@ public class PatchTest extends PatchTestCase { assertThat(sortActions(patch.getActions())).containsExactly( new DeleteAction(patch, "lib/annotations.jar", CHECKSUMS.ANNOTATIONS_JAR), new CreateAction(patch, "lib/redist/"), - new UpdateAction(patch, "lib/redist/annotations.jar", CHECKSUMS.ANNOTATIONS_JAR)); + new UpdateAction(patch, "lib/redist/annotations.jar", "lib/annotations.jar", CHECKSUMS.ANNOTATIONS_JAR, true)); } @Test @@ -218,7 +218,7 @@ public class PatchTest extends PatchTestCase { assertThat(sortActions(patch.getActions())).containsExactly( new DeleteAction(patch, "lib/annotations.jar", CHECKSUMS.ANNOTATIONS_JAR), new CreateAction(patch, "lib/redist/"), - new UpdateZipAction(patch, "lib/redist/annotations.jar", + new UpdateZipAction(patch, "lib/redist/annotations.jar", "lib/annotations.jar", Collections.singletonList("org/jetbrains/annotations/NewClass.class"), Collections.singletonList("org/jetbrains/annotations/Nullable.class"), Collections.singletonList("org/jetbrains/annotations/TestOnly.class"),