From 29e3f1843c91797df287e34ce81538f3d41ff5b2 Mon Sep 17 00:00:00 2001 From: Kalle Stenflo Date: Wed, 8 Oct 2014 10:54:39 +0200 Subject: [PATCH] Added build info to web test client. --- build.gradle | 1 + json-path-web-test/build.gradle | 14 ++++++-- .../jsonpath/web/resource/ApiResource.java | 32 ++++++++++++++----- .../src/main/resources/webapp/index.html | 11 +++++-- 4 files changed, 46 insertions(+), 12 deletions(-) diff --git a/build.gradle b/build.gradle index 046096cd..106e9fbb 100644 --- a/build.gradle +++ b/build.gradle @@ -24,6 +24,7 @@ ext { allprojects { ext.displayName = null + ext.buildTimestamp = new Date().format('yyyy-MM-dd HH:mm:ss') group = 'com.jayway.jsonpath' version = '1.1.1' + (snapshotVersion ? "-SNAPSHOT" : "") diff --git a/json-path-web-test/build.gradle b/json-path-web-test/build.gradle index d97df837..352d1d14 100644 --- a/json-path-web-test/build.gradle +++ b/json-path-web-test/build.gradle @@ -1,13 +1,22 @@ apply plugin: 'shadow' apply plugin: 'application' -displayName = "JsonPath Tets Bench" +displayName = "JsonPath Test Bench" description = "Web app that compares different JsonPath implementations." mainClassName = 'com.jayway.jsonpath.web.boot.Main' +task createBuildInfoFile << { + def buildInfoFile = new File("$buildDir/classes/main/build-info.properties") + Properties props = new Properties() + props.setProperty('version', project.version.toString()) + props.setProperty('timestamp', project.buildTimestamp) + props.store(buildInfoFile.newWriter(), null) +} + jar { + dependsOn createBuildInfoFile baseName 'json-path-web-test' manifest { attributes 'Implementation-Title': 'json-path-web-test', @@ -16,6 +25,7 @@ jar { } } + dependencies { compile project(':json-path') compile 'commons-io:commons-io:2.4' @@ -30,4 +40,4 @@ dependencies { exclude module: 'jackson-annotations:com.fasterxml.jackson.core' exclude module: 'jackson-core:com.fasterxml.jackson.core' } -} \ No newline at end of file +} diff --git a/json-path-web-test/src/main/java/com/jayway/jsonpath/web/resource/ApiResource.java b/json-path-web-test/src/main/java/com/jayway/jsonpath/web/resource/ApiResource.java index b858d5ad..fa6a0433 100644 --- a/json-path-web-test/src/main/java/com/jayway/jsonpath/web/resource/ApiResource.java +++ b/json-path-web-test/src/main/java/com/jayway/jsonpath/web/resource/ApiResource.java @@ -17,7 +17,9 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.util.Collections; +import java.util.HashMap; import java.util.Map; +import java.util.ResourceBundle; @Path("/") @Produces(MediaType.TEXT_HTML) @@ -25,16 +27,31 @@ public class ApiResource { private static final Logger logger = LoggerFactory.getLogger(ApiResource.class); + @GET + @Path("/info") + @Produces(MediaType.APPLICATION_JSON) + public Response info() { + Map result = new HashMap(); + try { + ResourceBundle resource = ResourceBundle.getBundle("build-info"); + result.put("version", resource.getString("version")); + result.put("timestamp", resource.getString("timestamp")); + } catch (Exception e){ + result.put("version", "LOCAL"); + result.put("timestamp", "NOW"); + } + return Response.ok(result).build(); + } @GET @Path("/validate") @Produces(MediaType.APPLICATION_JSON) - public Response validate(@QueryParam("path") String path){ + public Response validate(@QueryParam("path") String path) { int result = -1; try { JsonPath compiled = JsonPath.compile(path); - result = compiled.isDefinite()?0:1; - } catch (Exception e){ + result = compiled.isDefinite() ? 0 : 1; + } catch (Exception e) { } return Response.ok(Collections.singletonMap("result", result)).build(); } @@ -47,10 +64,10 @@ public class ApiResource { public Response getTemplate(@FormParam("json") String json, @FormParam("path") String path, @FormParam("type") String type, - @FormParam("flagWrap") boolean flagWrap, - @FormParam("flagNullLeaf") boolean flagNullLeaf, - @FormParam("flagSuppress") boolean flagSuppress, - @FormParam("flagRequireProps") boolean flagRequireProps){ + @FormParam("flagWrap") boolean flagWrap, + @FormParam("flagNullLeaf") boolean flagNullLeaf, + @FormParam("flagSuppress") boolean flagSuppress, + @FormParam("flagRequireProps") boolean flagRequireProps) { boolean value = "VALUE".equalsIgnoreCase(type); @@ -60,5 +77,4 @@ public class ApiResource { } - } diff --git a/json-path-web-test/src/main/resources/webapp/index.html b/json-path-web-test/src/main/resources/webapp/index.html index 7b35974c..e1ef5ca3 100644 --- a/json-path-web-test/src/main/resources/webapp/index.html +++ b/json-path-web-test/src/main/resources/webapp/index.html @@ -16,7 +16,10 @@
-

Jayway JsonPath evaluator

+

Jayway JsonPath Evaluator

+
+  -  +
@@ -211,6 +214,11 @@ } $( document ).ready(function() { + $.get('/api/info', function(data) { + $("#version").text(data.version); + $("#timestamp").text(data.timestamp); + }); + $('#path-status-tool').tooltip({ container: 'body', delay: 0 @@ -288,7 +296,6 @@ success: function(data) { $('#jayway-time').text(data.jayway.time); - //$('#jayway-res').hide().text(data.jayway.result).fadeIn(); $('#jayway-res').hide().empty(); if(data.jayway.error){ $('#jayway-error').text(data.jayway.error).show();