-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathArgParser.java
More file actions
137 lines (127 loc) · 3.15 KB
/
ArgParser.java
File metadata and controls
137 lines (127 loc) · 3.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import java.io.File;
import java.io.IOException;
/**
* 此类用来处理命令行参数。
*/
public class ArgParser {
/**
* SO符号表的路径
*/
private String mSymParam;
/**
* 崩溃日志路径
*/
private String mDumpParam;
/**
* 最多分析多少条日志
*/
private int mMaxParam;
/**
* 解析命令行参数,并验证命令行参数。
* @param args 命令行参数
* @return 成功返回true,否则返回false
*/
public boolean parse(String[] args) {
for (int i = 0; i < args.length; i++) {
if (args[i].equals("-sym")) {
if (i + 1 < args.length) {
mSymParam = args[i + 1];
i++;
} else {
printLoseValue(args[i]);
return false;
}
} else if (args[i].equals("-dump")) {
if (i + 1 < args.length) {
mDumpParam = args[i + 1];
i++;
} else {
printLoseValue(args[i]);
return false;
}
} else if (args[i].equals("-max")) {
if (i + 1 < args.length) {
try {
mMaxParam = Integer.parseInt(args[i + 1]);
} catch (NumberFormatException e) {
System.err.println("error: invalid value for \"max\" parameter.");
return false;
}
i++;
} else {
printLoseValue(args[i]);
return false;
}
} else {
System.err.println(String.format("error: invalid parameter \"%s\",please see usage bellow:", args[i]));
printUsage();
return false;
}
}
if (mDumpParam == null) {
System.err.println("error: lose parameter \"-dump\".");
printUsage();
return false;
}
if (mSymParam != null) {
try {
Runtime.getRuntime().exec("ndk-stack");
} catch (IOException e) {
System.err
.println("error:\"ndk-stack\" command not found,please add \"ndk-stack\" to path environment.");
return false;
}
}
if (mSymParam != null) {
if (!new File(mSymParam).exists()) {
System.err.println(String.format("error: can not find file:%s", mSymParam));
printUsage();
return false;
}
}
if (mDumpParam != null) {
if (!new File(mDumpParam).exists()) {
System.err.println(String.format("error: can not find file:%s", mDumpParam));
printUsage();
return false;
}
}
return true;
}
/**
* 某个参数未指定值时,输出提示信息
*/
private void printLoseValue(String param) {
System.err.println(String.format("error: lose value for \"%s\" paramter,please see usage bellow:", param));
printUsage();
}
/**
* 输出帮助文档
*/
private void printUsage() {
System.out.println("Usage:");
System.out.println(" acrash-report -sym <path> [-dump <path>]");
System.out.println();
System.out.println(" -dump Contains full path to the file containing the crash dump.");
System.out.println(" -sym Contains full path to the root directory for symbols.");
System.out.println(" This is an optional parameter. If ommited, C crash will ignore.");
}
/**
* @return 返回SO符号表的路径
*/
public String getSymParam() {
return mSymParam;
}
/**
* @return 返回崩溃日志路径
*/
public String getDumpParam() {
return mDumpParam;
}
/**
* @return 返回最多分析多少条日志
*/
public int getMaxParam() {
return mMaxParam;
}
}