public UpdateStrategy( int majorVersion, @NotNull BuildNumber currentBuild, @NotNull UpdatesInfo updatesInfo, @NotNull UserUpdateSettings updateSettings) { myMajorVersion = majorVersion; myUpdatesInfo = updatesInfo; myUpdateSettings = updateSettings; myCurrentBuild = currentBuild; myChannelStatus = updateSettings.getSelectedChannelStatus(); }
private boolean hasNewVersion(@NotNull UpdateChannel channel) { BuildInfo latestBuild = channel.getLatestBuild(); if (latestBuild == null || latestBuild.getNumber() == null || myUpdateSettings .getIgnoredBuildNumbers() .contains(latestBuild.getNumber().asStringWithoutProductCode())) { return false; } return myCurrentBuild.compareTo(latestBuild.getNumber()) < 0; }
public final CheckForUpdateResult checkForUpdates() { final Product product = myUpdatesInfo.getProduct(myCurrentBuild.getProductCode()); if (product == null || product.getChannels().isEmpty()) { return new CheckForUpdateResult(State.NOTHING_LOADED); } UpdateChannel updatedChannel = null; BuildInfo newBuild = null; List<UpdateChannel> activeChannels = getActiveChannels(product); for (UpdateChannel channel : activeChannels) { if (hasNewVersion(channel)) { updatedChannel = channel; newBuild = updatedChannel.getLatestBuild(); break; } } CheckForUpdateResult result = new CheckForUpdateResult(updatedChannel, newBuild, product.getAllChannelIds()); UpdateChannel channelToPropose = null; for (UpdateChannel channel : product.getChannels()) { if (!myUpdateSettings.getKnownChannelsIds().contains(channel.getId()) && channel.getMajorVersion() >= myMajorVersion && channel.getStatus().compareTo(myChannelStatus) >= 0 && hasNewVersion(channel)) { result.addNewChannel(channel); if (channelToPropose == null || isBetter(channelToPropose, channel)) { channelToPropose = channel; } } } result.setChannelToPropose(channelToPropose); return result; }