From: Stefan F. <ste...@us...> - 2012-03-06 14:17:14
|
buildRails.xml | 14 ++++++++----- rails/common/ConfigManager.java | 6 ++--- rails/common/ConfigProfile.java | 43 +++------------------------------------- rails/util/Util.java | 42 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 47 deletions(-) New commits: commit 2633abcb7e2722e82c0a0822d148d299c893650e Author: Stefan Frey <ste...@we...> Date: Tue Mar 6 15:16:52 2012 +0100 Updated mechanism for version.number diff --git a/buildRails.xml b/buildRails.xml index 07b6d96..9878e88 100644 --- a/buildRails.xml +++ b/buildRails.xml @@ -13,11 +13,8 @@ <!-- Define a filter to substitute version number --> <filterset id="versionFilter"> - <filter token="VERSION" value="${version}"/> - </filterset> - <!-- Define a filter to substitute develop tag to version number --> - <filterset id="developFilter"> - <filter token="DEVELOP" value=""/> + <filter token="VERSION" value="${version}"/> + <filter token="DEVELOP" value=""/> </filterset> <!-- Clean the current release --> @@ -47,6 +44,7 @@ <exclude name="rails-*-${version}/**"/> <exclude name="rails.bat"/> <exclude name="rails.sh"/> + <exclude name="version.number" /> <exclude name=".project"/> <exclude name=".classpath"/> <exclude name=".git/**"/> @@ -57,6 +55,12 @@ <exclude name="**/rails-${version}.jar"/> </fileset> </copy> + <copy todir="jar"> + <filterset refid="versionFilter"/> + <fileset dir="."> + <include name="version.number" /> + </fileset> + </copy> <mkdir dir="rails-${version}"/> <copy includeemptydirs="false" todir="rails-${version}/lib"> <fileset dir="./lib"> diff --git a/rails/common/ConfigManager.java b/rails/common/ConfigManager.java index ca4f7c9..e328aad 100644 --- a/rails/common/ConfigManager.java +++ b/rails/common/ConfigManager.java @@ -152,7 +152,7 @@ public class ConfigManager implements ConfigurableComponentI { // load recent data File recentFile = new File(SystemOS.get().getConfigurationFolder(false), RECENT_FILE); - ConfigProfile.loadProperties(recentData, recentFile.getAbsolutePath(), false); + Util.loadProperties(recentData, recentFile); // define profiles ConfigProfile.readPredefined(); @@ -177,7 +177,7 @@ public class ConfigManager implements ConfigurableComponentI { // TODO: Check if this is the right place for this /* Load version number and develop flag */ Properties versionNumber = new Properties(); - ConfigProfile.loadProperties(versionNumber, "version.number", true); + Util.loadPropertiesFromResource(versionNumber, "version.number"); String version = versionNumber.getProperty("version"); if (Util.hasValue("version")) { @@ -292,7 +292,7 @@ public class ConfigManager implements ConfigurableComponentI { recentData.setProperty(key, value); } File recentFile = new File(SystemOS.get().getConfigurationFolder(true), RECENT_FILE); - return ConfigProfile.storeProperties(recentData, recentFile); + return Util.storeProperties(recentData, recentFile); } // nothing has changed return true; diff --git a/rails/common/ConfigProfile.java b/rails/common/ConfigProfile.java index 1fed682..c6bcb7d 100644 --- a/rails/common/ConfigProfile.java +++ b/rails/common/ConfigProfile.java @@ -1,11 +1,7 @@ package rails.common; import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; import java.io.FilenameFilter; -import java.io.IOException; -import java.io.InputStream; import java.util.Collection; import java.util.HashMap; import java.util.Map; @@ -96,7 +92,7 @@ public final class ConfigProfile implements Comparable<ConfigProfile> { static void readPredefined() { Properties list = new Properties(); String filePath = PREDEFINED_FOLDER + LIST_OF_PROFILES; - loadProperties(list, filePath, true); + Util.loadPropertiesFromResource(list, filePath); for (String name:list.stringPropertyNames()) { new ConfigProfile(Type.PREDEFINED, name); } @@ -269,7 +265,7 @@ public final class ConfigProfile implements Comparable<ConfigProfile> { return false; } else { File profile = new File(folder, name + PROFILE_EXTENSION); - return loadProperties(properties, profile.getAbsolutePath(), false); + return Util.loadProperties(properties, profile); } } @@ -283,7 +279,7 @@ public final class ConfigProfile implements Comparable<ConfigProfile> { filePath = PREDEFINED_FOLDER + name + PREDEFINED_EXTENSION ; break; } - return loadProperties(properties, filePath, true); + return Util.loadPropertiesFromResource(properties, filePath); } boolean store() { @@ -294,41 +290,10 @@ public final class ConfigProfile implements Comparable<ConfigProfile> { return false; } else { File profile = new File(folder, name + PROFILE_EXTENSION); - return storeProperties(properties, profile); + return Util.storeProperties(properties, profile); } } - static boolean loadProperties(Properties properties, String filePath, boolean resource) { - try { - log.info("Loading properties from file " + filePath); - InputStream inFile; - if (resource) { - inFile = ConfigProfile.class.getClassLoader().getResourceAsStream(filePath); - } else { - inFile = new FileInputStream(filePath); - } - properties.load(inFile); - } catch (Exception e) { - log.error(e + " whilst loading properties file " - + filePath, e); - return false; - } - return true; - } - - static boolean storeProperties(Properties properties, File file) { - boolean result = true; - try { - properties.store(new FileOutputStream(file), "Automatically generated, do not edit"); - log.info("Storing properties to file " + file.getAbsolutePath()); - } catch (IOException e) { - log.error(e + " whilst storing properties file " - + file.getAbsolutePath()); - result = false; - } - return result; - } - private int compare(ConfigProfile a, ConfigProfile b) { if (a.type.sort != b.type.sort) { return a.type.sort.compareTo(b.type.sort); diff --git a/rails/util/Util.java b/rails/util/Util.java index 25c716a..813db49 100644 --- a/rails/util/Util.java +++ b/rails/util/Util.java @@ -5,9 +5,11 @@ import java.awt.Color; import java.io.*; import java.util.ArrayList; import java.util.List; +import java.util.Properties; import org.apache.log4j.Logger; +import rails.common.ConfigProfile; import rails.common.parser.ConfigurationException; import rails.game.move.Moveable; import rails.game.move.MoveableHolder; @@ -226,4 +228,44 @@ public final class Util { return null; } } + + public static boolean loadProperties(Properties properties, File file) { + try { + log.info("Loading properties from file " + file); + InputStream inFile = new FileInputStream(file); + properties.load(inFile); + } catch (Exception e) { + log.error(e + " whilst loading properties file " + + file, e); + return false; + } + return true; + } + + public static boolean loadPropertiesFromResource(Properties properties, String resourcePath) { + try { + log.info("Loading properties from resource " + resourcePath); + InputStream inFile; + inFile = ConfigProfile.class.getClassLoader().getResourceAsStream(resourcePath); + properties.load(inFile); + } catch (Exception e) { + log.error(e + " whilst loading properties file from resource at " + + resourcePath, e); + return false; + } + return true; + } + + public static boolean storeProperties(Properties properties, File file) { + boolean result = true; + try { + properties.store(new FileOutputStream(file), "Automatically generated, do not edit"); + log.info("Storing properties to file " + file.getAbsolutePath()); + } catch (IOException e) { + log.error(e + " whilst storing properties file " + + file.getAbsolutePath()); + result = false; + } + return result; + } } |