2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.yangtools.yang.test.util;
11 import com.google.common.annotations.Beta;
12 import com.google.common.base.Preconditions;
14 import java.io.FileFilter;
15 import java.io.FileNotFoundException;
16 import java.io.InputStream;
18 import java.net.URISyntaxException;
19 import java.util.ArrayList;
20 import java.util.Arrays;
21 import java.util.Collection;
22 import java.util.List;
24 import org.opendaylight.yangtools.yang.common.QName;
25 import org.opendaylight.yangtools.yang.common.YangConstants;
26 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
27 import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode;
28 import org.opendaylight.yangtools.yang.parser.rfc6020.repo.YinStatementStreamSource;
29 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
30 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
31 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
32 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
33 import org.opendaylight.yangtools.yang.parser.util.NamedFileInputStream;
36 * Utility class which provides convenience methods for producing effective schema context based on the supplied
37 * yang/yin sources or paths to these sources.
40 public final class YangParserTestUtils {
42 private static final FileFilter YANG_FILE_FILTER = file -> {
43 final String name = file.getName().toLowerCase();
44 return name.endsWith(YangConstants.RFC6020_YANG_FILE_EXTENSION) && file.isFile();
47 private YangParserTestUtils() {
48 throw new UnsupportedOperationException("Utility class should not be instantiated.");
52 * Creates a new effective schema context containing the specified YANG source. Statement parser mode is set to
53 * default mode and all YANG features are supported.
55 * @param yangSourcePath relative path to the YANG file to be parsed
57 * @return effective schema context
59 * @throws ReactorException if there is an error in the parsed YANG source
60 * @throws FileNotFoundException if the specified file does not exist
61 * @throws URISyntaxException if the specified file does not exist
63 public static SchemaContext parseYangSource(final String yangSourcePath) throws ReactorException,
64 FileNotFoundException, URISyntaxException {
65 return parseYangSource(yangSourcePath, StatementParserMode.DEFAULT_MODE);
69 * Creates a new effective schema context containing the specified YANG source. Statement parser mode is set to
72 * @param yangSourcePath relative path to the YANG file to be parsed
73 * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
76 * @return effective schema context
78 * @throws ReactorException if there is an error in the parsed YANG source
79 * @throws FileNotFoundException if the specified file does not exist
80 * @throws URISyntaxException if the specified file does not exist
82 public static SchemaContext parseYangSource(final String yangSourcePath, final Set<QName> supportedFeatures)
83 throws ReactorException, FileNotFoundException, URISyntaxException {
84 return parseYangSource(yangSourcePath, supportedFeatures, StatementParserMode.DEFAULT_MODE);
88 * Creates a new effective schema context containing the specified YANG source. All YANG features are supported.
90 * @param yangSourcePath relative path to the YANG file to be parsed
91 * @param statementParserMode mode of statement parser
93 * @return effective schema context
95 * @throws ReactorException if there is an error in the parsed YANG source
96 * @throws FileNotFoundException if the specified file does not exist
97 * @throws URISyntaxException if the specified file does not exist
99 public static SchemaContext parseYangSource(final String yangSourcePath,
100 final StatementParserMode statementParserMode) throws ReactorException, FileNotFoundException,
102 return parseYangSource(yangSourcePath, null, statementParserMode);
106 * Creates a new effective schema context containing the specified YANG source.
108 * @param yangSourcePath relative path to the YANG file to be parsed
109 * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
111 * @param statementParserMode mode of statement parser
113 * @return effective schema context
115 * @throws ReactorException if there is an error in the parsed YANG source
116 * @throws FileNotFoundException if the specified file does not exist
117 * @throws URISyntaxException if the specified file does not exist
119 public static SchemaContext parseYangSource(final String yangSourcePath, final Set<QName> supportedFeatures,
120 final StatementParserMode statementParserMode) throws ReactorException, FileNotFoundException,
122 final URI sourcePath = YangParserTestUtils.class.getResource(yangSourcePath).toURI();
123 final File sourceFile = new File(sourcePath);
124 return parseYangSources(supportedFeatures, statementParserMode, sourceFile);
128 * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
129 * default mode and all YANG features are supported.
131 * @param sources YANG sources to be parsed
133 * @return effective schema context
135 * @throws ReactorException if there is an error in one of the parsed YANG sources
137 * @deprecated Migration method only, do not use.
140 public static SchemaContext parseYangSources(final YangStatementSourceImpl... sources) throws ReactorException {
141 return parseYangSources(StatementParserMode.DEFAULT_MODE, sources);
145 * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
148 * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
149 * models are resolved
150 * @param sources YANG sources to be parsed
152 * @return effective schema context
153 * @throws ReactorException if there is an error in one of the parsed YANG sources
155 * @deprecated Migration method only, do not use.
158 public static SchemaContext parseYangSources(final Set<QName> supportedFeatures,
159 final YangStatementSourceImpl... sources) throws ReactorException {
160 return parseYangSources(supportedFeatures, StatementParserMode.DEFAULT_MODE, sources);
164 * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
166 * @param statementParserMode mode of statement parser
167 * @param sources YANG sources to be parsed
169 * @return effective schema context
170 * @throws ReactorException if there is an error in one of the parsed YANG sources
172 * @deprecated Migration method only, do not use.
175 public static SchemaContext parseYangSources(final StatementParserMode statementParserMode,
176 final YangStatementSourceImpl... sources) throws ReactorException {
177 return parseYangSources(null, statementParserMode, sources);
181 * Creates a new effective schema context containing the specified YANG sources.
183 * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
184 * models are resolved
185 * @param statementParserMode mode of statement parser
186 * @param sources YANG sources to be parsed
188 * @return effective schema context
190 * @throws ReactorException if there is an error in one of the parsed YANG sources
192 public static SchemaContext parseYangSources(final Set<QName> supportedFeatures,
193 final StatementParserMode statementParserMode, final YangStatementSourceImpl... sources)
194 throws ReactorException {
195 final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(
196 statementParserMode, supportedFeatures);
197 reactor.addSources(sources);
199 return reactor.buildEffective();
203 * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
204 * default mode and all YANG features are supported.
206 * @param files YANG files to be parsed
208 * @return effective schema context
210 * @throws ReactorException if there is an error in one of the parsed YANG sources
211 * @throws FileNotFoundException if one of the specified files does not exist
213 public static SchemaContext parseYangSources(final File... files) throws ReactorException, FileNotFoundException {
214 return parseYangSources(StatementParserMode.DEFAULT_MODE, files);
218 * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
221 * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
222 * models are resolved
223 * @param files YANG files to be parsed
225 * @return effective schema context
227 * @throws ReactorException if there is an error in one of the parsed YANG sources
228 * @throws FileNotFoundException if one of the specified files does not exist
230 public static SchemaContext parseYangSources(final Set<QName> supportedFeatures, final File... files)
231 throws ReactorException, FileNotFoundException {
232 return parseYangSources(supportedFeatures, StatementParserMode.DEFAULT_MODE, files);
236 * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
238 * @param statementParserMode mode of statement parser
239 * @param files YANG files to be parsed
241 * @return effective schema context
243 * @throws ReactorException if there is an error in one of the parsed YANG sources
244 * @throws FileNotFoundException if one of the specified files does not exist
246 public static SchemaContext parseYangSources(final StatementParserMode statementParserMode, final File... files)
247 throws ReactorException, FileNotFoundException {
248 return parseYangSources(null, statementParserMode, files);
252 * Creates a new effective schema context containing the specified YANG sources.
254 * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
255 * models are resolved
256 * @param statementParserMode mode of statement parser
257 * @param files YANG files to be parsed
259 * @return effective schema context
261 * @throws ReactorException if there is an error in one of the parsed YANG sources
262 * @throws FileNotFoundException if one of the specified files does not exist
264 public static SchemaContext parseYangSources(final Set<QName> supportedFeatures,
265 final StatementParserMode statementParserMode, final File... files) throws ReactorException,
266 FileNotFoundException {
267 final YangStatementSourceImpl[] sources = new YangStatementSourceImpl[files.length];
268 for (int i = 0; i < files.length; i++) {
269 sources[i] = new YangStatementSourceImpl(new NamedFileInputStream(files[i], files[i].getPath()));
272 return parseYangSources(supportedFeatures, statementParserMode, sources);
276 * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
277 * default mode and all YANG features are supported.
279 * @param files collection of YANG files to be parsed
281 * @return effective schema context
283 * @throws ReactorException if there is an error in one of the parsed YANG sources
284 * @throws FileNotFoundException if one of the specified files does not exist
286 public static SchemaContext parseYangSources(final Collection<File> files) throws ReactorException,
287 FileNotFoundException {
288 return parseYangSources(files, StatementParserMode.DEFAULT_MODE);
292 * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
295 * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
296 * models are resolved
297 * @param files collection of YANG files to be parsed
299 * @return effective schema context
301 * @throws ReactorException if there is an error in one of the parsed YANG sources
302 * @throws FileNotFoundException if one of the specified files does not exist
304 public static SchemaContext parseYangSources(final Collection<File> files, final Set<QName> supportedFeatures)
305 throws ReactorException, FileNotFoundException {
306 return parseYangSources(files, supportedFeatures, StatementParserMode.DEFAULT_MODE);
310 * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
312 * @param statementParserMode mode of statement parser
313 * @param files collection of YANG files to be parsed
315 * @return effective schema context
317 * @throws ReactorException if there is an error in one of the parsed YANG sources
318 * @throws FileNotFoundException if one of the specified files does not exist
320 public static SchemaContext parseYangSources(final Collection<File> files,
321 final StatementParserMode statementParserMode) throws ReactorException, FileNotFoundException {
322 return parseYangSources(files, null, statementParserMode);
326 * Creates a new effective schema context containing the specified YANG sources.
328 * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
329 * models are resolved
330 * @param statementParserMode mode of statement parser
331 * @param files collection of YANG files to be parsed
333 * @return effective schema context
335 * @throws ReactorException if there is an error in one of the parsed YANG sources
336 * @throws FileNotFoundException if one of the specified files does not exist
338 public static SchemaContext parseYangSources(final Collection<File> files, final Set<QName> supportedFeatures,
339 final StatementParserMode statementParserMode) throws ReactorException, FileNotFoundException {
340 return parseYangSources(supportedFeatures, statementParserMode, files.toArray(new File[files.size()]));
344 * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
345 * default mode and all YANG features are supported.
347 * @param yangSourcesDirectoryPath relative path to the directory with YANG files to be parsed
349 * @return effective schema context
351 * @throws ReactorException if there is an error in one of the parsed YANG sources
352 * @throws FileNotFoundException if the specified directory does not exist
353 * @throws URISyntaxException if the specified directory does not exist
355 public static SchemaContext parseYangSources(final String yangSourcesDirectoryPath) throws ReactorException,
356 FileNotFoundException, URISyntaxException {
357 return parseYangSources(yangSourcesDirectoryPath, StatementParserMode.DEFAULT_MODE);
361 * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
364 * @param yangSourcesDirectoryPath relative path to the directory with YANG files to be parsed
365 * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
366 * models are resolved
368 * @return effective schema context
370 * @throws ReactorException if there is an error in one of the parsed YANG sources
371 * @throws FileNotFoundException if the specified directory does not exist
372 * @throws URISyntaxException if the specified directory does not exist
374 public static SchemaContext parseYangSources(final String yangSourcesDirectoryPath,
375 final Set<QName> supportedFeatures) throws ReactorException, FileNotFoundException,
377 return parseYangSources(yangSourcesDirectoryPath, supportedFeatures, StatementParserMode.DEFAULT_MODE);
381 * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
383 * @param yangSourcesDirectoryPath relative path to the directory with YANG files to be parsed
384 * @param statementParserMode mode of statement parser
386 * @return effective schema context
388 * @throws ReactorException if there is an error in one of the parsed YANG sources
389 * @throws FileNotFoundException if the specified directory does not exist
390 * @throws URISyntaxException if the specified directory does not exist
392 public static SchemaContext parseYangSources(final String yangSourcesDirectoryPath,
393 final StatementParserMode statementParserMode) throws ReactorException, FileNotFoundException,
395 return parseYangSources(yangSourcesDirectoryPath, null, statementParserMode);
399 * Creates a new effective schema context containing the specified YANG sources.
401 * @param yangSourcesDirectoryPath relative path to the directory with YANG files to be parsed
402 * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
403 * models are resolved
404 * @param statementParserMode mode of statement parser
406 * @return effective schema context
408 * @throws ReactorException if there is an error in one of the parsed YANG sources
409 * @throws FileNotFoundException if the specified directory does not exist
410 * @throws URISyntaxException if the specified directory does not exist
412 public static SchemaContext parseYangSources(final String yangSourcesDirectoryPath,
413 final Set<QName> supportedFeatures, final StatementParserMode statementParserMode)
414 throws ReactorException, FileNotFoundException, URISyntaxException {
415 final URI directoryPath = YangParserTestUtils.class.getResource(yangSourcesDirectoryPath).toURI();
416 final File dir = new File(directoryPath);
418 return parseYangSources(supportedFeatures, statementParserMode, dir.listFiles(YANG_FILE_FILTER));
422 * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
423 * default mode and all YANG features are supported.
425 * @param yangDirs relative paths to the directories containing YANG files to be parsed
426 * @param yangFiles relative paths to the YANG files to be parsed
428 * @return effective schema context
430 * @throws ReactorException if there is an error in one of the parsed YANG sources
431 * @throws FileNotFoundException if one of the specified directories or files does not exist
432 * @throws URISyntaxException if one of the specified directories or files does not exist
434 public static SchemaContext parseYangSources(final List<String> yangDirs, final List<String> yangFiles)
435 throws FileNotFoundException, ReactorException, URISyntaxException {
436 return parseYangSources(yangDirs, yangFiles, StatementParserMode.DEFAULT_MODE);
440 * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
443 * @param yangDirs relative paths to the directories containing YANG files to be parsed
444 * @param yangFiles relative paths to the YANG files to be parsed
445 * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
446 * models are resolved
448 * @return effective schema context
450 * @throws ReactorException if there is an error in one of the parsed YANG sources
451 * @throws FileNotFoundException if one of the specified directories or files does not exist
452 * @throws URISyntaxException if one of the specified directories or files does not exist
454 public static SchemaContext parseYangSources(final List<String> yangDirs, final List<String> yangFiles,
455 final Set<QName> supportedFeatures) throws FileNotFoundException, ReactorException,
457 return parseYangSources(yangDirs, yangFiles, supportedFeatures, StatementParserMode.DEFAULT_MODE);
461 * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
463 * @param yangDirs relative paths to the directories containing YANG files to be parsed
464 * @param yangFiles relative paths to the YANG files to be parsed
465 * @param statementParserMode mode of statement parser
467 * @return effective schema context
469 * @throws ReactorException if there is an error in one of the parsed YANG sources
470 * @throws FileNotFoundException if one of the specified directories or files does not exist
471 * @throws URISyntaxException if one of the specified directories or files does not exist
473 public static SchemaContext parseYangSources(final List<String> yangDirs, final List<String> yangFiles,
474 final StatementParserMode statementParserMode) throws FileNotFoundException, ReactorException,
476 return parseYangSources(yangDirs, yangFiles, null, statementParserMode);
480 * Creates a new effective schema context containing the specified YANG sources.
482 * @param yangDirs relative paths to the directories containing YANG files to be parsed
483 * @param yangFiles relative paths to the YANG files to be parsed
484 * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
485 * models are resolved
486 * @param statementParserMode mode of statement parser
488 * @return effective schema context
490 * @throws ReactorException if there is an error in one of the parsed YANG sources
491 * @throws FileNotFoundException if one of the specified directories or files does not exist
492 * @throws URISyntaxException if one of the specified directories or files does not exist
494 public static SchemaContext parseYangSources(final List<String> yangDirs, final List<String> yangFiles,
495 final Set<QName> supportedFeatures, final StatementParserMode statementParserMode)
496 throws FileNotFoundException, ReactorException, URISyntaxException {
497 final List<File> allYangFiles = new ArrayList<>();
498 for (final String yangDir : yangDirs) {
499 allYangFiles.addAll(getYangFiles(yangDir));
502 for (final String yangFile : yangFiles) {
503 final URI filePath = YangParserTestUtils.class.getResource(yangFile).toURI();
504 allYangFiles.add(new File(filePath));
507 return parseYangSources(allYangFiles, supportedFeatures, statementParserMode);
511 * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
512 * default mode and all YANG features are supported.
514 * @param filePaths relative paths to the YANG files to be parsed
516 * @return effective schema context
518 * @throws ReactorException if there is an error in one of the parsed YANG sources
520 public static SchemaContext parseYangSources(final List<String> filePaths) throws ReactorException {
521 return parseYangSources(filePaths, StatementParserMode.DEFAULT_MODE);
525 * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
528 * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
529 * models are resolved
530 * @param filePaths relative paths to the YANG files to be parsed
532 * @return effective schema context
534 * @throws ReactorException if there is an error in one of the parsed YANG sources
536 public static SchemaContext parseYangSources(final List<String> filePaths, final Set<QName> supportedFeatures)
537 throws ReactorException {
538 return parseYangSources(filePaths, supportedFeatures, StatementParserMode.DEFAULT_MODE);
542 * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
544 * @param statementParserMode mode of statement parser
545 * @param filePaths relative paths to the YANG files to be parsed
547 * @return effective schema context
549 * @throws ReactorException if there is an error in one of the parsed YANG sources
551 public static SchemaContext parseYangSources(final List<String> filePaths,
552 final StatementParserMode statementParserMode) throws ReactorException {
553 return parseYangSources(filePaths, (Set<QName>) null, statementParserMode);
557 * Creates a new effective schema context containing the specified YANG sources.
559 * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
560 * models are resolved
561 * @param statementParserMode mode of statement parser
562 * @param filePaths relative paths to the YANG files to be parsed
564 * @return effective schema context
566 * @throws ReactorException if there is an error in one of the parsed YANG sources
568 public static SchemaContext parseYangSources(final List<String> filePaths,
569 final Set<QName> supportedFeatures, final StatementParserMode statementParserMode)
570 throws ReactorException {
571 final YangStatementSourceImpl[] sources = new YangStatementSourceImpl[filePaths.size()];
573 for (int i = 0; i < filePaths.size(); i++) {
574 sources[i] = new YangStatementSourceImpl(YangParserTestUtils.class.getResourceAsStream(filePaths.get(i)));
577 return parseYangSources(supportedFeatures, statementParserMode, sources);
581 * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
582 * default mode and all YANG features are supported.
584 * @param streams input streams containing YANG sources to be parsed
586 * @return effective schema context
588 * @throws ReactorException if there is an error in one of the parsed YANG sources
590 public static SchemaContext parseYangStreams(final List<InputStream> streams) throws ReactorException {
591 return parseYangStreams(streams, StatementParserMode.DEFAULT_MODE);
595 * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
598 * @param streams input streams containing YANG sources to be parsed
599 * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
600 * models are resolved
602 * @return effective schema context
604 * @throws ReactorException if there is an error in one of the parsed YANG sources
606 public static SchemaContext parseYangStreams(final List<InputStream> streams, final Set<QName> supportedFeatures)
607 throws ReactorException {
608 return parseYangStreams(streams, supportedFeatures, StatementParserMode.DEFAULT_MODE);
612 * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
614 * @param streams input streams containing YANG sources to be parsed
615 * @param statementParserMode mode of statement parser
617 * @return effective schema context
619 * @throws ReactorException if there is an error in one of the parsed YANG sources
621 public static SchemaContext parseYangStreams(final List<InputStream> streams,
622 final StatementParserMode statementParserMode) throws ReactorException {
623 return parseYangStreams(streams, null, statementParserMode);
627 * Creates a new effective schema context containing the specified YANG sources.
629 * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
630 * models are resolved
631 * @param statementParserMode mode of statement parser
632 * @param streams input streams containing YANG sources to be parsed
634 * @return effective schema context
636 * @throws ReactorException if there is an error in one of the parsed YANG sources
638 public static SchemaContext parseYangStreams(final List<InputStream> streams, final Set<QName> supportedFeatures,
639 final StatementParserMode statementParserMode) throws ReactorException {
640 final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(
641 statementParserMode, supportedFeatures);
642 return reactor.buildEffective(streams);
646 * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
647 * default mode and all YANG features are supported.
649 * @param streams input streams containing YANG sources to be parsed
651 * @return effective schema context
653 * @throws ReactorException if there is an error in one of the parsed YANG sources
655 public static SchemaContext parseYangStreams(final InputStream... streams) throws ReactorException {
656 return parseYangStreams(Arrays.asList(streams));
660 * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
663 * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
664 * models are resolved
665 * @param streams input streams containing YANG sources to be parsed
667 * @return effective schema context
669 * @throws ReactorException if there is an error in one of the parsed YANG sources
671 public static SchemaContext parseYangStreams(final Set<QName> supportedFeatures,
672 final InputStream... streams) throws ReactorException {
673 return parseYangStreams(Arrays.asList(streams), supportedFeatures);
677 * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
679 * @param statementParserMode mode of statement parser
680 * @param streams input streams containing YANG sources to be parsed
682 * @return effective schema context
684 * @throws ReactorException if there is an error in one of the parsed YANG sources
686 public static SchemaContext parseYangStreams(final StatementParserMode statementParserMode,
687 final InputStream... streams) throws ReactorException {
688 return parseYangStreams(Arrays.asList(streams), statementParserMode);
692 * Creates a new effective schema context containing the specified YANG sources.
694 * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
695 * models are resolved
696 * @param statementParserMode mode of statement parser
697 * @param streams input streams containing YANG sources to be parsed
699 * @return effective schema context
701 * @throws ReactorException if there is an error in one of the parsed YANG sources
703 public static SchemaContext parseYangStreams(final Set<QName> supportedFeatures,
704 final StatementParserMode statementParserMode, final InputStream... streams) throws ReactorException {
705 return parseYangStreams(Arrays.asList(streams), supportedFeatures, statementParserMode);
709 * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
710 * default mode and all YANG features are supported.
712 * @param clazz Resource lookup base
713 * @param resources Resource names to be looked up
715 * @return effective schema context
717 * @throws ReactorException if there is an error in one of the parsed YANG sources
719 public static SchemaContext parseYangResources(final Class<?> clazz, final String... resources)
720 throws ReactorException {
721 final List<InputStream> streams = new ArrayList<>(resources.length);
722 for (final String r : resources) {
723 final InputStream is = clazz.getResourceAsStream(r);
724 Preconditions.checkArgument(is != null, "Resource %s not found", r);
728 return parseYangStreams(streams);
732 * Creates a new effective schema context containing the specified YIN sources. Statement parser mode is set to
733 * default mode and all YANG features are supported.
735 * @param sources YIN sources to be parsed
737 * @return effective schema context
739 * @throws ReactorException if there is an error in one of the parsed YIN sources
741 public static SchemaContext parseYinSources(final YinStatementStreamSource... sources) throws ReactorException {
742 return parseYinSources(StatementParserMode.DEFAULT_MODE, sources);
746 * Creates a new effective schema context containing the specified YIN sources. Statement parser mode is set to
749 * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YIN
750 * models are resolved
751 * @param sources YIN sources to be parsed
753 * @return effective schema context
754 * @throws ReactorException if there is an error in one of the parsed YIN sources
756 public static SchemaContext parseYinSources(final Set<QName> supportedFeatures,
757 final YinStatementStreamSource... sources) throws ReactorException {
758 return parseYinSources(supportedFeatures, StatementParserMode.DEFAULT_MODE, sources);
762 * Creates a new effective schema context containing the specified YIN sources. All YANG features are supported.
764 * @param statementParserMode mode of statement parser
765 * @param sources YIN sources to be parsed
767 * @return effective schema context
769 * @throws ReactorException if there is an error in one of the parsed YIN sources
771 public static SchemaContext parseYinSources(final StatementParserMode statementParserMode,
772 final YinStatementStreamSource... sources) throws ReactorException {
773 return parseYinSources(null, statementParserMode, sources);
777 * Creates a new effective schema context containing the specified YIN sources.
779 * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YIN
780 * models are resolved
781 * @param statementParserMode mode of statement parser
782 * @param sources YIN sources to be parsed
784 * @return effective schema context
786 * @throws ReactorException if there is an error in one of the parsed YIN sources
788 public static SchemaContext parseYinSources(final Set<QName> supportedFeatures,
789 final StatementParserMode statementParserMode, final YinStatementStreamSource... sources)
790 throws ReactorException {
791 final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(
792 statementParserMode, supportedFeatures);
793 reactor.addSources(sources);
795 return reactor.buildEffective();
798 private static Collection<File> getYangFiles(final String yangSourcesDirectoryPath) throws URISyntaxException {
799 final URI directoryPath = YangParserTestUtils.class.getResource(yangSourcesDirectoryPath).toURI();
800 final File dir = new File(directoryPath);
802 return Arrays.asList(dir.listFiles(YANG_FILE_FILTER));