import java.io.File;
import java.io.FileFilter;
import java.io.FileNotFoundException;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
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.parser.api.YangSyntaxErrorException;
+import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.parser.rfc6020.repo.YangStatementStreamSource;
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;
class SystemTestUtils {
- static final FileFilter YANG_FILE_FILTER = new FileFilter() {
- @Override
- public boolean accept(final File file) {
- final String name = file.getName().toLowerCase();
- return name.endsWith(".yang") && file.isFile();
- }
+ static final FileFilter YANG_FILE_FILTER = file -> {
+ final String name = file.getName().toLowerCase();
+ return name.endsWith(".yang") && file.isFile();
};
static SchemaContext parseYangSources(final List<String> yangLibDirs, final List<String> yangTestFiles,
- final Set<QName> supportedFeatures, final boolean recursiveSearch) throws FileNotFoundException, ReactorException {
+ final Set<QName> supportedFeatures, final boolean recursiveSearch) throws ReactorException, IOException,
+ YangSyntaxErrorException {
/*
* Current dir "." should be always present implicitly in the list of
* directories where dependencies are searched for
}
static SchemaContext parseYangSources(final Set<QName> supportedFeatures, final List<File> testFiles,
- final List<File> libFiles) throws FileNotFoundException, ReactorException {
- final StatementStreamSource[] testSources = getYangStatementSources(testFiles);
- final StatementStreamSource[] libSources = getYangStatementSources(libFiles);
+ final List<File> libFiles) throws ReactorException, IOException, YangSyntaxErrorException {
+ final List<StatementStreamSource> testSources = getYangStatementSources(testFiles);
+ final List<StatementStreamSource> libSources = getYangStatementSources(libFiles);
return parseYangSources(testSources, libSources, supportedFeatures);
}
- static SchemaContext parseYangSources(final StatementStreamSource[] testSources,
- final StatementStreamSource[] libSources, final Set<QName> supportedFeatures) throws ReactorException {
- Preconditions.checkArgument(testSources != null && testSources.length > 0, "No yang sources");
+ static SchemaContext parseYangSources(final List<StatementStreamSource> testSources,
+ final List<StatementStreamSource> libSources, final Set<QName> supportedFeatures) throws ReactorException {
+ Preconditions.checkArgument(testSources != null && !testSources.isEmpty(), "No yang sources");
final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
reactor.addSources(testSources);
return reactor.buildEffective();
}
- private static StatementStreamSource[] getYangStatementSources(final List<File> 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()));
+ private static List<StatementStreamSource> getYangStatementSources(final List<File> yangFiles)
+ throws IOException, YangSyntaxErrorException {
+ final List<StatementStreamSource> yangSources = new ArrayList<>(yangFiles.size());
+ for (File file : yangFiles) {
+ yangSources.add(YangStatementStreamSource.create(YangTextSchemaSource.forFile(file)));
}
return yangSources;
}
private static Collection<File> getYangFiles(final String yangSourcesDirectoryPath, final boolean recursiveSearch)
throws FileNotFoundException {
final File testSourcesDir = new File(yangSourcesDirectoryPath);
- if (testSourcesDir == null || !testSourcesDir.isDirectory()) {
+ if (!testSourcesDir.isDirectory()) {
throw new FileNotFoundException(String.format("%s no such directory", yangSourcesDirectoryPath));
}