Add a knob to control warnings about unkeyed lists
[yangtools.git] / tools / yang-model-validator / src / main / java / org / opendaylight / yangtools / yang / validator / SystemTestUtils.java
index 8db35300baffffe9dae8f5a61a5cfc553ed7b7eb..db42013067959dc8179c25710b5d1696c9b87b58 100644 (file)
@@ -34,6 +34,7 @@ import org.opendaylight.yangtools.yang.common.YangConstants;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
 import org.opendaylight.yangtools.yang.parser.api.YangParser;
+import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
 import org.opendaylight.yangtools.yang.parser.api.YangParserException;
 import org.opendaylight.yangtools.yang.parser.api.YangParserFactory;
 
@@ -61,7 +62,8 @@ final class SystemTestUtils {
     };
 
     static EffectiveModelContext parseYangSources(final List<String> yangLibDirs, final List<String> yangTestFiles,
-            final Set<QName> supportedFeatures, final boolean recursiveSearch) throws IOException, YangParserException {
+            final Set<QName> supportedFeatures, final boolean recursiveSearch,
+            final boolean warnForUnkeyedLists) throws IOException, YangParserException {
         /*
          * Current dir "." should be always present implicitly in the list of
          * directories where dependencies are searched for
@@ -84,23 +86,25 @@ final class SystemTestUtils {
             }
         }
 
-        return parseYangSources(supportedFeatures, testFiles, libFiles);
+        return parseYangSources(supportedFeatures, testFiles, libFiles, warnForUnkeyedLists);
     }
 
     static EffectiveModelContext parseYangSources(final Set<QName> supportedFeatures, final List<File> testFiles,
-            final List<File> libFiles) throws IOException, YangParserException {
+            final List<File> libFiles,  final boolean warnForUnkeyedLists) throws IOException, YangParserException {
         checkArgument(!testFiles.isEmpty(), "No yang sources");
 
-        final YangParser parser = PARSER_FACTORY.createParser();
+        final YangParserConfiguration configuration = YangParserConfiguration.builder()
+                .warnForUnkeyedLists(warnForUnkeyedLists).build();
+        final YangParser parser = PARSER_FACTORY.createParser(configuration);
         if (supportedFeatures != null) {
             parser.setSupportedFeatures(supportedFeatures);
         }
 
         for (File file : testFiles) {
-            parser.addSource(YangTextSchemaSource.forFile(file));
+            parser.addSource(YangTextSchemaSource.forPath(file.toPath()));
         }
         for (File file : libFiles) {
-            parser.addLibSource(YangTextSchemaSource.forFile(file));
+            parser.addLibSource(YangTextSchemaSource.forPath(file.toPath()));
         }
 
         return parser.buildEffectiveModel();