public static void main(String[] args) throws Throwable {
        final XSLTMain main = loadMain();

        TransformerFactory transformerFactory;
        try {
            transformerFactory = main.createTransformerFactory();
        } catch (AbstractMethodError e) {
            // old debugger
            transformerFactory = createTransformerFactoryStatic();
        } catch (ClassNotFoundException e) {
            transformerFactory = createTransformerFactoryStatic();
        }

        final String uriResolverClass = System.getProperty("xslt.uri-resolver");
        if (uriResolverClass != null) {
            transformerFactory.setURIResolver((URIResolver)Class.forName(uriResolverClass).newInstance());
        }

        final boolean[] trouble = new boolean[]{ false };
        final MyErrorListener listener = new MyErrorListener(trouble);
        final boolean isSmartErrorHandling = System.getProperty("xslt.smart-error-handling", "false").equals("true");
        if (isSmartErrorHandling) {
            transformerFactory.setErrorListener(listener);
        }

        final File xslt = new File(System.getProperty("xslt.file"));
        try {
            final Transformer transformer = transformerFactory.newTransformer(new StreamSource(xslt));
            if (transformer != null && !trouble[0]) {
                final Enumeration props = System.getProperties().keys();
                while (props.hasMoreElements()) {
                    String s = (String)props.nextElement();
                    if (s.startsWith("xslt.param.")) {
                        final String name = s.substring("xslt.param.".length());
                        final String value = System.getProperty(s);
                        transformer.setParameter(name, value);
                    }
                }

                final File input = new File(System.getProperty("xslt.input"));
                final String out = System.getProperty("xslt.output");
                OutputStream fileStream;
                if (out != null) {
                  final File output = new File(out);
                  fileStream = new BufferedOutputStream(new FileOutputStream(output));
                } else {
                  fileStream = null;
                }
                final StreamResult result;

                final Integer _port = Integer.getInteger("xslt.listen-port", -1);
                final int port = _port.intValue();
                if (port != -1) {
                    // block until IDEA connects
                    try {
                        final ServerSocket serverSocket = new ServerSocket(port, 1, InetAddress.getByName("127.0.0.1"));
                        serverSocket.setSoTimeout(Integer.getInteger("xslt.listen-timeout", 5000).intValue());
                        final Socket socket = serverSocket.accept();
                        final BufferedOutputStream socketStream = new BufferedOutputStream(socket.getOutputStream(), 16);

                        if (out != null) {
                            result = new StreamResult(new ForkedOutputStream(new OutputStream[]{ socketStream, fileStream }));
                        } else {
                            result = new StreamResult(new OutputStreamWriter(socketStream, StandardCharsets.UTF_8));
                        }
                    } catch (SocketTimeoutException ignored) {
                        System.err.println("Plugin did not connect to runner within timeout. Run aborted.");
                        return;
                    }
                } else {
                    final String encoding = System.getProperty("file.encoding");
                    if (encoding != null) {
                        // ensure proper encoding in xml declaration
                        transformer.setOutputProperty("encoding", encoding);
                        if (out != null) {
                          result = new StreamResult(new OutputStreamWriter(new ForkedOutputStream(new OutputStream[]{System.out, fileStream}), encoding));
                        } else {
                          result = new StreamResult(new OutputStreamWriter(System.out, encoding));
                        }
                      } else {
                        if (out != null) {
                          result = new StreamResult(new ForkedOutputStream(new OutputStream[]{ System.out, fileStream }));
                        } else {
                          result = new StreamResult(System.out);
                        }
                      }
                }

                Runtime.getRuntime().addShutdownHook(new Thread("XSLT runner") {
                  public void run() {
                    try {
                      final Writer out = result.getWriter();
                      if (out != null) {
                        out.flush();
                        out.close();
                      } else if (result.getOutputStream() != null) {
                        result.getOutputStream().flush();
                        result.getOutputStream().close();
                      }
                    } catch (IOException e) {
                      // no chance to fix...
                    }
                  }
                });

                main.start(transformer, new StreamSource(input), result);
            }
        } catch (TransformerException e) {
            if (isSmartErrorHandling) {
                listener.error(e);
            } else {
                throw e;
            }
        } catch (Throwable t) {
            t.printStackTrace();
            System.exit(1);
        }
    }
public static void main(String[] args)