Java Code Examples for com.intellij.execution.configurations.GeneralCommandLine#addParameter()

The following examples show how to use com.intellij.execution.configurations.GeneralCommandLine#addParameter() . 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: JavaCommandBuilder.java    From intellij with Apache License 2.0 6 votes vote down vote up
GeneralCommandLine build() {
  checkArgument(javaBinary != null, "javaBinary was not set");
  checkArgument(mainClass != null, "mainClass was not set");
  GeneralCommandLine commandLine = new GeneralCommandLine(javaBinary.getPath());
  commandLine.addParameters("-cp", classpaths.stream().map(File::getPath).collect(joining(":")));
  commandLine.addParameters(jvmArgs);
  commandLine.addParameters(
      systemProperties.entrySet().stream()
          .map(e -> "-D" + e.getKey() + '=' + e.getValue())
          .collect(toList()));
  commandLine.addParameter(mainClass);
  commandLine.addParameters(programArgs);

  if (workingDirectory != null) {
    commandLine.setWorkDirectory(workingDirectory);
  }

  commandLine.withParentEnvironmentType(ParentEnvironmentType.NONE);
  environmentVariables.forEach(commandLine::withEnvironment);

  return commandLine;
}
 
Example 2
Source File: CliBuilder.java    From eslint-plugin with MIT License 6 votes vote down vote up
@NotNull
static GeneralCommandLine createLint(@NotNull ESLintRunner.ESLintSettings settings) {
    GeneralCommandLine commandLine = create(settings);
    // TODO validate arguments (file exist etc)
    commandLine.addParameter(settings.targetFile);
    CLI.addParamIfNotEmpty(commandLine, C, settings.config);
    if (StringUtil.isNotEmpty(settings.rules)) {
        CLI.addParam(commandLine, RULESDIR, "['" + settings.rules + "']");
    }
    if (StringUtil.isNotEmpty(settings.ext)) {
        CLI.addParam(commandLine, EXT, settings.ext);
    }
    if (settings.fix) {
        commandLine.addParameter(FIX);
    }
    if (settings.reportUnused) {
        commandLine.addParameter(REPORT_UNUSED);
    }
    CLI.addParam(commandLine, FORMAT, JSON);
    return commandLine;
}
 
Example 3
Source File: FlutterCommand.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Creates the command line to run.
 * <p>
 * If a project is supplied, it will be used to determine the ANDROID_HOME variable for the subprocess.
 */
@NotNull
public GeneralCommandLine createGeneralCommandLine(@Nullable Project project) {
  final GeneralCommandLine line = new GeneralCommandLine();
  line.setCharset(CharsetToolkit.UTF8_CHARSET);
  line.withEnvironment(FlutterSdkUtil.FLUTTER_HOST_ENV, FlutterSdkUtil.getFlutterHostEnvValue());
  final String androidHome = IntelliJAndroidSdk.chooseAndroidHome(project, false);
  if (androidHome != null) {
    line.withEnvironment("ANDROID_HOME", androidHome);
  }
  line.setExePath(FileUtil.toSystemDependentName(sdk.getHomePath() + "/bin/" + FlutterSdkUtil.flutterScriptName()));
  if (workDir != null) {
    line.setWorkDirectory(workDir.getPath());
  }
  if (!isDoctorCommand()) {
    line.addParameter("--no-color");
  }
  line.addParameters(type.subCommand);
  line.addParameters(args);
  return line;
}
 
Example 4
Source File: NodeRunner.java    From vue-for-idea with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * @param cwd working directory
 * @param node node interpreter path
 * @param exe node executable to run
 * @return command line to sdk
 */
@NotNull
public static GeneralCommandLine createCommandLine(@NotNull String cwd, String node, String exe) {
    GeneralCommandLine commandLine = new GeneralCommandLine();
    if (!new File(cwd).exists()) {
        throw new IllegalArgumentException("cwd: "+cwd +" doesn't exist");
    }
    if (!new File(exe).exists()) {
        throw new IllegalArgumentException("exe: "+exe +" doesn't exist");

    }
    commandLine.setWorkDirectory(cwd);
    if (SystemInfo.isWindows) {
        commandLine.setExePath(exe);
    } else {
        if (!new File(node).exists()) {
            throw new IllegalArgumentException("path doesn't exist");
        }
        commandLine.setExePath(node);
        commandLine.addParameter(exe);
    }
    return commandLine;
}
 
Example 5
Source File: GaugeRunConfiguration.java    From Intellij-Plugin with Apache License 2.0 6 votes vote down vote up
private void addFlags(GeneralCommandLine commandLine, ExecutionEnvironment env) {
    commandLine.addParameter(Constants.RUN);
    if (GaugeVersion.isGreaterOrEqual(TEST_RUNNER_SUPPORT_VERSION, true)
            && GaugeSettingsService.getSettings().useIntelliJTestRunner()) {
        LOG.info("Using IntelliJ Test Runner");
        commandLine.addParameter(Constants.MACHINE_READABLE);
        commandLine.addParameter(Constants.HIDE_SUGGESTION);
    }
    commandLine.addParameter(Constants.SIMPLE_CONSOLE);
    if (!Strings.isBlank(tags)) {
        commandLine.addParameter(Constants.TAGS);
        commandLine.addParameter(tags);
    }
    if (!Strings.isBlank(environment)) {
        commandLine.addParameters(Constants.ENV_FLAG, environment);
    }
    addTableRowsRangeFlags(commandLine);
    addParallelExecFlags(commandLine, env);
    addProgramArguments(commandLine);
    if (!Strings.isBlank(specsToExecute)) {
        addSpecs(commandLine, specsToExecute);
    }
}
 
Example 6
Source File: BuckCommandHandler.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * @param project a project
 * @param command a command to execute (if empty string, the parameter is ignored)
 * @param doStartNotify true if the handler should call OSHandler#startNotify
 */
public BuckCommandHandler(Project project, BuckCommand command, boolean doStartNotify) {
  this.doStartNotify = doStartNotify;

  String buckExecutable =
      BuckExecutableSettingsProvider.getInstance(project).resolveBuckExecutable();

  this.project = project;
  this.buckModule = project.getComponent(BuckModule.class);
  this.command = command;
  commandLine = new GeneralCommandLine();
  commandLine.setExePath(buckExecutable);
  commandLine.withWorkDirectory(calcWorkingDirFor(project));
  commandLine.withEnvironment(EnvironmentUtil.getEnvironmentMap());
  commandLine.addParameter(command.name());
  for (String parameter : command.getParameters()) {
    commandLine.addParameter(parameter);
  }
}
 
Example 7
Source File: JdkUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void appendParamsEncodingClasspath(SimpleJavaParameters javaParameters,
                                                  GeneralCommandLine commandLine,
                                                  ParametersList parametersList) {
  commandLine.addParameters(parametersList.getList());
  appendEncoding(javaParameters, commandLine, parametersList);
  if (!parametersList.hasParameter("-classpath") && !parametersList.hasParameter("-cp")){
    commandLine.addParameter("-classpath");
    commandLine.addParameter(javaParameters.getClassPath().getPathsString());
  }
}
 
Example 8
Source File: PantsIntegrationTestCase.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
protected void killNailgun() throws ExecutionException {
  // NB: the ideal interface here is defaultCommandLine(myProject). However,
  // not all tests call doImport therefore myProject may not always contain modules.
  final GeneralCommandLine commandLine = PantsUtil.defaultCommandLine(getProjectPath());
  commandLine.addParameter("ng-killall");
  // Wait for command to finish.
  PantsUtil.getCmdOutput(commandLine, null);
}
 
Example 9
Source File: SassLintRunner.java    From sass-lint-plugin with MIT License 5 votes vote down vote up
@NotNull
private static GeneralCommandLine createCommandLineLint(@NotNull SassLintSettings settings) {
    GeneralCommandLine commandLine = createCommandLine(settings);
    // TODO validate arguments (file exist etc)
    commandLine.addParameter(settings.targetFile);
    commandLine.addParameter("-v");
    commandLine.addParameter("-q");
    CLI.addParamIfNotEmpty(commandLine, "-c", settings.config);
    CLI.addParam(commandLine, "--format", "checkstyle");
    return commandLine;
}
 
Example 10
Source File: JetSymbolsExe.java    From teamcity-symbol-server with Apache License 2.0 5 votes vote down vote up
public PdbType getPdbType(File symbolsFile, BuildProgressLogger buildLogger) {
  final GeneralCommandLine commandLine = new GeneralCommandLine();
  commandLine.setExePath(myExePath.getPath());
  commandLine.addParameter(GET_PDB_TYPE_CMD);
  commandLine.addParameter(symbolsFile.getAbsolutePath());

  final ExecResult execResult = executeCommandLine(commandLine, buildLogger);
  if (execResult.getExitCode() == 0) {
    return parsePdbType(execResult.getOutLines(), buildLogger);
  } else {
    buildLogger.error("Cannot parse PDB type.");
    return PdbType.Undefined;
  }
}
 
Example 11
Source File: HaxeTestsRunner.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
@Override
protected RunContentDescriptor doExecute(@NotNull final Project project,
                                         @NotNull RunProfileState state,
                                         final RunContentDescriptor descriptor,
                                         @NotNull final ExecutionEnvironment environment) throws ExecutionException {

  final HaxeTestsConfiguration profile = (HaxeTestsConfiguration)environment.getRunProfile();
  final Module module = profile.getConfigurationModule().getModule();

  ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
  VirtualFile[] roots = rootManager.getContentRoots();

  return super.doExecute(project, new CommandLineState(environment) {
    @NotNull
    @Override
    protected ProcessHandler startProcess() throws ExecutionException {
      //actually only neko target is supported for tests
      HaxeTarget currentTarget = HaxeTarget.NEKO;
      final GeneralCommandLine commandLine = new GeneralCommandLine();
      commandLine.setWorkDirectory(PathUtil.getParentPath(module.getModuleFilePath()));
      commandLine.setExePath(currentTarget.getFlag());
      final HaxeModuleSettings settings = HaxeModuleSettings.getInstance(module);
      String folder = settings.getOutputFolder() != null ? (settings.getOutputFolder() + "/release/") : "";
      commandLine.addParameter(getFileNameWithCurrentExtension(currentTarget, folder + settings.getOutputFileName()));

      final TextConsoleBuilder consoleBuilder = TextConsoleBuilderFactory.getInstance().createBuilder(module.getProject());
      consoleBuilder.addFilter(new ErrorFilter(module));
      setConsoleBuilder(consoleBuilder);

      return new OSProcessHandler(commandLine.createProcess(), commandLine.getCommandLineString());
    }

    private String getFileNameWithCurrentExtension(HaxeTarget haxeTarget, String fileName) {
      if (haxeTarget != null) {
        return haxeTarget.getTargetFileNameWithExtension(FileUtil.getNameWithoutExtension(fileName));
      }
      return fileName;
    }
  }, descriptor, environment);
}
 
Example 12
Source File: JetSymbolsExe.java    From teamcity-symbol-server with Apache License 2.0 5 votes vote down vote up
public int dumpPdbGuidsToFile(Collection<File> files, File output, BuildProgressLogger buildLogger) throws IOException {
  final GeneralCommandLine commandLine = new GeneralCommandLine();
  commandLine.setExePath(myExePath.getPath());
  commandLine.addParameter(DUMP_SYMBOL_SIGN_CMD);
  commandLine.addParameter(String.format("/o=%s", output.getPath()));
  commandLine.addParameter(String.format("/i=%s", dumpPathsToFile(files).getPath()));

  final ExecResult execResult = executeCommandLine(commandLine, buildLogger);
  if (execResult.getExitCode() == 0 && !execResult.getStdout().isEmpty()) {
    buildLogger.message("Stdout: " + execResult.getStdout());
  }

  return execResult.getExitCode();
}
 
Example 13
Source File: RNUtil.java    From react-native-console with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void build(Project project) {
    GeneralCommandLine commandLine = new GeneralCommandLine();
    commandLine.setWorkDirectory(project.getBasePath());
    commandLine.setExePath("python");
    commandLine.addParameter("freeline.py");
    // debug
    commandLine.addParameter("-d");

    // commands process
    try {
        processCommandline(project, commandLine);
    } catch (ExecutionException e) {
        e.printStackTrace();
    }
}
 
Example 14
Source File: CliBuilder.java    From eslint-plugin with MIT License 4 votes vote down vote up
@NotNull
static GeneralCommandLine createVersion(@NotNull ESLintRunner.ESLintSettings settings) {
    GeneralCommandLine commandLine = create(settings);
    commandLine.addParameter(V);
    return commandLine;
}
 
Example 15
Source File: MongoConsoleRunner.java    From nosql4idea with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
protected Process createProcess() throws ExecutionException {

    NoSqlConfiguration noSqlConfiguration = NoSqlConfiguration.getInstance(getProject());
    String shellPath = noSqlConfiguration.getShellPath(DatabaseVendor.MONGO);
    final GeneralCommandLine commandLine = new GeneralCommandLine();
    commandLine.setExePath(shellPath);

    commandLine.addParameter(MongoUtils.buildMongoUrl(serverConfiguration, database));

    String shellWorkingDir = serverConfiguration.getShellWorkingDir();
    if (StringUtils.isNotBlank(shellWorkingDir)) {
        commandLine.withWorkDirectory(shellWorkingDir);
    }

    AuthenticationSettings authenticationSettings = serverConfiguration.getAuthenticationSettings();

    String username = authenticationSettings.getUsername();
    if (StringUtils.isNotBlank(username)) {
        commandLine.addParameter("--username");
        commandLine.addParameter(username);
    }

    String password = authenticationSettings.getPassword();
    if (StringUtils.isNotBlank(password)) {
        commandLine.addParameter("--password");
        commandLine.addParameter(password);
    }

    MongoExtraSettings mongoExtraSettings = new MongoExtraSettings(authenticationSettings.getExtras());
    String authenticationDatabase = mongoExtraSettings.getAuthenticationDatabase();
    if (StringUtils.isNotBlank(authenticationDatabase)) {
        commandLine.addParameter("--authenticationDatabase");
        commandLine.addParameter(authenticationDatabase);
    }

    AuthenticationMechanism authenticationMecanism = mongoExtraSettings.getAuthenticationMechanism();
    if (authenticationMecanism != null) {
        commandLine.addParameter("--authenticationMecanism");
        commandLine.addParameter(authenticationMecanism.getMechanismName());
    }

    String shellArgumentsLine = serverConfiguration.getShellArgumentsLine();
    if (StringUtils.isNotBlank(shellArgumentsLine)) {
        commandLine.addParameters(shellArgumentsLine.split(" "));
    }

    return commandLine.createProcess();
}
 
Example 16
Source File: SassLintRunner.java    From sass-lint-plugin with MIT License 4 votes vote down vote up
@NotNull
private static ProcessOutput version(@NotNull SassLintSettings settings) throws ExecutionException {
    GeneralCommandLine commandLine = createCommandLine(settings);
    commandLine.addParameter("-V");
    return NodeRunner.execute(commandLine, TIME_OUT);
}
 
Example 17
Source File: JscsRunner.java    From jscs-plugin with MIT License 4 votes vote down vote up
@NotNull
private static ProcessOutput runVersion(@NotNull JscsSettings settings) throws ExecutionException {
    GeneralCommandLine commandLine = createCommandLine(settings);
    commandLine.addParameter("--version");
    return execute(commandLine, TIME_OUT);
}
 
Example 18
Source File: HaxeSdkUtil.java    From intellij-haxe with Apache License 2.0 4 votes vote down vote up
@Nullable
public static HaxeSdkData testHaxeSdk(String path) {
  final String exePath = getCompilerPathByFolderPath(path);

  if (exePath == null) {
    return null;
  }

  final GeneralCommandLine command = new GeneralCommandLine();
  command.setExePath(exePath);
  command.addParameter("-help");
  command.setWorkDirectory(path);

  try {
    final ProcessOutput output = new CapturingProcessHandler(
      command.createProcess(),
      Charset.defaultCharset(),
      command.getCommandLineString()).runProcess();

    if (output.getExitCode() != 0) {
      LOG.error("Haxe compiler exited with invalid exit code: " + output.getExitCode());
      return null;
    }

    final String outputString = output.getStderr();

    String haxeVersion = "NA";
    final Matcher matcher = VERSION_MATCHER.matcher(outputString);
    if (matcher.find()) {
      haxeVersion = matcher.group(1);
    }
    final HaxeSdkData haxeSdkData = new HaxeSdkData(path, haxeVersion);
    haxeSdkData.setHaxelibPath(getHaxelibPathByFolderPath(path));
    haxeSdkData.setNekoBinPath(suggestNekoBinPath(path));
    return haxeSdkData;
  }
  catch (ExecutionException e) {
    LOG.info("Exception while executing the process:", e);
    return null;
  }
}
 
Example 19
Source File: GaugeRunConfiguration.java    From Intellij-Plugin with Apache License 2.0 4 votes vote down vote up
private void addTableRowsRangeFlags(GeneralCommandLine commandLine) {
    if (!Strings.isBlank(rowsRange)) {
        commandLine.addParameter(Constants.TABLE_ROWS);
        commandLine.addParameter(rowsRange);
    }
}
 
Example 20
Source File: OSSPantsIdeaPluginGoalIntegrationTest.java    From intellij-pants-plugin with Apache License 2.0 4 votes vote down vote up
public void testPantsIdeaPluginGoal() throws Throwable {
  assertEmpty(ModuleManager.getInstance(myProject).getModules());

  /**
   * Check whether Pants supports `idea-plugin` goal.
   */
  final GeneralCommandLine commandLinePantsGoals = PantsUtil.defaultCommandLine(getProjectFolder().getPath());
  commandLinePantsGoals.addParameter("goals");
  final ProcessOutput cmdOutputGoals = PantsUtil.getCmdOutput(commandLinePantsGoals.withWorkDirectory(getProjectFolder()), null);
  assertEquals(commandLinePantsGoals.toString() + " failed", 0, cmdOutputGoals.getExitCode());
  if (!cmdOutputGoals.getStdout().contains("idea-plugin")) {
    return;
  }

  /**
   * Generate idea project via `idea-plugin` goal.
   */
  final GeneralCommandLine commandLine = PantsUtil.defaultCommandLine(getProjectFolder().getPath());
  final File outputFile = FileUtil.createTempFile("project_dir_location", ".out");
  String targetToImport = "testprojects/tests/java/org/pantsbuild/testproject/matcher:matcher";
  commandLine.addParameters(
    "idea-plugin",
    "--no-open",
    "--output-file=" + outputFile.getPath(),
    targetToImport
  );
  final ProcessOutput cmdOutput = PantsUtil.getCmdOutput(commandLine.withWorkDirectory(getProjectFolder()), null);
  assertEquals(commandLine.toString() + " failed", 0, cmdOutput.getExitCode());
  // `outputFile` contains the path to the project directory.
  String projectDir = FileUtil.loadFile(outputFile);

  // Search the directory for ipr file.
  File[] files = new File(projectDir).listFiles();
  assertNotNull(files);
  Optional<String> iprFile = Arrays.stream(files)
    .map(File::getPath)
    .filter(s -> s.endsWith(ProjectFileType.DOT_DEFAULT_EXTENSION))
    .findFirst();
  assertTrue(iprFile.isPresent());

  myProject = ProjectUtil.openProject(iprFile.get(), myProject, false);
  // Invoke post startup activities.
  UIUtil.dispatchAllInvocationEvents();
  /**
   * Under unit test mode, {@link com.intellij.ide.impl.ProjectUtil#openProject} will force open a project in a new window,
   * so Project SDK has to be reset. In practice, this is not needed.
   */
  ApplicationManager.getApplication().runWriteAction(new Runnable() {
    @Override
    public void run() {
      final JavaSdk javaSdk = JavaSdk.getInstance();
      ProjectRootManager.getInstance(myProject).setProjectSdk(ProjectJdkTable.getInstance().getSdksOfType(javaSdk).iterator().next());
    }
  });

  assertSuccessfulTest(PantsUtil.getCanonicalModuleName(targetToImport), "org.pantsbuild.testproject.matcher.MatcherTest");
  assertTrue(ProjectUtil.closeAndDispose(myProject));
}