use of com.intellij.execution.ExecutionException in project intellij-community by JetBrains.
the class CreateSnapShotAction method actionPerformed.
public void actionPerformed(AnActionEvent e) {
final Project project = e.getData(CommonDataKeys.PROJECT);
final IdeView view = e.getData(LangDataKeys.IDE_VIEW);
if (project == null || view == null) {
return;
}
final PsiDirectory dir = view.getOrChooseDirectory();
if (dir == null)
return;
final SnapShotClient client = new SnapShotClient();
List<RunnerAndConfigurationSettings> appConfigurations = new ArrayList<>();
RunnerAndConfigurationSettings snapshotConfiguration = null;
boolean connected = false;
ApplicationConfigurationType cfgType = ApplicationConfigurationType.getInstance();
List<RunnerAndConfigurationSettings> racsi = RunManager.getInstance(project).getConfigurationSettingsList(cfgType);
for (RunnerAndConfigurationSettings config : racsi) {
if (config.getConfiguration() instanceof ApplicationConfiguration) {
ApplicationConfiguration appConfig = (ApplicationConfiguration) config.getConfiguration();
appConfigurations.add(config);
if (appConfig.ENABLE_SWING_INSPECTOR) {
SnapShooterConfigurationSettings settings = SnapShooterConfigurationSettings.get(appConfig);
snapshotConfiguration = config;
if (settings.getLastPort() > 0) {
try {
client.connect(settings.getLastPort());
connected = true;
} catch (IOException ex) {
connected = false;
}
}
}
if (connected)
break;
}
}
if (snapshotConfiguration == null) {
snapshotConfiguration = promptForSnapshotConfiguration(project, appConfigurations);
if (snapshotConfiguration == null)
return;
}
if (!connected) {
int rc = Messages.showYesNoDialog(project, UIDesignerBundle.message("snapshot.run.prompt"), UIDesignerBundle.message("snapshot.title"), Messages.getQuestionIcon());
if (rc == Messages.NO)
return;
final ApplicationConfiguration appConfig = (ApplicationConfiguration) snapshotConfiguration.getConfiguration();
final SnapShooterConfigurationSettings settings = SnapShooterConfigurationSettings.get(appConfig);
settings.setNotifyRunnable(() -> SwingUtilities.invokeLater(() -> {
Messages.showMessageDialog(project, UIDesignerBundle.message("snapshot.prepare.notice"), UIDesignerBundle.message("snapshot.title"), Messages.getInformationIcon());
try {
client.connect(settings.getLastPort());
} catch (IOException ex) {
Messages.showMessageDialog(project, UIDesignerBundle.message("snapshot.connection.error"), UIDesignerBundle.message("snapshot.title"), Messages.getErrorIcon());
return;
}
runSnapShooterSession(client, project, dir, view);
}));
try {
ExecutionEnvironmentBuilder.create(DefaultRunExecutor.getRunExecutorInstance(), snapshotConfiguration).buildAndExecute();
} catch (ExecutionException ex) {
Messages.showMessageDialog(project, UIDesignerBundle.message("snapshot.run.error", ex.getMessage()), UIDesignerBundle.message("snapshot.title"), Messages.getErrorIcon());
}
} else {
runSnapShooterSession(client, project, dir, view);
}
}
use of com.intellij.execution.ExecutionException in project intellij-community by JetBrains.
the class IpnbConnectionManager method startIpythonServer.
public boolean startIpythonServer(@NotNull final String initUrl, @NotNull final IpnbFileEditor fileEditor) {
final Module module = ProjectFileIndex.SERVICE.getInstance(myProject).getModuleForFile(fileEditor.getVirtualFile());
if (module == null)
return false;
final Sdk sdk = PythonSdkType.findPythonSdk(module);
if (sdk == null) {
showWarning(fileEditor, "Please check Python Interpreter in Settings->Python Interpreter", null);
return false;
}
final List<PyPackage> packages = PyPackageManager.getInstance(sdk).getPackages();
final PyPackage ipythonPackage = packages != null ? PyPackageUtil.findPackage(packages, "ipython") : null;
final PyPackage jupyterPackage = packages != null ? PyPackageUtil.findPackage(packages, "jupyter") : null;
if (ipythonPackage == null && jupyterPackage == null) {
showWarning(fileEditor, "Add Jupyter to the interpreter of the current project.", null);
return false;
}
String url = showDialogUrl(initUrl);
if (url == null)
return false;
final IpnbSettings ipnbSettings = IpnbSettings.getInstance(myProject);
ipnbSettings.setURL(url);
final Pair<String, String> hostPort = getHostPortFromUrl(url);
if (hostPort == null) {
showWarning(fileEditor, "Please, check Jupyter Notebook URL in <a href=\"\">Settings->Tools->Jupyter Notebook</a>", new IpnbSettingsAdapter());
return false;
}
final String homePath = sdk.getHomePath();
if (homePath == null) {
showWarning(fileEditor, "Python Sdk is invalid, please check Python Interpreter in Settings->Python Interpreter", null);
return false;
}
Map<String, String> env = null;
final ArrayList<String> parameters = Lists.newArrayList(homePath);
String ipython = findJupyterRunner(homePath);
if (ipython == null) {
ipython = findIPythonRunner(homePath);
if (ipython == null) {
ipython = PythonHelper.LOAD_ENTRY_POINT.asParamString();
env = ImmutableMap.of("PYCHARM_EP_DIST", "ipython", "PYCHARM_EP_NAME", "ipython");
}
parameters.add(ipython);
parameters.add("notebook");
} else {
parameters.add(ipython);
}
parameters.add("--no-browser");
if (hostPort.getFirst() != null) {
parameters.add("--ip");
parameters.add(hostPort.getFirst());
}
if (hostPort.getSecond() != null) {
parameters.add("--port");
parameters.add(hostPort.getSecond());
}
final String arguments = ipnbSettings.getArguments();
if (!StringUtil.isEmptyOrSpaces(arguments)) {
parameters.addAll(StringUtil.split(arguments, " "));
}
final String directory = ipnbSettings.getWorkingDirectory();
final String baseDir = !StringUtil.isEmptyOrSpaces(directory) ? directory : ModuleRootManager.getInstance(module).getContentRoots()[0].getCanonicalPath();
final GeneralCommandLine commandLine = new GeneralCommandLine(parameters).withWorkDirectory(baseDir);
if (env != null) {
commandLine.withEnvironment(env);
}
try {
final boolean[] serverStarted = { false };
final KillableColoredProcessHandler processHandler = new KillableColoredProcessHandler(commandLine) {
@Override
protected void doDestroyProcess() {
super.doDestroyProcess();
myKernels.clear();
myToken = null;
UnixProcessManager.sendSigIntToProcessTree(getProcess());
}
@Override
public void coloredTextAvailable(@NotNull @NonNls String text, @NotNull Key attributes) {
super.coloredTextAvailable(text, attributes);
if (text.toLowerCase().contains("active kernels")) {
serverStarted[0] = true;
}
final String token = "?token=";
if (text.toLowerCase().contains(token)) {
myToken = text.substring(text.indexOf(token) + token.length()).trim();
}
}
@Override
public boolean isSilentlyDestroyOnClose() {
return true;
}
};
processHandler.setShouldDestroyProcessRecursively(true);
GuiUtils.invokeLaterIfNeeded(() -> new RunContentExecutor(myProject, processHandler).withTitle("Jupyter Notebook").withStop(() -> {
myKernels.clear();
processHandler.destroyProcess();
UnixProcessManager.sendSigIntToProcessTree(processHandler.getProcess());
}, () -> !processHandler.isProcessTerminated()).withRerun(() -> startIpythonServer(url, fileEditor)).withHelpId("reference.manage.py").withFilter(new UrlFilter()).run(), ModalityState.defaultModalityState());
int countAttempt = 0;
while (!serverStarted[0] && countAttempt < MAX_ATTEMPTS) {
countAttempt += 1;
TimeoutUtil.sleep(1000);
}
return true;
} catch (ExecutionException e) {
return false;
}
}
use of com.intellij.execution.ExecutionException in project intellij-community by JetBrains.
the class GriffonFramework method createJavaParameters.
@Override
public JavaParameters createJavaParameters(@NotNull Module module, boolean forCreation, boolean forTests, boolean classpathFromDependencies, @NotNull MvcCommand command) throws ExecutionException {
JavaParameters params = new JavaParameters();
Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
params.setJdk(sdk);
final VirtualFile sdkRoot = getSdkRoot(module);
if (sdkRoot == null) {
return params;
}
params.addEnv(getSdkHomePropertyName(), FileUtil.toSystemDependentName(sdkRoot.getPath()));
final VirtualFile lib = sdkRoot.findChild("lib");
if (lib != null) {
for (final VirtualFile child : lib.getChildren()) {
final String name = child.getName();
if (name.startsWith("groovy-all-") && name.endsWith(".jar")) {
params.getClassPath().add(child);
}
}
}
final VirtualFile dist = sdkRoot.findChild("dist");
if (dist != null) {
for (final VirtualFile child : dist.getChildren()) {
final String name = child.getName();
if (name.endsWith(".jar")) {
if (name.startsWith("griffon-cli-") || name.startsWith("griffon-rt-") || name.startsWith("griffon-resources-")) {
params.getClassPath().add(child);
}
}
}
}
/////////////////////////////////////////////////////////////
params.setMainClass("org.codehaus.griffon.cli.support.GriffonStarter");
final VirtualFile rootFile;
if (forCreation) {
VirtualFile[] roots = ModuleRootManager.getInstance(module).getContentRoots();
if (roots.length != 1) {
throw new ExecutionException("Failed to initialize griffon module: module " + module.getName() + " contains more than one root");
}
command.getArgs().add(0, roots[0].getName());
rootFile = roots[0].getParent();
} else {
rootFile = findAppRoot(module);
if (rootFile == null) {
throw new ExecutionException("Failed to run griffon command: module " + module.getName() + " is not a Griffon module");
}
}
String workDir = VfsUtilCore.virtualToIoFile(rootFile).getAbsolutePath();
params.getVMParametersList().addParametersString(command.getVmOptions());
if (!params.getVMParametersList().getParametersString().contains(XMX_JVM_PARAMETER)) {
params.getVMParametersList().add("-Xmx256M");
}
final String griffonHomePath = FileUtil.toSystemDependentName(sdkRoot.getPath());
params.getVMParametersList().add("-Dgriffon.home=" + griffonHomePath);
params.getVMParametersList().add("-Dbase.dir=" + workDir);
assert sdk != null;
params.getVMParametersList().add("-Dtools.jar=" + ((JavaSdkType) sdk.getSdkType()).getToolsPath(sdk));
final String confpath = griffonHomePath + GROOVY_STARTER_CONF;
params.getVMParametersList().add("-Dgroovy.starter.conf=" + confpath);
params.getVMParametersList().add("-Dgroovy.sanitized.stacktraces=\"groovy., org.codehaus.groovy., java., javax., sun., gjdk.groovy., gant., org.codehaus.gant.\"");
params.getProgramParametersList().add("--main");
params.getProgramParametersList().add("org.codehaus.griffon.cli.GriffonScriptRunner");
params.getProgramParametersList().add("--conf");
params.getProgramParametersList().add(confpath);
if (!forCreation && classpathFromDependencies) {
final String path = getApplicationClassPath(module).getPathsString();
if (StringUtil.isNotEmpty(path)) {
params.getProgramParametersList().add("--classpath");
params.getProgramParametersList().add(path);
}
}
params.setWorkingDirectory(workDir);
ParametersList paramList = new ParametersList();
command.addToParametersList(paramList);
params.getProgramParametersList().add(paramList.getParametersString());
params.setDefaultCharset(module.getProject());
return params;
}
use of com.intellij.execution.ExecutionException in project intellij-community by JetBrains.
the class PyRemoteProcessStarter method startRemoteProcess.
public ProcessHandler startRemoteProcess(@NotNull Sdk sdk, @NotNull GeneralCommandLine commandLine, @Nullable Project project, @Nullable PyRemotePathMapper pathMapper) throws ExecutionException {
PythonRemoteInterpreterManager manager = PythonRemoteInterpreterManager.getInstance();
if (manager != null) {
PyRemoteProcessHandlerBase processHandler;
try {
processHandler = doStartRemoteProcess(sdk, commandLine, manager, project, pathMapper);
} catch (ExecutionException e) {
final Application application = ApplicationManager.getApplication();
if (application != null && (application.isUnitTestMode() || application.isHeadlessEnvironment())) {
throw new RuntimeException(e);
}
throw new ExecutionException("Can't run remote python interpreter: " + e.getMessage(), e);
}
ProcessTerminatedListener.attach(processHandler);
return processHandler;
} else {
throw new PythonRemoteInterpreterManager.PyRemoteInterpreterExecutionException();
}
}
use of com.intellij.execution.ExecutionException in project intellij-community by JetBrains.
the class StudyRunAction method executeFile.
private void executeFile(@NotNull final Project project, @NotNull final VirtualFile openedFile, @NotNull final String filePath) {
GeneralCommandLine cmd = new GeneralCommandLine();
cmd.withWorkDirectory(openedFile.getParent().getCanonicalPath());
TaskFile selectedTaskFile = StudyUtils.getTaskFile(project, openedFile);
assert selectedTaskFile != null;
final Task currentTask = selectedTaskFile.getTask();
final Sdk sdk = StudyUtils.findSdk(currentTask, project);
if (sdk == null) {
StudyUtils.showNoSdkNotification(currentTask, project);
return;
}
String sdkHomePath = sdk.getHomePath();
if (sdkHomePath != null) {
cmd.setExePath(sdkHomePath);
StudyUtils.setCommandLineParameters(cmd, project, filePath, sdkHomePath, currentTask);
try {
myHandler = new OSProcessHandler(cmd);
} catch (ExecutionException e) {
LOG.error(e);
return;
}
for (ProcessListener processListener : myProcessListeners) {
myHandler.addProcessListener(processListener);
}
final RunContentExecutor executor = StudyUtils.getExecutor(project, currentTask, myHandler);
if (executor != null) {
Disposer.register(project, executor);
executor.run();
}
EduUtils.synchronize();
}
}
Aggregations