diff --git a/platform/platform-impl/src/com/intellij/remote/RemoteProcessUtil.java b/platform/platform-impl/src/com/intellij/remote/RemoteProcessUtil.java
index 9adff3320852..0f75c040648a 100644
--- a/platform/platform-impl/src/com/intellij/remote/RemoteProcessUtil.java
+++ b/platform/platform-impl/src/com/intellij/remote/RemoteProcessUtil.java
@@ -1,7 +1,6 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.remote;
-import com.google.common.base.Joiner;
import com.intellij.util.AbstractPathMapper;
import com.intellij.util.ArrayUtilRt;
import com.intellij.util.PathMapper;
@@ -30,6 +29,6 @@ public final class RemoteProcessUtil {
for (String path : pathsValue.split(File.pathSeparator)) {
mappedPaths.add(RemoteFile.createRemoteFile(pathMapper.convertToRemote(path), isWin).getPath());
}
- return Joiner.on(isWin ? ';' : ':').join(mappedPaths);
+ return String.join(isWin ? ";" : ":", mappedPaths);
}
}
diff --git a/platform/remote-core/src/remote/RemoteCredentials.java b/platform/remote-core/src/remote/RemoteCredentials.java
index 5e8fa4a839db..304f750c6c44 100644
--- a/platform/remote-core/src/remote/RemoteCredentials.java
+++ b/platform/remote-core/src/remote/RemoteCredentials.java
@@ -1,4 +1,4 @@
-// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.remote;
import com.intellij.openapi.util.NlsSafe;
@@ -45,15 +45,15 @@ public interface RemoteCredentials {
}
/**
- * By default when user connects to a remote server, host fingerprint should be verified via
- *
~/.ssh/known_hosts
file and user should explicitly confirm connection if he never
- * connected to the remote host before. When remote host is trusted regardless of known hosts file
+ * By default, when a user connects to a remote server, host fingerprint should be verified via
+ * ~/.ssh/known_hosts
file and a user should explicitly confirm connection if they never
+ * connected to the remote host before.
+ * When a remote host is trusted regardless of known hosts file
* (for example, when connecting to Vagrant VM), confirmation should be skipped.
*
- * @return true if host key verification should be skipped.
- *
- * TODO Replace with {@link #getConnectionConfigPatch()}.
+ * @return {@code true} if host key verification should be skipped.
*/
+ // TODO Replace with {@link #getConnectionConfigPatch()}.
default boolean isSkippingHostKeyVerification() {
return false;
}
diff --git a/platform/remote-core/src/remote/RemoteCredentialsHolder.java b/platform/remote-core/src/remote/RemoteCredentialsHolder.java
index 0c34b3f7d2a4..bacb662d8262 100644
--- a/platform/remote-core/src/remote/RemoteCredentialsHolder.java
+++ b/platform/remote-core/src/remote/RemoteCredentialsHolder.java
@@ -36,17 +36,17 @@ public class RemoteCredentialsHolder implements MutableRemoteCredentials {
private static final Map CREDENTIAL_ATTRIBUTES_QUALIFIERS =
Map.of(AuthType.PASSWORD, "password", AuthType.KEY_PAIR, "passphrase", AuthType.OPEN_SSH, "empty");
- private @NotNull String myHost = "";
- private int myPort;//will always be equal to myLiteralPort, if it's valid, or equal to 0 otherwise
- private @NotNull String myLiteralPort = "";
+ private String myHost = "";
+ private int myPort; // will always be equal to `myLiteralPort` if it's valid, or to 0 otherwise
+ private String myLiteralPort = "";
private @Nullable String myUserName;
private @Nullable String myPassword;
- private @NotNull String myPrivateKeyFile = "";
+ private String myPrivateKeyFile = "";
private @Nullable String myPassphrase;
private boolean myStorePassword;
private boolean myStorePassphrase;
private boolean myUseOpenSSHConfig;
- private @NotNull AuthType myAuthType = AuthType.PASSWORD;
+ private AuthType myAuthType = AuthType.PASSWORD;
private @Nullable SshConnectionConfigPatch myConnectionConfigPatch;
public RemoteCredentialsHolder() {}
@@ -99,9 +99,8 @@ public class RemoteCredentialsHolder implements MutableRemoteCredentials {
}
@Override
- @Nullable
@Transient
- public String getUserName() {
+ public @Nullable String getUserName() {
return myUserName;
}
@@ -171,9 +170,8 @@ public class RemoteCredentialsHolder implements MutableRemoteCredentials {
myPassphrase = StringUtil.notNullize(passphrase);
}
- @NotNull
@Override
- public AuthType getAuthType() {
+ public @NotNull AuthType getAuthType() {
return myAuthType;
}
@@ -182,9 +180,8 @@ public class RemoteCredentialsHolder implements MutableRemoteCredentials {
myAuthType = authType;
}
- @Nullable
@Override
- public SshConnectionConfigPatch getConnectionConfigPatch() {
+ public @Nullable SshConnectionConfigPatch getConnectionConfigPatch() {
return myConnectionConfigPatch;
}
@@ -265,8 +262,8 @@ public class RemoteCredentialsHolder implements MutableRemoteCredentials {
myAuthType = AuthType.PASSWORD;
}
// try to load credentials from PasswordSafe
- final CredentialAttributes attributes = createAttributes(false);
- final Credentials credentials = PasswordSafe.getInstance().get(attributes);
+ CredentialAttributes attributes = createAttributes(false);
+ Credentials credentials = PasswordSafe.getInstance().get(attributes);
if (credentials != null) {
final boolean memoryOnly = PasswordSafe.getInstance().isPasswordStoredOnlyInMemory(attributes, credentials);
if (myAuthType == AuthType.KEY_PAIR) {
@@ -313,29 +310,22 @@ public class RemoteCredentialsHolder implements MutableRemoteCredentials {
// the old `USE_AUTH_AGENT` attribute is used to avoid settings migration
rootElement.setAttribute(USE_AUTH_AGENT, Boolean.toString(myAuthType == AuthType.OPEN_SSH));
- boolean memoryOnly = (myAuthType == AuthType.KEY_PAIR && !isStorePassphrase())
- || (myAuthType == AuthType.PASSWORD && !isStorePassword())
- || myAuthType == AuthType.OPEN_SSH;
- String password;
- if (myAuthType == AuthType.KEY_PAIR) {
- password = getPassphrase();
- }
- else if (myAuthType == AuthType.PASSWORD) {
- password = getPassword();
- }
- else {
- password = null;
- }
+ boolean memoryOnly = myAuthType == AuthType.KEY_PAIR && !isStorePassphrase() ||
+ myAuthType == AuthType.PASSWORD && !isStorePassword() ||
+ myAuthType == AuthType.OPEN_SSH;
+ String password = switch (myAuthType) {
+ case KEY_PAIR -> getPassphrase();
+ case PASSWORD -> getPassword();
+ default -> null;
+ };
PasswordSafe.getInstance().set(createAttributes(memoryOnly), new Credentials(getUserName(), password));
// getConnectionConfigPatch() is omitted intentionally.
// It's expected that the options will be set with SSH settings by one of `copyTo` calls.
}
- @NotNull
private CredentialAttributes createAttributes(boolean memoryOnly) {
- final String serviceName =
- SERVICE_NAME_PREFIX + getCredentialsString(this) + "(" + CREDENTIAL_ATTRIBUTES_QUALIFIERS.get(myAuthType) + ")";
+ String serviceName = SERVICE_NAME_PREFIX + getCredentialsString(this) + '(' + CREDENTIAL_ATTRIBUTES_QUALIFIERS.get(myAuthType) + ')';
return new CredentialAttributes(serviceName, getUserName(), null, memoryOnly);
}
diff --git a/python/src/com/jetbrains/python/remote/PyCommandLineStateUtil.java b/python/src/com/jetbrains/python/remote/PyCommandLineStateUtil.java
index d282b3c00605..cee999069ff7 100644
--- a/python/src/com/jetbrains/python/remote/PyCommandLineStateUtil.java
+++ b/python/src/com/jetbrains/python/remote/PyCommandLineStateUtil.java
@@ -18,46 +18,34 @@ import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
-/**
- * @author Alexander Koshevoy
- */
+@SuppressWarnings("SameParameterValue")
public final class PyCommandLineStateUtil {
- // the environment variable used by BDD to hold set of folder or feature files
+ // the environment variable used by BDD to hold a set of folder or feature files
private static final String PY_STUFF_TO_RUN = "PY_STUFF_TO_RUN";
- private PyCommandLineStateUtil() {
- }
+ private PyCommandLineStateUtil() { }
- public static void remap(@NotNull PyRemoteSdkCredentials data,
- @NotNull GeneralCommandLine commandLine,
- @NotNull PathMapper pathMapper) {
+ public static void remap(@NotNull PyRemoteSdkCredentials data, @NotNull GeneralCommandLine commandLine, @NotNull PathMapper pathMapper) {
remap(data.getInterpreterPath(), commandLine, pathMapper);
}
- public static void remap(@NotNull String interpreterPath,
- @NotNull GeneralCommandLine commandLine,
- @NotNull PathMapper pathMapper) {
- remapParams(interpreterPath, commandLine, pathMapper);
+ public static void remap(@NotNull String interpreterPath, @NotNull GeneralCommandLine commandLine, @NotNull PathMapper pathMapper) {
+ ParamsGroup paramsGroup = commandLine.getParametersList().getParamsGroup(PythonCommandLineState.GROUP_SCRIPT);
+ remapParameters(interpreterPath, pathMapper, paramsGroup, commandLine.getWorkDirectory());
remapEnvPaths(commandLine.getEnvironment(), pathMapper, interpreterPath, PythonEnvUtil.PYTHONPATH);
remapEnvPaths(commandLine.getEnvironment(), pathMapper, interpreterPath, PyDebugRunner.IDE_PROJECT_ROOTS);
remapEnvStuffPaths(commandLine.getEnvironment(), pathMapper, interpreterPath, PY_STUFF_TO_RUN);
}
- private static void remapParams(@NotNull String interpreterPath,
- @NotNull GeneralCommandLine commandLine,
- @NotNull PathMapper pathMapper) {
- ParamsGroup paramsGroup = commandLine.getParametersList().getParamsGroup(PythonCommandLineState.GROUP_SCRIPT);
-
- remapParameters(interpreterPath, pathMapper, paramsGroup, commandLine.getWorkDirectory());
- }
-
- public static void remapParameters(@NotNull String interpreterPath,
- @NotNull PathMapper pathMapper,
- @Nullable ParamsGroup paramsGroup,
- @Nullable File workDirectory) {
+ public static void remapParameters(
+ @NotNull String interpreterPath,
+ @NotNull PathMapper pathMapper,
+ @Nullable ParamsGroup paramsGroup,
+ @Nullable File workDirectory
+ ) {
if (paramsGroup != null) {
- if (paramsGroup.getParameters().size() > 0) {
+ if (!paramsGroup.getParameters().isEmpty()) {
makeParamAbsoluteIfRelative(paramsGroup, 0, workDirectory);
}
@@ -71,9 +59,7 @@ public final class PyCommandLineStateUtil {
}
}
- private static void makeParamAbsoluteIfRelative(@NotNull ParamsGroup paramsGroup,
- int paramIndex,
- @Nullable File workDirectory) {
+ private static void makeParamAbsoluteIfRelative(ParamsGroup paramsGroup, int paramIndex, @Nullable File workDirectory) {
String param = paramsGroup.getParameters().get(paramIndex);
if (!new File(param).isAbsolute() && workDirectory != null) {
File paramFile = new File(workDirectory, param);
@@ -83,23 +69,16 @@ public final class PyCommandLineStateUtil {
}
}
- private static void remapEnvPaths(@NotNull Map env,
- @NotNull PathMapper pathMapper,
- @NotNull String interpreterPath,
- @NotNull String envKey) {
+ private static void remapEnvPaths(Map env, PathMapper pathMapper, String interpreterPath, String envKey) {
if (env.isEmpty()) return;
String envPaths = env.get(envKey);
-
if (envPaths != null) {
env.put(envKey, RemoteProcessUtil.remapPathsList(envPaths, pathMapper, interpreterPath));
}
}
- private static void remapEnvStuffPaths(@NotNull Map env,
- @NotNull PathMapper pathMapper,
- @NotNull String interpreterPath,
- @NotNull String envKey) {
+ private static void remapEnvStuffPaths(Map env, PathMapper pathMapper, String interpreterPath, String envKey) {
String envPaths = env.get(envKey);
if (envPaths != null) {
env.put(envKey, remapStuffPathsList(envPaths, pathMapper, interpreterPath));
diff --git a/python/src/com/jetbrains/python/remote/PyRemoteCommandLineStateUtil.java b/python/src/com/jetbrains/python/remote/PyRemoteCommandLineStateUtil.java
index 38245dff33c9..1d5d57ee1d39 100644
--- a/python/src/com/jetbrains/python/remote/PyRemoteCommandLineStateUtil.java
+++ b/python/src/com/jetbrains/python/remote/PyRemoteCommandLineStateUtil.java
@@ -16,8 +16,7 @@ import java.io.File;
* Use {@link PyRemoteCommandLinePatcherKt} instead
*/
public final class PyRemoteCommandLineStateUtil {
- private PyRemoteCommandLineStateUtil() {
- }
+ private PyRemoteCommandLineStateUtil() { }
/**
* Patches the debug parameters of PyCharm debugger script when it is run in
@@ -48,10 +47,8 @@ public final class PyRemoteCommandLineStateUtil {
) throws RemoteSdkException {
debugParams.getParametersList().set(0, RemoteFile.createRemoteFile(helpersPath, PyDebugRunner.DEBUGGER_MAIN).getPath());
- Pair socket = remoteSocketProvider.getRemoteSocket(Integer.parseInt(debugParams.getParametersList()
- .get(PyDebugRunner.findIndex(
- debugParams.getParameters(),
- PyDebugRunner.PORT_PARAM))));
+ int port = Integer.parseInt(debugParams.getParametersList().get(PyDebugRunner.findIndex(debugParams.getParameters(),PyDebugRunner.PORT_PARAM)));
+ Pair socket = remoteSocketProvider.getRemoteSocket(port);
int clientParamIndex = PyDebugRunner.findIndex(debugParams.getParameters(), PyDebugRunner.CLIENT_PARAM);
if (clientParamIndex != -1) {
@@ -62,30 +59,27 @@ public final class PyRemoteCommandLineStateUtil {
.set(PyDebugRunner.findIndex(debugParams.getParameters(), PyDebugRunner.PORT_PARAM), Integer.toString(socket.getSecond()));
}
- public static void patchProfileParams(@NotNull String interpreterPath,
- @NotNull PyRemoteSocketToLocalHostProvider remoteSocketProvider,
- @NotNull ParamsGroup profileParams,
- @Nullable File workDirectory,
- @NotNull PathMapper pathMapper)
- throws RemoteSdkException {
+ public static void patchProfileParams(
+ @NotNull String interpreterPath,
+ @NotNull PyRemoteSocketToLocalHostProvider remoteSocketProvider,
+ @NotNull ParamsGroup profileParams,
+ @Nullable File workDirectory,
+ @NotNull PathMapper pathMapper
+ ) throws RemoteSdkException {
PyCommandLineStateUtil.remapParameters(interpreterPath, pathMapper, profileParams, workDirectory);
- Pair socket = remoteSocketProvider.getRemoteSocket(Integer.parseInt(profileParams.getParametersList()
- .get(2)));
+ Pair socket = remoteSocketProvider.getRemoteSocket(Integer.parseInt(profileParams.getParametersList().get(2)));
- profileParams.getParametersList()
- .set(1, socket.getFirst());
-
-
- profileParams.getParametersList()
- .set(2, Integer.toString(socket.getSecond()));
+ profileParams.getParametersList().set(1, socket.getFirst());
+ profileParams.getParametersList().set(2, Integer.toString(socket.getSecond()));
}
- public static void patchCoverageParams(@NotNull String interpreterPath,
- @NotNull ParamsGroup coverageParams,
- @Nullable File workDirectory,
- @NotNull PathMapper pathMapper) {
-
+ public static void patchCoverageParams(
+ @NotNull String interpreterPath,
+ @NotNull ParamsGroup coverageParams,
+ @Nullable File workDirectory,
+ @NotNull PathMapper pathMapper
+ ) {
PyCommandLineStateUtil.remapParameters(interpreterPath, pathMapper, coverageParams, workDirectory);
int i = 0;