Skip to content

Commit

Permalink
fetch Implementation-Version from manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
reugn committed Sep 25, 2019
1 parent cb418de commit 6618e15
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
5 changes: 2 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@
<configuration>
<archive>
<manifest>
<mainClass>
com.github.reugn.devtools.Main
</mainClass>
<mainClass>com.github.reugn.devtools.Main</mainClass>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
</archive>
<descriptorRefs>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.VBox;
import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;

import java.io.FileReader;
import java.net.URL;
import java.util.ResourceBundle;
import java.util.jar.Manifest;

public class MainController implements Initializable, Logger {

Expand Down Expand Up @@ -60,12 +58,17 @@ public void initialize(URL location, ResourceBundle resources) {
}

private String getVersion() {
String version;
try {
MavenXpp3Reader reader = new MavenXpp3Reader();
Model model = reader.read(new FileReader("pom.xml"));
return model.getVersion();
Class clazz = this.getClass();
String classPath = clazz.getResource(clazz.getSimpleName() + ".class").toString();
String manifestPath = classPath.substring(0, classPath.lastIndexOf("!") + 1) +
"/META-INF/MANIFEST.MF";
Manifest manifest = new Manifest(new URL(manifestPath).openStream());
version = manifest.getMainAttributes().getValue("Implementation-Version");
} catch (Exception e) {
return "NA";
}
return version;
}
}

0 comments on commit 6618e15

Please sign in to comment.