KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > scriptella > util > BugReport


1 /*
2  * Copyright 2006-2007 The Scriptella Project Team.
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 package scriptella.util;
17
18 import scriptella.core.ExceptionInterceptor;
19 import scriptella.core.SystemException;
20 import scriptella.execution.EtlExecutorException;
21
22 import java.io.PrintWriter JavaDoc;
23 import java.io.StringWriter JavaDoc;
24
25 /**
26  * Represents bug report for unexpected conditions.
27  *
28  * @author Fyodor Kupolov
29  * @version 1.0
30  */

31 public class BugReport {
32     private Throwable JavaDoc throwable;
33
34     /**
35      * Creates bug report for throwable.
36      *
37      * @param throwable
38      */

39     public BugReport(Throwable JavaDoc throwable) {
40         this.throwable = throwable;
41     }
42
43     /**
44      * @param throwable
45      * @return true if throwable is likely to be caused by bug
46      */

47     public static boolean isPossibleBug(Throwable JavaDoc throwable) {
48         if (throwable instanceof ExceptionInterceptor.ExecutionException) {
49             //intercepted exceptions should be handled too
50
if (throwable.getCause() != null) {
51                 return isPossibleBug(throwable.getCause());
52             } else {
53                 return true; //intercepted exceptions must have cause
54
}
55         } else if (throwable instanceof EtlExecutorException) {
56             if (throwable.getCause() != null) {
57                 return isPossibleBug(throwable.getCause());
58             } else {
59                 return true; //EtlExecutorException must have cause
60
}
61         }
62         return !(throwable instanceof SystemException);
63     }
64
65     /**
66      * @return report content.
67      */

68     public String JavaDoc toString() {
69         //produce bug report
70
StringWriter JavaDoc rep = new StringWriter JavaDoc();
71         PrintWriter JavaDoc pw = new PrintWriter JavaDoc(rep);
72         pw.println("Scriptella bug report. Submit to issue tracker.");
73         Package JavaDoc p = BugReport.class.getPackage();
74         String JavaDoc version = p != null && p.getImplementationVersion() != null ? p.getImplementationVersion() : "Unknown";
75         pw.println("Scriptella version: " + version);
76         pw.println("Exception: ");
77         throwable.printStackTrace(pw);
78         pw.println("Environment: ");
79         pw.println(System.getenv());
80         pw.println("System properties: ");
81         pw.println(System.getProperties());
82         pw.println("-----------------------------------------------------------------");
83         //todo add information about version, thread states etc.
84
return rep.toString();
85
86     }
87
88
89 }
90
Popular Tags