customize update strategy in Android Studio

This commit is contained in:
nik
2015-08-21 13:56:52 +03:00
parent 1921404bbb
commit cf84f62e3d
4 changed files with 56 additions and 8 deletions
@@ -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;
}
}
@@ -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();
}
}
}
@@ -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);
}
}
}
}
@@ -134,6 +134,7 @@
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"