changeset 35:76d1ce01cc7a default tip master

Fail build on YAML lint error This patch will cause SwaggerCombine to throw an exception if "--throw" is specified on the command line and there is a lint error in the YAML files. Currently there are no such messages. Reviewed-by: neugens Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2017-October/025574.html
author Simon Tooke <stooke@redhat.com>
date Tue, 31 Oct 2017 09:49:01 -0400
parents dd224447c87d
children
files common/pom.xml common/src/main/java/com/redhat/thermostat/common/swaggercombine/SwaggerCombine.java common/src/main/java/com/redhat/thermostat/common/swaggercombine/SwaggerCombineMain.java
diffstat 3 files changed, 18 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/common/pom.xml	Fri Oct 27 13:27:00 2017 -0400
+++ b/common/pom.xml	Tue Oct 31 09:49:01 2017 -0400
@@ -6,7 +6,7 @@
 
     <groupId>com.redhat.thermostat</groupId>
     <artifactId>thermostat-common</artifactId>
-    <version>0.1.3</version>
+    <version>0.1.4</version>
     <packaging>bundle</packaging>
 
     <!-- required for uploading to Maven Central -->
--- a/common/src/main/java/com/redhat/thermostat/common/swaggercombine/SwaggerCombine.java	Fri Oct 27 13:27:00 2017 -0400
+++ b/common/src/main/java/com/redhat/thermostat/common/swaggercombine/SwaggerCombine.java	Tue Oct 31 09:49:01 2017 -0400
@@ -53,6 +53,7 @@
 import com.google.gson.JsonElement;
 import com.google.gson.JsonObject;
 import com.google.gson.JsonParser;
+
 import com.redhat.thermostat.common.json.JsonUtil;
 import com.redhat.thermostat.common.yaml.JsonToYaml;
 import com.redhat.thermostat.common.yaml.RefResolver;
@@ -65,6 +66,7 @@
 
     private Gson gson = null;
     private Gson prettyGson = null;
+    private int lintCount = 0;
 
     private static final String SWAGGER_TEMPLATE = "/swagger-template.json";
 
@@ -95,6 +97,14 @@
         return processAPIs(ctx.getAPIList(), ctx.isQuiet(), ctx.isUseTemplate(), ctx.isLint());
     }
 
+    /**
+     * return number of lint messages
+     * @return number of lint messages
+     */
+    public int getLintCount() {
+        return lintCount;
+    }
+
     private void writeObject(JsonObject root, Writer out, boolean toYaml, boolean pretty) throws IOException {
 
         if (root != null) {
@@ -164,6 +174,7 @@
             RefResolver.resolveRefs(in, copy);
         } catch (IOException e) {
             // exceptiuon here means there were issues
+            lintCount++;
             System.err.println("lint: " + e.getMessage());
         }
         // TODO: test for mandatory elements
@@ -248,6 +259,7 @@
         JsonObject dest = destroot.getAsJsonObject(name);
         for (final Map.Entry<String, JsonElement> entry : src.entrySet()) {
             if (entry.getKey() == null) {
+                lintCount++;
                 error("key is null");
             }
             if (dest.has(entry.getKey())) {
@@ -353,6 +365,7 @@
     }
 
     protected void error(String msg) {
+        lintCount++;
         System.err.println("error: " + msg);
     }
 }
--- a/common/src/main/java/com/redhat/thermostat/common/swaggercombine/SwaggerCombineMain.java	Fri Oct 27 13:27:00 2017 -0400
+++ b/common/src/main/java/com/redhat/thermostat/common/swaggercombine/SwaggerCombineMain.java	Tue Oct 31 09:49:01 2017 -0400
@@ -68,6 +68,10 @@
                 combine.run(ctx, out);
                 out.close();
             }
+            if (combine.getLintCount() > 0 && ctx.isThrowExceptions()) {
+                System.err.println(combine.getLintCount() + " lint warnings were output");
+                throw new IOException("Lint issues found");
+            }
         } catch (Exception e) {
             // there's a chance the exception was thrown while parsing arguments,
             // but before parsing any '--throw'.  Run a quick check