* the file extension to scan for (eg .cfg)
* @return an option containing all the read configurations
*/
public static Option configurationFolder(File folder, String extension) {
if (!folder.exists()) {
throw new TestContainerException("folder " + folder + " does not exits");
}
List<Option> options = new ArrayList<Option>();
File[] files = folder.listFiles();
for (File file : files) {
if (file.isDirectory()) {
continue;
}
String name = file.getName();
if (!name.endsWith(extension)) {
continue;
}
else {
name = name.substring(0, name.length() - extension.length());
}
String[] split = name.split("-");
ConfigurationProvisionOption cfg = new ConfigurationProvisionOption(split[0],
new HashMap<String, Object>());
cfg.factory(split.length > 1);
Properties properties = new Properties();
try {
FileInputStream stream = new FileInputStream(file);
try {
properties.load(stream);
}
finally {
stream.close();
}
}
catch (IOException e) {
throw new TestContainerException("can't read configuration file " + file, e);
}
Set<String> names = properties.stringPropertyNames();
for (String key : names) {
cfg.put(key, properties.getProperty(key));
}