Skip to content

Commit

Permalink
Merge pull request #27 from bobi/master
Browse files Browse the repository at this point in the history
Fix compatibility issue for IDEA 2021.3.
  • Loading branch information
DenisKusakin authored Dec 24, 2021
2 parents 991baf9 + cce4423 commit a496c1b
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 33 deletions.
7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
buildscript {
ext.kotlin_version = '1.4.20'
ext.kotlin_version = '1.5.10'

repositories {
mavenCentral()
Expand All @@ -14,7 +14,7 @@ plugins {
}

group 'org.deniskusakin.aem'
version '0.2.8'
version '0.2.9'

apply plugin: 'kotlin'

Expand All @@ -36,10 +36,11 @@ compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
intellij {
version '2021.2'
version '2021.3'
}
patchPluginXml {
changeNotes """
Fix compatibility issue. Plugin is now available for IDEA 2021.2.
Fix compatibility issue. Plugin is now available for IDEA 2021.3.
"""
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package org.deniskusakin.aem.groovyconsoleplugin.actions

import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.components.ServiceManager
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.popup.PopupStep
import com.intellij.openapi.ui.popup.util.BaseListPopupStep
Expand All @@ -18,15 +17,15 @@ import org.deniskusakin.aem.groovyconsoleplugin.services.PersistentStateService
class AemGrSelectServerAction(private val project: Project, private val file: VirtualFile, private val serverName: String)
: AnAction(serverName, "AEM Server", Icons.AEM_ICON) {
override fun actionPerformed(e: AnActionEvent) {
val service = ServiceManager.getService(project, PersistentStateService::class.java)
val service = project.getService(PersistentStateService::class.java)
val component = e.inputEvent?.component ?: return
val step = object : BaseListPopupStep<String>("On which server the script should be applied?", service.getAEMServers().map { it.name }) {
override fun onChosen(selectedValue: String?, finalChoice: Boolean): PopupStep<*>? {
file.putUserData(GROOVY_CONSOLE_CURRENT_SERVER, selectedValue)
return null
}
}
val popup = ListPopupImpl(step)
val popup = ListPopupImpl(project, step)
popup.showUnderneathOf(component)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import com.intellij.openapi.util.IconLoader
* @author Denis_Kusakin. 6/29/2018.
*/
object Icons {
val AEM_ICON = IconLoader.getIcon("/icons/aem_16x16.png")
val GROOVY_ICON = IconLoader.getIcon("/icons/groovy_16x16.png")
val AEM_ICON = IconLoader.getIcon("/icons/aem_16x16.png", Icons::class.java)
val GROOVY_ICON = IconLoader.getIcon("/icons/groovy_16x16.png", Icons::class.java)
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,16 @@ class AemServersConfigurable(val project: Project) : Configurable {
return Pair(panel, editor)
}

override fun getDisplayName(): String? {
override fun getDisplayName(): String {
return "AEM Servers"
}

override fun createComponent(): JComponent? {
override fun createComponent(): JComponent {
return component
}

override fun isModified(): Boolean {
val service = ServiceManager.getService(project, PersistentStateService::class.java)
val service = project.getService(PersistentStateService::class.java)
val persistedData = service.getAEMServers()
val actualData: List<AemServerConfigUI> = getDataFromEditors()
val isModified = actualData != persistedData.map { it.toUIRepresentation() }
Expand All @@ -154,7 +154,7 @@ class AemServersConfigurable(val project: Project) : Configurable {
}

override fun apply() {
val service = ServiceManager.getService(project, PersistentStateService::class.java)
val service = project.getService(PersistentStateService::class.java)
service.setAEMServers(getDataFromEditors().map { it.toAemServerConfig() })
project.messageBus.syncPublisher(SettingsChangedNotifier.TOPIC).settingsChanged()
}
Expand Down Expand Up @@ -187,7 +187,7 @@ class AemServersConfigurable(val project: Project) : Configurable {
}

override fun reset() {
val service = ServiceManager.getService(project, PersistentStateService::class.java)
val service = project.getService(PersistentStateService::class.java)
resetData(service.getAEMServers().map { it.toUIRepresentation() })
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package org.deniskusakin.aem.groovyconsoleplugin.console
import com.github.kittinunf.fuel.Fuel
import com.github.kittinunf.result.Result
import com.google.gson.Gson
import com.intellij.execution.ExecutionManager
import com.intellij.execution.executors.DefaultRunExecutor
import com.intellij.execution.filters.RegexpFilter
import com.intellij.execution.filters.RegexpFilter.FILE_PATH_MACROS
Expand All @@ -12,13 +11,13 @@ import com.intellij.execution.filters.TextConsoleBuilderFactory
import com.intellij.execution.ui.ConsoleView
import com.intellij.execution.ui.ConsoleViewContentType
import com.intellij.execution.ui.RunContentDescriptor
import com.intellij.execution.ui.RunContentManager
import com.intellij.execution.ui.actions.CloseAction
import com.intellij.icons.AllIcons
import com.intellij.openapi.actionSystem.ActionManager
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.DefaultActionGroup
import com.intellij.openapi.components.ServiceManager
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.Key
import com.intellij.openapi.vfs.VirtualFile
Expand Down Expand Up @@ -86,13 +85,13 @@ class AEMGroovyConsole(val project: Project, val descriptor: RunContentDescripto
val ui = descriptor.component
ui.add(consoleViewComponent, BorderLayout.CENTER)
ui.add(toolbar.component, BorderLayout.WEST)
ExecutionManager.getInstance(project).getContentManager().showRunContent(defaultExecutor, descriptor)
RunContentManager.getInstance(project).showRunContent(defaultExecutor, descriptor)
return console
}

private fun VirtualFile.getConsole(serverName: String): AEMGroovyConsole? {
val console = getUserData(GROOVY_CONSOLE)?.get(serverName) ?: return null
if (ExecutionManager.getInstance(console.project).getContentManager().allDescriptors.contains(console.descriptor)) {
if (RunContentManager.getInstance(console.project).allDescriptors.contains(console.descriptor)) {
return console
}
//TODO: In default Groovy Console implementation this somehow works without such hack
Expand All @@ -112,14 +111,14 @@ class AEMGroovyConsole(val project: Project, val descriptor: RunContentDescripto
}

fun execute(scriptContent: String) {
val service = ServiceManager.getService(project, PersistentStateService::class.java)
val service = project.getService(PersistentStateService::class.java)
val currentServerInfo = service.getAEMServers().find { it.name == serverName }
val login = currentServerInfo!!.login
val password = currentServerInfo.password
val serverHost = currentServerInfo.url
view.clear()
view.print("\nRunning script on $serverName\n\n", ConsoleViewContentType.LOG_WARNING_OUTPUT)
ExecutionManager.getInstance(project).getContentManager().toFrontRunContent(defaultExecutor, descriptor)
RunContentManager.getInstance(project).toFrontRunContent(defaultExecutor, descriptor)

Fuel.post("$serverHost/bin/groovyconsole/post.json", listOf(Pair("script", scriptContent)))
.timeout(NETWORK_TIMEOUT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package org.deniskusakin.aem.groovyconsoleplugin.console
import com.intellij.openapi.actionSystem.ActionManager
import com.intellij.openapi.actionSystem.CommonShortcuts
import com.intellij.openapi.actionSystem.DefaultActionGroup
import com.intellij.openapi.components.ServiceManager
import com.intellij.openapi.editor.impl.EditorHeaderComponent
import com.intellij.openapi.fileEditor.FileEditor
import com.intellij.openapi.options.ShowSettingsUtil
Expand Down Expand Up @@ -40,7 +39,7 @@ class EditorDecorator(private val project: Project) : EditorNotifications.Provid
if (file.extension != "groovy" || !AemGroovyScriptsDetectionService.isAemGroovyFile(file.path, project))
return null

val service = ServiceManager.getService(project, PersistentStateService::class.java)
val service = project.getService(PersistentStateService::class.java)
val serverFromFile = file.getUserData(AEMGroovyConsole.GROOVY_CONSOLE_CURRENT_SERVER)
val availableServerNames = service.getAEMServers().map { it.name }
val currentServerName =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import com.intellij.execution.configurations.*
import com.intellij.execution.process.OSProcessHandler
import com.intellij.execution.process.ProcessHandler
import com.intellij.execution.runners.ExecutionEnvironment
import com.intellij.openapi.components.ServiceManager
import com.intellij.openapi.options.SettingsEditor
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.JDOMExternalizer
Expand All @@ -22,7 +21,7 @@ class AemGroovyRunConfiguration(project: Project, factory: ConfigurationFactory,
var serverName: String? = null
set(value) {
field = value
val service = ServiceManager.getService(project, PersistentStateService::class.java)
val service = project.getService(PersistentStateService::class.java)
val serverInfo = service.getAEMServers().find { it.name == value }
serverUrl = serverInfo?.url
login = serverInfo?.login
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@ package org.deniskusakin.aem.groovyconsoleplugin.run.configuration

import com.intellij.execution.actions.ConfigurationContext
import com.intellij.execution.actions.RunConfigurationProducer
import com.intellij.openapi.components.ServiceManager
import com.intellij.openapi.util.Ref
import com.intellij.psi.PsiElement
import org.deniskusakin.aem.groovyconsoleplugin.services.PersistentStateService

class AemGroovyRunConfigurationProducer private constructor() : RunConfigurationProducer<AemGroovyRunConfiguration>(AemGroovyConfigurationType()) {

override fun isConfigurationFromContext(configuration: AemGroovyRunConfiguration, context: ConfigurationContext): Boolean {
val service = ServiceManager.getService(context.project, PersistentStateService::class.java)
val service = context.project.getService(PersistentStateService::class.java)
val firstServerFromGlobalConfig = service.getAEMServers().firstOrNull()

return context.location?.virtualFile?.path == configuration.scriptPath && configuration.serverName == firstServerFromGlobalConfig?.name
}

override fun setupConfigurationFromContext(configuration: AemGroovyRunConfiguration, context: ConfigurationContext, sourceElement: Ref<PsiElement>): Boolean {
val service = ServiceManager.getService(context.project, PersistentStateService::class.java)
val service = context.project.getService(PersistentStateService::class.java)
val firstServerFromGlobalConfig = service.getAEMServers().firstOrNull()
if (true && firstServerFromGlobalConfig != null) {
configuration.scriptPath = context.location?.virtualFile?.path
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
package org.deniskusakin.aem.groovyconsoleplugin.run.configuration

import com.intellij.openapi.components.ServiceManager
import com.intellij.openapi.fileChooser.FileChooserDescriptor
import com.intellij.openapi.options.ConfigurationException
import com.intellij.openapi.options.SettingsEditor
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.ComboBox
import com.intellij.openapi.ui.TextFieldWithBrowseButton
import com.intellij.ui.CollectionComboBoxModel
import com.intellij.ui.layout.CCFlags
import com.intellij.ui.layout.panel
import org.deniskusakin.aem.groovyconsoleplugin.services.PersistentStateService

import javax.swing.*
import javax.swing.JComponent
import javax.swing.JPanel

class AemGroovySettingsEditor(private val project: Project) : SettingsEditor<AemGroovyRunConfiguration>() {
private var contentPane: JPanel
private val scriptPath: TextFieldWithBrowseButton = TextFieldWithBrowseButton()
private val service = ServiceManager.getService(project, PersistentStateService::class.java)
private val service = project.getService(PersistentStateService::class.java)
private val items = service.getAEMServers().map { it.name } + ""
private val aemServerComboBox = ComboBox<String>(items.toTypedArray())
private val aemServerComboBox = ComboBox(items.toTypedArray())

init {
// aemServerComboBox.model = CollectionComboBoxModel(items)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class RootFoldersService : PersistentStateComponent<RootFoldersService.State> {

companion object {
fun getInstance(project: Project): RootFoldersService? {
return ServiceManager.getService(project, RootFoldersService::class.java)
return project.getService(RootFoldersService::class.java)
}
}
}

0 comments on commit a496c1b

Please sign in to comment.