Java Code Examples for com.intellij.execution.configurations.GeneralCommandLine#addParameters()
The following examples show how to use
com.intellij.execution.configurations.GeneralCommandLine#addParameters() .
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: FlutterCommand.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * 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 2
Source File: GaugeRunConfiguration.java From Intellij-Plugin with Apache License 2.0 | 6 votes |
private void addProgramArguments(GeneralCommandLine commandLine) { if (programParameters == null) { return; } String parameters = programParameters.getProgramParameters(); if (!Strings.isEmpty(parameters)) { commandLine.addParameters(programParameters.getProgramParameters().split(" ")); } Map<String, String> envs = programParameters.getEnvs(); if (!envs.isEmpty()) { commandLine.withEnvironment(envs); } if (Strings.isNotEmpty(programParameters.getWorkingDirectory())) { commandLine.setWorkDirectory(new File(programParameters.getWorkingDirectory())); } }
Example 3
Source File: FlutterCommand.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * 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: BaseExternalTool.java From consulo with Apache License 2.0 | 6 votes |
public void show(DiffRequest request) { for (DiffContent diffContent : request.getContents()) { Document document = diffContent.getDocument(); if (document != null) { FileDocumentManager.getInstance().saveDocument(document); } } GeneralCommandLine commandLine = new GeneralCommandLine(); commandLine.setExePath(getToolPath()); try { commandLine.addParameters(getParameters(request)); commandLine.createProcess(); } catch (Exception e) { ExecutionErrorDialog.show(new ExecutionException(e.getMessage()), DiffBundle.message("cant.launch.diff.tool.error.message"), request.getProject()); } }
Example 5
Source File: GaugeRunConfiguration.java From Intellij-Plugin with Apache License 2.0 | 6 votes |
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: BrowserLauncherAppless.java From consulo with Apache License 2.0 | 6 votes |
private static void addArgs(@Nonnull GeneralCommandLine command, @Nullable BrowserSpecificSettings settings, @Nonnull String[] additional) { List<String> specific = settings == null ? Collections.<String>emptyList() : settings.getAdditionalParameters(); if (specific.size() + additional.length > 0) { if (isOpenCommandUsed(command)) { if (BrowserUtil.isOpenCommandSupportArgs()) { command.addParameter("--args"); } else { LOG.warn("'open' command doesn't allow to pass command line arguments so they will be ignored: " + StringUtil.join(specific, ", ") + " " + Arrays.toString(additional)); return; } } command.addParameters(specific); command.addParameters(additional); } }
Example 7
Source File: SimpleExportResult.java From intellij-pants-plugin with Apache License 2.0 | 6 votes |
@NotNull public static SimpleExportResult getExportResult(@NotNull String pantsExecutable) { File pantsExecutableFile = new File(pantsExecutable); SimpleExportResult cache = simpleExportCache.get(pantsExecutableFile); if (cache != null) { return cache; } final GeneralCommandLine commandline = PantsUtil.defaultCommandLine(pantsExecutable); commandline.addParameters("--no-quiet", "export", PantsConstants.PANTS_CLI_OPTION_NO_COLORS); try (TempFile tempFile = TempFile.create("pants_export_run", ".out")) { commandline.addParameter( String.format("%s=%s", PantsConstants.PANTS_CLI_OPTION_EXPORT_OUTPUT_FILE, tempFile.getFile().getPath())); final ProcessOutput processOutput = PantsUtil.getCmdOutput(commandline, null); if (processOutput.checkSuccess(LOG)) { SimpleExportResult result = parse(FileUtil.loadFile(tempFile.getFile())); simpleExportCache.put(pantsExecutableFile, result); return result; } } catch (IOException | ExecutionException e) { // Fall-through to handle outside the block. } throw new PantsException("Failed:" + commandline.getCommandLineString()); }
Example 8
Source File: FastpassUpdater.java From intellij-pants-plugin with Apache License 2.0 | 6 votes |
private static boolean runFastpassRefresh(FastpassData data, Project project) { try { GeneralCommandLine commandLine = PantsUtil.defaultCommandLine(project); commandLine.setExePath(FASTPASS_PATH); commandLine.addParameters( "refresh", "--intellij", "--intellijLauncher", "echo", // to avoid opening project again data.projectName ); Process refresh = commandLine.createProcess(); refresh.waitFor(); return refresh.exitValue() == 0; } catch (Exception e) { LOG.warn(e); return false; } }
Example 9
Source File: GeneralCommandLineTest.java From consulo with Apache License 2.0 | 6 votes |
@Test public void printCommandLine() { GeneralCommandLine commandLine = new GeneralCommandLine(); commandLine.setExePath("e x e path"); commandLine.addParameter("with space"); commandLine.addParameter("\"quoted\""); commandLine.addParameter("\"quoted with spaces\""); commandLine.addParameters("param 1", "param2"); commandLine.addParameter("trailing slash\\"); assertEquals("\"e x e path\"" + " \"with space\"" + " \\\"quoted\\\"" + " \"\\\"quoted with spaces\\\"\"" + " \"param 1\"" + " param2" + " \"trailing slash\\\"", commandLine.getCommandLineString()); }
Example 10
Source File: GeneralCommandLineTest.java From consulo with Apache License 2.0 | 6 votes |
@Test public void argumentsPassing() throws Exception { String[] parameters = { "with space", "\"quoted\"", "\"quoted with spaces\"", "", " ", "param 1", "\"", "param2", "trailing slash\\" }; GeneralCommandLine commandLine = makeJavaCommand(ParamPassingTest.class, null); commandLine.addParameters(parameters); String output = execAndGetOutput(commandLine, null); assertEquals("=====\n" + StringUtil.join(parameters, new Function<String, String>() { @Override public String fun(String s) { return ParamPassingTest.format(s); } }, "\n") + "\n=====\n", StringUtil.convertLineSeparators(output)); }
Example 11
Source File: GaugeRunConfiguration.java From Intellij-Plugin with Apache License 2.0 | 5 votes |
private void addParallelExecFlags(GeneralCommandLine commandLine, ExecutionEnvironment env) { if (parallelExec(env)) { commandLine.addParameter(Constants.PARALLEL); try { if (!Strings.isEmpty(parallelNodes)) { Integer.parseInt(this.parallelNodes); commandLine.addParameters(Constants.PARALLEL_NODES, parallelNodes); } } catch (NumberFormatException e) { System.err.println("Incorrect number of parallel execution streams specified: " + parallelNodes); LOG.debug("Incorrect number of parallel execution streams specified: " + parallelNodes); e.printStackTrace(); } } }
Example 12
Source File: RNUtil.java From react-native-console with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static void runGradleCI(Project project, String... params) { String path = RNPathUtil.getRNProjectPath(project); String gradleLocation = RNPathUtil.getAndroidProjectPath(path); if (gradleLocation == null) { NotificationUtils.gradleFileNotFound(); } else { GeneralCommandLine commandLine = new GeneralCommandLine(); // ExecutionEnvironment environment = getEnvironment(); commandLine.setWorkDirectory(gradleLocation); commandLine.setExePath("." + File.separator + "gradlew"); commandLine.addParameters(params); // try { //// Process process = commandLine.createProcess(); // OSProcessHandler processHandler = new KillableColoredProcessHandler(commandLine); // RunnerUtil.showHelperProcessRunContent("Update AAR", processHandler, project, DefaultRunExecutor.getRunExecutorInstance()); // // Run // processHandler.startNotify(); // } catch (ExecutionException e) { // e.printStackTrace(); // NotificationUtils.errorNotification("Can't execute command: " + e.getMessage()); // } // commands process try { processCommandline(project, commandLine); } catch (ExecutionException e) { e.printStackTrace(); } } }
Example 13
Source File: ExecUtil.java From intellij-haskforce with Apache License 2.0 | 5 votes |
@NotNull public static Either<ExecError, String> readCommandLine(@Nullable String workingDirectory, @NotNull String command, @NotNull String[] params, @Nullable String input) { GeneralCommandLine commandLine = new GeneralCommandLine(command); if (workingDirectory != null) { commandLine.setWorkDirectory(workingDirectory); } commandLine.addParameters(params); return readCommandLine(commandLine, input); }
Example 14
Source File: ExecutableValidator.java From consulo with Apache License 2.0 | 5 votes |
protected static boolean doCheckExecutable(@Nonnull String executable, @Nonnull List<String> processParameters) { try { GeneralCommandLine commandLine = new GeneralCommandLine(); commandLine.setExePath(executable); commandLine.addParameters(processParameters); commandLine.setCharset(CharsetToolkit.getDefaultSystemCharset()); CapturingProcessHandler handler = new CapturingProcessHandler(commandLine); ProcessOutput result = handler.runProcess(TIMEOUT_MS); boolean timeout = result.isTimeout(); int exitCode = result.getExitCode(); String stderr = result.getStderr(); if (timeout) { LOG.warn("Validation of " + executable + " failed with a timeout"); } if (exitCode != 0) { LOG.warn("Validation of " + executable + " failed with a non-zero exit code: " + exitCode); } if (!stderr.isEmpty()) { LOG.warn("Validation of " + executable + " failed with a non-empty error output: " + stderr); } return !timeout && exitCode == 0 && stderr.isEmpty(); } catch (Throwable t) { LOG.warn(t); return false; } }
Example 15
Source File: JdkUtil.java From consulo with Apache License 2.0 | 5 votes |
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 16
Source File: DevToolsManager.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Gets the process handler that will start DevTools in bazel. */ @Nullable private OSProcessHandler getProcessHandlerForBazel() { final WorkspaceCache workspaceCache = WorkspaceCache.getInstance(project); if (!workspaceCache.isBazel()) { return null; } final Workspace workspace = workspaceCache.get(); assert (workspace != null); if (workspace.getDevtoolsScript() == null) { return null; } final GeneralCommandLine commandLine = new GeneralCommandLine().withWorkDirectory(workspace.getRoot().getPath()); commandLine.setExePath(FileUtil.toSystemDependentName(workspace.getRoot().getPath() + "/" + workspace.getLaunchScript())); commandLine.setCharset(CharsetToolkit.UTF8_CHARSET); commandLine.addParameters(workspace.getDevtoolsScript(), "--", "--machine", "--port=0"); OSProcessHandler handler; try { handler = new MostlySilentOsProcessHandler(commandLine); } catch (ExecutionException e) { FlutterUtils.warn(LOG, e); handler = null; } if (handler != null) { FlutterConsoles.displayProcessLater(handler, project, null, handler::startNotify); } return handler; }
Example 17
Source File: GaugeRerunFailedAction.java From Intellij-Plugin with Apache License 2.0 | 5 votes |
@Nullable @Override public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment env) throws ExecutionException { GeneralCommandLine commandLine = GaugeCommandLine.getInstance(config.getModule(), getProject()); commandLine.addParameters(Constants.RUN, Constants.FAILED); return new GaugeCommandLineState(commandLine, getProject(), env, config); }
Example 18
Source File: OSSPantsIdeaPluginGoalIntegrationTest.java From intellij-pants-plugin with Apache License 2.0 | 4 votes |
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)); }
Example 19
Source File: SourceJarGenerator.java From intellij-pants-plugin with Apache License 2.0 | 4 votes |
private static List<String> getSourcesForTarget(Project project, String targetAddress) { GeneralCommandLine cmd = PantsUtil.defaultCommandLine(project); try { cmd.addParameters("filemap", targetAddress); final ProcessOutput processOutput = PantsUtil.getCmdOutput(cmd, null); if (processOutput.checkSuccess(LOG)) { String stdout = processOutput.getStdout(); return Arrays.stream(stdout.split("\n")) .map(String::trim) .filter(s -> !s.isEmpty()) .map(line -> line.split("\\s+")) .filter(s -> targetAddress.equals(s[1])) .map(s -> s[0]) .collect(Collectors.toList()); } else { List<String> errorLogs = Lists.newArrayList( String.format( "Could not list sources for target: Pants exited with status %d", processOutput.getExitCode() ), String.format("argv: '%s'", cmd.getCommandLineString()), "stdout:", processOutput.getStdout(), "stderr:", processOutput.getStderr() ); final String errorMessage = String.join("\n", errorLogs); LOG.warn(errorMessage); throw new PantsException(errorMessage); } } catch (ExecutionException e) { final String processCreationFailureMessage = String.format( "Could not execute command: '%s' due to error: '%s'", cmd.getCommandLineString(), e.getMessage() ); LOG.warn(processCreationFailureMessage, e); throw new PantsException(processCreationFailureMessage); } }
Example 20
Source File: PantsUtil.java From intellij-pants-plugin with Apache License 2.0 | 4 votes |
public static Collection<String> listAllTargets(@NotNull String projectPath) throws PantsException { if (!PantsUtil.isBUILDFilePath(projectPath)) { return Lists.newArrayList(); } GeneralCommandLine cmd = PantsUtil.defaultCommandLine(projectPath); try (TempFile tempFile = TempFile.create("list", ".out")) { cmd.addParameters( "list", Paths.get(projectPath).getParent().toString() + ':', String.format("%s=%s", PantsConstants.PANTS_CLI_OPTION_LIST_OUTPUT_FILE, tempFile.getFile().getPath() ) ); final ProcessOutput processOutput = PantsUtil.getCmdOutput(cmd, null); if (processOutput.checkSuccess(LOG)) { // output only exists if "list" task succeeds final String output = FileUtil.loadFile(tempFile.getFile()); return Arrays.asList(output.split("\n")); } else { List<String> errorLogs = Lists.newArrayList( String.format( "Could not list targets: Pants exited with status %d", processOutput.getExitCode() ), String.format("argv: '%s'", cmd.getCommandLineString()), "stdout:", processOutput.getStdout(), "stderr:", processOutput.getStderr() ); final String errorMessage = String.join("\n", errorLogs); LOG.warn(errorMessage); throw new PantsException(errorMessage); } } catch (IOException | ExecutionException e) { final String processCreationFailureMessage = String.format( "Could not execute command: '%s' due to error: '%s'", cmd.getCommandLineString(), e.getMessage() ); LOG.warn(processCreationFailureMessage, e); throw new PantsException(processCreationFailureMessage); } }