private void readMigrations( SortedMap<Long, List<ConfigMigrationStategy>> configMigrations, URL url) throws IOException { InputStreamReader r = null; try { r = new InputStreamReader(url.openStream(), ConfigUtilConstants.DEFAULT_TEXT_ENCODING); XStream x = createXStream(); ConfigManagerMigrations migrations = (ConfigManagerMigrations) x.fromXML(r); for (Migration m : migrations.getMigrationList()) { long versionTarget = m.getTargetVersion(); String className = m.getMigrationClass(); String[] constructorArguments = m.getArguments(); List<ConfigMigrationStategy> configMigrationForVersionTarget = configMigrations.get(versionTarget); if (configMigrationForVersionTarget == null) { configMigrationForVersionTarget = new ArrayList(); configMigrations.put(versionTarget, configMigrationForVersionTarget); } ConfigMigrationStategy configMigration = createMigrationStrategy(versionTarget, className, constructorArguments); configMigrationForVersionTarget.add(configMigration); } } finally { try { if (r != null) r.close(); } catch (IOException e) { ConfigLogImplementation.logMethods.error( "Failed to close ConfigMigration InputStream from URL " + url, e); } } }
// util to write the first config migrations file, solve the chicken an egg problem. After that we // can do it manually public static void main(String[] args) { Migration c = new Migration(201011181800L, NullMigrationStrategy.class.getName(), new String[] {}); Migration c1 = new Migration( 201103201834L, RegexMigrationStrategy.class.getName(), new String[] {"Last Refresh\\w", "Last Refresh Time"}); ConfigManagerMigrations m = new ConfigManagerMigrations(); m.addMigration(c); m.addMigration(c1); writeMigrationsFile(m, new File(args[0])); }