mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-95644 Support console input filtering
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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 com.intellij.execution.filters;
|
||||
|
||||
import com.intellij.execution.ui.ConsoleViewContentType;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.DumbService;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.util.containers.ContainerUtilRt;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CompositeInputFilter implements InputFilter {
|
||||
private static final Logger LOG = Logger.getInstance(CompositeInputFilter.class);
|
||||
|
||||
private final List<Pair<InputFilter, Boolean /* is dumb aware */>> myFilters = ContainerUtilRt.newArrayList();
|
||||
private final DumbService myDumbService;
|
||||
|
||||
public CompositeInputFilter(@NotNull Project project) {
|
||||
myDumbService = DumbService.getInstance(project);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Pair<String, ConsoleViewContentType> applyFilter(final String text, final ConsoleViewContentType contentType) {
|
||||
boolean dumb = myDumbService.isDumb();
|
||||
for (Pair<InputFilter, Boolean> pair : myFilters) {
|
||||
if (!dumb || pair.second == Boolean.TRUE) {
|
||||
long t0 = System.currentTimeMillis();
|
||||
InputFilter filter = pair.first;
|
||||
Pair<String, ConsoleViewContentType> result = filter.applyFilter(text, contentType);
|
||||
t0 = System.currentTimeMillis() - t0;
|
||||
if (t0 > 100) {
|
||||
LOG.warn(filter.getClass().getSimpleName() + ".applyFilter() took " + t0 + " ms on '''" + text + "'''");
|
||||
}
|
||||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void addFilter(@NotNull final InputFilter filter) {
|
||||
myFilters.add(Pair.create(filter, DumbService.isDumbAware(filter)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 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 com.intellij.execution.filters;
|
||||
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface ConsoleInputFilterProvider {
|
||||
ExtensionPointName<ConsoleInputFilterProvider> INPUT_FILTER_PROVIDERS =
|
||||
ExtensionPointName.create("com.intellij.consoleInputFilterProvider");
|
||||
|
||||
@NotNull
|
||||
InputFilter[] getDefaultFilters(@NotNull Project project);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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 com.intellij.execution.filters;
|
||||
|
||||
import com.intellij.execution.ui.ConsoleViewContentType;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface InputFilter {
|
||||
|
||||
/**
|
||||
* @param text the text to be filtered.
|
||||
* @param contentType the content type of filtered text
|
||||
* @return <tt>null</tt>, if there was no match, otherwise, a pair of ('string to use', 'content type to use')
|
||||
*/
|
||||
@Nullable
|
||||
Pair<String, ConsoleViewContentType> applyFilter(String text, ConsoleViewContentType contentType);
|
||||
|
||||
}
|
||||
@@ -241,6 +241,8 @@ public class ConsoleViewImpl extends JPanel implements ConsoleView, ObservableCo
|
||||
protected final CompositeFilter myPredefinedMessageFilter;
|
||||
protected final CompositeFilter myCustomFilter;
|
||||
|
||||
@Nullable private final InputFilter myInputMessageFilter;
|
||||
|
||||
private final Alarm myFoldingAlarm = new Alarm(Alarm.ThreadToUse.SWING_THREAD, this);
|
||||
private final List<FoldRegion> myPendingFoldRegions = new ArrayList<FoldRegion>();
|
||||
|
||||
@@ -264,7 +266,11 @@ public class ConsoleViewImpl extends JPanel implements ConsoleView, ObservableCo
|
||||
this(project, GlobalSearchScope.allScope(project), viewer, fileType);
|
||||
}
|
||||
|
||||
public ConsoleViewImpl(@NotNull final Project project, @NotNull GlobalSearchScope searchScope, boolean viewer, @Nullable FileType fileType) {
|
||||
public ConsoleViewImpl(@NotNull final Project project,
|
||||
@NotNull GlobalSearchScope searchScope,
|
||||
boolean viewer,
|
||||
@Nullable FileType fileType)
|
||||
{
|
||||
this(project, searchScope, viewer, fileType,
|
||||
new ConsoleState.NotStartedStated() {
|
||||
@Override
|
||||
@@ -278,7 +284,8 @@ public class ConsoleViewImpl extends JPanel implements ConsoleView, ObservableCo
|
||||
@NotNull GlobalSearchScope searchScope,
|
||||
boolean viewer,
|
||||
@Nullable FileType fileType,
|
||||
@NotNull final ConsoleState initialState) {
|
||||
@NotNull final ConsoleState initialState)
|
||||
{
|
||||
super(new BorderLayout());
|
||||
isViewer = viewer;
|
||||
myState = initialState;
|
||||
@@ -299,6 +306,21 @@ public class ConsoleViewImpl extends JPanel implements ConsoleView, ObservableCo
|
||||
myHeavyUpdateTicket = 0;
|
||||
myHeavyAlarm = myPredefinedMessageFilter.isAnyHeavy() ? new Alarm(Alarm.ThreadToUse.SHARED_THREAD, this) : null;
|
||||
|
||||
ConsoleInputFilterProvider[] inputFilters = Extensions.getExtensions(ConsoleInputFilterProvider.INPUT_FILTER_PROVIDERS);
|
||||
if (inputFilters.length > 0) {
|
||||
CompositeInputFilter compositeInputFilter = new CompositeInputFilter(project);
|
||||
myInputMessageFilter = compositeInputFilter;
|
||||
for (ConsoleInputFilterProvider eachProvider : inputFilters) {
|
||||
InputFilter[] filters = eachProvider.getDefaultFilters(project);
|
||||
for (InputFilter filter : filters) {
|
||||
compositeInputFilter.addFilter(filter);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
myInputMessageFilter = null;
|
||||
}
|
||||
|
||||
Disposer.register(project, this);
|
||||
myFinishProgress = new Runnable() {
|
||||
@Override
|
||||
@@ -338,6 +360,7 @@ public class ConsoleViewImpl extends JPanel implements ConsoleView, ObservableCo
|
||||
if (myEditor == null || myFlushAlarm.isDisposed()) return;
|
||||
class ScrollRunnable extends MyFlushRunnable {
|
||||
private final int myOffset = offset;
|
||||
|
||||
@Override
|
||||
public void doRun() {
|
||||
flushDeferredText();
|
||||
@@ -510,7 +533,20 @@ public class ConsoleViewImpl extends JPanel implements ConsoleView, ObservableCo
|
||||
|
||||
@Override
|
||||
public void print(String s, final ConsoleViewContentType contentType) {
|
||||
printHyperlink(s, contentType, null);
|
||||
if (myInputMessageFilter == null) {
|
||||
printHyperlink(s, contentType, null);
|
||||
return;
|
||||
}
|
||||
|
||||
Pair<String, ConsoleViewContentType> result = myInputMessageFilter.applyFilter(s, contentType);
|
||||
if (result == null) {
|
||||
printHyperlink(s, contentType, null);
|
||||
}
|
||||
else {
|
||||
if (result.first != null) {
|
||||
printHyperlink(result.first, result.second == null ? contentType : result.second, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void printHyperlink(String s, ConsoleViewContentType contentType, HyperlinkInfo info) {
|
||||
|
||||
@@ -294,6 +294,7 @@
|
||||
area="IDEA_PROJECT"/>
|
||||
|
||||
<extensionPoint name="consoleFilterProvider" interface="com.intellij.execution.filters.ConsoleFilterProvider"/>
|
||||
<extensionPoint name="consoleInputFilterProvider" interface="com.intellij.execution.filters.ConsoleInputFilterProvider"/>
|
||||
<extensionPoint name="consoleActionsPostProcessor" interface="com.intellij.execution.actions.ConsoleActionsPostProcessor"/>
|
||||
|
||||
<extensionPoint name="console.folding" interface="com.intellij.execution.ConsoleFolding"/>
|
||||
|
||||
Reference in New Issue
Block a user