Apache Thrift Ant Task
Thrift-task is an native(ish) cross-platform Ant task for the Apache Thrift
project. It also includes a full Java implementation of
thrift than can be used from the command line.
thrift-task-0.0.2-SNAPSHOT.jarinto your project directory.
- Define the task in your build file, setting classpath to the relative path to the jar:
<taskdef name="thrift" classname="com.nsegment.thrift.ThriftTask" classpath="thrift-task-0.0.2-SNAPSHOT.jar" />
- Now add a task to your build file:
<thrift srcdir="." includes="**/*.thrift" destdir="bin" java="" />
- This task will build all
.thriftfiles in the project directory and drop off
thrift as a standalone process (not from Ant), do
java -jar thrift-task-0.0.2-SNAPSHOT.jar -help # or java -cp thrift-task-0.0.2-SNAPSHOT.jar com.nsegment.thrift.Thriftc -help
Windows users using thrift-task outside of Ant should use absolute paths like
separators are forward slashes, a leading forward slash is added before the drive letter, and the drive letter is
lower-case. When using the Ant task, this conversion is handled for you.
Thrift-task is a MatchingTask, so it supports filesets, includes, and excludes like
--gen flags are passed as attributes to the task, and their options are comma-separated attribute values:
<thrift srcdir="." includes="**/*.thrift" destdir="bin" java="hashcode,include_prefix" />
The following boolean flags are supported:
- A thrift-task addition,
quiet="true"will discard all output, regardless of the settings of other flags
The following languages and options are supported and behave the same as those in the the compiled
- as3 (bindable)
- cocoa (log_unexpected, validate_required)
- cpp (cob_style, no_client_completion, no_default_operators, templates, pure_enums, dense, include_prefix)
- csharp (async, asyncctp, wcf, serial, nullable, hashcode, union)
- delphi (ansistr_binary, register_types, constprefix, events, xmldoc)
- erl (legacynames)
- go (package_prefix, thrift_import, package)
- html (standalone)
- java (beans, private-members, nocamel, fullcamel, android, android_legacy, java5, reuse-objects, sorted_containers)
- js (jquery, node, ts)
- php (inlined, server, oop, rest, nsglobal=NAME, validate, json)
- py (new_style, twisted, tornado, utf8strings, slots, dynamic, dynbase=CLS, dynexc=CLS, dynimport='from foo.bar import CLS')
- rb (rubygems, namespaced)
Rather than being a native Java implementation, thrift-task uses code translated from a MIPS build of
thrift to Java
byte code by the NestedVM project and a modified Unix runtime. It's essentially emulated
MIPS code, but in a compiled form. While it's noticeably slower than a native executable or native Java code, it's far
easier to perfectly match existing behavior or change behavior to match a specific build.
The process for building the emulated class blob is documented in toolchain. Once built, jars just need
to be copied to
pom.xml modified to relfect the new versions.
- It's a little slow, but tolerable. This is because the code is emulated.
- It doesn't detect if source files need to be rebuilt, so it always rebuilds. Part of the reason is detecting modification times requires parsing the file to find its includes.