Search in sources :

Example 1 with RegexpFilter

use of com.intellij.execution.filters.RegexpFilter in project intellij-community by JetBrains.

the class ToolRunProfile method getState.

@Override
public RunProfileState getState(@NotNull final Executor executor, @NotNull final ExecutionEnvironment env) {
    final Project project = env.getProject();
    if (myCommandLine == null) {
        // can return null if creation of cmd line has been cancelled
        return null;
    }
    final CommandLineState commandLineState = new CommandLineState(env) {

        GeneralCommandLine createCommandLine() {
            return myCommandLine;
        }

        @Override
        @NotNull
        protected OSProcessHandler startProcess() throws ExecutionException {
            final GeneralCommandLine commandLine = createCommandLine();
            final OSProcessHandler processHandler = new ColoredProcessHandler(commandLine);
            ProcessTerminatedListener.attach(processHandler);
            return processHandler;
        }

        @Override
        @NotNull
        public ExecutionResult execute(@NotNull final Executor executor, @NotNull ProgramRunner runner) throws ExecutionException {
            final ExecutionResult result = super.execute(executor, runner);
            final ProcessHandler processHandler = result.getProcessHandler();
            if (processHandler != null) {
                processHandler.addProcessListener(new ToolProcessAdapter(project, myTool.synchronizeAfterExecution(), getName()));
                processHandler.addProcessListener(new ProcessAdapter() {

                    @Override
                    public void onTextAvailable(ProcessEvent event, Key outputType) {
                        if ((outputType == ProcessOutputTypes.STDOUT && myTool.isShowConsoleOnStdOut()) || (outputType == ProcessOutputTypes.STDERR && myTool.isShowConsoleOnStdErr())) {
                            ExecutionManager.getInstance(project).getContentManager().toFrontRunContent(executor, processHandler);
                        }
                    }
                });
            }
            return result;
        }
    };
    TextConsoleBuilder builder = TextConsoleBuilderFactory.getInstance().createBuilder(project);
    final FilterInfo[] outputFilters = myTool.getOutputFilters();
    for (FilterInfo outputFilter : outputFilters) {
        builder.addFilter(new RegexpFilter(project, outputFilter.getRegExp()));
    }
    commandLineState.setConsoleBuilder(builder);
    return commandLineState;
}
Also used : RegexpFilter(com.intellij.execution.filters.RegexpFilter) ExecutionResult(com.intellij.execution.ExecutionResult) NotNull(org.jetbrains.annotations.NotNull) Project(com.intellij.openapi.project.Project) Executor(com.intellij.execution.Executor) TextConsoleBuilder(com.intellij.execution.filters.TextConsoleBuilder) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) CommandLineState(com.intellij.execution.configurations.CommandLineState) ProgramRunner(com.intellij.execution.runners.ProgramRunner) Key(com.intellij.openapi.util.Key)

Example 2 with RegexpFilter

use of com.intellij.execution.filters.RegexpFilter in project intellij-community by JetBrains.

the class MavenConsoleImpl method createConsoleBuilder.

public static TextConsoleBuilder createConsoleBuilder(final Project project) {
    TextConsoleBuilder builder = TextConsoleBuilderFactory.getInstance().createBuilder(project);
    builder.addFilter(new RegexpFilter(project, CONSOLE_FILTER_REGEXP) {

        @Nullable
        @Override
        protected HyperlinkInfo createOpenFileHyperlink(String fileName, int line, int column) {
            HyperlinkInfo res = super.createOpenFileHyperlink(fileName, line, column);
            if (res == null && fileName.startsWith("\\") && SystemInfo.isWindows) {
                // Maven cut prefix 'C:\' from paths on Windows
                VirtualFile[] roots = ProjectRootManager.getInstance(project).getContentRoots();
                if (roots.length > 0) {
                    String projectPath = roots[0].getPath();
                    if (projectPath.matches("[A-Z]:[\\\\/].+")) {
                        res = super.createOpenFileHyperlink(projectPath.charAt(0) + ":" + fileName, line, column);
                    }
                }
            }
            return res;
        }
    });
    builder.addFilter(new MavenGroovyConsoleFilter(project));
    builder.addFilter(new MavenScalaConsoleFilter(project));
    builder.addFilter(new MavenTestConsoleFilter());
    return builder;
}
Also used : RegexpFilter(com.intellij.execution.filters.RegexpFilter) TextConsoleBuilder(com.intellij.execution.filters.TextConsoleBuilder) Nullable(org.jetbrains.annotations.Nullable) HyperlinkInfo(com.intellij.execution.filters.HyperlinkInfo)

Example 3 with RegexpFilter

use of com.intellij.execution.filters.RegexpFilter in project intellij-community by JetBrains.

the class GradleConsoleFilterProvider method getDefaultFilters.

@NotNull
@Override
public Filter[] getDefaultFilters(@NotNull Project project) {
    return new Filter[] { new GradleConsoleFilter(project), new RegexpFilter(project, RegexpFilter.FILE_PATH_MACROS + ":" + RegexpFilter.LINE_MACROS) {

        private CachedValue<Boolean> myIsGradleProject = new CachedValueImpl<>(() -> CachedValueProvider.Result.create(isGradleProject(), ProjectRootModificationTracker.getInstance(project)));

        @Override
        public Result applyFilter(String line, int entireLength) {
            if (line == null || !FileUtil.isAbsolutePlatformIndependent(line))
                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(StringUtil.newBombedCharSequence(line, 100));
            if (!matcher.lookingAt())
                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() {
            return !GradleSettings.getInstance(project).getLinkedProjectsSettings().isEmpty();
        }
    } };
}
Also used : Pattern(java.util.regex.Pattern) RegexpFilter(com.intellij.execution.filters.RegexpFilter) Filter(com.intellij.execution.filters.Filter) RegexpFilter(com.intellij.execution.filters.RegexpFilter) Matcher(java.util.regex.Matcher) CachedValue(com.intellij.psi.util.CachedValue) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

RegexpFilter (com.intellij.execution.filters.RegexpFilter)3 TextConsoleBuilder (com.intellij.execution.filters.TextConsoleBuilder)2 NotNull (org.jetbrains.annotations.NotNull)2 ExecutionResult (com.intellij.execution.ExecutionResult)1 Executor (com.intellij.execution.Executor)1 CommandLineState (com.intellij.execution.configurations.CommandLineState)1 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)1 Filter (com.intellij.execution.filters.Filter)1 HyperlinkInfo (com.intellij.execution.filters.HyperlinkInfo)1 ProgramRunner (com.intellij.execution.runners.ProgramRunner)1 Project (com.intellij.openapi.project.Project)1 Key (com.intellij.openapi.util.Key)1 CachedValue (com.intellij.psi.util.CachedValue)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Nullable (org.jetbrains.annotations.Nullable)1