Commit f2e9ed46 authored by Viuginov Nickolay's avatar Viuginov Nickolay
Browse files

wip

parent 51e1f703
Showing with 56 additions and 38 deletions
+56 -38
......@@ -174,12 +174,7 @@ public class ProcessListUtil {
}
@Nullable
public static List<ProcessInfo> parseProcessInfos(@NotNull String commandOnly, @NotNull String full) {
return parseMacOutput(commandOnly, full);
}
@Nullable
static List<ProcessInfo> parseMacOutput(@NotNull String commandOnly, @NotNull String full) {
public static List<ProcessInfo> parseMacOutput(@NotNull String commandOnly, @NotNull String full) {
List<MacProcessInfo> commands = doParseMacOutput(commandOnly);
List<MacProcessInfo> fulls = doParseMacOutput(full);
if (commands == null || fulls == null) return null;
......
......@@ -3,6 +3,8 @@ package com.intellij.xdebugger.attach;
import com.intellij.execution.ExecutionException;
import com.intellij.execution.configurations.GeneralCommandLine;
import com.intellij.execution.process.BaseProcessHandler;
import com.intellij.execution.process.CapturingProcessRunner;
import com.intellij.execution.process.ProcessInfo;
import com.intellij.execution.process.ProcessOutput;
import com.intellij.openapi.project.Project;
......@@ -14,28 +16,40 @@ import org.jetbrains.annotations.Nullable;
import java.io.InputStream;
import java.util.Arrays;
/**
* This abstract class represent {@link XAttachHost} with extended functional, such as executing {@link GeneralCommandLine},
* downloading remote files and getting OS of a remote host
*/
@ApiStatus.Experimental
public abstract class EnvironmentAwareHost implements XAttachHost {
private OSType myOSType;
/**
* @param command commandLine to execute on this host
* @param commandLine commandLine to execute on this host
* @return output of the corresponding process
*/
@NotNull
public abstract ProcessOutput execAndGetOutput(@Nullable Project project,
@NotNull GeneralCommandLine command) throws ExecutionException;
public abstract BaseProcessHandler getProcessHandler(@Nullable Project project,
@NotNull GeneralCommandLine commandLine) throws ExecutionException;
@NotNull
public ProcessOutput getProcessOutput(@Nullable Project project,
@NotNull GeneralCommandLine commandLine) throws ExecutionException {
BaseProcessHandler handler = getProcessHandler(project, commandLine);
CapturingProcessRunner runner = new CapturingProcessRunner(handler);
return runner.runProcess();
}
/**
* Retrieves remote file contents stream. May be used to sync parts of the debugged project.
* @param remotePath host-dependent path
*
* @param filePath host-dependent path
* @return stream with file contents or <code>null</code> if the specified file does not exist
* @throws ExecutionException on stream retrieval error
*/
@Nullable
public abstract InputStream getRemoteFile(@NotNull String remotePath) throws ExecutionException;
public abstract InputStream getFile(@NotNull String filePath) throws ExecutionException;
/**
* @return uid of user or -1 if error occurred
......@@ -56,31 +70,28 @@ public abstract class EnvironmentAwareHost implements XAttachHost {
}
}
private int getUidUnix(Project project) throws ExecutionException {
private int getUidUnix(@Nullable Project project) throws ExecutionException {
GeneralCommandLine commandLine = new GeneralCommandLine(Arrays.asList("id", "-u"));
ProcessOutput uidOutput = execAndGetOutput(project, commandLine);
String uid = uidOutput.getStdout().trim();
String uid = getProcessOutput(project, commandLine).getStdout();
try {
return Integer.valueOf(uid);
}
catch (NumberFormatException e) {
throw new ExecutionException("Error while parsing uid");
throw new ExecutionException("Error while parsing uid from " + uid + "\n" + e);
}
}
public OSType getOsType(Project project) throws ExecutionException {
@NotNull
public OSType getOsType(@Nullable Project project) throws ExecutionException {
if (myOSType != null) {
return myOSType;
}
try {
GeneralCommandLine getOsCommandLine = new GeneralCommandLine("uname", "-s");
ProcessOutput getOsOutput = execAndGetOutput(project, getOsCommandLine);
String osString = getOsOutput.getStdout().trim();
final String osString = getProcessOutput(project, getOsCommandLine).getStdout().trim();
OSType osType;
......@@ -98,7 +109,6 @@ public abstract class EnvironmentAwareHost implements XAttachHost {
osType = OSType.UNKNOWN;
break;
}
return myOSType = osType;
}
catch (ExecutionException ex) {
......
......@@ -3,9 +3,10 @@ package com.intellij.xdebugger.attach;
import com.intellij.execution.ExecutionException;
import com.intellij.execution.configurations.GeneralCommandLine;
import com.intellij.execution.process.BaseProcessHandler;
import com.intellij.execution.process.CapturingProcessHandler;
import com.intellij.execution.process.OSProcessUtil;
import com.intellij.execution.process.ProcessInfo;
import com.intellij.execution.process.ProcessOutput;
import com.intellij.execution.util.ExecUtil;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
......@@ -55,15 +56,14 @@ public class LocalAttachHost extends EnvironmentAwareHost {
@NotNull
@Override
public ProcessOutput execAndGetOutput(@Nullable Project project, @NotNull GeneralCommandLine command)
throws ExecutionException {
return ExecUtil.execAndGetOutput(command);
public BaseProcessHandler getProcessHandler(@Nullable Project project, @NotNull GeneralCommandLine commandLine) throws ExecutionException {
return new CapturingProcessHandler(commandLine);
}
@Nullable
@Override
public InputStream getRemoteFile(@NotNull String remotePath) throws ExecutionException {
VirtualFile file = LocalFileSystem.getInstance().findFileByPath(remotePath);
public InputStream getFile(@NotNull String filePath) throws ExecutionException {
VirtualFile file = LocalFileSystem.getInstance().findFileByPath(filePath);
if (file == null) {
return null;
}
......@@ -98,7 +98,7 @@ public class LocalAttachHost extends EnvironmentAwareHost {
private static boolean isSudoNeededUnix(int pid) {
/* TODO actually, if security level is 1 then depending on CAP_SYS_PTRACE or some predefined relationship with
* the target process we might can attach to it without sudo. Thats why we might need pid.
* the target process we might can attach to it without sudo. That's why we might need pid.
*/
return (getPtraceScope() > 0 || !isSameUser(pid));
}
......
......@@ -15,16 +15,11 @@
*/
package com.intellij.xdebugger.attach;
import com.intellij.execution.ExecutionException;
import com.intellij.execution.configurations.GeneralCommandLine;
import com.intellij.execution.process.ProcessInfo;
import com.intellij.execution.process.ProcessOutput;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.InputStream;
import java.util.List;
/**
......
......@@ -16,7 +16,9 @@
package com.intellij.xdebugger.attach;
import com.intellij.openapi.extensions.ExtensionPointName;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import java.util.List;
......@@ -36,6 +38,6 @@ public interface XAttachHostProvider<T extends XAttachHost> {
/**
* @return a list of connections of this type
*/
List<T> getAvailableHosts();
List<T> getAvailableHosts(@NotNull Project project);
}
......@@ -33,13 +33,27 @@ public interface XAttachPresentationGroup<T> {
@NotNull
String getGroupName();
/**
* @deprecated Use {@link #getIcon(Project, Object, UserDataHolder)}
*/
@NotNull
Icon getProcessIcon(@NotNull Project project, @NotNull T info, @NotNull UserDataHolder dataHolder);
/**
* @param dataHolder you may put your specific data into the holder at previous step in method @{@link XAttachDebuggerProvider#getAvailableDebuggers}
* and use it for presentation
* @return an icon to be shown in popup menu for your item
*/
@NotNull
Icon getIcon(@NotNull Project project, @NotNull T info, @NotNull UserDataHolder dataHolder);
default Icon getIcon(@NotNull Project project, @NotNull T info, @NotNull UserDataHolder dataHolder) {
return getProcessIcon(project, info, dataHolder);
}
/**
* @deprecated Use {@link #getItemDisplayText(Project, Object, UserDataHolder)}
*/
@NotNull
String getProcessDisplayText(@NotNull Project project, @NotNull T info, @NotNull UserDataHolder dataHolder);
/**
* @param dataHolder you may put your specific data into the holder at previous step in method @{@link XAttachDebuggerProvider#getAvailableDebuggers}
......@@ -47,7 +61,9 @@ public interface XAttachPresentationGroup<T> {
* @return a text to be shown on your item
*/
@NotNull
String getItemDisplayText(@NotNull Project project, @NotNull T info, @NotNull UserDataHolder dataHolder);
default String getItemDisplayText(@NotNull Project project, @NotNull T info, @NotNull UserDataHolder dataHolder) {
return getProcessDisplayText(project, info, dataHolder);
}
/**
* @param dataHolder you may put your specific data into the holder at previous step in method @{@link XAttachDebuggerProvider#getAvailableDebuggers}
......
......@@ -120,7 +120,7 @@ public class LazyAttachVirtualFS extends VirtualFileSystem {
@Nullable
private static String getFileContent(@NotNull EnvironmentAwareHost host, @NotNull String path) throws ExecutionException {
InputStream stream = host.getRemoteFile(path);
InputStream stream = host.getFile(path);
if (stream == null) {
return null;
}
......
......@@ -147,7 +147,7 @@ public class AttachToProcessAction extends AnAction {
for (XAttachHostProvider hostProvider : hostProviders) {
//noinspection unchecked
List<XAttachHost> settingsList = hostProvider.getAvailableHosts();
List<XAttachHost> settingsList = hostProvider.getAvailableHosts(project);
for (XAttachHost eachSettings : settingsList) {
groupWithItems.putValue(hostProvider.getPresentationGroup(), Pair.create(eachSettings, hostProvider));
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment