Coder Social home page Coder Social logo

gaps's Introduction

gaps - Git information As Plain Source

tl;dr: Capture git metadata in Java source at build time.

Why?

In the modern world of continuous integration and deployment, the traditional approach with using Maven versions turns out to be too inflexible as this version number is hard coded in the POM. It is therefore typical to identify the sources by git commit which is typically only available at build time , and that information also needs to be present at runtime to allow linking back to the corresponding sources. Hence a mechanism is needed to persist the git metadata during the build.

The existing Java tooling typically do this, by extracting the metadata from git during the when running the build process compiling the sources and put it in a resource file. This is usually not available during development as IDE's use their own internal build system. This typically mean that git metadata is not fully integrated during local development but only when building deployments, typically by a build server.

How?

This project uses another approach inspired by Dagger 2, namely by doing the magic transparently at compilation time by generating a Java class containing constants with the necessary metadata, which can then be accessed completely without any kind of magic at any time in the project for what is necessary, like logging at startup time.

Technically, this is done by having an annotation processor that is triggered by @Gaps and then queries the classloader where we are in the file system, and uses that to locate the .git folder. Then use jgit to read in the repository metadata and jpoet to generate the Java class with the desired constants in the current project.

Usage

Put the gaps-processor artifact on the classpath. The compile scope ensures all the magic is gone after the end of compilation.

    <dependency>
        <groupId>com.github.users.ravn.gaps</groupId>
        <artifactId>gaps-processor</artifactId>
        <version>0.0-SNAPSHOT</version>
        <scope>compile</scope>
    </dependency>

Sample run:

mvn clean install
mvn -q -pl gaps-example exec:java

For a given class bar.Foo, annotate it with @gaps to have bar.FooGaps automatically generated by the compiler. FooGaps then provide several constants with git metadata. See demo/Main.java for a functional example.

This is still on a proof-of-concept state, and feedback is needed to identify what is actually needed and in what form?

Examples:

  • Should dates be as Date or String?
  • Do we realistically need more metadata than for current commit? (Parents/full tree/how long ago?)
  • Would a toString() realistically be useful?
  • Should this be donated to Spring Boot or Google code?
  • How can the documentation be improved?

Feel free to open issues!

Helpful links for maintainers:

gaps's People

Contributors

trandersen-ufst avatar ravn 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.