Пример #1
0
 private String getGoEnvFromTool(ProcessExecutor processExecutor, String env) {
   Path goTool = getGoToolPath();
   Optional<Map<String, String>> goRootEnv =
       delegate
           .getPath("go", "root")
           .transform(
               new Function<Path, Map<String, String>>() {
                 @Override
                 public Map<String, String> apply(Path input) {
                   return ImmutableMap.of("GOROOT", input.toString());
                 }
               });
   try {
     ProcessExecutor.Result goToolResult =
         processExecutor.launchAndExecute(
             ProcessExecutorParams.builder()
                 .addCommand(goTool.toString(), "env", env)
                 .setEnvironment(goRootEnv)
                 .build(),
             EnumSet.of(ProcessExecutor.Option.EXPECTING_STD_ERR),
             /* stdin */ Optional.<String>absent(),
             /* timeOutMs */ Optional.<Long>absent(),
             /* timeoutHandler */ Optional.<Function<Process, Void>>absent());
     if (goToolResult.getExitCode() == 0) {
       return CharMatcher.WHITESPACE.trimFrom(goToolResult.getStdout().get());
     } else {
       throw new HumanReadableException(goToolResult.getStderr().get());
     }
   } catch (InterruptedException e) {
     throw Throwables.propagate(e);
   } catch (IOException e) {
     throw new HumanReadableException(e, "Could not run \"%s env %s\": %s", env, goTool);
   }
 }
 @Test
 public void fatJarWithOutput() throws IOException, InterruptedException {
   ProjectWorkspace workspace =
       TestDataHelper.createProjectWorkspaceForScenario(this, "fat_jar", tmp);
   workspace.setUp();
   Path jar = workspace.buildAndReturnOutput("//:bin-output");
   ProcessExecutor.Result result = workspace.runJar(jar);
   assertEquals("output", result.getStdout().get().trim());
   assertEquals("error", result.getStderr().get().trim());
 }
Пример #3
0
 @VisibleForTesting
 static PythonVersion extractPythonVersion(Path pythonPath, ProcessExecutor.Result versionResult) {
   if (versionResult.getExitCode() == 0) {
     String versionString =
         CharMatcher.WHITESPACE.trimFrom(
             CharMatcher.WHITESPACE.trimFrom(versionResult.getStderr().get())
                 + CharMatcher.WHITESPACE
                     .trimFrom(versionResult.getStdout().get())
                     .replaceAll("\u001B\\[[;\\d]*m", ""));
     Matcher matcher = PYTHON_VERSION_REGEX.matcher(versionString.split("\\r?\\n")[0]);
     if (!matcher.matches()) {
       throw new HumanReadableException(
           "`%s -V` returned an invalid version string %s", pythonPath, versionString);
     }
     return PythonVersion.of(matcher.group(1));
   } else {
     throw new HumanReadableException(versionResult.getStderr().get());
   }
 }