customize update strategy in Android Studio
authornik <Nikolay.Chashnikov@jetbrains.com>
Fri, 21 Aug 2015 10:56:06 +0000 (13:56 +0300)
committernik <Nikolay.Chashnikov@jetbrains.com>
Fri, 21 Aug 2015 10:56:52 +0000 (13:56 +0300)
platform/platform-impl/src/com/intellij/openapi/updateSettings/UpdateStrategyCustomization.java [new file with mode: 0644]
platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateSettings.java
platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateStrategy.java
platform/platform-resources/src/META-INF/PlatformExtensions.xml

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 (file)
index 0000000..698139f
--- /dev/null
@@ -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;
+  }
+}
index b693bbf23b638c59ca1ddf790ea818d4d60f80a7..f032bdd57038a20db51cdde17ee536998d9ee641 100644 (file)
@@ -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<UpdateSettings.S
   }
 
   private void updateDefaultChannel() {
-    if (ApplicationInfoImpl.getShadowInstance().isEAP()) {
+    if (UpdateStrategyCustomization.getInstance().forceEapUpdateChannelForEapBuilds() && ApplicationInfoImpl.getShadowInstance().isEAP()) {
       myState.UPDATE_CHANNEL_TYPE = ChannelStatus.EAP_CODE;
     }
   }
@@ -174,4 +175,4 @@ public class UpdateSettings implements PersistentStateComponent<UpdateSettings.S
   public boolean canUseSecureConnection() {
     return myState.SECURE_CONNECTION && NetUtils.isSniEnabled();
   }
-}
\ No newline at end of file
+}
index 399168ab35e2b457535b06043e083d009e6908d5..ff98cf2ac71be8a258e84f136c9026e74427323f 100644 (file)
@@ -15,6 +15,7 @@
  */
 package com.intellij.openapi.updateSettings.impl;
 
+import com.intellij.openapi.updateSettings.UpdateStrategyCustomization;
 import com.intellij.openapi.util.BuildNumber;
 import org.jetbrains.annotations.NotNull;
 
@@ -87,12 +88,19 @@ public class UpdateStrategy {
     List<UpdateChannel> channels = product.getChannels();
     List<UpdateChannel> result = new ArrayList<UpdateChannel>();
     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);
+          }
         }
       }
     }
index f3807dc10c13921c2e83812a66f86d763b74996e..38405b1b9f0977a6309602104ca2de3c4bbb77c2 100644 (file)
                         serviceImplementation="com.intellij.openapi.editor.impl.EditorActionManagerImpl"/>
     <applicationService serviceInterface="com.intellij.openapi.updateSettings.impl.UpdateSettings"
                         serviceImplementation="com.intellij.openapi.updateSettings.impl.UpdateSettings"/>
+    <applicationService serviceImplementation="com.intellij.openapi.updateSettings.UpdateStrategyCustomization"/>
     <applicationService serviceInterface="com.intellij.ide.plugins.InstalledPluginsState"
                         serviceImplementation="com.intellij.ide.plugins.InstalledPluginsState"/>
     <applicationService serviceInterface="com.intellij.featureStatistics.FeatureUsageTracker"