@Test void testDefaultConfigFile() throws RedPenException, IOException { File file; file = Main.resolveConfigLocation("not-exist.conf"); assertNull(file); String defaultConfPath = "." + File.separator + "redpen-conf.xml"; File defaultConfFile = new File(defaultConfPath); if (defaultConfFile.createNewFile()) { defaultConfFile.deleteOnExit(); file = Main.resolveConfigLocation(defaultConfPath); assertNotNull(file); defaultConfFile.delete(); } String localeSpecificConfPath = "." + File.separator + "redpen-conf-" + Locale.getDefault().getLanguage() + ".xml"; File localeSpecificConfFile = new File(localeSpecificConfPath); if (localeSpecificConfFile.createNewFile()) { localeSpecificConfFile.deleteOnExit(); file = Main.resolveConfigLocation(defaultConfPath); assertNotNull(file); localeSpecificConfFile.delete(); } }
static File resolveConfigLocation(String configFileName) { List<String> pathCandidates = new ArrayList<>(); if (configFileName != null) { pathCandidates.add(configFileName); } pathCandidates.add(DEFAULT_CONFIG_NAME + ".xml"); pathCandidates.add(DEFAULT_CONFIG_NAME + "-" + Locale.getDefault().getLanguage() + ".xml"); String redpenHome = System.getenv("REDPEN_HOME"); if (redpenHome != null) { pathCandidates.add(redpenHome + File.separator + DEFAULT_CONFIG_NAME + ".xml"); pathCandidates.add(redpenHome + File.separator + DEFAULT_CONFIG_NAME + "-" + Locale.getDefault().getLanguage() + ".xml"); pathCandidates.add(redpenHome + File.separator + "conf" + File.separator + DEFAULT_CONFIG_NAME + ".xml"); pathCandidates.add(redpenHome + File.separator + "conf" + File.separator + DEFAULT_CONFIG_NAME + "-" + Locale.getDefault().getLanguage() + ".xml"); } File resolved = resolve(pathCandidates); if (resolved != null && resolved.exists() && resolved.isFile()) { LOG.info("Configuration file: {}", resolved.getAbsolutePath()); } else { resolved = null; } return resolved; }
Main { static File resolveConfigLocation(String configFileName) { List<String> pathCandidates = new ArrayList<>(); if (configFileName != null) { pathCandidates.add(configFileName); } pathCandidates.add(DEFAULT_CONFIG_NAME + ".xml"); pathCandidates.add(DEFAULT_CONFIG_NAME + "-" + Locale.getDefault().getLanguage() + ".xml"); String redpenHome = System.getenv("REDPEN_HOME"); if (redpenHome != null) { pathCandidates.add(redpenHome + File.separator + DEFAULT_CONFIG_NAME + ".xml"); pathCandidates.add(redpenHome + File.separator + DEFAULT_CONFIG_NAME + "-" + Locale.getDefault().getLanguage() + ".xml"); pathCandidates.add(redpenHome + File.separator + "conf" + File.separator + DEFAULT_CONFIG_NAME + ".xml"); pathCandidates.add(redpenHome + File.separator + "conf" + File.separator + DEFAULT_CONFIG_NAME + "-" + Locale.getDefault().getLanguage() + ".xml"); } File resolved = resolve(pathCandidates); if (resolved != null && resolved.exists() && resolved.isFile()) { LOG.info("Configuration file: {}", resolved.getAbsolutePath()); } else { resolved = null; } return resolved; } }
Main { static File resolveConfigLocation(String configFileName) { List<String> pathCandidates = new ArrayList<>(); if (configFileName != null) { pathCandidates.add(configFileName); } pathCandidates.add(DEFAULT_CONFIG_NAME + ".xml"); pathCandidates.add(DEFAULT_CONFIG_NAME + "-" + Locale.getDefault().getLanguage() + ".xml"); String redpenHome = System.getenv("REDPEN_HOME"); if (redpenHome != null) { pathCandidates.add(redpenHome + File.separator + DEFAULT_CONFIG_NAME + ".xml"); pathCandidates.add(redpenHome + File.separator + DEFAULT_CONFIG_NAME + "-" + Locale.getDefault().getLanguage() + ".xml"); pathCandidates.add(redpenHome + File.separator + "conf" + File.separator + DEFAULT_CONFIG_NAME + ".xml"); pathCandidates.add(redpenHome + File.separator + "conf" + File.separator + DEFAULT_CONFIG_NAME + "-" + Locale.getDefault().getLanguage() + ".xml"); } File resolved = resolve(pathCandidates); if (resolved != null && resolved.exists() && resolved.isFile()) { LOG.info("Configuration file: {}", resolved.getAbsolutePath()); } else { resolved = null; } return resolved; } private  Main(); }
Main { static File resolveConfigLocation(String configFileName) { List<String> pathCandidates = new ArrayList<>(); if (configFileName != null) { pathCandidates.add(configFileName); } pathCandidates.add(DEFAULT_CONFIG_NAME + ".xml"); pathCandidates.add(DEFAULT_CONFIG_NAME + "-" + Locale.getDefault().getLanguage() + ".xml"); String redpenHome = System.getenv("REDPEN_HOME"); if (redpenHome != null) { pathCandidates.add(redpenHome + File.separator + DEFAULT_CONFIG_NAME + ".xml"); pathCandidates.add(redpenHome + File.separator + DEFAULT_CONFIG_NAME + "-" + Locale.getDefault().getLanguage() + ".xml"); pathCandidates.add(redpenHome + File.separator + "conf" + File.separator + DEFAULT_CONFIG_NAME + ".xml"); pathCandidates.add(redpenHome + File.separator + "conf" + File.separator + DEFAULT_CONFIG_NAME + "-" + Locale.getDefault().getLanguage() + ".xml"); } File resolved = resolve(pathCandidates); if (resolved != null && resolved.exists() && resolved.isFile()) { LOG.info("Configuration file: {}", resolved.getAbsolutePath()); } else { resolved = null; } return resolved; } private  Main(); static void main(String... args); @SuppressWarnings("static-access") static int run(String... args); }
Main { static File resolveConfigLocation(String configFileName) { List<String> pathCandidates = new ArrayList<>(); if (configFileName != null) { pathCandidates.add(configFileName); } pathCandidates.add(DEFAULT_CONFIG_NAME + ".xml"); pathCandidates.add(DEFAULT_CONFIG_NAME + "-" + Locale.getDefault().getLanguage() + ".xml"); String redpenHome = System.getenv("REDPEN_HOME"); if (redpenHome != null) { pathCandidates.add(redpenHome + File.separator + DEFAULT_CONFIG_NAME + ".xml"); pathCandidates.add(redpenHome + File.separator + DEFAULT_CONFIG_NAME + "-" + Locale.getDefault().getLanguage() + ".xml"); pathCandidates.add(redpenHome + File.separator + "conf" + File.separator + DEFAULT_CONFIG_NAME + ".xml"); pathCandidates.add(redpenHome + File.separator + "conf" + File.separator + DEFAULT_CONFIG_NAME + "-" + Locale.getDefault().getLanguage() + ".xml"); } File resolved = resolve(pathCandidates); if (resolved != null && resolved.exists() && resolved.isFile()) { LOG.info("Configuration file: {}", resolved.getAbsolutePath()); } else { resolved = null; } return resolved; } private  Main(); static void main(String... args); @SuppressWarnings("static-access") static int run(String... args);  }