new channel

This commit is contained in:
Dmitry Jemerov
2011-03-04 19:33:30 +01:00
parent 2c2b93c231
commit d563c9d46c
8 changed files with 62 additions and 160 deletions
@@ -70,4 +70,9 @@ public class BuildInfo implements Comparable<BuildInfo> {
}
return null;
}
@Override
public String toString() {
return "BuildInfo(number=" + myNumber + ")";
}
}
@@ -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<UpdateChannel> newChannels;
@NotNull
private final Collection<UpdateChannel> myNewChannels;
@Nullable
private final List<String> 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<UpdateChannel> newChannels, List<String> allChannelsIds,
@Nullable UpdateChannel channelToPropose) {
List<String> allChannelsIds) {
this.newBuildInSelectedChannel = newBuildInSelectedChannel;
myUpdatedChannel = updated;
this.newChannels = newChannels;
myNewChannels = new ArrayList<UpdateChannel>();
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<UpdateChannel> 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
@@ -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<Element>, UserUp
return !CHECK_NEEDED;
}
@NotNull
@Override
public List<String> getKnownChannelsIds() {
if (myKnownUpdateChannels==null){
return null;
}
List<String> ids = new ArrayList<String>();
for (String channel : myKnownUpdateChannels) {
ids.add(channel);
@@ -96,12 +93,6 @@ public class UpdateSettings implements PersistentStateComponent<Element>, UserUp
return ids;
}
@NotNull
@Override
public String getAppDefaultChannelId() {
return ApplicationInfo.getInstance().getDefaultUpdateChannel();
}
@Override
public void setKnownChannelIds(List<String> ids) {
myKnownUpdateChannels.clear();
@@ -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.<String>emptyList(), null);
CheckForUpdateResult result = new CheckForUpdateResult(updatedChannel, newBuild, Collections.<String>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<List<UpdateChannel>, 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<UpdateChannel> getActiveChannels(Product product) {
@@ -105,81 +95,10 @@ public class UpdateStrategy {
return result;
}
@Nullable
private List<String> getFilteredKnownChannels(@NotNull Product product) {
List<String> result = new ArrayList<String>();
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<List<UpdateChannel>, UpdateChannel> getNewChannels(@NotNull Product product) {
List<String> knownChannels =
updateSettings.getKnownChannelsIds() != null ? updateSettings.getKnownChannelsIds() : Collections.<String>emptyList();
UpdateChannel versionUpgradeChannel = null;
List<UpdateChannel> newChannels = new ArrayList<UpdateChannel>();
final List<UpdateChannel> 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<List<UpdateChannel>, 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();
}
}
@@ -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<String> getKnownChannelsIds();
@NotNull
String getAppDefaultChannelId();
void setKnownChannelIds(List<String> ids);
@NotNull
@@ -28,10 +28,10 @@ public class TestUpdateSettings implements UserUpdateSettings {
private boolean disabled;
private List<String> 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<String> getKnownChannelsIds() {
return knowsChannels;
}
@NotNull
@Override
public String getAppDefaultChannelId() {
return "IDEA10EAP";
}
@Override
public void setKnownChannelIds(List<String> ids) {
knowsChannels = ids;
@@ -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());
@@ -3,7 +3,7 @@
<code>IU</code>
<code>IC</code>
<channel id="maiaEAP" name="IntelliJ IDEA 9 updates" status="release"
<channel id="maiaEAP" name="IntelliJ IDEA 9 updates" status="release" majorVersion="9"
url="http://www.jetbrains.com/idea/whatsnew"
feedback="http://youtrack.jetbrains.net">
<build number="95.627" version="9.0.4">
@@ -14,7 +14,8 @@
</build>
</channel>
<channel id="idea90" name="IntelliJ IDEA 9 updates" status="release" url="http://www.jetbrains.com/idea/whatsnew">
<channel id="idea90" name="IntelliJ IDEA 9 updates" status="release" majorVersion="9"
url="http://www.jetbrains.com/idea/whatsnew">
<build number="95.627" version="9.0.4">
<message>IntelliJ IDEA 9.0.4 is available.
Please visit http://www.jetbrains.com/idea to learn more and download it.
@@ -23,7 +24,8 @@
</build>
</channel>
<channel id="IDEA10EAP" name="IntelliJ IDEA X EAP" status="eap" url="http://confluence.jetbrains.net/display/IDEADEV/IDEA+X+EAP">
<channel id="IDEA10EAP" name="IntelliJ IDEA X EAP" status="eap" majorVersion="10"
url="http://confluence.jetbrains.net/display/IDEADEV/IDEA+X+EAP">
<build number="98.520" version="10">
<message>IntelliJ IDEA X RC is available.
Please visit http://confluence.jetbrains.net/display/IDEADEV/IDEA+X+EAP to learn more and download it.