Example #1
0
 public static void log(String text) {
   basicOpenConsole();
   MessageConsole myConsole = findConsole(SQLPLUS_CONSOLE_VIEW);
   MessageConsoleStream out = myConsole.newMessageStream();
   out.println(text);
   buffer = buffer + text;
 }
  private static MessageConsoleStream createConsoleStream() {

    MessageConsole console = new MessageConsole("Annotations Search Results", null);
    console.activate();
    ConsolePlugin consolePlugin = ConsolePlugin.getDefault();
    consolePlugin.getConsoleManager().addConsoles(new IConsole[] {console});
    MessageConsoleStream messageStream = console.newMessageStream();
    return messageStream;
  }
  public void writeToShell(String serverId, String[] lines) {
    MessageConsole myConsole = findConsole(serverId);
    MessageConsoleStream out = myConsole.newMessageStream();
    for (int i = 0; i < lines.length; i++) out.println(lines[i]);

    ConsolePlugin plugin = ConsolePlugin.getDefault();
    IConsoleManager conMan = plugin.getConsoleManager();
    conMan.showConsoleView(myConsole);
  }
Example #4
0
  private SimpleLogger() {
    MessageConsole console = new MessageConsole("System Output", null); // $NON-NLS-1$
    ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[] {console});
    ConsolePlugin.getDefault().getConsoleManager().showConsoleView(console);
    MessageConsoleStream stream = console.newMessageStream();

    System.setOut(new PrintStream(stream));
    System.setErr(new PrintStream(stream));
  }
 private static MessageConsoleStream getConsoleStreamBlue() {
   if (out_blue == null) {
     Color color_blue = PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_BLUE);
     MessageConsole console = getRhinoConsole();
     if (console == null) return null;
     out_blue = console.newMessageStream();
     out_blue.setColor(color_blue);
   }
   return out_blue;
 }
 private static MessageConsoleStream getConsoleStreamRed() {
   if (out_red == null) {
     Color color_red = PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_RED);
     MessageConsole console = getRhinoConsole();
     if (console == null) return null;
     out_red = console.newMessageStream();
     out_red.setColor(color_red);
   }
   return out_red;
 }
Example #7
0
 @Override
 public void start(BundleContext context) throws Exception {
   console = new MessageConsole("Terracotta build system", null);
   final Device device = console.getFont() != null ? console.getFont().getDevice() : null;
   initStream(ConsoleStream.DEFAULT, device, BLACK);
   initStream(ConsoleStream.STDOUT, device, BLUE);
   initStream(ConsoleStream.STDERR, device, RED);
   final IConsoleManager mgr = ConsolePlugin.getDefault().getConsoleManager();
   mgr.addConsoles(new IConsole[] {console});
   super.start(context);
 }
  public ConsoleLogger() {
    console = findConsole(CONSOLE_IDENTIFIER);
    consoleOutput = new BufferedWriter(new OutputStreamWriter(console.newOutputStream()));

    try {
      console.clearConsole();
      addTitle(consoleOutput);
    } catch (IOException e) {
      throw new RuntimeException("Unable to write to console.", e);
    }
  }
  protected void onBeforeStartJob() {
    // Get the console
    final MessageConsole console = Utils.findConsole("ocarina");
    console.addPatternMatchListener(new AadlFilenamePatternMatchListener());
    console.clearConsole();

    if (automaticallyShowConsole) {
      showConsole();
    }

    // Create and configure streams
    this.out = console.newMessageStream();
    this.err = console.newMessageStream();
    this.err.setColor(new Color(Display.getCurrent(), 255, 0, 0));
  }
Example #10
0
 public void createConsoleStream() {
   // 出力コンソールの用意
   console = new MessageConsole("キーワードプログラミング", null);
   consoleManager = ConsolePlugin.getDefault().getConsoleManager();
   consoleManager.addConsoles(new IConsole[] {console});
   consoleStream = console.newMessageStream();
 }
  public EclipseAppender() {

    if (myConsole == null || out == null) {
      myConsole = findConsole(CONSOLE_NAME);
      out = myConsole.newMessageStream();
      out.println("=============== Wellcome to Zathuracode is Cool ===============");
    } else {
      System.out.println("Zathuracode EclipseAppender: The Eclipse Console was not finded");
    }
  }
 MessageConsoleStream createMessageStream(final int color) {
   final MessageConsoleStream stream = console.newMessageStream();
   Display.getDefault()
       .syncExec(
           new Runnable() {
             @Override
             public void run() {
               stream.setColor(PlatformUI.getWorkbench().getDisplay().getSystemColor(color));
             }
           });
   return stream;
 }
  // print to stream, lazily instantiating and opening console if necessary
  private void print(final LoggingEvent event) {
    // ensure in UI thread
    assert Display.getCurrent() != null;

    // ensure console view is open
    if (WorkbenchUtil.getView(IConsoleConstants.ID_CONSOLE_VIEW) == null) {
      try {
        IWorkbenchPage activePage = WorkbenchUtil.getActivePage();
        if (activePage != null) {
          activePage.showView(IConsoleConstants.ID_CONSOLE_VIEW);
        }
      } catch (PartInitException pie) {
        // ignore for now
      }
    }

    // lazily instantiate console if necessary
    if (_consoleStream == null) {
      IConsoleManager mgr = ConsolePlugin.getDefault().getConsoleManager();
      MessageConsole logConsole =
          new MessageConsole(
              Activator.getResourceString("MessageConsoleAppender.Log"), // $NON-NLS-1$
              null);
      mgr.addConsoles(new IConsole[] {logConsole});
      mgr.showConsoleView(logConsole);
      _consoleStream = logConsole.newMessageStream();
    }

    // print message
    _consoleStream.print(getLayout().format(event));
    if (getLayout().ignoresThrowable()) {
      String[] lines = event.getThrowableStrRep();
      if (lines != null) {
        for (String line : lines) {
          _consoleStream.println(line);
        }
      }
    }
  }
  @Override
  public void launch(
      ILaunchConfiguration config, String mode, ILaunch launch, IProgressMonitor monitor)
      throws CoreException {
    try {
      ConfigUtils configUtils = new ConfigUtils(config);
      project = configUtils.getProject();
      // check if Perf exists in $PATH
      if (!PerfCore.checkPerfInPath(project)) {
        IStatus status =
            new Status(
                IStatus.ERROR,
                PerfPlugin.PLUGIN_ID,
                "Error: Perf was not found on PATH"); //$NON-NLS-1$
        throw new CoreException(status);
      }
      URI binURI = new URI(configUtils.getExecutablePath());
      binPath = Path.fromPortableString(binURI.toString());
      workingDirPath =
          Path.fromPortableString(
              Path.fromPortableString(binURI.toString()).removeLastSegments(2).toPortableString());
      PerfPlugin.getDefault().setWorkingDir(workingDirPath);
      if (config.getAttribute(PerfPlugin.ATTR_ShowStat, PerfPlugin.ATTR_ShowStat_default)) {
        showStat(config, launch);
      } else {
        URI exeURI = new URI(configUtils.getExecutablePath());
        String configWorkingDir = configUtils.getWorkingDirectory() + IPath.SEPARATOR;
        RemoteConnection exeRC = new RemoteConnection(exeURI);
        String perfPathString =
            RuntimeProcessFactory.getFactory().whichCommand(PerfPlugin.PERF_COMMAND, project);
        boolean copyExecutable = configUtils.getCopyExecutable();
        if (copyExecutable) {
          URI copyExeURI = new URI(configUtils.getCopyFromExecutablePath());
          RemoteConnection copyExeRC = new RemoteConnection(copyExeURI);
          IRemoteFileProxy copyExeRFP = copyExeRC.getRmtFileProxy();
          IFileStore copyExeFS = copyExeRFP.getResource(copyExeURI.getPath());
          IRemoteFileProxy exeRFP = exeRC.getRmtFileProxy();
          IFileStore exeFS = exeRFP.getResource(exeURI.getPath());
          IFileInfo exeFI = exeFS.fetchInfo();
          if (exeFI.isDirectory()) {
            // Assume the user wants to copy the file to the given directory, using
            // the same filename as the "copy from" executable.
            IPath copyExePath = Path.fromOSString(copyExeURI.getPath());
            IPath newExePath =
                Path.fromOSString(exeURI.getPath()).append(copyExePath.lastSegment());
            // update the exeURI with the new path.
            exeURI =
                new URI(
                    exeURI.getScheme(),
                    exeURI.getAuthority(),
                    newExePath.toString(),
                    exeURI.getQuery(),
                    exeURI.getFragment());
            exeFS = exeRFP.getResource(exeURI.getPath());
          }
          copyExeFS.copy(exeFS, EFS.OVERWRITE | EFS.SHALLOW, new SubProgressMonitor(monitor, 1));
          // Note: assume that we don't need to create a new exeRC since the
          // scheme and authority remain the same between the original exeURI and the new one.
        }
        IPath remoteBinFile = Path.fromOSString(exeURI.getPath());
        IFileStore workingDir;
        URI workingDirURI =
            new URI(RemoteProxyManager.getInstance().getRemoteProjectLocation(project));
        RemoteConnection workingDirRC = new RemoteConnection(workingDirURI);
        IRemoteFileProxy workingDirRFP = workingDirRC.getRmtFileProxy();
        workingDir = workingDirRFP.getResource(workingDirURI.getPath());
        // Build the commandline string to run perf recording the given project
        String arguments[] = getProgramArgumentsArray(config); // Program args from launch config.
        ArrayList<String> command = new ArrayList<>(4 + arguments.length);
        Version perfVersion = PerfCore.getPerfVersion(config);
        command.addAll(
            Arrays.asList(
                PerfCore.getRecordString(
                    config,
                    perfVersion))); // Get the base commandline string (with flags/options based on
                                    // config)
        command.add(remoteBinFile.toOSString()); // Add the path to the executable
        command.set(0, perfPathString);
        command.add(2, OUTPUT_STR + configWorkingDir + PerfPlugin.PERF_DEFAULT_DATA);
        // Compile string
        command.addAll(Arrays.asList(arguments));

        // Spawn the process
        String[] commandArray = command.toArray(new String[command.size()]);
        Process pProxy =
            RuntimeProcessFactory.getFactory()
                .exec(commandArray, getEnvironment(config), workingDir, project);
        MessageConsole console = new MessageConsole("Perf Console", null); // $NON-NLS-1$
        console.activate();
        ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[] {console});
        MessageConsoleStream stream = console.newMessageStream();

        if (pProxy != null) {
          try (BufferedReader error =
              new BufferedReader(new InputStreamReader(pProxy.getErrorStream()))) {
            String err = error.readLine();
            while (err != null) {
              stream.println(err);
              err = error.readLine();
            }
          }
        }

        /* This commented part is the basic method to run perf record without integrating into eclipse.
        String binCall = exePath.toOSString();
        for(String arg : arguments) {
            binCall.concat(" " + arg);
        }
        PerfCore.Run(binCall);*/

        pProxy.destroy();
        PrintStream print = null;
        if (config.getAttribute(IDebugUIConstants.ATTR_CAPTURE_IN_CONSOLE, true)) {
          // Get the console to output to.
          // This may not be the best way to accomplish this but it shall do for now.
          ConsolePlugin plugin = ConsolePlugin.getDefault();
          IConsoleManager conMan = plugin.getConsoleManager();
          IConsole[] existing = conMan.getConsoles();
          IOConsole binaryOutCons = null;

          // Find the console
          for (IConsole x : existing) {
            if (x.getName().contains(renderProcessLabel(commandArray[0]))) {
              binaryOutCons = (IOConsole) x;
            }
          }
          if ((binaryOutCons == null)
              && (existing.length
                  != 0)) { // if can't be found get the most recent opened, this should probably
                           // never happen.
            if (existing[existing.length - 1] instanceof IOConsole)
              binaryOutCons = (IOConsole) existing[existing.length - 1];
          }

          // Get the printstream via the outputstream.
          // Get ouput stream
          OutputStream outputTo;
          if (binaryOutCons != null) {
            outputTo = binaryOutCons.newOutputStream();
            // Get the printstream for that console
            print = new PrintStream(outputTo);
          }

          for (int i = 0; i < command.size(); i++) {
            print.print(command.get(i) + " "); // $NON-NLS-1$
          }

          // Print Message
          print.println();
          print.println("Analysing recorded perf.data, please wait..."); // $NON-NLS-1$
          // Possibly should pass this (the console reference) on to PerfCore.Report if theres
          // anything we ever want to spit out to user.
        }
        PerfCore.report(
            config,
            getEnvironment(config),
            Path.fromOSString(configWorkingDir),
            monitor,
            null,
            print);

        URI perfDataURI = null;
        IRemoteFileProxy proxy = null;
        perfDataURI =
            new URI(
                RemoteProxyManager.getInstance().getRemoteProjectLocation(project)
                    + PerfPlugin.PERF_DEFAULT_DATA);
        proxy = RemoteProxyManager.getInstance().getFileProxy(perfDataURI);
        IFileStore perfDataFileStore = proxy.getResource(perfDataURI.getPath());
        IFileInfo info = perfDataFileStore.fetchInfo();
        info.setAttribute(EFS.ATTRIBUTE_READ_ONLY, true);
        perfDataFileStore.putInfo(info, EFS.SET_ATTRIBUTES, null);

        PerfCore.refreshView(renderProcessLabel(exeURI.getPath()));
        if (config.getAttribute(
            PerfPlugin.ATTR_ShowSourceDisassembly, PerfPlugin.ATTR_ShowSourceDisassembly_default)) {
          showSourceDisassembly(
              Path.fromPortableString(workingDirURI.toString() + IPath.SEPARATOR));
        }
      }
    } catch (IOException e) {
      e.printStackTrace();
      abort(e.getLocalizedMessage(), null, ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR);
    } catch (RemoteConnectionException e) {
      e.printStackTrace();
      abort(e.getLocalizedMessage(), null, ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR);
    } catch (URISyntaxException e) {
      e.printStackTrace();
      abort(e.getLocalizedMessage(), null, ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR);
    }
  }
 /** Static instanciation block */
 static {
   console = new MessageConsole(Messages.CONSOLE_NAME.message(), null);
   ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[] {console});
   console.activate();
 }
 private void clearConsole() {
   console.clearConsole();
 }
  @Override
  public void launch(
      ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor)
      throws CoreException {
    try {
      this.launch = launch;
      cleanup();

      final MitraLaunchConfigurationAdapter configAdapter =
          new MitraLaunchConfigurationAdapter(configuration);

      String consoleName = "Mitra Interpreter [" + configAdapter.getName() + "] " + mode;
      console = findConsole(consoleName);
      console.activate();
      initConsoleStream();

      clearConsole();

      final StandaloneExecutor executor =
          MitraStandaloneLaunchFactory.createExecutor(configAdapter);
      executor.getProjectContext().setMessageAcceptor(new ConsoleMessageAcceptor(console));

      console.addPatternMatchListener(new MitraConsoleTracker(executor.getProjectContext()));

      executor.getProjectContext().out = new PrintStream(createMessageStream(SWT.COLOR_BLACK));

      PrintStream err = new PrintStream(createMessageStream(SWT.COLOR_RED));
      executor.getProjectContext().err = err;

      executor.getProjectContext().log = new PrintStream(createMessageStream(SWT.COLOR_BLUE));

      try {
        executor.prepareInterpreter();
      } catch (Exception ex) {
        throw new CoreException(
            new Status(
                IStatus.ERROR,
                MitraDebugPlugin.PLUGIN_ID,
                "Error preparing Mitra interpreter: " + ex.getMessage(),
                ex));
      }

      executor
          .getDebugable()
          .addInterpreterListener(
              new IDebugableListener() {

                @Override
                public void terminated() {

                  out("Mitra interpreter terminated.");
                  try {
                    for (String fileName : configAdapter.getOutputModelFilenames().values()) {
                      URI uri = URI.createFileURI(fileName);
                      refreshPath(uri);
                    }
                    for (String fileName : configAdapter.getInputModelFilenames().values()) {
                      URI uri = URI.createFileURI(fileName);
                      refreshPath(uri);
                    }
                    if (configAdapter.isSaveTraces()) {
                      URI uri = URI.createFileURI(configAdapter.getTraceModelFilename());
                      refreshPath(uri);
                    }
                  } catch (CoreException ex) {
                    out("Error refreshing project path: " + ex);
                  }
                }

                @Override
                public void processDebugableEvent(DebugEventType eventType) {
                  // not interested in
                }

                @Override
                public void suspended() {
                  // not interested in
                }
              });

      ResourceSet rs = executor.getProjectContext().getResourceSet();
      int errorCount = 0;
      int warningCount = 0;
      int moduleCount = 0;
      // iterate over copy, as new resources may be
      // added while resolving proxies
      List<Resource> resources = new ArrayList<Resource>(rs.getResources());
      for (Resource resource : resources) {
        errorCount += resource.getErrors().size();
        warningCount += resource.getWarnings().size();

        if (resource.getContents().size() > 0) {
          for (EObject model : resource.getContents()) {

            if (model instanceof Module) {
              moduleCount++;
            }
            Diagnostic diagnostic = Diagnostician.INSTANCE.validate(model);
            for (Diagnostic child : diagnostic.getChildren()) {
              switch (child.getSeverity()) {
                case Diagnostic.ERROR:
                  if (!(model instanceof Module)) {
                    err.println(model.eResource().getURI() + ": " + child.getMessage());
                  }
                  errorCount++;
                  break;
                case Diagnostic.WARNING:
                  warningCount++;
              }
            }
          }
        }
      }

      MessageFormat form = new MessageFormat("Loaded {0}{1}, {2}.");
      double[] limits = {0, 1, 2};
      String[] moduleparts = {"no module", "1 module", "{0,number} modules"};
      ChoiceFormat moduleform = new ChoiceFormat(limits, moduleparts);
      form.setFormatByArgumentIndex(0, moduleform);
      String[] errorparts = {" successfully: 0 errors", ": 1 error", ": {1,number} errors"};
      ChoiceFormat errorform = new ChoiceFormat(limits, errorparts);
      form.setFormatByArgumentIndex(1, errorform);
      String[] warningparts = {"0 warnings", "1 warning", "{2,number} warnings"};
      ChoiceFormat warningform = new ChoiceFormat(limits, warningparts);
      form.setFormatByArgumentIndex(2, warningform);

      String msg = form.format(new Object[] {moduleCount, errorCount, warningCount});
      if (errorCount > 0) {
        msg += " Cannot start Mitra intpreter.";
      }
      out(msg);
      if (errorCount > 0 || moduleCount == 0) {
        throw new CoreException(new Status(IStatus.ERROR, MitraDebugPlugin.PLUGIN_ID, msg));
      }

      IDebuggable debugable = executor.getDebugable(); // debugable
      // supports
      // listeners!

      if (debugable == null) {
        throw new CoreException(
            new Status(
                IStatus.ERROR, MitraDebugPlugin.PLUGIN_ID, "No debuggable interpreter prepared."));
      }

      RuleDeclaration decl = debugable.getCalledRule();

      if (decl == null) {
        throw new CoreException(
            new Status(IStatus.ERROR, MitraDebugPlugin.PLUGIN_ID, "No rule selected."));
      }
      IDebugTarget debugTarget =
          new MitraDebugTarget(
              launch, new MitraDebugProxy(debugable), decl.eResource().getURI().toFileString());

      Display display = Display.getCurrent();
      if (display == null) { // start in normal thread
        if (log.isLoggable(Level.INFO)) {
          log.info("Start mitra interpreter via new thread");
        }
        out("Start Mitra interpreter on new thread");

        Thread interpreterThread = new Thread(debugable);
        if (mode.equals(ILaunchManager.DEBUG_MODE)) {
          debugable.enableDebug(true);
          interpreterThread.setName("MitraInterpreter");
          interpreterThread.start();
          launch.addDebugTarget(debugTarget);
        } else {
          interpreterThread.start();
        }
      } else { // start via display
        if (log.isLoggable(Level.INFO)) {
          log.info("Start mitra interpreter via display.asyncExec");
        }
        out("Start Mitra interpreter on display thread");

        if (mode.equals(ILaunchManager.DEBUG_MODE)) {
          debugable.enableDebug(true);
          display.asyncExec(debugable);
          // interpreterThread.setName("MitraInterpreter");
          // interpreterThread.start();
          launch.addDebugTarget(debugTarget);
        } else {
          display.asyncExec(debugable);
        }
      }
      out("Interpreter running...");
    } finally {
      console = null;
    }
  }
 /** Activate the Console in the selected perspective */
 public static void show() {
   console.activate();
 }
Example #19
0
 private void initStream(final ConsoleStream consoleStream, final Device device, final RGB rgb) {
   consoleStream.color = new Color(device, rgb);
   consoleStream.stream = console.newMessageStream();
   consoleStream.stream.setActivateOnWrite(true);
   consoleStream.stream.setColor(consoleStream.color);
 }
Example #20
0
  @Override
  public void performFullBuild(IFile config) {
    if (!isPluginInstalled(PLUGIN_ID_XTEXT)) {
      generateWarning(PLUGIN_WARNING_XTEXT);
      return;
    }
    if (!isPluginInstalled(PLUGIN_ID_XTYPES)) {
      generateWarning(PLUGIN_WARNING_XTYPES);
      return;
    }
    // init console
    MessageConsole console = new MessageConsole("DeltaJ Error Log", null);
    console.activate();
    ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[] {(IConsole) console});
    consoleMessageStream = console.newMessageStream();

    // initialization
    this.errors = 0;
    this.errorReport = "";
    boolean ioError = false;
    this.outputPath = this.featureProject.getBuildPath().replace('\\', '/') + "/";
    this.configName = config.getName().split("\\.")[0];
    this.spl = new DeltajSPLDefinition();
    IFolder sourceFolder = featureProject.getSourceFolder();
    this.featureModel = featureProject.getFeatureModel();
    this.spl.setName(this.featureModel.getRoot().getName());

    // get all features
    this.spl.addAllFeatures(this.featureModel.getConcreteFeatures());

    // get deltas specification
    this.spl.setDeltas(parseApplicationRules());

    // get current configuration
    Configuration configuration = new Configuration(this.featureModel);
    ConfigurationReader reader = new ConfigurationReader(configuration);
    try {
      reader.readFromFile(config);
    } catch (CoreException e) {
      DeltajCorePlugin.getDefault().logError(e);
    } catch (IOException e) {
      DeltajCorePlugin.getDefault().logError(e);
    }

    // collect all deltaj files of selected features
    String composedDeltas = "";
    deltajFiles = new ArrayList<DeltajFile>();
    composedDeltas += composeAllFileContents(sourceFolder);
    composedDeltas += this.spl.toString();
    composedDeltas += this.createProductDefinition(configuration);

    IFile tmpFile =
        featureProject
            .getProject()
            .getFile(featureProject.getBuildFolder().getName() + "/tmp" + DeltajComposer.FILE_EXT);
    InputStream in = new ByteArrayInputStream(composedDeltas.getBytes());
    try {
      tmpFile.create(in, false, null);
    } catch (CoreException e) {
      DeltajCorePlugin.getDefault().logError(e);
    }

    // compile
    compileResource(tmpFile.getFullPath().toString());

    // cleanup
    try {
      tmpFile.delete(false, null);
    } catch (CoreException e) {
      DeltajCorePlugin.getDefault().logError(e);
    }

    // print errors

    if (!issueList.isEmpty()) {
      for (Issue issue : issueList) {
        printError(issue);
      }
    }
    consoleMessageStream.print(
        "DeltaJ Files compiled with " + this.errors + (this.errors == 1 ? " error" : " errors"));
    if (this.errors != 0 || ioError) {
      this.errorReport += "\n" + this.errors + " compile errors";
      System.out.println(this.errorReport);
    }
  }