use of com.intellij.execution.ExecutionException in project intellij-community by JetBrains.
the class RerunFailedActionsTestTools method findRestartActionState.
/**
* Searches for "rerun failed tests" action and fetches state from it
*
* @param descriptor previous run descriptor
* @return state (if found)
*/
@Nullable
public static RunProfileState findRestartActionState(@NotNull final RunContentDescriptor descriptor) {
final ExecutionEnvironment action = findRestartAction(descriptor);
if (action == null) {
return null;
}
final Ref<RunProfileState> stateRef = new Ref<>();
ApplicationManager.getApplication().invokeAndWait(() -> {
try {
stateRef.set(action.getState());
} catch (final ExecutionException e) {
throw new IllegalStateException("Error obtaining execution state", e);
}
}, ModalityState.NON_MODAL);
return stateRef.get();
}
use of com.intellij.execution.ExecutionException in project intellij-community by JetBrains.
the class EditExternallyAction method actionPerformed.
public void actionPerformed(AnActionEvent e) {
Project project = e.getData(CommonDataKeys.PROJECT);
VirtualFile[] files = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
Options options = OptionsManager.getInstance().getOptions();
String executablePath = options.getExternalEditorOptions().getExecutablePath();
if (StringUtil.isEmpty(executablePath)) {
Messages.showErrorDialog(project, ImagesBundle.message("error.empty.external.editor.path"), ImagesBundle.message("error.title.empty.external.editor.path"));
ImagesConfigurable.show(project);
} else {
if (files != null) {
Map<String, String> env = EnvironmentUtil.getEnvironmentMap();
for (String varName : env.keySet()) {
if (SystemInfo.isWindows) {
executablePath = StringUtil.replace(executablePath, "%" + varName + "%", env.get(varName), true);
} else {
executablePath = StringUtil.replace(executablePath, "${" + varName + "}", env.get(varName), false);
}
}
executablePath = FileUtil.toSystemDependentName(executablePath);
File executable = new File(executablePath);
GeneralCommandLine commandLine = new GeneralCommandLine();
final String path = executable.exists() ? executable.getAbsolutePath() : executablePath;
if (SystemInfo.isMac) {
commandLine.setExePath(ExecUtil.getOpenCommandPath());
commandLine.addParameter("-a");
commandLine.addParameter(path);
} else {
commandLine.setExePath(path);
}
ImageFileTypeManager typeManager = ImageFileTypeManager.getInstance();
for (VirtualFile file : files) {
if (file.isInLocalFileSystem() && typeManager.isImage(file)) {
commandLine.addParameter(VfsUtilCore.virtualToIoFile(file).getAbsolutePath());
}
}
commandLine.setWorkDirectory(new File(executablePath).getParentFile());
try {
commandLine.createProcess();
} catch (ExecutionException ex) {
Messages.showErrorDialog(project, ex.getLocalizedMessage(), ImagesBundle.message("error.title.launching.external.editor"));
ImagesConfigurable.show(project);
}
}
}
}
use of com.intellij.execution.ExecutionException in project intellij-community by JetBrains.
the class DebugProcessImpl method createVirtualMachineInt.
private VirtualMachine createVirtualMachineInt() throws ExecutionException {
try {
if (myArguments != null) {
throw new IOException(DebuggerBundle.message("error.debugger.already.listening"));
}
final String address = myConnection.getAddress();
if (myConnection.isServerMode()) {
ListeningConnector connector = (ListeningConnector) findConnector(myConnection.isUseSockets() ? SOCKET_LISTENING_CONNECTOR_NAME : SHMEM_LISTENING_CONNECTOR_NAME);
if (connector == null) {
throw new CantRunException(DebuggerBundle.message("error.debug.connector.not.found", DebuggerBundle.getTransportName(myConnection)));
}
myArguments = connector.defaultArguments();
if (myArguments == null) {
throw new CantRunException(DebuggerBundle.message("error.no.debug.listen.port"));
}
if (address == null) {
throw new CantRunException(DebuggerBundle.message("error.no.debug.listen.port"));
}
// zero port number means the caller leaves to debugger to decide at which port to listen
//noinspection HardCodedStringLiteral
final Connector.Argument portArg = myConnection.isUseSockets() ? myArguments.get("port") : myArguments.get("name");
if (portArg != null) {
portArg.setValue(address);
}
//noinspection HardCodedStringLiteral
final Connector.Argument timeoutArg = myArguments.get("timeout");
if (timeoutArg != null) {
// wait forever
timeoutArg.setValue("0");
}
String listeningAddress = connector.startListening(myArguments);
String port = StringUtil.substringAfter(listeningAddress, ":");
if (port != null) {
listeningAddress = port;
}
myConnection.setAddress(listeningAddress);
myDebugProcessDispatcher.getMulticaster().connectorIsReady();
try {
return connector.accept(myArguments);
} finally {
if (myArguments != null) {
try {
connector.stopListening(myArguments);
} catch (IllegalArgumentException | IllegalConnectorArgumentsException ignored) {
// ignored
}
}
}
} else {
// is client mode, should attach to already running process
AttachingConnector connector = (AttachingConnector) findConnector(myConnection.isUseSockets() ? SOCKET_ATTACHING_CONNECTOR_NAME : SHMEM_ATTACHING_CONNECTOR_NAME);
if (connector == null) {
throw new CantRunException(DebuggerBundle.message("error.debug.connector.not.found", DebuggerBundle.getTransportName(myConnection)));
}
myArguments = connector.defaultArguments();
if (myConnection.isUseSockets()) {
//noinspection HardCodedStringLiteral
final Connector.Argument hostnameArg = myArguments.get("hostname");
if (hostnameArg != null && myConnection.getHostName() != null) {
hostnameArg.setValue(myConnection.getHostName());
}
if (address == null) {
throw new CantRunException(DebuggerBundle.message("error.no.debug.attach.port"));
}
//noinspection HardCodedStringLiteral
final Connector.Argument portArg = myArguments.get("port");
if (portArg != null) {
portArg.setValue(address);
}
} else {
if (address == null) {
throw new CantRunException(DebuggerBundle.message("error.no.shmem.address"));
}
//noinspection HardCodedStringLiteral
final Connector.Argument nameArg = myArguments.get("name");
if (nameArg != null) {
nameArg.setValue(address);
}
}
//noinspection HardCodedStringLiteral
final Connector.Argument timeoutArg = myArguments.get("timeout");
if (timeoutArg != null) {
// wait forever
timeoutArg.setValue("0");
}
myDebugProcessDispatcher.getMulticaster().connectorIsReady();
try {
return connector.attach(myArguments);
} catch (IllegalArgumentException e) {
throw new CantRunException(e.getLocalizedMessage());
}
}
} catch (IOException e) {
throw new ExecutionException(processIOException(e, DebuggerBundle.getAddressDisplayName(myConnection)), e);
} catch (IllegalConnectorArgumentsException e) {
throw new ExecutionException(processError(e), e);
} finally {
myArguments = null;
}
}
use of com.intellij.execution.ExecutionException in project intellij-community by JetBrains.
the class DebugProcessImpl method createVirtualMachine.
private void createVirtualMachine(final DebugEnvironment environment) {
final String sessionName = environment.getSessionName();
final long pollTimeout = environment.getPollTimeout();
final Semaphore semaphore = new Semaphore();
semaphore.down();
final AtomicBoolean connectorIsReady = new AtomicBoolean(false);
myDebugProcessDispatcher.addListener(new DebugProcessListener() {
@Override
public void connectorIsReady() {
connectorIsReady.set(true);
semaphore.up();
myDebugProcessDispatcher.removeListener(this);
}
});
// reload to make sure that source positions are initialized
DebuggerManagerEx.getInstanceEx(myProject).getBreakpointManager().reloadBreakpoints();
getManagerThread().schedule(new DebuggerCommandImpl() {
@Override
protected void action() {
VirtualMachine vm = null;
try {
final long time = System.currentTimeMillis();
do {
try {
vm = createVirtualMachineInt();
break;
} catch (final ExecutionException e) {
if (pollTimeout > 0 && !myConnection.isServerMode() && e.getCause() instanceof IOException) {
synchronized (this) {
try {
wait(500);
} catch (InterruptedException ignored) {
break;
}
}
} else {
ProcessHandler processHandler = getProcessHandler();
boolean terminated = processHandler != null && (processHandler.isProcessTerminating() || processHandler.isProcessTerminated());
fail();
DebuggerInvocationUtil.swingInvokeLater(myProject, () -> {
// this problem to the user
if ((myExecutionResult != null && !terminated) || !connectorIsReady.get()) {
ExecutionUtil.handleExecutionError(myProject, ToolWindowId.DEBUG, sessionName, e);
}
});
break;
}
}
} while (System.currentTimeMillis() - time < pollTimeout);
} finally {
semaphore.up();
}
if (vm != null) {
final VirtualMachine vm1 = vm;
afterProcessStarted(() -> getManagerThread().schedule(new DebuggerCommandImpl() {
@Override
protected void action() throws Exception {
commitVM(vm1);
}
}));
}
}
@Override
protected void commandCancelled() {
try {
super.commandCancelled();
} finally {
semaphore.up();
}
}
});
semaphore.waitFor();
}
use of com.intellij.execution.ExecutionException in project intellij-community by JetBrains.
the class DebugProcessImpl method findConnector.
static Connector findConnector(String connectorName) throws ExecutionException {
VirtualMachineManager virtualMachineManager;
try {
virtualMachineManager = Bootstrap.virtualMachineManager();
} catch (Error e) {
final String error = e.getClass().getName() + " : " + e.getLocalizedMessage();
throw new ExecutionException(DebuggerBundle.message("debugger.jdi.bootstrap.error", error));
}
List connectors;
if (SOCKET_ATTACHING_CONNECTOR_NAME.equals(connectorName) || SHMEM_ATTACHING_CONNECTOR_NAME.equals(connectorName)) {
connectors = virtualMachineManager.attachingConnectors();
} else if (SOCKET_LISTENING_CONNECTOR_NAME.equals(connectorName) || SHMEM_LISTENING_CONNECTOR_NAME.equals(connectorName)) {
connectors = virtualMachineManager.listeningConnectors();
} else {
return null;
}
for (Object connector1 : connectors) {
Connector connector = (Connector) connector1;
if (connectorName.equals(connector.name())) {
return connector;
}
}
return null;
}
Aggregations