Debug
debug的入口在CtsConsole类,所以我们把第一个断点打在249行:
Console console = new CtsConsole();
按F6再按F5进入到Console.startConsole方法中。
按F5进入GlobalConfiguration.createGlobalConfiguration方法中。
该方法内主要是读取全局配置文件并设置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方法。
下一篇继续
时间: 2025-01-13 23:42:35