List of usage examples for org.apache.commons.configuration ConfigurationException getLocalizedMessage
public String getLocalizedMessage()
From source file:com.github.rwhogg.git_vcr.App.java
/** * main is the entry point for Git-VCR//from w w w . j a v a 2 s . c o m * @param args Command-line arguments */ public static void main(String[] args) { Options options = parseCommandLine(args); HierarchicalINIConfiguration configuration = null; try { configuration = getConfiguration(); } catch (ConfigurationException e) { Util.error("could not parse configuration file!"); } // verify we are in a git folder and then construct the repo final File currentFolder = new File("."); FileRepositoryBuilder builder = new FileRepositoryBuilder(); Repository localRepo = null; try { localRepo = builder.findGitDir().build(); } catch (IOException e) { Util.error("not in a Git folder!"); } // deal with submodules assert localRepo != null; if (localRepo.isBare()) { FileRepositoryBuilder parentBuilder = new FileRepositoryBuilder(); Repository parentRepo; try { parentRepo = parentBuilder.setGitDir(new File("..")).findGitDir().build(); localRepo = SubmoduleWalk.getSubmoduleRepository(parentRepo, currentFolder.getName()); } catch (IOException e) { Util.error("could not find parent of submodule!"); } } // if we need to retrieve the patch file, get it now URL patchUrl = options.getPatchUrl(); String patchPath = patchUrl.getFile(); File patchFile = null; HttpUrl httpUrl = HttpUrl.get(patchUrl); if (httpUrl != null) { try { patchFile = com.twitter.common.io.FileUtils.SYSTEM_TMP.createFile(".diff"); Request request = new Request.Builder().url(httpUrl).build(); OkHttpClient client = new OkHttpClient(); Call call = client.newCall(request); Response response = call.execute(); ResponseBody body = response.body(); if (!response.isSuccessful()) { Util.error("could not retrieve diff file from URL " + patchUrl); } String content = body.string(); org.apache.commons.io.FileUtils.write(patchFile, content, (Charset) null); } catch (IOException ie) { Util.error("could not retrieve diff file from URL " + patchUrl); } } else { patchFile = new File(patchPath); } // find the patch //noinspection ConstantConditions if (!patchFile.canRead()) { Util.error("patch file " + patchFile.getAbsolutePath() + " is not readable!"); } final Git git = new Git(localRepo); // handle the branch String branchName = options.getBranchName(); String theOldCommit = null; try { theOldCommit = localRepo.getBranch(); } catch (IOException e2) { Util.error("could not get reference to current branch!"); } final String oldCommit = theOldCommit; // needed to reference from shutdown hook if (branchName != null) { // switch to the branch try { git.checkout().setName(branchName).call(); } catch (RefAlreadyExistsException e) { // FIXME Auto-generated catch block e.printStackTrace(); } catch (RefNotFoundException e) { Util.error("the branch " + branchName + " was not found!"); } catch (InvalidRefNameException e) { Util.error("the branch name " + branchName + " is invalid!"); } catch (org.eclipse.jgit.api.errors.CheckoutConflictException e) { Util.error("there was a checkout conflict!"); } catch (GitAPIException e) { Util.error("there was an unspecified Git API failure!"); } } // ensure there are no changes before we apply the patch try { if (!git.status().call().isClean()) { Util.error("cannot run git-vcr while there are uncommitted changes!"); } } catch (NoWorkTreeException e1) { // won't happen assert false; } catch (GitAPIException e1) { Util.error("call to git status failed!"); } // list all the files changed String patchName = patchFile.getName(); Patch patch = new Patch(); try { patch.parse(new FileInputStream(patchFile)); } catch (FileNotFoundException e) { assert false; } catch (IOException e) { Util.error("could not parse the patch file!"); } ReviewResults oldResults = new ReviewResults(patchName, patch, configuration, false); try { oldResults.review(); } catch (InstantiationException e1) { Util.error("could not instantiate a review tool class!"); } catch (IllegalAccessException e1) { Util.error("illegal access to a class"); } catch (ClassNotFoundException e1) { Util.error("could not find a review tool class"); } catch (ReviewFailedException e1) { e1.printStackTrace(); Util.error("Review failed!"); } // we're about to change the repo, so register a shutdown hook to clean it up Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { cleanupGit(git, oldCommit); } }); // apply the patch try { git.apply().setPatch(new FileInputStream(patchFile)).call(); } catch (PatchFormatException e) { Util.error("patch file " + patchFile.getAbsolutePath() + " is malformatted!"); } catch (PatchApplyException e) { Util.error("patch file " + patchFile.getAbsolutePath() + " did not apply correctly!"); } catch (FileNotFoundException e) { assert false; } catch (GitAPIException e) { Util.error(e.getLocalizedMessage()); } ReviewResults newResults = new ReviewResults(patchName, patch, configuration, true); try { newResults.review(); } catch (InstantiationException e1) { Util.error("could not instantiate a review tool class!"); } catch (IllegalAccessException e1) { Util.error("illegal access to a class"); } catch (ClassNotFoundException e1) { Util.error("could not find a review tool class"); } catch (ReviewFailedException e1) { e1.printStackTrace(); Util.error("Review failed!"); } // generate and show the report VelocityReport report = new VelocityReport(patch, oldResults, newResults); File reportFile = null; try { reportFile = com.twitter.common.io.FileUtils.SYSTEM_TMP.createFile(".html"); org.apache.commons.io.FileUtils.write(reportFile, report.toString(), (String) null); } catch (IOException e) { Util.error("could not generate the results page!"); } try { assert reportFile != null; Desktop.getDesktop().open(reportFile); } catch (IOException e) { Util.error("could not open the results page!"); } }
From source file:cross.io.PropertyFileGenerator.java
/** * Creates a property file for the given class, containing those fields, * which are annotated by {@link cross.annotations.Configurable}. * * @param className/*from www.ja v a 2 s . c o m*/ * @param basedir */ public static void createProperties(String className, File basedir) { Class<?> c; try { c = PropertyFileGenerator.class.getClassLoader().loadClass(className); LoggerFactory.getLogger(PropertyFileGenerator.class).info("Class: {}", c.getName()); PropertiesConfiguration pc = createProperties(c); if (!basedir.exists()) { basedir.mkdirs(); } try { pc.save(new File(basedir, c.getSimpleName() + ".properties")); } catch (ConfigurationException ex) { LoggerFactory.getLogger(PropertyFileGenerator.class).warn("{}", ex.getLocalizedMessage()); } } catch (ClassNotFoundException e) { LoggerFactory.getLogger(PropertyFileGenerator.class).warn("{}", e.getLocalizedMessage()); } }
From source file:com.runwaysdk.configuration.CommonsConfigurationResolver.java
private void loadProperties(String fileName) { try {//from w w w . j a v a 2 s . c o m String path = ConfigGroup.COMMON.getPath() + fileName; // Read the configuration URL url = CommonsConfigurationReader.class.getClassLoader().getResource(path); if (url != null) { cconfig.addConfiguration(new PropertiesConfiguration(url)); log.trace("Loading [" + fileName + "] configuration overrides."); } else { log.info("Did not find " + fileName + ". No overrides were loaded."); } } catch (ConfigurationException e) { log.error(e.getLocalizedMessage(), e); } }
From source file:dk.cubing.liveresults.uploader.configuration.Configuration.java
/** * Save the current values to selected properties file *///from ww w. ja va 2s. c o m public void save() { try { config.save(); engine.restart(); } catch (ConfigurationException e) { log.error(e.getLocalizedMessage(), e); } }
From source file:TestExtractor.java
@Test public void TestConf() { try {/*w w w .ja v a 2 s . c om*/ Configuration conf = new PropertiesConfiguration( System.getProperty("user.dir") + "/src/test/resources/xwiki.cfg"); int ldapPort = conf.getInt("xwiki.authentication.ldap.port", 389); String tmpldap_server = conf .getString("xwiki.authentication.trustedldap.remoteUserMapping.ldap_server"); //String tmpldap_base_DN = conf.getString("xwiki.authentication.trustedldap.remoteUserMapping.ldap_base_DN"); String tmpBinDN = conf.getString("xwiki.authentication.trustedldap.remoteUserMapping.ldap_bind_DN"); String tmpldap_bind_pass = conf .getString("xwiki.authentication.trustedldap.remoteUserMapping.ldap_bind_pass"); String[] ldap_server = StringUtils.split(tmpldap_server, "|"); //String[] ldap_base_DN = StringUtils.split(tmpldap_base_DN,"|"); String[] BinDN = StringUtils.split(tmpBinDN, "|"); String[] ldap_bind_pass = StringUtils.split(tmpldap_bind_pass, "|"); //assertTrue(ldap_server.length == ldap_base_DN.length); assertTrue(BinDN.length == ldap_bind_pass.length); assertTrue(ldap_server.length == ldap_bind_pass.length); assertTrue(ldap_server.length == 6); assertTrue(ldapPort == 389); String className = conf.getString("xwiki.authentication.ldap.ssl.secure_provider", "com.sun.net.ssl.internal.ssl.Provider"); assertEquals(className, "com.sun.net.ssl.internal.ssl.Provider"); assertEquals(conf.getInt("xwiki.authentication.ldap.timeout", 500), 500); assertEquals(conf.getInt("xwiki.authentication.ldap.maxresults", 10), 10); } catch (ConfigurationException ex) { Logger.getLogger(TestExtractor.class.getName()).log(Level.SEVERE, null, ex); fail(ex.getLocalizedMessage()); } }
From source file:TestExtractor.java
@Test public void testValue() { try {/*from w w w . j a va2s . c o m*/ Configuration conf = new PropertiesConfiguration( System.getProperty("user.dir") + "/src/test/resources/xwiki.cfg"); String tmpldap_server = conf .getString("xwiki.authentication.trustedldap.remoteUserMapping.ldap_server"); //String tmpldap_base_DN = conf.getString("xwiki.authentication.trustedldap.remoteUserMapping.ldap_base_DN"); String tmpBinDN = conf.getString("xwiki.authentication.trustedldap.remoteUserMapping.ldap_bind_DN"); String tmpldap_bind_pass = conf .getString("xwiki.authentication.trustedldap.remoteUserMapping.ldap_bind_pass"); String[] ldap_server = StringUtils.split(tmpldap_server, "|"); //String[] ldap_base_DN = StringUtils.split(tmpldap_base_DN,"|"); String[] BinDN = StringUtils.split(tmpBinDN, "|"); String[] ldap_bind_pass = StringUtils.split(tmpldap_bind_pass, "|"); int i = 0; String userDomain = StringUtils.split(ldap_server[i], "=")[0]; String userDomainLDAPServer = StringUtils.split(ldap_server[i], "=")[1]; // never used String userDomainLDAPBaseDN = ldap_base_DN[i].split("=")[1]; String userDomainBinDN = StringUtils.split(BinDN[i], "=")[1]; String userDomainldap_bind_pass = StringUtils.split(ldap_bind_pass[i], "=")[1]; assertEquals(userDomain, "ZOZO.AD"); assertEquals(userDomainLDAPServer, "10.0.0.1"); assertEquals(userDomainBinDN, "connecuserssosw@ZOZO.AD"); assertEquals(userDomainldap_bind_pass, "secret001"); i = 3; userDomain = ldap_server[i].split("=")[0]; userDomainLDAPServer = ldap_server[i].split("=")[1]; // never used String userDomainLDAPBaseDN = ldap_base_DN[i].split("=")[1]; userDomainBinDN = BinDN[i].split("=")[1]; userDomainldap_bind_pass = ldap_bind_pass[i].split("=")[1]; assertEquals(userDomain, "SOMEWHERE.INTERNAL"); assertEquals(userDomainLDAPServer, "10.0.0.4"); assertEquals(userDomainBinDN, "connecuserssoau@SOMEWHERE.INTERNAL"); assertEquals(userDomainldap_bind_pass, "secret004"); } catch (ConfigurationException ex) { Logger.getLogger(TestExtractor.class.getName()).log(Level.SEVERE, null, ex); fail(ex.getLocalizedMessage()); } }
From source file:cross.ObjectFactory.java
@Override public <T> T instantiate(final String classname, final Class<T> cls, final String configurationFile) { CompositeConfiguration cc = new CompositeConfiguration(); try {// www. j a v a 2s . c o m File configFileLocation = new File(configurationFile); cc.addConfiguration(new PropertiesConfiguration(configFileLocation.getAbsolutePath())); } catch (ConfigurationException e) { log.warn(e.getLocalizedMessage()); } cc.addConfiguration(this.cfg); return instantiate(classname, cls, cc); }
From source file:cross.Factory.java
/** * Save the current configuration to file. * * @param cfg the configuration to save/* w ww . ja v a 2s .co m*/ * @param location the file to write to */ @Override public void saveConfiguration(final Configuration cfg, final File location) { if (cfg instanceof FileConfiguration) { try { ((FileConfiguration) cfg).save(location); } catch (final ConfigurationException e) { LoggerFactory.getLogger(Factory.class).error(e.getLocalizedMessage()); } } else { try { ConfigurationUtils.dump(cfg, new PrintStream(location)); } catch (final FileNotFoundException e) { LoggerFactory.getLogger(Factory.class).error(e.getLocalizedMessage()); } } }
From source file:nl.cyso.vcloud.client.config.Configuration.java
public static void loadFile(String filename) { org.apache.commons.configuration.Configuration conf = null; try {// ww w . j a v a 2 s . com conf = new PropertiesConfiguration(filename); } catch (ConfigurationException e) { Formatter.printErrorLine("Failed to load configuration file"); Formatter.printErrorLine(e.getLocalizedMessage()); return; } Iterator<String> i = conf.getKeys(); while (i.hasNext()) { String key = i.next(); if (key.equals("help")) { Configuration.setMode(ModeType.HELP); } else if (key.equals("version")) { Configuration.setMode(ModeType.VERSION); } else if (key.equals("list")) { Configuration.setMode(ModeType.LIST); Configuration.setListType(ListType.valueOf(conf.getString(key).toUpperCase())); } else if (key.equals("ip")) { try { Configuration.setIp(conf.getString(key)); } catch (UnknownHostException uhe) { Configuration.setIp((InetAddress) null); } } else { Configuration.set(key, conf.getString(key)); } } }
From source file:nl.nekoconeko.glaciercmd.config.Configuration.java
public static void loadFile(String filename) { org.apache.commons.configuration.Configuration conf = null; try {//from www. ja v a 2 s . c o m conf = new PropertiesConfiguration(filename); } catch (ConfigurationException e) { Formatter.printErrorLine("Failed to load configuration file"); Formatter.printErrorLine(e.getLocalizedMessage()); return; } Iterator<String> i = conf.getKeys(); while (i.hasNext()) { String key = i.next(); if (key.equals("help")) { Configuration.setMode(ModeType.HELP); } else if (key.equals("version")) { Configuration.setMode(ModeType.VERSION); } else if (key.equals("list")) { Configuration.setMode(ModeType.LIST); Configuration.setListType(ListType.valueOf(conf.getString(key).toUpperCase())); } else if (key.equals("region")) { Configuration.setRegion(AWSGlacierRegion.valueOf(conf.getString(key).toUpperCase())); } else { Configuration.set(key, conf.getString(key)); } } }