您的位置:首页 > 其它

老李推荐:第8章2节《MonkeyRunner源码剖析》MonkeyRunner启动运行过程-解析处理命令行参数 2

2016-01-05 16:44 381 查看
我们这一节会先去分析下monkeyrunner是如何对参数进行处理的,我们跳转到MonkeyRunnerOptions这个类里面的processOptions这个方法:93 public static MonkeyRunnerOptions processOptions(String[] args) 94 { 95 int index = 0; 96 97 String hostname = DEFAULT_MONKEY_SERVER_ADDRESS; 98 File scriptFile = null; 99 int port = DEFAULT_MONKEY_PORT;100 String backend = "adb";101 Level logLevel = Level.SEVERE;102103 ImmutableList.Builder<File> pluginListBuilder = ImmutableList.builder();104 ImmutableList.Builder<String> argumentBuilder = ImmutableList.builder();105 while (index < args.length) {106 String argument = args[(index++)];107108 if ("-s".equals(argument)) {109 if (index == args.length) {110 printUsage("Missing Server after -s");111 return null;112 }113 hostname = args[(index++)];114 }115 else if ("-p".equals(argument))116 {117 if (index == args.length) {118 printUsage("Missing Server port after -p");119 return null;120 }121 port = Integer.parseInt(args[(index++)]);122 }123 else if ("-v".equals(argument))124 {125 if (index == args.length) {126 printUsage("Missing Log Level after -v");127 return null;128 }129130 logLevel = Level.parse(args[(index++)]);131 } else if ("-be".equals(argument))132 {133 if (index == args.length) {134 printUsage("Missing backend name after -be");135 return null;136 }137 backend = args[(index++)];138 } else if ("-plugin".equals(argument))139 {140 if (index == args.length) {141 printUsage("Missing plugin path after -plugin");142 return null;143 }144 File plugin = new File(args[(index++)]);145 if (!plugin.exists()) {146 printUsage("Plugin file doesn't exist");147 return null;148 }149150 if (!plugin.canRead()) {151 printUsage("Can't read plugin file");152 return null;153 }154155 pluginListBuilder.add(plugin);156 } else if (!"-u".equals(argument))157 {158 if ((argument.startsWith("-")) && (scriptFile == null))159 {160161162 printUsage("Unrecognized argument: " + argument + ".");163 return null;164 }165 if (scriptFile == null)166 {167168 scriptFile = new File(argument);169 if (!scriptFile.exists()) {170 printUsage("Can't open specified script file");171 return null;172 }173 if (!scriptFile.canRead()) {174 printUsage("Can't open specified script file");175 return null;176 }177 } else {178 argumentBuilder.add(argument);179 }180 }181 }182183 return new MonkeyRunnerOptions(hostname,port,scriptFile,backend,logLevel,pluginListBuilder.build(),argumentBuilder.build());184 }185 }代码8-2-2 MonkeyRunnerOptions - processOptions
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  软件测试开发