Package se.sics.cooja.dialogs

Examples of se.sics.cooja.dialogs.MessageList


            "Error during main source file generation: " + e.getMessage())
            .initCause(e);
      }

      // Compile library
      MessageList taskOutput = new MessageList();
      boolean compilationSucceded = ContikiMoteTypeDialog.compileLibrary(
          identifier, new File(contikiBaseDir), compilationFiles,
          hasSystemSymbols, commStack, taskOutput
              .getInputStream(MessageList.NORMAL), taskOutput
              .getInputStream(MessageList.ERROR));
      if (!libFile.exists()) {
        MoteTypeCreationException ex = new MoteTypeCreationException(
        "Compilation error: " + libFile.getPath() + " does not exist");
        ex.setCompilationOutput(taskOutput);
View Full Code Here


    JPanel progressPanel = new JPanel(new BorderLayout());
    final JDialog progressDialog = new JDialog(myDialog, (String) null);
    JProgressBar progressBar;
    JButton button;
    final MessageList taskOutput;
    progressDialog.setLocationRelativeTo(myDialog);

    progressBar = new JProgressBar(0, 100);
    progressBar.setValue(0);
    progressBar.setStringPainted(true);
    progressBar.setIndeterminate(true);

    taskOutput = new MessageList();

    final Thread compilationThreadCopy = compilationThread;
    button = new JButton("Close/Abort");
    button.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        if (compilationThreadCopy != null && compilationThreadCopy.isAlive()) {
          compilationThreadCopy.interrupt();
        }
        if (progressDialog != null && progressDialog.isDisplayable()) {
          progressDialog.dispose();
        }
      }
    });

    final JPopupMenu popup = new JPopupMenu();
    JMenuItem headerMenuItem = new JMenuItem("Compilation output:");
    headerMenuItem.setEnabled(false);
    popup.add(headerMenuItem);
    popup.add(new JSeparator());

    JMenuItem consoleOutputMenuItem = new JMenuItem("Output to console");
    consoleOutputMenuItem.setEnabled(true);
    consoleOutputMenuItem.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        int nrRows = taskOutput.getModel().getSize();
        System.out.println("\nCOMPILATION OUTPUT:\n");
        for (int n=0; n < nrRows; n++) {
          System.out.println(taskOutput.getModel().getElementAt(n));
        }
        System.out.println();
      }
    });
    popup.add(consoleOutputMenuItem);

    JMenuItem clipboardMenuItem = new JMenuItem("Copy to clipboard");
    clipboardMenuItem.setEnabled(true);
    clipboardMenuItem.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();

        String output = "";
        int nrRows = taskOutput.getModel().getSize();
        for (int n=0; n < nrRows; n++) {
          output += taskOutput.getModel().getElementAt(n) + "\n";
        }

        StringSelection stringSelection = new StringSelection(output);
        clipboard.setContents(stringSelection, null);

        logger.info("Output copied to clipboard");
      }
    });
    popup.add(clipboardMenuItem);

    taskOutput.addMouseListener(new MouseAdapter() {
      public void mouseClicked(MouseEvent e) {
        if (e.isPopupTrigger() || SwingUtilities.isRightMouseButton(e)) {
          popup.show(taskOutput, e.getX(), e.getY());
        }
      }
    });

    progressPanel.add(BorderLayout.CENTER, new JScrollPane(taskOutput));
    progressPanel.add(BorderLayout.NORTH, progressBar);
    progressPanel.add(BorderLayout.SOUTH, button);
    progressPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
    progressPanel.setVisible(true);

    progressDialog.getContentPane().add(progressPanel);
    progressDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    progressDialog.pack();

    progressDialog.getRootPane().setDefaultButton(button);
    progressDialog.setVisible(true);

    // Create temp output directory if not already exists
    if (!ContikiMoteType.tempOutputDirectory.exists()) {
      ContikiMoteType.tempOutputDirectory.mkdir();
    }

    // Parse selected sensors
    Vector<String> sensors = new Vector<String>();
    for (Component checkBox : sensorPanel.getComponents()) {
      if (((JCheckBox) checkBox).isSelected()) {
        sensors.add(((JCheckBox) checkBox).getText());
      }
    }

    // Parse selected core interfaces
    Vector<String> coreInterfaces = new Vector<String>();
    for (Component checkBox : coreInterfacePanel.getComponents()) {
      if (((JCheckBox) checkBox).isSelected()) {
        coreInterfaces.add(((JCheckBox) checkBox).getText());
      }
    }

    // Parse selected user processes
    Vector<String> userProcesses = new Vector<String>();
    for (Component checkBox : processPanel.getComponents()) {
      if (((JCheckBox) checkBox).isSelected()) {
        userProcesses.add(((JCheckBox) checkBox).getText());
      }
    }

    // Generate main contiki source file
    String filename = null;
    try {
      filename = generateSourceFile(textID.getText(), sensors, coreInterfaces,
          userProcesses);
    } catch (Exception e) {
      libraryCreatedOK = false;
      progressBar.setBackground(Color.ORANGE);
      progressBar.setString(e.getMessage());
      progressBar.setIndeterminate(false);
      progressBar.setValue(0);
      createButton.setEnabled(libraryCreatedOK);
      return;
    }

    // Test compile shared library
    progressBar.setString("..compiling..");
    final File contikiDir = new File(textContikiDir.getText());
    final String identifier = textID.getText();
    File libFile = new File(ContikiMoteType.tempOutputDirectory,
        identifier + ContikiMoteType.librarySuffix);
    File mapFile = new File(ContikiMoteType.tempOutputDirectory,
        identifier + ContikiMoteType.mapSuffix);
    File depFile = new File(ContikiMoteType.tempOutputDirectory,
        identifier + ContikiMoteType.dependSuffix);

    if (libFile.exists()) {
      libFile.delete();
    }

    if (depFile.exists()) {
      depFile.delete();
    }

    if (mapFile.exists()) {
      mapFile.delete();
    }

    compilationThread = new Thread(new Runnable() {
      public void run() {
        // Add all project directories
        compilationFiles = (Vector<File>) myGUI
            .getProjectDirs().clone();


        if (moteTypeProjectDirs == null || moteTypeProjectDirs.isEmpty()) {
          compilationFiles.add(new File(textCoreDir.getText(), "testapps"));
        } else {
          compilationFiles.addAll(moteTypeProjectDirs);
        }

        // Add source files from project configs
        String[] projectSourceFiles = newMoteTypeConfig.getStringArrayValue(
            ContikiMoteType.class, "C_SOURCES");
        for (String projectSourceFile : projectSourceFiles) {
          if (!projectSourceFile.equals("")) {
            File file = new File(projectSourceFile);
            if (file.getParent() != null) {
              // Find which project directory added this file
              File projectDir = newMoteTypeConfig.getUserProjectDefining(
                  ContikiMoteType.class, "C_SOURCES", projectSourceFile);
              if (projectDir != null) {
                // We found a project directory; add it to path
                compilationFiles.add(new File(projectDir.getPath(), file
                    .getParent()));
              }
            }
            compilationFiles.add(new File(file.getName()));
          }
        }

        // Add selected process source files
        for (Component checkBox : processPanel.getComponents()) {
          if (((JCheckBox) checkBox).isSelected()) {
            String fileName = ((JCheckBox) checkBox).getToolTipText();
            if (fileName != null) {
              compilationFiles.add(new File(fileName));
            }
          }
        }

        compilationSucceded = ContikiMoteTypeDialog.compileLibrary(identifier,
            contikiDir, compilationFiles, symbolsCheckBox.isSelected(),
            (ContikiMoteType.CommunicationStack) commStackComboBox.getSelectedItem(),
            taskOutput.getInputStream(MessageList.NORMAL),
            taskOutput.getInputStream(MessageList.ERROR));
      }
    }, "compilation thread");
    compilationThread.start();

    while (compilationThread.isAlive()) {
View Full Code Here

   * @throws MoteTypeCreationException
   *           If Java class compilation error occurs
   */
  private static void compileSourceFile(String className)
      throws MoteTypeCreationException {
    MessageList compilationOutput = new MessageList();
    OutputStream compilationStandardStream = compilationOutput
        .getInputStream(MessageList.NORMAL);
    OutputStream compilationErrorStream = compilationOutput
        .getInputStream(MessageList.ERROR);

    File classFile = new File("se/sics/cooja/corecomm/" + className + ".class");

    try {
View Full Code Here

    JPanel progressPanel = new JPanel(new BorderLayout());
    final JDialog progressDialog = new JDialog(myDialog, (String) null);
    JProgressBar progressBar;
    JButton button;
    final MessageList taskOutput;
    progressDialog.setLocationRelativeTo(myDialog);

    progressBar = new JProgressBar(0, 100);
    progressBar.setValue(0);
    progressBar.setStringPainted(true);
    progressBar.setIndeterminate(true);

    taskOutput = new MessageList();

    button = new JButton("Close/Abort");
    button.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        if (compilationThread != null && compilationThread.isAlive()) {
          compilationThread.interrupt();
        }
        if (progressDialog != null && progressDialog.isDisplayable())
          progressDialog.dispose();
      }
    });

    progressPanel.add(BorderLayout.CENTER, new JScrollPane(taskOutput));
    progressPanel.add(BorderLayout.NORTH, progressBar);
    progressPanel.add(BorderLayout.SOUTH, button);
    progressPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
    progressPanel.setVisible(true);

    progressDialog.getContentPane().add(progressPanel);
    progressDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    progressDialog.pack();

    progressDialog.getRootPane().setDefaultButton(button);
    progressDialog.setVisible(true);

    // Generate main mantis source file
    try {
      // Remove old file is existing
      if (srcFile.exists()) {
        srcFile.delete();
      }
     
      if (srcFile.exists()) {
        throw new Exception("could not remove old source file");
      }
     
      generateSourceFile(srcFile);
     
      if (!srcFile.exists()) {
        throw new Exception("source file not created");
      }
    } catch (Exception e) {
      libraryCreatedOK = false;
      progressBar.setBackground(Color.ORANGE);
      if (e.getMessage() != null)
        progressBar.setString("source file generation failed: " + e.getMessage());
      else
        progressBar.setString("source file generation failed");
        
      progressBar.setIndeterminate(false);
      progressBar.setValue(0);
      createButton.setEnabled(libraryCreatedOK);
      return;
    }
   
    // Test compile shared library
    progressBar.setString("..compiling..");

    if (libFile.exists()) {
      libFile.delete();
    }

    compilationThread = new Thread(new Runnable() {
      public void run() {
        compilationSucceded =
          MantisMoteTypeDialog.compileLibrary(
              libFile,
              objFile,
              srcFile,
              workingDir,
              taskOutput.getInputStream(MessageList.NORMAL),
              taskOutput.getInputStream(MessageList.ERROR));
      }
    }, "compilation thread");
    compilationThread.start();

    while (compilationThread.isAlive()) {
View Full Code Here

      boolean success = simulation.setConfigXML(arguments, false);
    } catch (Exception e) {
      logger.fatal("Error when configuring simulation: " + e);
      if (DEBUG_OUTPUT) {
        if (e instanceof MoteTypeCreationException) {
          MessageList compilationOutput = ((MoteTypeCreationException) e).getCompilationOutput();
          if (compilationOutput != null) {
            logger.info("Compilation output:");
            for(int i = 0; i < compilationOutput.getModel().getSize(); i++) {
              logger.info(compilationOutput.getModel().getElementAt(i));
            }
          }
          StackTraceElement[] stackTrace = e.getStackTrace();
          if (stackTrace != null) {
            logger.info("Stack trace:");
View Full Code Here

          /* Wait for compilation to end */
          try {
            compileProcess.waitFor();
          } catch (Exception e) {
            compilationOutput.addMessage(e.getMessage(), MessageList.ERROR);
            syncException.setCompilationOutput(new MessageList());
            syncException.fillInStackTrace();
            return;
          }

          /* Check return value */
          if (compileProcess.exitValue() != 0) {
            compilationOutput.addMessage("Process returned error code " + compileProcess.exitValue(), MessageList.ERROR);
            if (onFailure != null) {
              onFailure.actionPerformed(null);
            }
            syncException.setCompilationOutput(new MessageList());
            syncException.fillInStackTrace();
            return;
          }

          if (outputFile == null) {
            /* No firmware to generate: OK */
            if (onSuccess != null) {
              onSuccess.actionPerformed(null);
            }
            return;
          }

          if (!outputFile.exists()) {
            compilationOutput.addMessage("No firmware file: " + outputFile, MessageList.ERROR);
            if (onFailure != null) {
              onFailure.actionPerformed(null);
            }
            syncException.setCompilationOutput(new MessageList());
            syncException.fillInStackTrace();
            return;
          }

          compilationOutput.addMessage("", MessageList.NORMAL);
View Full Code Here

   * @throws MoteTypeCreationException
   *           If Java class compilation error occurs
   */
  public static void compileSourceFile(String className)
      throws MoteTypeCreationException {
    MessageList compilationOutput = new MessageList();
    OutputStream compilationStandardStream = compilationOutput
        .getInputStream(MessageList.NORMAL);
    OutputStream compilationErrorStream = compilationOutput
        .getInputStream(MessageList.ERROR);

    File classFile = new File("se/sics/cooja/corecomm/" + className + ".class");

    try {
View Full Code Here

        }
        Box buttonBox = Box.createHorizontalBox();

        if (exception != null) {
          /* Compilation output */
          MessageList compilationOutput = null;
          if (exception instanceof MoteTypeCreationException
              && ((MoteTypeCreationException) exception).hasCompilationOutput()) {
            compilationOutput = ((MoteTypeCreationException) exception).getCompilationOutput();
          } else if (exception.getCause() != null
              && exception.getCause() instanceof MoteTypeCreationException
              && ((MoteTypeCreationException) exception.getCause()).hasCompilationOutput()) {
            compilationOutput = ((MoteTypeCreationException) exception.getCause()).getCompilationOutput();
          }
          if (compilationOutput != null) {
            compilationOutput.addPopupMenuItem(null, true);
            tabbedPane.addTab("Compilation output", null, new JScrollPane(compilationOutput), null);
          }

          /* Stack trace */
          MessageList stackTrace = new MessageList();
          PrintStream printStream = stackTrace.getInputStream(MessageList.NORMAL);
          exception.printStackTrace(printStream);
          stackTrace.addPopupMenuItem(null, true);
          tabbedPane.addTab("Java stack trace", null, new JScrollPane(stackTrace), null);

          /* Exception message */
          buttonBox.add(Box.createHorizontalStrut(10));
          buttonBox.add(new JLabel(exception.getMessage()));
View Full Code Here

    /* Not visualized: Compile Contiki immediately */
    if (getIdentifier() == null) {
      throw new MoteTypeCreationException("No identifier");
    }

    final MessageList compilationOutput = new MessageList();

    if (getCompileCommands() != null) {
      /* Handle multiple compilation commands one by one */
      String[] arr = getCompileCommands().split("\n");
      for (String cmd: arr) {
        if (cmd.trim().isEmpty()) {
          continue;
        }

        try {
          CompileContiki.compile(
              cmd,
              null,
              null /* Do not observe output firmware file */,
              getContikiSourceFile().getParentFile(),
              null,
              null,
              compilationOutput,
              true
          );
        } catch (Exception e) {
          MoteTypeCreationException newException =
            new MoteTypeCreationException("Mote type creation failed: " + e.getMessage());
          newException = (MoteTypeCreationException) newException.initCause(e);
          newException.setCompilationOutput(compilationOutput);

          /* Print last 10 compilation errors to console */
          MessageContainer[] messages = compilationOutput.getMessages();
          for (int i=messages.length-10; i < messages.length; i++) {
            if (i < 0) {
              continue;
            }
            logger.fatal(">> " + messages[i]);
View Full Code Here

    /* Not visualized: Compile Contiki immediately */
    if (getIdentifier() == null) {
      throw new MoteTypeCreationException("No identifier");
    }

    final MessageList compilationOutput = new MessageList();

    if (getCompileCommands() != null) {
      /* Handle multiple compilation commands one by one */
      String[] arr = getCompileCommands().split("\n");
      for (String cmd: arr) {
        if (cmd.trim().isEmpty()) {
          continue;
        }

        try {
          CompileContiki.compile(
              cmd,
              null,
              null /* Do not observe output firmware file */,
              getContikiSourceFile().getParentFile(),
              null,
              null,
              compilationOutput,
              true
          );
        } catch (Exception e) {
          MoteTypeCreationException newException =
            new MoteTypeCreationException("Mote type creation failed: " + e.getMessage());
          newException = (MoteTypeCreationException) newException.initCause(e);
          newException.setCompilationOutput(compilationOutput);

          /* Print last 10 compilation errors to console */
          MessageContainer[] messages = compilationOutput.getMessages();
          for (int i=messages.length-10; i < messages.length; i++) {
            if (i < 0) {
              continue;
            }
            logger.fatal(">> " + messages[i]);
View Full Code Here

TOP

Related Classes of se.sics.cooja.dialogs.MessageList

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.