This is an automated email from the ASF dual-hosted git repository.
dkulp pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/avro.git
The following commit(s) were added to refs/heads/master by this push:
new aa5860f Allow to set template dir for avro-tools compile
aa5860f is described below
commit aa5860fc355d7d44c3d567fdb1fb2d20ad474cc0
Author: Artem Yarulin <[email protected]>
AuthorDate: Wed Nov 7 00:30:41 2018 +0200
Allow to set template dir for avro-tools compile
maven-avro-plugin allows to specify custom template
directory (https://issues.apache.org/jira/browse/AVRO-983), same
applies to
gradle-avro-plugin
(https://github.com/commercehub-oss/gradle-avro-plugin#templatedirectory).
It would be useful to support that in Arvo CLI tools as well. Use
case: generating Java classes during CI or for any scripting needs
when using maven or gradle plugins is too much
---
.../java/org/apache/avro/tool/SpecificCompilerTool.java | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
diff --git
a/lang/java/tools/src/main/java/org/apache/avro/tool/SpecificCompilerTool.java
b/lang/java/tools/src/main/java/org/apache/avro/tool/SpecificCompilerTool.java
index b640388..4873271 100644
---
a/lang/java/tools/src/main/java/org/apache/avro/tool/SpecificCompilerTool.java
+++
b/lang/java/tools/src/main/java/org/apache/avro/tool/SpecificCompilerTool.java
@@ -47,7 +47,7 @@ public class SpecificCompilerTool implements Tool {
List<String> args) throws Exception {
if (args.size() < 3) {
System.err
- .println("Usage: [-encoding <outputencoding>] [-string]
[-bigDecimal] [-dateTimeLogicalTypeImpl <dateTimeType>] (schema|protocol)
input... outputdir");
+ .println("Usage: [-encoding <outputencoding>] [-string]
[-bigDecimal] [-dateTimeLogicalTypeImpl <dateTimeType>] [-templateDir
<templateDir>] (schema|protocol) input... outputdir");
System.err
.println(" input - input files or directories");
System.err
@@ -59,6 +59,7 @@ public class SpecificCompilerTool implements Tool {
"decimal type instead of java.nio.ByteBuffer");
System.err.println(" -dateTimeLogicalTypeImpl [joda|jsr310] - use either
" +
"Joda time classes (default) or Java 8 native date/time classes (JSR
310)");
+ System.err.println(" -templateDir - directory with custom Velocity
templates");
return 1;
}
@@ -66,6 +67,7 @@ public class SpecificCompilerTool implements Tool {
boolean useLogicalDecimal = false;
Optional<DateTimeLogicalTypeImplementation>
dateTimeLogicalTypeImplementation = Optional.empty();
Optional<String> encoding = Optional.empty();
+ Optional<String> templateDir = Optional.empty();
int arg = 0;
@@ -96,6 +98,13 @@ public class SpecificCompilerTool implements Tool {
arg++;
}
+ if ("-templateDir".equals(args.get(arg))) {
+ arg++;
+ templateDir = Optional.of(args.get(arg));
+ arg++;
+ }
+
+
String method = args.get(arg);
List<File> inputs = new ArrayList<>();
File output = new File(args.get(args.size() - 1));
@@ -110,14 +119,14 @@ public class SpecificCompilerTool implements Tool {
Schema schema = parser.parse(src);
SpecificCompiler compiler = new SpecificCompiler(schema,
dateTimeLogicalTypeImplementation.orElse(DateTimeLogicalTypeImplementation.JODA));
- executeCompiler(compiler, encoding, stringType, useLogicalDecimal,
src, output);
+ executeCompiler(compiler, encoding, stringType, useLogicalDecimal,
templateDir, src, output);
}
} else if ("protocol".equals(method)) {
for (File src : determineInputs(inputs, PROTOCOL_FILTER)) {
Protocol protocol = Protocol.parse(src);
SpecificCompiler compiler = new SpecificCompiler(protocol,
dateTimeLogicalTypeImplementation.orElse(DateTimeLogicalTypeImplementation.JODA));
- executeCompiler(compiler, encoding, stringType, useLogicalDecimal,
src, output);
+ executeCompiler(compiler, encoding, stringType, useLogicalDecimal,
templateDir, src, output);
}
} else {
System.err.println("Expected \"schema\" or \"protocol\".");
@@ -130,9 +139,11 @@ public class SpecificCompilerTool implements Tool {
Optional<String> encoding,
StringType stringType,
boolean enableDecimalLogicalType,
+ Optional<String> templateDir,
File src,
File output) throws IOException {
compiler.setStringType(stringType);
+ templateDir.ifPresent(compiler::setTemplateDir);
compiler.setEnableDecimalLogicalType(enableDecimalLogicalType);
encoding.ifPresent(compiler::setOutputCharacterEncoding);
compiler.compileToDestination(src, output);