Java 8: use lambdas and function references
[yangtools.git] / yang / yang-maven-plugin / src / main / java / org / opendaylight / yangtools / yang2sources / plugin / Util.java
index 424bb486fe852f741450fe468092f6909430deb2..939b0451ecf365a0dd82aec0efdc59ef49a9fe2b 100644 (file)
@@ -13,7 +13,6 @@ import com.google.common.collect.Maps;
 import java.io.Closeable;
 import java.io.File;
 import java.io.FileNotFoundException;
-import java.io.FilenameFilter;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -231,7 +230,7 @@ final class Util {
     private static final String JAR_SUFFIX = ".jar";
 
     private static boolean isJar(File element) {
-        return (element.isFile() && element.getName().endsWith(JAR_SUFFIX)) ? true : false;
+        return (element.isFile() && element.getName().endsWith(JAR_SUFFIX));
     }
 
     static <T> T checkNotNull(T obj, String paramName) {
@@ -275,12 +274,8 @@ final class Util {
                     //FIXME: code duplicate
                     File yangDir = new File(file, YangToSourcesProcessor.META_INF_YANG_STRING);
                     if (yangDir.exists() && yangDir.isDirectory()) {
-                        File[] yangFiles = yangDir.listFiles(new FilenameFilter() {
-                            @Override
-                            public boolean accept(File dir, String name) {
-                                return name.endsWith(".yang") && new File(dir, name).isFile();
-                            }
-                        });
+                        File[] yangFiles = yangDir.listFiles(
+                                (dir, name) -> name.endsWith(".yang") && new File(dir, name).isFile());
                         for (final File yangFile : yangFiles) {
                             yangsFromDependencies.add(new YangSourceFromFile(yangFile));
                         }
@@ -328,23 +323,24 @@ final class Util {
     static Collection<File> findYangFilesInDependencies(MavenProject project) throws MojoFailureException {
         final List<File> yangsFilesFromDependencies = new ArrayList<>();
 
+        List<File> filesOnCp;
         try {
-            List<File> filesOnCp = Util.getClassPath(project);
-            LOG.info("{} Searching for yang files in following dependencies: {}", YangToSourcesProcessor.LOG_PREFIX,
-                    filesOnCp);
+            filesOnCp = Util.getClassPath(project);
+        } catch (Exception e) {
+            throw new MojoFailureException("Failed to scan for YANG files in dependencies", e);
+        }
+        LOG.info("{} Searching for yang files in following dependencies: {}", YangToSourcesProcessor.LOG_PREFIX,
+            filesOnCp);
 
-            for (File file : filesOnCp) {
+        for (File file : filesOnCp) {
+            try {
                 // 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() {
-                            @Override
-                            public boolean accept(File dir, String name) {
-                                return name.endsWith(".yang") && new File(dir, name).isFile();
-                            }
-                        });
+                        File[] yangFiles = yangDir.listFiles(
+                                (dir, name) -> name.endsWith(".yang") && new File(dir, name).isFile());
 
                         yangsFilesFromDependencies.addAll(Arrays.asList(yangFiles));
                     }
@@ -366,9 +362,9 @@ final class Util {
                         }
                     }
                 }
+            } catch (Exception e) {
+                throw new MojoFailureException("Failed to scan for YANG files in dependency: " + file.toString(), e);
             }
-        } catch (Exception e) {
-            throw new MojoFailureException("Failed to scan for YANG files in depedencies", e);
         }
         return yangsFilesFromDependencies;
     }