Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

Commit

Permalink
Merge pull request #21 from d-wojciechowski/dev
Browse files Browse the repository at this point in the history
Release 0.7.1
  • Loading branch information
d-wojciechowski authored May 23, 2020
2 parents 7241e9c + c424577 commit 836113f
Show file tree
Hide file tree
Showing 24 changed files with 267 additions and 126 deletions.
8 changes: 4 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import com.google.protobuf.gradle.*
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

group = "pl.dwojciechowski"
version = "0.7.0"
val protobufVersion = "3.12.0"
version = "0.7.1"
val protobufVersion = "3.12.1"
val rsocketRpcVersion = "0.2.18"
val rsocketVersion = "1.0.0-RC7"
val coroutinesVersion = "1.3.6"
val coroutinesVersion = "1.3.7"
val fuelVersion = "2.2.2"
val rxJavaVersion = "3.0.3"
val rxJavaVersion = "3.0.4"

plugins {
id("com.github.ben-manes.versions") version "0.28.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class PluginConfiguration : PersistentStateComponent<PluginConfiguration> {

var scanWindchill: Boolean = false
var statusControlled: Boolean = true
var autoOpenCommandPane: Boolean = false

var port: Int = 80
var addonPort: Int = 4040
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package pl.dwojciechowski.execution

import com.intellij.execution.configurations.ConfigurationFactory
import com.intellij.execution.configurations.ConfigurationTypeBase
import pl.dwojciechowski.execution.command.RemoteCommandFactory
import pl.dwojciechowski.ui.PluginIcons

class RemoteCommandConfigType : ConfigurationTypeBase(
id = "PLMCompanion.RemoteCommand",
displayName = "Remote Command",
description = "Remote Command execution configuration",
icon = PluginIcons.PLUGIN
) {

override fun getConfigurationFactories(): Array<ConfigurationFactory> {
return arrayOf(RemoteCommandFactory(this))
}

}
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package pl.dwojciechowski.run.factory
package pl.dwojciechowski.execution.command

import com.intellij.execution.configurations.ConfigurationFactory
import com.intellij.execution.configurations.ConfigurationType
import com.intellij.openapi.project.Project
import pl.dwojciechowski.run.config.RemoteCommandConfigurationBase


class RemoteCommandFactory(configurationType: ConfigurationType) : ConfigurationFactory(configurationType) {

override fun createTemplateConfiguration(project: Project) =
RemoteCommandConfigurationBase(project, this, "")
RemoteCommandRunConfig(project, this, "")

override fun getId() = "PLM_COMPANION.REMOTE_COMMAND"

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package pl.dwojciechowski.execution.command

import com.intellij.execution.Executor
import com.intellij.execution.process.NopProcessHandler
import com.intellij.execution.runners.ExecutionEnvironment
import com.intellij.openapi.application.ApplicationManager
import pl.dwojciechowski.model.CommandBean
import pl.dwojciechowski.service.IdeControlService
import pl.dwojciechowski.service.RemoteService
import java.time.LocalTime

class RemoteCommandProcessHandler(
environment: ExecutionEnvironment,
private val executor: Executor?
) : NopProcessHandler() {

private val remoteServiceManager = RemoteService.getInstance(environment.project)
private val ideControlService = IdeControlService.getInstance(environment.project)
private val runProfile = environment.runProfile as RemoteCommandRunConfig

private val command = CommandBean(runProfile.settings.command, runProfile.settings.command, LocalTime.now())

override fun destroyProcess() {
super.destroyProcess()
switchToSelectedTab()
}

override fun startNotify() {
super.startNotify()
ApplicationManager.getApplication().invokeLater {
executeCommand()
}
}

private fun executeCommand() {
if (runProfile.settings.async.not()) {
ideControlService.switchToCommandTab()
remoteServiceManager.executeStreaming(command) {
destroyProcess()
}
} else {
remoteServiceManager.executeStreaming(command)
destroyProcess()
}
}

private fun switchToSelectedTab() {
ideControlService.getToolWindow(executor?.toolWindowId)
?.let { toolWindow ->
toolWindow.contentManager.selectedContent?.let {
toolWindow.contentManager.removeContent(it, true)
ideControlService.switchToCommandTab()
}
}
}


}
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
package pl.dwojciechowski.run.config
package pl.dwojciechowski.execution.command

import com.intellij.execution.Executor
import com.intellij.execution.configurations.ConfigurationFactory
import com.intellij.execution.configurations.RunConfiguration
import com.intellij.execution.configurations.RunConfigurationBase
import com.intellij.execution.configurations.RunProfileState
import com.intellij.execution.configurations.*
import com.intellij.execution.runners.ExecutionEnvironment
import com.intellij.openapi.options.SettingsEditor
import com.intellij.openapi.project.Project
import com.intellij.util.xmlb.XmlSerializer
import org.jdom.Element
import pl.dwojciechowski.run.editor.RemoteCommandSettingsEditor
import pl.dwojciechowski.run.state.RemoteCommandState

class RemoteCommandConfigurationBase(
class RemoteCommandRunConfig(
project: Project,
factory: ConfigurationFactory,
name: String
) : RunConfigurationBase<RemoteCommandConfigurationBase>(project, factory, name) {
) : RunConfigurationBase<RemoteCommandRunConfig>(project, factory, name) {

var settings = RemoteCommandSettings("")
var settings = RemoteCommandSettings()

override fun clone(): RunConfiguration {
val runConfiguration = super.clone()
(runConfiguration as RemoteCommandRunConfig).settings = RemoteCommandSettings()
return runConfiguration
}

override fun getConfigurationEditor(): SettingsEditor<out RunConfiguration> {
return RemoteCommandSettingsEditor(project)
Expand All @@ -30,17 +31,9 @@ class RemoteCommandConfigurationBase(
}

override fun checkConfiguration() {
}

data class RemoteCommandSettings(var command: String) : Cloneable {
companion object {
const val TAG = "RemoteCommandSettings"
if (settings.command.isEmpty()) {
throw RuntimeConfigurationWarning("Command may not be empty, provide non empty command")
}

/**
* For serialization
*/
constructor() : this(command = "")
}

override fun readExternal(element: Element) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package pl.dwojciechowski.execution.command

data class RemoteCommandSettings(
var command: String = "",
var async: Boolean = true
) : Cloneable {

companion object {
const val TAG = "RemoteCommandSettings"
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="pl.dwojciechowski.run.editor.RemoteCommandSettingsEditor">
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="pl.dwojciechowski.execution.command.RemoteCommandSettingsEditor">
<grid id="27dc6" binding="myPanel" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
Expand All @@ -8,7 +8,7 @@
<properties/>
<border type="none"/>
<children>
<grid id="a6219" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="a6219" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
Expand All @@ -26,7 +26,7 @@
</component>
<scrollpane id="6858f">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
Expand All @@ -37,6 +37,14 @@
</component>
</children>
</scrollpane>
<component id="bda0c" class="javax.swing.JCheckBox" binding="async">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Do not wait for finish"/>
</properties>
</component>
</children>
</grid>
<vspacer id="d4932">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package pl.dwojciechowski.run.editor
package pl.dwojciechowski.execution.command

import com.intellij.openapi.components.ServiceManager
import com.intellij.openapi.options.SettingsEditor
import com.intellij.openapi.project.Project
import pl.dwojciechowski.configuration.PluginConfiguration
import pl.dwojciechowski.model.CommandBean
import pl.dwojciechowski.run.config.RemoteCommandConfigurationBase
import pl.dwojciechowski.ui.component.CommandList
import javax.swing.*

class RemoteCommandSettingsEditor(private val project: Project) : SettingsEditor<RemoteCommandConfigurationBase>() {
class RemoteCommandSettingsEditor(project: Project) : SettingsEditor<RemoteCommandRunConfig>() {

private val config: PluginConfiguration = ServiceManager.getService(project, PluginConfiguration::class.java)

Expand All @@ -18,6 +17,7 @@ class RemoteCommandSettingsEditor(private val project: Project) : SettingsEditor
private lateinit var commandTF: JTextField
private lateinit var commandHistory: CommandList
private lateinit var listModel: DefaultListModel<CommandBean>
private lateinit var async: JCheckBox

private val splitPattern = "|#*#$"

Expand All @@ -41,17 +41,16 @@ class RemoteCommandSettingsEditor(private val project: Project) : SettingsEditor
}
}

override fun resetEditorFrom(s: RemoteCommandConfigurationBase) {
override fun resetEditorFrom(s: RemoteCommandRunConfig) {
commandTF.text = s.settings.command
async.isSelected = s.settings.async
}

override fun applyEditorTo(s: RemoteCommandConfigurationBase) {
override fun applyEditorTo(s: RemoteCommandRunConfig) {
s.settings.command = commandTF.text
s.settings.async = async.isSelected
}

override fun createEditor(): JComponent {
return myPanel
}

override fun createEditor() = myPanel

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package pl.dwojciechowski.execution.command

import com.intellij.execution.DefaultExecutionResult
import com.intellij.execution.ExecutionException
import com.intellij.execution.ExecutionResult
import com.intellij.execution.Executor
import com.intellij.execution.configurations.RunProfileState
import com.intellij.execution.runners.ExecutionEnvironment
import com.intellij.execution.runners.ProgramRunner

class RemoteCommandState(private val environment: ExecutionEnvironment) : RunProfileState {

private val runProfile = environment.runProfile as RemoteCommandRunConfig

override fun execute(executor: Executor?, runner: ProgramRunner<*>): ExecutionResult? {
if (runProfile.settings.command.isEmpty()) {
throw ExecutionException("Could not execute command, no command provided")
}
return DefaultExecutionResult(RemoteCommandProcessHandler(environment, executor))
}

}
6 changes: 3 additions & 3 deletions src/main/kotlin/pl/dwojciechowski/model/CommandBean.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import java.time.LocalTime
data class CommandBean(
var name: String,
var command: String,
var executionTime: LocalTime = LocalTime.MIN,
var executionTime: LocalTime = LocalTime.now(),
var status: ExecutionStatus = ExecutionStatus.NONE,
var response: ReplaySubject<String> = ReplaySubject.create(),
var actualSubscription: Disposable = Disposables.never()
) {
) : Cloneable {

override fun toString(): String {
return if (name.isNotEmpty()) name else command
Expand All @@ -25,7 +25,7 @@ data class CommandBean(
.build()
}

fun safeCopy() =
public override fun clone() =
CommandBean(name, command, LocalTime.now(), ExecutionStatus.NONE, ReplaySubject.create(), Disposables.never())

enum class ExecutionStatus {
Expand Down

This file was deleted.

41 changes: 0 additions & 41 deletions src/main/kotlin/pl/dwojciechowski/run/state/RemoteCommandState.kt

This file was deleted.

Loading

0 comments on commit 836113f

Please sign in to comment.