Skip to content

Commit 373f544

Browse files
committed
Merge branch 'feature/gradle-plugin'
2 parents b09e5d1 + 1ae30d7 commit 373f544

File tree

140 files changed

+1913
-1245
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

140 files changed

+1913
-1245
lines changed

.classpath

Lines changed: 0 additions & 8 deletions
This file was deleted.

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@ target
22
.idea
33
.DS_Store
44
*.iml
5+
.gradle
6+
build
7+
out

.project

Lines changed: 0 additions & 23 deletions
This file was deleted.

.settings/com.wdev91.eclipse.copyright.xml

Lines changed: 0 additions & 45 deletions
This file was deleted.

.settings/org.eclipse.jdt.ui.prefs

Lines changed: 0 additions & 3 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
11
Android ContentProvider Generator Changelog
22
===========================================
33

4+
v1.12.0 (2017-02-06)
5+
------
6+
This is a somewhat big update in the way the tool is used, and there are also a few syntax differences.
7+
8+
- New **Gradle plugin**, and this is now the preferred way to generate the code.
9+
- The config `syntaxVersion` for this release is **4**. This means you **must** update your `_config.json` file.
10+
- Syntax updates:
11+
- `projectPackageId` is renamed to `packageName` to avoid confusion and match the term used here: https://developer.android.com/studio/build/application-id.html.
12+
- `sqliteOpenHelperCallbacksClassName` is now optional. If omitted, `BaseSQLiteOpenHelperCallbacks` is used in the generated code. If present, it must reference an existing class in your project (it will not be generated), that extends `BaseSQLiteOpenHelperCallbacks`.
13+
- `sqliteOpenHelperClassName`, `enableForeignKeys`, `useAnnotations`, `useSupportLibrary` and `generateBeans` are now optional and will assume default values if omitted.
14+
- The CLI tool still exists but its name has changed (now `acpg-cli-<version>.jar`).
15+
- Other internal changes that as a user, you needn't care about:
16+
- Use of Gradle instead of Maven.
17+
- Module separation (lib, cli, gradle-plugin).
18+
- Use of Jackson to parse the json files.
19+
- Use of Log4J to output logs.
20+
421
v1.11.0 (2016-11-12)
522
------
623
- Beans generation (if new `generateBeans` boolean parameter in config is true) - fix for issue #43.

README.md

Lines changed: 122 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
Android ContentProvider Generator
2-
=================================
1+
Android ContentProvider Generator (acpg)
2+
========================================
33

4-
A tool to generate an Android ContentProvider.
4+
[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-Android%20ContentProvider%20Generator-brightgreen.svg?style=plastic)](https://android-arsenal.com/details/1/111)
5+
6+
A tool to generate Android ContentProviders.
57
It takes a set of entity (a.k.a "table") definitions as the input, and generates:
68
- a `ContentProvider` class
7-
- a `SQLiteOpenHelper` class
8-
- a `SQLiteOpenHelperCallbacks` class
9+
- an `SQLiteOpenHelper` class
910
- one `Columns` class per entity
1011
- one `Cursor` class per entity
1112
- one `ContentValues` class per entity
@@ -14,32 +15,130 @@ It takes a set of entity (a.k.a "table") definitions as the input, and generates
1415
- one `Bean` class per entity (optionally)
1516

1617

17-
How to use
18-
----------
18+
Usage
19+
-----
20+
21+
There are two possible ways to generate the code:
22+
23+
1. as part of the build script (with a Gradle plugin)
24+
2. as a one-time step (using a command line tool)
25+
26+
The Gradle plugin is perhaps the 'cleaner' way in the sense that the generated
27+
code won't be part of the source (not checked into VCS). The configuration is declared inside
28+
the Gradle script which allows to update it easily.
29+
30+
Alternatively, a one-time generation can be done (typically at the beginning of the project.)
31+
The generated code is part of the source and checked into VCS: this allows you
32+
to modify it if you need to.
33+
34+
You can decide which option is the best for your project :)
35+
36+
37+
### Option 1: Gradle plugin
38+
39+
Add this to your app's `build.gradle`:
40+
```groovy
41+
buildscript {
42+
dependencies {
43+
classpath "org.jraf:acpg-gradle-plugin:1.12.0"
44+
}
45+
}
46+
47+
apply plugin: 'org.jraf.acpg.gradleplugin'
48+
49+
(...)
50+
51+
// This is where you declare a few parameters used to generate the code
52+
acpg {
53+
// Where to find the entity files (see 'Entity files' below)
54+
// Optional - default value: 'etc/acpg' in the root project
55+
entitiesDir file('etc/acpg-entities')
56+
57+
// Java package in which all the code will be generated
58+
providerJavaPackage 'com.example.app.provider'
59+
60+
// ContentProvider authority
61+
// "${applicationId}" will be substituted by BuildConfig.APPLICATION_ID in the generated code
62+
authority '${applicationId}.provider'
63+
64+
// Name of the provider class
65+
providerClassName 'ExampleProvider'
66+
67+
// Name of the db file
68+
databaseFileName 'example.db'
69+
70+
// Version of the db
71+
databaseVersion 1
72+
73+
// Name of the SQLiteOpenHelper class
74+
// Optional - default value: providerClassName + "SQLiteOpenHelper"
75+
sqliteOpenHelperClassName 'ExampleSQLiteOpenHelper'
76+
77+
// Name of a subclass of BaseSQLiteOpenHelperCallbacks
78+
// Optional - this allows you to get called when the db is opened/created/upgraded
79+
sqliteOpenHelperCallbacksClassName 'ExampleSQLiteOpenHelperCallbacks'
80+
81+
// Whether to enable foreign keys support (see 'Advanced usage' below)
82+
// Optional - default value: false
83+
enableForeignKeys true
84+
85+
// Whether @Nullable/@NonNull annotations will be used in the generated code
86+
// Optional - default value: false
87+
useAnnotations true
88+
89+
// Whether support library classes are used or the Android SDK ones (e.g. CursorLoader)
90+
// Optional - default value: false
91+
useSupportLibrary true
1992
20-
### The `_config.json` file
93+
// Whether to generate a 'Beans' class for each entity
94+
// Optional - default value: true
95+
generateBeans true
96+
97+
// Version of the tool syntax (must be 4)
98+
// The allows to break the build immediately if an incompatible version of the tool is used. Safety first!
99+
// Optional - default value: 4
100+
syntaxVersion 4
101+
}
102+
```
21103

22-
This is where you declare a few parameters that will be used to generate the code.
23104

24-
These are self-explanatory so here is an example:
105+
### Option 2: Command line tool
106+
107+
The configuration is the same, except you declare it in a file named `_config.json`
108+
in the same folder as the entity files.
109+
110+
Here is an example:
25111
```json
26112
{
27-
"syntaxVersion": 3,
28-
"projectPackageId": "com.example.app",
29-
"authority": "com.example.app.provider",
113+
"syntaxVersion": 4,
114+
"packageName": "com.example.app",
30115
"providerJavaPackage": "com.example.app.provider",
116+
"authority": "${applicationId}.provider",
31117
"providerClassName": "ExampleProvider",
32-
"sqliteOpenHelperClassName": "ExampleSQLiteOpenHelper",
33-
"sqliteOpenHelperCallbacksClassName": "ExampleSQLiteOpenHelperCallbacks",
34118
"databaseFileName": "example.db",
35119
"databaseVersion": 1,
120+
"sqliteOpenHelperClassName": "ExampleSQLiteOpenHelper",
121+
"sqliteOpenHelperCallbacksClassName": "ExampleSQLiteOpenHelperCallbacks",
36122
"enableForeignKeys": true,
37123
"useAnnotations": true,
38124
"useSupportLibrary": true,
39125
"generateBeans": true
40126
}
41127
```
42128

129+
About `packageName`: this must be the same as the value of the `package` attribute in your manifest.
130+
Not to be confused with the `applicationId` (see https://developer.android.com/studio/build/application-id.html)
131+
132+
#### Get and run the tool
133+
134+
Download the `acpg-cli-1.12.0.jar` file here:
135+
https://github.com/BoD/android-contentprovider-generator/releases/latest
136+
137+
`java -jar acpg-cli-1.12.0.jar -i <input folder> -o <output folder>`
138+
- Input folder: where to find `_config.json` and your entity json files
139+
- Output folder: where the resulting files will be generated
140+
141+
43142
### Entity files
44143

45144
Create one file per entity, naming it `<entity_name>.json`.
@@ -113,26 +212,16 @@ Notes:
113212
- if `documentation` is present the value will be copied in Javadoc blocks in the generated code.
114213
- the `constraints` and `defaultOrder` sections are optional
115214

116-
A more comprehensive sample is available in the [etc/sample](etc/sample) folder.
215+
A more comprehensive sample is available in the [sample-app/etc/acpg](sample-app/etc/acpg) folder.
117216

118-
You can also have a look at the corresponding generated code in the [etc/sample/app](etc/sample/app/src/org/jraf/androidcontentprovidergenerator/sample/provider) folder.
217+
You can have a look at the corresponding generated code in the [etc/sample-generated-code](etc/sample-generated-code) folder.
119218

120219
By convention, you should name your entities and fields in lower case with words separated by '_', like in the example above.
121220

122221
### The `header.txt` file (optional)
123222

124223
If a `header.txt` file is present, its contents will be inserted at the top of every generated file.
125224

126-
### Get the tool
127-
128-
Download the jar from here:
129-
https://github.com/BoD/android-contentprovider-generator/releases/latest
130-
131-
### Run the tool
132-
133-
`java -jar android_contentprovider_generator-1.11.0-bundle.jar -i <input folder> -o <output folder>`
134-
- Input folder: where to find `_config.json` and your entity json files
135-
- Output folder: where the resulting files will be generated
136225

137226
### Use the generated files
138227

@@ -230,22 +319,22 @@ with joins because you will get several columns named `_id` in the results!
230319
Sample
231320
------
232321

233-
A sample is available in the [etc/sample](etc/sample) folder.
322+
A sample is available in the [sample-app](sample-app) folder, with the entities in [sample-app/etc/acpg](sample-app/etc/acpg).
234323

235-
You can have a look at the corresponding generated code in the [etc/sample/app](etc/sample/app/src/org/jraf/androidcontentprovidergenerator/sample/provider) folder.
324+
You can have a look at the corresponding generated code in the [etc/sample-generated-code](etc/sample-generated-code) folder.
236325

237326
Here is the table shema of the sample:
238-
![Table shema of the sample](etc/sample/sample-schema.png?raw=true "The sample")
327+
![Table shema of the sample](etc/sample-schema.png?raw=true "The sample")
239328

240329

241330
Building
242331
--------
243332

244-
You need maven to build this tool.
333+
This is a Gradle project.
245334

246-
`mvn package`
335+
`./gradlew install` to 'install' the Gradle plugin to your local maven repo
247336

248-
This will produce `android_contentprovider_generator-1.11.0-bundle.jar` in the `target` folder.
337+
`./gradlew shadowJar` to build the cli tool
249338

250339

251340
Similar tools

acpg-gradle-plugin/build.gradle

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
description = 'gradle-plugin (Android ContentProvider Generator Gradle Plugin)'
2+
3+
apply plugin: 'groovy'
4+
apply plugin: 'maven-publish'
5+
6+
javadoc.failOnError = false
7+
8+
task sourcesJar(type: Jar, dependsOn: classes) {
9+
classifier = 'sources'
10+
from sourceSets.main.allSource
11+
}
12+
13+
task javadocJar(type: Jar, dependsOn: javadoc) {
14+
classifier = 'javadoc'
15+
from javadoc.destinationDir
16+
}
17+
18+
artifacts {
19+
archives sourcesJar
20+
archives javadocJar
21+
}
22+
23+
dependencies {
24+
compile gradleApi()
25+
compile localGroovy()
26+
compile project(':acpg-lib')
27+
compile 'com.android.tools.build:gradle:2.2.0'
28+
}
29+
30+
// Use "./gradlew install" to deploy the artifacts to your local maven repository

0 commit comments

Comments
 (0)