rvesse / airline

Java annotation-based framework for parsing Git like command line structures with deep extensibility
https://rvesse.github.io/airline/
Apache License 2.0
128 stars 20 forks source link

Add manifest file support for @Version #56

Closed stephenh closed 7 years ago

stephenh commented 7 years ago

Gradle has a built-in way of putting key/value pairs in the manifest file:

jar {
   manifest {
       attributes 'Mirror-Version': version
   }
}

So, given this, it'd be great to use @Version with a source of META-INF/MANIFEST.MF.

Admittedly, I should submit this as a PR (but I'm being lazy), because I think it should be pretty simple to do a "if source path ends with .MF then parse as a manifest file" and use a snippet like:

private void loadManifest(String manifestSource) throws IOException {
  try (InputStream in = VersionSection.class.getResourceAsStream(manifestSource)) {
    Manifest m = new Manifest(in);
    return m.getMainAttributes(); // but convert to Properties
  }

In the VersionSection.loadDataSource area.

stephenh commented 7 years ago

...actually, this may already work, I'm still trying to get @Version figured out, but I passed a sources of META-INF/MANIFEST.MF and the Properties implementation loaded it just fine.

stephenh commented 7 years ago

Yeah, j.u.Properties really does understand the MF format. Crazy.

Well, that is cool. It might be worth adding a hint to the docs that sources can be META-INF/MANIFEST.MF for others who wonder about this in the future, and similarly don't realize that Properties already supports this.