parent
8077b4a0dc
commit
cc066292c8
|
@ -23,96 +23,96 @@ import java.util.Map;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class BuildParameters {
|
public class BuildParameters {
|
||||||
|
|
||||||
private static final Map<String, String> fileContents = new HashMap<String, String>();
|
private static final Map<String, String> fileContents = new HashMap<String, String>();
|
||||||
|
|
||||||
static{
|
static{
|
||||||
// Fetch file content from resources.
|
// Fetch file content from resources.
|
||||||
String content = null;
|
String content = null;
|
||||||
try{
|
try{
|
||||||
content = ResourceUtil.fetchResource(BuildParameters.class, "BuildParameters.properties");
|
content = ResourceUtil.fetchResource(BuildParameters.class, "BuildParameters.properties");
|
||||||
}
|
}
|
||||||
catch(Throwable t){
|
catch(Throwable t){
|
||||||
t.printStackTrace();
|
t.printStackTrace();
|
||||||
}
|
}
|
||||||
// Parse properties.
|
// Parse properties.
|
||||||
if (content != null){
|
if (content != null){
|
||||||
ResourceUtil.parseToMap(content, fileContents);
|
ResourceUtil.parseToMap(content, fileContents);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////
|
//////////////////////
|
||||||
// Auxiliary methods.
|
// Auxiliary methods.
|
||||||
/////////////////////
|
/////////////////////
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This gets the raw mapping value, might be something like "${...}" in case the parameter has not been present during building.
|
* This gets the raw mapping value, might be something like "${...}" in case the parameter has not been present during building.
|
||||||
* @param path
|
* @param path
|
||||||
* @param preset
|
* @param preset
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static String getMappingValue(String path, String preset){
|
public static String getMappingValue(String path, String preset){
|
||||||
String input = fileContents.get(path);
|
String input = fileContents.get(path);
|
||||||
if (input == null) return preset;
|
if (input == null) return preset;
|
||||||
else return input;
|
else return input;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a string mapping value, excluding missing maven build parameters like '${...}'.
|
* Get a string mapping value, excluding missing maven build parameters like '${...}'.
|
||||||
* @param path
|
* @param path
|
||||||
* @param preset
|
* @param preset
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static String getString(String path, String preset){
|
public static String getString(String path, String preset){
|
||||||
String input = fileContents.get(path);
|
String input = fileContents.get(path);
|
||||||
if (input == null) return preset;
|
if (input == null) return preset;
|
||||||
else if (input.startsWith("${") && input.endsWith("}")) return preset;
|
else if (input.startsWith("${") && input.endsWith("}")) return preset;
|
||||||
else return input;
|
else return input;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Boolean getBoolean(String path, Boolean preset){
|
public static Boolean getBoolean(String path, Boolean preset){
|
||||||
String input = fileContents.get(path);
|
String input = fileContents.get(path);
|
||||||
if (input == null) return preset;
|
if (input == null) return preset;
|
||||||
else return ResourceUtil.getBoolean(input, preset);
|
else return ResourceUtil.getBoolean(input, preset);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Integer getInteger(String path, Integer preset){
|
public static Integer getInteger(String path, Integer preset){
|
||||||
String input = fileContents.get(path);
|
String input = fileContents.get(path);
|
||||||
if (input == null) return preset;
|
if (input == null) return preset;
|
||||||
else return ResourceUtil.getInteger(input, preset);
|
else return ResourceUtil.getInteger(input, preset);
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////
|
//////////////////////
|
||||||
// Public members.
|
// Public members.
|
||||||
//////////////////////
|
//////////////////////
|
||||||
|
|
||||||
/** Timestamp from build (maven). "?" if not present. */
|
/** Timestamp from build (maven). "?" if not present. */
|
||||||
public static final String buildTimeString = getString("BUILD_TIMESTAMP", "?");
|
public static final String buildTimeString = getString("BUILD_TIMESTAMP", "?");
|
||||||
|
|
||||||
/** Indicate something about where this was built. */
|
/** Indicate something about where this was built. */
|
||||||
public static final String buildSeries = getString("BUILD_SERIES", "?");
|
public static final String buildSeries = getString("BUILD_SERIES", "?");
|
||||||
|
|
||||||
/** The build number as given by Jenkins. Integer.MIN_VALUE if not present. */
|
/** The build number as given by Jenkins. Integer.MIN_VALUE if not present. */
|
||||||
public static final int buildNumber = getInteger("BUILD_NUMBER", Integer.MIN_VALUE);
|
public static final int buildNumber = getInteger("BUILD_NUMBER", Integer.MIN_VALUE);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test level: more testing for higher levels. Defaults to 0.
|
* Test level: more testing for higher levels. Defaults to 0.
|
||||||
* <hr>
|
* <hr>
|
||||||
* Currently only 0 and 1 are used, later there might be more levels and some general policy for level setup (concerning rough time needed on some reference hardware, console output etc.).<br>
|
* Currently only 0 and 1 are used, later there might be more levels and some general policy for level setup (concerning rough time needed on some reference hardware, console output etc.).<br>
|
||||||
* Compare to debugLevel.
|
* Compare to debugLevel.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public static final int testLevel = getInteger("TEST_LEVEL", 0);
|
public static final int testLevel = getInteger("TEST_LEVEL", 0);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Debug level: more debug output for higher levels. Defaults to 0.
|
* Debug level: more debug output for higher levels. Defaults to 0.
|
||||||
* <hr>
|
* <hr>
|
||||||
* Currently only 0 and 1 are used, however at some point this will follow some guidelines (to be documented here):<br>
|
* Currently only 0 and 1 are used, however at some point this will follow some guidelines (to be documented here):<br>
|
||||||
* <li>0 is meant for few output, just enough for user debug reports or simple testing. </li>
|
* <li>0 is meant for few output, just enough for user debug reports or simple testing. </li>
|
||||||
* <li>There are major levels every 100 units (100, 200, ....)</li>
|
* <li>There are major levels every 100 units (100, 200, ....)</li>
|
||||||
* <li>Consequently minor levels are between major levels to distinguish minor differences like flags</li>
|
* <li>Consequently minor levels are between major levels to distinguish minor differences like flags</li>
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public static final int debugLevel = getInteger("DEBUG_LEVEL", 10000);
|
public static final int debugLevel = getInteger("DEBUG_LEVEL", 10000);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue