├── paperwork-example
├── proguard-rules.pro
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ ├── values
│ │ │ ├── strings.xml
│ │ │ ├── colors.xml
│ │ │ ├── dimens.xml
│ │ │ └── styles.xml
│ │ ├── mipmap-hdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ │ └── ic_launcher.png
│ │ ├── values-w820dp
│ │ │ └── dimens.xml
│ │ └── layout
│ │ │ └── activity_main.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── hu
│ │ └── supercluster
│ │ └── paperwork
│ │ └── example
│ │ └── MainActivity.java
└── build.gradle
├── paperwork-plugin
├── .gitignore
├── src
│ ├── main
│ │ ├── resources
│ │ │ └── META-INF
│ │ │ │ └── gradle-plugins
│ │ │ │ ├── paperwork.properties
│ │ │ │ └── hu.supercluster.paperwork.properties
│ │ └── groovy
│ │ │ └── hu
│ │ │ └── supercluster
│ │ │ └── paperwork
│ │ │ └── plugin
│ │ │ ├── PaperworkPlugin.groovy
│ │ │ └── PaperworkPluginExtension.groovy
│ └── test
│ │ └── groovy
│ │ └── hu
│ │ └── supercluster
│ │ └── paperwork
│ │ └── plugin
│ │ └── PaperworkPluginExtensionTest.groovy
├── build.gradle
└── maven-push.gradle
├── paperwork-runtime
├── proguard-rules.pro
├── .gitignore
├── src
│ ├── test
│ │ ├── assets
│ │ │ ├── test.json
│ │ │ ├── paperwork.json
│ │ │ └── multiple_keys.json
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── hu
│ │ │ └── supercluster
│ │ │ └── paperwork
│ │ │ └── PaperworkTest.java
│ └── main
│ │ ├── res
│ │ └── values
│ │ │ └── strings.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── hu
│ │ └── supercluster
│ │ └── paperwork
│ │ ├── PaperworkException.java
│ │ └── Paperwork.java
├── build.gradle
└── maven-push.gradle
├── paperwork-integration
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ └── layout
│ │ │ │ └── activity_main.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── hu
│ │ │ └── supercluster
│ │ │ └── paperwork
│ │ │ └── integration
│ │ │ └── MainActivity.java
│ └── androidTest
│ │ └── java
│ │ └── hu
│ │ └── supercluster
│ │ └── paperwork
│ │ └── integration
│ │ ├── matcher
│ │ ├── GitShaMatcher.java
│ │ ├── RegexMatcher.java
│ │ └── BuildTimeMatcher.java
│ │ ├── runner
│ │ └── PaperworkTestRunner.java
│ │ └── test
│ │ └── MainActivityTest.java
├── proguard-rules.pro
└── build.gradle
├── scripts
├── test.sh
├── refresh-integration-dependencies.sh
└── run-tests.sh
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── .travis.yml
├── CHANGELOG.md
├── gradlew.bat
├── gradlew
├── README.md
└── LICENSE
/paperwork-example/proguard-rules.pro:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/paperwork-plugin/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/paperwork-runtime/proguard-rules.pro:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/paperwork-runtime/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/paperwork-runtime/src/test/assets/test.json:
--------------------------------------------------------------------------------
1 | { "key": "value" }
--------------------------------------------------------------------------------
/paperwork-example/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 | /src/main/assets/paperwork.json
3 |
--------------------------------------------------------------------------------
/paperwork-integration/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 | /src/main/assets/integration.json
3 |
--------------------------------------------------------------------------------
/paperwork-runtime/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/paperwork-runtime/src/test/assets/paperwork.json:
--------------------------------------------------------------------------------
1 | { "testing rocks": "hell yeah" }
--------------------------------------------------------------------------------
/scripts/test.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | echo "String output of test.sh"
4 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':paperwork-runtime', ':paperwork-plugin', ':paperwork-integration'
2 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zsoltk/paperwork/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/paperwork-runtime/src/test/assets/multiple_keys.json:
--------------------------------------------------------------------------------
1 | { "key 1": "value 1", "key 2": "value 2", "key 3": "value 3" }
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | .idea
4 | gradle.properties
5 | /local.properties
6 | .DS_Store
7 | /build
8 | /captures
9 |
--------------------------------------------------------------------------------
/scripts/refresh-integration-dependencies.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | cp -r paperwork-plugin/src/main/groovy/* buildSrc/src/main/groovy/
--------------------------------------------------------------------------------
/paperwork-example/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | paperwork-example
3 |
4 |
--------------------------------------------------------------------------------
/paperwork-integration/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Integration
3 |
4 |
--------------------------------------------------------------------------------
/paperwork-plugin/src/main/resources/META-INF/gradle-plugins/paperwork.properties:
--------------------------------------------------------------------------------
1 | implementation-class=hu.supercluster.paperwork.plugin.PaperworkPlugin
2 |
--------------------------------------------------------------------------------
/paperwork-example/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zsoltk/paperwork/HEAD/paperwork-example/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/paperwork-example/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zsoltk/paperwork/HEAD/paperwork-example/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/paperwork-example/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zsoltk/paperwork/HEAD/paperwork-example/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/paperwork-example/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zsoltk/paperwork/HEAD/paperwork-example/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/paperwork-plugin/src/main/resources/META-INF/gradle-plugins/hu.supercluster.paperwork.properties:
--------------------------------------------------------------------------------
1 | implementation-class=hu.supercluster.paperwork.plugin.PaperworkPlugin
2 |
--------------------------------------------------------------------------------
/paperwork-example/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zsoltk/paperwork/HEAD/paperwork-example/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/paperwork-integration/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zsoltk/paperwork/HEAD/paperwork-integration/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/paperwork-integration/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zsoltk/paperwork/HEAD/paperwork-integration/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/paperwork-integration/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zsoltk/paperwork/HEAD/paperwork-integration/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/paperwork-integration/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zsoltk/paperwork/HEAD/paperwork-integration/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/paperwork-integration/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zsoltk/paperwork/HEAD/paperwork-integration/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/paperwork-runtime/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/paperwork-runtime/src/test/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/scripts/run-tests.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ./gradlew clean \
4 | build \
5 | :paperwork-plugin:test \
6 | :paperwork-runtime:test \
7 | :paperwork-integration:connectedCheck
8 |
9 |
--------------------------------------------------------------------------------
/paperwork-example/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/paperwork-example/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/paperwork-integration/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/paperwork-integration/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Oct 21 11:34:03 PDT 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.9-all.zip
7 |
--------------------------------------------------------------------------------
/paperwork-integration/src/androidTest/java/hu/supercluster/paperwork/integration/matcher/GitShaMatcher.java:
--------------------------------------------------------------------------------
1 | package hu.supercluster.paperwork.integration.matcher;
2 |
3 | public class GitShaMatcher extends RegexMatcher {
4 | public GitShaMatcher() {
5 | super("[0-9a-f]{7}");
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/paperwork-example/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/paperwork-integration/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/paperwork-example/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/paperwork-integration/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/paperwork-integration/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /home/zzss/Apps/android-sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: android
2 | android:
3 | components:
4 | - platform-tools
5 | - tools
6 | - android-23
7 | - build-tools-23.0.2
8 | - extra-android-m2repository
9 | - extra-android-support
10 | - sys-img-armeabi-v7a-android-18
11 |
12 | before_cache:
13 | - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
14 |
15 | cache:
16 | directories:
17 | - $HOME/.gradle/caches/
18 | - $HOME/.gradle/wrapper/
19 |
20 | before_script:
21 | - echo no | android create avd --force -n test -t android-18 --abi armeabi-v7a
22 | - emulator -avd test -no-audio -no-window &
23 | - android-wait-for-emulator
24 | - adb shell date -s `date +"%Y%m%d.%H%M%S"`
25 | - adb shell input keyevent 82
26 |
27 | script:
28 | - scripts/run-tests.sh
--------------------------------------------------------------------------------
/paperwork-plugin/src/main/groovy/hu/supercluster/paperwork/plugin/PaperworkPlugin.groovy:
--------------------------------------------------------------------------------
1 | package hu.supercluster.paperwork.plugin
2 |
3 | import groovy.json.JsonOutput
4 | import org.gradle.api.Plugin
5 | import org.gradle.api.Project
6 |
7 | class PaperworkPlugin implements Plugin {
8 |
9 | void apply(Project project) {
10 | project.extensions.create("paperwork", PaperworkPluginExtension, project)
11 | project.afterEvaluate({
12 | File file = getFile(project)
13 |
14 | def set = project.paperwork.set
15 | def paperwork = JsonOutput.toJson(set)
16 |
17 | file.write paperwork
18 | })
19 | }
20 |
21 | private File getFile(Project project) {
22 | def file = project.file(project.paperwork.filename)
23 | file.parentFile.mkdirs()
24 | file
25 | }
26 | }
--------------------------------------------------------------------------------
/paperwork-runtime/src/main/java/hu/supercluster/paperwork/PaperworkException.java:
--------------------------------------------------------------------------------
1 | package hu.supercluster.paperwork;
2 |
3 | public class PaperworkException extends RuntimeException {
4 | public PaperworkException() {
5 | }
6 |
7 | public PaperworkException(String detailMessage) {
8 | super(detailMessage);
9 | }
10 |
11 | public PaperworkException(String detailMessage, Throwable throwable) {
12 | super(detailMessage, throwable);
13 | }
14 |
15 | public PaperworkException(Throwable throwable) {
16 | super(throwable);
17 | }
18 |
19 | public PaperworkException(String template, String filename) {
20 | super(String.format(template, filename));
21 | }
22 |
23 | public PaperworkException(String template, String filename, Throwable throwable) {
24 | super(String.format(template, filename), throwable);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/paperwork-example/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/paperwork-plugin/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | jcenter()
4 | }
5 |
6 | dependencies {
7 | classpath 'com.android.tools.build:gradle:1.5.0'
8 | }
9 | }
10 |
11 | apply plugin: 'groovy'
12 | sourceCompatibility = 1.6
13 | targetCompatibility = 1.6
14 |
15 | // gradle.properties holds credentials and is not checked in
16 | def gradleProperties = new File('gradle.properties')
17 | if (gradleProperties.exists()) {
18 | apply from: 'maven-push.gradle'
19 | }
20 |
21 | repositories {
22 | jcenter()
23 | mavenCentral()
24 | }
25 |
26 | dependencies {
27 | compile gradleApi()
28 | compile localGroovy()
29 |
30 | }
31 |
32 | test {
33 | testLogging {
34 | events 'passed', 'skipped', 'failed', 'standardOut', 'standardError'
35 | outputs.upToDateWhen { false }
36 | showStandardStreams = true
37 | exceptionFormat "full"
38 | }
39 | }
--------------------------------------------------------------------------------
/paperwork-integration/src/androidTest/java/hu/supercluster/paperwork/integration/matcher/RegexMatcher.java:
--------------------------------------------------------------------------------
1 | package hu.supercluster.paperwork.integration.matcher;
2 |
3 | import org.hamcrest.Description;
4 | import org.hamcrest.TypeSafeMatcher;
5 |
6 | public class RegexMatcher extends TypeSafeMatcher {
7 | public final String pattern;
8 |
9 | public RegexMatcher(String pattern) {
10 | this.pattern = pattern;
11 | }
12 |
13 | @Override
14 | protected boolean matchesSafely(String item) {
15 | return item.matches(pattern);
16 | }
17 |
18 | @Override
19 | public void describeTo(Description description) {
20 | description.appendText(" matches regex: "+ pattern +"");
21 | }
22 |
23 | @Override
24 | protected void describeMismatchSafely(String item, Description mismatchDescription) {
25 | mismatchDescription.appendText("supplied text was: " + item);
26 |
27 | super.describeMismatchSafely(item, mismatchDescription);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/paperwork-integration/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | Change Log
2 | ==========
3 |
4 | Version 1.2.0 *(2016-01-15)*
5 | ----------------------------
6 |
7 | * A more generic approach: nothing is generated by default
8 | * BC breaking changes in plugin configuration and runtime:
9 | * Removed ```env```, ```extra```, ```gitSha```, ```buildTime``` config keys
10 | * Removed ```getEnv()```, ```getExtra()```, ```getGitSha()```, ```getBuildTime()``` runtime methods
11 | * Added ```set``` config key and ```get()``` runtime method
12 | * Added plugin config helpers for commonly used functions: ```gitSha()```, ```gitTag()```, ```gitInfo()```, ```buildTime()```, ```env()```, ```shell()```
13 |
14 | Version 1.1.0 *(2015-12-26)*
15 | ----------------------------
16 |
17 | * Direct support for environment variables
18 | * Allow override for plugin parameters ```gitSha``` and ```buildTime```
19 | * Renamed plugin parameter ```outputFilename``` to ```filename```
20 | * Renamed plugin parameter ```extra``` to ```extras```
21 | * Renamed runtime getter ```getExtra()``` to ```getExtras()```
22 | * Added runtime method ```getExtra(key)``` to access an extra value directly
23 |
24 |
25 | Version 1.0.0 *(2015-12-24)*
26 | ----------------------------
27 |
28 | Initial release.
29 |
--------------------------------------------------------------------------------
/paperwork-runtime/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | // gradle.properties holds credentials and is not checked in
4 | def gradleProperties = new File('gradle.properties')
5 | if (gradleProperties.exists()) {
6 | apply from: 'maven-push.gradle'
7 | }
8 |
9 | android {
10 | compileSdkVersion 23
11 | buildToolsVersion "23.0.2"
12 |
13 | defaultConfig {
14 | minSdkVersion 8
15 | targetSdkVersion 23
16 | versionCode 1
17 | versionName "1.0"
18 | }
19 |
20 | compileOptions {
21 | sourceCompatibility 1.6
22 | targetCompatibility 1.6
23 | }
24 |
25 | buildTypes {
26 | release {
27 | minifyEnabled false
28 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
29 | }
30 | }
31 |
32 | testOptions.unitTests.all {
33 | testLogging {
34 | events 'passed', 'skipped', 'failed', 'standardOut', 'standardError'
35 | outputs.upToDateWhen { false }
36 | showStandardStreams = true
37 | exceptionFormat "full"
38 | }
39 | }
40 | }
41 |
42 | dependencies {
43 | testCompile 'junit:junit:4.12'
44 | testCompile 'org.mockito:mockito-core:1.10.19'
45 | testCompile 'org.robolectric:robolectric:3.0'
46 | }
47 |
--------------------------------------------------------------------------------
/paperwork-plugin/src/main/groovy/hu/supercluster/paperwork/plugin/PaperworkPluginExtension.groovy:
--------------------------------------------------------------------------------
1 | package hu.supercluster.paperwork.plugin
2 |
3 | class PaperworkPluginExtension {
4 | private final Object project
5 | def String filename = "src/main/assets/paperwork.json"
6 | def Map set = [:]
7 |
8 | PaperworkPluginExtension(project) {
9 | this.project = project
10 | }
11 |
12 | public String shell(String cmd) {
13 | cmd.execute([], project.rootDir).text.trim()
14 | }
15 |
16 | public String gitSha() {
17 | shell('git rev-parse --short HEAD')
18 | }
19 |
20 | public String gitTag() {
21 | shell('git describe --tags --abbrev=0')
22 | }
23 |
24 | public String gitInfo() {
25 | shell('git describe --tags --always --dirty')
26 | }
27 |
28 | public String gitBranch() {
29 | (shell('git branch') =~ /(?m)\* (.*)$/)[0][1]
30 | }
31 |
32 | public String buildTime() {
33 | new Date().getTime();
34 | }
35 |
36 | public String buildTime(String format) {
37 | new Date().format(format)
38 | }
39 |
40 | public String buildTime(String format, String timeZoneId) {
41 | new Date().format(format, TimeZone.getTimeZone(timeZoneId))
42 | }
43 |
44 | public String env(String var) {
45 | System.getenv(var)
46 | }
47 | }
--------------------------------------------------------------------------------
/paperwork-integration/src/androidTest/java/hu/supercluster/paperwork/integration/runner/PaperworkTestRunner.java:
--------------------------------------------------------------------------------
1 | package hu.supercluster.paperwork.integration.runner;
2 |
3 | import android.app.KeyguardManager;
4 | import android.content.Context;
5 | import android.os.PowerManager;
6 | import android.support.test.runner.AndroidJUnitRunner;
7 |
8 | import static android.content.Context.KEYGUARD_SERVICE;
9 | import static android.content.Context.POWER_SERVICE;
10 | import static android.os.PowerManager.ACQUIRE_CAUSES_WAKEUP;
11 | import static android.os.PowerManager.FULL_WAKE_LOCK;
12 | import static android.os.PowerManager.ON_AFTER_RELEASE;
13 |
14 | public class PaperworkTestRunner extends AndroidJUnitRunner {
15 | private PowerManager.WakeLock wakeLock;
16 |
17 | @Override
18 | public void onStart() {
19 | Context app = getTargetContext().getApplicationContext();
20 | String name = getClass().getSimpleName();
21 |
22 | KeyguardManager keyguard = (KeyguardManager) app.getSystemService(KEYGUARD_SERVICE);
23 | keyguard.newKeyguardLock(name).disableKeyguard();
24 |
25 | PowerManager power = (PowerManager) app.getSystemService(POWER_SERVICE);
26 | wakeLock = power.newWakeLock(FULL_WAKE_LOCK | ACQUIRE_CAUSES_WAKEUP | ON_AFTER_RELEASE, name);
27 | wakeLock.acquire();
28 |
29 | super.onStart();
30 | }
31 |
32 | @Override public void onDestroy() {
33 | super.onDestroy();
34 |
35 | wakeLock.release();
36 | }
37 | }
--------------------------------------------------------------------------------
/paperwork-runtime/src/test/java/hu/supercluster/paperwork/PaperworkTest.java:
--------------------------------------------------------------------------------
1 | package hu.supercluster.paperwork;
2 |
3 | import static org.junit.Assert.assertEquals;
4 |
5 | import org.junit.Test;
6 | import org.junit.runner.RunWith;
7 | import org.robolectric.RobolectricTestRunner;
8 | import org.robolectric.RuntimeEnvironment;
9 | import org.robolectric.annotation.Config;
10 |
11 | @Config(sdk = 18, manifest = "src/test/AndroidManifest.xml")
12 | @RunWith(RobolectricTestRunner.class)
13 | public class PaperworkTest {
14 | @Test
15 | public void testDefaultFileName() {
16 | assertEquals("paperwork.json", Paperwork.DEFAULT_FILENAME);
17 | }
18 |
19 | @Test
20 | public void testPaperworkCustomFileName() {
21 | final Paperwork paperwork = new Paperwork(RuntimeEnvironment.application, "test.json");
22 |
23 | assertEquals("value", paperwork.get("key"));
24 | }
25 |
26 | @Test
27 | public void testPaperworkDefaultFileName() {
28 | final Paperwork paperwork = new Paperwork(RuntimeEnvironment.application);
29 | assertEquals("hell yeah", paperwork.get("testing rocks"));
30 | }
31 |
32 | @Test
33 | public void testPaperworkMultipleKeys() {
34 | final Paperwork paperwork = new Paperwork(RuntimeEnvironment.application, "multiple_keys.json");
35 |
36 | assertEquals("value 1", paperwork.get("key 1"));
37 | assertEquals("value 2", paperwork.get("key 2"));
38 | assertEquals("value 3", paperwork.get("key 3"));
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/paperwork-example/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | mavenCentral()
4 | }
5 |
6 | dependencies {
7 | classpath 'com.android.tools.build:gradle:1.5.0'
8 | classpath 'hu.supercluster:paperwork-plugin:1.2.7'
9 | }
10 | }
11 |
12 | apply plugin: 'com.android.application'
13 | apply plugin: 'hu.supercluster.paperwork'
14 |
15 | paperwork {
16 | set = [
17 | simpleKey: "simpleValue",
18 | buildTime1: buildTime(),
19 | buildTime2: buildTime("yyyy-MM-dd HH:mm:ss"),
20 | buildTime3: buildTime("yyyy-MM-dd HH:mm:ss", "GMT"),
21 | buildTime4: buildTime("yyyy-MM-dd HH:mm:ss", "Pacific/Honolulu"),
22 | gitSha: gitSha(),
23 | gitTag: gitTag(),
24 | gitInfo: gitInfo(),
25 | gitBranch: gitBranch(),
26 | shell: shell("scripts/test.sh"),
27 | someEnv: env("USER")
28 | ]
29 | }
30 |
31 | android {
32 | compileSdkVersion 23
33 | buildToolsVersion "23.0.2"
34 |
35 | defaultConfig {
36 | applicationId "hu.supercluster.paperwork.example"
37 | minSdkVersion 15
38 | targetSdkVersion 23
39 | versionCode 1
40 | versionName "1.0"
41 | }
42 |
43 | buildTypes {
44 | release {
45 | minifyEnabled false
46 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
47 | }
48 | }
49 |
50 | lintOptions {
51 | textReport true
52 | textOutput 'stdout'
53 | }
54 | }
55 |
56 | dependencies {
57 | compile 'com.android.support:appcompat-v7:23.2.0'
58 | compile 'com.jakewharton:butterknife:7.0.1'
59 | compile 'hu.supercluster:paperwork:1.2.7'
60 |
61 | testCompile 'junit:junit:4.12'
62 | }
63 |
--------------------------------------------------------------------------------
/paperwork-example/src/main/java/hu/supercluster/paperwork/example/MainActivity.java:
--------------------------------------------------------------------------------
1 | package hu.supercluster.paperwork.example;
2 |
3 | import android.support.v7.app.AppCompatActivity;
4 | import android.os.Bundle;
5 | import android.widget.TextView;
6 |
7 | import butterknife.Bind;
8 | import butterknife.ButterKnife;
9 | import hu.supercluster.paperwork.Paperwork;
10 |
11 |
12 | public class MainActivity extends AppCompatActivity {
13 | @Bind(R.id.simpleKey) TextView simpleKey;
14 | @Bind(R.id.buildTime1) TextView buildTime1;
15 | @Bind(R.id.buildTime2) TextView buildTime2;
16 | @Bind(R.id.buildTime3) TextView buildTime3;
17 | @Bind(R.id.buildTime4) TextView buildTime4;
18 | @Bind(R.id.gitSha) TextView gitSha;
19 | @Bind(R.id.gitTag) TextView gitTag;
20 | @Bind(R.id.gitInfo) TextView gitInfo;
21 | @Bind(R.id.gitBranch) TextView gitBranch;
22 | @Bind(R.id.shell) TextView shell;
23 | @Bind(R.id.env) TextView env;
24 |
25 | @Override
26 | protected void onCreate(Bundle savedInstanceState) {
27 | super.onCreate(savedInstanceState);
28 | setContentView(R.layout.activity_main);
29 | ButterKnife.bind(this);
30 | showPaperwork();
31 | }
32 |
33 | private void showPaperwork() {
34 | final Paperwork paperwork = new Paperwork(this);
35 |
36 | simpleKey.setText(paperwork.get("simpleKey"));
37 | buildTime1.setText(paperwork.get("buildTime1"));
38 | buildTime2.setText(paperwork.get("buildTime2"));
39 | buildTime3.setText(paperwork.get("buildTime3"));
40 | buildTime4.setText(paperwork.get("buildTime4"));
41 | gitSha.setText(paperwork.get("gitSha"));
42 | gitTag.setText(paperwork.get("gitTag"));
43 | gitInfo.setText(paperwork.get("gitInfo"));
44 | gitBranch.setText(paperwork.get("gitBranch"));
45 | shell.setText(paperwork.get("shell"));
46 | env.setText(paperwork.get("someEnv"));
47 | }
48 | }
--------------------------------------------------------------------------------
/paperwork-integration/src/main/java/hu/supercluster/paperwork/integration/MainActivity.java:
--------------------------------------------------------------------------------
1 | package hu.supercluster.paperwork.integration;
2 |
3 | import android.support.v7.app.AppCompatActivity;
4 | import android.os.Bundle;
5 | import android.widget.TextView;
6 |
7 | import butterknife.Bind;
8 | import butterknife.ButterKnife;
9 | import hu.supercluster.paperwork.Paperwork;
10 |
11 |
12 | public class MainActivity extends AppCompatActivity {
13 | @Bind(R.id.simpleKey) TextView simpleKey;
14 | @Bind(R.id.buildTime1) TextView buildTime1;
15 | @Bind(R.id.buildTime2) TextView buildTime2;
16 | @Bind(R.id.buildTime3) TextView buildTime3;
17 | @Bind(R.id.buildTime4) TextView buildTime4;
18 | @Bind(R.id.gitSha) TextView gitSha;
19 | @Bind(R.id.gitTag) TextView gitTag;
20 | @Bind(R.id.gitInfo) TextView gitInfo;
21 | @Bind(R.id.gitBranch) TextView gitBranch;
22 | @Bind(R.id.shell) TextView shell;
23 | @Bind(R.id.env) TextView env;
24 |
25 | @Override
26 | protected void onCreate(Bundle savedInstanceState) {
27 | super.onCreate(savedInstanceState);
28 | setContentView(R.layout.activity_main);
29 | ButterKnife.bind(this);
30 | showPaperwork();
31 | }
32 |
33 | private void showPaperwork() {
34 | final Paperwork paperwork = new Paperwork(this, "integration.json");
35 |
36 | simpleKey.setText(paperwork.get("simpleKey"));
37 | buildTime1.setText(paperwork.get("buildTime1"));
38 | buildTime2.setText(paperwork.get("buildTime2"));
39 | buildTime3.setText(paperwork.get("buildTime3"));
40 | buildTime4.setText(paperwork.get("buildTime4"));
41 | gitSha.setText(paperwork.get("gitSha"));
42 | gitTag.setText(paperwork.get("gitTag"));
43 | gitInfo.setText(paperwork.get("gitInfo"));
44 | gitBranch.setText(paperwork.get("gitBranch"));
45 | shell.setText(paperwork.get("shell"));
46 | env.setText(paperwork.get("someEnv"));
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/paperwork-runtime/src/main/java/hu/supercluster/paperwork/Paperwork.java:
--------------------------------------------------------------------------------
1 | package hu.supercluster.paperwork;
2 |
3 | import android.content.Context;
4 |
5 | import org.json.JSONException;
6 | import org.json.JSONObject;
7 |
8 | import java.io.BufferedReader;
9 | import java.io.IOException;
10 | import java.io.InputStream;
11 | import java.io.InputStreamReader;
12 |
13 | public class Paperwork {
14 | public static final String DEFAULT_FILENAME = "paperwork.json";
15 |
16 | private final Context context;
17 | private final String filename;
18 | private JSONObject json;
19 |
20 | public Paperwork(Context context) {
21 | this(context, DEFAULT_FILENAME);
22 | }
23 |
24 | public Paperwork(Context context, String filename) {
25 | this.context = context;
26 | this.filename = filename;
27 | }
28 |
29 | public String get(String key) {
30 | init();
31 |
32 | return json.optString(key);
33 | }
34 |
35 | private void init() {
36 | if (json == null) {
37 | try {
38 | json = new JSONObject(getFileContents());
39 |
40 | } catch (JSONException e) {
41 | throw new PaperworkException("The file '%s' contains invalid JSON data", filename, e);
42 | }
43 | }
44 | }
45 |
46 | private String getFileContents() {
47 | StringBuilder builder;
48 |
49 | try {
50 | InputStream stream = context.getAssets().open(filename);
51 | BufferedReader in = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
52 | builder = new StringBuilder();
53 | String str;
54 |
55 | while ((str = in.readLine()) != null) {
56 | builder.append(str);
57 | }
58 |
59 | in.close();
60 |
61 | } catch (IOException e) {
62 | throw new PaperworkException("There was an error parsing the file '%s'", filename, e);
63 | }
64 |
65 | return builder.toString();
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/paperwork-example/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
17 |
18 |
22 |
23 |
27 |
28 |
32 |
33 |
37 |
38 |
42 |
43 |
47 |
48 |
52 |
53 |
57 |
58 |
62 |
63 |
67 |
68 |
69 |
--------------------------------------------------------------------------------
/paperwork-integration/src/androidTest/java/hu/supercluster/paperwork/integration/matcher/BuildTimeMatcher.java:
--------------------------------------------------------------------------------
1 | package hu.supercluster.paperwork.integration.matcher;
2 |
3 | import org.hamcrest.Description;
4 | import org.hamcrest.TypeSafeMatcher;
5 | import org.joda.time.DateTime;
6 | import org.joda.time.DateTimeZone;
7 | import org.joda.time.format.DateTimeFormat;
8 | import org.joda.time.format.DateTimeFormatter;
9 |
10 | public class BuildTimeMatcher extends TypeSafeMatcher {
11 | private final long threshold;
12 | private final String format;
13 | private final String timeZoneId;
14 |
15 | public BuildTimeMatcher(long threshold) {
16 | this(threshold, "");
17 | }
18 |
19 | public BuildTimeMatcher(long threshold, String format) {
20 | this(threshold, format, "");
21 | }
22 |
23 | public BuildTimeMatcher(long threshold, String format, String timeZoneId) {
24 | this.threshold = threshold;
25 | this.format = format;
26 | this.timeZoneId = timeZoneId;
27 | }
28 |
29 | @Override
30 | protected boolean matchesSafely(String item) {
31 | try {
32 | long timestamp = convertToTimestamp(item);
33 | long diff = DateTime.now().minus(timestamp).getMillis();
34 |
35 | return Math.abs(diff) < threshold;
36 |
37 | } catch (NumberFormatException e) {
38 | return false;
39 | }
40 | }
41 |
42 | private long convertToTimestamp(String item) {
43 | if (format.isEmpty()) {
44 | return Long.decode(item);
45 |
46 | } else {
47 | DateTimeFormatter formatter = DateTimeFormat.forPattern(format);
48 | DateTime parsed = formatter.withZone(getTimeZone()).parseDateTime(item);
49 |
50 | return parsed.getMillis();
51 | }
52 | }
53 |
54 | private DateTimeZone getTimeZone() {
55 | return timeZoneId.isEmpty() ? DateTimeZone.getDefault() : DateTimeZone.forID(timeZoneId);
56 | }
57 |
58 | @Override
59 | public void describeTo(Description description) {
60 | description.appendText(
61 | String.format(" holds a timestamp not older than: %d millisecs (current timestamp: %d, %s)",
62 | threshold,
63 | DateTime.now().getMillis(),
64 | DateTime.now().toString(DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss"))
65 | )
66 | );
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/paperwork-integration/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
17 |
18 |
22 |
23 |
27 |
28 |
32 |
33 |
37 |
38 |
42 |
43 |
47 |
48 |
52 |
53 |
57 |
58 |
62 |
63 |
67 |
68 |
69 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/paperwork-plugin/maven-push.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'maven'
2 | apply plugin: 'signing'
3 |
4 |
5 | task javadocJar(type: Jar, dependsOn: javadoc) {
6 | classifier = 'javadoc'
7 | from groovydoc
8 | }
9 |
10 | task sourcesJar(type: Jar) {
11 | from sourceSets.main.allSource
12 | classifier = 'sources'
13 | }
14 |
15 | artifacts {
16 | archives jar
17 | archives javadocJar
18 | archives sourcesJar
19 | }
20 |
21 | if (project.hasProperty("signing.keyId")) {
22 | signing {
23 | sign configurations.archives
24 | }
25 | }
26 |
27 | def isReleaseBuild() {
28 | return VERSION_NAME.contains("SNAPSHOT") == false
29 | }
30 |
31 | def getReleaseRepositoryUrl() {
32 | return hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL
33 | : "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
34 | }
35 |
36 | def getSnapshotRepositoryUrl() {
37 | return hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL
38 | : "https://oss.sonatype.org/content/repositories/snapshots/"
39 | }
40 |
41 | def getRepositoryUsername() {
42 | return hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : ""
43 | }
44 |
45 | def getRepositoryPassword() {
46 | return hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : ""
47 | }
48 |
49 | uploadArchives {
50 | repositories {
51 | mavenDeployer {
52 | beforeDeployment { deployment -> signing.signPom(deployment) }
53 |
54 | pom.groupId = GROUP
55 | pom.artifactId = POM_ARTIFACT_ID
56 | pom.version = VERSION_NAME
57 |
58 | repository(url: getReleaseRepositoryUrl()) {
59 | authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
60 | }
61 |
62 | snapshotRepository(url: getSnapshotRepositoryUrl()) {
63 | authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
64 | }
65 |
66 | uniqueVersion = true
67 |
68 | pom.project {
69 | name POM_NAME
70 | packaging POM_PACKAGING
71 | description POM_DESCRIPTION
72 | url POM_URL
73 |
74 | scm {
75 | url POM_SCM_URL
76 | connection POM_SCM_CONNECTION
77 | developerConnection POM_SCM_DEV_CONNECTION
78 | }
79 |
80 | licenses {
81 | license {
82 | name POM_LICENCE_NAME
83 | url POM_LICENCE_URL
84 | distribution POM_LICENCE_DIST
85 | }
86 | }
87 |
88 | developers {
89 | developer {
90 | id POM_DEVELOPER_ID
91 | name POM_DEVELOPER_NAME
92 | }
93 | }
94 | }
95 | }
96 | }
97 | }
--------------------------------------------------------------------------------
/paperwork-integration/build.gradle:
--------------------------------------------------------------------------------
1 | import hu.supercluster.paperwork.plugin.PaperworkPlugin
2 |
3 | buildscript {
4 | repositories {
5 | mavenCentral()
6 | }
7 |
8 | dependencies {
9 | classpath 'com.android.tools.build:gradle:1.5.0'
10 | }
11 | }
12 |
13 | apply plugin: 'com.android.application'
14 | apply plugin: PaperworkPlugin.class
15 |
16 | paperwork {
17 | filename = 'src/main/assets/integration.json'
18 |
19 | set = [
20 | simpleKey: "simpleValue",
21 | buildTime1: buildTime(),
22 | buildTime2: buildTime("G"),
23 | buildTime3: buildTime("yyyy-MM-dd HH:mm:ss", "GMT"),
24 | buildTime4: buildTime("yyyy-MM-dd HH:mm:ss", "Pacific/Honolulu"),
25 | gitSha: gitSha(),
26 | gitTag: gitTag(),
27 | gitInfo: gitInfo(),
28 | gitBranch: gitBranch(),
29 | shell: shell("scripts/test.sh"),
30 | someEnv: env("USER")
31 | ]
32 | }
33 |
34 | android {
35 | compileSdkVersion 23
36 | buildToolsVersion "23.0.2"
37 |
38 | defaultConfig {
39 | applicationId "hu.supercluster.paperwork.integration"
40 | minSdkVersion 15
41 | targetSdkVersion 23
42 | versionCode 1
43 | versionName "1.0"
44 | testInstrumentationRunner "hu.supercluster.paperwork.integration.runner.PaperworkTestRunner"
45 | }
46 |
47 | buildTypes {
48 | release {
49 | minifyEnabled false
50 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
51 | }
52 | }
53 |
54 | lintOptions {
55 | textReport true
56 | textOutput 'stdout'
57 | warningsAsErrors true
58 | abortOnError true
59 | }
60 |
61 | packagingOptions {
62 | exclude 'LICENSE.txt'
63 | exclude 'META-INF/LICENSE'
64 | exclude 'META-INF/LICENSE.txt'
65 | exclude 'META-INF/license.txt'
66 | exclude 'META-INF/NOTICE'
67 | exclude 'META-INF/NOTICE.txt'
68 | exclude 'META-INF/notice.txt'
69 | exclude 'META-INF/ASL2.0'
70 | exclude 'META-INF/DEPENDENCIES'
71 | exclude 'META-INF/MANIFEST.MF'
72 | exclude 'META-INF/services/javax.annotation.processing.Processor'
73 | }
74 | }
75 |
76 | dependencies {
77 | compile project(':paperwork-runtime')
78 |
79 | compile 'com.android.support:appcompat-v7:23.2.0'
80 | compile 'com.jakewharton:butterknife:7.0.1'
81 |
82 | androidTestCompile 'junit:junit:4.12'
83 | androidTestCompile "com.android.support:support-annotations:23.2.0"
84 | androidTestCompile "com.android.support.test:runner:0.4.1"
85 | androidTestCompile "com.android.support.test:rules:0.4.1"
86 | androidTestCompile "com.android.support.test.espresso:espresso-core:2.2.1"
87 | androidTestCompile "org.hamcrest:hamcrest-library:1.1"
88 | androidTestCompile "joda-time:joda-time:2.9.1"
89 | }
90 |
--------------------------------------------------------------------------------
/paperwork-plugin/src/test/groovy/hu/supercluster/paperwork/plugin/PaperworkPluginExtensionTest.groovy:
--------------------------------------------------------------------------------
1 | package hu.supercluster.paperwork.plugin
2 |
3 | import org.gradle.testfixtures.ProjectBuilder
4 | import org.junit.After
5 | import org.junit.Before
6 | import org.junit.Test
7 |
8 | import java.util.concurrent.TimeUnit
9 |
10 | class PaperworkPluginExtensionTest {
11 | private static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss"
12 | private static final String TEST_STRING = "Test string 123"
13 | private static final int TIMESTAMP_THRESHOLD = TimeUnit.SECONDS.toMillis(10)
14 | private def extension
15 | private File baseDir
16 |
17 | @Before
18 | public void setUp() {
19 | baseDir = new File("build/" + UUID.randomUUID().toString())
20 | baseDir.mkdirs()
21 |
22 | def project = ProjectBuilder.builder().withProjectDir(baseDir).build()
23 | extension = new PaperworkPluginExtension(project)
24 | }
25 |
26 | @After
27 | public void tearDown() throws Exception {
28 | baseDir.deleteDir()
29 | }
30 |
31 | @Test
32 | public void testDefaultFileName() {
33 | assert extension.filename == "src/main/assets/paperwork.json"
34 | }
35 |
36 | @Test
37 | public void testSetShouldBeEmptyByDefault() {
38 | assert extension.set.size() == 0
39 | }
40 |
41 | @Test
42 | public void testBuildTime() {
43 | def buildTime = extension.buildTime() as long
44 | def currentTime = new Date().getTime()
45 |
46 | assert fallsWithinThreshold(buildTime, currentTime);
47 | }
48 |
49 | @Test
50 | public void testBuildTimeWithFormat() {
51 | def buildTime = extension.buildTime(DATE_FORMAT)
52 | def parseBack = new Date().parse(DATE_FORMAT, buildTime).getTime();
53 | def currentTime = new Date().getTime()
54 |
55 | assert fallsWithinThreshold(parseBack, currentTime);
56 | }
57 |
58 | @Test
59 | public void testBuildTimeWithFormatAndTimeZone() {
60 | def timeZoneId = "UTC"
61 | def timeZone = TimeZone.getTimeZone(timeZoneId)
62 |
63 | def buildTime = extension.buildTime(DATE_FORMAT, timeZoneId)
64 | def parseBack = new Date().parse(DATE_FORMAT, buildTime, timeZone).getTime();
65 | def currentTime = new Date().getTime()
66 |
67 | assert fallsWithinThreshold(parseBack, currentTime);
68 | }
69 |
70 | private boolean fallsWithinThreshold(long time1, long time2) {
71 | Math.abs(time1 - time2) < TIMESTAMP_THRESHOLD
72 | }
73 |
74 | @Test
75 | public void testShell() {
76 | def testScript = new File(baseDir, "test.sh")
77 | testScript.write(String.format('echo "%s"', TEST_STRING))
78 | testScript.setExecutable(true)
79 |
80 | def result = extension.shell(testScript.absolutePath)
81 |
82 | assert result == TEST_STRING
83 | }
84 |
85 | @Test
86 | public void testEnv() {
87 | def key = "PATH"
88 |
89 | assert extension.env(key) == System.getenv(key)
90 | }
91 | }
--------------------------------------------------------------------------------
/paperwork-runtime/maven-push.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'maven'
2 | apply plugin: 'signing'
3 |
4 | def isReleaseBuild() {
5 | return VERSION_NAME.contains("SNAPSHOT") == false
6 | }
7 |
8 | def getReleaseRepositoryUrl() {
9 | return hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL
10 | : "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
11 | }
12 |
13 | def getSnapshotRepositoryUrl() {
14 | return hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL
15 | : "https://oss.sonatype.org/content/repositories/snapshots/"
16 | }
17 |
18 | def getRepositoryUsername() {
19 | return hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : ""
20 | }
21 |
22 | def getRepositoryPassword() {
23 | return hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : ""
24 | }
25 |
26 | afterEvaluate { project ->
27 | uploadArchives {
28 | repositories {
29 | mavenDeployer {
30 | beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
31 |
32 | pom.groupId = GROUP
33 | pom.artifactId = POM_ARTIFACT_ID
34 | pom.version = VERSION_NAME
35 |
36 | repository(url: getReleaseRepositoryUrl()) {
37 | authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
38 | }
39 |
40 | snapshotRepository(url: getSnapshotRepositoryUrl()) {
41 | authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
42 | }
43 |
44 | pom.project {
45 | name POM_NAME
46 | packaging POM_PACKAGING
47 | description POM_DESCRIPTION
48 | url POM_URL
49 |
50 | scm {
51 | url POM_SCM_URL
52 | connection POM_SCM_CONNECTION
53 | developerConnection POM_SCM_DEV_CONNECTION
54 | }
55 |
56 | licenses {
57 | license {
58 | name POM_LICENCE_NAME
59 | url POM_LICENCE_URL
60 | distribution POM_LICENCE_DIST
61 | }
62 | }
63 |
64 | developers {
65 | developer {
66 | id POM_DEVELOPER_ID
67 | name POM_DEVELOPER_NAME
68 | }
69 | }
70 | }
71 | }
72 | }
73 | }
74 |
75 | task androidSourcesJar(type: Jar) {
76 | classifier = 'sources'
77 | from android.sourceSets.main.java.sourceFiles
78 | }
79 |
80 | task androidJavadocs(type: Javadoc) {
81 | source = android.sourceSets.main.java.sourceFiles
82 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
83 | }
84 |
85 | task androidJavadocsJar(type: Jar) {
86 | classifier = 'javadoc'
87 | from androidJavadocs.destinationDir
88 | }
89 |
90 | artifacts {
91 | archives androidSourcesJar
92 | archives androidJavadocsJar
93 | }
94 |
95 | signing {
96 | required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") }
97 | sign configurations.archives
98 | }
99 | }
--------------------------------------------------------------------------------
/paperwork-integration/src/androidTest/java/hu/supercluster/paperwork/integration/test/MainActivityTest.java:
--------------------------------------------------------------------------------
1 | package hu.supercluster.paperwork.integration.test;
2 |
3 | import android.support.test.espresso.matcher.ViewMatchers;
4 | import android.support.test.rule.ActivityTestRule;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.hamcrest.Matchers;
8 | import org.junit.Rule;
9 | import org.junit.Test;
10 | import org.junit.rules.TestRule;
11 | import org.junit.runner.RunWith;
12 |
13 | import java.util.concurrent.TimeUnit;
14 |
15 | import hu.supercluster.paperwork.integration.*;
16 | import hu.supercluster.paperwork.integration.matcher.BuildTimeMatcher;
17 | import hu.supercluster.paperwork.integration.matcher.GitShaMatcher;
18 |
19 | import static android.support.test.espresso.Espresso.onView;
20 | import static android.support.test.espresso.assertion.ViewAssertions.matches;
21 | import static android.support.test.espresso.matcher.ViewMatchers.withId;
22 | import static android.support.test.espresso.matcher.ViewMatchers.withText;
23 | import static org.hamcrest.CoreMatchers.any;
24 | import static org.hamcrest.CoreMatchers.is;
25 | import static org.hamcrest.Matchers.isEmptyString;
26 | import static org.hamcrest.core.IsNot.not;
27 |
28 | @RunWith(AndroidJUnit4.class)
29 | public class MainActivityTest {
30 | public static final long TIMESTAMP_THRESHOLD = TimeUnit.MINUTES.toMillis(10);
31 | public static final String DATETIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
32 | public static final String TIMEZONE_ID_1 = "GMT";
33 | public static final String TIMEZONE_ID_2 = "Pacific/Honolulu";
34 |
35 | @Rule
36 | public TestRule rule = new ActivityTestRule<>(MainActivity.class);
37 |
38 | @Test
39 | public void shouldHaveCorrectValueForSimpleKey() {
40 | onView(ViewMatchers.withId(hu.supercluster.paperwork.integration.R.id.simpleKey)).check(matches(withText(is("simpleValue"))));
41 | }
42 |
43 | @Test
44 | public void shouldDisplayGitSha() {
45 | onView(ViewMatchers.withId(hu.supercluster.paperwork.integration.R.id.gitSha)).check(matches(withText(new GitShaMatcher())));
46 | }
47 |
48 | @Test
49 | public void shouldDisplayGitTag() {
50 | onView(ViewMatchers.withId(hu.supercluster.paperwork.integration.R.id.gitTag)).check(matches(not(withText(isEmptyString()))));
51 | }
52 |
53 | @Test
54 | public void shouldDisplayGitInfo() {
55 | onView(ViewMatchers.withId(hu.supercluster.paperwork.integration.R.id.gitInfo)).check(matches(not(withText(isEmptyString()))));
56 | }
57 |
58 | @Test
59 | public void shouldDisplayGitBranch() {
60 | onView(ViewMatchers.withId(hu.supercluster.paperwork.integration.R.id.gitBranch)).check(matches(not(withText(isEmptyString()))));
61 | }
62 |
63 | @Test
64 | public void shouldHaveRelevantBuildTime1() {
65 | onView(ViewMatchers.withId(hu.supercluster.paperwork.integration.R.id.buildTime1)).check(matches(withText(new BuildTimeMatcher(TIMESTAMP_THRESHOLD))));
66 | }
67 |
68 | @Test
69 | public void shouldDisplayBuildTime2() {
70 | onView(ViewMatchers.withId(hu.supercluster.paperwork.integration.R.id.buildTime2)).check(matches(withText("AD")));
71 | }
72 |
73 | @Test
74 | public void shouldHaveRelevantBuildTime3() {
75 | onView(ViewMatchers.withId(hu.supercluster.paperwork.integration.R.id.buildTime3)).check(matches(withText(new BuildTimeMatcher(TIMESTAMP_THRESHOLD, DATETIME_FORMAT, TIMEZONE_ID_1))));
76 | }
77 |
78 | @Test
79 | public void shouldHaveRelevantBuildTime4() {
80 | onView(ViewMatchers.withId(hu.supercluster.paperwork.integration.R.id.buildTime4)).check(matches(withText(new BuildTimeMatcher(TIMESTAMP_THRESHOLD, DATETIME_FORMAT, TIMEZONE_ID_2))));
81 | }
82 |
83 | @Test
84 | public void shouldHaveCorrectValueForShell() {
85 | onView(ViewMatchers.withId(hu.supercluster.paperwork.integration.R.id.shell)).check(matches(withText("String output of test.sh")));
86 | }
87 |
88 | @Test
89 | public void shouldDisplayEnv() {
90 | onView(ViewMatchers.withId(hu.supercluster.paperwork.integration.R.id.env)).check(matches(not(withText(isEmptyString()))));
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | scripts/refresh-integration-dependencies.sh
4 |
5 | ##############################################################################
6 | ##
7 | ## Gradle start up script for UN*X
8 | ##
9 | ##############################################################################
10 |
11 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | DEFAULT_JVM_OPTS=""
13 |
14 | APP_NAME="Gradle"
15 | APP_BASE_NAME=`basename "$0"`
16 |
17 | # Use the maximum available, or set MAX_FD != -1 to use that value.
18 | MAX_FD="maximum"
19 |
20 | warn ( ) {
21 | echo "$*"
22 | }
23 |
24 | die ( ) {
25 | echo
26 | echo "$*"
27 | echo
28 | exit 1
29 | }
30 |
31 | # OS specific support (must be 'true' or 'false').
32 | cygwin=false
33 | msys=false
34 | darwin=false
35 | case "`uname`" in
36 | CYGWIN* )
37 | cygwin=true
38 | ;;
39 | Darwin* )
40 | darwin=true
41 | ;;
42 | MINGW* )
43 | msys=true
44 | ;;
45 | esac
46 |
47 | # Attempt to set APP_HOME
48 | # Resolve links: $0 may be a link
49 | PRG="$0"
50 | # Need this for relative symlinks.
51 | while [ -h "$PRG" ] ; do
52 | ls=`ls -ld "$PRG"`
53 | link=`expr "$ls" : '.*-> \(.*\)$'`
54 | if expr "$link" : '/.*' > /dev/null; then
55 | PRG="$link"
56 | else
57 | PRG=`dirname "$PRG"`"/$link"
58 | fi
59 | done
60 | SAVED="`pwd`"
61 | cd "`dirname \"$PRG\"`/" >/dev/null
62 | APP_HOME="`pwd -P`"
63 | cd "$SAVED" >/dev/null
64 |
65 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
66 |
67 | # Determine the Java command to use to start the JVM.
68 | if [ -n "$JAVA_HOME" ] ; then
69 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
70 | # IBM's JDK on AIX uses strange locations for the executables
71 | JAVACMD="$JAVA_HOME/jre/sh/java"
72 | else
73 | JAVACMD="$JAVA_HOME/bin/java"
74 | fi
75 | if [ ! -x "$JAVACMD" ] ; then
76 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
77 |
78 | Please set the JAVA_HOME variable in your environment to match the
79 | location of your Java installation."
80 | fi
81 | else
82 | JAVACMD="java"
83 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
84 |
85 | Please set the JAVA_HOME variable in your environment to match the
86 | location of your Java installation."
87 | fi
88 |
89 | # Increase the maximum file descriptors if we can.
90 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
91 | MAX_FD_LIMIT=`ulimit -H -n`
92 | if [ $? -eq 0 ] ; then
93 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
94 | MAX_FD="$MAX_FD_LIMIT"
95 | fi
96 | ulimit -n $MAX_FD
97 | if [ $? -ne 0 ] ; then
98 | warn "Could not set maximum file descriptor limit: $MAX_FD"
99 | fi
100 | else
101 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
102 | fi
103 | fi
104 |
105 | # For Darwin, add options to specify how the application appears in the dock
106 | if $darwin; then
107 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
108 | fi
109 |
110 | # For Cygwin, switch paths to Windows format before running java
111 | if $cygwin ; then
112 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
113 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
114 | JAVACMD=`cygpath --unix "$JAVACMD"`
115 |
116 | # We build the pattern for arguments to be converted via cygpath
117 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
118 | SEP=""
119 | for dir in $ROOTDIRSRAW ; do
120 | ROOTDIRS="$ROOTDIRS$SEP$dir"
121 | SEP="|"
122 | done
123 | OURCYGPATTERN="(^($ROOTDIRS))"
124 | # Add a user-defined pattern to the cygpath arguments
125 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
126 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
127 | fi
128 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
129 | i=0
130 | for arg in "$@" ; do
131 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
132 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
133 |
134 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
135 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
136 | else
137 | eval `echo args$i`="\"$arg\""
138 | fi
139 | i=$((i+1))
140 | done
141 | case $i in
142 | (0) set -- ;;
143 | (1) set -- "$args0" ;;
144 | (2) set -- "$args0" "$args1" ;;
145 | (3) set -- "$args0" "$args1" "$args2" ;;
146 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
147 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
148 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
149 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
150 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
151 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
152 | esac
153 | fi
154 |
155 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
156 | function splitJvmOpts() {
157 | JVM_OPTS=("$@")
158 | }
159 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
160 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
161 |
162 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
163 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Paperwork
2 | [](https://travis-ci.org/zsoltk/paperwork)
3 |
4 | Generate build info for your Android project without breaking incremental compilation
5 |
6 | ### The problem
7 | A common use case is that you want to include the git hash of the last commit and build time into your project, so that you can use their values in your crash reporting tool (for example).
8 |
9 | The easiest way to do this is to generate them into your ```BuildConfig``` by adding these to your ```build.gradle```
10 |
11 | ```groovy
12 | def gitSha = 'git rev-parse --short HEAD'.execute([], project.rootDir).text.trim()
13 | def buildTime = new Date().format("yyyy-MM-dd'T'HH:mm:ss'Z'", TimeZone.getTimeZone("UTC"))
14 |
15 | android {
16 | defaultConfig {
17 | buildConfigField "String", "GIT_SHA", "\"${gitSha}\""
18 | buildConfigField "String", "BUILD_TIME", "\"${buildTime}\""
19 | }
20 | }
21 | ```
22 |
23 | But this will break incremental builds, resulting in increased build times all the time.
24 |
25 |
26 | ### What this lib offers
27 | Paperwork can generate this information (and more) for you, and put it into a ```paperwork.json``` file inside your assets folder instead of using ```BuildConfig```, and helps you read it from there:
28 |
29 | ```java
30 | Paperwork paperwork = new Paperwork(context);
31 | String gitSha = paperwork.get("gitSha");
32 | String buildTime = paperwork.get("buildTime");
33 | ```
34 |
35 | Not just git hash, not just build time: you define what gets generated, and you can use anything that otherwise would break incremental builds.
36 |
37 | Many helpers are available for the most common scenarios. See the configuration below.
38 |
39 | ### Build time comparison
40 | Measured three consecutive builds per type, running gradle daemon, hitting "Run 'app'" in Android Studio without touching anything else. Generated info: git hash and build time (using seconds) so that it has a new value every time.
41 |
42 | * Without generating build info: *3.989s*, *3.915s*, *3.902s*
43 | * Using BuildConfig fields: *14.843s*, *13.844s*, *13.194s*
44 | * Using Paperwork: *4.356s*, *4.075s*, *4.042s*
45 |
46 | ### Download and setup
47 | Add these dependencies to your ```build.gradle```:
48 |
49 | ```groovy
50 | buildscript {
51 | repositories {
52 | mavenCentral()
53 | }
54 |
55 | dependencies {
56 | classpath 'hu.supercluster:paperwork-plugin:1.2.7'
57 | }
58 | }
59 |
60 | apply plugin: 'hu.supercluster.paperwork'
61 |
62 | paperwork {
63 | // Configuration comes here, see next section for details
64 | }
65 |
66 | dependencies {
67 | compile 'hu.supercluster:paperwork:1.2.7'
68 | }
69 | ```
70 |
71 | Lastly, don't forget to add ```paperwork.json``` to your ```.gitignore``` file.
72 |
73 | ### Configuration
74 | Paperwork doesn't generate anything by default, you have to define whatever data you need in simple key-value pairings. For a list of helper methods you can use, see next section.
75 |
76 | ```groovy
77 | paperwork {
78 | set = [
79 | someKey1: "someValue",
80 | someKey2: someHelperMethod()
81 | ]
82 | }
83 | ```
84 |
85 | All the data will be available at runtime by querying for your own defined keys:
86 |
87 | ```java
88 | Paperwork paperwork = new Paperwork(context);
89 | String data1 = paperwork.get("someKey1"); // will return "someValue"
90 | String data1 = paperwork.get("someKey2"); // will return the result of someHelperMethod()
91 | ```
92 |
93 | You can also change the default filename or generate the file somewhere else:
94 |
95 | ```groovy
96 | paperwork {
97 | filename = 'src/main/assets/paperwork.json'
98 | }
99 | ```
100 |
101 | Note however, that in order for it to be available in Paperwork runtime,
102 | it has to be in the assets folder, and if the filename is not
103 | paperwork.json, you have to inject its name in the constructor:
104 |
105 | ```java
106 | Paperwork paperwork = new Paperwork(context, "paperwork.json");
107 | ```
108 |
109 |
110 | ### Helpers
111 |
112 | ```groovy
113 | buildTime()
114 | ```
115 | Simple unix timestamp (ms)
116 |
117 |
118 | ```groovy
119 | buildTime("yyyy-MM-dd HH:mm:ss")
120 | ```
121 | Formatted date string
122 |
123 |
124 | ```groovy
125 | buildTime("yyyy-MM-dd HH:mm:ss", "GMT")
126 | ```
127 | Formatted date string for a given timezone
128 |
129 |
130 | ```groovy
131 | gitSha()
132 | ```
133 | The current git SHA
134 |
135 |
136 | ```groovy
137 | gitTag()
138 | ```
139 | The last git tag (lightweight tags included)
140 |
141 |
142 | ```groovy
143 | gitInfo()
144 | ```
145 | Runs ```git describe --tags --always --dirty```. Returns a result like "v2.1.0-71-gb88c59a-dirty"
146 | (The last tag + how many commits ahead of that tag are we now in the working tree + current hash + whether the working tree has uncommited changes)
147 |
148 |
149 | ```groovy
150 | gitBranch()
151 | ```
152 | The current git branch
153 |
154 | ```groovy
155 | shell("scripts/test.sh")
156 | ```
157 | Runs a shell command and returns its output (doesn't have to be a script)
158 |
159 |
160 | ```groovy
161 | env("SOME_ENV")
162 | ```
163 | Returns the value of an environment variable
164 |
165 |
166 | ### Contributing
167 |
168 | Contributions are welcome! Got a question, found a bug, have a new helper method idea? Submit an issue and discuss it!
169 |
170 | I'd love to hear about your use case too, especially if it's not covered perfectly.
171 |
172 |
173 | ### License
174 |
175 | Copyright 2015 Zsolt Kocsi
176 |
177 | Licensed under the Apache License, Version 2.0 (the "License");
178 | you may not use this file except in compliance with the License.
179 | You may obtain a copy of the License at
180 |
181 | http://www.apache.org/licenses/LICENSE-2.0
182 |
183 | Unless required by applicable law or agreed to in writing, software
184 | distributed under the License is distributed on an "AS IS" BASIS,
185 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
186 | See the License for the specific language governing permissions and
187 | limitations under the License.
188 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright 2015 Zsolt Kocsi
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------