Skip to content
This repository was archived by the owner on May 8, 2024. It is now read-only.

Commit e0c5a33

Browse files
merge: resolve merge conflict
Signed-off-by: Matheus Ferreira <matheus.ferreira@zup.com.br>
2 parents ecae110 + bf12668 commit e0c5a33

File tree

20 files changed

+921
-38
lines changed

20 files changed

+921
-38
lines changed

build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ fun properties(key: String) = project.findProperty(key).toString()
66
plugins {
77
id("java")
88
id("jacoco")
9-
id("org.jetbrains.kotlin.jvm") version "1.7.10"
10-
id("org.jetbrains.intellij") version "1.8.0"
9+
id("org.jetbrains.kotlin.jvm") version "1.7.20"
10+
id("org.jetbrains.intellij") version "1.9.0"
1111
id("org.sonarqube") version "3.4.0.2513"
1212

1313
// Gradle Changelog Plugin

src/main/kotlin/com/stackspot/intellij/commands/BackgroundCommandRunner.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class BackgroundCommandRunner : CommandRunner {
5454
override fun runSync(commandLine: List<String>, workingDir: String?): BackgroundCommandRunner {
5555
return singleThread {
5656
var done = false
57-
this.run(commandLine, object : CommandRunner.CommandEndedListener {
57+
run(commandLine, object : CommandRunner.CommandEndedListener {
5858
override fun notifyEnded() {
5959
done = true
6060
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright 2022 ZUP IT SERVICOS EM TECNOLOGIA E INOVACAO SA
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.stackspot.intellij.commands.listeners
18+
19+
import com.stackspot.intellij.commands.CommandRunner
20+
import com.stackspot.intellij.ui.toolwindow.AbstractStackSpotTree
21+
22+
class NotifyStackSpotToolWindow(private val tree: AbstractStackSpotTree) : CommandRunner.CommandEndedListener {
23+
override fun notifyEnded() {
24+
tree.notifyChange()
25+
}
26+
}

src/main/kotlin/com/stackspot/intellij/commands/stk/ApplyPlugin.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ import com.stackspot.model.Stack
2525
class ApplyPlugin(
2626
private val stack: Stack,
2727
private val plugin: Plugin,
28-
project: Project
28+
project: Project,
29+
private val inputFlags: Array<String> = arrayOf()
2930
) : BaseCommand(StackSpotTerminalRunner(project)) {
3031

31-
override fun commandLine() = listOf("stk", "apply", "plugin", "${stack.name}/${plugin.name}")
32+
override fun commandLine() = listOf("stk", "apply", "plugin", "${stack.name}/${plugin.name}", *inputFlags)
3233
}

src/main/kotlin/com/stackspot/intellij/services/StackSpotToolWindowService.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class StackSpotToolWindowService {
3030
var project: Project? = null
3131
var history: History? = null
3232
var template: AppliedTemplate? = null
33-
var appliedPlugins: List<AppliedTemplate> = ArrayList<AppliedTemplate>(0)
33+
var appliedPlugins: List<AppliedTemplate> = ArrayList(0)
3434

3535
fun reloadProjectData() {
3636
val p = project
@@ -58,4 +58,10 @@ class StackSpotToolWindowService {
5858
appliedPlugins = appliedTemplates.subList(1, appliedTemplates.size)
5959
}
6060
}
61+
62+
fun pluginsOrTemplatesNotApplied(plugins: List<String>? = null): List<String> {
63+
return plugins
64+
?.filter { p -> appliedPlugins.none { ap -> ap.templateDataPath == p } && p != template?.templateDataPath }
65+
?.toList() ?: listOf()
66+
}
6167
}

src/main/kotlin/com/stackspot/intellij/ui/Icons.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,7 @@ object Icons {
5151

5252
@JvmField
5353
val WARNING = IconLoader.getIcon("/images/warning.svg", javaClass)
54+
55+
@JvmField
56+
val DEPENDENCY_WARNING = IconLoader.getIcon("/images/dependency_warning.svg", javaClass)
5457
}

src/main/kotlin/com/stackspot/intellij/ui/toolwindow/AvailablePluginsTreeNode.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ class AvailablePluginsTreeNode(private val service: StackSpotToolWindowService)
3535
val stackNode = StackSpotTreeNode(stack, null, stack, null)
3636
add(stackNode)
3737
plugins.forEach { plugin ->
38-
val pluginNode = StackSpotTreeNode(plugin, null, stack, plugin)
38+
val pluginsNotApplied = service.pluginsOrTemplatesNotApplied(plugin.requirements)
39+
val icon = if (pluginsNotApplied.isNotEmpty()) Icons.DEPENDENCY_WARNING else null
40+
val pluginNode = StackSpotTreeNode(plugin, icon, stack, plugin, pluginsNotApplied)
3941
stackNode.add(pluginNode)
4042
}
4143
}

src/main/kotlin/com/stackspot/intellij/ui/toolwindow/StackSpotCellRenderer.kt

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,27 @@
1616

1717
package com.stackspot.intellij.ui.toolwindow
1818

19+
import com.intellij.openapi.ui.Messages
1920
import com.intellij.openapi.util.IconLoader
2021
import com.intellij.ui.ColorUtil
2122
import com.intellij.util.ui.UIUtil
22-
import com.stackspot.intellij.commands.CommandRunner
23+
import com.stackspot.intellij.commands.listeners.NotifyStackSpotToolWindow
2324
import com.stackspot.intellij.commands.listeners.NotifyStacksUpdatedCommandListener
2425
import com.stackspot.intellij.commands.stk.ApplyPlugin
2526
import com.stackspot.intellij.commands.stk.DeleteStack
2627
import com.stackspot.intellij.commands.stk.UpdateStack
2728
import com.stackspot.intellij.ui.Icons
29+
import com.stackspot.intellij.ui.toolwindow.panels.PluginInputsPanel
2830
import java.awt.BorderLayout
2931
import java.awt.Color
3032
import java.awt.Component
3133
import java.awt.Dimension
3234
import javax.swing.*
3335
import javax.swing.tree.DefaultTreeCellRenderer
3436

37+
private const val COULD_NOT_APPLY_PLUGIN = "Could not apply plugin"
38+
private const val PLUGIN_HAS_DEPENDENCY = "This plugin has dependencies. First, apply these before proceeding:"
39+
3540
class StackSpotCellRenderer(val tree: AbstractStackSpotTree) : DefaultTreeCellRenderer() {
3641

3742
private val panel = object : JPanel() {
@@ -106,18 +111,29 @@ class StackSpotCellRenderer(val tree: AbstractStackSpotTree) : DefaultTreeCellRe
106111
): JButton {
107112
val button = createButton("Apply Plugin", getIcon(Icons.APPLY_PLUGIN, selected, true))
108113
button.addActionListener {
114+
if (stackSpotNode.hasPluginDependency()) {
115+
val requirements = stackSpotNode.pluginsNotAppliedToString()
116+
Messages.showWarningDialog("$PLUGIN_HAS_DEPENDENCY\n$requirements", COULD_NOT_APPLY_PLUGIN)
117+
return@addActionListener
118+
}
119+
109120
val stackSpotTree = (tree as AbstractStackSpotTree)
110121
val project = stackSpotTree.service.project
122+
111123
if (stackSpotNode.stack != null && stackSpotNode.plugin != null && project != null) {
112-
ApplyPlugin(
113-
stackSpotNode.stack,
114-
stackSpotNode.plugin,
115-
project,
116-
).run(object : CommandRunner.CommandEndedListener {
117-
override fun notifyEnded() {
118-
stackSpotTree.notifyChange()
124+
if (stackSpotNode.plugin.inputs != null) {
125+
val title = "${stackSpotNode.stack}/${stackSpotNode.plugin}"
126+
val pluginInputPanel = PluginInputsPanel(project, stackSpotNode.plugin, title)
127+
val isOkExit = pluginInputPanel.showAndGet()
128+
if (isOkExit) {
129+
val inputValueAsFlags = extractVarsToCmd(pluginInputPanel.variablesMap)
130+
val applyPluginCmd =
131+
ApplyPlugin(stackSpotNode.stack, stackSpotNode.plugin, project, inputValueAsFlags)
132+
applyPluginCmd.run(NotifyStackSpotToolWindow(tree))
119133
}
120-
})
134+
} else {
135+
ApplyPlugin(stackSpotNode.stack, stackSpotNode.plugin, project).run(NotifyStackSpotToolWindow(tree))
136+
}
121137
}
122138
}
123139
return button
@@ -130,18 +146,22 @@ class StackSpotCellRenderer(val tree: AbstractStackSpotTree) : DefaultTreeCellRe
130146
}
131147

132148
private fun getLabelForeground(selected: Boolean, focused: Boolean): Color {
133-
if (UIUtil.isUnderIntelliJLaF()) {
134-
if (!selected && focused || selected && !focused) {
135-
return UIUtil.getTreeForeground(true, true)
136-
}
149+
if (UIUtil.isUnderIntelliJLaF() && (!selected && focused || selected && !focused)) {
150+
return UIUtil.getTreeForeground(true, true)
137151
}
138152
return UIUtil.getTreeForeground(selected, focused)
139153
}
140154

141155
private fun createIcon(stackSpotNode: StackSpotTreeNode, selected: Boolean, focused: Boolean) {
142156
if (stackSpotNode.icon != null) {
143157
val icon = getIcon(stackSpotNode.icon, selected, focused)
144-
panel.add(JLabel(icon), BorderLayout.WEST)
158+
val jLabel = JLabel(icon)
159+
if (stackSpotNode.plugin != null && stackSpotNode.hasPluginDependency()) {
160+
jLabel.toolTipText =
161+
"This plugin has dependencies. First, apply these before proceeding: <br>" +
162+
"${stackSpotNode.pluginsNotAppliedToString(isHtml = true)}"
163+
}
164+
panel.add(jLabel, BorderLayout.WEST)
145165
}
146166
}
147167

@@ -200,4 +220,17 @@ class StackSpotCellRenderer(val tree: AbstractStackSpotTree) : DefaultTreeCellRe
200220
button.isContentAreaFilled = false
201221
return button
202222
}
223+
224+
private fun extractVarsToCmd(varsMap: Map<String, Any>): Array<String> {
225+
val args = mutableListOf<String>()
226+
varsMap.forEach { (key, value) ->
227+
if (value is Set<*>) {
228+
value.forEach { elem -> args.add("--$key $elem") }
229+
} else {
230+
args.add("--$key $value")
231+
}
232+
}
233+
234+
return args.toTypedArray()
235+
}
203236
}

src/main/kotlin/com/stackspot/intellij/ui/toolwindow/StackSpotTreeNode.kt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,19 @@ open class StackSpotTreeNode(
2626
val icon: Icon? = null,
2727
val stack: Stack? = null,
2828
val plugin: Plugin? = null,
29-
) : DefaultMutableTreeNode(userObject)
29+
private val pluginsNotApplied: List<String>? = null
30+
) : DefaultMutableTreeNode(userObject) {
31+
32+
fun hasPluginDependency(): Boolean {
33+
return pluginsNotApplied?.isNotEmpty() ?: false
34+
}
35+
36+
fun pluginsNotAppliedToString(isHtml: Boolean = false): StringBuilder {
37+
val newLine = if (isHtml) "<br>" else "\n"
38+
val stringBuilder = StringBuilder()
39+
pluginsNotApplied?.forEach { pa ->
40+
stringBuilder.append("- $pa $newLine")
41+
}
42+
return stringBuilder
43+
}
44+
}

0 commit comments

Comments
 (0)