/fixtures-maven-plugin/src/main/java/net/fixtures/plugin/FixturesHelper.java
https://bitbucket.org/emont01/maven-fixtures · Java · 60 lines · 37 code · 9 blank · 14 comment · 2 complexity · b6cd178b8577d076d8262b4af4516adc MD5 · raw file
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package net.fixtures.plugin;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.InputStream;
- import java.util.Map;
- import org.apache.commons.lang.StringUtils;
- import org.yaml.snakeyaml.Yaml;
- /**
- *
- * @author eivar
- */
- class FixturesHelper {
- /**
- * database connection fields
- */
- final static String URL = "url", USER_NAME = "username", PASSWORD = "password";
- /**
- * path constants
- */
- public final static String PATH_SEPARATOR = System.getProperty("file.separator");
- public final static String BASE_DIR = System.getProperty("basedir");
- private final static String RESOURCES_PATH = buildPath(BASE_DIR, "src", "main", "resources");
- static Map<String, Map<String, Object>> readDatabaseConfig(String configFile) {
- try {
- configFile = configFile == null ? buildPath(RESOURCES_PATH, "database.yml") : configFile;
- return readYamlFile(configFile);
- } catch (FileNotFoundException ex) {
- throw new RuntimeException("Imposible to load database.yml config", ex);
- }
- }
- static Map<String, Map<String, Object>> readYamlFile(String configFile) throws FileNotFoundException {
- return readYamlFile(new File(configFile));
- }
- static Map<String, Map<String, Object>> readYamlFile(File configFile) throws FileNotFoundException {
- return readYamlFile(new FileInputStream(configFile));
- }
- static Map<String, Map<String, Object>> readYamlFile(InputStream configFile) {
- return (Map<String, Map<String, Object>>) new Yaml().load(configFile);
- }
- static String buildPath(Object... elments) {
- return StringUtils.join(elments, PATH_SEPARATOR);
- }
- static String convertToString(Object value) {
- return value == null ? "" : value.toString();
- }
- }