Created
September 3, 2015 12:15
-
-
Save Sythelux/a8ebd19831d95f675d27 to your computer and use it in GitHub Desktop.
reads some Information from Manifest File and returns them as String
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.InputStream; | |
import java.net.URL; | |
import java.util.Collections; | |
import java.util.jar.Attributes; | |
import java.util.jar.JarFile; | |
import java.util.jar.Manifest; | |
public class BuildInfoBuilder { | |
public static String buildInfo() { | |
try { | |
for (URL url : Collections.list(Thread.currentThread().getContextClassLoader().getResources(JarFile.MANIFEST_NAME))) { | |
try (InputStream is = url.openStream()) { | |
Manifest manifest = new Manifest(is); | |
Attributes mainAttribs = manifest.getMainAttributes(); | |
String user = mainAttribs.getValue("Build-User"); | |
String version = mainAttribs.getValue("Build-Label"); | |
String time = mainAttribs.getValue("Build-Time"); | |
if (user != null || version != null || time != null) { | |
return user + " made " + version + " @ " + time; | |
} | |
} | |
} | |
} catch (Exception e1) { | |
e1.printStackTrace(); | |
} | |
return "no Info"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment