From 1d926b5c201c7ef5c7456abde34ad7dfaba54fdd Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Mon, 5 Oct 2015 22:14:16 +0200 Subject: [PATCH] Cleanup (parameter extracted) --- .../updateSettings/impl/UpdateChecker.java | 4 ++- .../updateSettings/impl/UpdateStrategy.java | 14 +++++++++- .../ide/updates/UpdateStrategyTest.java | 27 ++++++++++++------- 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateChecker.java b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateChecker.java index 7ca7cd3199c5..b7a4d189c5aa 100644 --- a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateChecker.java +++ b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateChecker.java @@ -33,6 +33,7 @@ import com.intellij.openapi.progress.Task; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.DialogWrapper; import com.intellij.openapi.ui.Messages; +import com.intellij.openapi.updateSettings.UpdateStrategyCustomization; import com.intellij.openapi.util.*; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; @@ -238,7 +239,8 @@ public final class UpdateChecker { ApplicationInfo appInfo = ApplicationInfo.getInstance(); int majorVersion = Integer.parseInt(appInfo.getMajorVersion()); - UpdateStrategy strategy = new UpdateStrategy(majorVersion, appInfo.getBuild(), updateInfo, settings); + UpdateStrategyCustomization customization = UpdateStrategyCustomization.getInstance(); + UpdateStrategy strategy = new UpdateStrategy(majorVersion, appInfo.getBuild(), updateInfo, settings, customization); return strategy.checkForUpdates(); } diff --git a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateStrategy.java b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateStrategy.java index 7784c3e85eb2..9e4a254ae88c 100644 --- a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateStrategy.java +++ b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateStrategy.java @@ -30,16 +30,28 @@ public class UpdateStrategy { private final UpdatesInfo myUpdatesInfo; private final UserUpdateSettings myUpdateSettings; private final ChannelStatus myChannelStatus; + private final UpdateStrategyCustomization myStrategyCustomization; + /** @deprecated use {@link #UpdateStrategy(int, BuildNumber, UpdatesInfo, UserUpdateSettings, UpdateStrategyCustomization)} */ + @SuppressWarnings("unused") public UpdateStrategy(int majorVersion, @NotNull BuildNumber currentBuild, @NotNull UpdatesInfo updatesInfo, @NotNull UserUpdateSettings updateSettings) { + this(majorVersion, currentBuild, updatesInfo, updateSettings, UpdateStrategyCustomization.getInstance()); + } + + public UpdateStrategy(int majorVersion, + @NotNull BuildNumber currentBuild, + @NotNull UpdatesInfo updatesInfo, + @NotNull UserUpdateSettings updateSettings, + @NotNull UpdateStrategyCustomization customization) { myMajorVersion = majorVersion; myCurrentBuild = currentBuild; myUpdatesInfo = updatesInfo; myUpdateSettings = updateSettings; myChannelStatus = updateSettings.getSelectedChannelStatus(); + myStrategyCustomization = customization; } public final CheckForUpdateResult checkForUpdates() { @@ -83,7 +95,7 @@ public class UpdateStrategy { for (UpdateChannel channel : product.getChannels()) { // If the update is to a new version and on a stabler channel, choose it. if ((channel.getMajorVersion() >= myMajorVersion && channel.getStatus().compareTo(myChannelStatus) >= 0) && - (UpdateStrategyCustomization.getInstance().allowMajorVersionUpdate() || + (myStrategyCustomization.allowMajorVersionUpdate() || channel.getMajorVersion() == myMajorVersion || channel.getStatus() == ChannelStatus.EAP && myChannelStatus == ChannelStatus.EAP)) { // Prefer channel that has same status as our selected channel status diff --git a/platform/platform-tests/testSrc/com/intellij/ide/updates/UpdateStrategyTest.java b/platform/platform-tests/testSrc/com/intellij/ide/updates/UpdateStrategyTest.java index 6d4f561dbd81..8ce530504860 100644 --- a/platform/platform-tests/testSrc/com/intellij/ide/updates/UpdateStrategyTest.java +++ b/platform/platform-tests/testSrc/com/intellij/ide/updates/UpdateStrategyTest.java @@ -15,9 +15,9 @@ */ package com.intellij.ide.updates; +import com.intellij.openapi.updateSettings.UpdateStrategyCustomization; import com.intellij.openapi.updateSettings.impl.*; import com.intellij.openapi.util.BuildNumber; -import com.intellij.testFramework.fixtures.BareTestFixtureTestCase; import org.jetbrains.annotations.NotNull; import org.junit.Test; @@ -27,12 +27,13 @@ import java.util.List; import static org.junit.Assert.*; -public class UpdateStrategyTest extends BareTestFixtureTestCase { +public class UpdateStrategyTest { @Test public void testWithUndefinedSelection() { // could be if somebody used before previous version of IDEA TestUpdateSettings settings = new TestUpdateSettings(ChannelStatus.EAP); - UpdateStrategy strategy = new UpdateStrategy(9, BuildNumber.fromString("IU-98.520"), InfoReader.read("idea-same.xml"), settings); + UpdateStrategyCustomization customization = new UpdateStrategyCustomization(); + UpdateStrategy strategy = new UpdateStrategy(9, BuildNumber.fromString("IU-98.520"), InfoReader.read("idea-same.xml"), settings, customization); CheckForUpdateResult result = strategy.checkForUpdates(); assertEquals(UpdateStrategy.State.LOADED, result.getState()); @@ -43,7 +44,8 @@ public class UpdateStrategyTest extends BareTestFixtureTestCase { public void testWithUserSelection() { // assume user has version 9 eap - and used eap channel - we want to introduce new eap TestUpdateSettings settings = new TestUpdateSettings(ChannelStatus.EAP); - UpdateStrategy strategy = new UpdateStrategy(9, BuildNumber.fromString("IU-95.429"), InfoReader.read("idea-new9eap.xml"), settings); + UpdateStrategyCustomization customization = new UpdateStrategyCustomization(); + UpdateStrategy strategy = new UpdateStrategy(9, BuildNumber.fromString("IU-95.429"), InfoReader.read("idea-new9eap.xml"), settings, customization); CheckForUpdateResult result = strategy.checkForUpdates(); assertEquals(UpdateStrategy.State.LOADED, result.getState()); @@ -56,7 +58,8 @@ public class UpdateStrategyTest extends BareTestFixtureTestCase { public void testIgnore() { // assume user has version 9 eap - and used eap channel - we want to introduce new eap TestUpdateSettings settings = new TestUpdateSettings(ChannelStatus.EAP, "95.627", "98.620"); - UpdateStrategy strategy = new UpdateStrategy(9, BuildNumber.fromString("IU-95.429"), InfoReader.read("idea-new9eap.xml"), settings); + UpdateStrategyCustomization customization = new UpdateStrategyCustomization(); + UpdateStrategy strategy = new UpdateStrategy(9, BuildNumber.fromString("IU-95.429"), InfoReader.read("idea-new9eap.xml"), settings, customization); CheckForUpdateResult result = strategy.checkForUpdates(); assertEquals(UpdateStrategy.State.LOADED, result.getState()); @@ -69,7 +72,8 @@ public class UpdateStrategyTest extends BareTestFixtureTestCase { // assume user has version 9 eap subscription (default or selected) // and new channel appears - eap of version 10 is there TestUpdateSettings settings = new TestUpdateSettings(ChannelStatus.RELEASE); - UpdateStrategy strategy = new UpdateStrategy(9, BuildNumber.fromString("IU-95.627"), InfoReader.read("idea-newChannel-release.xml"), settings); + UpdateStrategyCustomization customization = new UpdateStrategyCustomization(); + UpdateStrategy strategy = new UpdateStrategy(9, BuildNumber.fromString("IU-95.627"), InfoReader.read("idea-newChannel-release.xml"), settings, customization); CheckForUpdateResult result = strategy.checkForUpdates(); assertEquals(UpdateStrategy.State.LOADED, result.getState()); @@ -85,7 +89,8 @@ public class UpdateStrategyTest extends BareTestFixtureTestCase { @Test public void testNewChannelWithOlderBuild() { TestUpdateSettings settings = new TestUpdateSettings(ChannelStatus.EAP); - UpdateStrategy strategy = new UpdateStrategy(10, BuildNumber.fromString("IU-107.80"), InfoReader.read("idea-newChannel.xml"), settings); + UpdateStrategyCustomization customization = new UpdateStrategyCustomization(); + UpdateStrategy strategy = new UpdateStrategy(10, BuildNumber.fromString("IU-107.80"), InfoReader.read("idea-newChannel.xml"), settings, customization); CheckForUpdateResult result = strategy.checkForUpdates(); assertEquals(UpdateStrategy.State.LOADED, result.getState()); @@ -103,7 +108,8 @@ public class UpdateStrategyTest extends BareTestFixtureTestCase { // and new build withing old channel appears also // we need to show only one dialog TestUpdateSettings settings = new TestUpdateSettings(ChannelStatus.EAP); - UpdateStrategy strategy = new UpdateStrategy(9, BuildNumber.fromString("IU-95.429"), InfoReader.read("idea-newChannel.xml"), settings); + UpdateStrategyCustomization customization = new UpdateStrategyCustomization(); + UpdateStrategy strategy = new UpdateStrategy(9, BuildNumber.fromString("IU-95.429"), InfoReader.read("idea-newChannel.xml"), settings, customization); CheckForUpdateResult result = strategy.checkForUpdates(); assertEquals(UpdateStrategy.State.LOADED, result.getState()); @@ -119,9 +125,10 @@ public class UpdateStrategyTest extends BareTestFixtureTestCase { @Test public void testChannelWithCurrentStatusPreferred() { - TestUpdateSettings settings = new TestUpdateSettings(ChannelStatus.EAP); BuildNumber currentBuild = BuildNumber.fromString("IU-139.658"); - UpdateStrategy strategy = new UpdateStrategy(14, currentBuild, InfoReader.read("idea-patchAvailable.xml"), settings); + TestUpdateSettings settings = new TestUpdateSettings(ChannelStatus.EAP); + UpdateStrategyCustomization customization = new UpdateStrategyCustomization(); + UpdateStrategy strategy = new UpdateStrategy(14, currentBuild, InfoReader.read("idea-patchAvailable.xml"), settings, customization); CheckForUpdateResult result = strategy.checkForUpdates(); assertEquals(UpdateStrategy.State.LOADED, result.getState());