Application { public void persistRepositoryConfigurations() throws IOException { for (final RepositoryConfiguration repositoryConfig : repositoryConfigurations.getAllConfigurations()) { if (!repositoryConfig.isPersisted()) { final File configDir = getConfigurationDirectoryForRepository(repositoryConfig.getName()); if (!configDir.exists() && !configDir.mkdirs()) { throw new IOException("Unable to create directory: " + configDir.getAbsolutePath()); } final File configFile = new File(configDir, getConfigurationFileName()); logger.info("Storing configuration: " + configFile.getAbsolutePath()); FileOutputStream fileOutputStream = null; try { fileOutputStream = new FileOutputStream(configFile); final Properties configProperties = repositoryConfig.getAsProperties(); logger.debug("Storing properties: " + configProperties); configProperties.store(fileOutputStream, ""); fileOutputStream.flush(); repositoryConfig.setPersisted(); } finally { IOUtils.closeQuietly(fileOutputStream); } } } } Application(final ConfigDirectory configDirectory); void setScheduler(final Scheduler scheduler); @PostConstruct void init(); @ManagedOperation synchronized void reinit(); File[] getConfigDirectories(); File[] getBackupConfigDirectories(); void initCaches(); void persistRepositoryConfigurations(); void addConfiguration(final RepositoryConfiguration configuration); void deleteConfiguration(final RepositoryName name); void setConfigurationFileName(String configurationFileName); String getConfigurationFileName(); Set<RepositoryName> getRepositoryNames(); RepositoryConfiguration getConfiguration(final RepositoryName name); int getRepositoryConfigurationCount(); boolean hasConfigurations(); boolean isConfigured(); synchronized boolean isUpdating(final RepositoryName name); void setConfigPassword(final String configPassword); boolean isValidConfigPassword(final String configPassword); synchronized void setUpdatingCache(final RepositoryName name, final boolean updating); void setConfigured(final boolean configured); File getConfigurationDirectoryForRepository(final RepositoryName repositoryName); @Autowired void setCacheManagers(final List<CacheManager> cacheManagers); void setEditableConfig(final boolean editableConfig); boolean isEditableConfig(); boolean isConfigurationReloadSupported(); void setConfigurationReloadSupported(boolean configurationReloadSupported); URL getBaseURL(); static final String PROPERTY_KEY_SVENTON_BASE_URL; }
@Test public void testPersistRepositoryConfigurations() throws Exception { final MockServletContext servletContext = new MockServletContext(); servletContext.setContextPath("sventon-test"); configDirectory.setServletContext(servletContext); final File repos1 = new File(configDirectory.getRepositoriesDirectory(), "testrepos1"); final File repos2 = new File(configDirectory.getRepositoriesDirectory(), "testrepos2"); final Application application = new Application(configDirectory); application.setConfigurationFileName(CONFIG_FILE_NAME); final RepositoryConfiguration repositoryConfiguration1 = new RepositoryConfiguration("testrepos1"); repositoryConfiguration1.setRepositoryUrl("http: repositoryConfiguration1.setUserCredentials(new Credentials("user1", "abc123")); repositoryConfiguration1.setCacheUsed(false); repositoryConfiguration1.setZippedDownloadsAllowed(false); final RepositoryConfiguration repositoryConfiguration2 = new RepositoryConfiguration("testrepos2"); repositoryConfiguration2.setRepositoryUrl("http: repositoryConfiguration2.setUserCredentials(new Credentials("user2", "123abc")); repositoryConfiguration2.setCacheUsed(false); repositoryConfiguration2.setZippedDownloadsAllowed(false); application.addConfiguration(repositoryConfiguration1); application.addConfiguration(repositoryConfiguration2); assertFalse(new File(repos1, CONFIG_FILE_NAME).exists()); assertFalse(new File(repos2, CONFIG_FILE_NAME).exists()); application.persistRepositoryConfigurations(); assertTrue(new File(repos1, CONFIG_FILE_NAME).exists()); assertTrue(new File(repos2, CONFIG_FILE_NAME).exists()); }