Improve yang-maven-plugin error reporting for errors in dependencies 17/43517/1
authorMichael Vorburger <vorburger@redhat.com>
Tue, 9 Aug 2016 10:32:58 +0000 (12:32 +0200)
committerRobert Varga <nite@hq.sk>
Tue, 9 Aug 2016 14:20:35 +0000 (14:20 +0000)
Instead of e.g. this: [ERROR] yang-to-sources: Unable to parse yang
files from
/home/vorburger/dev/ODL/git/netvirt/vpnservice/aclservice/impl/src/main/yang
java.util.zip.ZipException: invalid LOC header (bad signature) at
java.util.zip.ZipFile.read(Native Method)

it will now report the much more useful variation like this:
java.io.IOException: Exception when reading from:
/home/vorburger/.m2/repository/org/opendaylight/netvirt/neutronvpn-api/0.3.0-SNAPSHOT/neutronvpn-api-0.3.0-SNAPSHOT.jar::META-INF/yang/neutronvpn.yang
at (...)
Caused by: java.util.zip.ZipException: invalid LOC header (bad
signature)

similar to earlier https://git.opendaylight.org/gerrit/#/c/42193/

Change-Id: Ic5bcdc8597825cdc0506516618ec13ede6433bc7
Signed-off-by: Michael Vorburger <vorburger@redhat.com>
(cherry picked from commit 1d98955b96490bfda3cba04e004c29e00a3e80e6)

yang/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangSourceFromDependency.java
yang/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangSourceFromFile.java
yang/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangSourceInZipFile.java
yang/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangToSourcesProcessor.java

index 6a531534df6331de104fc451adedc1ecf1c18360..009382bfc799311c46c652fe66ad4a0bed2dd619 100644 (file)
@@ -10,4 +10,16 @@ package org.opendaylight.yangtools.yang2sources.plugin;
 import com.google.common.io.ByteSource;
 
 abstract class YangSourceFromDependency extends ByteSource {
+
+    /**
+     * Return a description for this dependency, to be used for error output when
+     * working with the dependency.
+     */
+    abstract String getDescription();
+
+    @Override
+    public final String toString() {
+        return getDescription();
+    }
+
 }
index a5d15e8cead9d9916ac71e349aecb0b1925ea863..4f4992790f8b07354851036a55215c66cccc6ecf 100644 (file)
@@ -33,4 +33,8 @@ class YangSourceFromFile extends YangSourceFromDependency {
         return source.length();
     }
 
+    @Override
+    String getDescription() {
+        return source.getAbsolutePath();
+    }
 }
index eb876f689c01ba6dd1d9a1e2c055305895d20f17..72ba67d4c82ee43ec299c8332115cfa281361b2c 100644 (file)
@@ -32,4 +32,9 @@ class YangSourceInZipFile extends YangSourceFromDependency {
     public InputStream openStream() throws IOException {
         return file.getInputStream(entry);
     }
-}
\ No newline at end of file
+
+    @Override
+    String getDescription() {
+        return file.getName() + "::" + entry.getName();
+    }
+}
index f22b6ee5e31102de32a2b170cfadc51aec81aba3..8ad0e463353a784fccfad75e7f8938420daf4dc7 100644 (file)
@@ -230,6 +230,8 @@ class YangToSourcesProcessor {
             try (InputStream dataStream = yangFromDependency.openStream()) {
                 String contents = IOUtils.toString(dataStream);
                 byContent.putIfAbsent(contents, yangFromDependency);
+            } catch (IOException e) {
+                throw new IOException("Exception when reading from: " + yangFromDependency.getDescription(), e);
             }
 
         }