Search in sources :

Example 1 with IProcess

use of org.eclipse.debug.core.model.IProcess in project jop by jop-devel.

the class JavaDownLaunchConfigurationDelegate method jopize.

/**
     * 
     * @param configuration
     * @param mode
     * @param launch
     * @param monitor
     * @return
     * @throws CoreException
     * @throws IOException
     * @throws InterruptedException
     */
private int jopize(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException, IOException, InterruptedException {
    IPath workingDir = getAbsoluteProjectOutputPath(configuration);
    IPath jopizedFile = getJopizedFile(configuration);
    IPath jopHome = Path.fromOSString(JOPUIPlugin.getDefault().getPreferenceStore().getString(IJOPLaunchConfigurationConstants.ATTR_JOP_HOME));
    String[] args = new String[] { "java", "-classpath", String.format("%s;%s;%s", jopHome.append("java/lib/bcel-5.1.jar"), jopHome.append("java/lib/jakarta-regexp-1.3.jar"), jopHome.append("java/tools/dist/lib/jop-tools.jar")), "com.jopdesign.build.JOPizer", "-cp", jopHome.append("java/target/dist/lib/classes.zip") + ";" + workingDir.toOSString(), "-o", jopizedFile.toOSString(), getMainTypeName(configuration) };
    Process process = DebugPlugin.exec(args, workingDir.toFile());
    IProcess p = DebugPlugin.newProcess(launch, process, "JOPizer");
    p.setAttribute(DebugPlugin.ATTR_CAPTURE_OUTPUT, "true");
    return process.waitFor();
}
Also used : IPath(org.eclipse.core.runtime.IPath) IProcess(org.eclipse.debug.core.model.IProcess) IProcess(org.eclipse.debug.core.model.IProcess)

Example 2 with IProcess

use of org.eclipse.debug.core.model.IProcess in project bndtools by bndtools.

the class AbstractOSGiLaunchDelegate method launch.

@Override
public void launch(ILaunchConfiguration configuration, String mode, final ILaunch launch, IProgressMonitor monitor) throws CoreException {
    // Register listener to clean up temp files on exit of launched JVM
    final ProjectLauncher launcher = getProjectLauncher();
    IDebugEventSetListener listener = new IDebugEventSetListener() {

        @Override
        public void handleDebugEvents(DebugEvent[] events) {
            for (DebugEvent event : events) {
                if (event.getKind() == DebugEvent.TERMINATE) {
                    Object source = event.getSource();
                    if (source instanceof IProcess) {
                        ILaunch processLaunch = ((IProcess) source).getLaunch();
                        if (processLaunch == launch) {
                            // Not interested in any further events =>
                            // unregister this listener
                            DebugPlugin.getDefault().removeDebugEventListener(this);
                            // *may* cause LinkageErrors.
                            try {
                                launcher.cleanup();
                            } catch (Throwable t) {
                                logger.logError("Error cleaning launcher temporary files", t);
                            }
                            LaunchUtils.endRun((Run) launcher.getProject());
                        }
                    }
                }
            }
        }
    };
    DebugPlugin.getDefault().addDebugEventListener(listener);
    // Now actually launch
    super.launch(configuration, mode, launch, monitor);
}
Also used : IDebugEventSetListener(org.eclipse.debug.core.IDebugEventSetListener) DebugEvent(org.eclipse.debug.core.DebugEvent) ILaunch(org.eclipse.debug.core.ILaunch) ProjectLauncher(aQute.bnd.build.ProjectLauncher) IProcess(org.eclipse.debug.core.model.IProcess)

Example 3 with IProcess

use of org.eclipse.debug.core.model.IProcess in project bndtools by bndtools.

the class TerminationListener method handleDebugEvents.

public void handleDebugEvents(DebugEvent[] events) {
    for (DebugEvent event : events) {
        Object source = event.getSource();
        if (event.getKind() == DebugEvent.TERMINATE && (source instanceof IProcess) && ((IProcess) source).getLaunch() == launch) {
            terminatedProcesses.add((IProcess) source);
            boolean isTerminated = true;
            IProcess[] createdProcesses = launch.getProcesses();
            for (IProcess process : createdProcesses) {
                if (!terminatedProcesses.contains(process)) {
                    isTerminated = false;
                    break;
                }
            }
            if (isTerminated) {
                DebugPlugin.getDefault().removeDebugEventListener(this);
                onTerminate.run();
            }
        }
    }
}
Also used : DebugEvent(org.eclipse.debug.core.DebugEvent) IProcess(org.eclipse.debug.core.model.IProcess)

Example 4 with IProcess

use of org.eclipse.debug.core.model.IProcess in project ow by vtst.

the class SoyCompilerLaunchConfigurationDelegate method addProcessListeners.

@Override
protected void addProcessListeners(final ILaunchConfiguration config, final Fixture fixture, IProcessListenerAcceptor acceptor) {
    acceptor.acceptTerminationListener(new IProcessTerminationListener() {

        public void terminated(IProcess process, int exitValue) {
            IConsole console = DebugUITools.getConsole(process);
            if (console instanceof IOConsole) {
                IOConsole ioConsole = (IOConsole) console;
                IOConsoleOutputStream stream = ioConsole.newOutputStream();
                if (exitValue == 0) {
                    try {
                        stream.write(messages.getString("soy_compiler_success"));
                        stream.write("\n");
                        stream.flush();
                        for (IFile file : configHelper.getOutputFiles(config)) {
                            try {
                                file.refreshLocal(0, null);
                            } catch (CoreException e) {
                            }
                        }
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                } else {
                    try {
                        stream.write(messages.getString("soy_compiler_error"));
                        stream.write("\n");
                        stream.flush();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        //try { fixture.outputFile.refreshLocal(0, null); } catch (CoreException e) {}
        }
    });
    acceptor.acceptPatternMatchListener(new EasyPatternMatchListener() {

        private Pattern pattern = Pattern.compile("Exception [^:]*com.google.template.soy.base.SoySyntaxException: " + "(In file ([^:]*)(:([0-9]+))?(, template [^:]*)?: )?(.*)");

        @Override
        public void connect(TextConsole console) {
            super.connect(console);
            try {
                for (IMarker marker : fixture.inputFile.findMarkers(MARKER_TYPE, true, IResource.DEPTH_ZERO)) {
                    if (MARKER_SOURCE_ID.equals(marker.getAttribute(IMarker.SOURCE_ID))) {
                        marker.delete();
                    }
                }
            } catch (CoreException e) {
            }
        }

        private void processLine(int offset, int length) throws BadLocationException {
            String line = document.get(offset, length);
            Matcher matcher = pattern.matcher(line);
            if (matcher.matches()) {
                String lineNumberAsString = matcher.group(4);
                int lineNumber = (lineNumberAsString == null ? 1 : Integer.parseInt(lineNumberAsString));
                String errorMessage = matcher.group(6);
                IMarker marker;
                try {
                    marker = fixture.inputFile.createMarker(MARKER_TYPE);
                    marker.setAttribute(IMarker.LINE_NUMBER, lineNumber);
                    marker.setAttribute(IMarker.MESSAGE, errorMessage);
                    marker.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_NORMAL);
                    marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
                    marker.setAttribute(IMarker.SOURCE_ID, MARKER_SOURCE_ID);
                } catch (CoreException e) {
                    e.printStackTrace();
                }
            }
        }

        @Override
        public void matchFound(PatternMatchEvent matchEvent) {
            try {
                processLine(matchEvent.getOffset(), matchEvent.getLength());
            } catch (BadLocationException e) {
            // This should never arise if the code is correct
            }
        }

        @Override
        public String getPattern() {
            return ".+";
        }
    });
}
Also used : Pattern(java.util.regex.Pattern) IFile(org.eclipse.core.resources.IFile) IOConsoleOutputStream(org.eclipse.ui.console.IOConsoleOutputStream) Matcher(java.util.regex.Matcher) IProcessTerminationListener(net.vtst.eclipse.easyxtext.ui.launching.EasyLaunchConfigurationDelegateUtils.IProcessTerminationListener) IConsole(org.eclipse.ui.console.IConsole) IOException(java.io.IOException) PatternMatchEvent(org.eclipse.ui.console.PatternMatchEvent) CoreException(org.eclipse.core.runtime.CoreException) EasyPatternMatchListener(net.vtst.eclipse.easyxtext.ui.launching.EasyPatternMatchListener) TextConsole(org.eclipse.ui.console.TextConsole) IMarker(org.eclipse.core.resources.IMarker) IProcess(org.eclipse.debug.core.model.IProcess) IOConsole(org.eclipse.ui.console.IOConsole) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 5 with IProcess

use of org.eclipse.debug.core.model.IProcess in project ow by vtst.

the class LessCompilerLaunchConfigurationDelegate method addProcessListeners.

protected void addProcessListeners(ILaunchConfiguration config, final Fixture fixture, IProcessListenerAcceptor acceptor) {
    acceptor.acceptTerminationListener(new IProcessTerminationListener() {

        public void terminated(IProcess process, int exitValue) {
            IConsole console = DebugUITools.getConsole(process);
            if (console instanceof IOConsole) {
                IOConsole ioConsole = (IOConsole) console;
                IOConsoleOutputStream stream = ioConsole.newOutputStream();
                if (exitValue == 0) {
                    try {
                        stream.write(messages.getString("less_compiler_success"));
                        stream.write("\n");
                        stream.flush();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                /*
            FileLink link = new FileLink(destinationFile, null, -1, -1, -1);
            console.defaultStream.hyperlink(link, messages.getString("less_link_to_output"));
            console.defaultStream.println();
            */
                } else {
                    try {
                        stream.write(messages.getString("less_compiler_error"));
                        stream.write("\n");
                        stream.flush();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
            try {
                fixture.outputFile.refreshLocal(0, null);
            } catch (CoreException e) {
            }
        }
    });
    acceptor.acceptPatternMatchListener(new EasyPatternMatchListener() {

        private Pattern pattern = Pattern.compile("([0-9]+)( .*)");

        private int numberOfLines = 0;

        private int errorLineNumber = 0;

        private String errorMessage = null;

        @Override
        public void connect(TextConsole console) {
            super.connect(console);
            try {
                for (IMarker marker : fixture.inputFile.findMarkers(MARKER_TYPE, true, IResource.DEPTH_ZERO)) {
                    if (MARKER_SOURCE_ID.equals(marker.getAttribute(IMarker.SOURCE_ID))) {
                        marker.delete();
                    }
                }
            } catch (CoreException e) {
            }
        }

        @Override
        public void disconnect() {
            if (errorLineNumber != 0 && errorMessage != null) {
                try {
                    IMarker marker = fixture.inputFile.createMarker(MARKER_TYPE);
                    marker.setAttribute(IMarker.LINE_NUMBER, this.errorLineNumber);
                    marker.setAttribute(IMarker.MESSAGE, this.errorMessage);
                    marker.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_NORMAL);
                    marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
                    marker.setAttribute(IMarker.SOURCE_ID, MARKER_SOURCE_ID);
                } catch (CoreException e) {
                    e.printStackTrace();
                }
            }
        }

        private void processLine(int offset, int length) throws BadLocationException {
            String line = document.get(offset, length);
            Matcher matcher = pattern.matcher(line);
            if (matcher.matches()) {
                this.numberOfLines++;
                int lineNumber = Integer.parseInt(matcher.group(1));
                if (this.numberOfLines <= 2)
                    errorLineNumber = lineNumber;
                FileLink link = new FileLink(fixture.inputFile, null, -1, -1, lineNumber);
                console.addHyperlink(link, offset, matcher.group(1).length());
            } else {
                if (this.numberOfLines == 0)
                    errorMessage = line;
            }
        }

        @Override
        public void matchFound(PatternMatchEvent matchEvent) {
            try {
                processLine(matchEvent.getOffset(), matchEvent.getLength());
            } catch (BadLocationException e) {
            // This should never arise if the code is correct
            }
        }

        @Override
        public String getPattern() {
            return ".+";
        }
    });
}
Also used : Pattern(java.util.regex.Pattern) IOConsoleOutputStream(org.eclipse.ui.console.IOConsoleOutputStream) Matcher(java.util.regex.Matcher) IProcessTerminationListener(net.vtst.eclipse.easyxtext.ui.launching.EasyLaunchConfigurationDelegateUtils.IProcessTerminationListener) FileLink(org.eclipse.debug.ui.console.FileLink) IConsole(org.eclipse.ui.console.IConsole) IOException(java.io.IOException) PatternMatchEvent(org.eclipse.ui.console.PatternMatchEvent) CoreException(org.eclipse.core.runtime.CoreException) EasyPatternMatchListener(net.vtst.eclipse.easyxtext.ui.launching.EasyPatternMatchListener) TextConsole(org.eclipse.ui.console.TextConsole) IMarker(org.eclipse.core.resources.IMarker) IProcess(org.eclipse.debug.core.model.IProcess) IOConsole(org.eclipse.ui.console.IOConsole) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

IProcess (org.eclipse.debug.core.model.IProcess)12 IStatus (org.eclipse.core.runtime.IStatus)4 Status (org.eclipse.core.runtime.Status)4 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)4 CoreException (org.eclipse.core.runtime.CoreException)3 DebugException (org.eclipse.debug.core.DebugException)3 ILaunch (org.eclipse.debug.core.ILaunch)3 BndPreferences (bndtools.preferences.BndPreferences)2 File (java.io.File)2 IOException (java.io.IOException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 MessageFormat (java.text.MessageFormat)2 Date (java.util.Date)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 IResource (org.eclipse.core.resources.IResource)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2