1 /* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Eclipse Public License, Version 1.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.eclipse.org/org/documents/epl-v10.php 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 com.android.ide.eclipse.adt.internal.build; 18 19 /** 20 * Base exception class containing the error code and output of an external tool failed exec. 21 * 22 */ 23 class ExecResultException extends Exception { 24 private static final long serialVersionUID = 1L; 25 26 private final int mErrorCode; 27 private final String[] mOutput; 28 ExecResultException(int errorCode, String[] output)29 protected ExecResultException(int errorCode, String[] output) { 30 mErrorCode = errorCode; 31 mOutput = output; 32 } 33 34 /** 35 * Returns the full output of aapt. 36 */ getOutput()37 public String[] getOutput() { 38 return mOutput; 39 } 40 41 /** 42 * Returns the aapt return code. 43 */ getErrorCode()44 public int getErrorCode() { 45 return mErrorCode; 46 } 47 getLabel()48 public String getLabel() { 49 return "Command-line"; 50 } 51 52 @Override toString()53 public String toString() { 54 String result = String.format("%1$s Error %2$d", getLabel(), mErrorCode); 55 if (mOutput != null && mOutput.length > 0) { 56 // Note : the "error detail" window in Eclipse seem to ignore the \n, 57 // so we prefix them with a space. It's not optimal but it's slightly readable. 58 result += " \nOutput:"; 59 for (String o : mOutput) { 60 if (o != null) { 61 result += " \n" + o; 62 } 63 } 64 } 65 return result; 66 } 67 68 @Override getMessage()69 public String getMessage() { 70 return toString(); 71 } 72 } 73