/** * Load configuration. * * @param file the file * @return the configuration * @throws IOException Signals that an I/O exception has occurred. */ private void loadConfiguration(File file) throws IOException, ConfigurationException { getLogger().info("Loading Nexus configuration from " + file.getAbsolutePath()); FileInputStream fis = null; try { fis = new FileInputStream(file); loadConfiguration(fis); // seems a bit dirty, but the config might need to be upgraded. if (this.getConfiguration() != null) { // decrypt the passwords setConfiguration(configHelper.encryptDecryptPasswords(getConfiguration(), false)); } } finally { if (fis != null) { fis.close(); } } }
/** * Save configuration. * * @param file the file * @throws IOException Signals that an I/O exception has occurred. */ private void saveConfiguration(File file) throws IOException { FileOutputStream fos = null; File backupFile = new File(file.getParentFile(), file.getName() + ".old"); try { // Create the dir if doesn't exist, throw runtime exception on failure // bad bad bad if (!file.getParentFile().exists() && !file.getParentFile().mkdirs()) { String message = "\r\n******************************************************************************\r\n" + "* Could not create configuration file [ " + file.toString() + "]!!!! *\r\n" + "* Nexus cannot start properly until the process has read+write permissions to this folder *\r\n" + "******************************************************************************"; getLogger().error(message); } // copy the current nexus config file as file.bak if (file.exists()) { FileUtils.copyFile(file, backupFile); } // Clone the conf so we can encrypt the passwords Configuration copyOfConfig = configHelper.encryptDecryptPasswords(getConfiguration(), true); fos = new FileOutputStream(file); saveConfiguration(fos, copyOfConfig); fos.flush(); } finally { IOUtil.close(fos); } // if all went well, delete the bak file backupFile.delete(); }