-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Android support in gradle plugin (fix issue 266)
Previously the `java` plugin was automatically applied when configuring the task dependencies. This was not compatible with the `android` plugin. Now this plugin will inspect the build to determine the right configuration to target. Added the example provided by @samskiter that demonstrated the bug and now shows a working sample.
- Loading branch information
Showing
36 changed files
with
715 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.gradle | ||
/local.properties | ||
/.idea/workspace.xml | ||
/.idea/libraries | ||
.DS_Store | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
The Android SDK is required to build this project. After installing the Android | ||
Studio, add a `local.properties` file with the path to the SDK. For example, | ||
`sdk.dir=/Users/<user>/Library/Android/sdk/` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
131 changes: 131 additions & 0 deletions
131
jsonschema2pojo-gradle-plugin/example/android/app/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
apply plugin: 'com.android.application' | ||
apply plugin: 'jsonschema2pojo' | ||
|
||
buildscript { | ||
repositories { | ||
jcenter() | ||
mavenLocal() | ||
} | ||
dependencies { | ||
classpath 'org.jsonschema2pojo:jsonschema2pojo-gradle-plugin:latest.integration' | ||
} | ||
} | ||
|
||
android { | ||
compileSdkVersion 21 | ||
buildToolsVersion "21.1.2" | ||
|
||
defaultConfig { | ||
applicationId "jsonschema2pojo.joelittlejohn.github.com.androidexample" | ||
minSdkVersion 17 | ||
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. <strong>Be warned</strong>, when activated this option | ||
// will cause jsonschema2pojo to <strong>indiscriminately delete the entire contents of the target | ||
// directory (all files and folders)</strong> 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 | ||
} |
17 changes: 17 additions & 0 deletions
17
jsonschema2pojo-gradle-plugin/example/android/app/proguard-rules.pro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in /Users/sduke/Android-SDK/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 *; | ||
#} |
15 changes: 15 additions & 0 deletions
15
...oidTest/java/jsonschema2pojo/joelittlejohn/github/com/androidexample/ApplicationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package jsonschema2pojo.joelittlejohn.github.com.androidexample; | ||
|
||
import android.app.Application; | ||
import android.test.ApplicationTestCase; | ||
|
||
/** | ||
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a> | ||
*/ | ||
public class ApplicationTest extends ApplicationTestCase<Application> | ||
{ | ||
public ApplicationTest() | ||
{ | ||
super(Application.class); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
jsonschema2pojo-gradle-plugin/example/android/app/src/main/AndroidManifest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="jsonschema2pojo.joelittlejohn.github.com.androidexample" > | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:theme="@style/AppTheme" > | ||
<activity | ||
android:name=".MainActivity" | ||
android:label="@string/app_name" > | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
44 changes: 44 additions & 0 deletions
44
...p/src/main/java/jsonschema2pojo/joelittlejohn/github/com/androidexample/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package jsonschema2pojo.joelittlejohn.github.com.androidexample; | ||
|
||
import android.support.v7.app.ActionBarActivity; | ||
import android.os.Bundle; | ||
import android.view.Menu; | ||
import android.view.MenuItem; | ||
|
||
|
||
public class MainActivity extends ActionBarActivity | ||
{ | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) | ||
{ | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
} | ||
|
||
|
||
@Override | ||
public boolean onCreateOptionsMenu(Menu menu) | ||
{ | ||
// Inflate the menu; this adds items to the action bar if it is present. | ||
getMenuInflater().inflate(R.menu.menu_main, menu); | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean onOptionsItemSelected(MenuItem item) | ||
{ | ||
// Handle action bar item clicks here. The action bar will | ||
// automatically handle clicks on the Home/Up button, so long | ||
// as you specify a parent activity in AndroidManifest.xml. | ||
int id = item.getItemId(); | ||
|
||
//noinspection SimplifiableIfStatement | ||
if (id == R.id.action_settings) | ||
{ | ||
return true; | ||
} | ||
|
||
return super.onOptionsItemSelected(item); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
jsonschema2pojo-gradle-plugin/example/android/app/src/main/res/layout/activity_main.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:paddingLeft="@dimen/activity_horizontal_margin" | ||
android:paddingRight="@dimen/activity_horizontal_margin" | ||
android:paddingTop="@dimen/activity_vertical_margin" | ||
android:paddingBottom="@dimen/activity_vertical_margin" | ||
tools:context=".MainActivity"> | ||
|
||
<TextView | ||
android:text="@string/hello_world" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content"/> | ||
|
||
</RelativeLayout> |
9 changes: 9 additions & 0 deletions
9
jsonschema2pojo-gradle-plugin/example/android/app/src/main/res/menu/menu_main.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<menu xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
tools:context=".MainActivity"> | ||
<item android:id="@+id/action_settings" | ||
android:title="@string/action_settings" | ||
android:orderInCategory="100" | ||
app:showAsAction="never"/> | ||
</menu> |
Binary file added
BIN
+3.34 KB
...pojo-gradle-plugin/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.15 KB
...pojo-gradle-plugin/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.73 KB
...ojo-gradle-plugin/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+7.54 KB
...jo-gradle-plugin/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions
6
jsonschema2pojo-gradle-plugin/example/android/app/src/main/res/values-w820dp/dimens.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<resources> | ||
<!-- Example customization of dimensions originally defined in res/values/dimens.xml | ||
(such as screen margins) for screens with more than 820dp of available width. This | ||
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). --> | ||
<dimen name="activity_horizontal_margin">64dp</dimen> | ||
</resources> |
5 changes: 5 additions & 0 deletions
5
jsonschema2pojo-gradle-plugin/example/android/app/src/main/res/values/dimens.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<resources> | ||
<!-- Default screen margins, per the Android Design guidelines. --> | ||
<dimen name="activity_horizontal_margin">16dp</dimen> | ||
<dimen name="activity_vertical_margin">16dp</dimen> | ||
</resources> |
6 changes: 6 additions & 0 deletions
6
jsonschema2pojo-gradle-plugin/example/android/app/src/main/res/values/strings.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<resources> | ||
<string name="app_name">AndroidExample</string> | ||
|
||
<string name="hello_world">Hello world!</string> | ||
<string name="action_settings">Settings</string> | ||
</resources> |
8 changes: 8 additions & 0 deletions
8
jsonschema2pojo-gradle-plugin/example/android/app/src/main/res/values/styles.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<resources> | ||
|
||
<!-- Base application theme. --> | ||
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> | ||
<!-- Customize your theme here. --> | ||
</style> | ||
|
||
</resources> |
19 changes: 19 additions & 0 deletions
19
jsonschema2pojo-gradle-plugin/example/android/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Top-level build file where you can add configuration options common to all sub-projects/modules. | ||
|
||
buildscript { | ||
repositories { | ||
jcenter() | ||
} | ||
dependencies { | ||
classpath 'com.android.tools.build:gradle:1.1.0' | ||
|
||
// NOTE: Do not place your application dependencies here; they belong | ||
// in the individual module build.gradle files | ||
} | ||
} | ||
|
||
allprojects { | ||
repositories { | ||
jcenter() | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
jsonschema2pojo-gradle-plugin/example/android/gradle.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Project-wide Gradle settings. | ||
|
||
# IDE (e.g. Android Studio) users: | ||
# Gradle settings configured through the IDE *will override* | ||
# any settings specified in this file. | ||
|
||
# For more details on how to configure your build environment visit | ||
# http://www.gradle.org/docs/current/userguide/build_environment.html | ||
|
||
# Specifies the JVM arguments used for the daemon process. | ||
# The setting is particularly useful for tweaking memory settings. | ||
# Default value: -Xmx10248m -XX:MaxPermSize=256m | ||
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 | ||
|
||
# When configured, Gradle will run in incubating parallel mode. | ||
# This option should only be used with decoupled projects. More details, visit | ||
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects | ||
# org.gradle.parallel=true |
Binary file added
BIN
+48.7 KB
jsonschema2pojo-gradle-plugin/example/android/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
6 changes: 6 additions & 0 deletions
6
jsonschema2pojo-gradle-plugin/example/android/gradle/wrapper/gradle-wrapper.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#Wed Apr 10 15:27:10 PDT 2013 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip |
File renamed without changes.
File renamed without changes.
Oops, something went wrong.