jaxb-workshop
  1. jaxb-workshop
  2. JAXB_WORKSHOP-4

Capturing output of Main.compile of tools.jar

    Details

    • Type: Task Task
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: current
    • Fix Version/s: Release 1.0
    • Component/s: xjc explorer
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

    • Issuezilla Id:
      4

      Description

      Try see if it is possible to capture the regular and warning messages of javac
      compiler when it is activated via Main.compile of tools.jar. If this is
      possible, the failure message of the compilation must be shown along
      "Compilation failed" message in JOptionPane.

        Activity

        Hide
        kirillcool added a comment -

        Moved to appropriate component

        Show
        kirillcool added a comment - Moved to appropriate component
        Hide
        kirillcool added a comment -

        The static initializer of Workspace was changed to
        javac = toolsJarLoader.loadClass("com.sun.tools.javac.Main")
        .getMethod("compile", new Class[]

        { String[].class, PrintWriter.class }

        );

        The function compileAll() now gets a LinkedList<String> parameter and fills it
        with compilation messages:
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        long time0 = System.currentTimeMillis();
        int compileReturnCode = ((Integer) Workspace.javac.invoke(null,
        new Object[]

        { allFileNames, new PrintWriter(baos) }

        ))
        .intValue();
        // com.sun.tools.javac.Main.compile(allFileNames);
        long time1 = System.currentTimeMillis();
        BufferedReader br = new BufferedReader(new InputStreamReader(
        new ByteArrayInputStream(baos.toByteArray())));
        while (true)

        { String str = br.readLine(); if (str == null) break; this._logger.info("/javac/ " + str); compilerMessages.addLast(str); }

        These messages are then shown in MessageListDialog, a new class that was created
        in order to show a list of messages (as well as a stack trace of a Throwable):

        LinkedList<String> compilerMessages = new LinkedList<String>();
        boolean compileSucceeded = this.compileAll(classInfoList,
        compilerMessages);
        if (!compileSucceeded)

        { MessageListDialog.showMessageDialog(mainFrame, "Compilation failed", compilerMessages); return; }
        Show
        kirillcool added a comment - The static initializer of Workspace was changed to javac = toolsJarLoader.loadClass("com.sun.tools.javac.Main") .getMethod("compile", new Class[] { String[].class, PrintWriter.class } ); The function compileAll() now gets a LinkedList<String> parameter and fills it with compilation messages: ByteArrayOutputStream baos = new ByteArrayOutputStream(); long time0 = System.currentTimeMillis(); int compileReturnCode = ((Integer) Workspace.javac.invoke(null, new Object[] { allFileNames, new PrintWriter(baos) } )) .intValue(); // com.sun.tools.javac.Main.compile(allFileNames); long time1 = System.currentTimeMillis(); BufferedReader br = new BufferedReader(new InputStreamReader( new ByteArrayInputStream(baos.toByteArray()))); while (true) { String str = br.readLine(); if (str == null) break; this._logger.info("/javac/ " + str); compilerMessages.addLast(str); } These messages are then shown in MessageListDialog, a new class that was created in order to show a list of messages (as well as a stack trace of a Throwable): LinkedList<String> compilerMessages = new LinkedList<String>(); boolean compileSucceeded = this.compileAll(classInfoList, compilerMessages); if (!compileSucceeded) { MessageListDialog.showMessageDialog(mainFrame, "Compilation failed", compilerMessages); return; }

          People

          • Assignee:
            kirillcool
            Reporter:
            kirillcool
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: