IDEA-143319 Gradle: add path anchor in gradle task output

This commit is contained in:
Vladislav.Soroka
2015-09-29 14:04:10 +03:00
parent d8192522fa
commit 9761255e76
4 changed files with 175 additions and 0 deletions
+1
View File
@@ -78,6 +78,7 @@
<orderEnumerationHandlerFactory implementation="org.jetbrains.plugins.gradle.execution.GradleOrderEnumeratorHandler$FactoryImpl"/>
<compileServer.plugin classpath="gradle-jps-plugin.jar"/>
<consoleFilterProvider implementation="org.jetbrains.plugins.gradle.execution.GradleConsoleFilterProvider"/>
<buildProcess.parametersProvider implementation="org.jetbrains.plugins.gradle.compiler.GradleBuildProcessParametersProvider"/>
<resolveScopeEnlarger implementation="org.jetbrains.plugins.gradle.config.GradleBuildClasspathResolveScopeEnlarger"/>
@@ -0,0 +1,104 @@
/*
* Copyright 2000-2015 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.plugins.gradle.execution;
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.TextAttributes;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.Nullable;
import java.awt.*;
import java.io.File;
/**
* @author Vladislav.Soroka
* @since 9/29/2015
*/
public class GradleConsoleFilter implements Filter {
private final Project myProject;
private static final TextAttributes HYPERLINK_ATTRIBUTES =
EditorColorsManager.getInstance().getGlobalScheme().getAttributes(CodeInsightColors.HYPERLINK_ATTRIBUTES);
private String myFilteredFileName;
private int myFilteredLineNumber;
public GradleConsoleFilter(Project project) {
myProject = project;
}
@Nullable
@Override
public Result applyFilter(String line, int entireLength) {
final String filePrefix = "Build file '";
final String linePrefix = "' line: ";
int filePrefixIndex = StringUtil.indexOf(line, filePrefix);
if (filePrefixIndex == -1) {
return null;
}
final String fileAndLineNumber = line.substring(filePrefix.length() + filePrefixIndex);
int linePrefixIndex = StringUtil.indexOf(fileAndLineNumber, linePrefix);
if (linePrefixIndex == -1) {
return null;
}
final String fileName = fileAndLineNumber.substring(0, linePrefixIndex);
myFilteredFileName = fileName;
String lineNumberStr = fileAndLineNumber.substring(linePrefixIndex + linePrefix.length(), fileAndLineNumber.length()).trim();
int lineNumber;
try {
lineNumber = Integer.parseInt(lineNumberStr);
myFilteredLineNumber = lineNumber;
}
catch (NumberFormatException e) {
return null;
}
final VirtualFile file = LocalFileSystem.getInstance().findFileByPath(fileName.replace(File.separatorChar, '/'));
if (file == null) {
return null;
}
int textStartOffset = entireLength - line.length() + filePrefix.length();
int highlightEndOffset = textStartOffset + fileName.length();
OpenFileHyperlinkInfo info = new OpenFileHyperlinkInfo(myProject, file, Math.max(lineNumber - 1, 0));
TextAttributes attributes = HYPERLINK_ATTRIBUTES.clone();
if (!ProjectRootManager.getInstance(myProject).getFileIndex().isInContent(file)) {
Color color = UIUtil.getInactiveTextColor();
attributes.setForegroundColor(color);
attributes.setEffectColor(color);
}
return new Result(textStartOffset, highlightEndOffset, info, attributes);
}
public String getFilteredFileName() {
return myFilteredFileName;
}
public int getFilteredLineNumber() {
return myFilteredLineNumber;
}
}
@@ -0,0 +1,33 @@
/*
* Copyright 2000-2015 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.plugins.gradle.execution;
import com.intellij.execution.filters.ConsoleFilterProvider;
import com.intellij.execution.filters.Filter;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
/**
* @author Vladislav.Soroka
* @since 9/29/2015
*/
public class GradleConsoleFilterProvider implements ConsoleFilterProvider {
@NotNull
@Override
public Filter[] getDefaultFilters(@NotNull final Project project) {
return new Filter[]{new GradleConsoleFilter(project)};
}
}
@@ -0,0 +1,37 @@
/*
* Copyright 2000-2015 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.plugins.gradle.execution;
import com.intellij.testFramework.fixtures.CodeInsightFixtureTestCase;
/**
* @author Vladislav.Soroka
* @since 9/29/2015
*/
public class GradleConsoleFilterTest extends CodeInsightFixtureTestCase {
public void testApplyFilter() throws Exception {
doTest("Build file 'C:\\project\\build.gradle' line: 7", "C:\\project\\build.gradle", 7);
doTest("Build file '/project/build.gradle' line: 7", "/project/build.gradle", 7);
}
private void doTest(String line, String expectedFileName, int expectedLineNumber) {
GradleConsoleFilter filter = new GradleConsoleFilter(myFixture.getProject());
filter.applyFilter(line, 0);
assertEquals(expectedFileName, filter.getFilteredFileName());
assertEquals(expectedLineNumber, filter.getFilteredLineNumber());
}
}