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.util.text.StringUtil;
22 import com.intellij.util.SmartList;
23 import com.intellij.util.containers.ContainerUtil;
24 import com.intellij.util.net.NetUtils;
25 import com.intellij.util.xmlb.annotations.CollectionBean;
26 import org.jetbrains.annotations.NotNull;
27 import org.jetbrains.annotations.Nullable;
29 import java.util.ArrayList;
30 import java.util.List;
33 name = "UpdatesConfigurable",
35 @Storage(file = StoragePathMacros.APP_CONFIG + "/updates.xml", roamingType = RoamingType.DISABLED),
36 @Storage(file = StoragePathMacros.APP_CONFIG + "/other.xml", deprecated = true)
39 public class UpdateSettings implements PersistentStateComponent<UpdateSettings.State>, UserUpdateSettings {
40 public static class State {
41 @CollectionBean public final List<String> pluginHosts = new SmartList<String>();
42 @CollectionBean public final List<String> knownUpdateChannels = new SmartList<String>();
43 @CollectionBean public final List<String> ignoredBuildNumbers = new SmartList<String>();
44 @CollectionBean public final List<String> outdatedPlugins = new SmartList<String>();
46 public boolean CHECK_NEEDED = true;
47 public long LAST_TIME_CHECKED = 0;
49 public String LAST_BUILD_CHECKED;
50 public String UPDATE_CHANNEL_TYPE = ChannelStatus.RELEASE_CODE;
51 public boolean SECURE_CONNECTION = true;
54 public static UpdateSettings getInstance() {
55 return ServiceManager.getService(UpdateSettings.class);
58 private State myState = new State();
60 public UpdateSettings() {
61 updateDefaultChannel();
65 public String getLasBuildChecked() {
66 return myState.LAST_BUILD_CHECKED;
70 public List<String> getStoredPluginHosts() {
71 return myState.pluginHosts;
74 public boolean isCheckNeeded() {
75 return myState.CHECK_NEEDED;
78 public void setCheckNeeded(boolean value) {
79 myState.CHECK_NEEDED = value;
82 public boolean isSecureConnection() {
83 return myState.SECURE_CONNECTION;
86 public void setSecureConnection(boolean value) {
87 myState.SECURE_CONNECTION = value;
91 public String getUpdateChannelType() {
92 return myState.UPDATE_CHANNEL_TYPE;
95 public long getLastTimeChecked() {
96 return myState.LAST_TIME_CHECKED;
99 public void setUpdateChannelType(@NotNull String value) {
100 myState.UPDATE_CHANNEL_TYPE = value;
104 public List<String> getOutdatedPlugins() {
105 return myState.outdatedPlugins;
108 private void updateDefaultChannel() {
109 if (ApplicationInfoImpl.getShadowInstance().isEAP()) {
110 myState.UPDATE_CHANNEL_TYPE = ChannelStatus.EAP_CODE;
116 public State getState() {
121 public void loadState(@NotNull State state) {
123 myState.LAST_BUILD_CHECKED = StringUtil.nullize(myState.LAST_BUILD_CHECKED);
124 updateDefaultChannel();
129 public List<String> getKnownChannelsIds() {
130 return new ArrayList<String>(myState.knownUpdateChannels);
134 public void setKnownChannelIds(@NotNull List<String> ids) {
135 myState.knownUpdateChannels.clear();
136 for (String id : ids) {
137 myState.knownUpdateChannels.add(id);
141 public void forgetChannelId(String id) {
142 myState.knownUpdateChannels.remove(id);
146 public List<String> getIgnoredBuildNumbers() {
147 return myState.ignoredBuildNumbers;
152 public ChannelStatus getSelectedChannelStatus() {
153 return ChannelStatus.fromCode(myState.UPDATE_CHANNEL_TYPE);
156 public List<String> getPluginHosts() {
157 List<String> hosts = new ArrayList<String>(myState.pluginHosts);
158 String pluginHosts = System.getProperty("idea.plugin.hosts");
159 if (pluginHosts != null) {
160 ContainerUtil.addAll(hosts, pluginHosts.split(";"));
165 public void forceCheckForUpdateAfterRestart() {
166 myState.LAST_TIME_CHECKED = 0;
169 public void saveLastCheckedInfo() {
170 myState.LAST_TIME_CHECKED = System.currentTimeMillis();
171 myState.LAST_BUILD_CHECKED = ApplicationInfo.getInstance().getBuild().asString();
174 public boolean canUseSecureConnection() {
175 return myState.SECURE_CONNECTION && NetUtils.isSniEnabled();