예제 #1
1
 public static boolean testCommand(
     final Context context,
     final String command,
     final String contains,
     final List<String> arguments) {
   try {
     final List<String> commandAndArgs = new ArrayList<String>();
     commandAndArgs.add(command);
     commandAndArgs.addAll(arguments);
     final ProcessBuilder pb = new ProcessBuilder(commandAndArgs);
     logCommand(context, pb);
     final Process compilation = pb.start();
     final ConsumeStream result = ConsumeStream.start(compilation.getInputStream(), null);
     final ConsumeStream error = ConsumeStream.start(compilation.getErrorStream(), null);
     compilation.waitFor();
     result.join();
     error.join();
     return error.output.toString().contains(contains)
         || result.output.toString().contains(contains);
   } catch (IOException ex) {
     context.log(ex.getMessage());
     return false;
   } catch (InterruptedException ex) {
     context.log(ex.getMessage());
     return false;
   }
 }
예제 #2
0
 public static Either<CommandResult> runCommand(
     final Context context, final String command, final File path, final List<String> arguments) {
   try {
     final List<String> commandAndArgs = new ArrayList<String>();
     commandAndArgs.add(command);
     commandAndArgs.addAll(arguments);
     final ProcessBuilder pb = new ProcessBuilder(commandAndArgs);
     if (path != null) {
       pb.directory(path);
     }
     logCommand(context, pb);
     final Process compilation = pb.start();
     final ConsumeStream result = ConsumeStream.start(compilation.getInputStream(), context);
     final ConsumeStream error = ConsumeStream.start(compilation.getErrorStream(), context);
     final int exitCode = compilation.waitFor();
     result.join();
     error.join();
     if (result.exception != null) {
       return Either.fail(result.exception);
     }
     if (error.exception != null) {
       return Either.fail(error.exception);
     }
     return Either.success(
         new CommandResult(result.output.toString(), error.output.toString(), exitCode));
   } catch (IOException ex) {
     return Either.fail(ex);
   } catch (InterruptedException ex) {
     return Either.fail(ex);
   }
 }
예제 #3
0
 public static ConsumeStream start(final InputStream stream, final Context context) {
   if (stream == null) {
     return new ConsumeStream();
   }
   final ConsumeStream cs = new ConsumeStream(stream, context);
   cs.start();
   return cs;
 }