1 package org.testng.xml; 2 3 import static org.testng.collections.CollectionUtils.hasElements; 4 5 import org.testng.collections.Lists; 6 import org.testng.reporters.XMLStringBuffer; 7 import org.testng.xml.dom.OnElement; 8 9 import java.util.List; 10 11 public class XmlRun { 12 13 public String toXml(String indent) { 14 XMLStringBuffer xsb = new XMLStringBuffer(indent); 15 boolean hasElements = hasElements(m_excludes) || hasElements(m_includes); 16 if (hasElements) { 17 xsb.push("run"); 18 } 19 for (String s : m_includes) { 20 xsb.addEmptyElement("include", "name", s); 21 } 22 for (String s : m_excludes) { 23 xsb.addEmptyElement("exclude", "name", s); 24 } 25 if (hasElements) { 26 xsb.pop("run"); 27 } 28 29 return xsb.toXML(); 30 } 31 32 private List<String> m_excludes = Lists.newArrayList(); 33 34 public List<String> getExcludes() { 35 return m_excludes; 36 } 37 38 @OnElement(tag = "exclude", attributes = "name") 39 public void onExclude(String name) { 40 m_excludes.add(name); 41 } 42 43 private List<String> m_includes = Lists.newArrayList(); 44 45 public List<String> getIncludes() { 46 return m_includes; 47 } 48 49 @OnElement(tag = "include", attributes = "name") 50 public void onInclude(String name) { 51 m_includes.add(name); 52 } 53 } 54