From ffd7109727c50c3906d85a24482cf984cfbc0d93 Mon Sep 17 00:00:00 2001 From: Eldar Abusalimov Date: Tue, 10 Nov 2020 15:48:45 +0300 Subject: [PATCH] CPP-22344: ElevationService: Extract and move interface to platform-api GitOrigin-RevId: 78b95bb87bcd61d84738d4e9d0a438986feec787 --- ...tionService.kt => ElevationServiceImpl.kt} | 21 +++++++---------- .../execution/process/ElevationService.java | 23 +++++++++++++++++++ .../intellij.platform.ide.impl.iml | 1 + .../src/META-INF/PlatformExtensions.xml | 6 ++++- 4 files changed, 37 insertions(+), 14 deletions(-) rename platform/elevation/src/com/intellij/execution/process/elevation/{ElevationService.kt => ElevationServiceImpl.kt} (86%) create mode 100644 platform/platform-api/src/com/intellij/execution/process/ElevationService.java diff --git a/platform/elevation/src/com/intellij/execution/process/elevation/ElevationService.kt b/platform/elevation/src/com/intellij/execution/process/elevation/ElevationServiceImpl.kt similarity index 86% rename from platform/elevation/src/com/intellij/execution/process/elevation/ElevationService.kt rename to platform/elevation/src/com/intellij/execution/process/elevation/ElevationServiceImpl.kt index a5af9123ce88..2bf15ff346bf 100644 --- a/platform/elevation/src/com/intellij/execution/process/elevation/ElevationService.kt +++ b/platform/elevation/src/com/intellij/execution/process/elevation/ElevationServiceImpl.kt @@ -3,6 +3,7 @@ package com.intellij.execution.process.elevation import com.intellij.execution.ExecutionException import com.intellij.execution.configurations.GeneralCommandLine +import com.intellij.execution.process.ElevationService import com.intellij.execution.process.SelfKiller import com.intellij.execution.process.elevation.settings.ElevationSettings import com.intellij.execution.process.mediator.MediatedProcessHandler @@ -11,30 +12,20 @@ import com.intellij.execution.process.mediator.client.MediatedProcess import com.intellij.execution.process.mediator.client.ProcessMediatorClient import com.intellij.execution.process.mediator.daemon.QuotaExceededException import com.intellij.openapi.Disposable -import com.intellij.openapi.components.Service -import com.intellij.openapi.components.service import com.intellij.openapi.util.Disposer -@Service -class ElevationService : Disposable { - companion object { - @JvmStatic - fun getInstance() = service() - - private const val MAX_RELAUNCHING_DAEMON_UNTIL_HAVE_QUOTA_PERMIT_ATTEMPTS = 3 - } - +class ElevationServiceImpl : ElevationService, Disposable { private val clientManager = ProcessMediatorClientManager().also { Disposer.register(this, it) } - fun createProcessHandler(commandLine: GeneralCommandLine): MediatedProcessHandler { + override fun createProcessHandler(commandLine: GeneralCommandLine): MediatedProcessHandler { val processBuilder = commandLine.toProcessBuilder() val process = createProcess(processBuilder) return MediatedProcessHandler(process, commandLine) } - fun createProcess(processBuilder: ProcessBuilder): MediatedProcess { + override fun createProcess(processBuilder: ProcessBuilder): MediatedProcess { return tryRelaunchingDaemonUntilHaveQuotaPermit { client -> object : MediatedProcess(client, processBuilder), SelfKiller { init { @@ -62,4 +53,8 @@ class ElevationService : Disposable { } override fun dispose() = Unit + + companion object { + private const val MAX_RELAUNCHING_DAEMON_UNTIL_HAVE_QUOTA_PERMIT_ATTEMPTS = 3 + } } diff --git a/platform/platform-api/src/com/intellij/execution/process/ElevationService.java b/platform/platform-api/src/com/intellij/execution/process/ElevationService.java new file mode 100644 index 000000000000..98e2d49bc5ba --- /dev/null +++ b/platform/platform-api/src/com/intellij/execution/process/ElevationService.java @@ -0,0 +1,23 @@ +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package com.intellij.execution.process; + +import com.intellij.execution.ExecutionException; +import com.intellij.execution.configurations.GeneralCommandLine; +import com.intellij.openapi.application.ApplicationManager; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; + +@ApiStatus.Experimental +public interface ElevationService { + static ElevationService getInstance() { + return ApplicationManager.getApplication().getService(ElevationService.class); + } + + @NotNull OSProcessHandler createProcessHandler(@NotNull GeneralCommandLine commandLine) throws ExecutionException; + + default @NotNull Process createProcess(@NotNull GeneralCommandLine commandLine) throws ExecutionException { + return createProcess(commandLine.toProcessBuilder()); + } + + @NotNull Process createProcess(@NotNull ProcessBuilder processBuilder) throws ExecutionException; +} diff --git a/platform/platform-impl/intellij.platform.ide.impl.iml b/platform/platform-impl/intellij.platform.ide.impl.iml index 344afdccf923..271968498d60 100644 --- a/platform/platform-impl/intellij.platform.ide.impl.iml +++ b/platform/platform-impl/intellij.platform.ide.impl.iml @@ -93,5 +93,6 @@ + \ No newline at end of file diff --git a/platform/platform-resources/src/META-INF/PlatformExtensions.xml b/platform/platform-resources/src/META-INF/PlatformExtensions.xml index f4d1dd2184ee..0b40830a6499 100644 --- a/platform/platform-resources/src/META-INF/PlatformExtensions.xml +++ b/platform/platform-resources/src/META-INF/PlatformExtensions.xml @@ -321,6 +321,10 @@ bundle="messages.CredentialStoreBundle" key="password.safe.configurable" id="application.passwordSafe"/> + + + @@ -329,7 +333,7 @@ - +