Cleanup SystemTestUtils 89/61289/4
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 7 Aug 2017 17:56:13 +0000 (19:56 +0200)
committerRobert Varga <nite@hq.sk>
Mon, 28 Aug 2017 12:17:39 +0000 (12:17 +0000)
Remove use of deprecated class. Also convert to using collections.

Change-Id: I15eeee89628dfedb2ca0baf9a9b4f318801daddb
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/CrossSourceStatementReactor.java
yang/yang-system-test/src/main/java/org/opendaylight/yangtools/yang/parser/system/test/SystemTestUtils.java

index 87dfcecb8188f22c06b69e086469c53af5a173ea..122fad30133d8ff3e80629d3800661a0b882aeda 100644 (file)
@@ -233,6 +233,10 @@ public final class CrossSourceStatementReactor {
          *            yang sources which should be added into library sources
          */
         public void addLibSources(final StatementStreamSource... libSources) {
+            addLibSources(Arrays.asList(libSources));
+        }
+
+        public void addLibSources(final Collection<StatementStreamSource> libSources) {
             for (final StatementStreamSource libSource : libSources) {
                 context.addLibSource(libSource);
             }
index 5b1e3b40388bfd871319dcce6a796693276d2b48..986ab006041b613b97eaf696894168527f8aa118 100644 (file)
@@ -12,6 +12,7 @@ import com.google.common.base.Preconditions;
 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;
@@ -19,25 +20,24 @@ 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.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
@@ -60,15 +60,15 @@ class SystemTestUtils {
     }
 
     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);
@@ -81,12 +81,11 @@ class SystemTestUtils {
         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;
     }
@@ -94,7 +93,7 @@ class SystemTestUtils {
     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));
         }