diff --git a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/BuildInfo.java b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/BuildInfo.java index 2f2e847d0310..e698b045e6e3 100644 --- a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/BuildInfo.java +++ b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/BuildInfo.java @@ -70,4 +70,9 @@ public class BuildInfo implements Comparable { } return null; } + + @Override + public String toString() { + return "BuildInfo(number=" + myNumber + ")"; + } } 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 ac3d83789be3..1178f7dfbd96 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 @@ -19,7 +19,9 @@ package com.intellij.openapi.updateSettings.impl; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.List; public class CheckForUpdateResult { @@ -29,14 +31,14 @@ public class CheckForUpdateResult { @Nullable private final BuildInfo newBuildInSelectedChannel; - @Nullable - private final Collection newChannels; + @NotNull + private final Collection myNewChannels; @Nullable private final List allChannelsIds; @Nullable - private final UpdateChannel newChannelToPropose; + private UpdateChannel myChannelToPropose; @NotNull private final UpdateStrategy.State state; @@ -46,22 +48,20 @@ public class CheckForUpdateResult { public CheckForUpdateResult(@Nullable UpdateChannel updated, @Nullable BuildInfo newBuildInSelectedChannel, - @Nullable Collection newChannels, List allChannelsIds, - @Nullable UpdateChannel channelToPropose) { + List allChannelsIds) { this.newBuildInSelectedChannel = newBuildInSelectedChannel; myUpdatedChannel = updated; - this.newChannels = newChannels; + myNewChannels = new ArrayList(); this.allChannelsIds = allChannelsIds; - this.newChannelToPropose = channelToPropose; this.state = UpdateStrategy.State.LOADED; this.error = null; } public CheckForUpdateResult(UpdateStrategy.State state, Exception e) { this.newBuildInSelectedChannel = null; - this.newChannels = null; + myNewChannels = Collections.emptyList(); this.allChannelsIds = null; - this.newChannelToPropose = null; + this.myChannelToPropose = null; this.myUpdatedChannel = null; this.state = state; this.error = e; @@ -80,9 +80,13 @@ public class CheckForUpdateResult { return newBuildInSelectedChannel!=null; } - @Nullable + public void addNewChannel(UpdateChannel channel) { + myNewChannels.add(channel); + } + + @NotNull public Collection getNewChannels() { - return newChannels; + return myNewChannels; } @Nullable @@ -91,8 +95,12 @@ public class CheckForUpdateResult { } @Nullable - public UpdateChannel getNewChannelToPropose() { - return newChannelToPropose; + public UpdateChannel getChannelToPropose() { + return myChannelToPropose; + } + + public void setChannelToPropose(@Nullable UpdateChannel channelToPropose) { + myChannelToPropose = channelToPropose; } @NotNull 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 84fff3171ba2..46c0c79919d3 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 @@ -15,7 +15,6 @@ */ package com.intellij.openapi.updateSettings.impl; -import com.intellij.openapi.application.ApplicationInfo; import com.intellij.openapi.components.PersistentStateComponent; import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.components.State; @@ -84,11 +83,9 @@ public class UpdateSettings implements PersistentStateComponent, UserUp return !CHECK_NEEDED; } + @NotNull @Override public List getKnownChannelsIds() { - if (myKnownUpdateChannels==null){ - return null; - } List ids = new ArrayList(); for (String channel : myKnownUpdateChannels) { ids.add(channel); @@ -96,12 +93,6 @@ public class UpdateSettings implements PersistentStateComponent, UserUp return ids; } - @NotNull - @Override - public String getAppDefaultChannelId() { - return ApplicationInfo.getInstance().getDefaultUpdateChannel(); - } - @Override public void setKnownChannelIds(List ids) { myKnownUpdateChannels.clear(); 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 e905dd49b755..2e39000717da 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 @@ -17,20 +17,16 @@ package com.intellij.openapi.updateSettings.impl; import com.intellij.openapi.util.BuildNumber; -import com.intellij.openapi.util.Pair; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Collections; import java.util.List; -@SuppressWarnings({"ConstantConditions"}) - public class UpdateStrategy { public static enum State {LOADED, CONNECTION_ERROR, NOTHING_LOADED} - private UserUpdateSettings updateSettings; + private UserUpdateSettings myUpdateSettings; private int myMajorVersion; private BuildNumber myCurrentBuild; @@ -42,7 +38,7 @@ public class UpdateStrategy { @NotNull UserUpdateSettings updateSettings) { myMajorVersion = majorVersion; myUpdatesInfo = updatesInfo; - this.updateSettings = updateSettings; + myUpdateSettings = updateSettings; this.myCurrentBuild = currentBuild; myChannelStatus = updateSettings.getSelectedChannelStatus(); } @@ -65,33 +61,27 @@ public class UpdateStrategy { } } - return new CheckForUpdateResult(updatedChannel, newBuild, null, Collections.emptyList(), null); + CheckForUpdateResult result = new CheckForUpdateResult(updatedChannel, newBuild, Collections.emptyList()); - /* - boolean replacedWithAppDef = false; - - UpdateChannel channel = getChannelByIds(selectedChannel, product); - - if (!forced && (channel == null || isChannelIsOlderThenBuild(channel))) { - selectedChannel = updateSettings.getAppDefaultChannelId(); - replacedWithAppDef = true; - channel = getChannelByIds(selectedChannel, product); + UpdateChannel channelToPropose = null; + for (UpdateChannel channel : product.getChannels()) { + if (!myUpdateSettings.getKnownChannelsIds().contains(channel.getId()) && + channel.getMajorVersion() >= myMajorVersion && + channel.getStatus().compareTo(myChannelStatus) >= 0) { + result.addNewChannel(channel); + if (channelToPropose == null || isBetter(channelToPropose, channel)) { + channelToPropose = channel; + } + } } + result.setChannelToPropose(channelToPropose); + return result; + } - if (channel == null) { - return new CheckForUpdateResult(State.NOTHING_LOADED); - } - - final Pair, UpdateChannel> newChannels = getNewChannels(product); - - - - return new CheckForUpdateResult( - replacedWithAppDef, channel, - getNewVersionInSelectedChannel(channel), - newChannels.getFirst(), getFilteredKnownChannels(product), - newChannels.getSecond()); - */ + private static boolean isBetter(UpdateChannel channelToPropose, UpdateChannel channel) { + return channel.getMajorVersion() > channelToPropose.getMajorVersion() || + (channel.getMajorVersion() == channelToPropose.getMajorVersion() && + channel.getStatus().compareTo(channelToPropose.getStatus()) > 0); } private List getActiveChannels(Product product) { @@ -105,81 +95,10 @@ public class UpdateStrategy { return result; } - @Nullable - private List getFilteredKnownChannels(@NotNull Product product) { - List result = new ArrayList(); - for (UpdateChannel channel : product.getChannels()) { - //if (!isChannelIsOlderThenBuild(channel)){ - result.add(channel.getId()); - //} - } - return result; - } - private boolean hasNewVersion(@NotNull UpdateChannel channel) { if (channel.getLatestBuild() == null || channel.getLatestBuild().getNumber() == null) { return false; } return myCurrentBuild.compareTo(channel.getLatestBuild().getNumber()) < 0; } - - @Nullable - private static UpdateChannel getChannelByIds(@Nullable String selectedChannel, @NotNull Product product) { - if (selectedChannel == null) { - return null; - } - for (UpdateChannel channel : product.getChannels()) { - if (selectedChannel.equals(channel.getId())) { - return channel; - } - } - return null; - } - - - @Nullable - private BuildInfo getNewVersionInSelectedChannel(@NotNull UpdateChannel channel) { - final BuildInfo latestBuild = channel.getLatestBuild(); - if (myCurrentBuild.compareTo(latestBuild.getNumber()) < 0) { - return latestBuild; - } - return null; - } - - - /** - * - * @param product - * @return pair: list of all new channel + one channel could be proposed to user specially - */ - @NotNull - private Pair, UpdateChannel> getNewChannels(@NotNull Product product) { - List knownChannels = - updateSettings.getKnownChannelsIds() != null ? updateSettings.getKnownChannelsIds() : Collections.emptyList(); - - UpdateChannel versionUpgradeChannel = null; - List newChannels = new ArrayList(); - final List loadedChannels = product.getChannels(); - - for (UpdateChannel channel : loadedChannels) { - if (knownChannels.contains(channel.getId()) || !isInteresting(channel)) { - continue; - } - newChannels.add(channel); - if (isNewer(channel)) { - versionUpgradeChannel = channel; - } - } - return new Pair, UpdateChannel>(newChannels.size() > 0 ? newChannels : null, versionUpgradeChannel); - } - - - - private boolean isInteresting(UpdateChannel channel) { - return myCurrentBuild.getBaselineVersion() <= channel.getLatestBuild().getNumber().getBaselineVersion(); - } - - private boolean isNewer(UpdateChannel channel) { - 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 fe030c170e0b..000450414632 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 @@ -16,20 +16,16 @@ package com.intellij.openapi.updateSettings.impl; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.util.List; public interface UserUpdateSettings { boolean isCheckingDisabled(); - @Nullable + @NotNull List getKnownChannelsIds(); - @NotNull - String getAppDefaultChannelId(); - void setKnownChannelIds(List ids); @NotNull 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 e0e75a686db7..d30c07e6c5c6 100644 --- a/platform/platform-impl/testSrc/com/intellij/ide/updates/TestUpdateSettings.java +++ b/platform/platform-impl/testSrc/com/intellij/ide/updates/TestUpdateSettings.java @@ -28,10 +28,10 @@ public class TestUpdateSettings implements UserUpdateSettings { private boolean disabled; private List knowsChannels; - public TestUpdateSettings(ChannelStatus channelStatus, boolean disabled, String[] knowsChannels) { + public TestUpdateSettings(ChannelStatus channelStatus, boolean disabled, String... knowsChannels) { myChannelStatus = channelStatus; this.disabled = disabled; - this.knowsChannels = knowsChannels!=null?Arrays.asList(knowsChannels):null; + this.knowsChannels = Arrays.asList(knowsChannels); } @Override @@ -39,17 +39,12 @@ public class TestUpdateSettings implements UserUpdateSettings { return disabled; } + @NotNull @Override public List getKnownChannelsIds() { return knowsChannels; } - @NotNull - @Override - public String getAppDefaultChannelId() { - return "IDEA10EAP"; - } - @Override public void setKnownChannelIds(List ids) { knowsChannels = ids; 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 bd8591441aa1..84e328ac1218 100644 --- a/platform/platform-impl/testSrc/com/intellij/ide/updates/UpdateStrategyTest.java +++ b/platform/platform-impl/testSrc/com/intellij/ide/updates/UpdateStrategyTest.java @@ -26,33 +26,19 @@ public class UpdateStrategyTest extends TestCase { //could be if somebody used before previous version of IDEA public void testWithUndefinedSelection() { - final TestUpdateSettings settings = new TestUpdateSettings(ChannelStatus.EAP, false, null); + final TestUpdateSettings settings = new TestUpdateSettings(ChannelStatus.EAP, false); //first time load UpdateStrategy strategy = new UpdateStrategy(9, BuildNumber.fromString("IU-98.520"), UpdatesInfoXppParserTest.InfoReader.read("idea-same.xml"), settings); final CheckForUpdateResult result1 = strategy.checkForUpdates(); Assert.assertEquals(UpdateStrategy.State.LOADED, result1.getState()); Assert.assertNull(result1.getNewBuildInSelectedChannel()); - - /* - settings.setSelectedChannelId(result1.getSelected().getId()); - - //second time load - strategy = new UpdateStrategy(BuildNumber.fromString("IU-98.520"), UpdatesInfoXppParserTest.InfoReader.read("idea-same.xml"), settings); - - - final CheckForUpdateResult result2 = strategy.checkForUpdates(); - Assert.assertEquals(UpdateStrategy.State.LOADED, result2.getState()); - Assert.assertFalse(result2.isReplacedWithAppDef()); - Assert.assertNull(result2.getNewBuildInSelectedChannel()); - Assert.assertEquals(settings.getAppDefaultChannelId(), settings.getSelectedChannelId()); - */ } public void testWithUserSelection() { //assume user has version 9 eap - and used eap channel - we want to introduce new eap - final TestUpdateSettings settings = new TestUpdateSettings(ChannelStatus.EAP, true, null); + final TestUpdateSettings settings = new TestUpdateSettings(ChannelStatus.EAP, true); //first time load UpdateStrategy strategy = new UpdateStrategy(9, BuildNumber.fromString("IU-95.429"), UpdatesInfoXppParserTest.InfoReader.read("idea-new9eap.xml"), settings); @@ -66,7 +52,7 @@ public class UpdateStrategyTest extends TestCase { public void testNewChannelAppears() { // assume user has version 9 eap subscription (default or selected) // and new channel appears - eap of version 10 is there - final TestUpdateSettings settings = new TestUpdateSettings(ChannelStatus.EAP, true, null); + final TestUpdateSettings settings = new TestUpdateSettings(ChannelStatus.EAP, true); //first time load UpdateStrategy strategy = new UpdateStrategy(9, BuildNumber.fromString("IU-95.627"), UpdatesInfoXppParserTest.InfoReader.read("idea-newChannel.xml"), settings); @@ -76,7 +62,7 @@ public class UpdateStrategyTest extends TestCase { final BuildInfo update = result.getNewBuildInSelectedChannel(); Assert.assertNull(update); - final UpdateChannel newChannel = result.getNewChannelToPropose(); + final UpdateChannel newChannel = result.getChannelToPropose(); Assert.assertNotNull(newChannel); Assert.assertEquals("IDEA10EAP", newChannel.getId()); Assert.assertEquals("IntelliJ IDEA X EAP", newChannel.getName()); @@ -87,7 +73,7 @@ public class UpdateStrategyTest extends TestCase { //and new channels appears - eap of version 10 is there //and new build withing old channel appears also //we need to show only one dialog - final TestUpdateSettings settings = new TestUpdateSettings(ChannelStatus.EAP, true, null); + final TestUpdateSettings settings = new TestUpdateSettings(ChannelStatus.EAP, true); //first time load UpdateStrategy strategy = new UpdateStrategy(9, BuildNumber.fromString("IU-95.429"), UpdatesInfoXppParserTest.InfoReader.read("idea-newChannel.xml"), settings); @@ -97,7 +83,7 @@ public class UpdateStrategyTest extends TestCase { Assert.assertNotNull(update); Assert.assertEquals("95.627", update.getNumber().toString()); - final UpdateChannel newChannel = result.getNewChannelToPropose(); + final UpdateChannel newChannel = result.getChannelToPropose(); Assert.assertNotNull(newChannel); Assert.assertEquals("IDEA10EAP", newChannel.getId()); Assert.assertEquals("IntelliJ IDEA X EAP", newChannel.getName()); diff --git a/platform/platform-impl/testSrc/com/intellij/ide/updates/idea-newChannel.xml b/platform/platform-impl/testSrc/com/intellij/ide/updates/idea-newChannel.xml index 3b4681cdeceb..0404bc4f42e4 100644 --- a/platform/platform-impl/testSrc/com/intellij/ide/updates/idea-newChannel.xml +++ b/platform/platform-impl/testSrc/com/intellij/ide/updates/idea-newChannel.xml @@ -3,7 +3,7 @@ IU IC - @@ -14,7 +14,8 @@ - + IntelliJ IDEA 9.0.4 is available. Please visit http://www.jetbrains.com/idea to learn more and download it. @@ -23,7 +24,8 @@ - + IntelliJ IDEA X RC is available. Please visit http://confluence.jetbrains.net/display/IDEADEV/IDEA+X+EAP to learn more and download it.