(Box root)
| 24 | ReloadTarget target = new ReloadTarget(); |
| 25 | |
| 26 | public Reload(Box root) { |
| 27 | Log.on(".*reload.*", Log::red); |
| 28 | |
| 29 | new Thread(() -> { |
| 30 | int lastNotified = 0; |
| 31 | while (true) { |
| 32 | try { |
| 33 | toReload = Trampoline.loadMap.entrySet().stream().filter(x -> x.getValue().modified()) |
| 34 | .collect(Collectors.toList()); |
| 35 | |
| 36 | } catch (ConcurrentModificationException e) { |
| 37 | // doesn't matter (will happen if classes are loading while we iterate over it) |
| 38 | } |
| 39 | try { |
| 40 | Thread.sleep(2000); |
| 41 | } catch (InterruptedException e) { |
| 42 | e.printStackTrace(); |
| 43 | } |
| 44 | if (toReload.size()>lastNotified) { |
| 45 | lastNotified = toReload.size(); |
| 46 | String classList = toReload.stream().map( x-> x.getKey().getName().substring(x.getKey().getName().lastIndexOf(".")+1)).collect(Collectors.joining(", ")); |
| 47 | if (classList.length()>100) classList = classList.substring(0, 100)+"..."; |
| 48 | String fclassList = classList; |
| 49 | Log.log("reload", ()->"There are classes that can be reloaded: " + fclassList); |
| 50 | Log.log("reload", ()->"Use the reload command to do so"); |
| 51 | NotificationBox.notification(root, "The following "+(toReload.size())+" class"+(toReload.size()==1 ? "" : "es")+" are ready to be reloaded (with <i>command-space</i>): "+classList); |
| 52 | } |
| 53 | } |
| 54 | }).start(); |
| 55 | |
| 56 | properties.put(Commands.commands, () -> { |
| 57 | Map<Pair<String, String>, Runnable> m = new LinkedHashMap<>(); |
| 58 | Log.log("reload", ()->"needing reloading h..."+toReload); |
| 59 | |
| 60 | List<Map.Entry<Class, Trampoline.Record>> toReload_copy = toReload; |
| 61 | |
| 62 | if (toReload_copy.size() == 0) { |
| 63 | } else { |
| 64 | String classList = toReload_copy.stream().map( x-> x.getKey().getName().substring(x.getKey().getName().lastIndexOf(".")+1)).collect(Collectors.joining(", ")); |
| 65 | if (classList.length()>100) classList = classList.substring(0, 100)+"..."; |
| 66 | NotificationBox.clearNotifications(root); |
| 67 | m.put(new Pair<>("Reload changed classes", "Reloads the class" + (toReload_copy |
| 68 | .size() != 1 ? "es" : "") + " that have changed on disk — <i>" + classList+"</i>"), () -> { |
| 69 | boolean fine = Hotswapper.swapClass(x -> NotificationBox.notification(root, x), toReload_copy.stream().map(x ->x .getKey()).collect(Collectors.toList()).toArray(new Class[0])); |
| 70 | if (fine) |
| 71 | NotificationBox.notification(root, "reloaded :<b>"+toReload_copy.size()+" class"+(toReload_copy.size()==1 ? "" : "es")+"</b>"); |
| 72 | else |
| 73 | NotificationBox.notification(root, "<b> an error ocurred reloading classes, either Field is not being run in debug mode, or the reload was not possible </b>"); |
| 74 | toReload_copy.stream().forEach( x -> Trampoline.loadMap.compute( x.getKey(), (z, r) -> r.update())); |
| 75 | }); |
| 76 | } |
| 77 | |
| 78 | // m.put(new Pair<>("do that thing", "does it work yet?"), () -> Hotswapper.doSomething()); |
| 79 | |
| 80 | |
| 81 | return m; |
| 82 | }); |
| 83 | } |
nothing calls this directly
no test coverage detected