From 5b6df18bd2f627d8caf03c6403e58b1676e44fc3 Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Thu, 20 Oct 2016 12:01:50 +0300 Subject: [PATCH] Introduce a factory to create various ProcessHandlers To be able to move implementations from api to impl, in particular the ColoredProcessHandler. --- .../JavaCommandLineStateUtil.java | 10 ++--- .../process/ProcessHandlerFactory.java | 41 +++++++++++++++++++ .../process/ProcessHandlerFactoryImpl.java | 35 ++++++++++++++++ .../src/META-INF/PlatformExtensions.xml | 3 ++ 4 files changed, 84 insertions(+), 5 deletions(-) create mode 100644 platform/platform-api/src/com/intellij/execution/process/ProcessHandlerFactory.java create mode 100644 platform/platform-impl/src/com/intellij/execution/process/ProcessHandlerFactoryImpl.java diff --git a/java/execution/openapi/src/com/intellij/execution/configurations/JavaCommandLineStateUtil.java b/java/execution/openapi/src/com/intellij/execution/configurations/JavaCommandLineStateUtil.java index 4917af0fdee8..7a70933d5027 100644 --- a/java/execution/openapi/src/com/intellij/execution/configurations/JavaCommandLineStateUtil.java +++ b/java/execution/openapi/src/com/intellij/execution/configurations/JavaCommandLineStateUtil.java @@ -16,14 +16,11 @@ package com.intellij.execution.configurations; import com.intellij.execution.ExecutionException; -import com.intellij.execution.process.ColoredProcessHandler; import com.intellij.execution.process.OSProcessHandler; +import com.intellij.execution.process.ProcessHandlerFactory; import com.intellij.execution.process.ProcessTerminatedListener; import org.jetbrains.annotations.NotNull; -/** - * @author spleaner - */ public class JavaCommandLineStateUtil { private JavaCommandLineStateUtil() { } @@ -34,7 +31,10 @@ public class JavaCommandLineStateUtil { @NotNull public static OSProcessHandler startProcess(@NotNull GeneralCommandLine commandLine, boolean ansiColoring) throws ExecutionException { - OSProcessHandler processHandler = ansiColoring ? new ColoredProcessHandler(commandLine) : new OSProcessHandler(commandLine); + ProcessHandlerFactory factory = ProcessHandlerFactory.getInstance(); + OSProcessHandler processHandler = ansiColoring ? + factory.createColoredProcessHandler(commandLine) : + factory.createProcessHandler(commandLine); ProcessTerminatedListener.attach(processHandler); return processHandler; } diff --git a/platform/platform-api/src/com/intellij/execution/process/ProcessHandlerFactory.java b/platform/platform-api/src/com/intellij/execution/process/ProcessHandlerFactory.java new file mode 100644 index 000000000000..d96602f4b277 --- /dev/null +++ b/platform/platform-api/src/com/intellij/execution/process/ProcessHandlerFactory.java @@ -0,0 +1,41 @@ +/* + * 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. + * 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.process; + +import com.intellij.execution.ExecutionException; +import com.intellij.execution.configurations.GeneralCommandLine; +import com.intellij.openapi.components.ServiceManager; +import org.jetbrains.annotations.NotNull; + +public abstract class ProcessHandlerFactory { + + public static ProcessHandlerFactory getInstance() { + return ServiceManager.getService(ProcessHandlerFactory.class); + } + + /** + * Returns a new instance of the {@link OSProcessHandler}. + */ + @NotNull + public abstract OSProcessHandler createProcessHandler(@NotNull GeneralCommandLine commandLine) throws ExecutionException; + + /** + * Returns a new instance of the {@link OSProcessHandler} which is aware of ANSI coloring output. + */ + @NotNull + public abstract OSProcessHandler createColoredProcessHandler(@NotNull GeneralCommandLine commandLine) throws ExecutionException; + +} diff --git a/platform/platform-impl/src/com/intellij/execution/process/ProcessHandlerFactoryImpl.java b/platform/platform-impl/src/com/intellij/execution/process/ProcessHandlerFactoryImpl.java new file mode 100644 index 000000000000..cec6541ce557 --- /dev/null +++ b/platform/platform-impl/src/com/intellij/execution/process/ProcessHandlerFactoryImpl.java @@ -0,0 +1,35 @@ +/* + * 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. + * 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.process; + +import com.intellij.execution.ExecutionException; +import com.intellij.execution.configurations.GeneralCommandLine; +import org.jetbrains.annotations.NotNull; + +public class ProcessHandlerFactoryImpl extends ProcessHandlerFactory { + + @NotNull + @Override + public OSProcessHandler createProcessHandler(@NotNull GeneralCommandLine commandLine) throws ExecutionException { + return new OSProcessHandler(commandLine); + } + + @Override + @NotNull + public OSProcessHandler createColoredProcessHandler(@NotNull GeneralCommandLine commandLine) throws ExecutionException { + return new ColoredProcessHandler(commandLine); + } +} diff --git a/platform/platform-resources/src/META-INF/PlatformExtensions.xml b/platform/platform-resources/src/META-INF/PlatformExtensions.xml index 7cf3e81acdaf..68bffee40e35 100644 --- a/platform/platform-resources/src/META-INF/PlatformExtensions.xml +++ b/platform/platform-resources/src/META-INF/PlatformExtensions.xml @@ -215,6 +215,9 @@ + +