|
5 | 5 | import java.lang.annotation.Annotation; |
6 | 6 | import java.util.ArrayList; |
7 | 7 | import java.util.HashMap; |
8 | | -import java.util.HashSet; |
9 | 8 | import java.util.List; |
10 | 9 | import java.util.Map; |
11 | 10 | import java.util.Set; |
|
16 | 15 | public class CommandFactory { |
17 | 16 |
|
18 | 17 | private static final org.slf4j.Logger logger = LoggerFactory.getLogger(CommandFactory.class); |
19 | | - private static final Map<String, Class<Command>> commands = new HashMap<>(); |
20 | | - private static final Map<String, List<Class<Command>>> packages = new HashMap<>(); |
| 18 | + private static Map<String, Class<Command>> commands; |
| 19 | + private static Map<String, List<Class<Command>>> packages; |
21 | 20 |
|
22 | 21 | static { |
23 | | - /* Force load the CommandList so that it's static initialization block is executed. |
24 | | - * This hack is used instead of import so that the IDEs won't cry about the nonexistent |
25 | | - * class. |
26 | | - */ |
27 | | - try { |
28 | | - Class.forName("fi.helsinki.cs.tmc.cli.core.CommandList"); |
29 | | - } catch (ClassNotFoundException ex) { |
30 | | - System.out.println("Fail " + ex); |
31 | | - } |
| 22 | + CommandFactory.reload(); |
32 | 23 | } |
33 | 24 |
|
34 | 25 | /** |
@@ -121,4 +112,19 @@ public static List<Class<Command>> getCategoryCommands(String category) { |
121 | 112 | public static Class<Command> castToCommandClass(Class command) { |
122 | 113 | return command; |
123 | 114 | } |
| 115 | + |
| 116 | + protected static void reload() { |
| 117 | + CommandFactory.commands = new HashMap<>(); |
| 118 | + CommandFactory.packages = new HashMap<>(); |
| 119 | + |
| 120 | + /* Run constructor of the CommandList. |
| 121 | + * This hack is used instead of import so that the IDEs won't cry about the nonexistent |
| 122 | + * class. |
| 123 | + */ |
| 124 | + try { |
| 125 | + Class.forName("fi.helsinki.cs.tmc.cli.core.CommandList").newInstance(); |
| 126 | + } catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) { |
| 127 | + logger.warn("CommandList initialization failed", ex); |
| 128 | + } |
| 129 | + } |
124 | 130 | } |
0 commit comments