From cf84f62e3dc1fca0b61444c1a5331d39c50fcd9d Mon Sep 17 00:00:00 2001 From: nik Date: Fri, 21 Aug 2015 13:56:06 +0300 Subject: [PATCH] customize update strategy in Android Studio --- .../UpdateStrategyCustomization.java | 38 +++++++++++++++++++ .../updateSettings/impl/UpdateSettings.java | 5 ++- .../updateSettings/impl/UpdateStrategy.java | 20 +++++++--- .../src/META-INF/PlatformExtensions.xml | 1 + 4 files changed, 56 insertions(+), 8 deletions(-) create mode 100644 platform/platform-impl/src/com/intellij/openapi/updateSettings/UpdateStrategyCustomization.java diff --git a/platform/platform-impl/src/com/intellij/openapi/updateSettings/UpdateStrategyCustomization.java b/platform/platform-impl/src/com/intellij/openapi/updateSettings/UpdateStrategyCustomization.java new file mode 100644 index 000000000000..698139fb9ee3 --- /dev/null +++ b/platform/platform-impl/src/com/intellij/openapi/updateSettings/UpdateStrategyCustomization.java @@ -0,0 +1,38 @@ +/* + * Copyright 2000-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.openapi.updateSettings; + +import com.intellij.openapi.components.ServiceManager; + +/** + * Override this service in your IDE to customize update behavior. It isn't supposed to be overriden in plugins. + */ +public class UpdateStrategyCustomization { + public static UpdateStrategyCustomization getInstance() { + return ServiceManager.getService(UpdateStrategyCustomization.class); + } + + public boolean forceEapUpdateChannelForEapBuilds() { + return true; + } + + /** + * Whether the updater will allow patch updates to cross major version boundaries. + */ + public boolean allowMajorVersionUpdate() { + return false; + } +} 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 b693bbf23b63..f032bdd57038 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 @@ -18,6 +18,7 @@ package com.intellij.openapi.updateSettings.impl; import com.intellij.openapi.application.ApplicationInfo; import com.intellij.openapi.application.impl.ApplicationInfoImpl; import com.intellij.openapi.components.*; +import com.intellij.openapi.updateSettings.UpdateStrategyCustomization; import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.SmartList; import com.intellij.util.containers.ContainerUtil; @@ -106,7 +107,7 @@ public class UpdateSettings implements PersistentStateComponent channels = product.getChannels(); List result = new ArrayList(); for (UpdateChannel channel : channels) { - if ((channel.getMajorVersion() == myMajorVersion && channel.getStatus().compareTo(myChannelStatus) >= 0) || - (channel.getMajorVersion() > myMajorVersion && channel.getStatus() == ChannelStatus.EAP && myChannelStatus == ChannelStatus.EAP)) { - if (channel.getMajorVersion() == myMajorVersion && channel.getStatus().compareTo(myChannelStatus) == 0) { - result.add(0, channel); // prefer channel that has same status as our selected channel status - } else { - result.add(channel); + + // If the update is to a new version and on a stabler channel, choose it. + if ((channel.getMajorVersion() >= myMajorVersion && channel.getStatus().compareTo(myChannelStatus) >= 0)) { + if (UpdateStrategyCustomization.getInstance().allowMajorVersionUpdate() + || channel.getMajorVersion() == myMajorVersion + || channel.getStatus() == ChannelStatus.EAP && myChannelStatus == ChannelStatus.EAP) { + // Prefer channel that has same status as our selected channel status + if (channel.getMajorVersion() == myMajorVersion && channel.getStatus().compareTo(myChannelStatus) == 0) { + result.add(0, channel); + } + else { + result.add(channel); + } } } } diff --git a/platform/platform-resources/src/META-INF/PlatformExtensions.xml b/platform/platform-resources/src/META-INF/PlatformExtensions.xml index f3807dc10c13..38405b1b9f09 100644 --- a/platform/platform-resources/src/META-INF/PlatformExtensions.xml +++ b/platform/platform-resources/src/META-INF/PlatformExtensions.xml @@ -134,6 +134,7 @@ serviceImplementation="com.intellij.openapi.editor.impl.EditorActionManagerImpl"/> +