From 47f1101d3b50782fd035d2ccd2b7f5e515fe8db6 Mon Sep 17 00:00:00 2001 From: Yoann Mikami Date: Fri, 13 Mar 2015 19:11:31 +0900 Subject: [PATCH 1/2] Added Android library sample module (Issue #305) --- .../example/android/lib/.gitignore | 1 + .../example/android/lib/build.gradle | 128 ++++++++++++++++++ .../example/android/lib/proguard-rules.pro | 17 +++ .../android/lib/src/main/AndroidManifest.xml | 4 + .../androidlibexample/AndroidLibExample.java | 4 + .../example/android/settings.gradle | 2 +- 6 files changed, 155 insertions(+), 1 deletion(-) create mode 100644 jsonschema2pojo-gradle-plugin/example/android/lib/.gitignore create mode 100644 jsonschema2pojo-gradle-plugin/example/android/lib/build.gradle create mode 100644 jsonschema2pojo-gradle-plugin/example/android/lib/proguard-rules.pro create mode 100644 jsonschema2pojo-gradle-plugin/example/android/lib/src/main/AndroidManifest.xml create mode 100644 jsonschema2pojo-gradle-plugin/example/android/lib/src/main/java/jsonschema2pojo/joelittlejohn/github/com/androidlibexample/AndroidLibExample.java diff --git a/jsonschema2pojo-gradle-plugin/example/android/lib/.gitignore b/jsonschema2pojo-gradle-plugin/example/android/lib/.gitignore new file mode 100644 index 000000000..796b96d1c --- /dev/null +++ b/jsonschema2pojo-gradle-plugin/example/android/lib/.gitignore @@ -0,0 +1 @@ +/build diff --git a/jsonschema2pojo-gradle-plugin/example/android/lib/build.gradle b/jsonschema2pojo-gradle-plugin/example/android/lib/build.gradle new file mode 100644 index 000000000..cf1739e00 --- /dev/null +++ b/jsonschema2pojo-gradle-plugin/example/android/lib/build.gradle @@ -0,0 +1,128 @@ +apply plugin: 'com.android.library' +apply plugin: 'jsonschema2pojo' + +buildscript { + repositories { + jcenter() + mavenLocal() + } + dependencies { + classpath 'org.jsonschema2pojo:jsonschema2pojo-gradle-plugin:latest.integration' + } +} + +android { + compileSdkVersion 21 + buildToolsVersion "21.1.2" + + defaultConfig { + minSdkVersion 15 + targetSdkVersion 21 + versionCode 1 + versionName "1.0" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + compile 'com.android.support:appcompat-v7:21.0.3' +} + +// Each configuration is set to the default value +jsonSchema2Pojo { + // Whether to generate builder-style methods of the form withXxx(value) (that return this), + // alongside the standard, void-return setters. + generateBuilders = false + + // Whether to use primitives (long, double, boolean) instead of wrapper types where possible + // when generating bean properties (has the side-effect of making those properties non-null). + usePrimitives = false + + // Location of the JSON Schema file(s). This may refer to a single file or a directory of files. + //source = files("${sourceSets.main.output.resourcesDir}/json") + source = files("${project.rootDir}/schema") + + // Target directory for generated Java source files. The plugin will add this directory to the + // java source set so the compiler will find and compile the newly generated source files. + targetDirectory = file("${project.rootDir}/build/generated-sources/js2p") + + // Package name used for generated Java classes (for types where a fully qualified name has not + // been supplied in the schema using the 'javaType' property). + targetPackage = 'com.oosocial.clarityn.rest.clarityn.model' + + // The characters that should be considered as word delimiters when creating Java Bean property + // names from JSON property names. If blank or not set, JSON properties will be considered to + // contain a single word when creating Java Bean property names. + propertyWordDelimiters = [] as char[] + + // Whether to use the java type long (or Long) instead of int (or Integer) when representing the + // JSON Schema type 'integer'. + useLongIntegers = false + + // Whether to use the java type double (or Double) instead of float (or Float) when representing + // the JSON Schema type 'number'. + useDoubleNumbers = true + + // Whether to include hashCode and equals methods in generated Java types. + includeHashcodeAndEquals = true + + // Whether to include a toString method in generated Java types. + includeToString = true + + // The style of annotations to use in the generated Java types. Supported values: + // - jackson (alias of jackson2) + // - jackson2 (apply annotations from the Jackson 2.x library) + // - jackson1 (apply annotations from the Jackson 1.x library) + // - gson (apply annotations from the Gson library) + // - none (apply no annotations at all) + annotationStyle = 'gson' + + // A fully qualified class name, referring to a custom annotator class that implements + // org.jsonschema2pojo.NoopAnnotator and will be used in addition to the one chosen + // by annotationStyle. If you want to use the custom annotator alone, set annotationStyle to none. + customAnnotator = 'org.jsonschema2pojo.NoopAnnotator' + + // Whether to include JSR-303/349 annotations (for schema rules like minimum, maximum, etc) in + // generated Java types. Schema rules and the annotation they produce: + // - maximum = @DecimalMax + // - minimum = @DecimalMin + // - minItems,maxItems = @Size + // - minLength,maxLength = @Size + // - pattern = @Pattern + // - required = @NotNull + // Any Java fields which are an object or array of objects will be annotated with @Valid to + // support validation of an entire document tree. + includeJsr303Annotations = true + + // The type of input documents that will be read. Supported values: + // - jsonschema (schema documents, containing formal rules that describe the structure of json data) + // - json (documents that represent an example of the kind of json data that the generated Java types + // will be mapped to) + sourceType = 'jsonschema' + + // Whether to empty the target directory before generation occurs, to clear out all source files + // that have been generated previously. Be warned, when activated this option + // will cause jsonschema2pojo to indiscriminately delete the entire contents of the target + // directory (all files and folders) before it begins generating sources. + boolean removeOldOutput = true + + // The character encoding that should be used when writing the generated Java source files + String outputEncoding = 'UTF-8' + + // Whether to use {@link org.joda.time.DateTime} instead of {@link java.util.Date} when adding + // date type fields to generated Java types. + boolean useJodaDates = false + + // Whether to use commons-lang 3.x imports instead of commons-lang 2.x imports when adding equals, + // hashCode and toString methods. + boolean useCommonsLang3 = false + + // Whether to initialize Set and List fields as empty collections, or leave them as null. + boolean initializeCollections = true +} diff --git a/jsonschema2pojo-gradle-plugin/example/android/lib/proguard-rules.pro b/jsonschema2pojo-gradle-plugin/example/android/lib/proguard-rules.pro new file mode 100644 index 000000000..1fd753b4a --- /dev/null +++ b/jsonschema2pojo-gradle-plugin/example/android/lib/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in /opt/android/android-sdk-linux/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/jsonschema2pojo-gradle-plugin/example/android/lib/src/main/AndroidManifest.xml b/jsonschema2pojo-gradle-plugin/example/android/lib/src/main/AndroidManifest.xml new file mode 100644 index 000000000..1910d3108 --- /dev/null +++ b/jsonschema2pojo-gradle-plugin/example/android/lib/src/main/AndroidManifest.xml @@ -0,0 +1,4 @@ + + + + diff --git a/jsonschema2pojo-gradle-plugin/example/android/lib/src/main/java/jsonschema2pojo/joelittlejohn/github/com/androidlibexample/AndroidLibExample.java b/jsonschema2pojo-gradle-plugin/example/android/lib/src/main/java/jsonschema2pojo/joelittlejohn/github/com/androidlibexample/AndroidLibExample.java new file mode 100644 index 000000000..2b21a8694 --- /dev/null +++ b/jsonschema2pojo-gradle-plugin/example/android/lib/src/main/java/jsonschema2pojo/joelittlejohn/github/com/androidlibexample/AndroidLibExample.java @@ -0,0 +1,4 @@ +package jsonschema2pojo.joelittlejohn.github.com.androidlibexample; + +public final class AndroidLibExample { +} \ No newline at end of file diff --git a/jsonschema2pojo-gradle-plugin/example/android/settings.gradle b/jsonschema2pojo-gradle-plugin/example/android/settings.gradle index e7b4def49..3cbe24935 100644 --- a/jsonschema2pojo-gradle-plugin/example/android/settings.gradle +++ b/jsonschema2pojo-gradle-plugin/example/android/settings.gradle @@ -1 +1 @@ -include ':app' +include ':app', ':lib' From 0107b93761f014b17368131959b82d5f4b03a131 Mon Sep 17 00:00:00 2001 From: Yoann Mikami Date: Mon, 16 Mar 2015 18:12:45 +0900 Subject: [PATCH 2/2] Added support for Android library plugin (Issue #305) --- .../org/jsonschema2pojo/gradle/GenerateJsonSchemaTask.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jsonschema2pojo-gradle-plugin/src/main/groovy/org/jsonschema2pojo/gradle/GenerateJsonSchemaTask.groovy b/jsonschema2pojo-gradle-plugin/src/main/groovy/org/jsonschema2pojo/gradle/GenerateJsonSchemaTask.groovy index aadd2f16c..9dd978df3 100644 --- a/jsonschema2pojo-gradle-plugin/src/main/groovy/org/jsonschema2pojo/gradle/GenerateJsonSchemaTask.groovy +++ b/jsonschema2pojo-gradle-plugin/src/main/groovy/org/jsonschema2pojo/gradle/GenerateJsonSchemaTask.groovy @@ -41,7 +41,7 @@ class GenerateJsonSchemaTask extends DefaultTask { if (project.plugins.hasPlugin('java')) { configureJava() - } else if (project.plugins.hasPlugin('com.android.application')) { + } else if (project.plugins.hasPlugin('com.android.application') || project.plugins.hasPlugin('com.android.library')) { configureAndroid() } else { throw new GradleException('generateJsonSchema: Java or Android plugin required')