Last active
April 21, 2016 02:51
-
-
Save eratzlaff/7cdd37edc9a5122f2f0c48a030aa0388 to your computer and use it in GitHub Desktop.
Version file based on pom.xml attributes
This file contains 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
mvn -P Production install | |
mvn install |
This file contains 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
<?xml version="1.0" encoding="UTF-8"?> | |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
<properties> | |
<env.value>Dev</prop.value> | |
</properties> | |
..... | |
<build> | |
<resources> | |
<resource> | |
<directory>src/main/resources</directory> | |
<filtering>true</filtering> | |
<includes> | |
<include>**/version.properties</include> | |
</includes> | |
</resource> | |
</resources> | |
..... | |
</build> | |
.... | |
<profiles> | |
<profile> | |
<id>Production</id> | |
<properties> | |
<env.value>Prod</env.value> | |
</properties> | |
.... | |
</profile> | |
</profiles> | |
.... | |
</project> |
This file contains 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
@Named | |
@ApplicationScoped | |
public class Version { | |
private static final String FILE_NAME = "/META-INF/version.properties"; | |
private static final String VERSION = "version"; | |
private static final String TIMESTAMP = "timestamp"; | |
private static final String NAME = "name"; | |
private static final String VENDOR = "vendor"; | |
private static final String ENV = "env"; | |
public String getVendor() { | |
try { | |
return loadConfig().getProperty(VENDOR); | |
} catch (IOException ex) { | |
return ""; | |
} | |
} | |
public String getTimestamp() { | |
try { | |
return loadConfig().getProperty(TIMESTAMP); | |
} catch (IOException ex) { | |
return ""; | |
} | |
} | |
public String getName() { | |
try { | |
return loadConfig().getProperty(NAME); | |
} catch (IOException ex) { | |
return ""; | |
} | |
} | |
public String getVersion() { | |
try { | |
return loadConfig().getProperty(VERSION); | |
} catch (IOException ex) { | |
return ""; | |
} | |
} | |
public String getEnvironment() { | |
try { | |
return loadConfig().getProperty(ENV); | |
} catch (IOException ex) { | |
return ""; | |
} | |
} | |
private Properties loadConfig() throws FileNotFoundException, IOException { | |
Properties prop = new Properties(); | |
prop.load(getClass().getResourceAsStream(FILE_NAME)); | |
return prop; | |
} | |
} |
This file contains 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
version=${pom.version} | |
timestamp=${timestamp} | |
name=${project.artifactId} | |
vendor=${project.organization.name} | |
env=${env.value} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment