01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19: package org.apache.openjpa.persistence.common.utils;
20:
21: import java.io.*;
22:
23: import junit.framework.*;
24:
25: /**
26: * Extension of an assertion error that indicates to the outside
27: * build process (if any) that an assertion failed due to a known
28: * bug.
29: *
30: * @author Marc Prud'hommeaux
31: */
32: public class Bug extends AssertionFailedError {
33:
34: public static final String BUG_TOKEN = "SOLARBUG";
35: public static final String BUG_DELIMITER = "|";
36:
37: private Throwable error = null;
38: private int trackingId;
39:
40: // the the static factory method, please
41: private Bug(int trackingId, Throwable t, String message) {
42: super (BUG_DELIMITER + BUG_TOKEN + BUG_DELIMITER + trackingId
43: + BUG_DELIMITER + message);
44: this .trackingId = trackingId;
45: error = t;
46:
47: printStackTrace(System.err);
48: }
49:
50: public static Bug bug(int trackingId, Throwable t, String message) {
51: return new Bug(trackingId, t, message);
52: }
53:
54: public void printStackTrace(PrintWriter pw) {
55: super .printStackTrace(pw);
56: if (error != null) {
57: pw.println("Embedded error message:");
58: error.printStackTrace(pw);
59: }
60: }
61:
62: public void printStackTrace(PrintStream ps) {
63: super .printStackTrace(ps);
64: if (error != null) {
65: ps.println("Embedded error message:");
66: error.printStackTrace(ps);
67: }
68: }
69:
70: public String getMessage() {
71: return super .getMessage() + " [reported bug #" + trackingId
72: + "]";
73: }
74:
75: public int getTrackingId() {
76: return trackingId;
77: }
78: }
|