avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r883884 - in /hadoop/avro/trunk: CHANGES.txt src/java/org/apache/avro/Protocol.java src/java/org/apache/avro/Schema.java src/java/org/apache/avro/reflect/InduceSchemaTool.java src/java/org/apache/avro/tool/Tool.java src/test/bin/test_avroj.sh
Date Tue, 24 Nov 2009 21:25:16 GMT
Author: cutting
Date: Tue Nov 24 21:25:15 2009
New Revision: 883884

URL: http://svn.apache.org/viewvc?rev=883884&view=rev
Log:
AVRO-236.  Add protocol support to avroj induce tool.

Modified:
    hadoop/avro/trunk/CHANGES.txt
    hadoop/avro/trunk/src/java/org/apache/avro/Protocol.java
    hadoop/avro/trunk/src/java/org/apache/avro/Schema.java
    hadoop/avro/trunk/src/java/org/apache/avro/reflect/InduceSchemaTool.java
    hadoop/avro/trunk/src/java/org/apache/avro/tool/Tool.java
    hadoop/avro/trunk/src/test/bin/test_avroj.sh

Modified: hadoop/avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/CHANGES.txt?rev=883884&r1=883883&r2=883884&view=diff
==============================================================================
--- hadoop/avro/trunk/CHANGES.txt (original)
+++ hadoop/avro/trunk/CHANGES.txt Tue Nov 24 21:25:15 2009
@@ -103,6 +103,8 @@
 
     AVRO-233. Elaborate Java tool API. (Philip Zeyliger via cutting)
 
+    AVRO-236. Add protocol support to avroj induce tool.  (cutting)
+    
   OPTIMIZATIONS
 
     AVRO-172. More efficient schema processing (massie)

Modified: hadoop/avro/trunk/src/java/org/apache/avro/Protocol.java
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/java/org/apache/avro/Protocol.java?rev=883884&r1=883883&r2=883884&view=diff
==============================================================================
--- hadoop/avro/trunk/src/java/org/apache/avro/Protocol.java (original)
+++ hadoop/avro/trunk/src/java/org/apache/avro/Protocol.java Tue Nov 24 21:25:15 2009
@@ -193,10 +193,18 @@
       + types.hashCode() + messages.hashCode();
   }
 
-  public String toString() {
+  /** Render this as <a href="http://json.org/">JSON</a>.*/
+  @Override
+  public String toString() { return toString(false); }
+
+  /** Render this as <a href="http://json.org/">JSON</a>.
+   * @param pretty if true, pretty-print JSON.
+   */
+  public String toString(boolean pretty) {
     try {
       StringWriter writer = new StringWriter();
       JsonGenerator gen = Schema.FACTORY.createJsonGenerator(writer);
+      if (pretty) gen.useDefaultPrettyPrinter();
       toJson(gen);
       gen.flush();
       return writer.toString();

Modified: hadoop/avro/trunk/src/java/org/apache/avro/Schema.java
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/java/org/apache/avro/Schema.java?rev=883884&r1=883883&r2=883884&view=diff
==============================================================================
--- hadoop/avro/trunk/src/java/org/apache/avro/Schema.java (original)
+++ hadoop/avro/trunk/src/java/org/apache/avro/Schema.java Tue Nov 24 21:25:15 2009
@@ -200,10 +200,17 @@
   }
 
   /** Render this as <a href="http://json.org/">JSON</a>.*/
-  public String toString() {
+  @Override
+  public String toString() { return toString(false); }
+
+  /** Render this as <a href="http://json.org/">JSON</a>.
+   * @param pretty if true, pretty-print JSON.
+   */
+  public String toString(boolean pretty) {
     try {
       StringWriter writer = new StringWriter();
       JsonGenerator gen = FACTORY.createJsonGenerator(writer);
+      if (pretty) gen.useDefaultPrettyPrinter();
       toJson(new Names(), gen);
       gen.flush();
       return writer.toString();

Modified: hadoop/avro/trunk/src/java/org/apache/avro/reflect/InduceSchemaTool.java
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/java/org/apache/avro/reflect/InduceSchemaTool.java?rev=883884&r1=883883&r2=883884&view=diff
==============================================================================
--- hadoop/avro/trunk/src/java/org/apache/avro/reflect/InduceSchemaTool.java (original)
+++ hadoop/avro/trunk/src/java/org/apache/avro/reflect/InduceSchemaTool.java Tue Nov 24 21:25:15
2009
@@ -27,8 +27,7 @@
 import org.apache.avro.tool.Tool;
 
 /**
- * Utility to induce the schema of a given class using
- * reflection.
+ * Utility to induce a schema from a class or a protocol from an interface.
  */
 public class InduceSchemaTool implements Tool {
 
@@ -57,7 +56,11 @@
     }
 
     Class<?> klass = classLoader.loadClass(className);
-    System.out.println(ReflectData.get().getSchema(klass).toString());
+    if (klass.isInterface()) {
+      System.out.println(ReflectData.get().getProtocol(klass).toString(true));
+    } else {
+      System.out.println(ReflectData.get().getSchema(klass).toString(true));
+    }
   }
 
   @Override
@@ -67,6 +70,7 @@
 
   @Override
   public String getShortDescription() {
-    return "Uses reflection to induce schema for a given class.";
+    return "Use reflection to induce a schema from a class"
+      + " or a protocol from an interface.";
   }
 }

Modified: hadoop/avro/trunk/src/java/org/apache/avro/tool/Tool.java
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/java/org/apache/avro/tool/Tool.java?rev=883884&r1=883883&r2=883884&view=diff
==============================================================================
--- hadoop/avro/trunk/src/java/org/apache/avro/tool/Tool.java (original)
+++ hadoop/avro/trunk/src/java/org/apache/avro/tool/Tool.java Tue Nov 24 21:25:15 2009
@@ -18,7 +18,6 @@
 package org.apache.avro.tool;
 
 import java.io.InputStream;
-import java.io.OutputStream;
 import java.io.PrintStream;
 import java.util.List;
 
@@ -48,4 +47,4 @@
    * 1-line description to be used in command listings.
    */
   String getShortDescription();
-}
\ No newline at end of file
+}

Modified: hadoop/avro/trunk/src/test/bin/test_avroj.sh
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/test/bin/test_avroj.sh?rev=883884&r1=883883&r2=883884&view=diff
==============================================================================
--- hadoop/avro/trunk/src/test/bin/test_avroj.sh (original)
+++ hadoop/avro/trunk/src/test/bin/test_avroj.sh Tue Nov 24 21:25:15 2009
@@ -54,9 +54,13 @@
   "$(find $TMPDIR/schema -name "*.java" \
     | awk -F "/" '{ print $NF }' | sort | tr '\n' ' ')" ]
 ######################################################################
-echo "Testing induce schema..."
-$CMD induce build/test/classes org.apache.avro.BarRecord | grep -q -F \
-  '{"type":"record","name":"BarRecord","namespace":"org.apache.avro","fields":[{"name":"beerMsg","type":"string"}]}'
+# Testing induce schema
+$CMD induce build/test/classes org.apache.avro.BarRecord \
+ | tr -d '\n ' | grep -q -F  '{"type":"record","name":"BarRecord"'
+######################################################################
+# Test induce protocol
+$CMD induce build/test/classes 'org.apache.avro.TestReflect$C' \
+ | tr -d '\n ' | grep -q -F  '{"protocol":"C"'
 ######################################################################
 $CMD 2>&1 | grep -q "Available tools:"
 $CMD doesnotexist 2>&1 | grep -q "Available tools:"



Mime
View raw message