|
1 /* |
|
2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 package com.nokia.s60tools.crashanalyser.files; |
|
19 |
|
20 import java.io.File; |
|
21 import java.util.Date; |
|
22 import org.xml.sax.helpers.DefaultHandler; |
|
23 import com.nokia.s60tools.crashanalyser.data.*; |
|
24 import java.text.DateFormat; |
|
25 |
|
26 /** |
|
27 * This is a base class for all Crash Analyser file types. |
|
28 * |
|
29 */ |
|
30 public abstract class CrashAnalyserFile extends DefaultHandler{ |
|
31 |
|
32 // File extensions |
|
33 public static final String OUTPUT_FILE_EXTENSION = "crashxml"; |
|
34 public static final String MOBILECRASH_FILE_EXTENSION = "bin"; |
|
35 public static final String D_EXC_FILE_EXTENSION = "txt"; |
|
36 public static final String TRACE_EXTENSION = "trace"; |
|
37 public static final String ELF_CORE_DUMP_FILE_EXTENSION = "elf"; |
|
38 public static final String SUMMARY_FILE_EXTENSION = "xml"; |
|
39 public static final String EMULATOR_PANIC_EXTENSION = "panicxml"; |
|
40 |
|
41 // base data for all crash files |
|
42 protected String filePath = ""; |
|
43 protected String time = ""; |
|
44 protected String threadName = ""; |
|
45 protected String panicCategory = ""; |
|
46 protected String fileName = ""; |
|
47 protected String created = ""; |
|
48 protected String description = ""; |
|
49 protected String shortDescription = ""; |
|
50 protected String romId = ""; |
|
51 protected String panicCode = ""; |
|
52 |
|
53 protected ErrorLibrary errorLibrary; |
|
54 |
|
55 /** |
|
56 * Constructor |
|
57 * @param crashFilePath crash file path |
|
58 * @param library error library |
|
59 */ |
|
60 protected CrashAnalyserFile(String crashFilePath, ErrorLibrary library) { |
|
61 filePath = crashFilePath; |
|
62 errorLibrary = library; |
|
63 } |
|
64 |
|
65 public abstract String getFileType(); |
|
66 |
|
67 public String getTime() { |
|
68 return time; |
|
69 } |
|
70 |
|
71 public String getThreadName() { |
|
72 return threadName; |
|
73 } |
|
74 |
|
75 public String getPanicCategory() { |
|
76 return panicCategory; |
|
77 } |
|
78 |
|
79 public String getFileName() { |
|
80 return fileName; |
|
81 } |
|
82 |
|
83 public String getPanicCode() { |
|
84 return panicCode; |
|
85 } |
|
86 |
|
87 public String getCreated() { |
|
88 return created; |
|
89 } |
|
90 |
|
91 public String getDescription() { |
|
92 return description; |
|
93 } |
|
94 |
|
95 public String getShortDescription() { |
|
96 return shortDescription; |
|
97 } |
|
98 |
|
99 public String getRomId() { |
|
100 return romId; |
|
101 } |
|
102 |
|
103 public String getFilePath() { |
|
104 return filePath; |
|
105 } |
|
106 |
|
107 /** |
|
108 * Read file name and last modified time |
|
109 */ |
|
110 protected void doRead() { |
|
111 File f = new File(filePath); |
|
112 if (f.exists() && f.isFile()) { |
|
113 Date d = new Date(f.lastModified()); |
|
114 created = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM).format(d); |
|
115 fileName = f.getName(); |
|
116 } else { |
|
117 filePath = ""; |
|
118 } |
|
119 } |
|
120 |
|
121 /** |
|
122 * Returns the absolute path for a crash file. Given folder can only |
|
123 * contain one crash file of given extension. |
|
124 * @param folder from where the file is searched |
|
125 * @param extension extension of the file |
|
126 * @return absolute path for a wanted crash file. |
|
127 */ |
|
128 protected static String findFile(String folder, String extension) { |
|
129 String ext = extension; |
|
130 if (!extension.startsWith(".")) |
|
131 ext = "." + extension; |
|
132 |
|
133 File cFolder = new File(folder); |
|
134 // given folder is directory and is exists |
|
135 if (cFolder.isDirectory() && cFolder.exists()) { |
|
136 File[] files = cFolder.listFiles(); |
|
137 if (files != null) { |
|
138 // go through all files |
|
139 for (int i = 0; i < files.length; i++) { |
|
140 File file = files[i]; |
|
141 // return the file which has the given extension |
|
142 if (file.getName().endsWith(ext)) { |
|
143 return file.getAbsolutePath(); |
|
144 } |
|
145 } |
|
146 } |
|
147 } |
|
148 |
|
149 return null; |
|
150 } |
|
151 } |