首页 > 其他 > 详细

Cts框架解析(4)

时间:2014-10-19 18:39:18      阅读:484      评论:0      收藏:0      [点我收藏+]

Debug


bubuko.com,布布扣


debug的入口在CtsConsole类,所以我们把第一个断点打在249行:


Console console = new CtsConsole();


按F6再按F5进入到Console.startConsole方法中。


bubuko.com,布布扣


按F5进入GlobalConfiguration.createGlobalConfiguration方法中。


bubuko.com,布布扣


该方法内主要是读取全局配置文件并设置IGlobalConfiguration接口对象sInstance。主要方法为95行读取文件的getGlobalConfigPath():


private static String getGlobalConfigPath() throws ConfigurationException {
        String path = System.getenv(GLOBAL_CONFIG_VARIABLE);
        if (path != null) {
            // don't actually check for accessibility here, since the variable
            // might be specifying
            // a java resource rather than a filename. Even so, this can help
            // the user figure out
            // which global config (if any) was picked up by TF.
            System.err
                    .format("Attempting to use global config \"%s\" from variable $%s.\n",
                            path, GLOBAL_CONFIG_VARIABLE);
            return path;
        }

        File file = new File(GLOBAL_CONFIG_FILENAME);
        if (file.exists()) {
            path = file.getPath();
            System.err.format(
                    "Attempting to use auto detected global config \"%s\".\n",
                    path);
            System.err.flush();
            return path;
        }

        // FIXME: search in tradefed.sh launch dir (or classpath?)

        return null;
    }

首先判断是否设置了全局配置文件的系统变量,如果没有设置,那直接在当前文件目录下找tf_global_config.xml文件。很显然,本程序这些都没有,所以该方法返回的结果应该是null。回到了createGlobalConfiguration(String[] args)方法中:


if (globalConfigPath != null) {
				// Found a global config file; attempt to parse and use it
				sInstance = configFactory.createGlobalConfigurationFromArgs(
						ArrayUtil.buildArray(new String[] { globalConfigPath },
								args), nonGlobalArgs);
				System.err.format("Success!  Using global config \"%s\"\n",
						globalConfigPath);
			} else {
				// Use default global config
				sInstance = new GlobalConfiguration();
				nonGlobalArgs = Arrays.asList(args);
			}
			return nonGlobalArgs;

因为返回的路径为null,所以直接跳转到else语句块中,new一个新对象,没有设置任何属性。最后将命令行参数封装在list中返回,然后console设置参数,最终启动线程来执行任务。所以第二个断点要打在Console的run方法里,然后按F8进入run方法。


bubuko.com,布布扣


下一篇继续





Cts框架解析(4)

原文:http://blog.csdn.net/itfootball/article/details/40210811

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!