diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2d89f77 --- /dev/null +++ b/.gitignore @@ -0,0 +1,22 @@ +#built files +build/ +out/ +gen/ + +# Local configuration file (sdk path, etc) +local.properties + +# IntelliJ Idea/Android Studio files +*.iml +*.ipr +*.iws +.idea/ + +# Mac system files +.DS_* + +#proguard +proguard_logs/ + +#gradle +.gradle/ diff --git a/Library/build.gradle b/Library/build.gradle new file mode 100644 index 0000000..c6b9c4f --- /dev/null +++ b/Library/build.gradle @@ -0,0 +1,40 @@ +buildscript { + repositories { + mavenCentral() + } + dependencies { + classpath 'com.android.tools.build:gradle:0.8.+' + } +} +apply plugin: 'android-library' + +repositories { + mavenCentral() +} + +android { + compileSdkVersion 19 + buildToolsVersion "19.0.1" + + defaultConfig { + minSdkVersion 7 + targetSdkVersion 19 + } +} + +dependencies { + compile fileTree(dir: 'libs', include: '*.jar') +} + +task clearJar(type: Delete) { + delete 'build/libs/reservoir-1.0.jar' +} + +task makeJar(type: Copy) { + from('build/bundles/debug/') + into('build/libs/') + include('classes.jar') + rename ('classes.jar', 'reservoir-1.0.jar') +} + +makeJar.dependsOn(clearJar, build) diff --git a/Library/libs/commons-io-2.4.jar b/Library/libs/commons-io-2.4.jar new file mode 100644 index 0000000..90035a4 Binary files /dev/null and b/Library/libs/commons-io-2.4.jar differ diff --git a/Library/libs/disklrucache-2.0.2.jar b/Library/libs/disklrucache-2.0.2.jar new file mode 100644 index 0000000..ca7907d Binary files /dev/null and b/Library/libs/disklrucache-2.0.2.jar differ diff --git a/Library/libs/gson-2.2.4.jar b/Library/libs/gson-2.2.4.jar new file mode 100644 index 0000000..9478253 Binary files /dev/null and b/Library/libs/gson-2.2.4.jar differ diff --git a/Library/src/main/AndroidManifest.xml b/Library/src/main/AndroidManifest.xml new file mode 100644 index 0000000..31c939a --- /dev/null +++ b/Library/src/main/AndroidManifest.xml @@ -0,0 +1,14 @@ + + + + + + + + + diff --git a/Library/src/main/java/com/anupcowkur/reservoir/Reservoir.java b/Library/src/main/java/com/anupcowkur/reservoir/Reservoir.java new file mode 100644 index 0000000..9726d33 --- /dev/null +++ b/Library/src/main/java/com/anupcowkur/reservoir/Reservoir.java @@ -0,0 +1,175 @@ +package com.anupcowkur.reservoir; + +import android.content.Context; +import android.os.AsyncTask; + +import com.google.gson.Gson; + +import java.io.IOException; + +/** + * The main reservoir class. + */ +public class Reservoir { + + private static SimpleDiskCache cache; + + /** + * Initialize Reservoir + * + * @param context context. + * @param maxSize the maximum size in bytes. + */ + public static synchronized boolean init(Context context, long maxSize) { + try { + cache = SimpleDiskCache.open(context.getFilesDir(), 1, maxSize); + return true; + } catch (IOException e) { + return false; + } + + } + + /** + * Check if an object with the given key exists in the Reservoir. + * + * @param key they key string. + * @return true if object with given key exists, false if object doesn't exist or an + * exception occurs during disk read. + */ + public static boolean contains(String key) throws IOException { + + return cache.contains(key); + } + + /** + * Put an object into Reservoir with the given key. This a blocking IO operation. Previously + * stored object with the same + * key (if any) will be overwritten. + * + * @param key they key string. + * @param object the object to be stored. + */ + public static void put(String key, Object object) throws IOException { + String json = new Gson().toJson(object); + cache.put(key, json); + } + + /** + * Put an object into Reservoir with the given key asynchronously. Previously + * stored object with the same + * key (if any) will be overwritten. + * + * @param key they key string. + * @param object the object to be stored. + * @param callback a callback of type {@link com.anupcowkur.reservoirsample + * .ReservoirPutCallback} which is called upon completion. + */ + public static void putAsync(String key, Object object, + ReservoirPutCallback callback) { + + new PutTask(key, object, callback).execute(); + } + + /** + * Get an object from Reservoir with the given key. This a blocking IO operation. + * + * @param key they key string. + * @param classOfT the Class type of the expected return object. + * @return the object of the given type if it exists, null if object doesn't exist. + */ + public static T get(String key, Class classOfT) throws IOException { + try { + String json = cache.getString(key).getString(); + return new Gson().fromJson(json, classOfT); + } catch (NullPointerException e) { + return null; + } + } + + /** + * Get an object from Reservoir with the given key asynchronously. + * + * @param key they key string. + * @param callback a callback of type {@link com.anupcowkur.reservoirsample + * .ReservoirGetCallback} which is called upon completion. + */ + public static void getAsync(String key, Class classOfT, + ReservoirGetCallback callback) { + new GetTask(key, classOfT, callback).execute(); + } + + /** + * AsyncTask to perform put operation in a background thread. + */ + private static class PutTask extends AsyncTask { + + private final String key; + private Exception e; + private final ReservoirPutCallback callback; + final Object object; + + private PutTask(String key, Object object, ReservoirPutCallback callback) { + this.key = key; + this.callback = callback; + this.object = object; + this.e = null; + } + + @Override + protected Void doInBackground(Void... params) { + try { + String json = new Gson().toJson(object); + cache.put(key, json); + } catch (Exception e) { + this.e = e; + } + return null; + } + + @Override + protected void onPostExecute(Void aVoid) { + if (callback != null) { + callback.onComplete(e); + } + } + + } + + /** + * AsyncTask to perform get operation in a background thread. + */ + private static class GetTask extends AsyncTask { + + private final String key; + private final ReservoirGetCallback callback; + private final Class classOfT; + private Exception e; + + private GetTask(String key, Class classOfT, ReservoirGetCallback callback) { + this.key = key; + this.callback = callback; + this.classOfT = classOfT; + this.e = null; + } + + @Override + protected T doInBackground(Void... params) { + try { + String json = cache.getString(key).getString(); + return new Gson().fromJson(json, classOfT); + } catch (Exception e) { + this.e = e; + return null; + } + } + + @Override + protected void onPostExecute(T object) { + if (callback != null) { + callback.onComplete(e, object); + } + } + + } +} diff --git a/Library/src/main/java/com/anupcowkur/reservoir/ReservoirGetCallback.java b/Library/src/main/java/com/anupcowkur/reservoir/ReservoirGetCallback.java new file mode 100644 index 0000000..8ff79a1 --- /dev/null +++ b/Library/src/main/java/com/anupcowkur/reservoir/ReservoirGetCallback.java @@ -0,0 +1,8 @@ +package com.anupcowkur.reservoir; + +/** + * + */ +public interface ReservoirGetCallback { + public void onComplete(Exception e, T object); +} diff --git a/Library/src/main/java/com/anupcowkur/reservoir/ReservoirPutCallback.java b/Library/src/main/java/com/anupcowkur/reservoir/ReservoirPutCallback.java new file mode 100644 index 0000000..f31497f --- /dev/null +++ b/Library/src/main/java/com/anupcowkur/reservoir/ReservoirPutCallback.java @@ -0,0 +1,8 @@ +package com.anupcowkur.reservoir; + +/** + * + */ +public interface ReservoirPutCallback { + public void onComplete(Exception e); +} diff --git a/Library/src/main/java/com/anupcowkur/reservoir/SimpleDiskCache.java b/Library/src/main/java/com/anupcowkur/reservoir/SimpleDiskCache.java new file mode 100644 index 0000000..979b035 --- /dev/null +++ b/Library/src/main/java/com/anupcowkur/reservoir/SimpleDiskCache.java @@ -0,0 +1,213 @@ +package com.anupcowkur.reservoir; + +import com.jakewharton.disklrucache.DiskLruCache; + +import org.apache.commons.io.IOUtils; + +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FilterOutputStream; +import java.io.IOException; +import java.io.ObjectOutputStream; +import java.io.OutputStream; +import java.io.Serializable; +import java.io.UnsupportedEncodingException; +import java.math.BigInteger; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +class SimpleDiskCache { + + private static final int VALUE_IDX = 0; + private static final int METADATA_IDX = 1; + private static final List usedDirs = new ArrayList(); + + private final DiskLruCache diskLruCache; + + private SimpleDiskCache(File dir, int appVersion, long maxSize) throws IOException { + diskLruCache = DiskLruCache.open(dir, appVersion, 2, maxSize); + } + + static synchronized SimpleDiskCache open(File dir, int appVersion, + long maxSize) throws IOException { + + if (usedDirs.contains(dir)) { + throw new IllegalStateException("Cache dir " + dir.getAbsolutePath() + " was used " + + "before."); + } + + usedDirs.add(dir); + + return new SimpleDiskCache(dir, appVersion, maxSize); + } + + StringEntry getString(String key) throws IOException { + DiskLruCache.Snapshot snapshot = diskLruCache.get(toInternalKey(key)); + if (snapshot == null) + return null; + + try { + return new StringEntry(snapshot.getString(VALUE_IDX)); + } finally { + snapshot.close(); + } + } + + boolean contains(String key) throws IOException { + DiskLruCache.Snapshot snapshot = diskLruCache.get(toInternalKey(key)); + if (snapshot == null) + return false; + + snapshot.close(); + return true; + } + + private OutputStream openStream(String key, Map metadata) throws + IOException { + DiskLruCache.Editor editor = diskLruCache.edit(toInternalKey(key)); + try { + writeMetadata(metadata, editor); + BufferedOutputStream bos = new BufferedOutputStream(editor.newOutputStream(VALUE_IDX)); + return new CacheOutputStream(bos, editor); + } catch (IOException e) { + editor.abort(); + throw e; + } + } + + void put(String key, String value) throws IOException { + put(key, value, new HashMap()); + } + + private void put(String key, String value, Map annotations) + throws + IOException { + OutputStream cos = null; + try { + cos = openStream(key, annotations); + cos.write(value.getBytes()); + } finally { + if (cos != null) + cos.close(); + } + + } + + private void writeMetadata(Map metadata, + DiskLruCache.Editor editor) throws IOException { + ObjectOutputStream oos = null; + try { + oos = new ObjectOutputStream(new BufferedOutputStream(editor.newOutputStream + (METADATA_IDX))); + oos.writeObject(metadata); + } finally { + IOUtils.closeQuietly(oos); + } + } + + private String toInternalKey(String key) { + return md5(key); + } + + private String md5(String s) { + try { + MessageDigest m = MessageDigest.getInstance("MD5"); + m.update(s.getBytes("UTF-8")); + byte[] digest = m.digest(); + BigInteger bigInt = new BigInteger(1, digest); + return bigInt.toString(16); + } catch (NoSuchAlgorithmException e) { + throw new AssertionError(); + } catch (UnsupportedEncodingException e) { + throw new AssertionError(); + } + } + + private class CacheOutputStream extends FilterOutputStream { + + private final DiskLruCache.Editor editor; + private boolean failed = false; + + private CacheOutputStream(OutputStream os, DiskLruCache.Editor editor) { + super(os); + this.editor = editor; + } + + @Override + public void close() throws IOException { + IOException closeException = null; + try { + super.close(); + } catch (IOException e) { + closeException = e; + } + + if (failed) { + editor.abort(); + } else { + editor.commit(); + } + + if (closeException != null) + throw closeException; + } + + @Override + public void flush() throws IOException { + try { + super.flush(); + } catch (IOException e) { + failed = true; + throw e; + } + } + + @Override + public void write(int oneByte) throws IOException { + try { + super.write(oneByte); + } catch (IOException e) { + failed = true; + throw e; + } + } + + @Override + public void write(byte[] buffer) throws IOException { + try { + super.write(buffer); + } catch (IOException e) { + failed = true; + throw e; + } + } + + @Override + public void write(byte[] buffer, int offset, int length) throws IOException { + try { + super.write(buffer, offset, length); + } catch (IOException e) { + failed = true; + throw e; + } + } + } + + static class StringEntry { + private final String string; + + StringEntry(String string) { + this.string = string; + } + + String getString() { + return string; + } + + } +} + diff --git a/Library/src/main/res/drawable-hdpi/ic_launcher.png b/Library/src/main/res/drawable-hdpi/ic_launcher.png new file mode 100644 index 0000000..96a442e Binary files /dev/null and b/Library/src/main/res/drawable-hdpi/ic_launcher.png differ diff --git a/Library/src/main/res/drawable-mdpi/ic_launcher.png b/Library/src/main/res/drawable-mdpi/ic_launcher.png new file mode 100644 index 0000000..359047d Binary files /dev/null and b/Library/src/main/res/drawable-mdpi/ic_launcher.png differ diff --git a/Library/src/main/res/drawable-xhdpi/ic_launcher.png b/Library/src/main/res/drawable-xhdpi/ic_launcher.png new file mode 100644 index 0000000..71c6d76 Binary files /dev/null and b/Library/src/main/res/drawable-xhdpi/ic_launcher.png differ diff --git a/Library/src/main/res/drawable-xxhdpi/ic_launcher.png b/Library/src/main/res/drawable-xxhdpi/ic_launcher.png new file mode 100644 index 0000000..4df1894 Binary files /dev/null and b/Library/src/main/res/drawable-xxhdpi/ic_launcher.png differ diff --git a/Library/src/main/res/values/strings.xml b/Library/src/main/res/values/strings.xml new file mode 100644 index 0000000..49e2386 --- /dev/null +++ b/Library/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + My Module + diff --git a/Sample/build.gradle b/Sample/build.gradle new file mode 100644 index 0000000..9fdf340 --- /dev/null +++ b/Sample/build.gradle @@ -0,0 +1,28 @@ +buildscript { + repositories { + mavenCentral() + } + dependencies { + classpath 'com.android.tools.build:gradle:0.8.+' + } +} +apply plugin: 'android' + +repositories { + mavenCentral() +} + +android { + compileSdkVersion 19 + buildToolsVersion "19.0.1" + + defaultConfig { + minSdkVersion 7 + targetSdkVersion 19 + } +} + +dependencies { + compile project(':Library') + +} diff --git a/Sample/src/main/AndroidManifest.xml b/Sample/src/main/AndroidManifest.xml new file mode 100644 index 0000000..502ca7b --- /dev/null +++ b/Sample/src/main/AndroidManifest.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + diff --git a/Sample/src/main/java/com/anupcowkur/reservoirsample/MainActivity.java b/Sample/src/main/java/com/anupcowkur/reservoirsample/MainActivity.java new file mode 100644 index 0000000..ca3baed --- /dev/null +++ b/Sample/src/main/java/com/anupcowkur/reservoirsample/MainActivity.java @@ -0,0 +1,62 @@ +package com.anupcowkur.reservoirsample; + +import android.app.Activity; +import android.os.Bundle; +import android.widget.TextView; + +import com.anupcowkur.reservoir.Reservoir; +import com.anupcowkur.reservoir.ReservoirGetCallback; +import com.anupcowkur.reservoir.ReservoirPutCallback; + +public class MainActivity extends Activity { + + private static final String TEST_STRING = "my test string"; + private static final String KEY = "myKey"; + private TextView tv_status; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + tv_status = (TextView) findViewById(R.id.tv_status); + + putInReservoir(); + + } + + private void putInReservoir() { + + TestClass testPutObject = new TestClass(); + + testPutObject.setTestString(TEST_STRING); + + Reservoir.putAsync(KEY, testPutObject, new ReservoirPutCallback() { + @Override + public void onComplete(Exception e) { + if (e == null) + getFromReservoir(); //async put call completed, execute get call. + else + tv_status.setText(e.getMessage()); //failure + } + }); + + + } + + private void getFromReservoir() { + + Reservoir.getAsync(KEY, TestClass.class, new ReservoirGetCallback() { + @Override + public void onComplete(Exception e, TestClass testGetObject) { + if (e == null && testGetObject.getTestString().equals(TEST_STRING)) { + tv_status.setText(getString(R.string.success)); //success! + } else + tv_status.setText(e.getMessage()); //failure. + } + + }); + + } + +} diff --git a/Sample/src/main/java/com/anupcowkur/reservoirsample/SampleApp.java b/Sample/src/main/java/com/anupcowkur/reservoirsample/SampleApp.java new file mode 100644 index 0000000..9755841 --- /dev/null +++ b/Sample/src/main/java/com/anupcowkur/reservoirsample/SampleApp.java @@ -0,0 +1,17 @@ +package com.anupcowkur.reservoirsample; + +import android.app.Application; + +import com.anupcowkur.reservoir.Reservoir; + +/** + * The main application. + */ +public class SampleApp extends Application { + + @Override + public void onCreate() { + super.onCreate(); + Reservoir.init(this, 2048); + } +} diff --git a/Sample/src/main/java/com/anupcowkur/reservoirsample/TestClass.java b/Sample/src/main/java/com/anupcowkur/reservoirsample/TestClass.java new file mode 100644 index 0000000..02be9db --- /dev/null +++ b/Sample/src/main/java/com/anupcowkur/reservoirsample/TestClass.java @@ -0,0 +1,13 @@ +package com.anupcowkur.reservoirsample; + +class TestClass { + private String testString; + + public String getTestString() { + return testString; + } + + public void setTestString(String testString) { + this.testString = testString; + } +} diff --git a/Sample/src/main/res/drawable-hdpi/ic_launcher.png b/Sample/src/main/res/drawable-hdpi/ic_launcher.png new file mode 100644 index 0000000..55621cc Binary files /dev/null and b/Sample/src/main/res/drawable-hdpi/ic_launcher.png differ diff --git a/Sample/src/main/res/drawable-mdpi/ic_launcher.png b/Sample/src/main/res/drawable-mdpi/ic_launcher.png new file mode 100644 index 0000000..11ec206 Binary files /dev/null and b/Sample/src/main/res/drawable-mdpi/ic_launcher.png differ diff --git a/Sample/src/main/res/drawable-xhdpi/ic_launcher.png b/Sample/src/main/res/drawable-xhdpi/ic_launcher.png new file mode 100644 index 0000000..7c02b78 Binary files /dev/null and b/Sample/src/main/res/drawable-xhdpi/ic_launcher.png differ diff --git a/Sample/src/main/res/drawable-xxhdpi/ic_launcher.png b/Sample/src/main/res/drawable-xxhdpi/ic_launcher.png new file mode 100644 index 0000000..915d914 Binary files /dev/null and b/Sample/src/main/res/drawable-xxhdpi/ic_launcher.png differ diff --git a/Sample/src/main/res/layout/activity_main.xml b/Sample/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..7db76cb --- /dev/null +++ b/Sample/src/main/res/layout/activity_main.xml @@ -0,0 +1,17 @@ + + + + diff --git a/Sample/src/main/res/values/dimens.xml b/Sample/src/main/res/values/dimens.xml new file mode 100644 index 0000000..a0171a7 --- /dev/null +++ b/Sample/src/main/res/values/dimens.xml @@ -0,0 +1,6 @@ + + + 16dp + 16dp + + diff --git a/Sample/src/main/res/values/strings.xml b/Sample/src/main/res/values/strings.xml new file mode 100644 index 0000000..154836a --- /dev/null +++ b/Sample/src/main/res/values/strings.xml @@ -0,0 +1,9 @@ + + + + Reservoir Sample + Hang on.... + Success! + Failed :-( + + diff --git a/Sample/src/main/res/values/styles.xml b/Sample/src/main/res/values/styles.xml new file mode 100644 index 0000000..523923c --- /dev/null +++ b/Sample/src/main/res/values/styles.xml @@ -0,0 +1,8 @@ + + + + + + diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..f7a7ae7 --- /dev/null +++ b/build.gradle @@ -0,0 +1 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. \ No newline at end of file diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..0dd6bc4 --- /dev/null +++ b/gradle.properties @@ -0,0 +1 @@ +# Set Gradle settings which apply to all modules here. \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..8c0fb64 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..ba4bd1e --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Fri Jan 03 18:58:52 GMT+05:30 2014 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=http\://services.gradle.org/distributions/gradle-1.10-bin.zip diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..91a7e26 --- /dev/null +++ b/gradlew @@ -0,0 +1,164 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# For Cygwin, ensure paths are in UNIX format before anything is touched. +if $cygwin ; then + [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` +fi + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >&- +APP_HOME="`pwd -P`" +cd "$SAVED" >&- + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..aec9973 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,90 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windowz variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..625c22a --- /dev/null +++ b/settings.gradle @@ -0,0 +1 @@ +include ':Sample', ':Library'