Search in sources :

Example 56 with IMarker

use of org.eclipse.core.resources.IMarker in project che by eclipse.

the class MarkerUndoState method createMarker.

/**
	 * Create a marker from the marker description.
	 *
	 * @return the created marker
	 * @throws CoreException if the marker could not be created
	 */
public IMarker createMarker() throws CoreException {
    IMarker marker = resource.createMarker(type);
    marker.setAttributes(attributes);
    return marker;
}
Also used : IMarker(org.eclipse.core.resources.IMarker)

Example 57 with IMarker

use of org.eclipse.core.resources.IMarker in project flux by eclipse.

the class Repository method toJSON.

public String toJSON(IMarker[] markers) {
    StringBuilder result = new StringBuilder();
    boolean flag = false;
    result.append("[");
    for (IMarker m : markers) {
        if (flag) {
            result.append(",");
        }
        result.append("{");
        result.append("\"description\":" + JSONObject.quote(m.getAttribute("message", "")));
        result.append(",\"line\":" + m.getAttribute("lineNumber", 0));
        result.append(",\"severity\":\"" + (m.getAttribute("severity", IMarker.SEVERITY_WARNING) == IMarker.SEVERITY_ERROR ? "error" : "warning") + "\"");
        result.append(",\"start\":" + m.getAttribute("charStart", 0));
        result.append(",\"end\":" + m.getAttribute("charEnd", 0));
        result.append("}");
        flag = true;
    }
    result.append("]");
    return result.toString();
}
Also used : IMarker(org.eclipse.core.resources.IMarker)

Example 58 with IMarker

use of org.eclipse.core.resources.IMarker in project flux by eclipse.

the class Repository method sendMetadataUpdate.

public void sendMetadataUpdate(IResource resource) {
    try {
        String project = resource.getProject().getName();
        String resourcePath = resource.getProjectRelativePath().toString();
        JSONObject message = new JSONObject();
        message.put("username", this.username);
        message.put("project", project);
        message.put("resource", resourcePath);
        message.put("type", "marker");
        IMarker[] markers = resource.findMarkers(null, true, IResource.DEPTH_INFINITE);
        String markerJSON = toJSON(markers);
        JSONArray content = new JSONArray(markerJSON);
        message.put("metadata", content);
        messagingConnector.send("metadataChanged", message);
    } catch (Exception e) {
    }
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) IMarker(org.eclipse.core.resources.IMarker) CoreException(org.eclipse.core.runtime.CoreException) JSONException(org.json.JSONException) IOException(java.io.IOException)

Example 59 with IMarker

use of org.eclipse.core.resources.IMarker 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 60 with IMarker

use of org.eclipse.core.resources.IMarker 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

IMarker (org.eclipse.core.resources.IMarker)115 CoreException (org.eclipse.core.runtime.CoreException)31 Test (org.junit.Test)31 IFile (org.eclipse.core.resources.IFile)23 IResource (org.eclipse.core.resources.IResource)16 ArrayList (java.util.ArrayList)15 IProject (org.eclipse.core.resources.IProject)8 IPath (org.eclipse.core.runtime.IPath)8 Position (org.eclipse.jface.text.Position)8 Annotation (org.eclipse.jface.text.source.Annotation)7 Matchers.anyString (org.mockito.Matchers.anyString)7 IOException (java.io.IOException)6 HashMap (java.util.HashMap)6 Rule (net.sourceforge.pmd.Rule)6 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 BadLocationException (org.eclipse.jface.text.BadLocationException)6 RuleViolation (net.sourceforge.pmd.RuleViolation)5 JavaLanguageModule (net.sourceforge.pmd.lang.java.JavaLanguageModule)5 IDocument (org.eclipse.jface.text.IDocument)5 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)5