| 36 | import org.zaproxy.zap.utils.Stats; |
| 37 | |
| 38 | public class ZAP { |
| 39 | |
| 40 | static { |
| 41 | System.setProperty("java.util.logging.manager", "org.apache.logging.log4j.jul.LogManager"); |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * ZAP can be run in 4 different ways: cmdline: an inline process that exits when it completes |
| 46 | * the tasks specified by the parameters daemon: a single process with no Swing UI, typically |
| 47 | * run as a background process desktop: a Swing based desktop tool (which is how it originated, |
| 48 | * as a fork of Paros Proxy) zaas: a highly scalable distributed system with a web based UI, aka |
| 49 | * 'ZAP as a Service' (this is 'work in progress') |
| 50 | */ |
| 51 | public enum ProcessType { |
| 52 | cmdline, |
| 53 | daemon, |
| 54 | desktop, |
| 55 | zaas |
| 56 | } |
| 57 | |
| 58 | private static ProcessType processType; |
| 59 | |
| 60 | private static final EventBus eventBus = new SimpleEventBus(); |
| 61 | private static final Logger LOGGER = LogManager.getLogger(ZAP.class); |
| 62 | |
| 63 | static { |
| 64 | try { |
| 65 | // Disable JAR caching to avoid leaking add-on files and use of stale data. |
| 66 | URLConnection.class |
| 67 | .getDeclaredMethod("setDefaultUseCaches", String.class, boolean.class) |
| 68 | .invoke(null, "jar", false); |
| 69 | } catch (Exception e) { |
| 70 | // Nothing to do, Java 9+ API and logger was not yet initialised. |
| 71 | } |
| 72 | |
| 73 | Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionLogger()); |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Main method |
| 78 | * |
| 79 | * @param args the arguments passed to the command line version |
| 80 | * @throws Exception if something wrong happens |
| 81 | */ |
| 82 | public static void main(String[] args) throws Exception { |
| 83 | setCustomErrStream(); |
| 84 | |
| 85 | CommandLine cmdLine = null; |
| 86 | try { |
| 87 | cmdLine = new CommandLine(args != null ? Arrays.copyOf(args, args.length) : null); |
| 88 | |
| 89 | } catch (final Exception e) { |
| 90 | // Cant use the CommandLine help here as the |
| 91 | // i18n messages wont have been loaded |
| 92 | System.out.println("Failed due to invalid parameters: " + Arrays.toString(args)); |
| 93 | System.out.println(e.getMessage()); |
| 94 | System.out.println("Use '-h' for more details."); |
| 95 | System.exit(1); |