Created the ConfigurationManager.java
This commit is contained in:
parent
24c498ef25
commit
678757b0c5
41
src/main/java/de/gnmyt/mcdash/api/ConfigurationManager.java
Normal file
41
src/main/java/de/gnmyt/mcdash/api/ConfigurationManager.java
Normal file
@ -0,0 +1,41 @@
|
||||
package de.gnmyt.mcdash.api;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.Enumeration;
|
||||
import java.util.jar.Manifest;
|
||||
|
||||
public class ConfigurationManager {
|
||||
|
||||
private static final Logger LOG = new Logger(ConfigurationManager.class);
|
||||
private String version = null;
|
||||
|
||||
/**
|
||||
* Gets the version of the MCDash wrapper
|
||||
* @return the version of the MCDash wrapper
|
||||
*/
|
||||
public String getVersion() {
|
||||
if (version != null) {
|
||||
return version;
|
||||
}
|
||||
|
||||
try {
|
||||
Enumeration<URL> resources = getClass().getClassLoader()
|
||||
.getResources("META-INF/MANIFEST.MF");
|
||||
|
||||
while (resources.hasMoreElements()) {
|
||||
Manifest manifest = new Manifest(resources.nextElement().openStream());
|
||||
version = manifest.getMainAttributes().getValue("Version");
|
||||
if (version != null) {
|
||||
return version;
|
||||
}
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
LOG.warn("Could not read version from manifest file: {}", e.getMessage());
|
||||
}
|
||||
|
||||
return "DEVELOPMENT";
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user