Remove deprecated Yin/YangStatementSourceImpl
[yangtools.git] / yang / yang-test-util / src / main / java / org / opendaylight / yangtools / yang / test / util / YangParserTestUtils.java
index e5343e412b916ddfa6863289e45c12b09190d0cc..72b832e89ef76b15b80af5cdc9803e53c4537581 100644 (file)
@@ -9,11 +9,9 @@
 package org.opendaylight.yangtools.yang.test.util;
 
 import com.google.common.annotations.Beta;
-import com.google.common.base.Preconditions;
 import java.io.File;
 import java.io.FileFilter;
-import java.io.FileNotFoundException;
-import java.io.InputStream;
+import java.io.IOException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.ArrayList;
@@ -21,16 +19,19 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
 import java.util.Set;
+import java.util.stream.Collectors;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.YangConstants;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
 import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode;
+import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.parser.rfc6020.repo.YangStatementStreamSource;
 import org.opendaylight.yangtools.yang.parser.rfc6020.repo.YinStatementStreamSource;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
+import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
-import org.opendaylight.yangtools.yang.parser.util.NamedFileInputStream;
 
 /**
  * Utility class which provides convenience methods for producing effective schema context based on the supplied
@@ -52,166 +53,73 @@ public final class YangParserTestUtils {
      * Creates a new effective schema context containing the specified YANG source. Statement parser mode is set to
      * default mode and all YANG features are supported.
      *
-     * @param yangSourcePath relative path to the YANG file to be parsed
+     * @param resource relative path to the YANG file to be parsed
      *
      * @return effective schema context
-     *
-     * @throws ReactorException if there is an error in the parsed YANG source
-     * @throws FileNotFoundException if the specified file does not exist
-     * @throws URISyntaxException if the specified file does not exist
      */
-    public static SchemaContext parseYangSource(final String yangSourcePath) throws ReactorException,
-            FileNotFoundException, URISyntaxException {
-        return parseYangSource(yangSourcePath, StatementParserMode.DEFAULT_MODE);
+    public static SchemaContext parseYangResource(final String resource) {
+        return parseYangResource(resource, StatementParserMode.DEFAULT_MODE);
     }
 
     /**
-     * Creates a new effective schema context containing the specified YANG source. Statement parser mode is set to
-     * default mode.
-     *
-     * @param yangSourcePath relative path to the YANG file to be parsed
-     * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
-     *                          model are resolved
+     * Creates a new effective schema context containing the specified YANG source. All YANG features are supported.
      *
+     * @param resource relative path to the YANG file to be parsed
+     * @param parserMode mode of statement parser
      * @return effective schema context
-     *
-     * @throws ReactorException if there is an error in the parsed YANG source
-     * @throws FileNotFoundException if the specified file does not exist
-     * @throws URISyntaxException if the specified file does not exist
      */
-    public static SchemaContext parseYangSource(final String yangSourcePath, final Set<QName> supportedFeatures)
-            throws ReactorException, FileNotFoundException, URISyntaxException {
-        return parseYangSource(yangSourcePath, supportedFeatures, StatementParserMode.DEFAULT_MODE);
+    public static SchemaContext parseYangResource(final String resource, final StatementParserMode parserMode) {
+        return parseYangResource(resource, parserMode, null);
     }
 
     /**
-     * Creates a new effective schema context containing the specified YANG source. All YANG features are supported.
-     *
-     * @param yangSourcePath relative path to the YANG file to be parsed
-     * @param statementParserMode mode of statement parser
+     * Creates a new effective schema context containing the specified YANG source. Statement parser mode is set to
+     * default mode.
      *
+     * @param resource relative path to the YANG file to be parsed
+     * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
+     *                          model are resolved
      * @return effective schema context
-     *
-     * @throws ReactorException if there is an error in the parsed YANG source
-     * @throws FileNotFoundException if the specified file does not exist
-     * @throws URISyntaxException if the specified file does not exist
      */
-    public static SchemaContext parseYangSource(final String yangSourcePath,
-            final StatementParserMode statementParserMode) throws ReactorException, FileNotFoundException,
-            URISyntaxException {
-        return parseYangSource(yangSourcePath, null, statementParserMode);
+    public static SchemaContext parseYangResource(final String resource, final Set<QName> supportedFeatures) {
+        return parseYangResource(resource, StatementParserMode.DEFAULT_MODE, supportedFeatures);
     }
 
     /**
      * Creates a new effective schema context containing the specified YANG source.
      *
-     * @param yangSourcePath relative path to the YANG file to be parsed
+     * @param resource relative path to the YANG file to be parsed
      * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
      *                          model are resolved
-     * @param statementParserMode mode of statement parser
-     *
+     * @param parserMode mode of statement parser
      * @return effective schema context
-     *
-     * @throws ReactorException if there is an error in the parsed YANG source
-     * @throws FileNotFoundException if the specified file does not exist
-     * @throws URISyntaxException if the specified file does not exist
      */
-    public static SchemaContext parseYangSource(final String yangSourcePath, final Set<QName> supportedFeatures,
-            final StatementParserMode statementParserMode) throws ReactorException, FileNotFoundException,
-            URISyntaxException {
-        final URI sourcePath = YangParserTestUtils.class.getResource(yangSourcePath).toURI();
-        final File sourceFile = new File(sourcePath);
-        return parseYangSources(supportedFeatures, statementParserMode, sourceFile);
+    public static SchemaContext parseYangResource(final String resource, final StatementParserMode parserMode,
+            final Set<QName> supportedFeatures) {
+        final YangTextSchemaSource source = YangTextSchemaSource.forResource(YangParserTestUtils.class, resource);
+        return parseYangSources(parserMode, supportedFeatures, source);
     }
 
     /**
      * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
      * default mode and all YANG features are supported.
      *
-     * @param sources YANG sources to be parsed
-     *
-     * @return effective schema context
-     *
-     * @throws ReactorException if there is an error in one of the parsed YANG sources
-     *
-     * @deprecated Migration method only, do not use.
-     */
-    @Deprecated
-    public static SchemaContext parseYangSources(final YangStatementSourceImpl... sources) throws ReactorException {
-        return parseYangSources(StatementParserMode.DEFAULT_MODE, sources);
-    }
-
-    /**
-     * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
-     * default mode.
-     *
-     * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
-     *                          models are resolved
-     * @param sources YANG sources to be parsed
-     *
-     * @return effective schema context
-     * @throws ReactorException if there is an error in one of the parsed YANG sources
-     *
-     * @deprecated Migration method only, do not use.
-     */
-    @Deprecated
-    public static SchemaContext parseYangSources(final Set<QName> supportedFeatures,
-            final YangStatementSourceImpl... sources) throws ReactorException {
-        return parseYangSources(supportedFeatures, StatementParserMode.DEFAULT_MODE, sources);
-    }
-
-    /**
-     * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
-     *
-     * @param statementParserMode mode of statement parser
-     * @param sources YANG sources to be parsed
-     *
-     * @return effective schema context
-     * @throws ReactorException if there is an error in one of the parsed YANG sources
-     *
-     * @deprecated Migration method only, do not use.
-     */
-    @Deprecated
-    public static SchemaContext parseYangSources(final StatementParserMode statementParserMode,
-            final YangStatementSourceImpl... sources) throws ReactorException {
-        return parseYangSources(null, statementParserMode, sources);
-    }
-
-    /**
-     * Creates a new effective schema context containing the specified YANG sources.
-     *
-     * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
-     *                          models are resolved
-     * @param statementParserMode mode of statement parser
-     * @param sources YANG sources to be parsed
-     *
+     * @param files YANG files to be parsed
      * @return effective schema context
-     *
-     * @throws ReactorException if there is an error in one of the parsed YANG sources
      */
-    public static SchemaContext parseYangSources(final Set<QName> supportedFeatures,
-            final StatementParserMode statementParserMode, final YangStatementSourceImpl... sources)
-                    throws ReactorException {
-        final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(
-                statementParserMode, supportedFeatures);
-        reactor.addSources(sources);
-
-        return reactor.buildEffective();
+    public static SchemaContext parseYangFiles(final File... files) {
+        return parseYangFiles(Arrays.asList(files));
     }
 
     /**
      * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
      * default mode and all YANG features are supported.
      *
-     * @param files YANG files to be parsed
-     *
+     * @param files collection of YANG files to be parsed
      * @return effective schema context
-     *
-     * @throws ReactorException if there is an error in one of the parsed YANG sources
-     * @throws FileNotFoundException if one of the specified files does not exist
      */
-    public static SchemaContext parseYangSources(final File... files) throws ReactorException, FileNotFoundException {
-        return parseYangSources(StatementParserMode.DEFAULT_MODE, files);
+    public static SchemaContext parseYangFiles(final Collection<File> files) {
+        return parseYangFiles(StatementParserMode.DEFAULT_MODE, files);
     }
 
     /**
@@ -221,105 +129,36 @@ public final class YangParserTestUtils {
      * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
      *                          models are resolved
      * @param files YANG files to be parsed
-     *
      * @return effective schema context
-     *
-     * @throws ReactorException if there is an error in one of the parsed YANG sources
-     * @throws FileNotFoundException if one of the specified files does not exist
      */
-    public static SchemaContext parseYangSources(final Set<QName> supportedFeatures, final File... files)
-            throws ReactorException, FileNotFoundException {
-        return parseYangSources(supportedFeatures, StatementParserMode.DEFAULT_MODE, files);
+    public static SchemaContext parseYangFiles(final Set<QName> supportedFeatures, final File... files) {
+        return parseYangFiles(supportedFeatures, Arrays.asList(files));
     }
 
-    /**
-     * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
-     *
-     * @param statementParserMode mode of statement parser
-     * @param files YANG files to be parsed
-     *
-     * @return effective schema context
-     *
-     * @throws ReactorException if there is an error in one of the parsed YANG sources
-     * @throws FileNotFoundException if one of the specified files does not exist
-     */
-    public static SchemaContext parseYangSources(final StatementParserMode statementParserMode, final File... files)
-            throws ReactorException, FileNotFoundException {
-        return parseYangSources(null, statementParserMode, files);
+    public static SchemaContext parseYangFiles(final Set<QName> supportedFeatures, final Collection<File> files) {
+        return parseYangFiles(supportedFeatures, StatementParserMode.DEFAULT_MODE, files);
     }
 
     /**
-     * Creates a new effective schema context containing the specified YANG sources.
+     * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
      *
-     * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
-     *                          models are resolved
-     * @param statementParserMode mode of statement parser
+     * @param parserMode mode of statement parser
      * @param files YANG files to be parsed
-     *
      * @return effective schema context
-     *
-     * @throws ReactorException if there is an error in one of the parsed YANG sources
-     * @throws FileNotFoundException if one of the specified files does not exist
      */
-    public static SchemaContext parseYangSources(final Set<QName> supportedFeatures,
-            final StatementParserMode statementParserMode, final File... files) throws ReactorException,
-            FileNotFoundException {
-        final YangStatementSourceImpl[] sources = new YangStatementSourceImpl[files.length];
-        for (int i = 0; i < files.length; i++) {
-            sources[i] = new YangStatementSourceImpl(new NamedFileInputStream(files[i], files[i].getPath()));
-        }
-
-        return parseYangSources(supportedFeatures, statementParserMode, sources);
-    }
-
-    /**
-     * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
-     * default mode and all YANG features are supported.
-     *
-     * @param files collection of YANG files to be parsed
-     *
-     * @return effective schema context
-     *
-     * @throws ReactorException if there is an error in one of the parsed YANG sources
-     * @throws FileNotFoundException if one of the specified files does not exist
-     */
-    public static SchemaContext parseYangSources(final Collection<File> files) throws ReactorException,
-            FileNotFoundException {
-        return parseYangSources(files, StatementParserMode.DEFAULT_MODE);
-    }
-
-    /**
-     * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
-     * default mode.
-     *
-     * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
-     *                          models are resolved
-     * @param files collection of YANG files to be parsed
-     *
-     * @return effective schema context
-     *
-     * @throws ReactorException if there is an error in one of the parsed YANG sources
-     * @throws FileNotFoundException if one of the specified files does not exist
-     */
-    public static SchemaContext parseYangSources(final Collection<File> files, final Set<QName> supportedFeatures)
-            throws ReactorException, FileNotFoundException {
-        return parseYangSources(files, supportedFeatures, StatementParserMode.DEFAULT_MODE);
+    public static SchemaContext parseYangFiles(final StatementParserMode parserMode, final File... files) {
+        return parseYangFiles(parserMode, Arrays.asList(files));
     }
 
     /**
      * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
      *
-     * @param statementParserMode mode of statement parser
+     * @param parserMode mode of statement parser
      * @param files collection of YANG files to be parsed
-     *
      * @return effective schema context
-     *
-     * @throws ReactorException if there is an error in one of the parsed YANG sources
-     * @throws FileNotFoundException if one of the specified files does not exist
      */
-    public static SchemaContext parseYangSources(final Collection<File> files,
-            final StatementParserMode statementParserMode) throws ReactorException, FileNotFoundException {
-        return parseYangSources(files, null, statementParserMode);
+    public static SchemaContext parseYangFiles(final StatementParserMode parserMode, final Collection<File> files) {
+        return parseYangFiles(null, parserMode, files);
     }
 
     /**
@@ -327,405 +166,179 @@ public final class YangParserTestUtils {
      *
      * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
      *                          models are resolved
-     * @param statementParserMode mode of statement parser
-     * @param files collection of YANG files to be parsed
-     *
-     * @return effective schema context
-     *
-     * @throws ReactorException if there is an error in one of the parsed YANG sources
-     * @throws FileNotFoundException if one of the specified files does not exist
-     */
-    public static SchemaContext parseYangSources(final Collection<File> files, final Set<QName> supportedFeatures,
-            final StatementParserMode statementParserMode) throws ReactorException, FileNotFoundException {
-        return parseYangSources(supportedFeatures, statementParserMode, files.toArray(new File[files.size()]));
-    }
-
-    /**
-     * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
-     * default mode and all YANG features are supported.
-     *
-     * @param yangSourcesDirectoryPath relative path to the directory with YANG files to be parsed
-     *
-     * @return effective schema context
-     *
-     * @throws ReactorException if there is an error in one of the parsed YANG sources
-     * @throws FileNotFoundException if the specified directory does not exist
-     * @throws URISyntaxException if the specified directory does not exist
-     */
-    public static SchemaContext parseYangSources(final String yangSourcesDirectoryPath) throws ReactorException,
-            FileNotFoundException, URISyntaxException {
-        return parseYangSources(yangSourcesDirectoryPath, StatementParserMode.DEFAULT_MODE);
-    }
-
-    /**
-     * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
-     * default mode.
-     *
-     * @param yangSourcesDirectoryPath relative path to the directory with YANG files to be parsed
-     * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
-     *                          models are resolved
-     *
-     * @return effective schema context
-     *
-     * @throws ReactorException if there is an error in one of the parsed YANG sources
-     * @throws FileNotFoundException if the specified directory does not exist
-     * @throws URISyntaxException if the specified directory does not exist
-     */
-    public static SchemaContext parseYangSources(final String yangSourcesDirectoryPath,
-            final Set<QName> supportedFeatures) throws ReactorException, FileNotFoundException,
-            URISyntaxException {
-        return parseYangSources(yangSourcesDirectoryPath, supportedFeatures, StatementParserMode.DEFAULT_MODE);
-    }
-
-    /**
-     * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
-     *
-     * @param yangSourcesDirectoryPath relative path to the directory with YANG files to be parsed
-     * @param statementParserMode mode of statement parser
-     *
+     * @param parserMode mode of statement parser
+     * @param files YANG files to be parsed
      * @return effective schema context
-     *
-     * @throws ReactorException if there is an error in one of the parsed YANG sources
-     * @throws FileNotFoundException if the specified directory does not exist
-     * @throws URISyntaxException if the specified directory does not exist
      */
-    public static SchemaContext parseYangSources(final String yangSourcesDirectoryPath,
-            final StatementParserMode statementParserMode) throws ReactorException, FileNotFoundException,
-            URISyntaxException {
-        return parseYangSources(yangSourcesDirectoryPath, null, statementParserMode);
+    public static SchemaContext parseYangFiles(final Set<QName> supportedFeatures,
+            final StatementParserMode parserMode, final File... files) {
+        return parseYangFiles(supportedFeatures, parserMode, Arrays.asList(files));
     }
 
     /**
      * Creates a new effective schema context containing the specified YANG sources.
      *
-     * @param yangSourcesDirectoryPath relative path to the directory with YANG files to be parsed
      * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
      *                          models are resolved
-     * @param statementParserMode mode of statement parser
-     *
+     * @param parserMode mode of statement parser
+     * @param files YANG files to be parsed
      * @return effective schema context
-     *
-     * @throws ReactorException if there is an error in one of the parsed YANG sources
-     * @throws FileNotFoundException if the specified directory does not exist
-     * @throws URISyntaxException if the specified directory does not exist
      */
-    public static SchemaContext parseYangSources(final String yangSourcesDirectoryPath,
-            final Set<QName> supportedFeatures, final StatementParserMode statementParserMode)
-                    throws ReactorException, FileNotFoundException, URISyntaxException {
-        final URI directoryPath = YangParserTestUtils.class.getResource(yangSourcesDirectoryPath).toURI();
-        final File dir = new File(directoryPath);
-
-        return parseYangSources(supportedFeatures, statementParserMode, dir.listFiles(YANG_FILE_FILTER));
+    public static SchemaContext parseYangFiles(final Set<QName> supportedFeatures,
+            final StatementParserMode parserMode, final Collection<File> files) {
+        return parseYangSources(supportedFeatures, parserMode,
+            files.stream().map(YangTextSchemaSource::forFile).collect(Collectors.toList()));
     }
 
     /**
      * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
      * default mode and all YANG features are supported.
      *
-     * @param yangDirs relative paths to the directories containing YANG files to be parsed
-     * @param yangFiles relative paths to the YANG files to be parsed
-     *
+     * @param resourcePath relative path to the directory with YANG files to be parsed
      * @return effective schema context
-     *
-     * @throws ReactorException if there is an error in one of the parsed YANG sources
-     * @throws FileNotFoundException if one of the specified directories or files does not exist
-     * @throws URISyntaxException if one of the specified directories or files does not exist
      */
-    public static SchemaContext parseYangSources(final List<String> yangDirs, final List<String> yangFiles)
-            throws FileNotFoundException, ReactorException, URISyntaxException {
-        return parseYangSources(yangDirs, yangFiles, StatementParserMode.DEFAULT_MODE);
-    }
-
-    /**
-     * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
-     * default mode.
-     *
-     * @param yangDirs relative paths to the directories containing YANG files to be parsed
-     * @param yangFiles relative paths to the YANG files to be parsed
-     * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
-     *                          models are resolved
-     *
-     * @return effective schema context
-     *
-     * @throws ReactorException if there is an error in one of the parsed YANG sources
-     * @throws FileNotFoundException if one of the specified directories or files does not exist
-     * @throws URISyntaxException if one of the specified directories or files does not exist
-     */
-    public static SchemaContext parseYangSources(final List<String> yangDirs, final List<String> yangFiles,
-            final Set<QName> supportedFeatures) throws FileNotFoundException, ReactorException,
-            URISyntaxException {
-        return parseYangSources(yangDirs, yangFiles, supportedFeatures, StatementParserMode.DEFAULT_MODE);
+    public static SchemaContext parseYangResourceDirectory(final String resourcePath) {
+        return parseYangResourceDirectory(resourcePath, StatementParserMode.DEFAULT_MODE);
     }
 
     /**
      * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
      *
-     * @param yangDirs relative paths to the directories containing YANG files to be parsed
-     * @param yangFiles relative paths to the YANG files to be parsed
-     * @param statementParserMode mode of statement parser
-     *
+     * @param resourcePath relative path to the directory with YANG files to be parsed
+     * @param parserMode mode of statement parser
      * @return effective schema context
-     *
-     * @throws ReactorException if there is an error in one of the parsed YANG sources
-     * @throws FileNotFoundException if one of the specified directories or files does not exist
-     * @throws URISyntaxException if one of the specified directories or files does not exist
      */
-    public static SchemaContext parseYangSources(final List<String> yangDirs, final List<String> yangFiles,
-            final StatementParserMode statementParserMode) throws FileNotFoundException, ReactorException,
-            URISyntaxException {
-        return parseYangSources(yangDirs, yangFiles, null, statementParserMode);
-    }
-
-    /**
-     * Creates a new effective schema context containing the specified YANG sources.
-     *
-     * @param yangDirs relative paths to the directories containing YANG files to be parsed
-     * @param yangFiles relative paths to the YANG files to be parsed
-     * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
-     *                          models are resolved
-     * @param statementParserMode mode of statement parser
-     *
-     * @return effective schema context
-     *
-     * @throws ReactorException if there is an error in one of the parsed YANG sources
-     * @throws FileNotFoundException if one of the specified directories or files does not exist
-     * @throws URISyntaxException if one of the specified directories or files does not exist
-     */
-    public static SchemaContext parseYangSources(final List<String> yangDirs, final List<String> yangFiles,
-            final Set<QName> supportedFeatures, final StatementParserMode statementParserMode)
-            throws FileNotFoundException, ReactorException, URISyntaxException {
-        final List<File> allYangFiles = new ArrayList<>();
-        for (final String yangDir : yangDirs) {
-            allYangFiles.addAll(getYangFiles(yangDir));
-        }
-
-        for (final String yangFile : yangFiles) {
-            final URI filePath = YangParserTestUtils.class.getResource(yangFile).toURI();
-            allYangFiles.add(new File(filePath));
-        }
-
-        return parseYangSources(allYangFiles, supportedFeatures, statementParserMode);
-    }
-
-    /**
-     * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
-     * default mode and all YANG features are supported.
-     *
-     * @param filePaths relative paths to the YANG files to be parsed
-     *
-     * @return effective schema context
-     *
-     * @throws ReactorException if there is an error in one of the parsed YANG sources
-     */
-    public static SchemaContext parseYangSources(final List<String> filePaths) throws ReactorException {
-        return parseYangSources(filePaths, StatementParserMode.DEFAULT_MODE);
+    public static SchemaContext parseYangResourceDirectory(final String resourcePath,
+            final StatementParserMode parserMode) {
+        return parseYangResourceDirectory(resourcePath, null, parserMode);
     }
 
     /**
      * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
      * default mode.
      *
+     * @param resourcePath relative path to the directory with YANG files to be parsed
      * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
      *                          models are resolved
-     * @param filePaths relative paths to the YANG files to be parsed
-     *
-     * @return effective schema context
-     *
-     * @throws ReactorException if there is an error in one of the parsed YANG sources
-     */
-    public static SchemaContext parseYangSources(final List<String> filePaths, final Set<QName> supportedFeatures)
-            throws ReactorException {
-        return parseYangSources(filePaths, supportedFeatures, StatementParserMode.DEFAULT_MODE);
-    }
-
-    /**
-     * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
-     *
-     * @param statementParserMode mode of statement parser
-     * @param filePaths relative paths to the YANG files to be parsed
-     *
      * @return effective schema context
-     *
-     * @throws ReactorException if there is an error in one of the parsed YANG sources
      */
-    public static SchemaContext parseYangSources(final List<String> filePaths,
-            final StatementParserMode statementParserMode) throws ReactorException {
-        return parseYangSources(filePaths, (Set<QName>) null, statementParserMode);
+    public static SchemaContext parseYangResourceDirectory(final String resourcePath,
+            final Set<QName> supportedFeatures) {
+        return parseYangResourceDirectory(resourcePath, supportedFeatures, StatementParserMode.DEFAULT_MODE);
     }
 
     /**
      * Creates a new effective schema context containing the specified YANG sources.
      *
+     * @param resourcePath relative path to the directory with YANG files to be parsed
      * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
      *                          models are resolved
-     * @param statementParserMode mode of statement parser
-     * @param filePaths relative paths to the YANG files to be parsed
-     *
+     * @param parserMode mode of statement parser
      * @return effective schema context
-     *
-     * @throws ReactorException if there is an error in one of the parsed YANG sources
      */
-    public static SchemaContext parseYangSources(final List<String> filePaths,
-            final Set<QName> supportedFeatures, final StatementParserMode statementParserMode)
-                    throws ReactorException {
-        final YangStatementSourceImpl[] sources = new YangStatementSourceImpl[filePaths.size()];
-
-        for (int i = 0; i < filePaths.size(); i++) {
-            sources[i] = new YangStatementSourceImpl(YangParserTestUtils.class.getResourceAsStream(filePaths.get(i)));
+    public static SchemaContext parseYangResourceDirectory(final String resourcePath,
+            final Set<QName> supportedFeatures, final StatementParserMode parserMode) {
+        final URI directoryPath;
+        try {
+            directoryPath = YangParserTestUtils.class.getResource(resourcePath).toURI();
+        } catch (URISyntaxException e) {
+            throw new IllegalArgumentException("Failed to open resource " + resourcePath, e);
         }
-
-        return parseYangSources(supportedFeatures, statementParserMode, sources);
+        return parseYangFiles(supportedFeatures, parserMode, new File(directoryPath).listFiles(YANG_FILE_FILTER));
     }
 
     /**
      * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
      * default mode and all YANG features are supported.
      *
-     * @param streams input streams containing YANG sources to be parsed
-     *
+     * @param clazz Resource lookup base
+     * @param resources Resource names to be looked up
      * @return effective schema context
-     *
-     * @throws ReactorException if there is an error in one of the parsed YANG sources
      */
-    public static SchemaContext parseYangStreams(final List<InputStream> streams) throws ReactorException {
-        return parseYangStreams(streams, StatementParserMode.DEFAULT_MODE);
+    public static SchemaContext parseYangResources(final Class<?> clazz, final String... resources) {
+        final List<YangTextSchemaSource> sources = new ArrayList<>(resources.length);
+        for (final String r : resources) {
+            sources.add(YangTextSchemaSource.forResource(clazz, r));
+        }
+        return parseYangSources(null, StatementParserMode.DEFAULT_MODE, sources);
     }
 
     /**
      * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
      * default mode.
      *
-     * @param streams input streams containing YANG sources to be parsed
+     * @param yangDirs relative paths to the directories containing YANG files to be parsed
+     * @param yangFiles relative paths to the YANG files to be parsed
      * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
      *                          models are resolved
-     *
      * @return effective schema context
-     *
-     * @throws ReactorException if there is an error in one of the parsed YANG sources
      */
-    public static SchemaContext parseYangStreams(final List<InputStream> streams, final Set<QName> supportedFeatures)
-            throws ReactorException {
-        return parseYangStreams(streams, supportedFeatures, StatementParserMode.DEFAULT_MODE);
+    public static SchemaContext parseYangResources(final List<String> yangDirs, final List<String> yangFiles,
+            final Set<QName> supportedFeatures) {
+        return parseYangResources(yangDirs, yangFiles, supportedFeatures, StatementParserMode.DEFAULT_MODE);
     }
 
     /**
      * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
      *
-     * @param streams input streams containing YANG sources to be parsed
+     * @param yangResourceDirs relative paths to the directories containing YANG files to be parsed
+     * @param yangResources relative paths to the YANG files to be parsed
      * @param statementParserMode mode of statement parser
-     *
      * @return effective schema context
-     *
-     * @throws ReactorException if there is an error in one of the parsed YANG sources
      */
-    public static SchemaContext parseYangStreams(final List<InputStream> streams,
-            final StatementParserMode statementParserMode) throws ReactorException {
-        return parseYangStreams(streams, null, statementParserMode);
+    public static SchemaContext parseYangResources(final List<String> yangResourceDirs,
+            final List<String> yangResources, final StatementParserMode statementParserMode) {
+        return parseYangResources(yangResourceDirs, yangResources, null, statementParserMode);
     }
 
     /**
      * Creates a new effective schema context containing the specified YANG sources.
      *
+     * @param yangResourceDirs relative paths to the directories containing YANG files to be parsed
+     * @param yangResources relative paths to the YANG files to be parsed
      * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
      *                          models are resolved
      * @param statementParserMode mode of statement parser
-     * @param streams input streams containing YANG sources to be parsed
-     *
-     * @return effective schema context
-     *
-     * @throws ReactorException if there is an error in one of the parsed YANG sources
-     */
-    public static SchemaContext parseYangStreams(final List<InputStream> streams, final Set<QName> supportedFeatures,
-            final StatementParserMode statementParserMode) throws ReactorException {
-        final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(
-                statementParserMode, supportedFeatures);
-        return reactor.buildEffective(streams);
-    }
-
-    /**
-     * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
-     * default mode and all YANG features are supported.
-     *
-     * @param streams input streams containing YANG sources to be parsed
-     *
      * @return effective schema context
-     *
-     * @throws ReactorException if there is an error in one of the parsed YANG sources
      */
-    public static SchemaContext parseYangStreams(final InputStream... streams) throws ReactorException {
-        return parseYangStreams(Arrays.asList(streams));
-    }
+    public static SchemaContext parseYangResources(final List<String> yangResourceDirs,
+            final List<String> yangResources, final Set<QName> supportedFeatures,
+            final StatementParserMode statementParserMode) {
+        final List<File> allYangFiles = new ArrayList<>();
+        for (final String yangDir : yangResourceDirs) {
+            allYangFiles.addAll(getYangFiles(yangDir));
+        }
 
-    /**
-     * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
-     * default mode.
-     *
-     * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
-     *                          models are resolved
-     * @param streams input streams containing YANG sources to be parsed
-     *
-     * @return effective schema context
-     *
-     * @throws ReactorException if there is an error in one of the parsed YANG sources
-     */
-    public static SchemaContext parseYangStreams(final Set<QName> supportedFeatures,
-            final InputStream... streams) throws ReactorException {
-        return parseYangStreams(Arrays.asList(streams), supportedFeatures);
-    }
+        for (final String yangFile : yangResources) {
+            try {
+                allYangFiles.add(new File(YangParserTestUtils.class.getResource(yangFile).toURI()));
+            } catch (URISyntaxException e) {
+                throw new IllegalArgumentException("Invalid resource " + yangFile, e);
+            }
+        }
 
-    /**
-     * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
-     *
-     * @param statementParserMode mode of statement parser
-     * @param streams input streams containing YANG sources to be parsed
-     *
-     * @return effective schema context
-     *
-     * @throws ReactorException if there is an error in one of the parsed YANG sources
-     */
-    public static SchemaContext parseYangStreams(final StatementParserMode statementParserMode,
-            final InputStream... streams) throws ReactorException {
-        return parseYangStreams(Arrays.asList(streams), statementParserMode);
+        return parseYangFiles(supportedFeatures, statementParserMode, allYangFiles);
     }
 
-    /**
-     * Creates a new effective schema context containing the specified YANG sources.
-     *
-     * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
-     *                          models are resolved
-     * @param statementParserMode mode of statement parser
-     * @param streams input streams containing YANG sources to be parsed
-     *
-     * @return effective schema context
-     *
-     * @throws ReactorException if there is an error in one of the parsed YANG sources
-     */
-    public static SchemaContext parseYangStreams(final Set<QName> supportedFeatures,
-            final StatementParserMode statementParserMode, final InputStream... streams) throws ReactorException {
-        return parseYangStreams(Arrays.asList(streams), supportedFeatures, statementParserMode);
+    public static SchemaContext parseYangSources(final StatementParserMode parserMode,
+            final Set<QName> supportedFeatures, final YangTextSchemaSource... sources) {
+        return parseYangSources(supportedFeatures, parserMode, Arrays.asList(sources));
     }
 
-    /**
-     * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
-     * default mode and all YANG features are supported.
-     *
-     * @param clazz Resource lookup base
-     * @param resources Resource names to be looked up
-     *
-     * @return effective schema context
-     *
-     * @throws ReactorException if there is an error in one of the parsed YANG sources
-     */
-    public static SchemaContext parseYangResources(final Class<?> clazz, final String... resources)
-            throws ReactorException {
-        final List<InputStream> streams = new ArrayList<>(resources.length);
-        for (final String r : resources) {
-            final InputStream is = clazz.getResourceAsStream(r);
-            Preconditions.checkArgument(is != null, "Resource %s not found", r);
-            streams.add(is);
+    public static SchemaContext parseYangSources(final Set<QName> supportedFeatures,
+            final StatementParserMode parserMode, final Collection<? extends YangTextSchemaSource> sources) {
+        final Collection<YangStatementStreamSource> streams = new ArrayList<>(sources.size());
+        for (YangTextSchemaSource source : sources) {
+            try {
+                streams.add(YangStatementStreamSource.create(source));
+            } catch (IOException e) {
+                throw new IllegalArgumentException("Failed to read source " + source, e);
+            } catch (YangSyntaxErrorException e) {
+                throw new IllegalArgumentException("Malformed source " + source, e);
+            }
         }
 
-        return parseYangStreams(streams);
+        return parseSources(supportedFeatures, parserMode, streams);
     }
 
     /**
@@ -733,12 +346,9 @@ public final class YangParserTestUtils {
      * default mode and all YANG features are supported.
      *
      * @param sources YIN sources to be parsed
-     *
      * @return effective schema context
-     *
-     * @throws ReactorException if there is an error in one of the parsed YIN sources
      */
-    public static SchemaContext parseYinSources(final YinStatementStreamSource... sources) throws ReactorException {
+    public static SchemaContext parseYinSources(final YinStatementStreamSource... sources) {
         return parseYinSources(StatementParserMode.DEFAULT_MODE, sources);
     }
 
@@ -755,7 +365,7 @@ public final class YangParserTestUtils {
      */
     public static SchemaContext parseYinSources(final Set<QName> supportedFeatures,
             final YinStatementStreamSource... sources) throws ReactorException {
-        return parseYinSources(supportedFeatures, StatementParserMode.DEFAULT_MODE, sources);
+        return parseSources(supportedFeatures, StatementParserMode.DEFAULT_MODE, sources);
     }
 
     /**
@@ -763,42 +373,61 @@ public final class YangParserTestUtils {
      *
      * @param statementParserMode mode of statement parser
      * @param sources YIN sources to be parsed
-     *
      * @return effective schema context
-     *
-     * @throws ReactorException if there is an error in one of the parsed YIN sources
      */
     public static SchemaContext parseYinSources(final StatementParserMode statementParserMode,
-            final YinStatementStreamSource... sources) throws ReactorException {
-        return parseYinSources(null, statementParserMode, sources);
+            final YinStatementStreamSource... sources) {
+        return parseSources(null, statementParserMode, sources);
+    }
+
+    /**
+     * Creates a new effective schema context containing the specified YANG sources.
+     *
+     * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
+     *                          models are resolved
+     * @param parserMode mode of statement parser
+     * @param sources sources to be parsed
+     *
+     * @return effective schema context
+     */
+    public static SchemaContext parseSources(final Set<QName> supportedFeatures,
+            final StatementParserMode parserMode, final StatementStreamSource... sources) {
+        return parseSources(supportedFeatures, parserMode, Arrays.asList(sources));
     }
 
     /**
-     * Creates a new effective schema context containing the specified YIN sources.
+     * Creates a new effective schema context containing the specified YANG sources.
      *
-     * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YIN
+     * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
      *                          models are resolved
      * @param statementParserMode mode of statement parser
-     * @param sources YIN sources to be parsed
+     * @param sources sources to be parsed
      *
      * @return effective schema context
-     *
-     * @throws ReactorException if there is an error in one of the parsed YIN sources
      */
-    public static SchemaContext parseYinSources(final Set<QName> supportedFeatures,
-            final StatementParserMode statementParserMode, final YinStatementStreamSource... sources)
-                    throws ReactorException {
+    public static SchemaContext parseSources(final Set<QName> supportedFeatures,
+            final StatementParserMode statementParserMode, final Collection<? extends StatementStreamSource> sources) {
         final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(
-                statementParserMode, supportedFeatures);
+                statementParserMode);
+        if (supportedFeatures != null) {
+            reactor.setSupportedFeatures(supportedFeatures);
+        }
         reactor.addSources(sources);
 
-        return reactor.buildEffective();
+        try {
+            return reactor.buildEffective();
+        } catch (ReactorException e) {
+            throw new IllegalStateException(e);
+        }
     }
 
-    private static Collection<File> getYangFiles(final String yangSourcesDirectoryPath) throws URISyntaxException {
-        final URI directoryPath = YangParserTestUtils.class.getResource(yangSourcesDirectoryPath).toURI();
-        final File dir = new File(directoryPath);
-
-        return Arrays.asList(dir.listFiles(YANG_FILE_FILTER));
+    private static Collection<File> getYangFiles(final String resourcePath) {
+        final URI directoryPath;
+        try {
+            directoryPath = YangParserTestUtils.class.getResource(resourcePath).toURI();
+        } catch (URISyntaxException e) {
+            throw new IllegalArgumentException("Failed to open resource directory " + resourcePath, e);
+        }
+        return Arrays.asList(new File(directoryPath).listFiles(YANG_FILE_FILTER));
     }
 }