[json-lib] Build jenkins-json-lib artifact

Michal Srb msrb at fedoraproject.org
Wed Feb 12 16:27:26 UTC 2014


commit 32f0f6dfa94ea0147d6695f81008b375ac28863d
Author: Michal Srb <msrb at redhat.com>
Date:   Wed Feb 12 16:59:16 2014 +0100

    Build jenkins-json-lib artifact

 .gitignore                                         |    1 +
 ...sing-JsonConfig-used-for-property-setting.patch |   64 ++
 ...ds-to-write-out-JSON-in-the-canonical-for.patch |  690 ++++++++++++++++++++
 json-lib.spec                                      |   49 ++-
 sources                                            |    1 +
 5 files changed, 803 insertions(+), 2 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index aa795e6..900d16b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
 json-lib-2.3.tar.gz
 /json-lib-2.4.tar.xz
+/json-lib-2.4-jenkins-3.pom
diff --git a/json-lib-2.4-Exposing-JsonConfig-used-for-property-setting.patch b/json-lib-2.4-Exposing-JsonConfig-used-for-property-setting.patch
new file mode 100644
index 0000000..7694944
--- /dev/null
+++ b/json-lib-2.4-Exposing-JsonConfig-used-for-property-setting.patch
@@ -0,0 +1,64 @@
+From a875167a8bc6b2d04e6aee9a9927e83b0f2e2922 Mon Sep 17 00:00:00 2001
+From: Kohsuke Kawaguchi <kk at kohsuke.org>
+Date: Tue, 5 Mar 2013 15:19:15 -0800
+Subject: [PATCH 2/2] Exposing JsonConfig used for property setting.
+
+JsonConfig change the way the value is mangled, so this allows the
+caller of the builder to tweak the behaviour.
+
+(The reason I needed this change was because I use different default
+values for some of the JsonConfig options, and this allows me to keep
+tests happy with minimal modification. That said, I think this feature
+makes sense on its own.)
+---
+ src/main/java/net/sf/json/groovy/JsonGroovyBuilder.java | 15 +++++++++++++--
+ 1 file changed, 13 insertions(+), 2 deletions(-)
+
+diff --git a/src/main/java/net/sf/json/groovy/JsonGroovyBuilder.java b/src/main/java/net/sf/json/groovy/JsonGroovyBuilder.java
+index a72392a..a632b97 100644
+--- a/src/main/java/net/sf/json/groovy/JsonGroovyBuilder.java
++++ b/src/main/java/net/sf/json/groovy/JsonGroovyBuilder.java
+@@ -32,6 +32,7 @@ import net.sf.json.JSONArray;
+ import net.sf.json.JSONException;
+ import net.sf.json.JSONObject;
+ import net.sf.json.JSONSerializer;
++import net.sf.json.JsonConfig;
+ 
+ /**
+  * A Groovy builder for JSON values.
+@@ -111,10 +112,20 @@ public class JsonGroovyBuilder extends GroovyObjectSupport {
+    private JSON current;
+    private Map properties;
+    private Stack stack;
++   private JsonConfig jsonConfig;
+ 
+    public JsonGroovyBuilder() {
+       stack = new Stack();
+       properties = new HashMap();
++      jsonConfig = new JsonConfig();
++   }
++
++   public JsonConfig getJsonConfig() {
++      return jsonConfig;
++   }
++
++   public void setJsonConfig(JsonConfig jsonConfig) {
++      this.jsonConfig = jsonConfig;
+    }
+ 
+    public Object getProperty( String name ) {
+@@ -225,9 +236,9 @@ public class JsonGroovyBuilder extends GroovyObjectSupport {
+ 
+    private void _append( String key, Object value, JSON target ) {
+       if( target instanceof JSONObject ){
+-         ((JSONObject) target).accumulate( key, value );
++         ((JSONObject) target).accumulate( key, value, jsonConfig );
+       }else if( target instanceof JSONArray ){
+-         ((JSONArray) target).element( value );
++         ((JSONArray) target).element( value, jsonConfig );
+       }
+    }
+ 
+-- 
+1.8.5.3
+
diff --git a/json-lib-2.4-added-methods-to-write-out-JSON-in-the-canonical-for.patch b/json-lib-2.4-added-methods-to-write-out-JSON-in-the-canonical-for.patch
new file mode 100644
index 0000000..272d472
--- /dev/null
+++ b/json-lib-2.4-added-methods-to-write-out-JSON-in-the-canonical-for.patch
@@ -0,0 +1,690 @@
+From 93082f907e72ccb5776bea0a3cf2d854f9e458bf Mon Sep 17 00:00:00 2001
+From: Kohsuke Kawaguchi <kk at kohsuke.org>
+Date: Mon, 10 Oct 2011 14:00:09 +0900
+Subject: [PATCH 1/2] added methods to write out JSON in the 'canonical' form
+
+---
+ src/main/java/net/sf/json/AbstractJSON.java     | 52 +++++++++++++-
+ src/main/java/net/sf/json/JSON.java             |  8 ++-
+ src/main/java/net/sf/json/JSONArray.java        | 20 ++----
+ src/main/java/net/sf/json/JSONNull.java         | 14 ++--
+ src/main/java/net/sf/json/JSONObject.java       | 51 ++++++--------
+ src/main/java/net/sf/json/util/JSONUtils.java   | 68 +++++++++++++++----
+ src/main/jdk15/net/sf/json/JSONArray.java       | 90 ++++++++++---------------
+ src/main/jdk15/net/sf/json/JSONObject.java      | 25 +++----
+ src/test/java/net/sf/json/AbstractJSONTest.java |  2 +-
+ src/test/java/net/sf/json/TestJSONArray.java    |  3 +-
+ src/test/java/net/sf/json/TestJSONObject.java   | 21 ++++++
+ 11 files changed, 218 insertions(+), 136 deletions(-)
+
+diff --git a/src/main/java/net/sf/json/AbstractJSON.java b/src/main/java/net/sf/json/AbstractJSON.java
+index 6bee743..28ba210 100644
+--- a/src/main/java/net/sf/json/AbstractJSON.java
++++ b/src/main/java/net/sf/json/AbstractJSON.java
+@@ -16,10 +16,14 @@
+ 
+ package net.sf.json;
+ 
++import java.io.IOException;
++import java.io.Writer;
+ import java.lang.ref.SoftReference;
++import java.util.Collection;
+ import java.util.HashSet;
+ import java.util.Iterator;
+ import java.util.Set;
++import java.util.TreeSet;
+ 
+ import net.sf.json.util.JSONUtils;
+ import net.sf.json.util.JsonEventListener;
+@@ -32,7 +36,7 @@ import org.apache.commons.logging.LogFactory;
+  *
+  * @author Andres Almiray <aalmiray at users.sourceforge.net>
+  */
+-abstract class AbstractJSON {
++abstract class AbstractJSON implements JSON {
+    private static class CycleSet extends ThreadLocal {
+       protected Object initialValue() {
+          return new SoftReference(new HashSet());
+@@ -283,4 +287,50 @@ abstract class AbstractJSON {
+    private static Set getCycleSet() {
+       return cycleSet.getSet();
+    }
++
++    public final Writer write(Writer writer) throws IOException {
++        write(writer,NORMAL);
++        return writer;
++    }
++
++    public final Writer writeCanonical(Writer writer) throws IOException {
++        write(writer,CANONICAL);
++        return writer;
++    }
++
++    protected abstract void write(Writer w, WritingVisitor v) throws IOException;
++
++    interface WritingVisitor {
++        Collection keySet(JSONObject o);
++        void on(JSON o, Writer w) throws IOException;
++        void on(Object value, Writer w) throws IOException;
++    }
++
++    private static final WritingVisitor NORMAL = new WritingVisitor() {
++        public Collection keySet(JSONObject o) {
++            return o.keySet();
++        }
++
++        public void on(JSON o, Writer w) throws IOException {
++            o.write(w);
++        }
++
++        public void on(Object value, Writer w) throws IOException {
++            w.write(JSONUtils.valueToString(value));
++        }
++    };
++
++    private static final WritingVisitor CANONICAL = new WritingVisitor() {
++        public Collection keySet(JSONObject o) {
++            return new TreeSet(o.keySet()); // sort them alphabetically
++        }
++
++        public void on(JSON o, Writer w) throws IOException {
++            o.writeCanonical(w);
++        }
++
++        public void on(Object value, Writer w) throws IOException {
++            w.write(JSONUtils.valueToCanonicalString(value));
++        }
++    };
+ }
+\ No newline at end of file
+diff --git a/src/main/java/net/sf/json/JSON.java b/src/main/java/net/sf/json/JSON.java
+index 836cae5..6c26e98 100644
+--- a/src/main/java/net/sf/json/JSON.java
++++ b/src/main/java/net/sf/json/JSON.java
+@@ -15,6 +15,7 @@
+  */
+ package net.sf.json;
+ 
++import java.io.IOException;
+ import java.io.Writer;
+ import java.io.Serializable;
+ 
+@@ -85,5 +86,10 @@ public interface JSON extends Serializable {
+     * @return The writer.
+     * @throws JSONException
+     */
+-   Writer write( Writer writer );
++   Writer write( Writer writer ) throws IOException;
++
++    /**
++     * Writes the canonicalized form of this JSON object.
++     */
++    Writer writeCanonical(Writer w) throws IOException;
+ }
+\ No newline at end of file
+diff --git a/src/main/java/net/sf/json/JSONArray.java b/src/main/java/net/sf/json/JSONArray.java
+index 52b290f..81241ee 100644
+--- a/src/main/java/net/sf/json/JSONArray.java
++++ b/src/main/java/net/sf/json/JSONArray.java
+@@ -2281,16 +2281,7 @@ public final class JSONArray extends AbstractJSON implements JSON, List, Compara
+       return sb.toString();
+    }
+ 
+-   /**
+-    * Write the contents of the JSONArray as JSON text to a writer. For
+-    * compactness, no whitespace is added.
+-    * <p>
+-    * Warning: This method assumes that the data structure is acyclical.
+-    *
+-    * @return The writer.
+-    * @throws JSONException
+-    */
+-   public Writer write( Writer writer ) {
++   protected void write(Writer writer, WritingVisitor visitor) throws IOException {
+       try{
+          boolean b = false;
+          int len = size();
+@@ -2302,17 +2293,14 @@ public final class JSONArray extends AbstractJSON implements JSON, List, Compara
+                writer.write( ',' );
+             }
+             Object v = this.elements.get( i );
+-            if( v instanceof JSONObject ){
+-               ((JSONObject) v).write( writer );
+-            }else if( v instanceof JSONArray ){
+-               ((JSONArray) v).write( writer );
++            if( v instanceof JSON ){
++               visitor.on( (JSON) v, writer );
+             }else{
+-               writer.write( JSONUtils.valueToString( v ) );
++               visitor.on( v, writer );
+             }
+             b = true;
+          }
+          writer.write( ']' );
+-         return writer;
+       }catch( IOException e ){
+          throw new JSONException( e );
+       }
+diff --git a/src/main/java/net/sf/json/JSONNull.java b/src/main/java/net/sf/json/JSONNull.java
+index 30b0a06..0c74c4d 100644
+--- a/src/main/java/net/sf/json/JSONNull.java
++++ b/src/main/java/net/sf/json/JSONNull.java
+@@ -95,12 +95,12 @@ public final class JSONNull implements JSON {
+       return sb.toString();
+    }
+ 
+-   public Writer write( Writer writer ) {
+-      try{
+-         writer.write( toString() );
+-         return writer;
+-      }catch( IOException e ){
+-         throw new JSONException( e );
+-      }
++   public Writer write( Writer writer ) throws IOException {
++       writer.write( toString() );
++       return writer;
+    }
++
++    public Writer writeCanonical(Writer w) throws IOException {
++        return write(w);
++    }
+ }
+\ No newline at end of file
+diff --git a/src/main/java/net/sf/json/JSONObject.java b/src/main/java/net/sf/json/JSONObject.java
+index be3243f..f06dafc 100644
+--- a/src/main/java/net/sf/json/JSONObject.java
++++ b/src/main/java/net/sf/json/JSONObject.java
+@@ -2510,40 +2510,31 @@ public final class JSONObject extends AbstractJSON implements JSON, Map, Compara
+     * @return The writer.
+     * @throws JSONException
+     */
+-   public Writer write( Writer writer ) {
+-      try{
+-         if( isNullObject() ){
+-            writer.write( JSONNull.getInstance()
+-                  .toString() );
+-            return writer;
+-         }
++   protected void write(Writer writer, WritingVisitor visitor) throws IOException {
++      if( isNullObject() ){
++         writer.write(JSONNull.getInstance().toString());
++      }
+ 
+-         boolean b = false;
+-         Iterator keys = keys();
+-         writer.write( '{' );
++      boolean b = false;
++      Iterator keys = visitor.keySet(this).iterator();
++      writer.write('{');
+ 
+-         while( keys.hasNext() ){
+-            if( b ){
+-               writer.write( ',' );
+-            }
+-            Object k = keys.next();
+-            writer.write( JSONUtils.quote( k.toString() ) );
+-            writer.write( ':' );
+-            Object v = this.properties.get( k );
+-            if( v instanceof JSONObject ){
+-               ((JSONObject) v).write( writer );
+-            }else if( v instanceof JSONArray ){
+-               ((JSONArray) v).write( writer );
+-            }else{
+-               writer.write( JSONUtils.valueToString( v ) );
+-            }
+-            b = true;
++      while( keys.hasNext() ){
++         if( b ){
++            writer.write(',');
+          }
+-         writer.write( '}' );
+-         return writer;
+-      }catch( IOException e ){
+-         throw new JSONException( e );
++         Object k = keys.next();
++         writer.write(JSONUtils.quote(k.toString()));
++         writer.write(':');
++         Object v = this.properties.get(k);
++         if( v instanceof JSON ){
++            visitor.on((JSON) v, writer);
++         }else{
++            visitor.on(v, writer);
++         }
++         b = true;
+       }
++      writer.write('}');
+    }
+ 
+    private JSONObject _accumulate( String key, Object value, JsonConfig jsonConfig ) {
+diff --git a/src/main/java/net/sf/json/util/JSONUtils.java b/src/main/java/net/sf/json/util/JSONUtils.java
+index 897e42f..77ceece 100644
+--- a/src/main/java/net/sf/json/util/JSONUtils.java
++++ b/src/main/java/net/sf/json/util/JSONUtils.java
+@@ -548,7 +548,41 @@ public final class JSONUtils {
+       return sb.toString();
+    }
+ 
+-   /**
++    /**
++     * Minimal escape form.
++     */
++    public static String quoteCanonical(String s) {
++        if (s == null || s.length() == 0) {
++            return "\"\"";
++        }
++
++        int len = s.length();
++        StringBuilder sb = new StringBuilder(len + 4);
++
++        sb.append('"');
++        for (int i = 0; i < len; i += 1) {
++            char c = s.charAt(i);
++            switch (c) {
++            case '\\':
++            case '"':
++                sb.append('\\');
++                sb.append(c);
++                break;
++            default:
++                if (c < ' ') {
++                    String t = "000" + Integer.toHexString(c);
++                    sb.append("\\u")
++                            .append(t.substring(t.length() - 4));
++                } else {
++                    sb.append(c);
++                }
++            }
++        }
++        sb.append('"');
++        return sb.toString();
++    }
++
++    /**
+     * Strips any single-quotes or double-quotes from both sides of the string.
+     */
+    public static String stripQuotes( String input ) {
+@@ -653,16 +687,7 @@ public final class JSONUtils {
+          return ((JSONFunction) value).toString();
+       }
+       if( value instanceof JSONString ){
+-         Object o;
+-         try{
+-            o = ((JSONString) value).toJSONString();
+-         }catch( Exception e ){
+-            throw new JSONException( e );
+-         }
+-         if( o instanceof String ){
+-            return (String) o;
+-         }
+-         throw new JSONException( "Bad value from toJSONString: " + o );
++          return ((JSONString) value).toJSONString();
+       }
+       if( value instanceof Number ){
+          return numberToString( (Number) value );
+@@ -673,6 +698,25 @@ public final class JSONUtils {
+       return quote( value.toString() );
+    }
+ 
++    public static String valueToCanonicalString( Object value ) {
++       if( value == null || isNull( value ) ){
++          return "null";
++       }
++       if( value instanceof JSONFunction ){
++          return value.toString(); // there's really no canonical form for functions
++       }
++       if( value instanceof JSONString ){
++           return ((JSONString) value).toJSONString();
++       }
++       if( value instanceof Number ){
++          return numberToString( (Number) value ).toLowerCase();
++       }
++       if( value instanceof Boolean || value instanceof JSONObject || value instanceof JSONArray ){
++          return value.toString();
++       }
++       return quoteCanonical(value.toString());
++    }
++
+    /**
+     * Make a prettyprinted JSON text of an object value.
+     * <p>
+@@ -692,7 +736,7 @@ public final class JSONUtils {
+          return "null";
+       }
+       if( value instanceof JSONFunction ){
+-         return ((JSONFunction) value).toString();
++         return value.toString();
+       }
+       if( value instanceof JSONString ){
+          return ((JSONString) value).toJSONString();
+diff --git a/src/main/jdk15/net/sf/json/JSONArray.java b/src/main/jdk15/net/sf/json/JSONArray.java
+index 81c89c5..c97a040 100644
+--- a/src/main/jdk15/net/sf/json/JSONArray.java
++++ b/src/main/jdk15/net/sf/json/JSONArray.java
+@@ -91,7 +91,7 @@ import org.apache.commons.lang.StringUtils;
+  *
+  * @author JSON.org
+  */
+-public final class JSONArray extends AbstractJSON implements JSON, List, Comparable {
++public final class JSONArray extends AbstractJSON implements JSON, List<Object>, Comparable {
+    /**
+     * Creates a JSONArray.<br>
+     * Inspects the object type to call the correct JSONArray factory method.
+@@ -791,7 +791,7 @@ public final class JSONArray extends AbstractJSON implements JSON, List, Compara
+       JSONArray jsonArray = new JSONArray();
+       try{
+          for( int i = 0; i < array.length; i++ ){
+-            Double d = new Double( array[i] );
++            Double d = array[i];
+             JSONUtils.testValidity( d );
+             jsonArray.addValue( d, jsonConfig );
+             fireElementAddedEvent( i, d, jsonConfig );
+@@ -871,7 +871,7 @@ public final class JSONArray extends AbstractJSON implements JSON, List, Compara
+       JSONArray jsonArray = new JSONArray();
+       try{
+          for( int i = 0; i < array.length; i++ ){
+-            Float f = new Float( array[i] );
++            Float f = array[i];
+             JSONUtils.testValidity( f );
+             jsonArray.addValue( f, jsonConfig );
+             fireElementAddedEvent( i, f, jsonConfig );
+@@ -1199,11 +1199,11 @@ public final class JSONArray extends AbstractJSON implements JSON, List, Compara
+ 
+    private static void processArrayDimensions( JSONArray jsonArray, List dims, int index ) {
+       if( dims.size() <= index ){
+-         dims.add( new Integer( jsonArray.size() ) );
++         dims.add(jsonArray.size());
+       }else{
+          int i = ((Integer) dims.get( index )).intValue();
+          if( jsonArray.size() > i ){
+-            dims.set( index, new Integer( jsonArray.size() ) );
++            dims.set( index, jsonArray.size());
+          }
+       }
+       for( Iterator i = jsonArray.iterator(); i.hasNext(); ){
+@@ -1219,7 +1219,7 @@ public final class JSONArray extends AbstractJSON implements JSON, List, Compara
+    /**
+     * The List where the JSONArray's properties are kept.
+     */
+-   private List elements;
++   private List<Object> elements;
+ 
+    /**
+     * A flag for XML processing.
+@@ -1230,7 +1230,7 @@ public final class JSONArray extends AbstractJSON implements JSON, List, Compara
+     * Construct an empty JSONArray.
+     */
+    public JSONArray() {
+-      this.elements = new ArrayList();
++      this.elements = new ArrayList<Object>();
+    }
+ 
+    public void add( int index, Object value ) {
+@@ -1258,9 +1258,9 @@ public final class JSONArray extends AbstractJSON implements JSON, List, Compara
+       if( collection == null || collection.size() == 0 ){
+          return false;
+       }
+-      for( Iterator i = collection.iterator(); i.hasNext(); ){
+-         element( i.next(), jsonConfig );
+-      }
++       for (Object a : collection) {
++           element(a, jsonConfig);
++       }
+       return true;
+    }
+ 
+@@ -1273,9 +1273,9 @@ public final class JSONArray extends AbstractJSON implements JSON, List, Compara
+          return false;
+       }
+       int offset = 0;
+-      for( Iterator i = collection.iterator(); i.hasNext(); ){
+-         this.elements.add( index + (offset++), processValue( i.next(), jsonConfig ) );
+-      }
++       for (Object a : collection) {
++           this.elements.add(index + (offset++), processValue(a, jsonConfig));
++       }
+       return true;
+    }
+ 
+@@ -1382,7 +1382,7 @@ public final class JSONArray extends AbstractJSON implements JSON, List, Compara
+     * @return this.
+     */
+    public JSONArray element( double value ) {
+-      Double d = new Double( value );
++      Double d = value;
+       JSONUtils.testValidity( d );
+       return element( d );
+    }
+@@ -1670,7 +1670,7 @@ public final class JSONArray extends AbstractJSON implements JSON, List, Compara
+     * @return this.
+     */
+    public JSONArray element( long value ) {
+-      return element( JSONUtils.transformNumber( new Long( value ) ) );
++      return element( JSONUtils.transformNumber(value) );
+    }
+ 
+    /**
+@@ -2441,44 +2441,28 @@ public final class JSONArray extends AbstractJSON implements JSON, List, Compara
+       return sb.toString();
+    }
+ 
+-   /**
+-    * Write the contents of the JSONArray as JSON text to a writer. For
+-    * compactness, no whitespace is added.
+-    * <p>
+-    * Warning: This method assumes that the data structure is acyclical.
+-    *
+-    * @return The writer.
+-    * @throws JSONException
+-    */
+-   public Writer write( Writer writer ) {
+-      try{
+-         boolean b = false;
+-         int len = size();
+-
+-         writer.write( '[' );
+-
+-         for( int i = 0; i < len; i += 1 ){
+-            if( b ){
+-               writer.write( ',' );
+-            }
+-            Object v = this.elements.get( i );
+-            if( v instanceof JSONObject ){
+-               ((JSONObject) v).write( writer );
+-            }else if( v instanceof JSONArray ){
+-               ((JSONArray) v).write( writer );
+-            }else{
+-               writer.write( JSONUtils.valueToString( v ) );
+-            }
+-            b = true;
+-         }
+-         writer.write( ']' );
+-         return writer;
+-      }catch( IOException e ){
+-         throw new JSONException( e );
+-      }
+-   }
+-
+-   /**
++    protected void write(Writer writer, WritingVisitor visitor) throws IOException {
++        boolean b = false;
++        int len = size();
++
++        writer.write( '[' );
++
++        for( int i = 0; i < len; i += 1 ){
++           if( b ){
++              writer.write( ',' );
++           }
++           Object v = this.elements.get( i );
++           if( v instanceof JSON ){
++               visitor.on((JSON)v,writer);
++           }else{
++               visitor.on(v,writer);
++           }
++           b = true;
++        }
++        writer.write( ']' );
++    }
++
++    /**
+     * Adds a String without performing any conversion on it.
+     */
+    protected JSONArray addString( String str ) {
+diff --git a/src/main/jdk15/net/sf/json/JSONObject.java b/src/main/jdk15/net/sf/json/JSONObject.java
+index f328d00..0d92a38 100644
+--- a/src/main/jdk15/net/sf/json/JSONObject.java
++++ b/src/main/jdk15/net/sf/json/JSONObject.java
+@@ -34,6 +34,7 @@ import java.util.LinkedHashSet;
+ import java.util.List;
+ import java.util.Map;
+ import java.util.Set;
++import java.util.TreeMap;
+ 
+ import net.sf.ezmorph.Morpher;
+ import net.sf.ezmorph.array.ObjectArrayMorpher;
+@@ -116,7 +117,7 @@ import org.apache.commons.logging.LogFactory;
+  *
+  * @author JSON.org
+  */
+-public final class JSONObject extends AbstractJSON implements JSON, Map, Comparable {
++public final class JSONObject extends AbstractJSON implements JSON, Map<String,Object>, Comparable {
+ 
+    private static final Log log = LogFactory.getLog( JSONObject.class );
+ 
+@@ -526,9 +527,9 @@ public final class JSONObject extends AbstractJSON implements JSON, Map, Compara
+                               .morph( Array.newInstance( innerType, 0 )
+                                     .getClass(), array );
+                      }else if( !array.getClass()
+-                           .equals( pd.getPropertyType() ) ){
++                           .equals(pd.getPropertyType()) ){
+                         if( !pd.getPropertyType()
+-                              .equals( Object.class ) ){
++                              .equals(Object.class) ){
+                            Morpher morpher = JSONUtils.getMorpherRegistry()
+                                  .getMorpherFor( Array.newInstance( innerType, 0 )
+                                        .getClass() );
+@@ -2372,7 +2373,7 @@ public final class JSONObject extends AbstractJSON implements JSON, Map, Compara
+       return o != null ? o.toString() : defaultValue;
+    }
+ 
+-   public Object put( Object key, Object value ) {
++   public Object put( String key, Object value ) {
+       if( key == null ){
+          throw new IllegalArgumentException( "key is null." );
+       }
+@@ -2590,16 +2591,15 @@ public final class JSONObject extends AbstractJSON implements JSON, Map, Compara
+     * @return The writer.
+     * @throws JSONException
+     */
+-   public Writer write( Writer writer ) {
++   protected void write(Writer writer, WritingVisitor visitor) throws IOException {
+       try{
+          if( isNullObject() ){
+             writer.write( JSONNull.getInstance()
+-                  .toString() );
+-            return writer;
++                  .toString());
+          }
+ 
+          boolean b = false;
+-         Iterator keys = keys();
++         Iterator keys = visitor.keySet(this).iterator();
+          writer.write( '{' );
+ 
+          while( keys.hasNext() ){
+@@ -2610,17 +2610,14 @@ public final class JSONObject extends AbstractJSON implements JSON, Map, Compara
+             writer.write( JSONUtils.quote( k.toString() ) );
+             writer.write( ':' );
+             Object v = this.properties.get( k );
+-            if( v instanceof JSONObject ){
+-               ((JSONObject) v).write( writer );
+-            }else if( v instanceof JSONArray ){
+-               ((JSONArray) v).write( writer );
++            if( v instanceof JSON ){
++               visitor.on( (JSON) v, writer );
+             }else{
+-               writer.write( JSONUtils.valueToString( v ) );
++               visitor.on( v, writer );
+             }
+             b = true;
+          }
+          writer.write( '}' );
+-         return writer;
+       }catch( IOException e ){
+          throw new JSONException( e );
+       }
+diff --git a/src/test/java/net/sf/json/AbstractJSONTest.java b/src/test/java/net/sf/json/AbstractJSONTest.java
+index da59936..3ee639b 100644
+--- a/src/test/java/net/sf/json/AbstractJSONTest.java
++++ b/src/test/java/net/sf/json/AbstractJSONTest.java
+@@ -52,7 +52,7 @@ public abstract class AbstractJSONTest extends TestCase {
+       assertEquals( expected, json.toString( getIndentFactor(), getIndent() ) );
+    }
+ 
+-   public void testWrite() {
++   public void testWrite() throws Exception {
+       StringWriter w = new StringWriter();
+       String expected = (String) getWriteExpectations()[0];
+       JSON json = (JSON) getWriteExpectations()[1];
+diff --git a/src/test/java/net/sf/json/TestJSONArray.java b/src/test/java/net/sf/json/TestJSONArray.java
+index dd33532..fb86346 100644
+--- a/src/test/java/net/sf/json/TestJSONArray.java
++++ b/src/test/java/net/sf/json/TestJSONArray.java
+@@ -16,6 +16,7 @@
+ package net.sf.json;
+ 
+ import java.io.StringWriter;
++import java.io.IOException;
+ import java.math.BigDecimal;
+ import java.math.BigInteger;
+ import java.util.ArrayList;
+@@ -1442,7 +1443,7 @@ public class TestJSONArray extends TestCase {
+       Assertions.assertEquals( expected, actual );
+    }
+ 
+-   public void testWrite() {
++   public void testWrite() throws IOException {
+       JSONArray jsonArray = JSONArray.fromObject( "[[],{},1,true,\"json\"]" );
+       StringWriter sw = new StringWriter();
+       jsonArray.write( sw );
+diff --git a/src/test/java/net/sf/json/TestJSONObject.java b/src/test/java/net/sf/json/TestJSONObject.java
+index 965812a..77bf087 100644
+--- a/src/test/java/net/sf/json/TestJSONObject.java
++++ b/src/test/java/net/sf/json/TestJSONObject.java
+@@ -17,6 +17,8 @@
+ package net.sf.json;
+ 
+ import java.io.Serializable;
++import java.io.PrintWriter;
++import java.io.StringWriter;
+ import java.math.BigDecimal;
+ import java.math.BigInteger;
+ import java.util.ArrayList;
+@@ -1638,4 +1640,23 @@ public class TestJSONObject extends TestCase {
+    
+    public void test_fromJSONObject() {
+    }
++
++    public void testCanonicalWrite() throws Exception {
++        JSONArray a = new JSONArray();
++        a.add(true);
++//        a.add(null);
++        a.add(1);
++        a.add(5.3);
++        JSONObject o = new JSONObject();
++        o.put("key1","1");
++        o.put("key2","2");
++        o.put("key3","3");
++        o.put("string","123\r\n\b\t\f\\\\u65E5\\u672C\\u8A9E");
++        a.add(o);
++
++        StringWriter sw = new StringWriter();
++        a.writeCanonical(sw);
++        System.out.println(sw.toString());
++        assertEquals(sw.toString(),"[true,1,5.3,{\"key1\":\"1\",\"key2\":\"2\",\"key3\":\"3\",\"string\":\"123\\u000d\\u000a\\u0008\\u0009\\u000c\\\\\\\\u65E5\\\\u672C\\\\u8A9E\"}]");
++    }
+ }
+\ No newline at end of file
+-- 
+1.8.5.3
+
diff --git a/json-lib.spec b/json-lib.spec
index 1c25426..c8e615e 100644
--- a/json-lib.spec
+++ b/json-lib.spec
@@ -1,6 +1,6 @@
 Name:           json-lib
 Version:        2.4
-Release:        2%{?dist}
+Release:        3%{?dist}
 Summary:        JSON library for Java
 License:        ASL 2.0
 URL:            http://json-lib.sourceforge.net/
@@ -13,6 +13,11 @@ Source0:        %{name}-%{version}.tar.xz
 Source1:        create-tarball.sh
 Patch0:         %{name}-%{version}-antrun-plugin.patch
 
+# Jenkins sources/patches
+Source100:      http://repo.jenkins-ci.org/releases/org/kohsuke/stapler/json-lib/%{version}-jenkins-3/json-lib-%{version}-jenkins-3.pom
+Patch100:       json-lib-2.4-added-methods-to-write-out-JSON-in-the-canonical-for.patch
+Patch101:       json-lib-2.4-Exposing-JsonConfig-used-for-property-setting.patch
+
 BuildRequires:  java-devel
 # compile dep
 BuildRequires:  mvn(commons-beanutils:commons-beanutils)
@@ -48,6 +53,15 @@ BuildArch:      noarch
 JSON-lib is a java library for transforming beans, maps, collections, java
 arrays and XML to JSON and back again to beans and DynaBeans.
 
+%package -n jenkins-json-lib
+Summary:        Jenkins JSON library
+
+%description -n jenkins-json-lib
+JSON-lib is a java library for transforming beans, maps, collections, java
+arrays and XML to JSON and back again to beans and DynaBeans.
+
+This package contains JSON library used in Jenkins.
+
 %package javadoc
 Summary:        Javadoc for %{name}
 
@@ -85,20 +99,51 @@ rm -r src/main/jdk15/net/sf/json/JSON*.java
 # should be removed from distribution
 %pom_remove_dep :commons-httpclient
 
-%build
 
+# we will build the sources twice (second time with Jenkins patches applied)
+tar xf %{SOURCE0}
+pushd %{name}-%{version}
+
+cp %{SOURCE100} pom.xml
+%pom_xpath_set "pom:project/pom:dependencies/pom:dependency[pom:groupId = 'org.codehaus.groovy']/pom:artifactId" groovy
+%patch100 -p1
+%patch101 -p1
+rm src/main/jdk15/net/sf/json/JSON*.java
+rm src/test/jdk15/net/sf/json/TestJSON*Jdk15.java
+
+%mvn_file org.kohsuke.stapler:json-lib jenkins-%{name}
+%mvn_package org.kohsuke.stapler:json-lib jenkins-json-lib
+
+popd
+
+%build
 %mvn_file : %{name}
 %mvn_build -- -Dproject.build.sourceEncoding=UTF-8
 
+# build Jenkins JSON lib
+pushd %{name}-%{version}
+%mvn_build
+popd
+
 %install
 %mvn_install
 
+# install Jenkins JSON lib
+pushd %{name}-%{version}
+%mvn_install
+popd
+
 %files -f .mfiles
 %doc LICENSE.txt
+%files -n jenkins-json-lib -f %{name}-%{version}/.mfiles-jenkins-json-lib
+%doc LICENSE.txt
 %files javadoc -f .mfiles-javadoc
 %doc LICENSE.txt
 
 %changelog
+* Wed Feb 12 2014 Michal Srb <msrb at redhat.com> - 2.4-3
+- Build jenkins-json-lib artifact
+
 * Wed Feb 12 2014 Michal Srb <msrb at redhat.com> - 2.4-2
 - Install license file
 
diff --git a/sources b/sources
index b1b95ec..5a8597e 100644
--- a/sources
+++ b/sources
@@ -1 +1,2 @@
 1c68437d7fe7e2bc779e8e593bbfc081  json-lib-2.4.tar.xz
+e9595d0de043cefee1fb0d6a858ef723  json-lib-2.4-jenkins-3.pom


More information about the scm-commits mailing list