initial
This commit is contained in:
26
src/main/java/biz/redsoft/sample/Product.java
Normal file
26
src/main/java/biz/redsoft/sample/Product.java
Normal file
@ -0,0 +1,26 @@
|
||||
package biz.redsoft.sample;
|
||||
|
||||
import biz.redsoft.ncore.system.application.Application;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Victor Bellavin
|
||||
*/
|
||||
public class Product implements biz.redsoft.ncore.product.Product {
|
||||
@Override
|
||||
public void init(Map<Object, Object> properties) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(Application application) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy(Application application) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
}
|
||||
}
|
68
src/main/java/biz/redsoft/sample/Version.java
Normal file
68
src/main/java/biz/redsoft/sample/Version.java
Normal file
@ -0,0 +1,68 @@
|
||||
package biz.redsoft.sample;
|
||||
|
||||
import biz.redsoft.util.IncorrectVersionFormat;
|
||||
import biz.redsoft.util.VersionUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* @author Victor Bellavin
|
||||
*/
|
||||
public class Version {
|
||||
public static final Logger LOGGER = Logger.getLogger(Version.class);
|
||||
|
||||
public static final String VERSION_FILE = "version.properties";
|
||||
public static final String VERSION_PROP_NAME = "version";
|
||||
|
||||
private static final VersionUtils.Version version = readVersion();
|
||||
|
||||
public static VersionUtils.Version getInstance() {
|
||||
return getVersion();
|
||||
}
|
||||
|
||||
public static VersionUtils.Version getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
private static VersionUtils.Version readVersion() {
|
||||
final VersionUtils.Version version = new VersionUtils.Version();
|
||||
final String packageName = Version.class.getPackage().getName();
|
||||
final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||
final String versionPath = "META-INF/ncore-product/" + packageName + "/" + VERSION_FILE;
|
||||
final InputStream is = classLoader.getResourceAsStream(versionPath);
|
||||
if (is != null) {
|
||||
loadVersion(version, is);
|
||||
} else {
|
||||
LOGGER.warn("No version resource at " + versionPath + " Trying to load it from the main package...");
|
||||
final InputStream oldStream = Version.class.getResourceAsStream(VERSION_FILE);
|
||||
if (oldStream != null)
|
||||
loadVersion(version, oldStream);
|
||||
else
|
||||
LOGGER.error("No version resource in classpath");
|
||||
}
|
||||
return version;
|
||||
}
|
||||
|
||||
private static void loadVersion(VersionUtils.Version version, InputStream is) {
|
||||
try {
|
||||
try {
|
||||
final Properties props = new Properties();
|
||||
props.load(is);
|
||||
final String moduleVersion = props.getProperty(VERSION_PROP_NAME);
|
||||
if (moduleVersion != null)
|
||||
version.setVersion(moduleVersion);
|
||||
else
|
||||
LOGGER.error("No module.version key in version properties");
|
||||
} catch (IncorrectVersionFormat e) {
|
||||
LOGGER.error("Error reading version", e);
|
||||
} finally {
|
||||
is.close();
|
||||
}
|
||||
}catch (IOException e) {
|
||||
LOGGER.error("Error reading version", e);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user