Search in sources :

Example 31 with IConsole

use of org.eclipse.ui.console.IConsole in project linuxtools by eclipse.

the class PerfLaunchConfigDelegate method launch.

@Override
public void launch(ILaunchConfiguration config, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
    try {
        ConfigUtils configUtils = new ConfigUtils(config);
        project = configUtils.getProject();
        // Set the current project that will be profiled
        PerfPlugin.getDefault().setProfiledProject(project);
        // check if Perf exists in $PATH
        if (!PerfCore.checkPerfInPath(project)) {
            // $NON-NLS-1$
            IStatus status = new Status(IStatus.ERROR, PerfPlugin.PLUGIN_ID, "Error: Perf was not found on PATH");
            throw new CoreException(status);
        }
        URI workingDirURI = new URI(config.getAttribute(RemoteProxyCMainTab.ATTR_REMOTE_WORKING_DIRECTORY_NAME, EMPTY_STRING));
        // Local project
        if (workingDirURI.toString().equals(EMPTY_STRING)) {
            workingDirURI = getWorkingDirectory(config).toURI();
            workingDirPath = Path.fromPortableString(workingDirURI.getPath());
            binPath = CDebugUtils.verifyProgramPath(config);
        } else {
            workingDirPath = Path.fromPortableString(workingDirURI.getPath() + IPath.SEPARATOR);
            URI binURI = new URI(configUtils.getExecutablePath());
            binPath = Path.fromPortableString(binURI.getPath().toString());
        }
        PerfPlugin.getDefault().setWorkingDir(workingDirPath);
        if (config.getAttribute(PerfPlugin.ATTR_ShowStat, PerfPlugin.ATTR_ShowStat_default)) {
            showStat(config, launch);
        } else {
            String perfPathString = RuntimeProcessFactory.getFactory().whichCommand(PerfPlugin.PERF_COMMAND, project);
            IFileStore workingDir;
            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
            // Program args from launch config.
            String[] arguments = getProgramArgumentsArray(config);
            ArrayList<String> command = new ArrayList<>(4 + arguments.length);
            // Get the base commandline string (with flags/options based on config)
            command.addAll(Arrays.asList(PerfCore.getRecordString(config)));
            // Add the path to the executable
            command.add(binPath.toPortableString());
            command.set(0, perfPathString);
            command.add(2, OUTPUT_STR + 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);
            // $NON-NLS-1$
            MessageConsole console = new MessageConsole("Perf Console", null);
            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++) {
                    // $NON-NLS-1$
                    print.print(command.get(i) + " ");
                }
                // Print Message
                print.println();
                // $NON-NLS-1$
                print.println("Analysing recorded perf.data, please wait...");
            // 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, workingDirPath, monitor, null, print);
            URI perfDataURI = null;
            IRemoteFileProxy proxy = null;
            perfDataURI = new URI(workingDirURI.toString() + IPath.SEPARATOR + 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(binPath.toPortableString()));
            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);
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) OutputStream(java.io.OutputStream) ConfigUtils(org.eclipse.linuxtools.profiling.launch.ConfigUtils) ArrayList(java.util.ArrayList) MessageConsoleStream(org.eclipse.ui.console.MessageConsoleStream) ConsolePlugin(org.eclipse.ui.console.ConsolePlugin) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) IRemoteFileProxy(org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) PrintStream(java.io.PrintStream) MessageConsole(org.eclipse.ui.console.MessageConsole) RemoteConnectionException(org.eclipse.linuxtools.profiling.launch.RemoteConnectionException) InputStreamReader(java.io.InputStreamReader) IConsole(org.eclipse.ui.console.IConsole) IOException(java.io.IOException) IConsoleManager(org.eclipse.ui.console.IConsoleManager) IFileInfo(org.eclipse.core.filesystem.IFileInfo) CoreException(org.eclipse.core.runtime.CoreException) BufferedReader(java.io.BufferedReader) IFileStore(org.eclipse.core.filesystem.IFileStore) RemoteConnection(org.eclipse.linuxtools.profiling.launch.RemoteConnection) IOConsole(org.eclipse.ui.console.IOConsole)

Example 32 with IConsole

use of org.eclipse.ui.console.IConsole in project knime-core by knime.

the class ConsoleViewAppender method findConsole.

/**
 * Looks up the console view that is responsible for the given event, does
 * not activate the view.
 *
 * @param consoleName The name of the console to look up
 */
private MessageConsole findConsole(final String consoleName) {
    ConsolePlugin plugin = ConsolePlugin.getDefault();
    IConsoleManager conMan = plugin.getConsoleManager();
    IConsole[] existing = conMan.getConsoles();
    for (int i = 0; i < existing.length; i++) {
        if (consoleName.equals(existing[i].getName())) {
            return (MessageConsole) existing[i];
        }
    }
    // no console found, so create a new one
    MessageConsole myConsole = new MessageConsole(consoleName, null);
    conMan.addConsoles(new IConsole[] { myConsole });
    return myConsole;
}
Also used : IConsoleManager(org.eclipse.ui.console.IConsoleManager) MessageConsole(org.eclipse.ui.console.MessageConsole) ConsolePlugin(org.eclipse.ui.console.ConsolePlugin) IConsole(org.eclipse.ui.console.IConsole)

Example 33 with IConsole

use of org.eclipse.ui.console.IConsole in project eclipse.platform.releng by eclipse.

the class RemoveAllConsolesAction method run.

@Override
public void run() {
    List<IConsole> consolesList = new ArrayList<>();
    for (IConsole console : ConsolePlugin.getDefault().getConsoleManager().getConsoles()) {
        if (console instanceof FixConsole) {
            consolesList.add(console);
        }
    }
    if (consolesList.isEmpty())
        return;
    IConsole[] consoles = new IConsole[consolesList.size()];
    for (int i = 0; i < consoles.length; i++) {
        consoles[i] = consolesList.get(i);
    }
    ConsolePlugin.getDefault().getConsoleManager().removeConsoles(consoles);
}
Also used : FixConsole(org.eclipse.releng.tools.AdvancedFixCopyrightAction.FixConsole) ArrayList(java.util.ArrayList) IConsole(org.eclipse.ui.console.IConsole)

Example 34 with IConsole

use of org.eclipse.ui.console.IConsole in project ch.hsr.ifs.cdttesting by IFS-HSR.

the class Console method revealConsole.

private static void revealConsole() {
    IConsole myConsole = findConsole(name);
    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    String id = IConsoleConstants.ID_CONSOLE_VIEW;
    IConsoleView view;
    try {
        view = (IConsoleView) page.showView(id);
        view.display(myConsole);
    } catch (PartInitException e) {
        return;
    }
}
Also used : IConsoleView(org.eclipse.ui.console.IConsoleView) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IConsole(org.eclipse.ui.console.IConsole) PartInitException(org.eclipse.ui.PartInitException)

Example 35 with IConsole

use of org.eclipse.ui.console.IConsole in project ch.hsr.ifs.cdttesting by IFS-HSR.

the class Console method findConsole.

private static MessageConsole findConsole(String name) {
    ConsolePlugin plugin = ConsolePlugin.getDefault();
    IConsoleManager consoleManager = plugin.getConsoleManager();
    IConsole[] existing = consoleManager.getConsoles();
    for (int i = 0; i < existing.length; i++) {
        if (name.equals(existing[i].getName())) {
            return (MessageConsole) existing[i];
        }
    }
    return createNewConsole(name, consoleManager);
}
Also used : IConsoleManager(org.eclipse.ui.console.IConsoleManager) MessageConsole(org.eclipse.ui.console.MessageConsole) ConsolePlugin(org.eclipse.ui.console.ConsolePlugin) IConsole(org.eclipse.ui.console.IConsole)

Aggregations

IConsole (org.eclipse.ui.console.IConsole)50 IConsoleManager (org.eclipse.ui.console.IConsoleManager)32 ConsolePlugin (org.eclipse.ui.console.ConsolePlugin)28 MessageConsole (org.eclipse.ui.console.MessageConsole)22 IOConsole (org.eclipse.ui.console.IOConsole)6 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)4 PartInitException (org.eclipse.ui.PartInitException)4 IOException (java.io.IOException)3 CoreException (org.eclipse.core.runtime.CoreException)3 IProcess (org.eclipse.debug.core.model.IProcess)3 IConsoleView (org.eclipse.ui.console.IConsoleView)3 TextConsole (org.eclipse.ui.console.TextConsole)3 ArrayList (java.util.ArrayList)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 IProcessTerminationListener (net.vtst.eclipse.easyxtext.ui.launching.EasyLaunchConfigurationDelegateUtils.IProcessTerminationListener)2 EasyPatternMatchListener (net.vtst.eclipse.easyxtext.ui.launching.EasyPatternMatchListener)2 IMarker (org.eclipse.core.resources.IMarker)2 BadLocationException (org.eclipse.jface.text.BadLocationException)2 IOConsoleOutputStream (org.eclipse.ui.console.IOConsoleOutputStream)2