Improve yang-maven-plugin error reporting 93/42193/2
authorMichael Vorburger <vorburger@redhat.com>
Thu, 21 Jul 2016 01:58:22 +0000 (03:58 +0200)
committerRobert Varga <nite@hq.sk>
Thu, 21 Jul 2016 08:26:15 +0000 (08:26 +0000)
Instead of e.g. this: org.apache.maven.plugin.MojoFailureException:
Failed to scan for YANG files in depedencies (...) Caused by:
java.util.zip.ZipException: invalid CEN header (bad signature) at
java.util.zip.ZipFile.open(Native Method)

it will now report the much more useful variation like this:
org.apache.maven.plugin.MojoFailureException: Failed to scan for YANG
files in dependency:
/home/vorburger/.m2/repository/org/opendaylight/openflowplugin/model/model-flow-base/0.3.0-SNAPSHOT/model-flow-base-0.3.0-SNAPSHOT.jar

Change-Id: I1062d10d9157f9ac6b44cd86a29af8cc8e87b25f
Signed-off-by: Michael Vorburger <vorburger@redhat.com>
yang/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/Util.java

index 8ecf8f65ab289465c4d0fd79a043379fd6a9467d..a29ad42a4636d1961ad53d950a07d8882eea5dd8 100644 (file)
@@ -328,12 +328,17 @@ 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
@@ -366,9 +371,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;
     }