Skip to content
This repository has been archived by the owner on Aug 26, 2021. It is now read-only.

Commit

Permalink
Merge branch 'develop' into java-integration-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonycr committed Oct 25, 2018
2 parents ff4677f + 2650e32 commit d3e53be
Show file tree
Hide file tree
Showing 13 changed files with 328 additions and 228 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ jdk:
android:
components:
- tools
- build-tools-27.0.3
- android-27
- build-tools-28.0.3
- android-28
- extra-android-support
- extra-android-m2repository
# workaround for Google changing android-27 package and causing a checksum mismatch
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
Change Log
==========

Version 2.6.0 *(2018-10-25)*
----------------------------
- Improved formatting of generated code.
- Improved logging by putting all debug logging behind the `stagDebug` flag.
- Improve integration of library by switching to new nullability annotations library.
- Wrote unit tests for `KnownTypeAdapters`.
- Fixed bug where code generation was non deterministic by switching to linked versions of `HashSet` and `HashMap`.
- Added support for turning on/off serialization of `null` with `stag.serializeNulls` compiler option. Default is off, which is a behavior change from version 2.5.1.

Version 2.5.1 *(2018-01-17)*
----------------------------
- Fixed bug where types with wildcards caused compilation to fail.
Expand Down
27 changes: 17 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ buildscript {
apply plugin: 'net.ltgt.apt'
dependencies {
def stagVersion = '2.5.1'
def stagVersion = '2.6.0'
compile "com.vimeo.stag:stag-library:$stagVersion"
apt "com.vimeo.stag:stag-library-compiler:$stagVersion"
}
Expand All @@ -45,9 +45,10 @@ dependencies {
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
aptOptions.processorArgs = [
stagAssumeHungarianNotation: "true",
stagGeneratedPackageName : "com.vimeo.sample.stag.generated",
stagDebug : "true"
"stagAssumeHungarianNotation": "true",
"stagGeneratedPackageName" : "com.vimeo.sample.stag.generated",
"stagDebug " : "true",
"stag.serializeNulls" : "true",
]
}
}
Expand All @@ -58,7 +59,7 @@ gradle.projectsEvaluated {
apply plugin: 'kotlin-kapt'
dependencies {
def stagVersion = '2.5.1'
def stagVersion = '2.6.0'
compile "com.vimeo.stag:stag-library:$stagVersion"
kapt "com.vimeo.stag:stag-library-compiler:$stagVersion"
}
Expand All @@ -70,6 +71,7 @@ kapt {
arg("stagDebug", "true")
arg("stagGeneratedPackageName", "com.vimeo.sample.stag.generated")
arg("stagAssumeHungarianNotation", "true")
arg("stag.serializeNulls", "true")
}
}
```
Expand All @@ -78,7 +80,7 @@ kapt {

```groovy
dependencies {
def stagVersion = '2.5.1'
def stagVersion = '2.6.0'
compile "com.vimeo.stag:stag-library:$stagVersion"
annotationProcessor "com.vimeo.stag:stag-library-compiler:$stagVersion"
}
Expand All @@ -91,9 +93,10 @@ android {
javaCompileOptions {
annotationProcessorOptions {
arguments = [
stagAssumeHungarianNotation: 'true'
stagGeneratedPackageName : 'com.vimeo.sample.stag.generated',
stagDebug : 'true'
"stagAssumeHungarianNotation": 'true',
"stagGeneratedPackageName" : 'com.vimeo.sample.stag.generated',
"stagDebug" : 'true',
"stag.serializeNulls" : 'true'
]
}
}
Expand All @@ -112,6 +115,10 @@ android {
Stag will look for members named `set[variable_name]` and `get[variable_name]`. If your member variables are named using Hungarian notation,
then you will need to pass true to this parameter so that for a field named `mField`, Stag will look for `setField` and `getField` instead
of `setMField` and `getMField`. Default is false.
- `stag.serializeNulls`: By default this is set to false. If an object has a null field and you send it to be serialized by Gson, it is optional
whether or not that field is serialized into the JSON. If this field is set to `false` null fields will not be serialized, and if set to `true`,
they will be serialized. Prior to stag version 2.6.0, null fields were always serialized to JSON. This should not affect most models. However, if
you have a model that has a nullable field that also has a non null default value, then it might be a good idea to turn this option on.

## Features

Expand Down Expand Up @@ -249,7 +256,7 @@ class Herd {
* You parse the list from JSON using
* Gson.
*/
MyParsingClass {
class MyParsingClass {
private Gson gson = new GsonBuilder()
.registerTypeAdapterFactory(new Stag.Factory())
.create();
Expand Down
10 changes: 5 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
buildscript {
ext {
kotlinVersion = '1.2.61'
kotlinVersion = '1.2.71'
jacocoVersion = '0.7.9' // See http://www.eclemma.org/jacoco/
gsonVersion = '2.8.2'
assertJ = '3.9.1'

// android dependencies
targetSdk = 27
targetSdk = 28
minSdk = 14
buildTools = "27.0.3"
buildTools = "28.0.3"
}
repositories {
google()
Expand All @@ -17,7 +17,7 @@ buildscript {
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
classpath 'com.dicedmelon.gradle:jacoco-android:0.1.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
Expand All @@ -43,5 +43,5 @@ allprojects {

subprojects {
group = 'com.vimeo.stag'
version = '2.5.1'
version = '2.6.0'
}
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon Apr 09 13:12:02 EDT 2018
#Thu Oct 25 11:29:47 EDT 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
4 changes: 2 additions & 2 deletions integration-test-android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ android {

dependencies {
implementation 'org.jetbrains:annotations-java5:16.0.2@jar'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:support-annotations:27.1.1'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:support-annotations:28.0.0'

implementation project(':stag-library')
annotationProcessor project(':stag-library-compiler')
Expand Down
4 changes: 2 additions & 2 deletions integration-test-java-cross-module/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ apply plugin: "net.ltgt.apt"
dependencies {
implementation "com.google.code.gson:gson:$gsonVersion"
implementation 'org.jetbrains:annotations-java5:16.0.2@jar'
implementation 'com.android.support:support-annotations:27.1.1'
implementation 'com.android.support:support-annotations:28.0.0'

implementation project(':stag-library')
apt project(':stag-library-compiler')
annotationProcessor project(':stag-library-compiler')

implementation project(':integration-test-java')

Expand Down
2 changes: 1 addition & 1 deletion integration-test-java/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ dependencies {
implementation "com.google.code.gson:gson:$gsonVersion"

implementation project(':stag-library')
apt project(':stag-library-compiler')
annotationProcessor project(':stag-library-compiler')

testImplementation 'junit:junit:4.12'
testImplementation 'uk.co.jemos.podam:podam:7.2.0.RELEASE'
Expand Down
2 changes: 1 addition & 1 deletion sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ android {

dependencies {
testImplementation 'junit:junit:4.12'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:appcompat-v7:28.0.0'

implementation project(':stag-library')
annotationProcessor project(':stag-library-compiler')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,14 @@

@AutoService(Processor.class)
@SupportedAnnotationTypes(value = {"com.vimeo.stag.UseStag"})
@SupportedOptions(value = {StagProcessor.OPTION_PACKAGE_NAME, StagProcessor.OPTION_DEBUG, StagProcessor.OPTION_HUNGARIAN_NOTATION})
@SupportedOptions(value = {StagProcessor.OPTION_PACKAGE_NAME, StagProcessor.OPTION_DEBUG, StagProcessor.OPTION_HUNGARIAN_NOTATION, StagProcessor.OPTION_SERIALIZE_NULLS})
@SupportedSourceVersion(SourceVersion.RELEASE_7)
public final class StagProcessor extends AbstractProcessor {

static final String OPTION_DEBUG = "stagDebug";
static final String OPTION_PACKAGE_NAME = "stagGeneratedPackageName";
static final String OPTION_HUNGARIAN_NOTATION = "stagAssumeHungarianNotation";
static final String OPTION_SERIALIZE_NULLS = "stag.serializeNulls";
private static final String DEFAULT_GENERATED_PACKAGE_NAME = "com.vimeo.stag.generated";
private boolean mHasBeenProcessed;

Expand All @@ -98,6 +99,14 @@ private static boolean getAssumeHungarianNotation(@NotNull ProcessingEnvironment
return false;
}

private static boolean isSerializeNullsEnabled(@NotNull ProcessingEnvironment processingEnvironment) {
String debugString = processingEnvironment.getOptions().get(OPTION_SERIALIZE_NULLS);
if (debugString != null) {
return Boolean.valueOf(debugString);
}
return false;
}

@NotNull
private static String getOptionalPackageName(@NotNull ProcessingEnvironment processingEnvironment) {
String packageName = processingEnvironment.getOptions().get(OPTION_PACKAGE_NAME);
Expand Down Expand Up @@ -159,6 +168,7 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
String packageName = getOptionalPackageName(processingEnv);

boolean assumeHungarianNotation = getAssumeHungarianNotation(processingEnv);
boolean enableSerializeNulls = isSerializeNullsEnabled(processingEnv);

TypeUtils.initialize(processingEnv.getTypeUtils());
ElementUtils.initialize(processingEnv.getElementUtils());
Expand Down Expand Up @@ -190,7 +200,7 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
for (AnnotatedClass annotatedClass : supportedTypesModel.getSupportedTypes()) {
TypeElement element = annotatedClass.getElement();
if ((TypeUtils.isConcreteType(element) || TypeUtils.isParameterizedType(element)) && !TypeUtils.isAbstract(element)) {
generateTypeAdapter(supportedTypesModel, element, stagFactoryGenerator);
generateTypeAdapter(supportedTypesModel, element, stagFactoryGenerator, enableSerializeNulls);

ClassInfo classInfo = new ClassInfo(element.asType());
ArrayList<ClassInfo> result = new ArrayList<>();
Expand Down Expand Up @@ -242,13 +252,13 @@ private void generateStagFactory(@NotNull String packageName, List<SubFactoriesI

private void generateTypeAdapter(@NotNull SupportedTypesModel supportedTypesModel,
@NotNull TypeElement element,
@NotNull StagGenerator stagGenerator) throws IOException {
@NotNull StagGenerator stagGenerator, boolean enableSerializeNulls) throws IOException {

ClassInfo classInfo = new ClassInfo(element.asType());

AdapterGenerator independentAdapter = element.getKind() == ElementKind.ENUM ?
new EnumTypeAdapterGenerator(classInfo, element) :
new TypeAdapterGenerator(supportedTypesModel, classInfo);
new TypeAdapterGenerator(supportedTypesModel, classInfo, enableSerializeNulls);

// Create the type spec
TypeSpec typeAdapterSpec = independentAdapter.createTypeAdapterSpec(stagGenerator);
Expand Down
Loading

0 comments on commit d3e53be

Please sign in to comment.