incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1489484 - in /sling/trunk/contrib/extensions/healthcheck/hc-sling: pom.xml src/main/java/org/apache/sling/hc/sling/impl/JsonResultRendererImpl.java
Date Tue, 04 Jun 2013 15:43:20 GMT
Author: bdelacretaz
Date: Tue Jun  4 15:43:19 2013
New Revision: 1489484

URL: http://svn.apache.org/r1489484
Log:
SLING-2822 - JSON output works

Modified:
    sling/trunk/contrib/extensions/healthcheck/hc-sling/pom.xml
    sling/trunk/contrib/extensions/healthcheck/hc-sling/src/main/java/org/apache/sling/hc/sling/impl/JsonResultRendererImpl.java

Modified: sling/trunk/contrib/extensions/healthcheck/hc-sling/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/healthcheck/hc-sling/pom.xml?rev=1489484&r1=1489483&r2=1489484&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/healthcheck/hc-sling/pom.xml (original)
+++ sling/trunk/contrib/extensions/healthcheck/hc-sling/pom.xml Tue Jun  4 15:43:19 2013
@@ -59,6 +59,14 @@
                     <target>1.6</target>
                 </configuration>
             </plugin>
+            <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>animal-sniffer-maven-plugin</artifactId>
+                <configuration>
+                    <!-- Skip the check for JDK 5 API, causes trouble with commons.json
dependency -->
+                    <skip>true</skip>
+                </configuration>
+            </plugin>
         </plugins>
     </build>
 
@@ -124,6 +132,12 @@
             <artifactId>org.osgi.compendium</artifactId>
             <scope>provided</scope>
         </dependency>
+         <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.commons.json</artifactId>
+            <version>2.0.6</version>
+            <scope>provided</scope>
+        </dependency>
         <dependency>
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-api</artifactId>

Modified: sling/trunk/contrib/extensions/healthcheck/hc-sling/src/main/java/org/apache/sling/hc/sling/impl/JsonResultRendererImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/healthcheck/hc-sling/src/main/java/org/apache/sling/hc/sling/impl/JsonResultRendererImpl.java?rev=1489484&r1=1489483&r2=1489484&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/healthcheck/hc-sling/src/main/java/org/apache/sling/hc/sling/impl/JsonResultRendererImpl.java
(original)
+++ sling/trunk/contrib/extensions/healthcheck/hc-sling/src/main/java/org/apache/sling/hc/sling/impl/JsonResultRendererImpl.java
Tue Jun  4 15:43:19 2013
@@ -23,6 +23,8 @@ import java.util.List;
 
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Service;
+import org.apache.sling.commons.json.JSONException;
+import org.apache.sling.commons.json.io.JSONWriter;
 import org.apache.sling.hc.api.EvaluationResult;
 import org.apache.sling.hc.sling.api.JsonResultRenderer;
 
@@ -35,35 +37,41 @@ public class JsonResultRendererImpl impl
     
     @Override
     public void render(List<EvaluationResult> results, Writer output) throws IOException
{
-        // TODO: trouble with animalsniffer and JSON dependency
-        output.write("TODO: this should be JSON - not implemented yet\n\n");
-        for(EvaluationResult r : results) {
-            output.write(r.getRule().toString());
-            output.write("\n");
-            
-            if(!r.anythingToReport()) {
-                output.write("Rule execution successful, nothing to report\n");
-            } else {
-                output.write("*** WARNING *** Rule has info, warnings or errors, see log
for report\n");
-            }
-            
-            for(EvaluationResult.LogMessage msg : r.getLogMessages()) {
-                output.write("\t");
-                output.write(msg.getLevel().toString());
-                output.write("\t");
-                output.write(msg.getMessage());
-                output.write("\n");
-            }
-            output.write("\n");
-        }
-        /*
         final JSONWriter w = new JSONWriter(output);
+        w.setTidy(true);
         try {
             w.object();
+            w.key("results");
+            w.array();
+            for(EvaluationResult r : results) {
+                w.object();
+                {
+                    w.key("rule").value(r.getRule().toString());
+                    w.key("tags").array();
+                    for(String tag : r.getRule().getTags()) {
+                        w.value(tag);
+                    }
+                    w.endArray();
+                    if(r.anythingToReport()) {
+                        w.key("log").array();
+                        {
+                            for(EvaluationResult.LogMessage msg : r.getLogMessages()) {
+                                w.object();
+                                {
+                                    w.key(msg.getLevel().toString()).value(msg.getMessage());
+                                }
+                                w.endObject();
+                            }
+                        }
+                        w.endArray();
+                    }
+                }
+                w.endObject();
+            }
+            w.endArray();
             w.endObject();
         } catch (JSONException e) {
             throw new IOException(e.getClass().getSimpleName(), e);
         }
-        */
     }
 }



Mime
View raw message