Enable SpotBugs enforcement in yang-validation-tool
[yangtools.git] / yang-validation-tool / src / main / java / org / opendaylight / yangtools / yang / validation / tool / Params.java
index 6cd01cd64231cdb4218c131ff7e93bff31819806..aab1789532b1333a213788b2d7f303d462b2131d 100644 (file)
@@ -8,17 +8,19 @@
 package org.opendaylight.yangtools.yang.validation.tool;
 
 import java.io.File;
-import java.net.URISyntaxException;
 import net.sourceforge.argparse4j.ArgumentParsers;
 import net.sourceforge.argparse4j.annotation.Arg;
 import net.sourceforge.argparse4j.inf.ArgumentParser;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 final class Params {
+    private static final Logger LOG = LoggerFactory.getLogger(Params.class);
 
     @Arg(dest = "yang-source-dir")
     private File yangSourceDir;
 
-    static ArgumentParser getParser() throws URISyntaxException {
+    static ArgumentParser getParser() {
         final ArgumentParser parser = ArgumentParsers.newArgumentParser("jar_file_name");
         parser.description("Validation Tool for Yang Models")
             .formatUsage();
@@ -39,15 +41,20 @@ final class Params {
             return false;
         }
         if (!yangSourceDir.exists()) {
-            System.err.println("Yang source directory has to exist");
+            LOG.error("Yang source directory has to exist");
             return false;
         }
         if (!yangSourceDir.canRead()) {
-            System.err.println("Yang source directory has to be readable");
+            LOG.error("Yang source directory has to be readable");
             return false;
         }
-        if (yangSourceDir.list().length == 0) {
-            System.err.printf("Yang source directory '%s' does't contain any model%n", yangSourceDir.getPath());
+        final String[] listed = yangSourceDir.list();
+        if (listed == null) {
+            LOG.error("Yang source directory {} is not a directory or cannot be read", yangSourceDir.getPath());
+            return false;
+        }
+        if (listed.length == 0) {
+            LOG.error("Yang source directory {} doesn't contain any model", yangSourceDir.getPath());
             return false;
         }