[
  {
    "path": ".gitignore",
    "content": ".DS_Store\n.gradle\nbuild/\n\n# Package Files #\n*.jar\n*.class\n\n# Ignore Gradle GUI config\ngradle-app.setting\ngradle.properties"
  },
  {
    "path": ".travis.yml",
    "content": "branches:\n  only:\n    - master\n    - dev\n\nlanguage: java\n\ninstall: \n  - \"./gradlew assemble install test\"\n\nenv:\n  global:\n    - TERM=dumb\n\n#debug task (dump gradle test report)\nafter_failure: \n  - \"cat /home/travis/build/nhachicha/android-native-dependencies/build/reports/tests/index.html\"\n  - \"cat /home/travis/build/nhachicha/android-native-dependencies/build/reports/tests/classes/com.nabilhachicha.nativedependencies.DependenciesResolverTest.html\"\n  - \"cat /home/travis/build/nhachicha/android-native-dependencies/build/reports/tests/classes/com.nabilhachicha.nativedependencies.BasicPluginTest.html\"\n  - \"cat /home/travis/build/nhachicha/android-native-dependencies/build/reports/tests/classes/com.nabilhachicha.nativedependencies.DependenciesResolverTest.html\"\n"
  },
  {
    "path": "CHANGELOG.md",
    "content": "Version 0.1.2 *(2015-05-12)*\n----------------------------\n- Add support for 64bit ABI\n\nVersion 0.1.1 *(2014-08-17)*\n----------------------------\n\n- Add a DSL (addLibPrefixToArtifact=true|false) to disable prefixing the resolved artifact with 'lib'\n\nVersion 0.1.0 *(2014-05-25)*\n----------------------------\n\n- Initial version for the 0.1.x Android native dependencies plugin.\n"
  },
  {
    "path": "README.md",
    "content": "Overview\n========\nThis Gradle plugin allows you to automatically *resolve and add* your native dependencies to `jniLibs` directory.\n\n![screen shot 2014-04-10 at 15 29 40](https://cloud.githubusercontent.com/assets/1793238/2668930/6969020e-c0bd-11e3-9116-ae879991e356.png)\n\nUsage\n=====\nApply the plugin in your `build.gradle` after the regular `android` plugin, then declare the list of your native dependencies.\n```groovy\nbuildscript {\n  repositories {\n    mavenCentral()\n  }\n  dependencies {\n    classpath 'com.android.tools.build:gradle:1.0.0'\n    classpath 'com.nabilhachicha:android-native-dependencies:0.1.2'\n  }\n}\n\napply plugin: 'android'\napply plugin: 'android-native-dependencies'\n\nnative_dependencies {\n    artifact 'com.snappydb:snappydb-native:0.2.+:armeabi'\n    artifact 'com.snappydb:snappydb-native:0.2.+:x86'\n}\n\ndependencies {\n    //regular Jar dependencies ...\n}\n\n```\n\nConvention\n==========\n\n> The artifact DSL follows the naming convention for Maven artifacts.\n> thus, you can use one of the following syntax:\n\n- abbreviated *group:name:version[:classifier]*\n\n```groovy\n//adding x86 classifier will resolve only intel's (.so) lib\nnative_dependencies {\n    artifact 'com.snappydb:snappydb-native:0.2+:x86'\n}\n\n//omit the classifier will resolve all supported architectures\nnative_dependencies {\n    artifact 'com.snappydb:snappydb-native:0.2+'\n}\n```\n\n- map-style notation\n\n\n```groovy\n//adding x86 classifier will resolve only intel's (.so) lib\nnative_dependencies {\n    artifact group: 'com.snappydb', name: 'snappydb-native', version: '0.2+', classifier: 'x86'\n}\n\n//omit the classifier will resolve all supported architectures\nnative_dependencies {\n    artifact group: 'com.snappydb', name: 'snappydb-native', version: '0.2+'\n}\n```\n    \nIn both notations, *classifier* is optional. this means that when omitted, the plugin try to resolve the artifact for *all* architectures: `armeabi`, `armeabi-v7a`, `x86` and `mips`.\n\n- Disable `lib` prefix:\n\nYou may want to disable the plugin from prefixing the resolved artifact with `lib`  (when copying into **jniLibs** directory) \n```groovy\nnative_dependencies {\n    artifact ('com.snappydb:snappydb-native:0.2.+:armeabi') {\n           addLibPrefixToArtifact=false\n    }\n}\n```\nin this example the ARM dependency will have the name `snappydb-native.so` rather than `libsnappydb-native.so`\n\nTasks\n=====\n\nThe plugin adds the `resolveNativeDependencies` task to your project, this task runs automatically whenever you build your project. \n##### Note: #####\nThe plugin uses [Gradle incremental task](http://www.gradle.org/docs/current/dsl/org.gradle.api.tasks.incremental.IncrementalTaskInputs.html) system to run faster if the configuration didn't change since the last build.\n\nLicense\n=======\n\n    Copyright 2014 Nabil Hachicha\n\n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.\n\n[![Build Status](https://travis-ci.org/nhachicha/android-native-dependencies.svg?branch=master)](https://travis-ci.org/nhachicha/android-native-dependencies)\n\n\n"
  },
  {
    "path": "build.gradle",
    "content": "import org.gradle.api.artifacts.maven.MavenDeployment\n\nbuildscript {\n    repositories {\n        mavenCentral()\n        maven { url 'http://jcenter.bintray.com' }\n    }\n\n    dependencies {\n        classpath 'org.gradle.api.plugins:gradle-nexus-plugin:0.3'\n        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.2'\n    }\n}\n\napply plugin: 'groovy'\napply plugin: 'maven'\napply plugin: 'maven-publish'\napply plugin: 'com.jfrog.bintray'\napply plugin: 'nexus'\n\ndependencies {\n    compile gradleApi()\n    compile localGroovy()\n    compile 'com.android.tools.build:gradle:1.1.0'\n    compile 'commons-io:commons-io:2.4'\n    testCompile 'org.easytesting:fest-assert-core:2.0M10'\n}\n\nrepositories {\n    mavenCentral()\n}\n\ngroup = 'com.nabilhachicha'\nversion = '0.1.2'\n\nmodifyPom {\n    project {\n        name 'Android Native Dependencies'\n        description 'Gradle plugin for resolving and downloading Android native dependencies (.so)'\n        url 'https://github.com/nhachicha/android-native-dependencies'\n        inceptionYear '2014'\n\n        scm {\n            url 'https://github.com/nhachicha/android-native-dependencies'\n            connection 'scm:git:git://github.com/nhachicha/android-native-dependencies.git'\n            developerConnection 'scm:git:ssh://git@github.com/nhachicha/android-native-dependencies.git'\n        }\n\n        licenses {\n            license {\n                name 'The Apache Software License, Version 2.0'\n                url 'http://www.apache.org/licenses/LICENSE-2.0.txt'\n                distribution 'repo'\n            }\n        }\n\n        developers {\n            developer {\n                id 'nhachicha'\n                name 'Nabil Hachicha'\n                email 'nabil.hachicha@gmail.com'\n            }\n        }\n    }\n}\n\ntask srcJar(type: Jar) {\n    classifier 'sources'\n    from sourceSets.main.allSource\n}\n\ntask gdocJar(type: Jar, dependsOn: groovydoc) {\n    classifier 'groovydoc'\n    from groovydoc.destinationDir\n}\n\nartifacts {\n    archives srcJar\n    archives gdocJar\n    archives javadocJar\n}\n\npublishing {\n    publications {\n        mavenJava(MavenPublication) {\n            from components.java\n\n            artifact srcJar\n            artifact gdocJar\n            artifact javadocJar\n\n            pom.withXml {\n                def root = asNode()\n                root.appendNode('name', 'Android Native Dependencies')\n                root.appendNode('url', 'https://github.com/nhachicha/android-native-dependencies')\n                root.appendNode('description', 'Gradle plugin for resolving and downloading Android native dependencies (.so)')\n                root.appendNode('inceptionYear', '2014')\n\n                def scm = root.appendNode('scm')\n                scm.appendNode('url', 'https://github.com/nhachicha/android-native-dependencies')\n                scm.appendNode('connection', 'scm:git:git://github.com/nhachicha/android-native-dependencies.git')\n                scm.appendNode('developerConnection', 'scm:git:ssh://git@github.com/nhachicha/android-native-dependencies.git')\n\n                def license = root.appendNode('licenses').appendNode('license')\n                license.appendNode('name', 'The Apache Software License, Version 2.0')\n                license.appendNode('url', 'http://www.apache.org/licenses/LICENSE-2.0.txt')\n                license.appendNode('distribution', 'repo')\n\n                def developers = root.appendNode('developers')\n                def nabil = developers.appendNode('developer')\n                nabil.appendNode('id', 'nhachicha')\n                nabil.appendNode('name', 'Nabil Hachicha')\n                nabil.appendNode('email', 'nabil.hachicha@gmail.com')\n            }\n        }\n    }\n}\n\nbintray {\n    key = project.hasProperty('bintray_apikey') ? project.getProperty('bintray_apikey') : null\n    user = project.hasProperty('bintray_user') ? project.getProperty('bintray_user') : null\n    publications = ['mavenJava']\n\n    pkg {\n        repo = 'gradle-plugins'\n        name = 'android-native-dependencies'\n        licenses = ['Apache-2.0']\n    }\n}\n\ntask wrapper(type: Wrapper) {\n    gradleVersion = '2.2'\n}\n"
  },
  {
    "path": "gradle/wrapper/gradle-wrapper.properties",
    "content": "#Sat May 09 23:02:18 BST 2015\ndistributionBase=GRADLE_USER_HOME\ndistributionPath=wrapper/dists\nzipStoreBase=GRADLE_USER_HOME\nzipStorePath=wrapper/dists\ndistributionUrl=https\\://services.gradle.org/distributions/gradle-2.2-bin.zip\n"
  },
  {
    "path": "gradlew",
    "content": "#!/usr/bin/env bash\n\n##############################################################################\n##\n##  Gradle start up script for UN*X\n##\n##############################################################################\n\n# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.\nDEFAULT_JVM_OPTS=\"\"\n\nAPP_NAME=\"Gradle\"\nAPP_BASE_NAME=`basename \"$0\"`\n\n# Use the maximum available, or set MAX_FD != -1 to use that value.\nMAX_FD=\"maximum\"\n\nwarn ( ) {\n    echo \"$*\"\n}\n\ndie ( ) {\n    echo\n    echo \"$*\"\n    echo\n    exit 1\n}\n\n# OS specific support (must be 'true' or 'false').\ncygwin=false\nmsys=false\ndarwin=false\ncase \"`uname`\" in\n  CYGWIN* )\n    cygwin=true\n    ;;\n  Darwin* )\n    darwin=true\n    ;;\n  MINGW* )\n    msys=true\n    ;;\nesac\n\n# For Cygwin, ensure paths are in UNIX format before anything is touched.\nif $cygwin ; then\n    [ -n \"$JAVA_HOME\" ] && JAVA_HOME=`cygpath --unix \"$JAVA_HOME\"`\nfi\n\n# Attempt to set APP_HOME\n# Resolve links: $0 may be a link\nPRG=\"$0\"\n# Need this for relative symlinks.\nwhile [ -h \"$PRG\" ] ; do\n    ls=`ls -ld \"$PRG\"`\n    link=`expr \"$ls\" : '.*-> \\(.*\\)$'`\n    if expr \"$link\" : '/.*' > /dev/null; then\n        PRG=\"$link\"\n    else\n        PRG=`dirname \"$PRG\"`\"/$link\"\n    fi\ndone\nSAVED=\"`pwd`\"\ncd \"`dirname \\\"$PRG\\\"`/\" >&-\nAPP_HOME=\"`pwd -P`\"\ncd \"$SAVED\" >&-\n\nCLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar\n\n# Determine the Java command to use to start the JVM.\nif [ -n \"$JAVA_HOME\" ] ; then\n    if [ -x \"$JAVA_HOME/jre/sh/java\" ] ; then\n        # IBM's JDK on AIX uses strange locations for the executables\n        JAVACMD=\"$JAVA_HOME/jre/sh/java\"\n    else\n        JAVACMD=\"$JAVA_HOME/bin/java\"\n    fi\n    if [ ! -x \"$JAVACMD\" ] ; then\n        die \"ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME\n\nPlease set the JAVA_HOME variable in your environment to match the\nlocation of your Java installation.\"\n    fi\nelse\n    JAVACMD=\"java\"\n    which java >/dev/null 2>&1 || die \"ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.\n\nPlease set the JAVA_HOME variable in your environment to match the\nlocation of your Java installation.\"\nfi\n\n# Increase the maximum file descriptors if we can.\nif [ \"$cygwin\" = \"false\" -a \"$darwin\" = \"false\" ] ; then\n    MAX_FD_LIMIT=`ulimit -H -n`\n    if [ $? -eq 0 ] ; then\n        if [ \"$MAX_FD\" = \"maximum\" -o \"$MAX_FD\" = \"max\" ] ; then\n            MAX_FD=\"$MAX_FD_LIMIT\"\n        fi\n        ulimit -n $MAX_FD\n        if [ $? -ne 0 ] ; then\n            warn \"Could not set maximum file descriptor limit: $MAX_FD\"\n        fi\n    else\n        warn \"Could not query maximum file descriptor limit: $MAX_FD_LIMIT\"\n    fi\nfi\n\n# For Darwin, add options to specify how the application appears in the dock\nif $darwin; then\n    GRADLE_OPTS=\"$GRADLE_OPTS \\\"-Xdock:name=$APP_NAME\\\" \\\"-Xdock:icon=$APP_HOME/media/gradle.icns\\\"\"\nfi\n\n# For Cygwin, switch paths to Windows format before running java\nif $cygwin ; then\n    APP_HOME=`cygpath --path --mixed \"$APP_HOME\"`\n    CLASSPATH=`cygpath --path --mixed \"$CLASSPATH\"`\n\n    # We build the pattern for arguments to be converted via cygpath\n    ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`\n    SEP=\"\"\n    for dir in $ROOTDIRSRAW ; do\n        ROOTDIRS=\"$ROOTDIRS$SEP$dir\"\n        SEP=\"|\"\n    done\n    OURCYGPATTERN=\"(^($ROOTDIRS))\"\n    # Add a user-defined pattern to the cygpath arguments\n    if [ \"$GRADLE_CYGPATTERN\" != \"\" ] ; then\n        OURCYGPATTERN=\"$OURCYGPATTERN|($GRADLE_CYGPATTERN)\"\n    fi\n    # Now convert the arguments - kludge to limit ourselves to /bin/sh\n    i=0\n    for arg in \"$@\" ; do\n        CHECK=`echo \"$arg\"|egrep -c \"$OURCYGPATTERN\" -`\n        CHECK2=`echo \"$arg\"|egrep -c \"^-\"`                                 ### Determine if an option\n\n        if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then                    ### Added a condition\n            eval `echo args$i`=`cygpath --path --ignore --mixed \"$arg\"`\n        else\n            eval `echo args$i`=\"\\\"$arg\\\"\"\n        fi\n        i=$((i+1))\n    done\n    case $i in\n        (0) set -- ;;\n        (1) set -- \"$args0\" ;;\n        (2) set -- \"$args0\" \"$args1\" ;;\n        (3) set -- \"$args0\" \"$args1\" \"$args2\" ;;\n        (4) set -- \"$args0\" \"$args1\" \"$args2\" \"$args3\" ;;\n        (5) set -- \"$args0\" \"$args1\" \"$args2\" \"$args3\" \"$args4\" ;;\n        (6) set -- \"$args0\" \"$args1\" \"$args2\" \"$args3\" \"$args4\" \"$args5\" ;;\n        (7) set -- \"$args0\" \"$args1\" \"$args2\" \"$args3\" \"$args4\" \"$args5\" \"$args6\" ;;\n        (8) set -- \"$args0\" \"$args1\" \"$args2\" \"$args3\" \"$args4\" \"$args5\" \"$args6\" \"$args7\" ;;\n        (9) set -- \"$args0\" \"$args1\" \"$args2\" \"$args3\" \"$args4\" \"$args5\" \"$args6\" \"$args7\" \"$args8\" ;;\n    esac\nfi\n\n# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules\nfunction splitJvmOpts() {\n    JVM_OPTS=(\"$@\")\n}\neval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS\nJVM_OPTS[${#JVM_OPTS[*]}]=\"-Dorg.gradle.appname=$APP_BASE_NAME\"\n\nexec \"$JAVACMD\" \"${JVM_OPTS[@]}\" -classpath \"$CLASSPATH\" org.gradle.wrapper.GradleWrapperMain \"$@\"\n"
  },
  {
    "path": "gradlew.bat",
    "content": "@if \"%DEBUG%\" == \"\" @echo off\r\n@rem ##########################################################################\r\n@rem\r\n@rem  Gradle startup script for Windows\r\n@rem\r\n@rem ##########################################################################\r\n\r\n@rem Set local scope for the variables with windows NT shell\r\nif \"%OS%\"==\"Windows_NT\" setlocal\r\n\r\n@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.\r\nset DEFAULT_JVM_OPTS=\r\n\r\nset DIRNAME=%~dp0\r\nif \"%DIRNAME%\" == \"\" set DIRNAME=.\r\nset APP_BASE_NAME=%~n0\r\nset APP_HOME=%DIRNAME%\r\n\r\n@rem Find java.exe\r\nif defined JAVA_HOME goto findJavaFromJavaHome\r\n\r\nset JAVA_EXE=java.exe\r\n%JAVA_EXE% -version >NUL 2>&1\r\nif \"%ERRORLEVEL%\" == \"0\" goto init\r\n\r\necho.\r\necho ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.\r\necho.\r\necho Please set the JAVA_HOME variable in your environment to match the\r\necho location of your Java installation.\r\n\r\ngoto fail\r\n\r\n:findJavaFromJavaHome\r\nset JAVA_HOME=%JAVA_HOME:\"=%\r\nset JAVA_EXE=%JAVA_HOME%/bin/java.exe\r\n\r\nif exist \"%JAVA_EXE%\" goto init\r\n\r\necho.\r\necho ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%\r\necho.\r\necho Please set the JAVA_HOME variable in your environment to match the\r\necho location of your Java installation.\r\n\r\ngoto fail\r\n\r\n:init\r\n@rem Get command-line arguments, handling Windowz variants\r\n\r\nif not \"%OS%\" == \"Windows_NT\" goto win9xME_args\r\nif \"%@eval[2+2]\" == \"4\" goto 4NT_args\r\n\r\n:win9xME_args\r\n@rem Slurp the command line arguments.\r\nset CMD_LINE_ARGS=\r\nset _SKIP=2\r\n\r\n:win9xME_args_slurp\r\nif \"x%~1\" == \"x\" goto execute\r\n\r\nset CMD_LINE_ARGS=%*\r\ngoto execute\r\n\r\n:4NT_args\r\n@rem Get arguments from the 4NT Shell from JP Software\r\nset CMD_LINE_ARGS=%$\r\n\r\n:execute\r\n@rem Setup the command line\r\n\r\nset CLASSPATH=%APP_HOME%\\gradle\\wrapper\\gradle-wrapper.jar\r\n\r\n@rem Execute Gradle\r\n\"%JAVA_EXE%\" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% \"-Dorg.gradle.appname=%APP_BASE_NAME%\" -classpath \"%CLASSPATH%\" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%\r\n\r\n:end\r\n@rem End local scope for the variables with windows NT shell\r\nif \"%ERRORLEVEL%\"==\"0\" goto mainEnd\r\n\r\n:fail\r\nrem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of\r\nrem the _cmd.exe /c_ return code!\r\nif  not \"\" == \"%GRADLE_EXIT_CONSOLE%\" exit 1\r\nexit /b 1\r\n\r\n:mainEnd\r\nif \"%OS%\"==\"Windows_NT\" endlocal\r\n\r\n:omega\r\n"
  },
  {
    "path": "src/main/groovy/com/nabilhachicha/nativedependencies/NativeDependenciesPlugin.groovy",
    "content": "/*\n * Copyright (C) 2014 Nabil HACHICHA.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *      http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage com.nabilhachicha.nativedependencies\n\nimport org.gradle.api.Project\nimport com.android.build.gradle.AppPlugin\nimport com.android.build.gradle.LibraryPlugin\nimport org.gradle.api.Task\nimport org.gradle.api.tasks.TaskInstantiationException\nimport org.gradle.api.Plugin\nimport com.nabilhachicha.nativedependencies.extension.NativeDependenciesExtension\nimport com.nabilhachicha.nativedependencies.task.NativeDependenciesResolverTask\n\nclass NativeDependenciesPlugin implements Plugin<Project> {\n    final static PLUGIN_NAME = \"native_dependencies\"\n    final static TASK_NAME = \"resolveNativeDependencies\"\n    final static TASK_GROUP = \"Android\"\n    final static TASK_DESCRIPTION = \"Resolve native dependencies (.so)\"\n    final static TASK_ATTACH_TO_LIFECYCLE = \"preBuild\"\n\n    def void apply(Project project) {\n        verifyRequiredPlugins project\n\n        project.configure(project) {\n            extensions.create(PLUGIN_NAME, NativeDependenciesExtension)\n        }\n\n        project.afterEvaluate { evaluateResult ->\n            if (null == evaluateResult.state.getFailure()) {\n                Task task = project.task(TASK_NAME, type: NativeDependenciesResolverTask)\n                task.setDescription(TASK_DESCRIPTION)\n                task.setGroup(TASK_GROUP)\n                task.\n                \tdependencies = project.native_dependencies.dependencies\n\n                project.tasks.findByName(TASK_ATTACH_TO_LIFECYCLE).dependsOn task\n            }\n        }\n    }\n\n    private static void verifyRequiredPlugins(Project project) {\n        if (!project.plugins.hasPlugin(AppPlugin) && !project.plugins.hasPlugin(LibraryPlugin)) {\n            throw new TaskInstantiationException(\"'android' or 'android-library' plugin has to be applied before\")\n        }\n    }\n}\n"
  },
  {
    "path": "src/main/groovy/com/nabilhachicha/nativedependencies/extension/NativeDep.groovy",
    "content": "/*\n * Copyright (C) 2014 Nabil HACHICHA.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *      http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage com.nabilhachicha.nativedependencies.extension\nimport groovy.transform.Canonical\n\n/**\n * POGO that represents an artifact to resolve by the Plugin\n */\n@Canonical class NativeDep implements Serializable {\n    String dependency\n    boolean shouldPrefixWithLib = true\n}"
  },
  {
    "path": "src/main/groovy/com/nabilhachicha/nativedependencies/extension/NativeDependenciesExtension.groovy",
    "content": "/*\n * Copyright (C) 2014 Nabil HACHICHA.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *      http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage com.nabilhachicha.nativedependencies.extension\nimport org.gradle.api.tasks.StopExecutionException\nimport org.gradle.util.ConfigureUtil\n\nclass NativeDependenciesExtension {\n    final String CONFIGURATION_SEPARATOR = \":\"\n    final def classifiers = ['armeabi', 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64', 'mips', 'mips64']\n    def dependencies = []\n    /**\n     * set by a closure to let the user choose if he/she wants to disable\n     * prefixing the artifact with 'lib'\n     */\n    boolean addLibPrefixToArtifact = true\n\n    /**\n     * add {@code dep} to the list of dependencies to retrieve\n     *\n     * @param dep\n     * handle String notation ex: artifact com.snappydb:snappydb-native:0.2.+\n     */\n    def artifact (String dep, Closure... enablePrefixClosure) {\n        if (enablePrefixClosure?.size()>0) {\n            ConfigureUtil.configure(enablePrefixClosure[0], this);\n\n        } else {// reset to default\n            addLibPrefixToArtifact = true;\n        }\n\n        def dependency = dep.tokenize(CONFIGURATION_SEPARATOR)\n        if (dependency.size() < 3 || dependency.size()>4) {\n            throw new StopExecutionException('please specify group:name:version')\n\n        } else if (dependency.size() == 3) {//add classifier\n            classifiers.each {\n                dependencies << new NativeDep (dependency: dep + CONFIGURATION_SEPARATOR + it, shouldPrefixWithLib: addLibPrefixToArtifact)\n            }\n\n        } else {\n            dependencies << new NativeDep (dependency: dep, shouldPrefixWithLib: addLibPrefixToArtifact)\n        }\n    }\n\n    /**\n     * add {@code dep} to the list of dependencies to retrieve\n     *\n     * @param dep\n     * artifact group: 'com.snappydb', name: 'snappydb-native', version: '0.2.0'\n     *\n     * Note: if the user doesn't specify the optional 'classifier', this method will add\n     * all the supported architectures to this dependencies ('armeabi', 'armeabi-v7a', 'x86' and 'mips')\n     */\n    def artifact (Map m, Closure... enablePrefixClosure) {\n        if (enablePrefixClosure?.size()>0) {\n            ConfigureUtil.configure(enablePrefixClosure[0], this);\n\n        } else {// reset to default\n            addLibPrefixToArtifact = true;\n        }\n\n        String temp = m['group'] + CONFIGURATION_SEPARATOR + m['name'] + CONFIGURATION_SEPARATOR + m['version']\n\n        if(!m.containsKey('classifier')) {\n            classifiers.each {\n                dependencies << new NativeDep (dependency: temp + CONFIGURATION_SEPARATOR + it, shouldPrefixWithLib: addLibPrefixToArtifact)\n            }\n        } else {\n            dependencies << new NativeDep (dependency: temp + CONFIGURATION_SEPARATOR + m['classifier'], shouldPrefixWithLib: addLibPrefixToArtifact)\n        }\n    }\n}\n"
  },
  {
    "path": "src/main/groovy/com/nabilhachicha/nativedependencies/task/NativeDependenciesResolverTask.groovy",
    "content": "/*\n * Copyright (C) 2014 Nabil HACHICHA.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *      http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage com.nabilhachicha.nativedependencies.task\n\nimport com.nabilhachicha.nativedependencies.extension.NativeDep\nimport org.gradle.api.DefaultTask\nimport org.gradle.api.artifacts.Configuration\nimport org.gradle.api.artifacts.Dependency\nimport org.gradle.api.artifacts.ResolveException\nimport org.gradle.api.logging.Logger\nimport org.gradle.api.logging.Logging\nimport org.gradle.api.tasks.Input\nimport org.gradle.api.tasks.OutputDirectory\nimport org.gradle.api.tasks.TaskAction\nimport org.gradle.api.tasks.incremental.IncrementalTaskInputs\n\nclass NativeDependenciesResolverTask extends DefaultTask {\n    def @Input\n            dependencies\n    def @OutputDirectory\n            jniLibs = project.android.sourceSets.main.jniLibs.srcDirs.first()\n\n    final String X86_FILTER = \"x86\"\n    final String X86_64_FILTER = \"x86_64\"\n    final String MIPS_FILTER = \"mips\"\n    final String MIPS_64_FILTER = \"mips64\"\n    final String ARM_FILTER = \"armeabi\"\n    final String ARMV7A_FILTER = \"armeabi-v7a\"\n    final String ARM64_FILTER = \"arm64-v8a\"\n    final String DEPENDENCY_SUFFIX = \"@so\"\n    final String ARTIFACT_FILE_EXT = \".so\"\n\n    final Logger log = Logging.getLogger NativeDependenciesResolverTask\n\n    @TaskAction\n    def exec(IncrementalTaskInputs inputs) {\n        project.delete { jniLibs }\n        log.lifecycle \"Executing NativeDependenciesResolverTask\"\n        dependencies.each { artifact ->\n            log.info \"Processing artifact: '$artifact.dependency'\"\n            copyToJniLibs artifact\n        }\n    }\n\n    def copyToJniLibs(NativeDep artifact) {\n        String filter\n\n        if (artifact.dependency.endsWith(X86_FILTER)) {\n            filter = X86_FILTER\n\n        } else if (artifact.dependency.endsWith(X86_64_FILTER)) {\n            filter = X86_64_FILTER\n\n        } else if (artifact.dependency.endsWith(MIPS_FILTER)) {\n            filter = MIPS_FILTER\n\n        } else if (artifact.dependency.endsWith(MIPS_64_FILTER)) {\n            filter = MIPS_64_FILTER\n\n        } else if (artifact.dependency.endsWith(ARM_FILTER)) {\n            filter = ARM_FILTER\n\n        } else if (artifact.dependency.endsWith(ARMV7A_FILTER)) {\n            filter = ARMV7A_FILTER\n\n        } else if (artifact.dependency.endsWith(ARM64_FILTER)) {\n            filter = ARM64_FILTER\n\n        } else {\n            throw new IllegalArgumentException(\"Unsupported architecture for artifact '${artifact.dependency}'.\")\n        }\n\n        try {\n            def map = downloadDep(artifact.dependency)\n            if (!map.isEmpty()) {\n                copyToTarget(map.depFile, filter, map.depName, artifact.shouldPrefixWithLib)\n\n            } else {\n                log.warn(\"Failed to retrieve artifcat '$artifact'\")\n            }\n\n        } catch (ResolveException e) {\n            log.warn(\"Could not resolve artifcat '$artifact'\", e)\n        }\n    }\n\n    /**\n     * Download (or use gradle cache) the artifact from the user's defined repositories\n     *\n     * @param artifact\n     * The dependency notation, in one of the accepted notations:\n     *\n     * native_dependencies {\n     *   //the string notation, e.g. group:name:version\n     *   artifact com.snappydb:snappydb-native:0.2.+\n     *\n     *   //map notation:\n     *   artifact group: 'com.snappydb', name: 'snappydb-native', version: '0.2.0'\n     *\n     *   //optional, you can specify the 'classifier' in order to restrict the desired architecture(s)\n     *   artifact group: 'com.snappydb', name: 'snappydb-native', version: '0.2.0', classifier: 'armeabi'\n     *   //or\n     *   artifact com.snappydb:snappydb-native:0.2.+:armeabi\n     *}*\n     * @return\n     * the dependency {@link java.io.File} or null\n     */\n    def downloadDep(String artifact) {\n        log.info \"Trying to resolve artifact '$artifact' using defined repositories\"\n\n        def map = [:]\n        Dependency dependency = project.dependencies.create(artifact + DEPENDENCY_SUFFIX)\n        Configuration configuration = project.configurations.detachedConfiguration(dependency)\n        configuration.setTransitive(false)\n\n        configuration.files.each { file ->\n            if (file.isFile() && file.name.endsWith(ARTIFACT_FILE_EXT)) {\n                map['depFile'] = file\n                map['depName'] = dependency.getName()\n            } else {\n                log.info \"Could not find the file corresponding to the artifact '$artifact'\"\n            }\n        }\n        return map\n    }\n\n    /**\n     * Copy the artifact file from gradle cache to the project appropriate jniLibs directory\n     *\n     * @param depFile\n     * {@link java.io.File} to copy\n     *\n     * @param architecture\n     * supported jniLibs architecture (\"x86\", \"x86_64\", \"mips\", \"mips64\", \"armeabi\", \"armeabi-v7a\" or \"arm64-v8a\")\n     *\n     * @param shouldPrefixWithLib\n     * enable or disable the standard 'lib' prefix to an artifact name\n     */\n    def copyToTarget(File depFile, String architecture, String depName, boolean shouldPrefixWithLib) {\n        project.copy {\n            from depFile\n            into \"$jniLibs\" + File.separator + \"$architecture\"\n\n            rename { fileName ->\n                if (shouldPrefixWithLib) {\n                    \"lib\" + depName + \".so\"\n                } else {\n                    depName + \".so\"\n                }\n            }\n        }\n    }\n}\n"
  },
  {
    "path": "src/main/resources/META-INF/gradle-plugins/android-native-dependencies.properties",
    "content": "implementation-class=com.nabilhachicha.nativedependencies.NativeDependenciesPlugin"
  },
  {
    "path": "src/test/gradle_project_template/build.gradle",
    "content": "buildscript {\n    repositories {\n        mavenCentral()\n        mavenLocal()\n    }\n    dependencies {\n        classpath 'com.android.tools.build:gradle:1.2.3'\n        classpath group: 'com.nabilhachicha', name: 'android-native-dependencies', version: '0.1.2'\n        classpath 'com.jakewharton.sdkmanager:gradle-plugin:0.10.1'\n    }\n}\n\napply plugin: 'android-sdk-manager'\napply plugin: 'com.android.application'\napply plugin: 'android-native-dependencies'\n\nrepositories {\n    mavenCentral()\n}\n\nandroid {\n    compileSdkVersion 19\n    buildToolsVersion \"19.1.0\"\n}\n\n\n"
  },
  {
    "path": "src/test/gradle_project_template/src/main/AndroidManifest.xml",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n\n<manifest\n    xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    android:versionCode=\"1\"\n    android:versionName=\"1.0\"\n    package=\"com.example.nativedependencies\">\n    <uses-sdk android:minSdkVersion=\"9\" />\n</manifest>"
  },
  {
    "path": "src/test/gradle_project_template_custom_jni_dir/AndroidManifest.xml",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n\n<manifest\n    xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    android:versionCode=\"1\"\n    android:versionName=\"1.0\"\n    package=\"com.example.nativedependencies\"\n    />\n"
  },
  {
    "path": "src/test/gradle_project_template_custom_jni_dir/build.gradle",
    "content": "buildscript {\n    repositories {\n        mavenCentral()\n        mavenLocal()\n    }\n    dependencies {\n        classpath 'com.android.tools.build:gradle:1.2.3'\n        classpath group: 'com.nabilhachicha', name: 'android-native-dependencies', version: '0.1.2'\n        classpath 'com.jakewharton.sdkmanager:gradle-plugin:0.10.1'\n    }\n}\n\napply plugin: 'android-sdk-manager'\napply plugin: 'com.android.application'\napply plugin: 'android-native-dependencies'\n\nrepositories {\n    mavenCentral()\n}\n\nandroid {\n    compileSdkVersion 19\n    buildToolsVersion \"19.1.0\"\n\n    sourceSets {\n        main {\n            manifest.srcFile 'AndroidManifest.xml'\n            java.srcDirs = ['src']\n            resources.srcDirs = ['src']\n            res.srcDirs = ['res']\n            assets.srcDirs = ['assets']\n            jniLibs.srcDirs = ['src/main/native_libs']\n        }\n    }\n}\n\n\n\n"
  },
  {
    "path": "src/test/gradle_project_template_custom_jni_dir/src/main/native_libs/.empty",
    "content": ""
  },
  {
    "path": "src/test/groovy/com/nabilhachicha/nativedependencies/BasicPluginTest.groovy",
    "content": "/*\n * Copyright (C) 2014 Nabil HACHICHA.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *      http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage com.nabilhachicha.nativedependencies\nimport com.nabilhachicha.nativedependencies.task.NativeDependenciesResolverTask\nimport org.gradle.api.Project\nimport org.gradle.testfixtures.ProjectBuilder\nimport org.junit.Test\nimport org.gradle.api.internal.plugins.PluginApplicationException\nimport static org.junit.Assert.assertTrue\n\nclass BasicPluginTest {\n\n    @Test(expected = PluginApplicationException.class)\n    public void testShouldApplyAndroidPluginBefore() {\n        Project project = ProjectBuilder.builder().build()\n        project.apply plugin: 'android-native-dependencies'\n    }\n\n    @Test\n    public void testTaskCreation() {\n        Project project = ProjectBuilder.builder().build()\n        project.apply plugin: 'com.android.application'\n        project.apply plugin: 'android-native-dependencies'\n        def task = project.task('resolveNativeDependencies', type: NativeDependenciesResolverTask)\n\n        assertTrue(task instanceof NativeDependenciesResolverTask)\n    }\n\n}"
  },
  {
    "path": "src/test/groovy/com/nabilhachicha/nativedependencies/DependenciesResolverTest.groovy",
    "content": "/*\n * Copyright (C) 2014 Nabil HACHICHA.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *      http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage com.nabilhachicha.nativedependencies\n\nimport com.nabilhachicha.nativedependencies.utils.Artifacts\nimport com.nabilhachicha.nativedependencies.utils.ConfPath\nimport com.nabilhachicha.nativedependencies.utils.TempGradleProject\nimport org.gradle.tooling.BuildLauncher\nimport org.gradle.tooling.GradleConnector\nimport org.gradle.tooling.ProjectConnection\nimport org.junit.After\nimport org.junit.Before\nimport org.junit.Rule\nimport org.junit.Test\n\nimport static org.fest.assertions.api.Assertions.assertThat\n\nclass DependenciesResolverTest {\n    @Rule\n    public TempGradleProject gradleProject = new TempGradleProject(\n            new ConfPath(path: \"src${File.separator}test${File.separator}gradle_project_template\",\n                    jniLibsLocation: \"${File.separator}src${File.separator}main${File.separator}jniLibs\"),\n            new ConfPath(path: \"src${File.separator}test${File.separator}gradle_project_template_custom_jni_dir\",\n                    jniLibsLocation: \"${File.separator}src${File.separator}main${File.separator}native_libs\"))\n\n    ProjectConnection mConnection\n\n    @Before\n    public void setUp() {\n        try {\n            GradleConnector connector = GradleConnector.newConnector();\n\n            //append DSL to this build\n            gradleProject.gradleFile.append \"native_dependencies { \" + gradleProject.artifacts.join('\\n') + \" }\"\n\n            connector.forProjectDirectory(gradleProject.root);\n            mConnection = connector.connect();\n\n            // Configure the build\n            BuildLauncher launcher = mConnection.newBuild();\n            launcher.forTasks(\"resolveNativeDependencies\");\n            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();\n            launcher.setStandardOutput(outputStream);\n            launcher.setStandardError(outputStream);\n\n            // Run the build\n            launcher.run();\n        } catch (Exception exception) {\n            exception.printStackTrace()\n        }\n    }\n\n    @After\n    public void tearDown() {\n        mConnection?.close();\n    }\n\n    @Artifacts(\"artifact 'com.snappydb:snappydb-native:0.2.0'\")\n    @Test\n    public void testDSLResolveWithStringNotationAllArch() {\n        assertThat(gradleProject.mJniLibs).exists()\n\n        assertThat(gradleProject.mMipsDepFile).exists()\n        assertThat(gradleProject.mX86Dir).exists()\n        assertThat(gradleProject.mArmDir).exists()\n        assertThat(gradleProject.mArmv7aDir).exists()\n\n        assertThat(gradleProject.mMipsDepFile).exists()\n        assertThat(gradleProject.mX86DepFile).exists()\n        assertThat(gradleProject.mArmDepFile).exists()\n        assertThat(gradleProject.mArmv7aDepFile).exists()\n    }\n\n    @Artifacts(\"artifact group: 'com.snappydb', name: 'snappydb-native', version: '0.2.0'\")\n    @Test\n    public void testDSLResolveWithMappingNotationAllArch() {\n        assertThat(gradleProject.mJniLibs).exists()\n\n        assertThat(gradleProject.mMipsDir).exists()\n        assertThat(gradleProject.mX86Dir).exists()\n        assertThat(gradleProject.mArmDir).exists()\n        assertThat(gradleProject.mArmv7aDir).exists()\n\n        assertThat(gradleProject.mMipsDepFile).exists()\n        assertThat(gradleProject.mX86DepFile).exists()\n        assertThat(gradleProject.mArmDepFile).exists()\n        assertThat(gradleProject.mArmv7aDepFile).exists()\n    }\n\n    @Artifacts([\"artifact 'com.snappydb:snappydb-native:0.2.0:mips'\",\n            \"artifact 'com.snappydb:snappydb-native:0.2.0:x86'\"])\n    @Test\n    public void testDSLResolveWithStringNotationFilterByArch() {\n        assertThat(gradleProject.mJniLibs).exists()\n\n        assertThat(gradleProject.mMipsDepFile).exists()\n        assertThat(gradleProject.mX86Dir).exists()\n\n        assertThat(gradleProject.mMipsDepFile).exists()\n        assertThat(gradleProject.mX86DepFile).exists()\n    }\n\n    @Artifacts([\"artifact group: 'com.snappydb', name: 'snappydb-native', version: '0.2.0', classifier: 'armeabi'\",\n            \"artifact group: 'com.snappydb', name: 'snappydb-native', version: '0.2.0', classifier: 'armeabi-v7a'\"])\n    @Test\n    public void testDSLResolveWithMappingNotationFilterByArch() {\n        assertThat(gradleProject.mJniLibs).exists()\n\n        assertThat(gradleProject.mArmDir).exists()\n        assertThat(gradleProject.mArmv7aDir).exists()\n\n        assertThat(gradleProject.mArmDepFile).exists()\n        assertThat(gradleProject.mArmv7aDepFile).exists()\n    }\n\n    @Artifacts(\"artifact group: 'com.snappydb', name: 'snappydb-native', version: '0.2.+', classifier: 'armeabi'\")\n    @Test\n    public void testRangeNotationResolveWithMapping() {\n        assertThat(gradleProject.mJniLibs).exists()\n\n        assertThat(gradleProject.mArmDir).exists()\n\n        assertThat(gradleProject.mArmDepFile).exists()\n    }\n\n    @Artifacts(\"artifact 'com.snappydb:snappydb-native:0.2.+:x86'\")\n    @Test\n    public void testRangeNotationResolveWithStringNotation() {\n        assertThat(gradleProject.mJniLibs).exists()\n\n        assertThat(gradleProject.mX86Dir).exists()\n\n        assertThat(gradleProject.mX86DepFile).exists()\n    }\n\n    // Testing addLibPrefixToArtifact closure\n\n    @Artifacts(\"artifact (group: 'com.snappydb', name: 'snappydb-native', version: '0.2.0', classifier: 'mips') { addLibPrefixToArtifact=false }\")\n    @Test\n    public void testDisableLibPrefixStringNotation() {\n        assertThat(gradleProject.mJniLibs).exists()\n        assertThat(gradleProject.mMipsDir).exists()\n        assertThat(gradleProject.mMipsDepFileNoLibPrefix).exists()\n    }\n\n    @Artifacts(\"artifact (group: 'com.snappydb', name: 'snappydb-native', version: '0.2.0', classifier: 'mips') { addLibPrefixToArtifact=true }\")\n    @Test\n    public void testEnableLibPrefixStringNotation() {\n        assertThat(gradleProject.mJniLibs).exists()\n        assertThat(gradleProject.mMipsDir).exists()\n        assertThat(gradleProject.mMipsDepFile).exists()\n    }\n\n    @Artifacts([\"artifact ('com.snappydb:snappydb-native:0.2.0:mips') { addLibPrefixToArtifact = false } \",\n            \"artifact 'com.snappydb:snappydb-native:0.2.0:x86'\",\n            \"artifact ('com.snappydb:snappydb-native:0.2.0:armeabi') { addLibPrefixToArtifact = false } \",\n            \"artifact 'com.snappydb:snappydb-native:0.2.0:armeabi-v7a'\"])\n    @Test\n    public void testLibPrefixMixStringNotation() {\n        assertThat(gradleProject.mJniLibs).exists()\n        assertThat(gradleProject.mMipsDir).exists()\n        assertThat(gradleProject.mX86Dir).exists()\n        assertThat(gradleProject.mArmDir).exists()\n        assertThat(gradleProject.mArmv7aDir).exists()\n\n        assertThat(gradleProject.mMipsDepFileNoLibPrefix).exists()\n        assertThat(gradleProject.mX86DepFile).exists()\n        assertThat(gradleProject.mArmDepFileNoLibPrefix).exists()\n        assertThat(gradleProject.mArmv7aDepFile).exists()\n    }\n\n    @Artifacts([\"artifact (group: 'com.snappydb', name: 'snappydb-native', version: '0.2.0', classifier: 'mips') {}\",\n            \"artifact (group: 'com.snappydb', name: 'snappydb-native', version: '0.2.0', classifier: 'x86') { addLibPrefixToArtifact=false }\",\n            \"artifact (group: 'com.snappydb', name: 'snappydb-native', version: '0.2.0', classifier: 'armeabi')\",\n            \"artifact (group: 'com.snappydb', name: 'snappydb-native', version: '0.2.0', classifier: 'armeabi-v7a') { addLibPrefixToArtifact=false }\"])\n    @Test\n    public void testLibPrefixMixMappingNotation() {\n        assertThat(gradleProject.mJniLibs).exists()\n        assertThat(gradleProject.mMipsDir).exists()\n        assertThat(gradleProject.mX86Dir).exists()\n        assertThat(gradleProject.mArmDir).exists()\n        assertThat(gradleProject.mArmv7aDir).exists()\n\n        assertThat(gradleProject.mMipsDepFile).exists()\n        assertThat(gradleProject.mX86DepFileNoLibPrefix).exists()\n        assertThat(gradleProject.mArmDepFile).exists()\n        assertThat(gradleProject.mArmv7aDepFileNoLibPrefix).exists()\n    }\n}"
  },
  {
    "path": "src/test/groovy/com/nabilhachicha/nativedependencies/utils/AccessibleErrorCollector.java",
    "content": "package com.nabilhachicha.nativedependencies.utils;\n\nimport org.junit.rules.ErrorCollector;\n\n/**\n * Created by Nabil on 12/05/15.\n * Expose {@link ErrorCollector#verify()} method as public\n */\npublic class AccessibleErrorCollector extends ErrorCollector {\n    @Override\n    public void verify() throws Throwable {\n        super.verify();\n    }\n}"
  },
  {
    "path": "src/test/groovy/com/nabilhachicha/nativedependencies/utils/Artifacts.java",
    "content": "/*\n * Copyright (C) 2014 Nabil HACHICHA.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *      http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage com.nabilhachicha.nativedependencies.utils;\n\nimport java.lang.annotation.Retention;\nimport java.lang.annotation.Target;\n\nimport static java.lang.annotation.ElementType.METHOD;\nimport static java.lang.annotation.RetentionPolicy.RUNTIME;\n\n\n@Target(METHOD) @Retention(RUNTIME)\npublic @interface Artifacts {\n    String[] value ();\n}"
  },
  {
    "path": "src/test/groovy/com/nabilhachicha/nativedependencies/utils/ConfPath.groovy",
    "content": "package com.nabilhachicha.nativedependencies.utils;\n\n/**\n * Created by Nabil on 12/05/15.\n */\npublic class ConfPath {\n    String path\n    String jniLibsLocation\n}\n"
  },
  {
    "path": "src/test/groovy/com/nabilhachicha/nativedependencies/utils/TempGradleProject.groovy",
    "content": "/*\n * Copyright (C) 2014 Nabil HACHICHA.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *      http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage com.nabilhachicha.nativedependencies.utils\n\nimport org.apache.commons.io.FileUtils\nimport org.junit.rules.TemporaryFolder\nimport org.junit.runner.Description\nimport org.junit.runners.model.Statement\n\npublic class TempGradleProject extends TemporaryFolder {\n    final ConfPath[] gradleTemplateDir\n    final String GRADLE_BUILD_FILE = \"build.gradle\"\n    File gradleFile\n    String[] artifacts\n    ConfPath currentDir;\n\n    // Param\n    File mJniLibs\n\n    File mMipsDir\n    File mX86Dir\n    File mArmDir\n    File mArmv7aDir\n\n    File mMipsDepFile\n    File mX86DepFile\n    File mArmDepFile\n    File mArmv7aDepFile\n\n    File mMipsDepFileNoLibPrefix\n    File mX86DepFileNoLibPrefix\n    File mArmDepFileNoLibPrefix\n    File mArmv7aDepFileNoLibPrefix\n\n    public TempGradleProject(ConfPath... templateDir) {\n        gradleTemplateDir = templateDir\n    }\n\n    @Override\n    protected void before() throws Throwable {\n        super.before();\n\n        File templateDir = new File(currentDir.path)\n\n        def root = getRoot()\n        FileUtils.copyDirectory(templateDir, root)\n\n        gradleFile = new File(root, GRADLE_BUILD_FILE)\n\n        mJniLibs = new File(root.absolutePath + currentDir.jniLibsLocation)\n\n        mMipsDir = new File(mJniLibs, 'mips')\n        mX86Dir = new File(mJniLibs, 'x86')\n        mArmDir = new File(mJniLibs, 'armeabi')\n        mArmv7aDir = new File(mJniLibs, 'armeabi-v7a')\n\n        mMipsDepFile = new File(mMipsDir, 'libsnappydb-native.so')\n        mX86DepFile = new File(mX86Dir, 'libsnappydb-native.so')\n        mArmDepFile = new File(mArmDir, 'libsnappydb-native.so')\n        mArmv7aDepFile = new File(mArmv7aDir, 'libsnappydb-native.so')\n\n        mMipsDepFileNoLibPrefix = new File(mMipsDir, 'snappydb-native.so')\n        mX86DepFileNoLibPrefix = new File(mX86Dir, 'snappydb-native.so')\n        mArmDepFileNoLibPrefix = new File(mArmDir, 'snappydb-native.so')\n        mArmv7aDepFileNoLibPrefix = new File(mArmv7aDir, 'snappydb-native.so')\n\n    }\n\n    @Override\n    public Statement apply(Statement base, Description description) {\n        Artifacts annotation = description.getAnnotation(Artifacts.class);\n        if (annotation == null) {\n            throw new IllegalStateException(String.format(\"Test '%s' missing @Artifacts annotation.\",\n                    description.getDisplayName()));\n        }\n        artifacts = annotation.value();\n        return new RepeatedStatement(base, gradleTemplateDir);\n    }\n\n\n    class RepeatedStatement extends Statement {\n        final ConfPath[] dirPaths;\n        final Statement test;\n        final AccessibleErrorCollector errorCollector;\n\n        public RepeatedStatement(Statement test, ConfPath[] dirPaths) {\n            this.dirPaths = dirPaths;\n            this.test = test;\n            this.errorCollector = new AccessibleErrorCollector();\n        }\n\n\n        @Override\n        public void evaluate() throws Throwable {\n            for (ConfPath path : dirPaths) {\n                currentDir = path;\n                before();\n\n                try {\n                    test.evaluate();\n                } catch (Throwable t) {\n                    errorCollector.addError(new AssertionError(\"For dir: \" + currentDir.path, t));\n                } finally {\n                    after();\n                }\n            }\n\n            errorCollector.verify();\n        }\n    }\n}"
  }
]