All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.intellij.openapi.updateSettings.impl.UpdateSettings Maven / Gradle / Ivy

Go to download

A packaging of the IntelliJ Community Edition platform-impl library. This is release number 1 of trunk branch 142.

The newest version!
/*
 * 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.impl;

import com.intellij.openapi.application.ApplicationInfo;
import com.intellij.openapi.application.impl.ApplicationInfoImpl;
import com.intellij.openapi.components.*;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.SmartList;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.net.NetUtils;
import com.intellij.util.xmlb.annotations.CollectionBean;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;

@State(
  name = "UpdatesConfigurable",
  storages = {
    @Storage(file = StoragePathMacros.APP_CONFIG + "/updates.xml", roamingType = RoamingType.DISABLED),
    @Storage(file = StoragePathMacros.APP_CONFIG + "/other.xml", deprecated = true)
  }
)
public class UpdateSettings implements PersistentStateComponent, UserUpdateSettings {
  private State myState = new State();

  public UpdateSettings() {
    updateDefaultChannel();
  }

  public static UpdateSettings getInstance() {
    return ServiceManager.getService(UpdateSettings.class);
  }

  static class State {
    @CollectionBean
    public final List pluginHosts = new SmartList();
    @CollectionBean
    public final List knownUpdateChannels = new SmartList();
    @CollectionBean
    public final List ignoredBuildNumbers = new SmartList();
    @CollectionBean
    public final List outdatedPlugins = new SmartList();

    public boolean CHECK_NEEDED = true;
    public long LAST_TIME_CHECKED = 0;

    public String LAST_BUILD_CHECKED;
    public String UPDATE_CHANNEL_TYPE = ChannelStatus.RELEASE_CODE;
    public boolean SECURE_CONNECTION = false;
  }

  @Nullable
  public String getLasBuildChecked() {
    return myState.LAST_BUILD_CHECKED;
  }

  @NotNull
  public List getStoredPluginHosts() {
    return myState.pluginHosts;
  }

  public boolean isCheckNeeded() {
    return myState.CHECK_NEEDED;
  }

  public void setCheckNeeded(boolean value) {
    myState.CHECK_NEEDED = value;
  }

  public boolean isSecureConnection() {
    return myState.SECURE_CONNECTION;
  }

  public void setSecureConnection(boolean value) {
    myState.SECURE_CONNECTION = value;
  }

  @NotNull
  public String getUpdateChannelType() {
    return myState.UPDATE_CHANNEL_TYPE;
  }

  public long getLastTimeChecked() {
    return myState.LAST_TIME_CHECKED;
  }

  public void setUpdateChannelType(@NotNull String value) {
    myState.UPDATE_CHANNEL_TYPE = value;
  }

  @NotNull
  public List getOutdatedPlugins() {
    return myState.outdatedPlugins;
  }

  private void updateDefaultChannel() {
    if (ApplicationInfoImpl.getShadowInstance().isEAP()) {
      myState.UPDATE_CHANNEL_TYPE = ChannelStatus.EAP_CODE;
    }
  }

  @Override
  public State getState() {
    return myState;
  }

  @Override
  public void loadState(State state) {
    myState = state;
    myState.LAST_BUILD_CHECKED = StringUtil.nullize(myState.LAST_BUILD_CHECKED);
    updateDefaultChannel();
  }

  @NotNull
  @Override
  public List getKnownChannelsIds() {
    return new ArrayList(myState.knownUpdateChannels);
  }

  @Override
  public void setKnownChannelIds(@NotNull List ids) {
    myState.knownUpdateChannels.clear();
    for (String id : ids) {
      myState.knownUpdateChannels.add(id);
    }
  }

  public void forgetChannelId(String id) {
    myState.knownUpdateChannels.remove(id);
  }

  @Override
  public List getIgnoredBuildNumbers() {
    return myState.ignoredBuildNumbers;
  }

  @NotNull
  @Override
  public ChannelStatus getSelectedChannelStatus() {
    return ChannelStatus.fromCode(myState.UPDATE_CHANNEL_TYPE);
  }

  public List getPluginHosts() {
    List hosts = new ArrayList(myState.pluginHosts);
    String pluginHosts = System.getProperty("idea.plugin.hosts");
    if (pluginHosts != null) {
      ContainerUtil.addAll(hosts, pluginHosts.split(";"));
    }
    return hosts;
  }

  public void forceCheckForUpdateAfterRestart() {
    myState.LAST_TIME_CHECKED = 0;
  }

  public void saveLastCheckedInfo() {
    myState.LAST_TIME_CHECKED = System.currentTimeMillis();
    myState.LAST_BUILD_CHECKED = ApplicationInfo.getInstance().getBuild().asString();
  }

  public boolean canUseSecureConnection() {
    return myState.SECURE_CONNECTION && NetUtils.isSniEnabled();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy