1package org.testng.internal;
2
3import org.testng.xml.IPostProcessor;
4import org.testng.xml.XmlSuite;
5import org.testng.xml.XmlTest;
6
7import java.util.Arrays;
8import java.util.Collection;
9
10/**
11 * Override the groups included in the XML file with groups specified on the command line.
12 *
13 * @author Cedric Beust <cedric@beust.com>
14 */
15public class OverrideProcessor implements IPostProcessor {
16
17  private String[] m_groups;
18  private String[] m_excludedGroups;
19
20  public OverrideProcessor(String[] groups, String[] excludedGroups) {
21    m_groups = groups;
22    m_excludedGroups = excludedGroups;
23  }
24
25  @Override
26  public Collection<XmlSuite> process(Collection<XmlSuite> suites) {
27    for (XmlSuite s : suites) {
28      if (m_groups != null && m_groups.length > 0) {
29        for (XmlTest t : s.getTests()) {
30          t.getIncludedGroups().clear();
31          t.getIncludedGroups().addAll(Arrays.asList(m_groups));
32        }
33      }
34
35      if (m_excludedGroups != null && m_excludedGroups.length > 0) {
36        for (XmlTest t : s.getTests()) {
37          t.getExcludedGroups().clear();
38          t.getExcludedGroups().addAll(Arrays.asList(m_excludedGroups));
39        }
40      }
41    }
42
43    return suites;
44  }
45
46}
47