--- /dev/null
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.axyus.generator.pespj.utilities;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
+/**
+ *
+ * @author stephane.melois
+ */
+public class Version {
+
+ static private final Version CURRENT = fromRessourcePropertyFile("META-INF/maven/com.axyus/pes-pj-generator-core/pom.properties");
+
+ private int major;
+ private int minor;
+ private int patch;
+
+ static public Version getCurrent() {
+ return Version.CURRENT;
+ }
+
+ public int getMajor() {
+ return major;
+ }
+
+ public int getMinor() {
+ return minor;
+ }
+
+ public int getPatch() {
+ return patch;
+ }
+
+ protected void parse(String versionAsString) {
+ String versionArray[] = versionAsString.split("\\.");
+ this.major = Integer.parseInt(versionArray[0]);
+ this.minor = Integer.parseInt(versionArray[1]);
+ this.patch = Integer.parseInt(versionArray[2]);
+ }
+
+ @Override
+ public String toString() {
+ return this.major + "." + this.minor + "." + this.patch;
+ }
+
+ static protected Version fromRessourcePropertyFile(String ressourcePropertyFileName) {
+ Properties pomProperties = new Properties();
+ InputStream pomPropertiesStream = Version.class.getClassLoader().getResourceAsStream(ressourcePropertyFileName);
+ if (pomPropertiesStream != null) {
+ try {
+ pomProperties.load(pomPropertiesStream);
+ String versionAsString = pomProperties.getProperty("version");
+ pomPropertiesStream.close();
+ Version version = new Version();
+ version.parse(versionAsString);
+ return version;
+ } catch (IOException ioe) {
+ throw new RuntimeException(ioe);
+ }
+ } else {
+ // Cas le cas des tests unitaires, le fichier de proprités n'est pas accessible...
+ Version version = new Version();
+ version.parse("0.0.0");
+ return version;
+ }
+ }
+}
+
+