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

The following examples show how to use com.intellij.execution.configurations.GeneralCommandLine#withWorkDirectory() . 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: BuckCommandHandler.java    From Buck-IntelliJ-Plugin with Apache License 2.0 6 votes vote down vote up
/**
 * @param project   a project
 * @param directory a process directory
 * @param command   a command to execute (if empty string, the parameter is ignored)
 */
public BuckCommandHandler(
    Project project,
    File directory,
    BuckCommand command) {

  String buckExecutable = BuckSettingsProvider.getInstance().getState().buckExecutable;

  mProject = project;
  mCommand = command;
  mCommandLine = new GeneralCommandLine();
  mCommandLine.setExePath(buckExecutable);
  mWorkingDirectory = directory;
  mCommandLine.withWorkDirectory(mWorkingDirectory);
  mCommandLine.addParameter(command.name());
}
 
Example 2
Source File: BashRunConfigUtil.java    From BashSupport with Apache License 2.0 6 votes vote down vote up
@NotNull
public static GeneralCommandLine createCommandLine(String workingDir, BashRunConfiguration runConfig) {
    String interpreterPath;
    if (runConfig.isUseProjectInterpreter()) {
        interpreterPath = BashProjectSettings.storedSettings(runConfig.getProject()).getProjectInterpreter();
    } else {
        interpreterPath = runConfig.getInterpreterPath();
    }

    GeneralCommandLine cmd = new GeneralCommandLine();
    cmd.setExePath(interpreterPath);
    cmd.getParametersList().addParametersString(runConfig.getInterpreterOptions());

    cmd.addParameter(runConfig.getScriptName());
    cmd.getParametersList().addParametersString(runConfig.getProgramParameters());

    cmd.withWorkDirectory(workingDir);
    cmd.withParentEnvironmentType(runConfig.isPassParentEnvs() ? GeneralCommandLine.ParentEnvironmentType.CONSOLE : GeneralCommandLine.ParentEnvironmentType.NONE);
    cmd.withEnvironment(runConfig.getEnvs());
    return cmd;
}
 
Example 3
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 4
Source File: PantsUtil.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
@NotNull
public static GeneralCommandLine defaultCommandLine(@NotNull File pantsExecutable) {
  final GeneralCommandLine commandLine = new GeneralCommandLine();
  final String pantsExecutablePath = StringUtil.notNullize(
    System.getProperty("pants.executable.path"),
    pantsExecutable.getAbsolutePath()
  );
  commandLine.setExePath(pantsExecutablePath);
  final String workingDir = pantsExecutable.getParentFile().getAbsolutePath();
  return commandLine.withWorkDirectory(workingDir);
}
 
Example 5
Source File: BuckWSServerPortUtils.java    From buck with Apache License 2.0 5 votes vote down vote up
/** Returns the port number of Buck's HTTP server, if it can be determined. */
public static int getPort(Project project, String path)
    throws NumberFormatException, IOException, ExecutionException {
  String exec = BuckExecutableSettingsProvider.getInstance(project).resolveBuckExecutable();

  if (Strings.isNullOrEmpty(exec)) {
    throw new RuntimeException("Buck executable is not defined in settings.");
  }

  GeneralCommandLine commandLine = new GeneralCommandLine();
  commandLine.setExePath(exec);
  commandLine.withWorkDirectory(path);
  commandLine.withEnvironment(EnvironmentUtil.getEnvironmentMap());
  commandLine.addParameter("server");
  commandLine.addParameter("status");
  commandLine.addParameter("--reuse-current-config");
  commandLine.addParameter("--http-port");
  commandLine.setRedirectErrorStream(true);

  Process p = commandLine.createProcess();
  BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));

  String line;
  while ((line = reader.readLine()) != null) {
    if (line.startsWith(SEARCH_FOR)) {
      return Integer.parseInt(line.substring(SEARCH_FOR.length()));
    }
  }
  throw new RuntimeException(
      "Configured buck executable did not report a valid port string,"
          + " ensure "
          + commandLine.getCommandLineString()
          + " can be run from "
          + path);
}
 
Example 6
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();
}