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

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: davidmc24/gradle-avro-plugin
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1.6.0
Choose a base ref
...
head repository: davidmc24/gradle-avro-plugin
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 1.7.0
Choose a head ref
  • 8 commits
  • 12 files changed
  • 2 contributors

Commits on Feb 6, 2023

  1. version: 1.6.1-SNAPSHOT

    davidmc24 committed Feb 6, 2023
    Copy the full SHA
    af1134c View commit details
  2. Update changelog

    davidmc24 committed Feb 6, 2023
    Copy the full SHA
    cc62833 View commit details

Commits on Apr 4, 2023

  1. Verified

    This commit was signed with the committer’s verified signature.
    erdi Marcin Erdmann
    Copy the full SHA
    c165119 View commit details
  2. Verified

    This commit was signed with the committer’s verified signature.
    erdi Marcin Erdmann
    Copy the full SHA
    5ede65a View commit details
  3. Add documentation for using conversions and type factories located ou…

    …tside of build classpath
    erdi committed Apr 4, 2023

    Verified

    This commit was signed with the committer’s verified signature.
    erdi Marcin Erdmann
    Copy the full SHA
    09fafb2 View commit details
  4. Add deprecations for methods used to configure conversions and type f…

    …actories with classes
    erdi committed Apr 4, 2023

    Verified

    This commit was signed with the committer’s verified signature.
    erdi Marcin Erdmann
    Copy the full SHA
    b4ac5ba View commit details

Commits on Apr 5, 2023

  1. Merge pull request #228 from erdi/conversions-and-type-factories-outs…

    …ide-build-classpath
    
    Add ability to use conversions and type factories residing outside of build classpath
    davidmc24 authored Apr 5, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    457b926 View commit details
  2. Prep for 1.7.0 release

    davidmc24 committed Apr 5, 2023
    Copy the full SHA
    dda836f View commit details
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Change Log

## Unreleased

## 1.7.0
* Support for using conversions and type factories located outside of build classpath (contribution from [erdi](https://github.com/erdi)); see https://github.com/davidmc24/gradle-avro-plugin/pull/228

## 1.6.0
* Add support for configuring classpath for `GenerateAvroJavaTask` (thanks to [crtlib](https://github.com/crtlib)); see https://github.com/davidmc24/gradle-avro-plugin/pull/222
* Drop compatibility testing for old versions of Java (9, 10, 12, 13, 14, 15, 16)
* Built using Gradle 7.6
49 changes: 37 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -83,18 +83,21 @@ Actually, it will attempt to process an "avro" directory in every `SourceSet` (m

There are a number of configuration options supported in the `avro` block.

| option | default | description |
|--------------------------------------| --------------------- |----------------------------------------------------------------|
| createSetters | `true` | `createSetters` passed to Avro compiler |
| createOptionalGetters | `false` | `createOptionalGetters` passed to Avro compiler |
| gettersReturnOptional | `false` | `gettersReturnOptional` passed to Avro compiler |
| optionalGettersForNullableFieldsOnly | `false` | `optionalGettersForNullableFieldsOnly` passed to Avro compiler |
| fieldVisibility | `"PRIVATE"` | `fieldVisibility` passed to Avro compiler |
| outputCharacterEncoding | see below | `outputCharacterEncoding` passed to Avro compiler |
| stringType | `"String"` | `stringType` passed to Avro compiler |
| templateDirectory | see below | `templateDir` passed to Avro compiler |
| additionalVelocityToolClasses | see below | `additionalVelocityTools` passed to Avro compiler |
| enableDecimalLogicalType | `true` | `enableDecimalLogicalType` passed to Avro compiler |
| option | default | description |
|--------------------------------------|------------------------------------|-------------------------------------------------------------------------------------------------------------------|
| createSetters | `true` | `createSetters` passed to Avro compiler |
| createOptionalGetters | `false` | `createOptionalGetters` passed to Avro compiler |
| gettersReturnOptional | `false` | `gettersReturnOptional` passed to Avro compiler |
| optionalGettersForNullableFieldsOnly | `false` | `optionalGettersForNullableFieldsOnly` passed to Avro compiler |
| fieldVisibility | `"PRIVATE"` | `fieldVisibility` passed to Avro compiler |
| outputCharacterEncoding | see below | `outputCharacterEncoding` passed to Avro compiler |
| stringType | `"String"` | `stringType` passed to Avro compiler |
| templateDirectory | see below | `templateDir` passed to Avro compiler |
| additionalVelocityToolClasses | see below | `additionalVelocityTools` passed to Avro compiler |
| enableDecimalLogicalType | `true` | `enableDecimalLogicalType` passed to Avro compiler |
| conversionsAndTypeFactoriesClasspath | empty `ConfigurableFileCollection` | used for loading custom conversions and logical type factories |
| logicalTypeFactoryClassNames | empty `Map` | map from names to class names of logical types factories to be loaded from `conversionsAndTypeFactoriesClasspath` |
| customConversionClassNames | empty `List` | class names of custom conversions to be loaded from `conversionsAndTypeFactoriesClasspath` |

Additionally, the `avro` extension exposes the following methods:

@@ -257,6 +260,28 @@ avro {
}
```

## conversionsAndTypeFactoriesClasspath, logicalTypeFactoryClassNames and customConversionClassNames

Properties that can be used for loading [Conversion](https://avro.apache.org/docs/current/api/java/org/apache/avro/Conversion.html) and [LogicalTypeFactory](https://avro.apache.org/docs/current/api/java/org/apache/avro/LogicalTypes.LogicalTypeFactory.html) classes from outside of the build classpath.

Example:

```groovy
configurations {
customConversions
}
dependencies {
customConversions(project(":custom-conversions"))
}
avro {
conversionsAndTypeFactoriesClasspath.from(configurations.customConversions)
logicalTypeFactoryClassNames.put("timezone", "com.github.davidmc24.gradle.plugin.avro.test.custom.TimeZoneLogicalTypeFactory")
customConversionClassNames.add("com.github.davidmc24.gradle.plugin.avro.test.custom.TimeZoneConversion")
}
```

# IntelliJ Integration

The plugin attempts to make IntelliJ play more smoothly with generated sources when using Gradle-generated project files.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ plugins {
// support.

group = "com.github.davidmc24.gradle.plugin"
version = "1.6.0"
version = "1.7.0"

def isCI = System.getenv("CI") == "true"

Original file line number Diff line number Diff line change
@@ -24,6 +24,7 @@ public void apply(final Project project) {
configureExtension(project);
}

@SuppressWarnings("deprecation")
private static void configureExtension(final Project project) {
final AvroExtension avroExtension =
GradleCompatibility.createExtensionWithObjectFactory(project, Constants.AVRO_EXTENSION_NAME, DefaultAvroExtension.class);
@@ -38,8 +39,11 @@ private static void configureExtension(final Project project) {
task.isGettersReturnOptional().convention(avroExtension.isGettersReturnOptional());
task.isOptionalGettersForNullableFieldsOnly().convention(avroExtension.isOptionalGettersForNullableFieldsOnly());
task.isEnableDecimalLogicalType().convention(avroExtension.isEnableDecimalLogicalType());
task.getConversionsAndTypeFactoriesClasspath().from(avroExtension.getConversionsAndTypeFactoriesClasspath());
task.getLogicalTypeFactories().convention(avroExtension.getLogicalTypeFactories());
task.getLogicalTypeFactoryClassNames().convention(avroExtension.getLogicalTypeFactoryClassNames());
task.getCustomConversions().convention(avroExtension.getCustomConversions());
task.getCustomConversionClassNames().convention(avroExtension.getCustomConversionClassNames());
});
}
}
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@

import org.apache.avro.Conversion;
import org.apache.avro.LogicalTypes;
import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.provider.ListProperty;
import org.gradle.api.provider.MapProperty;
import org.gradle.api.provider.Property;
@@ -33,8 +34,33 @@ public interface AvroExtension {
Property<Boolean> isGettersReturnOptional();
Property<Boolean> isOptionalGettersForNullableFieldsOnly();
Property<Boolean> isEnableDecimalLogicalType();
ConfigurableFileCollection getConversionsAndTypeFactoriesClasspath();

/**
* @deprecated use {@link #getLogicalTypeFactoryClassNames()} instead
*/
@Deprecated
MapProperty<String, Class<? extends LogicalTypes.LogicalTypeFactory>> getLogicalTypeFactories();
MapProperty<String, String> getLogicalTypeFactoryClassNames();

/**
* @deprecated use {@link #getCustomConversionClassNames()} instead
*/
@Deprecated
ListProperty<Class<? extends Conversion<?>>> getCustomConversions();
ListProperty<String> getCustomConversionClassNames();

/**
* @deprecated use {@link #logicalTypeFactory(String, String)}
*/
@Deprecated
AvroExtension logicalTypeFactory(String typeName, Class<? extends LogicalTypes.LogicalTypeFactory> typeFactoryClass);
AvroExtension logicalTypeFactory(String typeName, String typeFactoryClassName);

/**
* @deprecated use {@link #customConversion(String)} instead
*/
@Deprecated
AvroExtension customConversion(Class<? extends Conversion<?>> conversionClass);
AvroExtension customConversion(String conversionClassName);
}
Original file line number Diff line number Diff line change
@@ -41,7 +41,9 @@ class Constants {
static final boolean DEFAULT_OPTIONAL_GETTERS_FOR_NULLABLE_FIELDS_ONLY = false;
static final boolean DEFAULT_ENABLE_DECIMAL_LOGICAL_TYPE = true;
static final Map<String, Class<? extends LogicalTypes.LogicalTypeFactory>> DEFAULT_LOGICAL_TYPE_FACTORIES = Collections.emptyMap();
static final Map<String, String> DEFAULT_LOGICAL_TYPE_FACTORY_CLASS_NAMES = Collections.emptyMap();
static final List<Class<? extends Conversion<?>>> DEFAULT_CUSTOM_CONVERSIONS = Collections.emptyList();
static final List<String> DEFAULT_CUSTOM_CONVERSION_CLASS_NAMES = Collections.emptyList();

static final String SCHEMA_EXTENSION = "avsc";
static final String PROTOCOL_EXTENSION = "avpr";
Original file line number Diff line number Diff line change
@@ -24,6 +24,8 @@
import org.apache.avro.LogicalTypes;
import org.apache.avro.compiler.specific.SpecificCompiler;
import org.apache.avro.generic.GenericData;
import org.gradle.api.Project;
import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.model.ObjectFactory;
import org.gradle.api.provider.ListProperty;
import org.gradle.api.provider.MapProperty;
@@ -44,11 +46,14 @@ public class DefaultAvroExtension implements AvroExtension {
private final Property<Boolean> gettersReturnOptional;
private final Property<Boolean> optionalGettersForNullableFieldsOnly;
private final Property<Boolean> enableDecimalLogicalType;
private final ConfigurableFileCollection conversionsAndTypeFactoriesClasspath;
private final MapProperty<String, Class<? extends LogicalTypes.LogicalTypeFactory>> logicalTypeFactories;
private final MapProperty<String, String> logicalTypeFactoryClassNames;
private final ListProperty<Class<? extends Conversion<?>>> customConversions;
private final ListProperty<String> customConversionClassNames;

@Inject
public DefaultAvroExtension(ObjectFactory objects) {
public DefaultAvroExtension(Project project, ObjectFactory objects) {
this.outputCharacterEncoding = objects.property(String.class);
this.stringType = objects.property(String.class).convention(Constants.DEFAULT_STRING_TYPE);
this.fieldVisibility = objects.property(String.class).convention(Constants.DEFAULT_FIELD_VISIBILITY);
@@ -61,10 +66,15 @@ public DefaultAvroExtension(ObjectFactory objects) {
this.optionalGettersForNullableFieldsOnly = objects.property(Boolean.class)
.convention(Constants.DEFAULT_OPTIONAL_GETTERS_FOR_NULLABLE_FIELDS_ONLY);
this.enableDecimalLogicalType = objects.property(Boolean.class).convention(Constants.DEFAULT_ENABLE_DECIMAL_LOGICAL_TYPE);
this.conversionsAndTypeFactoriesClasspath = GradleCompatibility.createConfigurableFileCollection(project);
this.logicalTypeFactories = objects.mapProperty(String.class, Constants.LOGICAL_TYPE_FACTORY_TYPE.getConcreteClass())
.convention(Constants.DEFAULT_LOGICAL_TYPE_FACTORIES);
this.logicalTypeFactoryClassNames = objects.mapProperty(String.class, String.class)
.convention(Constants.DEFAULT_LOGICAL_TYPE_FACTORY_CLASS_NAMES);
this.customConversions =
objects.listProperty(Constants.CONVERSION_TYPE.getConcreteClass()).convention(Constants.DEFAULT_CUSTOM_CONVERSIONS);
this.customConversionClassNames =
objects.listProperty(String.class).convention(Constants.DEFAULT_CUSTOM_CONVERSION_CLASS_NAMES);
}

@Override
@@ -190,43 +200,119 @@ public void setEnableDecimalLogicalType(boolean enableDecimalLogicalType) {
this.enableDecimalLogicalType.set(enableDecimalLogicalType);
}

@Override
public ConfigurableFileCollection getConversionsAndTypeFactoriesClasspath() {
return conversionsAndTypeFactoriesClasspath;
}

/**
* @deprecated use {@link #getLogicalTypeFactoryClassNames()} instead
*/
@Deprecated
@Override
public MapProperty<String, Class<? extends LogicalTypes.LogicalTypeFactory>> getLogicalTypeFactories() {
return logicalTypeFactories;
}

/**
* @deprecated use {@link #setLogicalTypeFactoryClassNames(Provider)} ()} instead
*/
@Deprecated
public void setLogicalTypeFactories(Provider<? extends Map<? extends String,
? extends Class<? extends LogicalTypes.LogicalTypeFactory>>> provider) {
this.logicalTypeFactories.set(provider);
}

/**
* @deprecated use {@link #setLogicalTypeFactoryClassNames(Map)} ()} instead
*/
@Deprecated
public void setLogicalTypeFactories(Map<? extends String,
? extends Class<? extends LogicalTypes.LogicalTypeFactory>> logicalTypeFactories) {
this.logicalTypeFactories.set(logicalTypeFactories);
}

@Override
public MapProperty<String, String> getLogicalTypeFactoryClassNames() {
return logicalTypeFactoryClassNames;
}

public void setLogicalTypeFactoryClassNames(Provider<? extends Map<? extends String,
? extends String>> provider) {
this.logicalTypeFactoryClassNames.set(provider);
}

public void setLogicalTypeFactoryClassNames(Map<? extends String,
? extends String> logicalTypeFactoryClassNames) {
this.logicalTypeFactoryClassNames.set(logicalTypeFactoryClassNames);
}

/**
* @deprecated use {@link #getCustomConversionClassNames()} instead
*/
@Deprecated
@Override
public ListProperty<Class<? extends Conversion<?>>> getCustomConversions() {
return customConversions;
}

/**
* @deprecated use {@link #setCustomConversionClassNames(Provider)} ()} instead
*/
@Deprecated
public void setCustomConversions(Provider<Iterable<Class<? extends Conversion<?>>>> provider) {
this.customConversions.set(provider);
}

/**
* @deprecated use {@link #setCustomConversionClassNames(Iterable)} instead
*/
@Deprecated
public void setCustomConversions(Iterable<Class<? extends Conversion<?>>> customConversions) {
this.customConversions.set(customConversions);
}

public ListProperty<String> getCustomConversionClassNames() {
return customConversionClassNames;
}

public void setCustomConversionClassNames(Provider<Iterable<String>> provider) {
this.customConversionClassNames.set(provider);
}

public void setCustomConversionClassNames(Iterable<String> customConversionClassNames) {
this.customConversionClassNames.set(customConversionClassNames);
}

/**
* @deprecated use {@link #logicalTypeFactory(String, String)} ()} instead
*/
@Deprecated
@Override
public AvroExtension logicalTypeFactory(String typeName, Class<? extends LogicalTypes.LogicalTypeFactory> typeFactoryClass) {
logicalTypeFactories.put(typeName, typeFactoryClass);
return this;
}

@Override
public AvroExtension logicalTypeFactory(String typeName, String typeFactoryClassName) {
logicalTypeFactoryClassNames.put(typeName, typeFactoryClassName);
return this;
}

/**
* @deprecated use {@link #customConversion(String)} ()} instead
*/
@Deprecated
@Override
public AvroExtension customConversion(Class<? extends Conversion<?>> conversionClass) {
customConversions.add(conversionClass);
return this;
}

@Override
public AvroExtension customConversion(String conversionClassName) {
customConversionClassNames.add(conversionClassName);
return this;
}
}
Loading