Skip to content

Commit

Permalink
[platform] extracts the enumeration of external update managers into …
Browse files Browse the repository at this point in the history
…a separate class
  • Loading branch information
trespasserw committed Jan 9, 2019
1 parent 3f72367 commit 852a90f
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 56 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.ide.actions;

import com.intellij.execution.ExecutionException;
Expand All @@ -18,6 +18,7 @@
import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.updateSettings.impl.ExternalUpdateManager;
import com.intellij.openapi.util.AtomicNullableLazyValue;
import com.intellij.openapi.util.NullableLazyValue;
import com.intellij.openapi.util.SystemInfo;
Expand Down Expand Up @@ -61,7 +62,7 @@ protected String compute() {
};

public static boolean isAvailable() {
return SystemInfo.isUnix && !PathManager.isSnap() && SystemInfo.hasXdgOpen();
return SystemInfo.isXWindow && !ExternalUpdateManager.isRoaming() && SystemInfo.hasXdgOpen();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.ide.actions;

import com.intellij.execution.ExecutionException;
Expand All @@ -19,6 +19,7 @@
import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.updateSettings.impl.ExternalUpdateManager;
import com.intellij.openapi.util.NullableLazyValue;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.io.FileUtil;
Expand Down Expand Up @@ -50,10 +51,7 @@ public class CreateLauncherScriptAction extends DumbAwareAction {
});

public static boolean isAvailable() {
return SystemInfo.isUnix
&& INTERPRETER_NAME.getValue() != null
&& !PathManager.isSnap()
&& !PathManager.isToolboxApp();
return SystemInfo.isUnix && !ExternalUpdateManager.isRoaming() && INTERPRETER_NAME.getValue() != null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.updateSettings.impl;

import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.util.SystemInfo;
import org.jetbrains.annotations.Nullable;

/**
* Represents a tool which manages IDE updates instead of a built-in update engine.
*/
public enum ExternalUpdateManager {
TOOLBOX("Toolbox"),
SNAP("Snap"),
UNKNOWN(System.getProperty("ide.no.platform.update"));

public final String toolName;

ExternalUpdateManager(String name) {
toolName = "true".equalsIgnoreCase(name) ? "(unknown)" : name;
}

/**
* Returns a tool managing this IDE instance, or {@code null} when no such tool is detected.
*/
public static final @Nullable ExternalUpdateManager ACTUAL;
static {
String home = PathManager.getHomePath().replace('\\', '/');
if (home.contains("/apps/") && home.contains("/ch-")) ACTUAL = TOOLBOX;
else if (SystemInfo.isLinux && (home.startsWith("/snap/") || home.startsWith("/var/lib/snapd/snap/"))) ACTUAL = SNAP;
else if (System.getProperty("ide.no.platform.update") != null) ACTUAL = UNKNOWN;
else ACTUAL = null;
}

/**
* Returns {@code true} when updates are managed by a tool which install different builds in different directories.
*/
public static boolean isRoaming() {
return ACTUAL == TOOLBOX || ACTUAL == SNAP;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.updateSettings.impl;

import com.intellij.CommonBundle;
Expand Down Expand Up @@ -40,18 +40,18 @@ private class NoUpdatesPanel {

NoUpdatesPanel() {
String app = ApplicationNamesInfo.getInstance().getFullProductName();
String toolName = UpdateSettings.getInstance().getPackageManagerName();
if (toolName == null) {
ExternalUpdateManager manager = ExternalUpdateManager.ACTUAL;
if (manager == null) {
myNothingToUpdateLabel.setText(IdeBundle.message("updates.no.updates.message", app));
}
else if (toolName == UpdateSettings.TOOLBOX_PM) {
else if (manager == ExternalUpdateManager.TOOLBOX) {
myNothingToUpdateLabel.setText(IdeBundle.message("updates.no.updates.toolbox.message", app));
}
else if (toolName == UpdateSettings.SNAP_PM) {
else if (manager == ExternalUpdateManager.SNAP) {
myNothingToUpdateLabel.setText(IdeBundle.message("updates.no.updates.snaps.message", app));
}
else {
myNothingToUpdateLabel.setText(IdeBundle.message("updates.no.updates.unknown.message", app, toolName));
myNothingToUpdateLabel.setText(IdeBundle.message("updates.no.updates.unknown.message", app, manager.toolName));
}
configureMessageArea(myMessageArea);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.updateSettings.impl

import com.intellij.diagnostic.IdeErrorsDialog
Expand Down Expand Up @@ -160,7 +160,7 @@ object UpdateChecker {
try {
var updateUrl = Urls.newFromEncoded(updateUrl)
if (updateUrl.scheme != URLUtil.FILE_PROTOCOL) {
updateUrl = prepareUpdateCheckArgs(updateUrl, settings.packageManagerName)
updateUrl = prepareUpdateCheckArgs(updateUrl)
}
LogUtil.debug(LOG, "load update xml (UPDATE_URL='%s')", updateUrl)

Expand Down Expand Up @@ -464,12 +464,12 @@ object UpdateChecker {
ourAdditionalRequestOptions[name] = value
}

private fun prepareUpdateCheckArgs(url: Url, packageManagerName: String?): Url {
private fun prepareUpdateCheckArgs(url: Url): Url {
addUpdateRequestParameter("build", ApplicationInfo.getInstance().build.asString())
addUpdateRequestParameter("uid", PermanentInstallationID.get())
addUpdateRequestParameter("os", SystemInfo.OS_NAME + ' ' + SystemInfo.OS_VERSION)
if (packageManagerName != null) {
addUpdateRequestParameter("manager", packageManagerName)
if (ExternalUpdateManager.ACTUAL != null) {
addUpdateRequestParameter("manager", ExternalUpdateManager.ACTUAL.toolName)
}
if (ApplicationInfoEx.getInstanceEx().isEAP) {
addUpdateRequestParameter("eap", "")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.updateSettings.impl;

import com.intellij.ide.AppLifecycleListener;
Expand Down Expand Up @@ -31,7 +31,6 @@
import java.io.File;
import java.io.IOException;

import static com.intellij.openapi.application.PathManager.isSnap;
import static java.lang.Math.max;

/**
Expand Down Expand Up @@ -158,7 +157,7 @@ public void cancelChecks() {
}

private void snapPackageNotification(Application app) {
if (!isSnap() || !mySettings.isCheckNeeded()) return;
if (!mySettings.isCheckNeeded() || ExternalUpdateManager.ACTUAL != ExternalUpdateManager.SNAP) return;

app.executeOnPooledThread(() -> {
final BuildNumber currentBuild = ApplicationInfo.getInstance().getBuild();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.updateSettings.impl;

import com.intellij.openapi.application.ApplicationInfo;
import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.components.*;
import com.intellij.openapi.updateSettings.UpdateStrategyCustomization;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.net.NetUtils;
import org.jetbrains.annotations.NotNull;
Expand All @@ -19,23 +17,14 @@

@State(name = "UpdatesConfigurable", storages = @Storage(value = "updates.xml", roamingType = RoamingType.DISABLED, exportable = true))
public class UpdateSettings implements PersistentStateComponent<UpdateOptions> {
public static final String TOOLBOX_PM = "Toolbox";
public static final String SNAP_PM = "Snap";

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

private final String myPackageManager = StringUtil.nullize(System.getProperty("ide.no.platform.update"), true);
private UpdateOptions myState = new UpdateOptions();

public boolean isPlatformUpdateEnabled() {
return getPackageManagerName() == null;
}

@Nullable
public String getPackageManagerName() {
return "true".equalsIgnoreCase(myPackageManager) ? TOOLBOX_PM : PathManager.isSnap() ? SNAP_PM : myPackageManager;
return ExternalUpdateManager.ACTUAL == null;
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.updateSettings.impl;

import com.intellij.ide.DataManager;
Expand Down Expand Up @@ -140,11 +140,11 @@ private static class UpdatesSettingsPanel {
ChannelStatus current = mySettings.getSelectedActiveChannel();
myUpdateChannels.setModel(new CollectionComboBoxModel<>(mySettings.getActiveChannels(), current));

String packageManager = mySettings.getPackageManagerName();
if (packageManager != null) {
ExternalUpdateManager manager = ExternalUpdateManager.ACTUAL;
if (manager != null) {
myCheckForUpdates.setText(IdeBundle.message("updates.settings.checkbox.external"));
myUpdateChannels.setVisible(false);
myChannelWarning.setText(IdeBundle.message("updates.settings.external", packageManager));
myChannelWarning.setText(IdeBundle.message("updates.settings.external", manager.toolName));
myChannelWarning.setForeground(JBColor.GRAY);
myChannelWarning.setVisible(true);
myChannelWarning.setBorder(new JBEmptyBorder(0, 0, 10, 0));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.application;

import com.intellij.openapi.util.Pair;
Expand Down Expand Up @@ -124,23 +124,6 @@ private static boolean isIdeaHome(File root) {
return false;
}

/**
* Check whether IDE is installed via snap packages (https://snapcraft.io/) or not
*/
public static boolean isSnap() {
// On Ubuntu snaps are located in /snap/ directory, but for other distros path is /var/lib/snapd/snap/
return SystemInfo.isLinux &&
(getHomePath().startsWith("/snap/") || getHomePath().startsWith("/var/lib/snapd/snap/"));
}

/**
* Check whether IDE is installed via JetBrains Toolbox App https://toolbox.app
*/
public static boolean isToolboxApp() {
String path = getHomePath().replace('\\', '/');
return path.contains("/apps/") && path.contains("/ch-");
}

private static String[] getBinDirectories(File root) {
List<String> binDirs = ContainerUtil.newSmartList();

Expand Down

0 comments on commit 852a90f

Please sign in to comment.