diff --git a/platform/platform-impl/src/com/intellij/idea/IdeaApplication.java b/platform/platform-impl/src/com/intellij/idea/IdeaApplication.java index 0c580e0e8a21..1f251d283317 100644 --- a/platform/platform-impl/src/com/intellij/idea/IdeaApplication.java +++ b/platform/platform-impl/src/com/intellij/idea/IdeaApplication.java @@ -209,7 +209,7 @@ public class IdeaApplication { final List updatedPlugins = UpdateChecker.updatePlugins(false, null); if (checkForUpdateResult.hasNewBuildInSelectedChannel()) { - UpdateChecker.showUpdateInfoDialog(true, checkForUpdateResult.getSelected(), updatedPlugins); + UpdateChecker.showUpdateInfoDialog(true, checkForUpdateResult.getUpdatedChannel(), updatedPlugins); } else if (updatedPlugins != null) { UpdateChecker.showNoUpdatesDialog(true, updatedPlugins, showConfirmation); diff --git a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/CheckForUpdateAction.java b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/CheckForUpdateAction.java index ea96a8de3bc7..9cbdd80be9a3 100644 --- a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/CheckForUpdateAction.java +++ b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/CheckForUpdateAction.java @@ -52,7 +52,7 @@ public class CheckForUpdateAction extends AnAction implements DumbAware { if (result.hasNewBuildInSelectedChannel()) { //information about new channel could be there UpdateSettings.getInstance().LAST_TIME_CHECKED = System.currentTimeMillis(); - UpdateChecker.showUpdateInfoDialog(enableLink, result.getSelected(), updatedPlugins); + UpdateChecker.showUpdateInfoDialog(enableLink, result.getUpdatedChannel(), updatedPlugins); }else{ //information about new channel could be there UpdateChecker.showNoUpdatesDialog(enableLink, updatedPlugins, true); diff --git a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/CheckForUpdateResult.java b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/CheckForUpdateResult.java index 5e45e6d68dc6..ac3d83789be3 100644 --- a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/CheckForUpdateResult.java +++ b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/CheckForUpdateResult.java @@ -23,8 +23,8 @@ import java.util.Collection; import java.util.List; public class CheckForUpdateResult { - @NotNull - private final UpdateChannel selected; + @Nullable + private final UpdateChannel myUpdatedChannel; @Nullable private final BuildInfo newBuildInSelectedChannel; @@ -44,12 +44,12 @@ public class CheckForUpdateResult { private final Exception error; - public CheckForUpdateResult(@NotNull UpdateChannel selected, + public CheckForUpdateResult(@Nullable UpdateChannel updated, @Nullable BuildInfo newBuildInSelectedChannel, @Nullable Collection newChannels, List allChannelsIds, @Nullable UpdateChannel channelToPropose) { this.newBuildInSelectedChannel = newBuildInSelectedChannel; - this.selected = selected; + myUpdatedChannel = updated; this.newChannels = newChannels; this.allChannelsIds = allChannelsIds; this.newChannelToPropose = channelToPropose; @@ -62,7 +62,7 @@ public class CheckForUpdateResult { this.newChannels = null; this.allChannelsIds = null; this.newChannelToPropose = null; - this.selected = null; + this.myUpdatedChannel = null; this.state = state; this.error = e; } @@ -106,7 +106,7 @@ public class CheckForUpdateResult { } @NotNull - public UpdateChannel getSelected() { - return selected; + public UpdateChannel getUpdatedChannel() { + return myUpdatedChannel; } } diff --git a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateChannel.java b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateChannel.java index 59b8194accde..c81f72893499 100644 --- a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateChannel.java +++ b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateChannel.java @@ -82,4 +82,8 @@ public class UpdateChannel { public String getName() { return myName; } + + public ChannelStatus getStatus() { + return myStatus; + } } diff --git a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateSettings.java b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateSettings.java index 51d87906d0fd..84fff3171ba2 100644 --- a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateSettings.java +++ b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateSettings.java @@ -112,6 +112,7 @@ public class UpdateSettings implements PersistentStateComponent, UserUp } } + @NotNull @Override public ChannelStatus getSelectedChannelStatus() { return ChannelStatus.fromCode(UPDATE_CHANNEL_TYPE); 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 6695419fbb78..e905dd49b755 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 @@ -32,28 +32,41 @@ public class UpdateStrategy { private UserUpdateSettings updateSettings; private int myMajorVersion; - private BuildNumber ourBuild; + private BuildNumber myCurrentBuild; private ChannelStatus myChannelStatus; - private UpdatesInfo updatesInfo; + private UpdatesInfo myUpdatesInfo; public UpdateStrategy(int majorVersion, @NotNull BuildNumber currentBuild, @NotNull UpdatesInfo updatesInfo, @NotNull UserUpdateSettings updateSettings) { myMajorVersion = majorVersion; - this.updatesInfo = updatesInfo; + myUpdatesInfo = updatesInfo; this.updateSettings = updateSettings; - this.ourBuild = currentBuild; + this.myCurrentBuild = currentBuild; myChannelStatus = updateSettings.getSelectedChannelStatus(); } public final CheckForUpdateResult checkForUpdates() { - final Product product = updatesInfo.getProduct(ourBuild.getProductCode()); + final Product product = myUpdatesInfo.getProduct(myCurrentBuild.getProductCode()); - if (product.getChannels().isEmpty()) { + if (product == null || product.getChannels().isEmpty()) { return new CheckForUpdateResult(State.NOTHING_LOADED); } + UpdateChannel updatedChannel = null; + BuildInfo newBuild = null; + List activeChannels = getActiveChannels(product); + for (UpdateChannel channel : activeChannels) { + if (hasNewVersion(channel)) { + updatedChannel = channel; + newBuild = updatedChannel.getLatestBuild(); + break; + } + } + + return new CheckForUpdateResult(updatedChannel, newBuild, null, Collections.emptyList(), null); + /* boolean replacedWithAppDef = false; @@ -79,7 +92,17 @@ public class UpdateStrategy { newChannels.getFirst(), getFilteredKnownChannels(product), newChannels.getSecond()); */ - return new CheckForUpdateResult(State.NOTHING_LOADED); + } + + private List getActiveChannels(Product product) { + List channels = product.getChannels(); + List result = new ArrayList(); + for (UpdateChannel channel : channels) { + if (channel.getMajorVersion() == myMajorVersion && channel.getStatus().compareTo(myChannelStatus) >= 0) { + result.add(channel); + } + } + return result; } @Nullable @@ -93,11 +116,11 @@ public class UpdateStrategy { return result; } - private boolean isChannelIsOlderThenBuild(@NotNull UpdateChannel channel) { + private boolean hasNewVersion(@NotNull UpdateChannel channel) { if (channel.getLatestBuild() == null || channel.getLatestBuild().getNumber() == null) { - return true; + return false; } - return ourBuild.compareTo(channel.getLatestBuild().getNumber()) >= 0; + return myCurrentBuild.compareTo(channel.getLatestBuild().getNumber()) < 0; } @Nullable @@ -117,7 +140,7 @@ public class UpdateStrategy { @Nullable private BuildInfo getNewVersionInSelectedChannel(@NotNull UpdateChannel channel) { final BuildInfo latestBuild = channel.getLatestBuild(); - if (ourBuild.compareTo(latestBuild.getNumber()) < 0) { + if (myCurrentBuild.compareTo(latestBuild.getNumber()) < 0) { return latestBuild; } return null; @@ -153,10 +176,10 @@ public class UpdateStrategy { private boolean isInteresting(UpdateChannel channel) { - return ourBuild.getBaselineVersion() <= channel.getLatestBuild().getNumber().getBaselineVersion(); + return myCurrentBuild.getBaselineVersion() <= channel.getLatestBuild().getNumber().getBaselineVersion(); } private boolean isNewer(UpdateChannel channel) { - return channel.getLatestBuild().getNumber().getBaselineVersion() > ourBuild.getBaselineVersion(); + return channel.getLatestBuild().getNumber().getBaselineVersion() > myCurrentBuild.getBaselineVersion(); } } diff --git a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UserUpdateSettings.java b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UserUpdateSettings.java index 23d60ce9dfed..fe030c170e0b 100644 --- a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UserUpdateSettings.java +++ b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UserUpdateSettings.java @@ -32,5 +32,6 @@ public interface UserUpdateSettings { void setKnownChannelIds(List ids); + @NotNull ChannelStatus getSelectedChannelStatus(); } diff --git a/platform/platform-impl/testSrc/com/intellij/ide/updates/TestUpdateSettings.java b/platform/platform-impl/testSrc/com/intellij/ide/updates/TestUpdateSettings.java index 88292ab33f05..e0e75a686db7 100644 --- a/platform/platform-impl/testSrc/com/intellij/ide/updates/TestUpdateSettings.java +++ b/platform/platform-impl/testSrc/com/intellij/ide/updates/TestUpdateSettings.java @@ -28,9 +28,6 @@ public class TestUpdateSettings implements UserUpdateSettings { private boolean disabled; private List knowsChannels; - public TestUpdateSettings() { - } - public TestUpdateSettings(ChannelStatus channelStatus, boolean disabled, String[] knowsChannels) { myChannelStatus = channelStatus; this.disabled = disabled; @@ -58,6 +55,7 @@ public class TestUpdateSettings implements UserUpdateSettings { knowsChannels = ids; } + @NotNull @Override public ChannelStatus getSelectedChannelStatus() { return myChannelStatus; diff --git a/platform/platform-impl/testSrc/com/intellij/ide/updates/UpdateStrategyTest.java b/platform/platform-impl/testSrc/com/intellij/ide/updates/UpdateStrategyTest.java index 2880050fdb40..bd8591441aa1 100644 --- a/platform/platform-impl/testSrc/com/intellij/ide/updates/UpdateStrategyTest.java +++ b/platform/platform-impl/testSrc/com/intellij/ide/updates/UpdateStrategyTest.java @@ -26,7 +26,7 @@ public class UpdateStrategyTest extends TestCase { //could be if somebody used before previous version of IDEA public void testWithUndefinedSelection() { - final TestUpdateSettings settings = new TestUpdateSettings(); + final TestUpdateSettings settings = new TestUpdateSettings(ChannelStatus.EAP, false, null); //first time load UpdateStrategy strategy = new UpdateStrategy(9, BuildNumber.fromString("IU-98.520"), UpdatesInfoXppParserTest.InfoReader.read("idea-same.xml"), settings); diff --git a/platform/platform-impl/testSrc/com/intellij/ide/updates/idea-new9eap.xml b/platform/platform-impl/testSrc/com/intellij/ide/updates/idea-new9eap.xml index bb4c8d3f6151..f8cbd5411e5a 100644 --- a/platform/platform-impl/testSrc/com/intellij/ide/updates/idea-new9eap.xml +++ b/platform/platform-impl/testSrc/com/intellij/ide/updates/idea-new9eap.xml @@ -2,7 +2,7 @@ IU IC - @@ -13,7 +13,8 @@ - + IntelliJ IDEA 9.0.4 is available. Please visit http://www.jetbrains.com/idea to learn more and download it. @@ -22,7 +23,8 @@ - + IntelliJ IDEA X RC is available. Please visit http://confluence.jetbrains.net/display/IDEADEV/IDEA+X+EAP to learn more and download it. diff --git a/platform/platform-impl/testSrc/com/intellij/ide/updates/idea-same.xml b/platform/platform-impl/testSrc/com/intellij/ide/updates/idea-same.xml index b421124e19d6..d8273e452e32 100644 --- a/platform/platform-impl/testSrc/com/intellij/ide/updates/idea-same.xml +++ b/platform/platform-impl/testSrc/com/intellij/ide/updates/idea-same.xml @@ -2,7 +2,7 @@ IU IC - @@ -13,7 +13,8 @@ - + IntelliJ IDEA 9.0.4 is available. Please visit http://www.jetbrains.com/idea to learn more and download it. @@ -22,7 +23,8 @@ - + IntelliJ IDEA X RC is available. Please visit http://confluence.jetbrains.net/display/IDEADEV/IDEA+X+EAP to learn more and download it.