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;
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);
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);
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() {
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() {