-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added configuration file to the Difido HTML report and the ability to…
… replace error status with failure. issue #258
- Loading branch information
Showing
3 changed files
with
136 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,3 +36,5 @@ runnerState.properties | |
log | ||
myFile.txt | ||
*.xml.versionsBackup | ||
difido.properties | ||
remoteDifido.properties |
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
126 changes: 126 additions & 0 deletions
126
...ore-projects/jsystemCore/src/main/java/jsystem/extensions/report/difido/DifidoConfig.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
package jsystem.extensions.report.difido; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.util.Properties; | ||
import java.util.logging.Logger; | ||
|
||
/** | ||
* Allows configuration of the Difido HTML report. This will affect the local | ||
* and the remote reports. | ||
* | ||
* @author Itai Agmon | ||
* | ||
*/ | ||
class DifidoConfig { | ||
|
||
private static final Logger log = Logger.getLogger(DifidoConfig.class.getName()); | ||
|
||
private static final String FILE_NAME = "difido.properties"; | ||
|
||
private static DifidoConfig instance; | ||
|
||
private Properties properties; | ||
|
||
static DifidoConfig getInstance() { | ||
if (null == instance) { | ||
instance = new DifidoConfig(); | ||
} | ||
return instance; | ||
} | ||
|
||
private DifidoConfig() { | ||
File configFile = new File(FILE_NAME); | ||
if (!configFile.exists()) { | ||
createDefaultConfigFile(); | ||
} | ||
readConfigFile(); | ||
} | ||
|
||
private void readConfigFile() { | ||
properties = new Properties(); | ||
try (FileInputStream in = new FileInputStream(FILE_NAME)) { | ||
properties.load(in); | ||
} catch (IOException e) { | ||
log.warning("Failed to read Difido configuration file"); | ||
} | ||
} | ||
|
||
private void createDefaultConfigFile() { | ||
Properties properties = new Properties(); | ||
for (DifidoProperty prop : DifidoProperty.values()) { | ||
properties.setProperty(prop.propName, prop.defaultValue != null ? prop.defaultValue.toString() : ""); | ||
} | ||
try (FileOutputStream out = new FileOutputStream(FILE_NAME)) { | ||
properties.store(out, "Difido report properties"); | ||
|
||
} catch (IOException e) { | ||
log.warning("Failed to create default Difido properties file due to " + e.getMessage()); | ||
} | ||
|
||
} | ||
|
||
/** | ||
* Get the value of the specified property. If the property was not found, | ||
* it will return the default value. | ||
* | ||
* @param property | ||
* @return property value from type string | ||
*/ | ||
String getString(DifidoProperty property) { | ||
String value = null; | ||
if (properties.containsKey(property.getPropName())) { | ||
value = properties.getProperty(property.getPropName()); | ||
} else { | ||
value = property.getDefaultValue(); | ||
} | ||
if (null == value) { | ||
value = ""; | ||
} | ||
return value.trim(); | ||
} | ||
|
||
/** | ||
* Get the value of the specified property. If the property was not found, | ||
* it will return the default value. | ||
* | ||
* @param property | ||
* @return property value from type boolean | ||
*/ | ||
boolean getBoolean(DifidoProperty property) { | ||
String value = getString(property); | ||
return Boolean.parseBoolean(value); | ||
} | ||
|
||
enum DifidoProperty { | ||
errorsToFailures("errors.to.failures", "false", "Replace each error with failure"); | ||
|
||
private String propName; | ||
|
||
private String defaultValue; | ||
|
||
private String description; | ||
|
||
DifidoProperty(String propName, String defaultValue, String description) { | ||
this.propName = propName; | ||
this.defaultValue = defaultValue; | ||
this.description = description; | ||
} | ||
|
||
protected String getPropName() { | ||
return propName; | ||
} | ||
|
||
protected String getDefaultValue() { | ||
return defaultValue; | ||
} | ||
|
||
protected String getDescription() { | ||
return description; | ||
} | ||
|
||
} | ||
|
||
} |