Paperwork


Source link: https://github.com/zsoltk/paperwork

Paperwork

Generate build info for your Android project without breaking incremental compilation

The problem

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).

The easiest way to do this is to generate them into your BuildConfig by adding these to your build.gradle

def gitSha = 'git rev-parse --short HEAD'.execute([], project.rootDir).text.trim() def buildTime = new Date().format("yyyy-MM-dd'T'HH:mm:ss'Z'", TimeZone.getTimeZone("UTC"))  android {

  defaultConfig {

buildConfigField "String", "GIT_SHA", "\"${
gitSha
}
\""

buildConfigField "String", "BUILD_TIME", "\"${
buildTime
}
\""
  
}
 
}

But this will break incremental builds, resulting in increased build times all the time.

What this lib offers

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:

Paperwork paperwork = new Paperwork(context);
 String gitSha = paperwork.get("gitSha");
 String buildTime = paperwork.get("buildTime");

Not just git hash, not just build time: you define what gets generated, and you can use anything that otherwise would break incremental builds.

Many helpers are available for the most common scenarios. See the configuration below.

Build time comparison

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.

  • Without generating build info: 3.989s, 3.915s, 3.902s
  • Using BuildConfig fields: 14.843s, 13.844s, 13.194s
  • Using Paperwork: 4.356s, 4.075s, 4.042s

Download and setup

Add these dependencies to your build.gradle:

buildscript {

  repositories {

mavenCentral()
  
}

dependencies {

classpath 'hu.supercluster:paperwork-plugin:1.2.7'
  
}
 
}
  apply plugin: 'hu.supercluster.paperwork'  paperwork {

  // Configuration comes here, see next section for details 
}
  dependencies {

  compile 'hu.supercluster:paperwork:1.2.7' 
}

Lastly, don't forget to add paperwork.json to your .gitignore file.

Configuration

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.

paperwork {

  set = [

someKey1: "someValue",

someKey2: someHelperMethod()
  ] 
}

All the data will be available at runtime by querying for your own defined keys:

Paperwork paperwork = new Paperwork(context);
 String data1 = paperwork.get("someKey1");

  // will return "someValue" String data1 = paperwork.get("someKey2");

  // will return the result of someHelperMethod()

You can also change the default filename or generate the file somewhere else:

paperwork {

  filename = 'src/main/assets/paperwork.json' 
}

Note however, that in order for it to be available in Paperwork runtime, it has to be in the assets folder, and if the filename is not paperwork.json, you have to inject its name in the constructor:

Paperwork paperwork = new Paperwork(context, "paperwork.json");

Helpers

buildTime()

Simple unix timestamp (ms)

buildTime("yyyy-MM-dd HH:mm:ss")

Formatted date string

buildTime("yyyy-MM-dd HH:mm:ss", "GMT")

Formatted date string for a given timezone

gitSha()

The current git SHA

gitTag()

The last git tag (lightweight tags included)

gitInfo()

Runs git describe --tags --always --dirty. Returns a result like "v2.1.0-71-gb88c59a-dirty" (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)

gitBranch()

The current git branch

shell("scripts/test.sh")

Runs a shell command and returns its output (doesn't have to be a script)

env("SOME_ENV")

Returns the value of an environment variable

Contributing

Contributions are welcome! Got a question, found a bug, have a new helper method idea? Submit an issue and discuss it!

I'd love to hear about your use case too, especially if it's not covered perfectly.

License

Copyright 2015 Zsolt Kocsi  Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License. You may obtain a copy of the License at
  http://www.apache.org/licenses/LICENSE-2.0  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 

Resources

Demo project for Mortar / Flow / Dagger2 with Auto Dagger2 and Auto Mortar.

ProgressDialog that waits a minimum time to be dismissed before showing. Once visible, the ProgressDialog will be visible for a minimum amount of time to avoid "flashes" in the UI.

The seeds-libraries project is an attempt to build and publish atomic versions of the Guava Libraries which are too valuable to leave out of any modern development project.

The Expandable RecyclerView is a library written to allow for an expanded view to be attached to each ViewHolder. To allow for full functionality of a normal RecyclerView in both the parent ViewHolder and the expanded child ViewHolder, the recyclerview has been modified to use two types of ViewHolders, a child and a parent with the ability to customize each separately.

Custom fonts without writing code.

Easy way to bind collections to listviews and recyclerviews with the new Android Data Binding framework.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes