mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
speedup gradle console filter, fix IDEA-150077
– cheap check if the string starts with / or {Alpha}:\
– check if the project has any gradle module
– wrap pattern matching with the bombed char sequence
This commit is contained in:
@@ -20,6 +20,7 @@ import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
@@ -139,7 +140,7 @@ public class RegexpFilter implements Filter {
|
||||
|
||||
@Override
|
||||
public Result applyFilter(String line, int entireLength) {
|
||||
Matcher matcher = myPattern.matcher(StringUtil.newBombedCharSequence(line, 1000));
|
||||
Matcher matcher = myPattern.matcher(oneSecondBomb(line));
|
||||
if (!matcher.find()) {
|
||||
return null;
|
||||
}
|
||||
@@ -177,6 +178,11 @@ public class RegexpFilter implements Filter {
|
||||
return new Result(highlightStartOffset, highlightEndOffset, info);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected static CharSequence oneSecondBomb(@NotNull String line) {
|
||||
return StringUtil.newBombedCharSequence(line, 1000);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected HyperlinkInfo createOpenFileHyperlink(String fileName, final int line, final int column) {
|
||||
fileName = fileName.replace(File.separatorChar, '/');
|
||||
|
||||
+25
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 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.
|
||||
@@ -18,8 +18,16 @@ package org.jetbrains.plugins.gradle.execution;
|
||||
import com.intellij.execution.filters.ConsoleFilterProvider;
|
||||
import com.intellij.execution.filters.Filter;
|
||||
import com.intellij.execution.filters.RegexpFilter;
|
||||
import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.util.CachedValue;
|
||||
import com.intellij.psi.util.CachedValueProvider;
|
||||
import com.intellij.util.CachedValueImpl;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.plugins.gradle.util.GradleConstants;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -31,18 +39,33 @@ public class GradleConsoleFilterProvider implements ConsoleFilterProvider {
|
||||
return new Filter[]{
|
||||
new GradleConsoleFilter(project),
|
||||
new RegexpFilter(project, RegexpFilter.FILE_PATH_MACROS + ":" + RegexpFilter.LINE_MACROS) {
|
||||
private CachedValue<Boolean> myIsGradleProject = new CachedValueImpl<Boolean>(
|
||||
() -> CachedValueProvider.Result.create(isGradleProject(), ModuleManager.getInstance(project)));
|
||||
|
||||
@Override
|
||||
public Result applyFilter(String line, int entireLength) {
|
||||
if (line == null) return null;
|
||||
boolean unixStyle = StringUtil.startsWith(line, "/");
|
||||
boolean winStyle = line.length() >= 3 && line.substring(0, 3).matches("\\p{Alpha}:\\\\");
|
||||
if (!unixStyle && !winStyle) return null;
|
||||
if (Boolean.FALSE.equals(myIsGradleProject.getValue())) return null;
|
||||
Result result = super.applyFilter(line, entireLength);
|
||||
if (result == null) return null;
|
||||
Pattern pattern = getPattern();
|
||||
Matcher matcher = pattern.matcher(line);
|
||||
Matcher matcher = pattern.matcher(oneSecondBomb(line));
|
||||
if (!matcher.find()) return result;
|
||||
int lineStart = entireLength - line.length();
|
||||
int start = lineStart + matcher.start();
|
||||
int end = lineStart + matcher.end();
|
||||
return new Result(start, end, result.getFirstHyperlinkInfo());
|
||||
}
|
||||
|
||||
private boolean isGradleProject() {
|
||||
for (Module module : ModuleManager.getInstance(project).getModules()) {
|
||||
if (ExternalSystemApiUtil.isExternalSystemAwareModule(GradleConstants.SYSTEM_ID, module)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user