forked from JetBrains-Research/paddle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement initial "Run Configurations" support
Fix PaddleProjectResolver, WIP with deps Adjust icons and naming
- Loading branch information
Oleg Smirnov
committed
May 24, 2022
1 parent
d0006cd
commit 42d1580
Showing
21 changed files
with
617 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
idea/src/main/kotlin/io/paddle/idea/execution/PaddleBeforeRunTaskProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package io.paddle.idea.execution | ||
|
||
import com.intellij.execution.configurations.RunConfiguration | ||
import com.intellij.openapi.externalSystem.service.execution.ExternalSystemBeforeRunTask | ||
import com.intellij.openapi.externalSystem.service.execution.ExternalSystemBeforeRunTaskProvider | ||
import com.intellij.openapi.project.DumbAware | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.util.Key | ||
import icons.PythonIcons | ||
import io.paddle.idea.PaddleManager | ||
import javax.swing.Icon | ||
|
||
class PaddleBeforeRunTaskProvider(project: Project) : ExternalSystemBeforeRunTaskProvider(PaddleManager.ID, project, ID), DumbAware { | ||
companion object { | ||
val ID = Key.create<ExternalSystemBeforeRunTask>("Paddle.BeforeRunTask") | ||
} | ||
|
||
override fun getIcon(): Icon { | ||
return PythonIcons.Python.Python | ||
} | ||
|
||
override fun getTaskIcon(task: ExternalSystemBeforeRunTask?): Icon { | ||
return PythonIcons.Python.Python | ||
} | ||
|
||
override fun createTask(runConfiguration: RunConfiguration): ExternalSystemBeforeRunTask { | ||
return ExternalSystemBeforeRunTask(ID, PaddleManager.ID) | ||
} | ||
} |
28 changes: 12 additions & 16 deletions
28
...dea/runner/PaddleTaskConfigurationType.kt → ...on/PaddleExternalTaskConfigurationType.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,31 @@ | ||
package io.paddle.idea.runner | ||
package io.paddle.idea.execution | ||
|
||
import com.intellij.execution.configurations.ConfigurationFactory | ||
import com.intellij.openapi.externalSystem.model.ProjectSystemId | ||
import com.intellij.openapi.externalSystem.service.execution.AbstractExternalSystemTaskConfigurationType | ||
import com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration | ||
import com.intellij.openapi.externalSystem.util.ExternalSystemUtil | ||
import com.intellij.openapi.project.Project | ||
import io.paddle.idea.PaddleManager | ||
|
||
class PaddleTaskConfigurationType : AbstractExternalSystemTaskConfigurationType(PaddleManager.ID) { | ||
override fun getConfigurationFactoryId() = "Paddle" | ||
|
||
override fun isDumbAware(): Boolean { | ||
return true | ||
} | ||
|
||
override fun isEditableInDumbMode(): Boolean { | ||
return true | ||
class PaddleExternalTaskConfigurationType : AbstractExternalSystemTaskConfigurationType(PaddleManager.ID) { | ||
companion object { | ||
fun getInstance(): PaddleExternalTaskConfigurationType { | ||
return ExternalSystemUtil.findConfigurationType(PaddleManager.ID) as PaddleExternalTaskConfigurationType | ||
} | ||
} | ||
|
||
override fun doCreateConfiguration( | ||
externalSystemId: ProjectSystemId, | ||
project: Project, | ||
factory: ConfigurationFactory, | ||
name: String | ||
): ExternalSystemRunConfiguration { | ||
): PaddleRunConfiguration { | ||
return PaddleRunConfiguration(project, factory, name) | ||
} | ||
|
||
companion object { | ||
val instance: PaddleTaskConfigurationType | ||
get() = ExternalSystemUtil.findConfigurationType(PaddleManager.ID) as PaddleTaskConfigurationType | ||
} | ||
override fun getConfigurationFactoryId(): String = "Paddle" | ||
|
||
override fun isDumbAware(): Boolean = true | ||
|
||
override fun isEditableInDumbMode(): Boolean = true | ||
} |
61 changes: 61 additions & 0 deletions
61
idea/src/main/kotlin/io/paddle/idea/execution/PaddleProjectTaskRunner.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package io.paddle.idea.execution | ||
|
||
import com.intellij.build.BuildViewManager | ||
import com.intellij.execution.executors.DefaultRunExecutor | ||
import com.intellij.openapi.diagnostic.Logger | ||
import com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration | ||
import com.intellij.openapi.externalSystem.service.execution.ProgressExecutionMode | ||
import com.intellij.openapi.externalSystem.task.TaskCallback | ||
import com.intellij.openapi.externalSystem.util.ExternalSystemUtil | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.util.UserDataHolderBase | ||
import com.intellij.task.* | ||
import io.paddle.idea.PaddleManager | ||
import org.jetbrains.concurrency.AsyncPromise | ||
import org.jetbrains.concurrency.Promise | ||
import java.util.concurrent.atomic.AtomicInteger | ||
|
||
@Suppress("UnstableApiUsage") | ||
class PaddleProjectTaskRunner : ProjectTaskRunner() { | ||
private val logger = Logger.getInstance(PaddleProjectTaskRunner::class.java) | ||
|
||
override fun canRun(projectTask: ProjectTask): Boolean = true | ||
|
||
override fun run(project: Project, context: ProjectTaskContext, vararg tasks: ProjectTask): Promise<Result> { | ||
val resultPromise = AsyncPromise<Result>() | ||
val executionSettingsBuilder = PaddleTasksExecutionSettingsBuilder(project, tasks.toList()) | ||
val rootProjectPath = project.basePath | ||
?: return resultPromise.also { | ||
logger.warn("Nothing will be run for: " + tasks.contentToString()) | ||
resultPromise.setResult(TaskRunnerResults.SUCCESS) | ||
} | ||
val settings = executionSettingsBuilder.build(rootProjectPath) | ||
val userData = UserDataHolderBase() | ||
userData.putUserData(ExternalSystemRunConfiguration.PROGRESS_LISTENER_KEY, BuildViewManager::class.java) | ||
|
||
val errorCounter = AtomicInteger() | ||
|
||
val taskCallback = object : TaskCallback { | ||
override fun onSuccess() { | ||
handle(true) | ||
} | ||
|
||
override fun onFailure() { | ||
handle(false) | ||
} | ||
|
||
private fun handle(success: Boolean) { | ||
val errors: Int = if (success) errorCounter.get() else errorCounter.incrementAndGet() | ||
resultPromise.setResult(if (errors > 0) TaskRunnerResults.FAILURE else TaskRunnerResults.SUCCESS) | ||
} | ||
} | ||
|
||
ExternalSystemUtil.runTask( | ||
settings, DefaultRunExecutor.EXECUTOR_ID, project, PaddleManager.ID, | ||
taskCallback, ProgressExecutionMode.IN_BACKGROUND_ASYNC, false, userData | ||
) | ||
|
||
return resultPromise | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
idea/src/main/kotlin/io/paddle/idea/execution/PaddleRunConfigurationExtension.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package io.paddle.idea.execution | ||
|
||
import com.intellij.openapi.externalSystem.service.execution.configuration.* | ||
import com.intellij.openapi.externalSystem.service.ui.project.path.ExternalSystemWorkingDirectoryInfo | ||
import com.intellij.openapi.externalSystem.service.ui.project.path.WorkingDirectoryField | ||
import com.intellij.openapi.project.Project | ||
import io.paddle.idea.PaddleManager | ||
import io.paddle.idea.execution.cmd.PaddleCommandLineInfo | ||
|
||
class PaddleRunConfigurationExtension | ||
: ExternalSystemReifiedRunConfigurationExtension<PaddleRunConfiguration>(PaddleRunConfiguration::class.java) { | ||
|
||
override fun SettingsFragmentsContainer<PaddleRunConfiguration>.configureFragments(configuration: PaddleRunConfiguration) { | ||
val project = configuration.project | ||
addBeforeRunFragment(PaddleBeforeRunTaskProvider.ID) | ||
val workingDirectoryField = addWorkingDirectoryFragment(project).component().component | ||
addCommandLineFragment(project, workingDirectoryField) | ||
} | ||
|
||
private fun SettingsFragmentsContainer<PaddleRunConfiguration>.addWorkingDirectoryFragment( | ||
project: Project | ||
) = addWorkingDirectoryFragment( | ||
project = project, | ||
workingDirectoryInfo = ExternalSystemWorkingDirectoryInfo(project, PaddleManager.ID) | ||
) | ||
|
||
private fun SettingsFragmentsContainer<PaddleRunConfiguration>.addCommandLineFragment( | ||
project: Project, | ||
workingDirectoryField: WorkingDirectoryField | ||
) = addCommandLineFragment( | ||
project = project, | ||
commandLineInfo = PaddleCommandLineInfo(project, workingDirectoryField), | ||
getCommandLine = { rawCommandLine }, | ||
setCommandLine = { rawCommandLine = it } | ||
) | ||
} |
33 changes: 33 additions & 0 deletions
33
idea/src/main/kotlin/io/paddle/idea/execution/PaddleRunConfigurationImporter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package io.paddle.idea.execution | ||
|
||
import com.intellij.execution.configurations.ConfigurationFactory | ||
import com.intellij.execution.configurations.RunConfiguration | ||
import com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider | ||
import com.intellij.openapi.externalSystem.service.project.settings.RunConfigurationImporter | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.util.ObjectUtils | ||
|
||
class PaddleRunConfigurationImporter : RunConfigurationImporter { | ||
override fun canImport(typeName: String): Boolean = typeName == "paddle" | ||
|
||
override fun getConfigurationFactory(): ConfigurationFactory = PaddleExternalTaskConfigurationType.getInstance().factory | ||
|
||
override fun process( | ||
project: Project, | ||
runConfiguration: RunConfiguration, | ||
cfg: MutableMap<String, Any>, | ||
modelsProvider: IdeModifiableModelsProvider | ||
) { | ||
if (runConfiguration !is PaddleRunConfiguration) { | ||
return | ||
} | ||
|
||
val settings = runConfiguration.settings | ||
|
||
ObjectUtils.consumeIfCast(cfg["projectPath"], String::class.java) { settings.externalProjectPath = it } | ||
ObjectUtils.consumeIfCast(cfg["taskNames"], List::class.java) { settings.taskNames = it as List<String> } | ||
ObjectUtils.consumeIfCast(cfg["envs"], Map::class.java) { settings.env = it as Map<String, String> } | ||
ObjectUtils.consumeIfCast(cfg["jvmArgs"], String::class.java) { settings.vmOptions = it } | ||
ObjectUtils.consumeIfCast(cfg["scriptParameters"], String::class.java) { settings.scriptParameters = it } | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
idea/src/main/kotlin/io/paddle/idea/execution/PaddleRuntimeConfigurationProducer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package io.paddle.idea.execution | ||
|
||
import com.intellij.execution.configurations.ConfigurationFactory | ||
import com.intellij.openapi.externalSystem.service.execution.AbstractExternalSystemRunConfigurationProducer | ||
|
||
class PaddleRuntimeConfigurationProducer : AbstractExternalSystemRunConfigurationProducer() { | ||
override fun getConfigurationFactory(): ConfigurationFactory { | ||
return PaddleExternalTaskConfigurationType.getInstance().factory | ||
} | ||
} |
Oops, something went wrong.