Author: cutting
Date: Tue Oct 27 23:57:53 2009
New Revision: 830407
URL: http://svn.apache.org/viewvc?rev=830407&view=rev
Log:
AVRO-149. Add Java command-line executable 'avroj'. Contributed by Philip
Zeyliger.
Added:
hadoop/avro/trunk/src/java/org/apache/avro/tool/
hadoop/avro/trunk/src/java/org/apache/avro/tool/Main.java
hadoop/avro/trunk/src/java/org/apache/avro/tool/Tool.java
hadoop/avro/trunk/src/java/org/apache/avro/tool/package.html
hadoop/avro/trunk/src/test/bin/
hadoop/avro/trunk/src/test/bin/test_avroj.sh (with props)
Modified:
hadoop/avro/trunk/CHANGES.txt
hadoop/avro/trunk/build.xml
hadoop/avro/trunk/src/java/org/apache/avro/specific/SpecificCompiler.java
Modified: hadoop/avro/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/CHANGES.txt?rev=830407&r1=830406&r2=830407&view=diff
==============================================================================
--- hadoop/avro/trunk/CHANGES.txt (original)
+++ hadoop/avro/trunk/CHANGES.txt Tue Oct 27 23:57:53 2009
@@ -31,6 +31,9 @@
AVRO-146. Add support for using Eclipse to develop Avro's Java.
(Philip Zeyliger via cutting)
+ AVRO-149. Add Java command-line executable, "avroj".
+ (Philip Zeyliger via cutting)
+
OPTIMIZATIONS
AVRO-172. More efficient schema processing (massie)
Modified: hadoop/avro/trunk/build.xml
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/build.xml?rev=830407&r1=830406&r2=830407&view=diff
==============================================================================
--- hadoop/avro/trunk/build.xml (original)
+++ hadoop/avro/trunk/build.xml Tue Oct 27 23:57:53 2009
@@ -279,7 +279,7 @@
</sequential>
</macrodef>
- <target name="test"
depends="test-java,test-py,test-c,test-cpp,test-interop"/>
+ <target name="test"
depends="test-java,test-py,test-c,test-cpp,test-interop,test-avroj"/>
<macrodef name="test-runner">
<attribute name="files.location" />
@@ -439,6 +439,26 @@
</py-run>
</target>
+ <target name="avroj" depends="compile-java" description="Build standalone
avroj jar file">
+ <jar jarfile="${build.dir}/avroj-${version}.jar">
+ <manifest>
+ <attribute name="Main-Class" value="org.apache.avro.tool.Main"/>
+ <attribute name="Implementation-Title" value="${Name}"/>
+ <attribute name="Implementation-Version" value="${version}"/>
+ <attribute name="Implementation-Vendor" value="${Org}"/>
+ </manifest>
+ <fileset dir="${build.classes}" />
+ <zipgroupfileset dir="${ivy.lib}" includes="*.jar"/>
+ </jar>
+ <chmod file="${build.dir}/avroj-${version}.jar" perm="ugo+x"/>
+ </target>
+
+ <target name="test-avroj" depends="avroj"
+ description="Tests avroj commands">
+ <exec executable="${basedir}/src/test/bin/test_avroj.sh"
+ failonerror="true" />
+ </target>
+
<target name="pydoc" description="Generate python api docs">
<taskdef name="py-doc" classname="org.pyant.tasks.PythonDocTask">
<classpath refid="java.classpath" />
@@ -505,7 +525,7 @@
<fail if="javadoc.warnings">Javadoc warnings!</fail>
</target>
- <target name="package" depends="jar, doc, package-c, package-cpp"
+ <target name="package" depends="jar, avroj, doc, package-c, package-cpp"
description="Build distribution">
<mkdir dir="${dist.dir}"/>
<mkdir dir="${dist.dir}/lib"/>
@@ -558,7 +578,6 @@
<fileset file="build.xml"/>
<fileset file="ivy.xml"/>
</copy>
-
</target>
<macrodef name="macro_tar" description="Worker Macro for tar">
Modified:
hadoop/avro/trunk/src/java/org/apache/avro/specific/SpecificCompiler.java
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/java/org/apache/avro/specific/SpecificCompiler.java?rev=830407&r1=830406&r2=830407&view=diff
==============================================================================
--- hadoop/avro/trunk/src/java/org/apache/avro/specific/SpecificCompiler.java
(original)
+++ hadoop/avro/trunk/src/java/org/apache/avro/specific/SpecificCompiler.java
Tue Oct 27 23:57:53 2009
@@ -30,6 +30,7 @@
import org.apache.avro.Protocol;
import org.apache.avro.Schema;
import org.apache.avro.Protocol.Message;
+import org.apache.avro.tool.Tool;
/** Generate specific Java interfaces and classes for protocols and schemas. */
public class SpecificCompiler {
@@ -355,5 +356,30 @@
compileProtocol(new File(args[0]), new File(args[1]));
}
+ /**
+ * Implementation of Tool for inclusion by the "avroj"
+ * runner.
+ */
+ public static class SpecificCompilerTool implements Tool {
+ @Override
+ public void run(List<String> args) throws IOException {
+ if (args.size() != 3) {
+ System.err.println("Expected 3 arguments: (schema|protocol) inputfile
outputdir");
+ return;
+ }
+ String method = args.get(0);
+ File input = new File(args.get(1));
+ File output = new File(args.get(2));
+ if ("schema".equals(method)) {
+ compileSchema(input, output);
+ } else if ("protocol".equals(method)) {
+ compileProtocol(input, output);
+ } else {
+ System.err.println("Expected \"schema\" or \"protocol\".");
+ return;
+ }
+ }
+ }
+
}
Added: hadoop/avro/trunk/src/java/org/apache/avro/tool/Main.java
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/java/org/apache/avro/tool/Main.java?rev=830407&view=auto
==============================================================================
--- hadoop/avro/trunk/src/java/org/apache/avro/tool/Main.java (added)
+++ hadoop/avro/trunk/src/java/org/apache/avro/tool/Main.java Tue Oct 27
23:57:53 2009
@@ -0,0 +1,58 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.avro.tool;
+
+import java.util.Arrays;
+import java.util.Map;
+import java.util.TreeMap;
+
+import org.apache.avro.specific.SpecificCompiler.SpecificCompilerTool;
+
+/** Command-line driver.*/
+public class Main {
+ /**
+ * Available tools, initialized in constructor.
+ */
+ private final Map<String, Tool> tools;
+
+ private Main() {
+ tools = new TreeMap<String, Tool>();
+ tools.put("compile", new SpecificCompilerTool());
+ }
+
+ public static void main(String[] args) throws Exception {
+ new Main().run(args);
+ }
+
+ /**
+ * Delegates to tool specified on the command-line.
+ */
+ private void run(String[] args) throws Exception {
+ if (args.length != 0) {
+ Tool tool = tools.get(args[0]);
+ if (tool != null) {
+ tool.run(Arrays.asList(args).subList(1, args.length));
+ return;
+ }
+ }
+ System.err.println("Expected one of the following arguments:");
+ for (String k : tools.keySet()) {
+ System.err.println("\t" + k);
+ }
+ }
+}
Added: 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=830407&view=auto
==============================================================================
--- hadoop/avro/trunk/src/java/org/apache/avro/tool/Tool.java (added)
+++ hadoop/avro/trunk/src/java/org/apache/avro/tool/Tool.java Tue Oct 27
23:57:53 2009
@@ -0,0 +1,34 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.avro.tool;
+
+import java.util.List;
+
+/**
+ * Command-line "avroj" utilities should implement this
+ * interface for delegation by {...@link Main}.
+ */
+public interface Tool {
+ /**
+ * Runs the tool with supplied arguments.
+ *
+ * @param args Non-null list of arguments.
+ * @throws Exception Just like main(), tools may throw Exception.
+ */
+ void run(List<String> args) throws Exception;
+}
Added: hadoop/avro/trunk/src/java/org/apache/avro/tool/package.html
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/java/org/apache/avro/tool/package.html?rev=830407&view=auto
==============================================================================
--- hadoop/avro/trunk/src/java/org/apache/avro/tool/package.html (added)
+++ hadoop/avro/trunk/src/java/org/apache/avro/tool/package.html Tue Oct 27
23:57:53 2009
@@ -0,0 +1,23 @@
+<html>
+
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<body>
+Avro command-line tool.
+</body>
+</html>
Added: 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=830407&view=auto
==============================================================================
--- hadoop/avro/trunk/src/test/bin/test_avroj.sh (added)
+++ hadoop/avro/trunk/src/test/bin/test_avroj.sh Tue Oct 27 23:57:53 2009
@@ -0,0 +1,53 @@
+#!/usr/bin/env bash
+
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Tests "avroj" script and commands.
+
+# Echo all commands, so that test failure location is clear.
+set -o xtrace
+# This script will exist at any false return value.
+set -o errexit
+
+AVROJ="java -jar build/avroj-*.jar"
+
+# Create a temp directory.
+TMPDIR=$(mktemp -d -t test_avroj)
+
+######################################################################
+echo "Testing code generation..."
+
+$AVROJ compile protocol src/test/schemata/namespace.avpr $TMPDIR/namespace
+# Check that the expected names were generated
+[ "MD5.java TestError.java TestNamespace.java TestRecord.java " = \
+ "$(find $TMPDIR/namespace -name "*.java" \
+ | awk -F "/" '{ print $NF }' | sort | tr '\n' ' ')" ]
+$AVROJ compile schema src/test/schemata/interop.avsc $TMPDIR/schema
+[ "Foo.java Interop.java Kind.java MD5.java Node.java " = \
+ "$(find $TMPDIR/schema -name "*.java" \
+ | awk -F "/" '{ print $NF }' | sort | tr '\n' ' ')" ]
+
+######################################################################
+echo "Testing avroj command..."
+
+$AVROJ 2>&1 | grep -q "Expected one of the following"
+$AVROJ doesnotexist 2>&1 | grep -q "Expected one of the following"
+
+######################################################################
+# Clean up temp directory.
+rm -rf $TMPDIR
+
+echo "Tests passed!"
Propchange: hadoop/avro/trunk/src/test/bin/test_avroj.sh
------------------------------------------------------------------------------
svn:executable = *