Skip to content
This repository has been archived by the owner on Dec 28, 2023. It is now read-only.

Commit

Permalink
Fix encoding support (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmc24 committed Oct 18, 2014
1 parent 1226f70 commit 4c373d4
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

# 0.3.1
* Fix extension support for configuring encoding
* Make default encoding UTF-8

* 0.3.0
* IntelliJ: register generated source directories even if they don't already exist.
* Add avro-base plugin, which exposes tasks and the extension without creating tasks, defaults, etc.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ public void apply(final Project project) {

private static void configureExtension(final Project project) {
final AvroExtension avroExtension = project.getExtensions().create(AVRO_EXTENSION_NAME, DefaultAvroExtension.class);
conventionMapping(avroExtension).map("stringType", new Callable<String>() {
ConventionMapping extensionMapping = conventionMapping(avroExtension);
extensionMapping.map("encoding", new Callable<String>() {
@Override
public String call() throws Exception {
return Constants.UTF8_ENCONDING;
}
});
extensionMapping.map("stringType", new Callable<String>() {
@Override
public String call() throws Exception {
return GenericData.StringType.String.name();
Expand All @@ -28,7 +35,14 @@ public String call() throws Exception {
project.getTasks().withType(GenerateAvroJavaTask.class).all(new Action<GenerateAvroJavaTask>() {
@Override
public void execute(GenerateAvroJavaTask task) {
conventionMapping(task).map("stringType", new Callable<String>() {
ConventionMapping taskMapping = conventionMapping(task);
taskMapping.map("encoding", new Callable<String>() {
@Override
public String call() throws Exception {
return avroExtension.getEncoding();
}
});
taskMapping.map("stringType", new Callable<String>() {
@Override
public String call() throws Exception {
return avroExtension.getStringType();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.commercehub.gradle.plugin.avro;

public interface AvroExtension {
String getEncoding();
String getStringType();
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
package com.commercehub.gradle.plugin.avro;

public class DefaultAvroExtension implements AvroExtension {
private String encoding;
private String stringType;

@Override
public String getEncoding() {
return encoding;
}

public void setEncoding(String encoding) {
this.encoding = encoding;
}

@Override
public String getStringType() {
return stringType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
public class GenerateAvroJavaTask extends OutputDirTask {
private static Set<String> SUPPORTED_EXTENSIONS = SetBuilder.build(PROTOCOL_EXTENSION, SCHEMA_EXTENSION);

private String encoding;
private String encoding = Constants.UTF8_ENCONDING;

private String stringType;

Expand Down Expand Up @@ -61,6 +61,7 @@ private GenericData.StringType parseStringType() {

@TaskAction
protected void process() {
getLogger().debug("Using encoding {}", getEncoding());
getLogger().info("Found {} files", getInputs().getSourceFiles().getFiles().size());
failOnUnsupportedFiles();
preClean();
Expand Down Expand Up @@ -109,9 +110,7 @@ private void processProtoFile(File sourceFile) {
Protocol protocol = Protocol.parse(sourceFile);
SpecificCompiler compiler = new SpecificCompiler(protocol);
compiler.setStringType(parseStringType());
if (encoding != null) {
compiler.setOutputCharacterEncoding(encoding);
}
compiler.setOutputCharacterEncoding(getEncoding());
compiler.compileToDestination(sourceFile, getOutputDir());
} catch (IOException ex) {
throw new GradleException(String.format("Failed to compile protocol definition file %s", sourceFile), ex);
Expand Down Expand Up @@ -140,9 +139,7 @@ private int processSchemaFiles() {
Schema schema = parser.parse(sourceFile);
SpecificCompiler compiler = new SpecificCompiler(schema);
compiler.setStringType(parseStringType());
if (encoding != null) {
compiler.setOutputCharacterEncoding(encoding);
}
compiler.setOutputCharacterEncoding(getEncoding());
compiler.compileToDestination(sourceFile, getOutputDir());
types = parser.getTypes();
getLogger().info("Processed {}", sourceFile);
Expand Down

0 comments on commit 4c373d4

Please sign in to comment.