Skip to content

Commit

Permalink
- New debugLogsFieldName config.
Browse files Browse the repository at this point in the history
- v1.13.0
  • Loading branch information
BoD committed Feb 20, 2017
1 parent ecb6077 commit 32b31fe
Show file tree
Hide file tree
Showing 30 changed files with 184 additions and 39 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Android ContentProvider Generator Changelog
===========================================

v1.13.0 (2017-02-20)
------
- `XyzSelection.getCursorLoader()` now returns loaders of wrapped cursors.
- New `XyzContentValues.notify(boolean)` method to enable/disable notifications.
- New `debugLogsFieldName` attribute to enable/disable debug logging in the generated code.

v1.12.0 (2017-02-06)
------
This is a somewhat big update in the way the tool is used, and there are also a few syntax differences.
Expand Down
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Add this to your app's `build.gradle`:
```groovy
buildscript {
dependencies {
classpath "org.jraf:acpg-gradle-plugin:1.12.0"
classpath "org.jraf:acpg-gradle-plugin:1.13.0"
}
}
Expand Down Expand Up @@ -94,6 +94,10 @@ acpg {
// Optional - default value: true
generateBeans true
// Name of a boolean field in BuildConfig to enable/disable debug logging in the generated code
// Optional - default value: "DEBUG"
debugLogsFieldName LOG_DEBUG_PROVIDER
// Version of the tool syntax (must be 4)
// The allows to break the build immediately if an incompatible version of the tool is used. Safety first!
// Optional - default value: 4
Expand Down Expand Up @@ -122,7 +126,8 @@ Here is an example:
"enableForeignKeys": true,
"useAnnotations": true,
"useSupportLibrary": true,
"generateBeans": true
"generateBeans": true,
"debugLogsFieldName": "LOG_DEBUG_PROVIDER"
}
```

Expand All @@ -131,10 +136,10 @@ Not to be confused with the `applicationId` (see https://developer.android.com/s

#### Get and run the tool

Download the `acpg-cli-1.12.0.jar` file here:
Download the `acpg-cli-1.13.0.jar` file here:
https://github.com/BoD/android-contentprovider-generator/releases/latest

`java -jar acpg-cli-1.12.0.jar -i <input folder> -o <output folder>`
`java -jar acpg-cli-1.13.0.jar -i <input folder> -o <output folder>`
- Input folder: where to find `_config.json` and your entity json files
- Output folder: where the resulting files will be generated

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,8 @@ class AcpgPluginExtension {
def generateBeans(boolean generateBeans) {
config.generateBeans = generateBeans
}

def debugLogsFieldName(String debugLogsFieldName) {
config.debugLogsFieldName = debugLogsFieldName
}
}
5 changes: 4 additions & 1 deletion acpg-lib/src/main/java/org/jraf/acpg/lib/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class Config implements Serializable, Cloneable {
public Boolean useAnnotations;
public Boolean useSupportLibrary;
public Boolean generateBeans;
public String debugLogsFieldName;

@Override
public Object clone() throws CloneNotSupportedException {
Expand Down Expand Up @@ -67,7 +68,8 @@ public boolean equals(Object o) {
if (enableForeignKeys != null ? !enableForeignKeys.equals(config.enableForeignKeys) : config.enableForeignKeys != null) return false;
if (useAnnotations != null ? !useAnnotations.equals(config.useAnnotations) : config.useAnnotations != null) return false;
if (useSupportLibrary != null ? !useSupportLibrary.equals(config.useSupportLibrary) : config.useSupportLibrary != null) return false;
return generateBeans != null ? generateBeans.equals(config.generateBeans) : config.generateBeans == null;
if (generateBeans != null ? !generateBeans.equals(config.generateBeans) : config.generateBeans != null) return false;
return debugLogsFieldName != null ? debugLogsFieldName.equals(config.debugLogsFieldName) : config.debugLogsFieldName == null;
}

@Override
Expand All @@ -85,6 +87,7 @@ public int hashCode() {
result = 31 * result + (useAnnotations != null ? useAnnotations.hashCode() : 0);
result = 31 * result + (useSupportLibrary != null ? useSupportLibrary.hashCode() : 0);
result = 31 * result + (generateBeans != null ? generateBeans.hashCode() : 0);
result = 31 * result + (debugLogsFieldName != null ? debugLogsFieldName.hashCode() : 0);
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ public void validateConfig(Config config) throws GeneratorException {
LOG.info("'generateBeans' not set in configuration: assuming true.");
config.generateBeans = true;
}
if (config.debugLogsFieldName == null) {
LOG.info("'debugLogsFieldName' not set in configuration: assuming 'DEBUG'.");
config.debugLogsFieldName = "DEBUG";
}
}

private void ensureNotNull(Object value, String fieldName) throws GeneratorException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,30 @@ public class BaseSQLiteOpenHelperCallbacks {
* @see android.database.sqlite.SQLiteOpenHelper#onOpen(SQLiteDatabase) onOpen
*/
public void onOpen(Context context, SQLiteDatabase db) {
if (BuildConfig.DEBUG) Log.d(TAG, "onOpen");
if (BuildConfig.${config.debugLogsFieldName}) Log.d(TAG, "onOpen");
}

/**
* Called before the database tables are created.
* @see android.database.sqlite.SQLiteOpenHelper#onCreate(SQLiteDatabase) onCreate
*/
public void onPreCreate(Context context, SQLiteDatabase db) {
if (BuildConfig.DEBUG) Log.d(TAG, "onPreCreate");
if (BuildConfig.${config.debugLogsFieldName}) Log.d(TAG, "onPreCreate");
}

/**
* Called after the database tables have been created.
* @see android.database.sqlite.SQLiteOpenHelper#onCreate(SQLiteDatabase) onCreate
*/
public void onPostCreate(Context context, SQLiteDatabase db) {
if (BuildConfig.DEBUG) Log.d(TAG, "onPostCreate");
if (BuildConfig.${config.debugLogsFieldName}) Log.d(TAG, "onPostCreate");
}

/**
* Called when the database needs to be upgraded.
* @see android.database.sqlite.SQLiteOpenHelper#onUpgrade(Context, SQLiteDatabase, int, int) onUpgrade
*/
public void onUpgrade(final Context context, final SQLiteDatabase db, final int oldVersion, final int newVersion) {
if (BuildConfig.DEBUG) Log.d(TAG, "Upgrading database from version " + oldVersion + " to " + newVersion);
if (BuildConfig.${config.debugLogsFieldName}) Log.d(TAG, "Upgrading database from version " + oldVersion + " to " + newVersion);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import ${config.providerJavaPackage}.${entity.packageName}.${entity.nameCamelCas
public class ${config.providerClassName} extends BaseContentProvider {
private static final String TAG = ${config.providerClassName}.class.getSimpleName();

private static final boolean DEBUG = BuildConfig.DEBUG;
private static final boolean DEBUG = BuildConfig.${config.debugLogsFieldName};

private static final String TYPE_CURSOR_ITEM = "vnd.android.cursor.item/";
private static final String TYPE_CURSOR_DIR = "vnd.android.cursor.dir/";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public class ${config.sqliteOpenHelperClassName} extends SQLiteOpenHelper {

@Override
public void onCreate(SQLiteDatabase db) {
if (BuildConfig.DEBUG) Log.d(TAG, "onCreate");
if (BuildConfig.${config.debugLogsFieldName}) Log.d(TAG, "onCreate");
mOpenHelperCallbacks.onPreCreate(mContext, db);
<#list model.entities as entity>
db.execSQL(SQL_CREATE_TABLE_${entity.nameUpperCase});
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ allprojects {
apply plugin: 'maven'

group = 'org.jraf'
version = '1.12.0'
version = '1.13.0'

repositories {
mavenLocal()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
public class SampleProvider extends BaseContentProvider {
private static final String TAG = SampleProvider.class.getSimpleName();

private static final boolean DEBUG = BuildConfig.DEBUG;
private static final boolean DEBUG = BuildConfig.LOG_DEBUG_PROVIDER;

private static final String TYPE_CURSOR_ITEM = "vnd.android.cursor.item/";
private static final String TYPE_CURSOR_DIR = "vnd.android.cursor.dir/";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ private SampleSQLiteOpenHelper(Context context, DatabaseErrorHandler errorHandle

@Override
public void onCreate(SQLiteDatabase db) {
if (BuildConfig.DEBUG) Log.d(TAG, "onCreate");
if (BuildConfig.LOG_DEBUG_PROVIDER) Log.d(TAG, "onCreate");
mOpenHelperCallbacks.onPreCreate(mContext, db);
db.execSQL(SQL_CREATE_TABLE_COMPANY);
db.execSQL(SQL_CREATE_INDEX_COMPANY_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,29 @@
import android.net.Uri;

@SuppressWarnings("unused")
public abstract class AbstractContentValues {
public abstract class AbstractContentValues<T extends AbstractContentValues<?>> {
protected final ContentValues mContentValues = new ContentValues();
private Boolean mNotify;

/**
* Returns the {@code uri} argument to pass to the {@code ContentResolver} methods.
*/
public abstract Uri uri();
protected abstract Uri baseUri();

/**
* Returns the {@code uri} argument to pass to the {@code ContentResolver} methods.
*/
public Uri uri() {
Uri uri = baseUri();
if (mNotify != null) uri = BaseContentProvider.notify(uri, mNotify);
return uri;
}

@SuppressWarnings("unchecked")
public T notify(boolean notify) {
mNotify = notify;
return (T) this;
}

/**
* Returns the {@code ContentValues} wrapped by this object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,9 +421,7 @@ public int count(Context context) {
* @param projection The projection to use.
* @return The CursorLoader.
*/
public CursorLoader getCursorLoader(Context context, String[] projection) {
return new CursorLoader(context, uri(), projection, sel(), args(), order());
}
public abstract CursorLoader getCursorLoader(Context context, String[] projection);

/**
* Returns a {@code CursorLoader} based on this selection, with a {@code null} (all columns) selection.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,30 +43,30 @@ public class BaseSQLiteOpenHelperCallbacks {
* @see android.database.sqlite.SQLiteOpenHelper#onOpen(SQLiteDatabase) onOpen
*/
public void onOpen(Context context, SQLiteDatabase db) {
if (BuildConfig.DEBUG) Log.d(TAG, "onOpen");
if (BuildConfig.LOG_DEBUG_PROVIDER) Log.d(TAG, "onOpen");
}

/**
* Called before the database tables are created.
* @see android.database.sqlite.SQLiteOpenHelper#onCreate(SQLiteDatabase) onCreate
*/
public void onPreCreate(Context context, SQLiteDatabase db) {
if (BuildConfig.DEBUG) Log.d(TAG, "onPreCreate");
if (BuildConfig.LOG_DEBUG_PROVIDER) Log.d(TAG, "onPreCreate");
}

/**
* Called after the database tables have been created.
* @see android.database.sqlite.SQLiteOpenHelper#onCreate(SQLiteDatabase) onCreate
*/
public void onPostCreate(Context context, SQLiteDatabase db) {
if (BuildConfig.DEBUG) Log.d(TAG, "onPostCreate");
if (BuildConfig.LOG_DEBUG_PROVIDER) Log.d(TAG, "onPostCreate");
}

/**
* Called when the database needs to be upgraded.
* @see android.database.sqlite.SQLiteOpenHelper#onUpgrade(Context, SQLiteDatabase, int, int) onUpgrade
*/
public void onUpgrade(final Context context, final SQLiteDatabase db, final int oldVersion, final int newVersion) {
if (BuildConfig.DEBUG) Log.d(TAG, "Upgrading database from version " + oldVersion + " to " + newVersion);
if (BuildConfig.LOG_DEBUG_PROVIDER) Log.d(TAG, "Upgrading database from version " + oldVersion + " to " + newVersion);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
* Content values wrapper for the {@code company} table.
*/
@SuppressWarnings({"ConstantConditions", "unused"})
public class CompanyContentValues extends AbstractContentValues {
public class CompanyContentValues extends AbstractContentValues<CompanyContentValues> {
@Override
public Uri uri() {
protected Uri baseUri() {
return CompanyColumns.CONTENT_URI;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import android.content.ContentResolver;
import android.database.Cursor;
import android.net.Uri;
import android.support.v4.content.CursorLoader;

import org.jraf.androidcontentprovidergenerator.sample.provider.base.AbstractSelection;
import org.jraf.androidcontentprovidergenerator.sample.provider.serialnumber.*;
Expand Down Expand Up @@ -86,6 +87,20 @@ public CompanyCursor query(Context context) {
}


/**
* {@inheritDoc}
*/
@Override
public CursorLoader getCursorLoader(Context context, String[] projection) {
return new CursorLoader(context, uri(), projection, sel(), args(), order()) {
@Override
public Cursor loadInBackground() {
return new CompanyCursor(super.loadInBackground());
}
};
}


public CompanySelection id(long... value) {
addEquals("company." + CompanyColumns._ID, toObjectArray(value));
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
* Content values wrapper for the {@code manual} table.
*/
@SuppressWarnings({"ConstantConditions", "unused"})
public class ManualContentValues extends AbstractContentValues {
public class ManualContentValues extends AbstractContentValues<ManualContentValues> {
@Override
public Uri uri() {
protected Uri baseUri() {
return ManualColumns.CONTENT_URI;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import android.content.ContentResolver;
import android.database.Cursor;
import android.net.Uri;
import android.support.v4.content.CursorLoader;

import org.jraf.androidcontentprovidergenerator.sample.provider.base.AbstractSelection;

Expand Down Expand Up @@ -85,6 +86,20 @@ public ManualCursor query(Context context) {
}


/**
* {@inheritDoc}
*/
@Override
public CursorLoader getCursorLoader(Context context, String[] projection) {
return new CursorLoader(context, uri(), projection, sel(), args(), order()) {
@Override
public Cursor loadInBackground() {
return new ManualCursor(super.loadInBackground());
}
};
}


public ManualSelection id(long... value) {
addEquals("manual." + ManualColumns._ID, toObjectArray(value));
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
* Content values wrapper for the {@code person} table.
*/
@SuppressWarnings({"ConstantConditions", "unused"})
public class PersonContentValues extends AbstractContentValues {
public class PersonContentValues extends AbstractContentValues<PersonContentValues> {
@Override
public Uri uri() {
protected Uri baseUri() {
return PersonColumns.CONTENT_URI;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import android.content.ContentResolver;
import android.database.Cursor;
import android.net.Uri;
import android.support.v4.content.CursorLoader;

import org.jraf.androidcontentprovidergenerator.sample.provider.base.AbstractSelection;

Expand Down Expand Up @@ -85,6 +86,20 @@ public PersonCursor query(Context context) {
}


/**
* {@inheritDoc}
*/
@Override
public CursorLoader getCursorLoader(Context context, String[] projection) {
return new CursorLoader(context, uri(), projection, sel(), args(), order()) {
@Override
public Cursor loadInBackground() {
return new PersonCursor(super.loadInBackground());
}
};
}


public PersonSelection id(long... value) {
addEquals("person." + PersonColumns._ID, toObjectArray(value));
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
* Content values wrapper for the {@code person_team} table.
*/
@SuppressWarnings({"ConstantConditions", "unused"})
public class PersonTeamContentValues extends AbstractContentValues {
public class PersonTeamContentValues extends AbstractContentValues<PersonTeamContentValues> {
@Override
public Uri uri() {
protected Uri baseUri() {
return PersonTeamColumns.CONTENT_URI;
}

Expand Down
Loading

0 comments on commit 32b31fe

Please sign in to comment.