generated from JetBrains/intellij-platform-plugin-template
-
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.
- Loading branch information
Showing
13 changed files
with
295 additions
and
113 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
20 changes: 0 additions & 20 deletions
20
src/main/kotlin/com/github/jbou/ideaundelegaterun/MyBundle.kt
This file was deleted.
Oops, something went wrong.
117 changes: 117 additions & 0 deletions
117
src/main/kotlin/com/github/jbou/ideaundelegaterun/ProjectPlugin.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,117 @@ | ||
package com.github.jbou.ideaundelegaterun | ||
|
||
import com.intellij.execution.configurations.RunProfile | ||
import com.intellij.openapi.components.PersistentStateComponent | ||
import com.intellij.openapi.components.State | ||
import com.intellij.openapi.components.Storage | ||
import com.intellij.openapi.diagnostic.Logger | ||
import com.intellij.openapi.module.Module | ||
import java.util.regex.Pattern | ||
import java.util.regex.PatternSyntaxException | ||
|
||
@State(name = "undelegate-run", reloadable = true, storages = [Storage("undelegate-run.xml")]) | ||
class ProjectPlugin : PersistentStateComponent<ProjectPlugin.State> { | ||
private val stateLock = Any() | ||
private var state: State? = null | ||
|
||
init { | ||
synchronized(stateLock) { | ||
state = State() | ||
} | ||
} | ||
|
||
override fun getState(): State { | ||
synchronized(stateLock) { | ||
return State(state) | ||
} | ||
} | ||
|
||
override fun loadState(state: State) { | ||
synchronized(stateLock) { | ||
this.state = State(state) | ||
} | ||
} | ||
|
||
class State { | ||
var isEnabled: Boolean = true | ||
private var excludedModules = "" | ||
private var excludedRunConfigurations = "" | ||
|
||
constructor() | ||
|
||
constructor(that: State?) { | ||
this.isEnabled = that!!.isEnabled | ||
this.excludedModules = that.excludedModules | ||
this.excludedRunConfigurations = that.excludedRunConfigurations | ||
} | ||
|
||
fun getExcludedModules(): String { | ||
return excludedModules | ||
} | ||
|
||
fun setExcludedModules(excludedModules: String?) { | ||
this.excludedModules = excludedModules ?: "" | ||
} | ||
|
||
fun getExcludedRunConfigurations(): String { | ||
return excludedRunConfigurations | ||
} | ||
|
||
fun setExcludedRunConfigurations(excludedRunConfigurations: String?) { | ||
this.excludedRunConfigurations = excludedRunConfigurations ?: "" | ||
} | ||
|
||
override fun equals(other: Any?): Boolean { | ||
if (this === other) return true | ||
if (other == null || javaClass != other.javaClass) return false | ||
val that = other as State | ||
if (isEnabled != that.isEnabled) return false | ||
if (excludedModules != that.excludedModules) return false | ||
return excludedRunConfigurations == that.excludedRunConfigurations | ||
} | ||
|
||
override fun hashCode(): Int { | ||
var result = (if (isEnabled) 1 else 0) | ||
result = 31 * result + excludedModules.hashCode() | ||
result = 31 * result + excludedRunConfigurations.hashCode() | ||
return result | ||
} | ||
} | ||
|
||
companion object { | ||
private val LOG = Logger.getInstance( | ||
ProjectPlugin::class.java | ||
) | ||
|
||
fun isEnabledFor(runProfile: RunProfile, module: Module?): Boolean { | ||
if (module == null) { | ||
return false | ||
} | ||
val state = module.project.getComponent( | ||
ProjectPlugin::class.java | ||
).getState() | ||
if (!state.isEnabled) { | ||
return false | ||
} | ||
if (isExcluded(state.getExcludedModules(), module.name)) { | ||
return false | ||
} | ||
if (isExcluded(state.getExcludedRunConfigurations(), runProfile.name)) { | ||
return false | ||
} | ||
return true | ||
} | ||
|
||
private fun isExcluded(pattern: String, string: String): Boolean { | ||
if (pattern.isBlank()) { | ||
return false | ||
} | ||
try { | ||
return Pattern.compile(pattern).matcher(string).find() | ||
} catch (e: PatternSyntaxException) { | ||
LOG.error("Illegal pattern: $pattern", e) | ||
return false | ||
} | ||
} | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
src/main/kotlin/com/github/jbou/ideaundelegaterun/Settings.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,86 @@ | ||
package com.github.jbou.ideaundelegaterun | ||
|
||
import com.intellij.openapi.diagnostic.Logger | ||
import com.intellij.openapi.options.Configurable | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.ui.VerticalFlowLayout | ||
import com.intellij.ui.DocumentAdapter | ||
import org.jetbrains.annotations.Nls | ||
import java.awt.BorderLayout | ||
import java.awt.Cursor | ||
import javax.swing.* | ||
import javax.swing.event.DocumentEvent | ||
|
||
class Settings(project: Project) : Configurable { | ||
private val plugin: ProjectPlugin? = project.getComponent(ProjectPlugin::class.java) | ||
|
||
private var state: ProjectPlugin.State? = null | ||
|
||
override fun getDisplayName(): @Nls(capitalization = Nls.Capitalization.Title) String { | ||
return "Un-Delegate Run Actions" | ||
} | ||
|
||
override fun createComponent(): JComponent { | ||
// nullability for searchable index builder | ||
state = plugin().state | ||
val container = JPanel(BorderLayout()) | ||
container.border = BorderFactory.createEmptyBorder(5, 5, 5, 5) | ||
val settings = JPanel(VerticalFlowLayout(true, false)) | ||
container.add(settings, BorderLayout.NORTH) | ||
// enabled check box | ||
var line = JPanel(BorderLayout()) | ||
val enabled = JCheckBox("Un-Delegate Run Actions") | ||
enabled.isSelected = state!!.isEnabled | ||
enabled.addChangeListener { state!!.isEnabled = enabled.isSelected } | ||
line.add(enabled, BorderLayout.WEST) | ||
settings.add(line) | ||
// exclude modules regex | ||
line = JPanel(BorderLayout(5, 5)) | ||
line.add(JLabel("Excluded Modules (Regex contains)"), BorderLayout.WEST) | ||
val excludedModules = JTextField() | ||
excludedModules.cursor = Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR) | ||
excludedModules.text = state!!.getExcludedModules() | ||
excludedModules.document.addDocumentListener(object : DocumentAdapter() { | ||
override fun textChanged(e: DocumentEvent) { | ||
state!!.setExcludedModules(excludedModules.text) | ||
} | ||
}) | ||
line.add(excludedModules, BorderLayout.CENTER) | ||
settings.add(line) | ||
// exclude run configurations regex | ||
line = JPanel(BorderLayout(5, 5)) | ||
line.add(JLabel("Excluded Run Configurations (Regex contains)"), BorderLayout.WEST) | ||
val excludedRunConfs = JTextField() | ||
excludedRunConfs.cursor = Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR) | ||
excludedRunConfs.text = state!!.getExcludedRunConfigurations() | ||
excludedRunConfs.document.addDocumentListener(object : DocumentAdapter() { | ||
override fun textChanged(e: DocumentEvent) { | ||
state!!.setExcludedRunConfigurations(excludedRunConfs.text) | ||
} | ||
}) | ||
line.add(excludedRunConfs, BorderLayout.CENTER) | ||
settings.add(line) | ||
return container | ||
} | ||
|
||
override fun isModified(): Boolean { | ||
return plugin().state != state | ||
} | ||
|
||
override fun apply() { | ||
plugin().loadState(state!!) | ||
} | ||
|
||
private fun plugin(): ProjectPlugin { | ||
if (plugin == null) { | ||
LOG.error("Plugin is null; that should only happen during indexing") | ||
return ProjectPlugin() | ||
} else { | ||
return plugin | ||
} | ||
} | ||
|
||
companion object { | ||
private val LOG = Logger.getInstance(Settings::class.java) | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/kotlin/com/github/jbou/ideaundelegaterun/UndelegateExecutionEnvironmentProvider.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,26 @@ | ||
package com.github.jbou.ideaundelegaterun | ||
|
||
import com.intellij.execution.Executor | ||
import com.intellij.execution.application.ApplicationConfiguration | ||
import com.intellij.execution.runners.ExecutionEnvironment | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.task.ExecuteRunConfigurationTask | ||
import org.jetbrains.plugins.gradle.execution.build.GradleExecutionEnvironmentProvider | ||
|
||
class UndelegateExecutionEnvironmentProvider : GradleExecutionEnvironmentProvider { | ||
override fun isApplicable(task: ExecuteRunConfigurationTask): Boolean { | ||
if (task.runProfile !is ApplicationConfiguration) { | ||
return false | ||
} | ||
val runProfile = task.runProfile as ApplicationConfiguration | ||
return ProjectPlugin.isEnabledFor(runProfile, runProfile.configurationModule.module) | ||
} | ||
|
||
override fun createExecutionEnvironment( | ||
project: Project, | ||
task: ExecuteRunConfigurationTask, | ||
executor: Executor | ||
): ExecutionEnvironment? { | ||
return null | ||
} | ||
} |
12 changes: 0 additions & 12 deletions
12
...ain/kotlin/com/github/jbou/ideaundelegaterun/listeners/MyApplicationActivationListener.kt
This file was deleted.
Oops, something went wrong.
17 changes: 0 additions & 17 deletions
17
src/main/kotlin/com/github/jbou/ideaundelegaterun/services/MyProjectService.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.