001 package org.tynamo.common;
002
003 import java.io.IOException;
004 import java.util.Properties;
005
006 public class ModuleProperties {
007 public static final String PROPERTYFILE = "module.properties";
008 public static final String VERSION = "module.version";
009
010 public static String getVersion(Class<?> aClass) {
011 String expectedPropertyPath = aClass.getPackage().getName() + "/" + PROPERTYFILE;
012 Properties moduleProperties = new Properties();
013 String version = null;
014 try {
015 moduleProperties.load(aClass.getResourceAsStream("module.properties"));
016 version = moduleProperties.getProperty("module.version");
017 if (version == null) throw new IllegalArgumentException(VERSION + " was not found from " + expectedPropertyPath);
018 if (version.startsWith("${")) throw new IllegalArgumentException(VERSION + " is not filtered in resource " + expectedPropertyPath);
019 } catch (IOException e) {
020 throw new IllegalArgumentException("No property file resource found from " + expectedPropertyPath);
021 }
022 if (version.endsWith("SNAPSHOT")) version += '-' + System.currentTimeMillis();
023 return version;
024 }
025
026 }