2 * Copyright 2000-2015 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.openapi.updateSettings.impl;
18 import com.intellij.openapi.application.ApplicationInfo;
19 import com.intellij.openapi.application.impl.ApplicationInfoImpl;
20 import com.intellij.openapi.components.*;
21 import com.intellij.openapi.updateSettings.UpdateStrategyCustomization;
22 import com.intellij.openapi.util.text.StringUtil;
23 import com.intellij.util.SmartList;
24 import com.intellij.util.containers.ContainerUtil;
25 import com.intellij.util.net.NetUtils;
26 import com.intellij.util.xmlb.annotations.CollectionBean;
27 import org.jetbrains.annotations.NotNull;
28 import org.jetbrains.annotations.Nullable;
30 import java.util.ArrayList;
31 import java.util.List;
34 name = "UpdatesConfigurable",
36 @Storage(file = StoragePathMacros.APP_CONFIG + "/updates.xml", roamingType = RoamingType.DISABLED),
37 @Storage(file = StoragePathMacros.APP_CONFIG + "/other.xml", deprecated = true)
40 public class UpdateSettings implements PersistentStateComponent<UpdateSettings.State>, UserUpdateSettings {
41 public static class State {
42 @CollectionBean public final List<String> pluginHosts = new SmartList<String>();
43 @CollectionBean public final List<String> knownUpdateChannels = new SmartList<String>();
44 @CollectionBean public final List<String> ignoredBuildNumbers = new SmartList<String>();
45 @CollectionBean public final List<String> outdatedPlugins = new SmartList<String>();
47 public boolean CHECK_NEEDED = true;
48 public long LAST_TIME_CHECKED = 0;
50 public String LAST_BUILD_CHECKED;
51 public String UPDATE_CHANNEL_TYPE = ChannelStatus.RELEASE_CODE;
52 public boolean SECURE_CONNECTION = true;
55 public static UpdateSettings getInstance() {
56 return ServiceManager.getService(UpdateSettings.class);
59 private State myState = new State();
61 public UpdateSettings() {
62 updateDefaultChannel();
66 public String getLasBuildChecked() {
67 return myState.LAST_BUILD_CHECKED;
71 public List<String> getStoredPluginHosts() {
72 return myState.pluginHosts;
75 public boolean isCheckNeeded() {
76 return myState.CHECK_NEEDED;
79 public void setCheckNeeded(boolean value) {
80 myState.CHECK_NEEDED = value;
83 public boolean isSecureConnection() {
84 return myState.SECURE_CONNECTION;
87 public void setSecureConnection(boolean value) {
88 myState.SECURE_CONNECTION = value;
92 public String getUpdateChannelType() {
93 return myState.UPDATE_CHANNEL_TYPE;
96 public long getLastTimeChecked() {
97 return myState.LAST_TIME_CHECKED;
100 public void setUpdateChannelType(@NotNull String value) {
101 myState.UPDATE_CHANNEL_TYPE = value;
105 public List<String> getOutdatedPlugins() {
106 return myState.outdatedPlugins;
109 private void updateDefaultChannel() {
110 if (UpdateStrategyCustomization.getInstance().forceEapUpdateChannelForEapBuilds() && ApplicationInfoImpl.getShadowInstance().isEAP()) {
111 myState.UPDATE_CHANNEL_TYPE = ChannelStatus.EAP_CODE;
117 public State getState() {
122 public void loadState(@NotNull State state) {
124 myState.LAST_BUILD_CHECKED = StringUtil.nullize(myState.LAST_BUILD_CHECKED);
125 updateDefaultChannel();
130 public List<String> getKnownChannelsIds() {
131 return new ArrayList<String>(myState.knownUpdateChannels);
135 public void setKnownChannelIds(@NotNull List<String> ids) {
136 myState.knownUpdateChannels.clear();
137 for (String id : ids) {
138 myState.knownUpdateChannels.add(id);
142 public void forgetChannelId(String id) {
143 myState.knownUpdateChannels.remove(id);
147 public List<String> getIgnoredBuildNumbers() {
148 return myState.ignoredBuildNumbers;
153 public ChannelStatus getSelectedChannelStatus() {
154 return ChannelStatus.fromCode(myState.UPDATE_CHANNEL_TYPE);
157 public List<String> getPluginHosts() {
158 List<String> hosts = new ArrayList<String>(myState.pluginHosts);
159 String pluginHosts = System.getProperty("idea.plugin.hosts");
160 if (pluginHosts != null) {
161 ContainerUtil.addAll(hosts, pluginHosts.split(";"));
166 public void forceCheckForUpdateAfterRestart() {
167 myState.LAST_TIME_CHECKED = 0;
170 public void saveLastCheckedInfo() {
171 myState.LAST_TIME_CHECKED = System.currentTimeMillis();
172 myState.LAST_BUILD_CHECKED = ApplicationInfo.getInstance().getBuild().asString();
175 public boolean canUseSecureConnection() {
176 return myState.SECURE_CONNECTION && NetUtils.isSniEnabled();