001: package org.testng.xml;
002:
003: import java.io.IOException;
004: import java.util.ArrayList;
005: import java.util.List;
006: import java.util.Properties;
007:
008: import org.testng.internal.PackageUtils;
009: import org.testng.internal.Utils;
010: import org.testng.reporters.XMLStringBuffer;
011:
012: /**
013: * This class describes the tag <package> in testng.xml.
014: *
015: * @author Cedric
016: * @author <a href='mailto:the_mindstorm[at]evolva[dot]ro'>Alexandru Popescu</a>
017: */
018: public class XmlPackage {
019: private String m_name;
020: private List<String> m_include = new ArrayList<String>();
021: private List<String> m_exclude = new ArrayList<String>();
022: private List<XmlClass> m_xmlClasses = null;
023:
024: /**
025: * @return the exclude
026: */
027: public List<String> getExclude() {
028: return m_exclude;
029: }
030:
031: /**
032: * @param exclude the exclude to set
033: */
034: public void setExclude(List<String> exclude) {
035: m_exclude = exclude;
036: }
037:
038: /**
039: * @return the include
040: */
041: public List<String> getInclude() {
042: return m_include;
043: }
044:
045: /**
046: * @param include the include to set
047: */
048: public void setInclude(List<String> include) {
049: m_include = include;
050: }
051:
052: /**
053: * @return the name
054: */
055: public String getName() {
056: return m_name;
057: }
058:
059: /**
060: * @param name the name to set
061: */
062: public void setName(String name) {
063: m_name = name;
064: }
065:
066: public List<XmlClass> getXmlClasses() {
067: if (null == m_xmlClasses) {
068: m_xmlClasses = initializeXmlClasses();
069: }
070:
071: return m_xmlClasses;
072: }
073:
074: private List<XmlClass> initializeXmlClasses() {
075: List<XmlClass> result = new ArrayList<XmlClass>();
076: try {
077: String[] classes = PackageUtils.findClassesInPackage(
078: m_name, m_include, m_exclude);
079:
080: for (String className : classes) {
081: result.add(new XmlClass(className));
082: }
083: } catch (IOException ioex) {
084: Utils.log("XmlPackage", 1, ioex.getMessage());
085: }
086:
087: return result;
088: }
089:
090: public Object toXml(String indent) {
091: XMLStringBuffer xsb = new XMLStringBuffer(indent);
092: Properties p = new Properties();
093: p.setProperty("name", getName());
094:
095: xsb.push("package", p);
096:
097: for (String m : getInclude()) {
098: Properties includeProp = new Properties();
099: includeProp.setProperty("name", m);
100: xsb.addEmptyElement("include", includeProp);
101: }
102: for (String m : getExclude()) {
103: Properties excludeProp = new Properties();
104: excludeProp.setProperty("name", m);
105: xsb.addEmptyElement("exclude", excludeProp);
106: }
107:
108: xsb.pop("package");
109:
110: return xsb.toXML();
111: }
112: }
|