# HG changeset patch # User Simon Tooke # Date 1509457741 14400 # Node ID 76d1ce01cc7aab0491143d75fee97beee73752c7 # Parent dd224447c87d17473b07cd26a556e45a2c09f919 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 diff -r dd224447c87d -r 76d1ce01cc7a common/pom.xml --- 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 @@ com.redhat.thermostat thermostat-common - 0.1.3 + 0.1.4 bundle diff -r dd224447c87d -r 76d1ce01cc7a common/src/main/java/com/redhat/thermostat/common/swaggercombine/SwaggerCombine.java --- 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 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); } } diff -r dd224447c87d -r 76d1ce01cc7a common/src/main/java/com/redhat/thermostat/common/swaggercombine/SwaggerCombineMain.java --- 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