1 package org.testng.xml; 2 3 import java.util.Map; 4 5 import org.testng.collections.Maps; 6 import org.testng.reporters.XMLStringBuffer; 7 import org.testng.xml.dom.OnElement; 8 9 import static org.testng.collections.CollectionUtils.hasElements; 10 11 public class XmlDependencies { 12 13 private Map<String, String> m_xmlDependencyGroups = Maps.newHashMap(); 14 15 @OnElement(tag = "group", attributes = { "name", "depends-on" }) onGroup(String name, String dependsOn)16 public void onGroup(String name, String dependsOn) { 17 m_xmlDependencyGroups.put(name, dependsOn); 18 } 19 getDependencies()20 public Map<String, String> getDependencies() { 21 return m_xmlDependencyGroups; 22 } 23 toXml(String indent)24 public String toXml(String indent) { 25 XMLStringBuffer xsb = new XMLStringBuffer(indent); 26 boolean hasElements = hasElements(m_xmlDependencyGroups); 27 if (hasElements) { 28 xsb.push("dependencies"); 29 } 30 for (Map.Entry<String, String> entry : m_xmlDependencyGroups.entrySet()) { 31 xsb.addEmptyElement("include", "name", entry.getKey(), "depends-on", entry.getValue()); 32 } 33 if (hasElements) { 34 xsb.pop("dependencies"); 35 } 36 37 return xsb.toXML(); 38 } 39 40 } 41