[testng] 72/160: Use service loader to find suite parsers

Eugene Zhukov eugene-guest at moszumanska.debian.org
Tue Aug 18 10:22:23 UTC 2015


This is an automated email from the git hooks/post-receive script.

eugene-guest pushed a commit to annotated tag testng-6.9.5
in repository testng.

commit 74e60601d3cb3197e7b7063227ec8414c236f793
Author: Julien Herr <julien.herr at alcatel-lucent.com>
Date:   Fri Jun 5 00:48:52 2015 +0200

    Use service loader to find suite parsers
---
 src/main/java/org/testng/xml/Parser.java                       | 10 ++++++++--
 .../resources/META-INF/services/org.testng.xml.SuiteParser     |  1 +
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/testng/xml/Parser.java b/src/main/java/org/testng/xml/Parser.java
index 908bdd8..4408c8b 100755
--- a/src/main/java/org/testng/xml/Parser.java
+++ b/src/main/java/org/testng/xml/Parser.java
@@ -2,7 +2,6 @@ package org.testng.xml;
 
 import org.testng.collections.Lists;
 import org.testng.collections.Maps;
-import org.testng.internal.YamlParser;
 import org.xml.sax.SAXException;
 
 import javax.xml.parsers.ParserConfigurationException;
@@ -15,6 +14,7 @@ import java.io.InputStream;
 import java.util.Collection;
 import java.util.List;
 import java.util.Map;
+import java.util.ServiceLoader;
 
 /**
  * <code>Parser</code> is a parser for a TestNG XML test suite file.
@@ -34,7 +34,13 @@ public class Parser {
   public static final String DEFAULT_FILENAME = "testng.xml";
 
   private static final SuiteParser DEFAULT_FILE_PARSER = new SuiteXmlParser();
-  private static final List<SuiteParser> PARSERS = Lists.newArrayList(DEFAULT_FILE_PARSER, new YamlParser());
+  private static final List<SuiteParser> PARSERS = Lists.newArrayList(DEFAULT_FILE_PARSER);
+  static {
+    ServiceLoader<SuiteParser> suiteParserLoader = ServiceLoader.load(SuiteParser.class);
+    for (SuiteParser parser : suiteParserLoader) {
+      PARSERS.add(parser);
+    }
+  }
 
   /** The file name of the xml suite being parsed. This may be null if the Parser
    * has not been initialized with a file name. TODO CQ This member is never used. */
diff --git a/src/main/resources/META-INF/services/org.testng.xml.SuiteParser b/src/main/resources/META-INF/services/org.testng.xml.SuiteParser
new file mode 100644
index 0000000..cc0fca3
--- /dev/null
+++ b/src/main/resources/META-INF/services/org.testng.xml.SuiteParser
@@ -0,0 +1 @@
+org.testng.internal.YamlParser
\ No newline at end of file

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/testng.git



More information about the pkg-java-commits mailing list