ARTEMIS-912 Fix file configuration migration tool

This commit is contained in:
Martyn Taylor 2017-01-09 14:48:28 +00:00 committed by Justin Bertram
parent ef4efe7d3f
commit 63cf4d5a60
1 changed files with 18 additions and 19 deletions

View File

@ -29,7 +29,7 @@ public class Main {
File input = new File(args[0]); File input = new File(args[0]);
if (input.isDirectory()) { if (input.isDirectory()) {
System.out.println("Scanning directory: " + input.getAbsolutePath()); System.out.println("Scanning directory: " + input.getAbsolutePath());
recursiveTransform(input); scanAndTransform(input);
} else { } else {
if (args.length != 2) { if (args.length != 2) {
System.err.println("Invalid args"); System.err.println("Invalid args");
@ -37,6 +37,7 @@ public class Main {
} else { } else {
try { try {
XMLConfigurationMigration migration = new XMLConfigurationMigration(input, new File(args[1])); XMLConfigurationMigration migration = new XMLConfigurationMigration(input, new File(args[1]));
migration.transform();
} catch (Exception e) { } catch (Exception e) {
// Unable to process file, move on. // Unable to process file, move on.
} }
@ -51,30 +52,28 @@ public class Main {
} }
} }
public static void scanAndTransform(File pFile) throws Exception { public static void scanAndTransform(File f) throws Exception {
try { try {
for (File f : pFile.listFiles()) { if (f.isDirectory()) {
if (f.isDirectory()) { recursiveTransform(f);
scanAndTransform(f); } else {
} else { try {
try { if (f.getName().endsWith("xml")) {
if (f.getName().endsWith("xml")) { File file = new File(f.getAbsolutePath() + ".new");
File file = new File(f.getAbsolutePath() + ".new"); XMLConfigurationMigration migration = new XMLConfigurationMigration(f, file);
XMLConfigurationMigration migration = new XMLConfigurationMigration(f, file); if (migration.transform()) {
if (migration.transform()) { File r = new File(f.getAbsolutePath());
File r = new File(f.getAbsolutePath()); f.renameTo(new File(f.getAbsolutePath() + ".bk"));
f.renameTo(new File(f.getAbsolutePath() + ".bk")); file.renameTo(r);
file.renameTo(r); System.out.println(f + " converted, old file renamed as " + f.getAbsolutePath() + ".bk");
System.out.println(f + " converted, old file renamed as " + f.getAbsolutePath() + ".bk");
}
} }
} catch (Exception e) {
//Unable to process file, continue
} }
} catch (Exception e) {
//Unable to process file, continue
} }
} }
} catch (NullPointerException e) { } catch (NullPointerException e) {
System.out.println(pFile.getAbsoluteFile()); System.out.println(f.getAbsoluteFile());
} }
} }