package com.hubilon; import com.hubilon.util.BrowserLauncher; import com.hubilon.util.DebugState; import java.io.File; import java.net.URISyntaxException; import java.nio.file.Path; import java.security.CodeSource; /** * Java replacement for run.ps1: embedded HTTP server serving the bundled * index.html and proxying Kong/APIM comparison requests, driven by a * config.json that lives next to this jar (created from a sample if missing). */ public final class Main { private Main() { } public static void main(String[] args) throws Exception { int port = 8080; String config = "config.json"; boolean noBrowser = false; boolean debug = false; for (int i = 0; i < args.length; i++) { switch (args[i]) { case "--port": port = Integer.parseInt(args[++i]); break; case "--config": config = args[++i]; break; case "--no-browser": noBrowser = true; break; case "--debug": debug = true; break; default: System.out.println("Unknown argument: " + args[i]); } } Path workDir = resolveWorkDir(); DebugState debugState = new DebugState(debug); ApiDiffServer server = ApiDiffServer.create(port, workDir, config, debugState); server.start(); System.out.println(); System.out.println(" Kong <-> Azure APIM diff tester (Java)"); System.out.println(" ---------------------------------------"); System.out.println(" URL : " + server.getBaseUrl()); System.out.println(" workDir : " + workDir); if (debug) { System.out.println(" debug : ON (--debug)"); } System.out.println(" Press Ctrl+C to stop."); System.out.println(); if (!noBrowser) { BrowserLauncher.open(server.getBaseUrl()); } Runtime.getRuntime().addShutdownHook(new Thread(server::stop)); } private static Path resolveWorkDir() { try { CodeSource codeSource = Main.class.getProtectionDomain().getCodeSource(); if (codeSource != null) { File location = new File(codeSource.getLocation().toURI()); File dir = location.isFile() ? location.getParentFile() : location; if (dir != null) { return dir.toPath().toAbsolutePath().normalize(); } } } catch (URISyntaxException e) { // fall through to the working-directory default } return Path.of("").toAbsolutePath(); } }