for (String suiteXmlPath : m_stringSuites) {
if(LOGGER.isDebugEnabled()) {
LOGGER.debug("suiteXmlPath: \"" + suiteXmlPath + "\"");
}
try {
Collection<XmlSuite> allSuites = new Parser(suiteXmlPath).parse();
for (XmlSuite s : allSuites) {
// If test names were specified, only run these test names
if (m_testNames != null) {
m_suites.add(extractTestNames(s, m_testNames));
}
else {
m_suites.add(s);
}
}
}
catch(FileNotFoundException e) {
e.printStackTrace(System.out);
}
catch(IOException e) {
e.printStackTrace(System.out);
}
catch(ParserConfigurationException e) {
e.printStackTrace(System.out);
}
catch(SAXException e) {
e.printStackTrace(System.out);
}
}
//
// jar path
//
// If suites were passed on the command line, they take precedence over the suite file
// inside that jar path
if (m_jarPath != null && m_stringSuites.size() > 0) {
StringBuilder suites = new StringBuilder();
for (String s : m_stringSuites) {
suites.append(s);
}
Utils.log("TestNG", 2, "Ignoring the XML file inside " + m_jarPath + " and using "
+ suites + " instead");
return;
}
if ((null == m_jarPath) || "".equals(m_jarPath)) return;
// We have a jar file and no XML file was specified: try to find an XML file inside the jar
File jarFile = new File(m_jarPath);
try {
URL jarfileUrl = jarFile.getCanonicalFile().toURI().toURL();
URLClassLoader jarLoader = new URLClassLoader(new URL[] { jarfileUrl });
Thread.currentThread().setContextClassLoader(jarLoader);
Utils.log("TestNG", 2, "Trying to open jar file:" + jarFile);
JarFile jf = new JarFile(jarFile);
// System.out.println(" result: " + jf);
Enumeration<JarEntry> entries = jf.entries();
List<String> classes = Lists.newArrayList();
boolean foundTestngXml = false;
while (entries.hasMoreElements()) {
JarEntry je = entries.nextElement();
if (je.getName().equals("testng.xml")) {
Parser parser = new Parser(jf.getInputStream(je));
m_suites.addAll(parser.parse());
foundTestngXml = true;
break;
}
else if (je.getName().endsWith(".class")) {
int n = je.getName().length() - ".class".length();