X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=yang%2Fyang-system-test%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fparser%2Fsystem%2Ftest%2FSystemTestUtils.java;fp=yang%2Fyang-system-test%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fparser%2Fsystem%2Ftest%2FSystemTestUtils.java;h=d8be9fd8be636815d73f61976b99563b333fd51f;hb=9f3ea6a51c910af28f01cf0a367c71d25d288f39;hp=20448408221fbd7f7b7d96d17950bc6dac22940f;hpb=0291abbea73d463bb0864591073ac1337c70e4af;p=yangtools.git diff --git a/yang/yang-system-test/src/main/java/org/opendaylight/yangtools/yang/parser/system/test/SystemTestUtils.java b/yang/yang-system-test/src/main/java/org/opendaylight/yangtools/yang/parser/system/test/SystemTestUtils.java index 2044840822..d8be9fd8be 100644 --- a/yang/yang-system-test/src/main/java/org/opendaylight/yangtools/yang/parser/system/test/SystemTestUtils.java +++ b/yang/yang-system-test/src/main/java/org/opendaylight/yangtools/yang/parser/system/test/SystemTestUtils.java @@ -18,8 +18,8 @@ import java.util.List; import java.util.Set; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode; 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; @@ -35,55 +35,62 @@ class SystemTestUtils { } }; - static SchemaContext parseYangSources(final Collection files, final Set supportedFeatures) - throws ReactorException, FileNotFoundException { - return parseYangSources(files, StatementParserMode.DEFAULT_MODE, supportedFeatures); - } - - static SchemaContext parseYangSources(final Collection files, - final StatementParserMode statementParserMode, final Set supportedFeatures) - throws ReactorException, FileNotFoundException { - return parseYangSources(supportedFeatures, statementParserMode, files.toArray(new File[files.size()])); - } + static SchemaContext parseYangSources(final List yangLibDirs, final List yangTestFiles, + final Set supportedFeatures) throws FileNotFoundException, ReactorException { + /* + * Current dir "." should be always present implicitly in the list of + * directories where dependencies are searched for + */ + if (!yangLibDirs.contains(".")) { + yangLibDirs.add("."); + } - static SchemaContext parseYangSources(final Set supportedFeatures, - final StatementParserMode statementParserMode, final File... files) throws ReactorException, - FileNotFoundException { - final YangStatementSourceImpl [] sources = new YangStatementSourceImpl[files.length]; + final List libFiles = new ArrayList<>(); + for (final String yangLibDir : yangLibDirs) { + libFiles.addAll(getYangFiles(yangLibDir)); + } - for (int i = 0; i < files.length; i++) { - sources[i] = new YangStatementSourceImpl(new NamedFileInputStream(files[i], files[i].getPath())); + final List testFiles = new ArrayList<>(); + for (final String yangTestFile : yangTestFiles) { + testFiles.add(new File(yangTestFile)); } - return parseYangSources(supportedFeatures, statementParserMode, sources); + return parseYangSources(supportedFeatures, testFiles, libFiles); + } + + static SchemaContext parseYangSources(final Set supportedFeatures, final List testFiles, + final List libFiles) throws FileNotFoundException, ReactorException { + final StatementStreamSource[] testSources = getYangStatementSources(testFiles); + final StatementStreamSource[] libSources = getYangStatementSources(libFiles); + return parseYangSources(testSources, libSources, supportedFeatures); } - static SchemaContext parseYangSources(final Set supportedFeatures, - final StatementParserMode statementParserMode, final YangStatementSourceImpl... sources) - throws ReactorException { - final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild( - statementParserMode, supportedFeatures); - reactor.addSources(sources); + static SchemaContext parseYangSources(final StatementStreamSource[] testSources, + final StatementStreamSource[] libSources, final Set supportedFeatures) throws ReactorException { + + final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR + .newBuild(supportedFeatures); + reactor.addSources(testSources); + reactor.addLibSources(libSources); return reactor.buildEffective(); } - static SchemaContext parseYangSources(final List yangDirs, final List yangFiles, - final Set supportedFeatures) throws FileNotFoundException, ReactorException { - final List allYangFiles = new ArrayList<>(); - for (final String yangDir : yangDirs) { - allYangFiles.addAll(getYangFiles(yangDir)); + private static StatementStreamSource[] getYangStatementSources(final List yangFiles) + throws FileNotFoundException { + final StatementStreamSource[] yangSources = new StatementStreamSource[yangFiles.size()]; + for (int i = 0; i < yangFiles.size(); i++) { + yangSources[i] = new YangStatementSourceImpl(new NamedFileInputStream(yangFiles.get(i), yangFiles.get(i) + .getPath())); } - - for (final String yangFile : yangFiles) { - allYangFiles.add(new File(yangFile)); - } - - return parseYangSources(allYangFiles, supportedFeatures); + return yangSources; } - private static Collection getYangFiles(final String yangSourcesDirectoryPath) { + private static Collection getYangFiles(final String yangSourcesDirectoryPath) throws FileNotFoundException { final File testSourcesDir = new File(yangSourcesDirectoryPath); + if (testSourcesDir == null || !testSourcesDir.isDirectory()) { + throw new FileNotFoundException(String.format("%s no such directory", yangSourcesDirectoryPath)); + } return Arrays.asList(testSourcesDir.listFiles(YANG_FILE_FILTER)); } }