All Projects → anthonycr → Mezzanine

anthonycr / Mezzanine

Licence: apache-2.0
An annotation processor that reads files at compile time

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to Mezzanine

Immutables
Annotation processor to create immutable objects and builders. Feels like Guava's immutable collections but for regular value objects. JSON, Jackson, Gson, JAX-RS integrations included
Stars: ✭ 3,031 (+6635.56%)
Mutual labels:  annotation-processor
Mapstruct
An annotation processor for generating type-safe bean mappers
Stars: ✭ 4,710 (+10366.67%)
Mutual labels:  annotation-processor
Android State
A utility library for Android to save objects in a Bundle without any boilerplate.
Stars: ✭ 857 (+1804.44%)
Mutual labels:  annotation-processor
Vscode Todo Highlight
a vscode extension to highlighting todos, fixmes, and any annotations...
Stars: ✭ 305 (+577.78%)
Mutual labels:  annotation-processor
Parceler
📦 Android Parcelables made easy through code generation.
Stars: ✭ 3,589 (+7875.56%)
Mutual labels:  annotation-processor
Onactivityresult
OnActivityResult annotation compiler for Android
Stars: ✭ 470 (+944.44%)
Mutual labels:  annotation-processor
annotation-processor-sample
An annotation processor which implements "Builder pattern" for your java classes.
Stars: ✭ 22 (-51.11%)
Mutual labels:  annotation-processor
Hamcrest Pojo Matcher Generator
Autogenerated java hamcrest matchers for pojo with help of AnnotationProcessor
Stars: ✭ 31 (-31.11%)
Mutual labels:  annotation-processor
Android Api Securekeys
Store data in a simple and secure way
Stars: ✭ 372 (+726.67%)
Mutual labels:  annotation-processor
Kotshi
An annotation processor that generates Moshi adapters from immutable Kotlin data classes.
Stars: ✭ 656 (+1357.78%)
Mutual labels:  annotation-processor
Jackdaw
Java Annotation Processor which allows to simplify development
Stars: ✭ 306 (+580%)
Mutual labels:  annotation-processor
Preferenceroom
🚚 Android processing library for managing SharedPreferences persistence efficiently and structurally.
Stars: ✭ 341 (+657.78%)
Mutual labels:  annotation-processor
Paperparcel
Auto-generate the fastest possible Parcelable implementations for Java and Kotlin
Stars: ✭ 494 (+997.78%)
Mutual labels:  annotation-processor
Blade
Android library for boilerplate destruction
Stars: ✭ 278 (+517.78%)
Mutual labels:  annotation-processor
Showkase
🔦 Showkase is an annotation-processor based Android library that helps you organize, discover, search and visualize Jetpack Compose UI elements
Stars: ✭ 873 (+1840%)
Mutual labels:  annotation-processor
Doma
DAO oriented database mapping framework for Java 8+
Stars: ✭ 257 (+471.11%)
Mutual labels:  annotation-processor
Deeplinkdispatch
A simple, annotation-based library for making deep link handling better on Android
Stars: ✭ 4,108 (+9028.89%)
Mutual labels:  annotation-processor
Metasra Pipeline
MetaSRA: normalized sample-specific metadata for the Sequence Read Archive
Stars: ✭ 33 (-26.67%)
Mutual labels:  annotation-processor
Koloboke
Java Collections till the last breadcrumb of memory and performance
Stars: ✭ 909 (+1920%)
Mutual labels:  annotation-processor
Derive4j
Java 8 annotation processor and framework for deriving algebraic data types constructors, pattern-matching, folds, optics and typeclasses.
Stars: ✭ 511 (+1035.56%)
Mutual labels:  annotation-processor

Mezzanine

An annotation processor that allows you to read static UTF-8 files synchronously.

Build Status Download codecov

What does this do?

Android apps often need to read in a default configuration file on startup and change functionality based on the contents of the configuration file. A convenient, frequently used way to store this configuration file is in assets, and then to read out of this file on startup. This can mean doing expensive disk I/O on the main thread, which increases startup times. You can get around the additional I/O by pasting the contents of the file into a String constant, but this can make code review difficult.

Mezzanine solves this problem by generating a class at compile time which stores the file contents in a String constant. This is loaded by the class loader, along with your code, when the application is started, rather than requiring additional disk I/O after startup. It acts as an intermediary between files and your running Java code. Instead of needing to paste the contents of the file into the constant yourself, you can store it in its own file and maintain proper separation. For instance, if you are executing JavaScript using a WebView or some library like duktape, you can store the files in .js files without the additional annoyance of needing to perform disk I/O.

Note: There is a hard limit set by the javac compiler where String constants cannot exceed 65535 bytes in size.

Usage

allprojects {
    repositories {
        bintray()
    }
}
Android/Java
dependencies {
  def mezzanineVersion = '1.1.1'
  compile "com.anthonycr.mezzanine:mezzanine:$mezzanineVersion"
  annotationProcessor "com.anthonycr.mezzanine:mezzanine-compiler:$mezzanineVersion"
}

android {
  defaultConfig {
    javaCompileOptions {
      annotationProcessorOptions {
        arguments = [
          "mezzanine.projectPath", project.rootDir
        ]
      }
    }
  }
}
Kotlin
apply plugin: 'kotlin-kapt'

dependencies {
  def mezzanineVersion = '1.1.1'
  compile "com.anthonycr.mezzanine:mezzanine:$mezzanineVersion"
  kapt "com.anthonycr.mezzanine:mezzanine-compiler:$mezzanineVersion"
}

kapt {
    arguments {
        arg("mezzanine.projectPath", project.rootDir)
    }
}
Java
plugins {
    id 'net.ltgt.apt' version '0.10'
}

dependencies {
    def mezzanineVersion = '1.1.1'
    compile "com.anthonycr.mezzanine:mezzanine:$mezzanineVersion"
    apt "com.anthonycr.mezzanine:mezzanine-compiler:$mezzanineVersion"
}

gradle.projectsEvaluated {
  tasks.withType(JavaCompile) {
    aptOptions.processorArgs = [
      "mezzanine.projectPath", project.rootDir
    ]
  }
}

API

  • @FileStream(String path): the path to the file relative to the project root.
  • mezzanine.projectPath annotation processing argument is used to determine the absolute path of the project root. If not provided, mezzanine will use the root accessible to the javac instance.
  • Create an interface with one method with no parameters and a return type of String.
  • Annotate the interface with @FileStream and pass the path to the file as the value in the annotation.
  • Consume the generated implementation of the interface to get the file as a string.
  • Files are assumed to be encoded as UTF-8.
  • Files must be less than 65kB, otherwise compilation will fail.

Sample

Kotlin

@FileStream("path/from/root/to/file.json")
interface MyFileReader {

    fun readMyFile(): String

}
...

val fileReader = MezzanineGenerator.MyFileReader()

val fileContents = fileReader.readMyFile()

println("File contents: $fileContents")

Java

@FileStream("path/from/root/to/file.json")
public interface MyFileReader {

    String readMyFile();

}
...

MyFileReader fileReader = new MezzanineGenerator.MyFileReader();

String fileContents = fileReader.readMyFile();

System.out.println("File contents: " + fileContents);

License

Copyright 2017 Anthony Restaino

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.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].