Bug 7396 - yang-system-test could support recursive search
[yangtools.git] / yang / yang-system-test / src / main / java / org / opendaylight / yangtools / yang / parser / system / test / Main.java
index cab46b9cf3898038eedcfbfcdf2469e38d87ade7..748ec5f7f39325300d929ae817d9067a4d09d192 100644 (file)
@@ -8,14 +8,11 @@
 package org.opendaylight.yangtools.yang.parser.system.test;
 
 import com.google.common.base.Stopwatch;
-import java.io.FileNotFoundException;
-import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.List;
-import java.util.function.Predicate;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 import org.apache.commons.cli.BasicParser;
@@ -25,11 +22,9 @@ import org.apache.commons.cli.HelpFormatter;
 import org.apache.commons.cli.Option;
 import org.apache.commons.cli.Options;
 import org.apache.commons.cli.ParseException;
+import org.apache.log4j.BasicConfigurator;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.model.repo.api.IfFeaturePredicates;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 
 /**
  * Main class of Yang parser system test.
@@ -43,6 +38,7 @@ import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
  *  -h,--help             print help message and exit.
  *  -p,--path <arg>       path is a colon (:) separated list of directories
  *                        to search for yang modules.
+ *  -r, --recursive       recursive search of directories specified by -p option
  *  -v,--verbose          shows details about the results of test running.
  *
  */
@@ -62,6 +58,11 @@ public class Main {
         path.setRequired(false);
         options.addOption(path);
 
+        final Option recursiveSearch = new Option("r", "recursive", false,
+                "recursive search of directories specified by -p option.");
+        recursiveSearch.setRequired(false);
+        options.addOption(recursiveSearch);
+
         final Option verbose = new Option("v", "verbose", false, "shows details about the results of test running.");
         verbose.setRequired(false);
         options.addOption(verbose);
@@ -78,8 +79,9 @@ public class Main {
         return options;
     }
 
-    public static void main(final String[] args) throws SourceException, FileNotFoundException, ReactorException,
-            URISyntaxException {
+    public static void main(final String[] args) {
+
+        BasicConfigurator.configure();
 
         final HelpFormatter formatter = new HelpFormatter();
         final Options options = createOptions();
@@ -96,28 +98,26 @@ public class Main {
             LOG.setLevel(Level.SEVERE);
         }
 
-        final List<String> yangDirs = initYangDirsPath(arguments);
+        final List<String> yangLibDirs = initYangDirsPath(arguments);
         final List<String> yangFiles = Arrays.asList(arguments.getArgs());
         final HashSet<QName> supportedFeatures = initSupportedFeatures(arguments);
 
-        runSystemTest(yangDirs, yangFiles, supportedFeatures);
+        runSystemTest(yangLibDirs, yangFiles, supportedFeatures, arguments.hasOption("recursive"));
     }
 
-    private static void runSystemTest(final List<String> yangDirs, final List<String> yangFiles,
-            final HashSet<QName> supportedFeatures) {
-        LOG.log(Level.INFO, "Yang model dirs: {0} ", yangDirs);
+    private static void runSystemTest(final List<String> yangLibDirs, final List<String> yangFiles,
+            final HashSet<QName> supportedFeatures, final boolean recursiveSearch) {
+        LOG.log(Level.INFO, "Yang model dirs: {0} ", yangLibDirs);
         LOG.log(Level.INFO, "Yang model files: {0} ", yangFiles);
         LOG.log(Level.INFO, "Supported features: {0} ", supportedFeatures);
 
-        final Predicate<QName> isFeatureSupported = supportedFeatures == null ? IfFeaturePredicates.ALL_FEATURES
-                : q -> supportedFeatures.contains(q);
         SchemaContext context = null;
 
         printMemoryInfo("start");
         final Stopwatch stopWatch = Stopwatch.createStarted();
 
         try {
-            context = YangParserUtils.parseYangSources(yangDirs, yangFiles, isFeatureSupported);
+            context = SystemTestUtils.parseYangSources(yangLibDirs, yangFiles, supportedFeatures, recursiveSearch);
         } catch (final Exception e) {
             LOG.log(Level.SEVERE, "Failed to create SchemaContext.", e);
             System.exit(1);