import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;
+import java.util.Collections;
import java.util.HashMap;
+import java.util.Map;
import java.util.Properties;
import javax.servlet.http.HttpServletRequest;
}
i++;
}
- try {
- String targetPort = mainProps.getProperty("http.port");
- String targetHost = mainProps.getProperty("name.www");
- URL u = new URL("http://" + targetHost + ":" + targetPort + "/kill");
- u.openStream();
- } catch (IOException e) {
- }
+ killPreviousInstance(mainProps);
ByteArrayOutputStream chunkConfig = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(chunkConfig);
System.exit(0);
}
+ private static void killPreviousInstance(Properties mainProps) {
+ try {
+ String targetPort = mainProps.getProperty("http.port");
+ String targetHost = mainProps.getProperty("name.www");
+ URL u = new URL("http://" + targetHost + ":" + targetPort + "/kill");
+ u.openStream();
+ } catch (IOException e) {
+ }
+ }
+
public static void addDevelPage() {
try {
Field instF = Gigi.class.getDeclaredField("instance");
instF.setAccessible(true);
pageF.setAccessible(true);
Object gigi = instF.get(null);
- HashMap<String, Page> pages = (HashMap<String, Page>) pageF.get(gigi);
+
+ // Check if we got a proper map (as much as we can tell)
+ Object pagesObj = pageF.get(gigi);
+ @SuppressWarnings("unchecked")
+ HashMap<String, Page> pages = pagesObj instanceof Map ? new HashMap<>((Map<String, Page>) pagesObj) : null;
+
pages.put("/manage", new Page("Page-manager") {
@Override
public boolean needsLogin() {
return false;
}
+
});
+
pages.put("/kill", new Page("Kill") {
+ /**
+ * The contained call to {@link System#exit(int)} is mainly
+ * needed to kill this instance immediately if another
+ * {@link DevelLauncher} is booting up to free all ports This is
+ * required for fast development cycles.
+ *
+ * @see #killPreviousInstance(Properties)
+ */
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
System.exit(0);
return false;
}
});
+
+ pageF.set(gigi, Collections.unmodifiableMap(pages));
} catch (ReflectiveOperationException e) {
e.printStackTrace();
}