• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2009 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package vogar.commands;
18 
19 import java.util.List;
20 
21 /**
22  * Thrown when an out of process executable does not return normally.
23  */
24 public class CommandFailedException extends RuntimeException {
25 
26     private final List<String> args;
27     private final List<String> outputLines;
28 
CommandFailedException(List<String> args, List<String> outputLines)29     public CommandFailedException(List<String> args, List<String> outputLines) {
30         super(formatMessage(args, outputLines));
31         this.args = args;
32         this.outputLines = outputLines;
33     }
34 
getArgs()35     public List<String> getArgs() {
36         return args;
37     }
38 
getOutputLines()39     public List<String> getOutputLines() {
40         return outputLines;
41     }
42 
formatMessage(List<String> args, List<String> outputLines)43     public static String formatMessage(List<String> args, List<String> outputLines) {
44         StringBuilder result = new StringBuilder();
45         result.append("Command failed:");
46         for (String arg : args) {
47             result.append(" ").append(arg);
48         }
49         for (String outputLine : outputLines) {
50             result.append("\n  ").append(outputLine);
51         }
52         return result.toString();
53     }
54 
55     private static final long serialVersionUID = 0;
56 }
57