View Javadoc
1   /*
2    * Copyright (C) 2015, Christian Halstrick <christian.halstrick@sap.com> and
3    * other copyright owners as documented in the project's IP log.
4    *
5    * This program and the accompanying materials are made available under the
6    * terms of the Eclipse Distribution License v1.0 which accompanies this
7    * distribution, is reproduced below, and is available at
8    * http://www.eclipse.org/org/documents/edl-v10.php
9    *
10   * All rights reserved.
11   *
12   * Redistribution and use in source and binary forms, with or without
13   * modification, are permitted provided that the following conditions are met:
14   *
15   * - Redistributions of source code must retain the above copyright notice, this
16   * list of conditions and the following disclaimer.
17   *
18   * - Redistributions in binary form must reproduce the above copyright notice,
19   * this list of conditions and the following disclaimer in the documentation
20   * and/or other materials provided with the distribution.
21   *
22   * - Neither the name of the Eclipse Foundation, Inc. nor the names of its
23   * contributors may be used to endorse or promote products derived from this
24   * software without specific prior written permission.
25   *
26   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
30   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36   * POSSIBILITY OF SUCH DAMAGE.
37   */
38  
39  package org.eclipse.jgit.api.errors;
40  
41  import java.text.MessageFormat;
42  
43  import org.eclipse.jgit.internal.JGitText;
44  
45  /**
46   * Exception thrown when the execution of a filter command failed
47   *
48   * @since 4.2
49   */
50  public class FilterFailedException extends GitAPIException {
51  	private static final long serialVersionUID = 1L;
52  
53  	private String filterCommand;
54  
55  	private String path;
56  
57  	private byte[] stdout;
58  
59  	private String stderr;
60  
61  	private int rc;
62  
63  	/**
64  	 * Thrown if during execution of filter command an exception occurred
65  	 *
66  	 * @param cause
67  	 *            the exception
68  	 * @param filterCommand
69  	 *            the command which failed
70  	 * @param path
71  	 *            the path processed by the filter
72  	 */
73  	public FilterFailedException(Exception cause, String filterCommand,
74  			String path) {
75  		super(MessageFormat.format(JGitText.get().filterExecutionFailed,
76  				filterCommand, path), cause);
77  		this.filterCommand = filterCommand;
78  		this.path = path;
79  	}
80  
81  	/**
82  	 * Thrown if a filter command returns a non-zero return code
83  	 *
84  	 * @param rc
85  	 *            the return code
86  	 * @param filterCommand
87  	 *            the command which failed
88  	 * @param path
89  	 *            the path processed by the filter
90  	 * @param stdout
91  	 *            the output the filter generated so far. This should be limited
92  	 *            to reasonable size.
93  	 * @param stderr
94  	 *            the stderr output of the filter
95  	 */
96  	@SuppressWarnings("boxing")
97  	public FilterFailedException(int rc, String filterCommand, String path,
98  			byte[] stdout, String stderr) {
99  		super(MessageFormat.format(JGitText.get().filterExecutionFailedRc,
100 				filterCommand, path, rc, stderr));
101 		this.rc = rc;
102 		this.filterCommand = filterCommand;
103 		this.path = path;
104 		this.stdout = stdout;
105 		this.stderr = stderr;
106 	}
107 
108 	/**
109 	 * Get filter command
110 	 *
111 	 * @return the filterCommand
112 	 */
113 	public String getFilterCommand() {
114 		return filterCommand;
115 	}
116 
117 	/**
118 	 * Get path
119 	 *
120 	 * @return the path of the file processed by the filter command
121 	 */
122 	public String getPath() {
123 		return path;
124 	}
125 
126 	/**
127 	 * Get output
128 	 *
129 	 * @return the output generated by the filter command. Might be truncated to
130 	 *         limit memory consumption.
131 	 */
132 	public byte[] getOutput() {
133 		return stdout;
134 	}
135 
136 	/**
137 	 * Get error
138 	 *
139 	 * @return the error output returned by the filter command
140 	 */
141 	public String getError() {
142 		return stderr;
143 	}
144 
145 	/**
146 	 * Get return code
147 	 *
148 	 * @return the return code returned by the filter command
149 	 */
150 	public int getReturnCode() {
151 		return rc;
152 	}
153 
154 }