GithubHelp home page GithubHelp logo

shebella / android-manifest-config Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rakutentech/android-manifest-config

0.0 2.0 0.0 18.19 MB

Annotation processor that generates a class to lookup manifest metadata.

License: Apache License 2.0

Java 62.35% Kotlin 37.65%

android-manifest-config's Introduction

Manifest Config

CircleCI

Annotation processor that generates a class to lookup manifest metadata.

Download

Example

  1. Add annotation processor to your project
repositories {
  jcenter()
}
dependencies {
  implementation        "com.rakuten.tech.mobile:manifest-config-annotations:$version"
  annotationProcessor   "com.rakuten.tech.mobile:manifest-config-processor:$version"
}
  1. Define the config interface
@ManifestConfig
public interface ApiClient {
  int retries();
  String apiEndpoint();
}
  1. Configure manifest meta-data
<?xml version="1.0" encoding="utf-8"?>
<manifest>
  <application>
    <meta-data
      android:name="Retries"
      android:value="1"/>
    <meta-data
      android:name="ApiEndpoint"
      android:value="https://example.com/"/>
  </application>
</manifest>
  1. Read config from generated class ApiClientManifestConfig (which looks up "Retries" and "ApiEndpoint" from the manifest meta data).
ApiClient config = new ApiClientManifestConfig(context);
config.retries();
config.apiEndpoint();

Why?: We use manifest metadata to configure many of our libraries with static values. To reduce duplication in both source and test code we generate that repetitive code.

Advanced Features

For more customization regarding meta keys and fallback values you can use the @MetaData annotation on interface methods, e.g.

@ManifestConfig
public interface ApiClient {
  @MetaData(key = "my.package.prefix.Retries", value = "4")
  int retries();
  @MetaData(key = "my.package.prefix.ApiEndpoint", value = "https://example.com")
  String apiEndpoint();
}
// Will generate lookup calls like this:
public interface ApiClientManifestconfig {
  // ... boilerplate
  @Override
  public int retries() {
    return metaData.getInt("my.package.prefix.Retries", 4);
  }
  @Override
  public String apiEndpoint() {
    return metaData.getString("my.package.prefix.ApiEndpoint", "https://example.com");
  }
}

Supported types & fallback value parsing

type default value parsing of MetaData.value()
int, java.lang.Integer -1 Kotlin's String.toInt
float, java.lang.Float -1.0f Kotlin's String.toFloat
boolean, java.lang.Boolean false only "true" and "false" convert (ignoring case)
java.lang.String `""`` taken as is

Contributions

Found a bug? Please file an issue or send a pull request ๐Ÿ™

Project structure

  • manifest-config-annotations: Java annotations to mark source code for generation
  • manifest-config-processor: Annotation processor that consumes the annotations and generates implementations
  • manifest-config-sample: Example project <<<<<<< HEAD

=======

Publishing

Setup environment variables:

  • BINTRAY_USER
  • BINTRAY_KEY
  • BINTRAY_REPO

and run

./gradlew publish

publish: setup publishing to jcenter

android-manifest-config's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.