Merge "Bug 2444: Added concrete API definitions for YANG statements."
[yangtools.git] / yang / yang-maven-plugin / src / main / java / org / opendaylight / yangtools / yang2sources / plugin / Util.java
index a3c2110b8c578c18208ce2bf67d9fc06ce86bfbc..ee9a6897423788f38eeff1bbce37a10103f44411 100644 (file)
@@ -16,6 +16,7 @@ import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.List;
@@ -82,7 +83,10 @@ final class Util {
 
     static Collection<File> listFiles(File root, File[] excludedFiles, Log log) throws FileNotFoundException {
         if (!root.exists()) {
-            throw new FileNotFoundException(root.toString());
+            if (log != null) {
+                log.warn(Util.message("YANG source directory %s not found. No code will be generated.", YangToSourcesProcessor.LOG_PREFIX, root.toString()));
+            }
+            return Collections.emptyList();
         }
         Collection<File> result = new ArrayList<>();
         Collection<File> yangFiles = FileUtils.listFiles(root, new String[] { YANG_SUFFIX }, true);
@@ -122,21 +126,12 @@ final class Util {
     private static Class<?> resolveClass(String codeGeneratorClass, Class<?> baseType) throws ClassNotFoundException {
         Class<?> clazz = Class.forName(codeGeneratorClass);
 
-        if (!isImplemented(baseType, clazz)) {
+        if (!baseType.isAssignableFrom(clazz)) {
             throw new IllegalArgumentException("Code generator " + clazz + " has to implement " + baseType);
         }
         return clazz;
     }
 
-    private static boolean isImplemented(Class<?> expectedIface, Class<?> byClazz) {
-        for (Class<?> iface : byClazz.getInterfaces()) {
-            if (iface.equals(expectedIface)) {
-                return true;
-            }
-        }
-        return false;
-    }
-
     static String message(String message, String logPrefix, Object... args) {
         String innerMessage = String.format(message, args);
         return String.format("%s %s", logPrefix, innerMessage);
@@ -297,6 +292,7 @@ final class Util {
                 List<String> foundFilesForReporting = new ArrayList<>();
                 // is it jar file or directory?
                 if (file.isDirectory()) {
+                    //FIXME: code duplicate
                     File yangDir = new File(file, YangToSourcesProcessor.META_INF_YANG_STRING);
                     if (yangDir.exists() && yangDir.isDirectory()) {
                         File[] yangFiles = yangDir.listFiles(new FilenameFilter() {
@@ -352,6 +348,7 @@ final class Util {
             for (File file : filesOnCp) {
                 // is it jar file or directory?
                 if (file.isDirectory()) {
+                    //FIXME: code duplicate
                     File yangDir = new File(file, YangToSourcesProcessor.META_INF_YANG_STRING);
                     if (yangDir.exists() && yangDir.isDirectory()) {
                         File[] yangFiles = yangDir.listFiles(new FilenameFilter() {