|
4 | 4 | import java.io.PrintStream;
|
5 | 5 | import java.util.Arrays;
|
6 | 6 | import java.util.Collections;
|
| 7 | +import java.util.Date; |
7 | 8 | import java.util.HashSet;
|
8 | 9 | import java.util.Set;
|
9 | 10 |
|
@@ -90,40 +91,67 @@ public void execute() {
|
90 | 91 | }
|
91 | 92 |
|
92 | 93 | private void runCommand() {
|
93 |
| - if (INIT.equals(command)) { |
94 |
| - new InitializeCommand(repository, environment, force).execute(params); |
95 |
| - } else if (BOOTSTRAP.equals(command)) { |
96 |
| - new BootstrapCommand(repository, environment, force).execute(params); |
97 |
| - } else if (NEW.equals(command)) { |
98 |
| - new NewCommand(repository, environment, template, force).execute(params); |
99 |
| - } else if (STATUS.equals(command)) { |
100 |
| - new StatusCommand(repository, environment, force).execute(params); |
101 |
| - } else if (UP.equals(command)) { |
102 |
| - new UpCommand(repository, environment, force).execute(params); |
103 |
| - } else if (VERSION.equals(command)) { |
104 |
| - new VersionCommand(repository, environment, force).execute(params); |
105 |
| - } else if (PENDING.equals(command)) { |
106 |
| - new PendingCommand(repository, environment, force).execute(params); |
107 |
| - } else if (DOWN.equals(command)) { |
108 |
| - new DownCommand(repository, environment, force).execute(params); |
109 |
| - } else if (SCRIPT.equals(command)) { |
110 |
| - new ScriptCommand(repository, environment, force).execute(params); |
111 |
| - } else { |
112 |
| - String match = null; |
113 |
| - for (String knownCommand : KNOWN_COMMANDS) { |
114 |
| - if (knownCommand.startsWith(command)) { |
115 |
| - if (match != null) { |
116 |
| - throw new MigrationException("Ambiguous command shortcut: " + command); |
| 94 | + printStream.println("------------------------------------------------------------------------"); |
| 95 | + printStream.printf("MyBatis Migrations - %s%n", command); |
| 96 | + printStream.println("------------------------------------------------------------------------"); |
| 97 | + |
| 98 | + long start = System.currentTimeMillis(); |
| 99 | + int exit = 0; |
| 100 | + |
| 101 | + try { |
| 102 | + if (INIT.equals(command)) { |
| 103 | + new InitializeCommand(repository, environment, force).execute(params); |
| 104 | + } else if (BOOTSTRAP.equals(command)) { |
| 105 | + new BootstrapCommand(repository, environment, force).execute(params); |
| 106 | + } else if (NEW.equals(command)) { |
| 107 | + new NewCommand(repository, environment, template, force).execute(params); |
| 108 | + } else if (STATUS.equals(command)) { |
| 109 | + new StatusCommand(repository, environment, force).execute(params); |
| 110 | + } else if (UP.equals(command)) { |
| 111 | + new UpCommand(repository, environment, force).execute(params); |
| 112 | + } else if (VERSION.equals(command)) { |
| 113 | + new VersionCommand(repository, environment, force).execute(params); |
| 114 | + } else if (PENDING.equals(command)) { |
| 115 | + new PendingCommand(repository, environment, force).execute(params); |
| 116 | + } else if (DOWN.equals(command)) { |
| 117 | + new DownCommand(repository, environment, force).execute(params); |
| 118 | + } else if (SCRIPT.equals(command)) { |
| 119 | + new ScriptCommand(repository, environment, force).execute(params); |
| 120 | + } else { |
| 121 | + String match = null; |
| 122 | + for (String knownCommand : KNOWN_COMMANDS) { |
| 123 | + if (knownCommand.startsWith(command)) { |
| 124 | + if (match != null) { |
| 125 | + throw new MigrationException("Ambiguous command shortcut: " + command); |
| 126 | + } |
| 127 | + match = knownCommand; |
117 | 128 | }
|
118 |
| - match = knownCommand; |
| 129 | + } |
| 130 | + if (match != null) { |
| 131 | + command = match; |
| 132 | + runCommand(); |
| 133 | + } else { |
| 134 | + throw new MigrationException("Attempt to execute unknown command: " + command); |
119 | 135 | }
|
120 | 136 | }
|
121 |
| - if (match != null) { |
122 |
| - command = match; |
123 |
| - runCommand(); |
124 |
| - } else { |
125 |
| - throw new MigrationException("Attempt to execute unknown command: " + command); |
126 |
| - } |
| 137 | + } catch (Throwable t) { |
| 138 | + exit = -1; |
| 139 | + t.printStackTrace(printStream); |
| 140 | + } finally { |
| 141 | + printStream.println("------------------------------------------------------------------------"); |
| 142 | + printStream.printf("MyBatis Migrations %s%n", (exit < 0) ? "FAILURE" : "SUCCESS"); |
| 143 | + printStream.printf("Total time: %ss%n", ((System.currentTimeMillis() - start) / 1000)); |
| 144 | + printStream.printf("Finished at: %s%n", new Date()); |
| 145 | + |
| 146 | + final Runtime runtime = Runtime.getRuntime(); |
| 147 | + final int megaUnit = 1024 * 1024; |
| 148 | + printStream.printf("Final Memory: %sM/%sM%n", |
| 149 | + (runtime.totalMemory() - runtime.freeMemory()) / megaUnit, |
| 150 | + runtime.totalMemory() / megaUnit); |
| 151 | + |
| 152 | + printStream.println("------------------------------------------------------------------------"); |
| 153 | + |
| 154 | + System.exit(exit); |
127 | 155 | }
|
128 | 156 | }
|
129 | 157 |
|
|
0 commit comments