From 285491073f88ebf46c491939b71935fb00ae4619 Mon Sep 17 00:00:00 2001 From: Sergey Evdokimov Date: Thu, 27 Jun 2013 20:41:43 +0400 Subject: [PATCH] IDEA-108381 File name in Error appears as plain text rather than link to code in Maven build console --- .../project/AbstractMavenConsoleFilter.java | 74 +++++++++++++++++++ .../idea/maven/project/MavenConsoleImpl.java | 1 + .../project/MavenGroovyConsoleFilter.java | 62 ++-------------- .../project/MavenScalaConsoleFilter.java | 37 ++++++++++ 4 files changed, 118 insertions(+), 56 deletions(-) create mode 100644 plugins/maven/src/main/java/org/jetbrains/idea/maven/project/AbstractMavenConsoleFilter.java create mode 100644 plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenScalaConsoleFilter.java diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/AbstractMavenConsoleFilter.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/AbstractMavenConsoleFilter.java new file mode 100644 index 000000000000..430c1693a35e --- /dev/null +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/AbstractMavenConsoleFilter.java @@ -0,0 +1,74 @@ +package org.jetbrains.idea.maven.project; + +import com.intellij.execution.filters.Filter; +import com.intellij.execution.filters.OpenFileHyperlinkInfo; +import com.intellij.openapi.editor.colors.CodeInsightColors; +import com.intellij.openapi.editor.colors.EditorColorsManager; +import com.intellij.openapi.editor.markup.EffectType; +import com.intellij.openapi.editor.markup.TextAttributes; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.SystemInfo; +import com.intellij.openapi.vfs.LocalFileSystem; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.ui.JBColor; +import org.jetbrains.annotations.Nullable; + +import java.awt.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * @author Sergey Evdokimov + */ +public abstract class AbstractMavenConsoleFilter implements Filter { + + private final Pattern myPattern; + + private final Project myProject; + + public AbstractMavenConsoleFilter(Project project, Pattern pattern) { + myProject = project; + myPattern = pattern; + } + + protected abstract boolean lightCheck(String line); + + @Nullable + @Override + public Result applyFilter(String line, int entireLength) { + if (!lightCheck(line)) return null; + + Matcher matcher = myPattern.matcher(line); + if (!matcher.matches()) return null; + + String path = matcher.group(1); + + VirtualFile file = LocalFileSystem.getInstance().findFileByPath(path); + if (file == null) { + if (SystemInfo.isWindows && path.matches("/[A-Z]:/.+")) { + file = LocalFileSystem.getInstance().findFileByPath(path.substring(1)); + } + if (file == null) return null; + } + + int lineNumber = Integer.parseInt(matcher.group(2)) - 1; + if (lineNumber < 0) { + lineNumber = -1; + } + + TextAttributes attr = createCompilationErrorAttr(); + + return new Result(entireLength - line.length() + matcher.start(1), entireLength - line.length() + matcher.end(1), + new OpenFileHyperlinkInfo(myProject, file, lineNumber), attr); + } + + private static TextAttributes createCompilationErrorAttr() { + TextAttributes attr = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(CodeInsightColors.HYPERLINK_ATTRIBUTES).clone(); + attr.setForegroundColor(JBColor.RED); + attr.setEffectColor(JBColor.RED); + attr.setEffectType(EffectType.LINE_UNDERSCORE); + attr.setFontType(Font.PLAIN); + return attr; + } + +} diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenConsoleImpl.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenConsoleImpl.java index af638f28829c..09c9c6c339c2 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenConsoleImpl.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenConsoleImpl.java @@ -105,6 +105,7 @@ public class MavenConsoleImpl extends MavenConsole { }); builder.addFilter(new MavenGroovyConsoleFilter(project)); + builder.addFilter(new MavenScalaConsoleFilter(project)); return builder; } diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenGroovyConsoleFilter.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenGroovyConsoleFilter.java index ae3003d556a4..598b3d541073 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenGroovyConsoleFilter.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenGroovyConsoleFilter.java @@ -15,76 +15,26 @@ */ package org.jetbrains.idea.maven.project; -import com.intellij.execution.filters.Filter; -import com.intellij.execution.filters.OpenFileHyperlinkInfo; -import com.intellij.openapi.editor.colors.CodeInsightColors; -import com.intellij.openapi.editor.colors.EditorColorsManager; -import com.intellij.openapi.editor.markup.EffectType; -import com.intellij.openapi.editor.markup.TextAttributes; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.SystemInfo; -import com.intellij.openapi.vfs.LocalFileSystem; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.ui.JBColor; -import org.jetbrains.annotations.Nullable; -import java.awt.*; -import java.util.regex.Matcher; import java.util.regex.Pattern; /** * @author Sergey Evdokimov */ -public class MavenGroovyConsoleFilter implements Filter { +public class MavenGroovyConsoleFilter extends AbstractMavenConsoleFilter { + // Example of gmaven error line: + // [ERROR] /home/user/ideaProjects/simpleMaven/src/main/groovy/com/A.groovy: 17: [Static type checking] - Cannot assign value of type java.lang.String to variable of type int private static final Pattern PATTERN = Pattern.compile("\\[ERROR\\] (\\S.+\\.groovy): (-?\\d{1,5}): .+", Pattern.DOTALL); - private final Project myProject; - public MavenGroovyConsoleFilter(Project project) { - myProject = project; + super(project, PATTERN); } - @Nullable @Override - public Result applyFilter(String line, int entireLength) { - - // Example of gmaven error line: - // [ERROR] /home/user/ideaProjects/simpleMaven/src/main/groovy/com/A.groovy: 17: [Static type checking] - Cannot assign value of type java.lang.String to variable of type int - - if (!line.startsWith("[ERROR] ") || !line.contains(".groovy: ")) return null; - - Matcher matcher = PATTERN.matcher(line); - if (!matcher.matches()) return null; - - String path = matcher.group(1); - - VirtualFile file = LocalFileSystem.getInstance().findFileByPath(path); - if (file == null) { - if (SystemInfo.isWindows && path.matches("/[A-Z]:/.+")) { - file = LocalFileSystem.getInstance().findFileByPath(path.substring(1)); - } - if (file == null) return null; - } - - int lineNumber = Integer.parseInt(matcher.group(2)) - 1; - if (lineNumber < 0) { - lineNumber = -1; - } - - TextAttributes attr = createCompilationErrorAttr(); - - return new Result(entireLength - line.length() + matcher.start(1), entireLength - line.length() + matcher.end(1), - new OpenFileHyperlinkInfo(myProject, file, lineNumber), attr); - } - - private static TextAttributes createCompilationErrorAttr() { - TextAttributes attr = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(CodeInsightColors.HYPERLINK_ATTRIBUTES).clone(); - attr.setForegroundColor(JBColor.RED); - attr.setEffectColor(JBColor.RED); - attr.setEffectType(EffectType.LINE_UNDERSCORE); - attr.setFontType(Font.PLAIN); - return attr; + protected boolean lightCheck(String line) { + return line.startsWith("[ERROR] ") && line.contains(".groovy: "); } } diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenScalaConsoleFilter.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenScalaConsoleFilter.java new file mode 100644 index 000000000000..abfa6cc2b266 --- /dev/null +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenScalaConsoleFilter.java @@ -0,0 +1,37 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jetbrains.idea.maven.project; + +import com.intellij.openapi.project.Project; + +import java.util.regex.Pattern; + +/** + * @author Sergey Evdokimov + */ +public class MavenScalaConsoleFilter extends AbstractMavenConsoleFilter { + + private static final Pattern PATTERN = Pattern.compile("\\[ERROR\\] (\\S.+\\.scala): ?(-?\\d{1,5}): .+", Pattern.DOTALL); + + public MavenScalaConsoleFilter(Project project) { + super(project, PATTERN); + } + + @Override + protected boolean lightCheck(String line) { + return line.startsWith("[ERROR] ") && line.contains(".scala:"); + } +}