From 03d1cbe4db7b1aed35d579f4d30597694948bd8a Mon Sep 17 00:00:00 2001 From: Konstantin Kolosovsky Date: Tue, 10 Nov 2015 00:11:35 +0300 Subject: [PATCH] vcs: Refactoring - introduced new overload of "ProjectLevelVcsManager.addMessageToConsoleWindow()" to avoid unnecessary "ConsoleViewContentType" instances creation while printing messages to vcs console --- .../openapi/vcs/ProjectLevelVcsManager.java | 4 ++++ .../vcs/impl/ProjectLevelVcsManagerImpl.java | 19 +++++++++++++------ plugins/git4idea/src/git4idea/GitVcs.java | 15 +++++++-------- .../src/org/zmlx/hg4idea/HgVFSListener.java | 2 +- .../hg4idea/src/org/zmlx/hg4idea/HgVcs.java | 6 +++--- .../hg4idea/execution/HgCommandExecutor.java | 6 +++--- 6 files changed, 31 insertions(+), 21 deletions(-) diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/ProjectLevelVcsManager.java b/platform/vcs-api/src/com/intellij/openapi/vcs/ProjectLevelVcsManager.java index 9e64eb092089..032ea0be76a9 100644 --- a/platform/vcs-api/src/com/intellij/openapi/vcs/ProjectLevelVcsManager.java +++ b/platform/vcs-api/src/com/intellij/openapi/vcs/ProjectLevelVcsManager.java @@ -15,6 +15,7 @@ */ package com.intellij.openapi.vcs; +import com.intellij.execution.ui.ConsoleViewContentType; import com.intellij.lifecycle.PeriodicalTasksCloser; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.editor.markup.TextAttributes; @@ -170,8 +171,11 @@ public abstract class ProjectLevelVcsManager { public abstract boolean hasAnyMappings(); + @Deprecated public abstract void addMessageToConsoleWindow(String message, TextAttributes attributes); + public abstract void addMessageToConsoleWindow(@Nullable String message, @NotNull ConsoleViewContentType contentType); + @NotNull public abstract VcsShowSettingOption getStandardOption(@NotNull VcsConfiguration.StandardOption option, @NotNull AbstractVcs vcs); diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/ProjectLevelVcsManagerImpl.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/ProjectLevelVcsManagerImpl.java index adc0d62e004d..ceebb1d91bf3 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/ProjectLevelVcsManagerImpl.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/ProjectLevelVcsManagerImpl.java @@ -61,6 +61,7 @@ import com.intellij.ui.content.ContentFactory; import com.intellij.ui.content.ContentManager; import com.intellij.util.ContentUtilEx; import com.intellij.util.Processor; +import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.Convertor; import com.intellij.util.messages.MessageBus; import com.intellij.util.messages.MessageBusConnection; @@ -119,7 +120,7 @@ public class ProjectLevelVcsManagerImpl extends ProjectLevelVcsManagerEx impleme private final Map myBackgroundableActionHandlerMap; - private final List> myPendingOutput = new ArrayList>(); + private final List> myPendingOutput = ContainerUtil.newArrayList(); private final VcsHistoryCache myVcsHistoryCache; private final ContentRevisionCache myContentRevisionCache; @@ -389,8 +390,14 @@ public class ProjectLevelVcsManagerImpl extends ProjectLevelVcsManagerEx impleme return !myMappings.isEmpty(); } + @Deprecated @Override public void addMessageToConsoleWindow(final String message, final TextAttributes attributes) { + addMessageToConsoleWindow(message, new ConsoleViewContentType("", attributes)); + } + + @Override + public void addMessageToConsoleWindow(@Nullable final String message, @NotNull final ConsoleViewContentType contentType) { if (!Registry.is("vcs.showConsole")) { return; } @@ -405,11 +412,11 @@ public class ProjectLevelVcsManagerImpl extends ProjectLevelVcsManagerEx impleme if (myProject.isDisposed() || myProject.isDefault()) return; final ContentManager contentManager = getContentManager(); if (contentManager == null) { - myPendingOutput.add(Pair.create(message, attributes)); + myPendingOutput.add(Pair.create(message, contentType)); } else { getOrCreateConsoleContent(contentManager); - printToConsole(message, attributes); + printToConsole(message, contentType); } } }, ModalityState.defaultModalityState()); @@ -434,7 +441,7 @@ public class ProjectLevelVcsManagerImpl extends ProjectLevelVcsManagerEx impleme content.setDisposer(myConsoleDisposer); contentManager.addContent(content); - for (Pair pair : myPendingOutput) { + for (Pair pair : myPendingOutput) { printToConsole(pair.first, pair.second); } myPendingOutput.clear(); @@ -442,8 +449,8 @@ public class ProjectLevelVcsManagerImpl extends ProjectLevelVcsManagerEx impleme return content; } - private void printToConsole(@NotNull String message, @Nullable TextAttributes attributes) { - myConsole.print(message + "\n", new ConsoleViewContentType("", attributes)); + private void printToConsole(@NotNull String message, @NotNull ConsoleViewContentType contentType) { + myConsole.print(message + "\n", contentType); } private void releaseConsole() { diff --git a/plugins/git4idea/src/git4idea/GitVcs.java b/plugins/git4idea/src/git4idea/GitVcs.java index f7664e41fb8f..5de354f4d328 100644 --- a/plugins/git4idea/src/git4idea/GitVcs.java +++ b/plugins/git4idea/src/git4idea/GitVcs.java @@ -23,7 +23,6 @@ import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.diff.impl.patch.formove.FilePathComparator; -import com.intellij.openapi.editor.markup.TextAttributes; import com.intellij.openapi.options.Configurable; import com.intellij.openapi.options.ShowSettingsUtil; import com.intellij.openapi.progress.Task; @@ -376,19 +375,19 @@ public class GitVcs extends AbstractVcs { */ public void showMessages(@NotNull String message) { if (message.length() == 0) return; - showMessage(message, ConsoleViewContentType.NORMAL_OUTPUT.getAttributes()); + showMessage(message, ConsoleViewContentType.NORMAL_OUTPUT); } /** * Show message in the Version Control Console * @param message a message to show - * @param style a style to use + * @param contentType a style to use */ - private void showMessage(@NotNull String message, final TextAttributes style) { + private void showMessage(@NotNull String message, @NotNull ConsoleViewContentType contentType) { if (message.length() > MAX_CONSOLE_OUTPUT_SIZE) { message = message.substring(0, MAX_CONSOLE_OUTPUT_SIZE); } - myVcsManager.addMessageToConsoleWindow(message, style); + myVcsManager.addMessageToConsoleWindow(message, contentType); } /** @@ -428,7 +427,7 @@ public class GitVcs extends AbstractVcs { final String reason = (e.getCause() != null ? e.getCause() : e).getMessage(); String message = GitBundle.message("vcs.unable.to.run.git", executable, reason); if (!myProject.isDefault()) { - showMessage(message, ConsoleViewContentType.SYSTEM_OUTPUT.getAttributes()); + showMessage(message, ConsoleViewContentType.SYSTEM_OUTPUT); } VcsBalloonProblemNotifier.showOverVersionControlView(myProject, message, MessageType.ERROR); } @@ -448,14 +447,14 @@ public class GitVcs extends AbstractVcs { */ public void showCommandLine(final String cmdLine) { SimpleDateFormat f = new SimpleDateFormat("HH:mm:ss.SSS"); - showMessage(f.format(new Date()) + ": " + cmdLine, ConsoleViewContentType.SYSTEM_OUTPUT.getAttributes()); + showMessage(f.format(new Date()) + ": " + cmdLine, ConsoleViewContentType.SYSTEM_OUTPUT); } /** * Shows error message in the Version Control Console */ public void showErrorMessages(final String line) { - showMessage(line, ConsoleViewContentType.ERROR_OUTPUT.getAttributes()); + showMessage(line, ConsoleViewContentType.ERROR_OUTPUT); } @Override diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/HgVFSListener.java b/plugins/hg4idea/src/org/zmlx/hg4idea/HgVFSListener.java index b7733278e4cd..6f9b1a31ed28 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/HgVFSListener.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/HgVFSListener.java @@ -107,7 +107,7 @@ public class HgVFSListener extends VcsVFSListener { catch (final VcsException ex) { UIUtil.invokeLaterIfNeeded(new Runnable() { public void run() { - ((HgVcs)myVcs).showMessageInConsole(ex.getMessage(), ConsoleViewContentType.ERROR_OUTPUT.getAttributes()); + ((HgVcs)myVcs).showMessageInConsole(ex.getMessage(), ConsoleViewContentType.ERROR_OUTPUT); } }); } diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/HgVcs.java b/plugins/hg4idea/src/org/zmlx/hg4idea/HgVcs.java index d3f96536fb76..45c8e1459288 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/HgVcs.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/HgVcs.java @@ -12,6 +12,7 @@ // limitations under the License. package org.zmlx.hg4idea; +import com.intellij.execution.ui.ConsoleViewContentType; import com.intellij.ide.BrowserUtil; import com.intellij.notification.Notification; import com.intellij.notification.NotificationListener; @@ -21,7 +22,6 @@ import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.diff.impl.patch.formove.FilePathComparator; -import com.intellij.openapi.editor.markup.TextAttributes; import com.intellij.openapi.fileTypes.FileTypeManager; import com.intellij.openapi.options.Configurable; import com.intellij.openapi.options.ShowSettingsUtil; @@ -363,11 +363,11 @@ public class HgVcs extends AbstractVcs { return globalSettings; } - public void showMessageInConsole(String message, final TextAttributes style) { + public void showMessageInConsole(@NotNull String message, @NotNull ConsoleViewContentType contentType) { if (message.length() > MAX_CONSOLE_OUTPUT_SIZE) { message = message.substring(0, MAX_CONSOLE_OUTPUT_SIZE); } - myVcsManager.addMessageToConsoleWindow(message, style); + myVcsManager.addMessageToConsoleWindow(message, contentType); } public HgExecutableValidator getExecutableValidator() { diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/execution/HgCommandExecutor.java b/plugins/hg4idea/src/org/zmlx/hg4idea/execution/HgCommandExecutor.java index 0f5cc788f30b..4281a64a0a2b 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/execution/HgCommandExecutor.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/execution/HgCommandExecutor.java @@ -204,7 +204,7 @@ public class HgCommandExecutor { } if (!myIsSilent) { LOG.info(cmdString); - myVcs.showMessageInConsole(cmdString, ConsoleViewContentType.NORMAL_OUTPUT.getAttributes()); + myVcs.showMessageInConsole(cmdString, ConsoleViewContentType.NORMAL_OUTPUT); } else { LOG.debug(cmdString); @@ -223,7 +223,7 @@ public class HgCommandExecutor { else if (!myOutputAlwaysSuppressed) { if (!myIsSilent && myShowOutput) { LOG.info(result.getRawOutput()); - myVcs.showMessageInConsole(result.getRawOutput(), ConsoleViewContentType.SYSTEM_OUTPUT.getAttributes()); + myVcs.showMessageInConsole(result.getRawOutput(), ConsoleViewContentType.SYSTEM_OUTPUT); } else { LOG.debug(result.getRawOutput()); @@ -238,7 +238,7 @@ public class HgCommandExecutor { } if (!myIsSilent) { LOG.info(result.getRawError()); - myVcs.showMessageInConsole(result.getRawError(), ConsoleViewContentType.ERROR_OUTPUT.getAttributes()); + myVcs.showMessageInConsole(result.getRawError(), ConsoleViewContentType.ERROR_OUTPUT); } else { LOG.debug(result.getRawError());