Esempio n. 1
1
  public ConsoleManager(GlowServer server) {
    this.server = server;

    // install Ansi code handler, which makes colors work on Windows
    AnsiConsole.systemInstall();

    for (Handler h : logger.getHandlers()) {
      logger.removeHandler(h);
    }

    // used until/unless gui is created
    consoleHandler = new FancyConsoleHandler();
    // consoleHandler.setFormatter(new DateOutputFormatter(CONSOLE_DATE));
    logger.addHandler(consoleHandler);

    // todo: why is this here?
    Runtime.getRuntime().addShutdownHook(new ServerShutdownThread());

    // reader must be initialized before standard streams are changed
    try {
      reader = new ConsoleReader();
    } catch (IOException ex) {
      logger.log(Level.SEVERE, "Exception initializing console reader", ex);
    }
    reader.addCompleter(new CommandCompleter());

    // set system output streams
    System.setOut(new PrintStream(new LoggerOutputStream(Level.INFO), true));
    System.setErr(new PrintStream(new LoggerOutputStream(Level.WARNING), true));
  }
Esempio n. 2
0
 private void redirectIO() {
   // redirect std I/O to console and problems:
   // > System.out => console
   // > System.err => problems
   // > console => System.in
   System.setOut(consoleView.getOutputStream());
   System.setErr(problemsView.getOutputStream());
   // redirect input from console to System.in
   System.setIn(consoleView.getInputStream());
 }
  protected static Logger setupLogger() {
    final Logger logger = Utils.getLogger();
    File logDirectory = new File(Utils.getLauncherDirectory(), "logs");
    if (!logDirectory.exists()) {
      logDirectory.mkdir();
    }
    File logs = new File(logDirectory, "lovelauncher_%D.log");
    RotatingFileHandler fileHandler = new RotatingFileHandler(logs.getPath());

    fileHandler.setFormatter(new TechnicLogFormatter());

    for (Handler h : logger.getHandlers()) {
      logger.removeHandler(h);
    }
    logger.addHandler(fileHandler);

    SpoutcraftLauncher.handler = fileHandler;

    if (params != null && !params.isDebugMode()) {
      logger.setUseParentHandlers(false);

      System.setOut(new PrintStream(new LoggerOutputStream(console, Level.INFO, logger), true));
      System.setErr(new PrintStream(new LoggerOutputStream(console, Level.SEVERE, logger), true));
    }

    Thread.setDefaultUncaughtExceptionHandler(
        new Thread.UncaughtExceptionHandler() {
          @Override
          public void uncaughtException(Thread t, Throwable e) {
            logger.log(Level.SEVERE, "Unhandled Exception in " + t, e);

            if (errorDialog == null) {
              LauncherFrame frame = null;

              try {
                frame = Launcher.getFrame();
              } catch (Exception ex) {
                // This can happen if we have a very early crash- before Launcher initializes
              }

              errorDialog = new ErrorDialog(frame, e);
              errorDialog.setVisible(true);
            }
          }
        });

    return logger;
  }
Esempio n. 4
0
  private void createUIComponents() {
    displayArea = new JEditorPane("text/html", "");
    displayArea.setEditable(false);
    kit = new HTMLEditorKit();
    displayArea.setEditorKit(kit);

    JScrollPane scrollPane = new JScrollPane(displayArea);
    scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

    logType = ELogType.valueOf(SettingsUtils.getValue(ESetting.LOGTYPE));
    refreshLogs();
    Logger.addListener(this);

    System.setOut(new OutputOverride(System.out, LogLevel.INFO));
    System.setErr(new OutputOverride(System.err, LogLevel.ERROR));
    try {
      Logger.addListener(new LogWriter(new File(launcherLogFile)));
    } catch (IOException e1) {
      Logger.logError(e1.getMessage(), e1);
    }
  }
  private void redirectSystemStreams() {
    OutputStream out =
        new OutputStream() {
          @Override
          public void write(int b) throws IOException {
            updateTextArea(String.valueOf((char) b));
          }

          @Override
          public void write(byte[] b, int off, int len) throws IOException {
            updateTextArea(new String(b, off, len));
          }

          @Override
          public void write(byte[] b) throws IOException {
            write(b, 0, b.length);
          }
        };

    System.setOut(new PrintStream(out, true));
    System.setErr(new PrintStream(out, true));
  }
  public static void main() {
    // Main
    frame = new JFrame("Java Playground");
    frame.setSize(640, 480);
    // Make sure the divider is properly resized
    frame.addComponentListener(
        new ComponentAdapter() {
          public void componentResized(ComponentEvent c) {
            splitter.setDividerLocation(.8);
          }
        });
    // Make sure the JVM is reset on close
    frame.addWindowListener(
        new WindowAdapter() {
          public void windowClosed(WindowEvent w) {
            new FrameAction().kill();
          }
        });

    // Setting up the keybinding
    // Ctrl+k or Cmd+k -> compile
    bind(KeyEvent.VK_K);

    // Ctrl+e or Cmd+e -> console
    bind(KeyEvent.VK_E);

    // Save, New file, Open file, Print.
    // Currently UNUSED until I figure out how normal java files and playground files will
    // interface.
    bind(KeyEvent.VK_S);
    bind(KeyEvent.VK_N);
    bind(KeyEvent.VK_O);
    bind(KeyEvent.VK_P);

    // Binds the keys to the action defined in the FrameAction class.
    frame.getRootPane().getActionMap().put("console", new FrameAction());

    // The main panel for typing code in.
    text = new JTextPane();
    textScroll = new JScrollPane(text);
    textScroll.setBorder(null);
    textScroll.setPreferredSize(new Dimension(640, 480));

    // Document with syntax highlighting. Currently unfinished.
    doc = text.getStyledDocument();
    doc.addDocumentListener(
        new DocumentListener() {
          public void changedUpdate(DocumentEvent d) {}

          public void insertUpdate(DocumentEvent d) {}

          public void removeUpdate(DocumentEvent d) {}
        });

    ((AbstractDocument) doc).setDocumentFilter(new NewLineFilter());

    // The output log; a combination compiler warning/error/runtime error/output log.
    outputText = new JTextPane();
    outputScroll = new JScrollPane(outputText);
    outputScroll.setBorder(null);

    // "Constant" for the error font
    error = new SimpleAttributeSet();
    error.addAttribute(StyleConstants.CharacterConstants.Italic, Boolean.TRUE);
    error.addAttribute(StyleConstants.Foreground, Color.RED);

    // "Constant" for the warning message font
    warning = new SimpleAttributeSet();
    warning.addAttribute(StyleConstants.CharacterConstants.Italic, Boolean.TRUE);
    warning.addAttribute(StyleConstants.Foreground, Color.PINK);

    // "Constant" for the debugger error font
    progErr = new SimpleAttributeSet();
    progErr.addAttribute(StyleConstants.Foreground, Color.BLUE);

    // Print streams to redirect System.out and System.err.
    out = new TextOutputStream(outputText, null);
    err = new TextOutputStream(outputText, error);
    System.setOut(new PrintStream(out));
    System.setErr(new PrintStream(err));

    // Sets up the output log
    outputText.setEditable(false);
    outputScroll.setVisible(true);

    // File input/output setup
    chooser = new JFileChooser();

    // Setting up miscellaneous stuff
    compiler = ToolProvider.getSystemJavaCompiler();
    JVMrunning = false;
    redirectErr = null;
    redirectOut = null;
    redirectIn = null;

    // Sets up the splitter pane and opens the program up
    splitter = new JSplitPane(JSplitPane.VERTICAL_SPLIT, textScroll, outputScroll);
    consoleDisplayed = false;
    splitter.remove(outputScroll); // Initially hides terminal until it is needed
    splitter.setOneTouchExpandable(true);
    frame.add(splitter);
    frame.setVisible(true);

    // Sets the divider to the proper one, for debugging
    // splitter.setDividerLocation(.8);
  }
Esempio n. 7
0
  public static void main(String argv[]) {
    System.setErr(System.out);

    try {

      UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");

    } catch (Exception e) {
      try {

        UIManager.setLookAndFeel("javax.swing.plaf.windows.WindowsLookAndFeel");

      } catch (Exception e1) {
        try {

          UIManager.setLookAndFeel("javax.swing.plaf.motif.MotifLookAndFeel");

        } catch (Exception e2) {
          try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
          } catch (Exception e3) {
          }
        }
      }
    }

    UIManager.put("TextField.background", new Color(255, 255, 255));
    String strCreateTables = null,
        strRunTests = null,
        strCleanUp = null,
        strCreateProc = null,
        strCreateResult = null,
        strDropResult = null,
        strLogLevel = null;
    String strTPCCRun = null, strTPCCLoad = null;
    BenchMain.bench = new BenchMain();
    bench.m_bInApplet = false;

    if (argv.length > 0)
      for (int nArg = 0; nArg < argv.length; nArg++) {
        if (argv[nArg].toUpperCase().startsWith("URL="))
          bench.m_strURL = argv[nArg].substring(argv[nArg].indexOf("=") + 1);
        else if (argv[nArg].toUpperCase().startsWith("USER="******"=") + 1);
        else if (argv[nArg].toUpperCase().startsWith("PASSWORD="******"=") + 1);
        else if (argv[nArg].toUpperCase().startsWith("DRIVER="))
          bench.m_strDriver = argv[nArg].substring(argv[nArg].indexOf("=") + 1);
        else if (argv[nArg].toUpperCase().startsWith("DRIVERTYPE="))
          bench.m_nDriverType =
              Integer.valueOf(argv[nArg].substring(argv[nArg].indexOf("=") + 1)).intValue();
        else if (argv[nArg].toUpperCase().startsWith("CREATETABLES="))
          strCreateTables = argv[nArg].substring(argv[nArg].indexOf("=") + 1);
        else if (argv[nArg].toUpperCase().startsWith("RUNTEST="))
          strRunTests = argv[nArg].substring(argv[nArg].indexOf("=") + 1);
        else if (argv[nArg].toUpperCase().startsWith("CLEANUP")) strCleanUp = argv[nArg];
        else if (argv[nArg].toUpperCase().startsWith("CREATEPROC")) strCreateProc = argv[nArg];
        else if (argv[nArg].toUpperCase().startsWith("CREATERESULT")) strCreateResult = argv[nArg];
        else if (argv[nArg].toUpperCase().startsWith("DROPRESULT")) strDropResult = argv[nArg];
        else if (argv[nArg].toUpperCase().startsWith("LOGLEVEL="))
          strLogLevel = argv[nArg].substring(argv[nArg].indexOf("=") + 1);
        else if (argv[nArg].toUpperCase().startsWith("TPCCRUN="))
          strTPCCRun = argv[nArg].substring(argv[nArg].indexOf("=") + 1);
        else if (argv[nArg].toUpperCase().startsWith("TPCCLOAD="))
          strTPCCLoad = argv[nArg].substring(argv[nArg].indexOf("=") + 1);
      }
    bench.m_bInApplet = false;
    try {
      if (strCreateTables != null
          || strRunTests != null
          || strCleanUp != null
          || strCreateProc != null
          || strCreateResult != null
          || strDropResult != null
          || strTPCCRun != null
          || strTPCCLoad != null) {
        // batch
        TextProgress progress = new TextProgress();
        Bench.BenchPanel pane =
            new Bench.BenchPanel(
                bench.m_strDriver,
                bench.m_strURL,
                bench.m_strUserName,
                bench.m_strPassword,
                bench.m_nDriverType);
        Bench.Logger new_log =
            new Bench.Logger() {
              int m_nLogLevel = 0;

              public synchronized void log(String strMessage, int nLevel) {
                if (nLevel <= m_nLogLevel) System.out.print(strMessage);
              }

              public synchronized void taskDone() {
                notify();
              }

              public synchronized void waitOn() throws InterruptedException {
                wait();
              }

              public synchronized void setLogLevel(int nNewLogLevel) {
                m_nLogLevel = nNewLogLevel;
              }

              public synchronized int getLogLevel() {
                return m_nLogLevel;
              }
            };

        if (strLogLevel != null) new_log.setLogLevel(Integer.valueOf(strLogLevel).intValue());
        pane.setLogger(new_log);
        if (strCreateTables != null) {
          StringTokenizer createTokens = new StringTokenizer(strCreateTables, ",;/");
          int nBranchCount = 10, nTellerCount = 100, nAccountCount = 1000;
          if (createTokens.hasMoreTokens())
            nBranchCount = Integer.valueOf(createTokens.nextToken()).intValue();
          if (createTokens.hasMoreTokens())
            nTellerCount = Integer.valueOf(createTokens.nextToken()).intValue();
          if (createTokens.hasMoreTokens())
            nAccountCount = Integer.valueOf(createTokens.nextToken()).intValue();
          // FIXME               pane.setMaxTableLimits(nBranchCount,nTellerCount,nAccountCount);
          // FIXME               pane.doCreateTables(true,true,true,true,true,true,true,true);
        }
        // FIXME            if(strCreateProc != null)
        // pane.doLoadProcedures(pane.pool.getConnection(0));
        if (strRunTests != null) {
          int nNumThreads = 1, nNumRuns = 100, nTestType = 1, nWaitMinutes = -1;
          boolean bTrans = false, bQuery = true;
          StringTokenizer runTokens = new StringTokenizer(strRunTests, ",;/");
          if (runTokens.hasMoreTokens())
            nNumThreads = Integer.valueOf(runTokens.nextToken()).intValue();
          if (runTokens.hasMoreTokens())
            nNumRuns = Integer.valueOf(runTokens.nextToken()).intValue();
          if (runTokens.hasMoreTokens())
            bTrans = runTokens.nextToken().toUpperCase().equals("TRUE");
          if (runTokens.hasMoreTokens())
            bQuery = runTokens.nextToken().toUpperCase().equals("TRUE");
          if (runTokens.hasMoreTokens())
            nTestType = Integer.valueOf(runTokens.nextToken()).intValue();
          if (runTokens.hasMoreTokens())
            nWaitMinutes = Integer.valueOf(runTokens.nextToken()).intValue();
          // FIXME               pane.doRunTests(nNumThreads,nNumRuns,nWaitMinutes,nTestType ==
          // 1,nTestType == 2,nTestType == 3,bTrans,bQuery);
        }
        // FIXME            if(strCleanUp != null) pane.doCleanUp(pane.pool.getConnection(0),
        // true,true,true,true);
        if (strDropResult != null) pane.doDropResult();
        // FIXME            if(strCreateResult != null) pane.doCreateResult();
        // ========TPCCTest
        //            if(strTPCCLoad != null) {
        //               int n_ware = 1;
        //               StringTokenizer runTokens = new StringTokenizer(strTPCCLoad,",;/");
        //               //					System.out.println("tpcload = " + strTPCCLoad);
        //               if(runTokens.hasMoreTokens()) {
        //                  n_ware = Integer.valueOf(runTokens.nextToken()).intValue();
        //               //						System.out.println("N_ware = " + n_ware);
        //               }
        //               pane.doTpccLoadData(pane.pool.getConnection(0),
        // n_ware,Bench.TPCCBench.DIST_PER_WARE,Bench.TPCCBench.CUST_PER_DIST,Bench.TPCCBench.MAXITEMS,Bench.TPCCBench.ORD_PER_DIST);
        //            }
        //            if(strTPCCRun != null) {
        //               int n_rounds = 1, local_w_id = 1, n_ware = 1, n_threads = 1;
        //               StringTokenizer runTokens = new StringTokenizer(strTPCCRun,",;/");
        //               if(runTokens.hasMoreTokens())
        //                  n_rounds = Integer.valueOf(runTokens.nextToken()).intValue();
        //               if(runTokens.hasMoreTokens())
        //                  local_w_id = Integer.valueOf(runTokens.nextToken()).intValue();
        //               if(runTokens.hasMoreTokens())
        //                  n_ware = Integer.valueOf(runTokens.nextToken()).intValue();
        //               if(runTokens.hasMoreTokens())
        //                  n_threads = Integer.valueOf(runTokens.nextToken()).intValue();
        //               pane.doTpccRun(n_threads, n_rounds,local_w_id,n_ware);
        //            }
        pane.closeConnection(true);
        System.exit(0);
      }
    } catch (Exception e) {
      System.out.println(e.getMessage());
    }
    // go interactive
    JFrame frame = new JFrame("JBench - Generic JDBC Benchmark Utility");
    WindowListener l =
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            BenchMain.bench.m_pane.closeConnection(true);
            System.exit(0);
          }
        };

    frame.addWindowListener(l);
    bench.m_parentFrame = frame;
    bench.init();
    frame.getContentPane().add(bench);
    frame.setSize(675, 400);
    frame.validate();
    frame.setVisible(true);
  }