Java Code Examples for com.intellij.execution.process.OSProcessHandler#startNotify()

The following examples show how to use com.intellij.execution.process.OSProcessHandler#startNotify() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OpenInXcodeAction.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private static void openWithXcode(String path) {
  try {
    final GeneralCommandLine cmd = new GeneralCommandLine().withExePath("open").withParameters(path);
    final OSProcessHandler handler = new OSProcessHandler(cmd);
    handler.addProcessListener(new ProcessAdapter() {
      @Override
      public void processTerminated(@NotNull final ProcessEvent event) {
        if (event.getExitCode() != 0) {
          FlutterMessages.showError("Error Opening", path);
        }
      }
    });
    handler.startNotify();
  }
  catch (ExecutionException ex) {
    FlutterMessages.showError(
      "Error Opening",
      "Exception: " + ex.getMessage());
  }
}
 
Example 2
Source File: FlutterConsoleFilter.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void navigate(Project project) {
  try {
    final GeneralCommandLine cmd = new GeneralCommandLine().withExePath("open").withParameters(myPath);
    final OSProcessHandler handler = new OSProcessHandler(cmd);
    handler.addProcessListener(new ProcessAdapter() {
      @Override
      public void processTerminated(@NotNull final ProcessEvent event) {
        if (event.getExitCode() != 0) {
          FlutterMessages.showError("Error Opening ", myPath);
        }
      }
    });
    handler.startNotify();
  }
  catch (ExecutionException e) {
    FlutterMessages.showError(
      "Error Opening External File",
      "Exception: " + e.getMessage());
  }
}
 
Example 3
Source File: OpenInXcodeAction.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private static void openWithXcode(String path) {
  try {
    final GeneralCommandLine cmd = new GeneralCommandLine().withExePath("open").withParameters(path);
    final OSProcessHandler handler = new OSProcessHandler(cmd);
    handler.addProcessListener(new ProcessAdapter() {
      @Override
      public void processTerminated(@NotNull final ProcessEvent event) {
        if (event.getExitCode() != 0) {
          FlutterMessages.showError("Error Opening", path);
        }
      }
    });
    handler.startNotify();
  }
  catch (ExecutionException ex) {
    FlutterMessages.showError(
      "Error Opening",
      "Exception: " + ex.getMessage());
  }
}
 
Example 4
Source File: FlutterConsoleFilter.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void navigate(Project project) {
  try {
    final GeneralCommandLine cmd = new GeneralCommandLine().withExePath("open").withParameters(myPath);
    final OSProcessHandler handler = new OSProcessHandler(cmd);
    handler.addProcessListener(new ProcessAdapter() {
      @Override
      public void processTerminated(@NotNull final ProcessEvent event) {
        if (event.getExitCode() != 0) {
          FlutterMessages.showError("Error Opening ", myPath);
        }
      }
    });
    handler.startNotify();
  }
  catch (ExecutionException e) {
    FlutterMessages.showError(
      "Error Opening External File",
      "Exception: " + e.getMessage());
  }
}
 
Example 5
Source File: InstallSdkAction.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void runCommand(@NotNull InstallCommand cmd) {
  try {
    handler = new OSProcessHandler(cmd.getCommandLine());
  }
  catch (ExecutionException e) {
    cmd.onError(e);
    return;
  }
  cmd.registerTo(handler);

  handler.startNotify();
}
 
Example 6
Source File: OpenInAndroidStudioAction.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static void openFileInStudio(@NotNull VirtualFile projectFile, @NotNull String androidStudioPath, @Nullable String sourceFile) {
  try {
    final GeneralCommandLine cmd;
    if (SystemInfo.isMac) {
      cmd = new GeneralCommandLine().withExePath("open").withParameters("-a", androidStudioPath, "--args", projectFile.getPath());
      if (sourceFile != null) {
        cmd.addParameter(sourceFile);
      }
    }
    else {
      // TODO Open editor on sourceFile for Linux, Windows
      if (SystemInfo.isWindows) {
        androidStudioPath += "\\bin\\studio.bat";
      }
      cmd = new GeneralCommandLine().withExePath(androidStudioPath).withParameters(projectFile.getPath());
    }
    final OSProcessHandler handler = new OSProcessHandler(cmd);
    handler.addProcessListener(new ProcessAdapter() {
      @Override
      public void processTerminated(@NotNull final ProcessEvent event) {
        if (event.getExitCode() != 0) {
          FlutterMessages.showError("Error Opening", projectFile.getPath());
        }
      }
    });
    handler.startNotify();
  }
  catch (ExecutionException ex) {
    FlutterMessages.showError(
      "Error Opening",
      "Exception: " + ex.getMessage());
  }
}
 
Example 7
Source File: InstallSdkAction.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void runCommand(@NotNull InstallCommand cmd) {
  try {
    handler = new OSProcessHandler(cmd.getCommandLine());
  }
  catch (ExecutionException e) {
    cmd.onError(e);
    return;
  }
  cmd.registerTo(handler);

  handler.startNotify();
}
 
Example 8
Source File: OpenInAndroidStudioAction.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static void openFileInStudio(@NotNull VirtualFile projectFile, @NotNull String androidStudioPath, @Nullable String sourceFile) {
  try {
    final GeneralCommandLine cmd;
    if (SystemInfo.isMac) {
      cmd = new GeneralCommandLine().withExePath("open").withParameters("-a", androidStudioPath, "--args", projectFile.getPath());
      if (sourceFile != null) {
        cmd.addParameter(sourceFile);
      }
    }
    else {
      // TODO Open editor on sourceFile for Linux, Windows
      if (SystemInfo.isWindows) {
        androidStudioPath += "\\bin\\studio.bat";
      }
      cmd = new GeneralCommandLine().withExePath(androidStudioPath).withParameters(projectFile.getPath());
    }
    final OSProcessHandler handler = new OSProcessHandler(cmd);
    handler.addProcessListener(new ProcessAdapter() {
      @Override
      public void processTerminated(@NotNull final ProcessEvent event) {
        if (event.getExitCode() != 0) {
          FlutterMessages.showError("Error Opening", projectFile.getPath());
        }
      }
    });
    handler.startNotify();
  }
  catch (ExecutionException ex) {
    FlutterMessages.showError(
      "Error Opening",
      "Exception: " + ex.getMessage());
  }
}
 
Example 9
Source File: FreelineUtil.java    From freeline with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static void processCommandline(final Project project, GeneralCommandLine commandLine) throws ExecutionException {
    final OSProcessHandler processHandler = new OSProcessHandler(commandLine);
    ProcessTerminatedListener.attach(processHandler);
    processHandler.startNotify();

    ApplicationManager.getApplication().invokeLater(new Runnable() {
        @Override
        public void run() {
            processConsole(project, processHandler);
        }
    });
}
 
Example 10
Source File: AndroidSdk.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@NotNull
public List<AndroidEmulator> getEmulators() {
  // Execute $ANDROID_HOME/emulator/emulator -list-avds and parse the results.
  final VirtualFile emulator = getEmulatorToolExecutable();
  if (emulator == null) {
    return Collections.emptyList();
  }

  final String emulatorPath = emulator.getCanonicalPath();
  assert (emulatorPath != null);

  final GeneralCommandLine cmd = new GeneralCommandLine()
    .withParentEnvironmentType(GeneralCommandLine.ParentEnvironmentType.CONSOLE)
    .withWorkDirectory(home.getCanonicalPath())
    .withExePath(emulatorPath)
    .withParameters("-list-avds");

  try {
    final StringBuilder stringBuilder = new StringBuilder();
    final OSProcessHandler process = new OSProcessHandler(cmd);
    process.addProcessListener(new ProcessAdapter() {
      @Override
      public void onTextAvailable(ProcessEvent event, Key outputType) {
        if (outputType == ProcessOutputTypes.STDOUT) {
          stringBuilder.append(event.getText());
        }
      }
    });
    process.startNotify();

    // We wait a maximum of 10s.
    if (!process.waitFor(10000)) {
      return Collections.emptyList();
    }

    final Integer exitCode = process.getExitCode();
    if (exitCode == null || process.getExitCode() != 0) {
      return Collections.emptyList();
    }

    // 'emulator -list-avds' results are in the form "foo\nbar\nbaz\n".
    final List<AndroidEmulator> emulators = new ArrayList<>();

    for (String str : stringBuilder.toString().split("\n")) {
      str = str.trim();
      if (str.isEmpty()) {
        continue;
      }
      emulators.add(new AndroidEmulator(this, str));
    }

    return emulators;
  }
  catch (ExecutionException | RuntimeException e) {
    FlutterUtils.warn(LOG, "Error listing android emulators", e);
    return Collections.emptyList();
  }
}
 
Example 11
Source File: AndroidSdk.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@NotNull
public List<AndroidEmulator> getEmulators() {
  // Execute $ANDROID_HOME/emulator/emulator -list-avds and parse the results.
  final VirtualFile emulator = getEmulatorToolExecutable();
  if (emulator == null) {
    return Collections.emptyList();
  }

  final String emulatorPath = emulator.getCanonicalPath();
  assert (emulatorPath != null);

  final GeneralCommandLine cmd = new GeneralCommandLine()
    .withParentEnvironmentType(GeneralCommandLine.ParentEnvironmentType.CONSOLE)
    .withWorkDirectory(home.getCanonicalPath())
    .withExePath(emulatorPath)
    .withParameters("-list-avds");

  try {
    final StringBuilder stringBuilder = new StringBuilder();
    final OSProcessHandler process = new OSProcessHandler(cmd);
    process.addProcessListener(new ProcessAdapter() {
      @Override
      public void onTextAvailable(ProcessEvent event, Key outputType) {
        if (outputType == ProcessOutputTypes.STDOUT) {
          stringBuilder.append(event.getText());
        }
      }
    });
    process.startNotify();

    // We wait a maximum of 10s.
    if (!process.waitFor(10000)) {
      return Collections.emptyList();
    }

    final Integer exitCode = process.getExitCode();
    if (exitCode == null || process.getExitCode() != 0) {
      return Collections.emptyList();
    }

    // 'emulator -list-avds' results are in the form "foo\nbar\nbaz\n".
    final List<AndroidEmulator> emulators = new ArrayList<>();

    for (String str : stringBuilder.toString().split("\n")) {
      str = str.trim();
      if (str.isEmpty()) {
        continue;
      }
      emulators.add(new AndroidEmulator(this, str));
    }

    return emulators;
  }
  catch (ExecutionException | RuntimeException e) {
    FlutterUtils.warn(LOG, "Error listing android emulators", e);
    return Collections.emptyList();
  }
}
 
Example 12
Source File: PluginGeneratorUtil.java    From idea-php-shopware-plugin with MIT License 4 votes vote down vote up
public static void installPlugin(@NotNull Project project, @NotNull PluginGeneratorSettings settings) {

        // download cli tools, if not existing locally
        VirtualFile cliFile = getCliToolsPharFile(project);
        if (cliFile == null) {
            showErrorNotification(project, "No CLI-Tools phar found");
            return;
        }

        List<String> commands = generateCommand(settings);

        String[] myCommand = ArrayUtil.toStringArray(commands);

        final StringBuilder outputBuilder = new StringBuilder();
        try {
            OSProcessHandler processHandler = ScriptRunnerUtil.execute(myCommand[0], project.getBaseDir().getPath(), null, Arrays.copyOfRange(myCommand, 1, myCommand.length));

            processHandler.addProcessListener(new ProcessAdapter() {
                @Override
                public void onTextAvailable(@NotNull ProcessEvent event, @NotNull com.intellij.openapi.util.Key outputType) {
                    String text = event.getText();
                    outputBuilder.append(text);
                }
            });

            processHandler.startNotify();
            for (;;){
                boolean finished = processHandler.waitFor(CHECKING_TIMEOUT_IN_MILLISECONDS);
                if (finished) {
                    break;
                }
            }
        }
        catch (ExecutionException e) {
            showErrorNotification(project, e.getMessage());
            return;
        }

        String output = outputBuilder.toString();
        if (output.toLowerCase().contains("exception")) {

            String message = SymfonyInstallerUtil.formatExceptionMessage(output);
            if(message == null) {
                message = "The unexpected happens...";
            }

            showErrorNotification(project, message);
            return;
        }

        // delete cli tools
        FileUtil.delete(VfsUtil.virtualToIoFile(cliFile));

        // move into correct plugin folder
        String newDir = project.getBasePath() + "/engine/Shopware/Plugins/Local/" + settings.getNamespace() + "/" + settings.getPluginName();
        if (FileUtil.canWrite(newDir)) {
            return;
        }

        FileUtil.createDirectory(new File(newDir));
        FileUtil.moveDirWithContent(new File(project.getBasePath() + "/" + settings.getPluginName()), new File(newDir));

        // open bootstrap file
        VirtualFile fileByIoFile = VfsUtil.findFileByIoFile(new File(newDir + "/Bootstrap.php"), true);
        if(fileByIoFile == null) {
            return;
        }
        final PsiFile file = PsiManager.getInstance(project).findFile(fileByIoFile);
        if (file == null) {
            return;
        }
        IdeHelper.navigateToPsiElement(file);
    }