├── .gitignore
├── settings.gradle.kts
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── qodana.yml
├── src
└── main
│ ├── kotlin
│ └── com
│ │ └── bredogen
│ │ └── projectenv
│ │ ├── providers
│ │ ├── EnvSourceException.kt
│ │ ├── EnvProviderFactory.kt
│ │ ├── EnvProvider.kt
│ │ └── files
│ │ │ ├── YamlFileProvider.kt
│ │ │ ├── EnvFileProvider.kt
│ │ │ └── DotEnvFileProvider.kt
│ │ ├── customizers
│ │ └── TerminalCustomizer.kt
│ │ ├── ui
│ │ ├── actions
│ │ │ ├── EnvTerminalToggleAction.kt
│ │ │ ├── EnvRunConfigurationToggleAction.kt
│ │ │ └── EnvEnableInTestConfigurationToggleAction.kt
│ │ ├── WindowFactory.kt
│ │ └── ToolWindowPanel.kt
│ │ ├── extensions
│ │ ├── PythonConsoleExtension.kt
│ │ ├── PythonRunConfigurationExtension.kt
│ │ ├── JavaRunConfigurationExtension.kt
│ │ └── GoRunConfigurationExtension.kt
│ │ ├── EnvSourceEntry.kt
│ │ └── services
│ │ └── ProjectEnvService.kt
│ └── resources
│ └── META-INF
│ ├── projectenv-go.xml
│ ├── projectenv-terminal.xml
│ ├── projectenv-java.xml
│ ├── projectenv-pycharm.xml
│ ├── plugin.xml
│ └── pluginIcon.svg
├── CHANGELOG.md
├── .github
├── dependabot.yml
└── workflows
│ ├── run-ui-tests.yml
│ ├── release.yml
│ └── build.yml
├── .run
├── Run IDE for UI Tests.run.xml
├── Run Plugin Tests.run.xml
├── Run Qodana.run.xml
├── Run Plugin Verification.run.xml
└── Run IDE with Plugin.run.xml
├── gradle.properties
├── README.md
├── gradlew.bat
└── gradlew
/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | .idea
3 | .qodana
4 | build
5 |
--------------------------------------------------------------------------------
/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | rootProject.name = "ProjectEnv"
2 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BredoGen/ProjectEnv/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/qodana.yml:
--------------------------------------------------------------------------------
1 | # Qodana configuration:
2 | # https://www.jetbrains.com/help/qodana/qodana-yaml.html
3 |
4 | version: 1.0
5 | profile:
6 | name: qodana.recommended
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 |
--------------------------------------------------------------------------------
/src/main/kotlin/com/bredogen/projectenv/providers/EnvSourceException.kt:
--------------------------------------------------------------------------------
1 | package com.bredogen.projectenv.providers
2 |
3 | class EnvSourceException : Exception {
4 | constructor(message: String?) : super(message)
5 | constructor(cause: Throwable?) : super(cause)
6 | }
7 |
--------------------------------------------------------------------------------
/src/main/resources/META-INF/projectenv-go.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/src/main/resources/META-INF/projectenv-terminal.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/src/main/resources/META-INF/projectenv-java.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/src/main/kotlin/com/bredogen/projectenv/providers/EnvProviderFactory.kt:
--------------------------------------------------------------------------------
1 | package com.bredogen.projectenv.providers
2 |
3 | import com.intellij.openapi.project.Project
4 |
5 | interface EnvProviderFactory {
6 | fun newInstance(params : Map): EnvProvider
7 | fun createParams(project: Project) : Map
8 | }
--------------------------------------------------------------------------------
/src/main/kotlin/com/bredogen/projectenv/providers/EnvProvider.kt:
--------------------------------------------------------------------------------
1 | package com.bredogen.projectenv.providers
2 | import com.intellij.openapi.project.Project
3 |
4 | interface EnvProvider {
5 | fun handleDoubleClick(project: Project) : Boolean
6 | fun getEnvValues() : LinkedHashMap
7 |
8 | val isValid : Boolean
9 | val isFile : Boolean
10 | val name : String
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/resources/META-INF/projectenv-pycharm.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | # ProjectEnv Changelog
4 |
5 | ## [Unreleased]
6 |
7 | ## [0.1.0]
8 | - Env Files tool window
9 | - Yaml / JSON support
10 |
11 | ## [0.0.5]
12 | - 2022.1+ compatibility
13 |
14 | ## [0.0.4]
15 | - IDEA 2021.3 compatibility
16 |
17 | ## [0.0.3]
18 | - IDEA 2021.2 compatibility
19 |
20 | ## [0.0.1]
21 | ### Added
22 | - Base dotenv files support for PyCharm, GoLand, IDEA projects.
--------------------------------------------------------------------------------
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | # Dependabot configuration:
2 | # https://docs.github.com/en/free-pro-team@latest/github/administering-a-repository/configuration-options-for-dependency-updates
3 |
4 | version: 2
5 | updates:
6 | # Maintain dependencies for Gradle dependencies
7 | - package-ecosystem: "gradle"
8 | directory: "/"
9 | target-branch: "next"
10 | schedule:
11 | interval: "daily"
12 | # Maintain dependencies for GitHub Actions
13 | - package-ecosystem: "github-actions"
14 | directory: "/"
15 | target-branch: "next"
16 | schedule:
17 | interval: "daily"
18 |
--------------------------------------------------------------------------------
/src/main/kotlin/com/bredogen/projectenv/customizers/TerminalCustomizer.kt:
--------------------------------------------------------------------------------
1 | package com.bredogen.projectenv.customizers
2 |
3 | import com.bredogen.projectenv.services.ProjectEnvService
4 | import com.intellij.openapi.project.Project
5 | import org.jetbrains.plugins.terminal.LocalTerminalCustomizer
6 |
7 | class TerminalCustomizer : LocalTerminalCustomizer() {
8 | override fun customizeCommandAndEnvironment(project: Project, command: Array, envs: MutableMap): Array {
9 | val envService = ProjectEnvService.getInstance(project)
10 | if (envService.enableTerminal) {
11 | envs.putAll(envService.getEnvValues())
12 | }
13 | return command
14 | }
15 | }
--------------------------------------------------------------------------------
/src/main/kotlin/com/bredogen/projectenv/ui/actions/EnvTerminalToggleAction.kt:
--------------------------------------------------------------------------------
1 | package com.bredogen.projectenv.ui.actions
2 |
3 | import com.bredogen.projectenv.services.ProjectEnvService
4 | import com.intellij.openapi.actionSystem.AnActionEvent
5 | import com.intellij.openapi.project.DumbAwareToggleAction
6 |
7 | internal class EnvTerminalToggleAction : DumbAwareToggleAction("Enable in Terminal") {
8 |
9 | override fun isSelected(event: AnActionEvent) = event.project?.let { ProjectEnvService.getInstance(it).enableTerminal } ?: true
10 |
11 | override fun setSelected(event: AnActionEvent, isSelected: Boolean) {
12 | event.project?.let {
13 | ProjectEnvService.getInstance(it).enableTerminal = isSelected
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/kotlin/com/bredogen/projectenv/ui/actions/EnvRunConfigurationToggleAction.kt:
--------------------------------------------------------------------------------
1 | package com.bredogen.projectenv.ui.actions
2 |
3 | import com.bredogen.projectenv.services.ProjectEnvService
4 | import com.intellij.openapi.actionSystem.AnActionEvent
5 | import com.intellij.openapi.project.DumbAwareToggleAction
6 |
7 | internal class EnvRunConfigurationToggleAction : DumbAwareToggleAction("Enable in Run Configurations") {
8 |
9 | override fun isSelected(event: AnActionEvent) = event.project?.let { ProjectEnvService.getInstance(it).enableRunConfiguration } ?: true
10 |
11 | override fun setSelected(event: AnActionEvent, isSelected: Boolean) {
12 | event.project?.let {
13 | ProjectEnvService.getInstance(it).enableRunConfiguration = isSelected
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/kotlin/com/bredogen/projectenv/ui/actions/EnvEnableInTestConfigurationToggleAction.kt:
--------------------------------------------------------------------------------
1 | package com.bredogen.projectenv.ui.actions
2 |
3 | import com.bredogen.projectenv.services.ProjectEnvService
4 | import com.intellij.openapi.actionSystem.AnActionEvent
5 | import com.intellij.openapi.project.DumbAwareToggleAction
6 |
7 | internal class EnvEnableInTestConfigurationToggleAction : DumbAwareToggleAction("Enable Also in Test Run Configurations") {
8 |
9 | override fun isSelected(event: AnActionEvent) = event.project?.let { ProjectEnvService.getInstance(it).includeTestConfiguration } ?: true
10 |
11 | override fun setSelected(event: AnActionEvent, isSelected: Boolean) {
12 | event.project?.let {
13 | ProjectEnvService.getInstance(it).includeTestConfiguration = isSelected
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/.run/Run IDE for UI Tests.run.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
12 |
15 |
16 |
17 | true
18 | true
19 | false
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.run/Run Plugin Tests.run.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
12 |
17 |
18 |
19 | true
20 | true
21 | false
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/.run/Run Qodana.run.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 | true
22 | true
23 | false
24 |
25 |
26 |
--------------------------------------------------------------------------------
/src/main/kotlin/com/bredogen/projectenv/extensions/PythonConsoleExtension.kt:
--------------------------------------------------------------------------------
1 | package com.bredogen.projectenv.extensions
2 |
3 | import com.bredogen.projectenv.services.ProjectEnvService
4 | import com.intellij.execution.configurations.GeneralCommandLine
5 | import com.intellij.openapi.project.Project
6 | import com.intellij.openapi.projectRoots.SdkAdditionalData
7 | import com.jetbrains.python.console.PydevConsoleRunnerImpl
8 | import com.jetbrains.python.run.PythonCommandLineEnvironmentProvider
9 | import com.jetbrains.python.run.PythonRunParams
10 |
11 | class PythonConsoleExtension : PythonCommandLineEnvironmentProvider {
12 | override fun extendEnvironment(
13 | project: Project,
14 | data: SdkAdditionalData?,
15 | cmdLine: GeneralCommandLine,
16 | runParams: PythonRunParams?
17 | ) {
18 | if (runParams !is PydevConsoleRunnerImpl.PythonConsoleRunParams) {
19 | return
20 | }
21 |
22 | val envService = ProjectEnvService.getInstance(project)
23 | if (envService.enableTerminal) {
24 | cmdLine.environment.putAll(envService.getEnvValues())
25 | }
26 | }
27 | }
--------------------------------------------------------------------------------
/src/main/resources/META-INF/plugin.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | com.bredogen.projectenv
4 | ProjectEnv
5 | Alexander Bayagin
6 |
7 | com.intellij.modules.platform
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | org.jetbrains.plugins.terminal
16 | com.intellij.modules.python
17 | com.intellij.java
18 | org.jetbrains.plugins.go
19 |
20 |
21 |
--------------------------------------------------------------------------------
/.run/Run Plugin Verification.run.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 | true
20 | true
21 | false
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/src/main/kotlin/com/bredogen/projectenv/ui/WindowFactory.kt:
--------------------------------------------------------------------------------
1 | package com.bredogen.projectenv.ui
2 |
3 | import com.bredogen.projectenv.ui.actions.EnvEnableInTestConfigurationToggleAction
4 | import com.bredogen.projectenv.ui.actions.EnvRunConfigurationToggleAction
5 | import com.bredogen.projectenv.ui.actions.EnvTerminalToggleAction
6 | import com.intellij.openapi.actionSystem.DefaultActionGroup
7 | import com.intellij.openapi.project.DumbAware
8 | import com.intellij.openapi.project.Project
9 | import com.intellij.openapi.wm.ToolWindow
10 | import com.intellij.openapi.wm.ToolWindowFactory
11 | import com.intellij.openapi.wm.ex.ToolWindowEx
12 | import com.intellij.ui.content.ContentFactory
13 |
14 | class WindowFactory : ToolWindowFactory, DumbAware {
15 | override fun createToolWindowContent(project: Project, toolWindow: ToolWindow) {
16 | val toolWindowPanel = ToolWindowPanel(project)
17 | val content = ContentFactory.SERVICE.getInstance().createContent(toolWindowPanel.component, null, false)
18 | toolWindow.contentManager.addContent(content)
19 |
20 | if (toolWindow is ToolWindowEx) {
21 | toolWindow.setAdditionalGearActions(DefaultActionGroup(listOf(
22 | EnvTerminalToggleAction(),
23 | EnvRunConfigurationToggleAction(),
24 | EnvEnableInTestConfigurationToggleAction(),
25 | )))
26 | }
27 | }
28 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # IntelliJ Platform Artifacts Repositories
2 | # -> https://plugins.jetbrains.com/docs/intellij/intellij-artifacts.html
3 |
4 | pluginGroup = com.bredogen.projectenv
5 | pluginName = ProjectEnv
6 | # SemVer format -> https://semver.org
7 | pluginVersion = 0.1.0
8 |
9 | # See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
10 | # for insight into build numbers and IntelliJ Platform versions.
11 | pluginSinceBuild = 203
12 | pluginUntilBuild = 221.*
13 |
14 | # IntelliJ Platform Properties -> https://github.com/JetBrains/gradle-intellij-plugin#intellij-platform-properties
15 | platformType = IU
16 | platformVersion = 2021.3.3
17 |
18 | # Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
19 | # Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22
20 | platformPlugins = terminal, com.intellij.java, Pythonid:213.7172.26, org.jetbrains.plugins.go:213.7172.6
21 |
22 | # Java language level used to compile sources and to generate the files for - Java 11 is required since 2020.3
23 | javaVersion = 11
24 |
25 | # Gradle Releases -> https://github.com/gradle/gradle/releases
26 | gradleVersion = 7.4
27 |
28 | # Opt-out flag for bundling Kotlin standard library.
29 | # See https://plugins.jetbrains.com/docs/intellij/kotlin.html#kotlin-standard-library for details.
30 | # suppress inspection "UnusedProperty"
31 | kotlin.stdlib.default.dependency = false
32 |
--------------------------------------------------------------------------------
/src/main/kotlin/com/bredogen/projectenv/providers/files/YamlFileProvider.kt:
--------------------------------------------------------------------------------
1 | package com.bredogen.projectenv.providers.files
2 | import com.bredogen.projectenv.providers.EnvProviderFactory
3 | import com.bredogen.projectenv.providers.EnvSourceException
4 | import com.intellij.openapi.project.Project
5 | import org.yaml.snakeyaml.Yaml
6 | import java.io.IOException
7 | import java.nio.file.Files
8 | import java.nio.file.Paths
9 |
10 |
11 | class YamlFileProvider(private val params : Map) : EnvFileProvider(params) {
12 |
13 | companion object : EnvProviderFactory {
14 | override fun newInstance(params : Map): YamlFileProvider {
15 | return YamlFileProvider(params)
16 | }
17 |
18 | override fun createParams(project: Project): Map {
19 | return EnvFileProvider.createParams(project)
20 | }
21 | }
22 |
23 | override fun getEnvValues(): LinkedHashMap {
24 | val path = params["path"] ?: throw EnvSourceException("No valid path to json/yaml file")
25 |
26 | val result: LinkedHashMap?
27 | try {
28 | result = Yaml().load(Files.readString(Paths.get(path)))
29 | } catch (ex: IOException) {
30 | throw EnvSourceException(ex)
31 | } catch (ex: java.lang.ClassCastException) {
32 | throw EnvSourceException("File content is not String:String map")
33 | }
34 | if (result == null) {
35 | throw EnvSourceException("Cannot process file. Malformed format?")
36 | }
37 | return result
38 | }
39 | }
--------------------------------------------------------------------------------
/.run/Run IDE with Plugin.run.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 | true
20 | true
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 | false
34 |
35 |
36 |
--------------------------------------------------------------------------------
/src/main/kotlin/com/bredogen/projectenv/extensions/PythonRunConfigurationExtension.kt:
--------------------------------------------------------------------------------
1 | package com.bredogen.projectenv.extensions
2 |
3 | import com.bredogen.projectenv.services.ProjectEnvService
4 | import com.intellij.execution.configurations.GeneralCommandLine
5 | import com.intellij.execution.configurations.RunConfigurationBase
6 | import com.intellij.execution.configurations.RunnerSettings
7 | import com.jetbrains.python.run.AbstractPythonRunConfiguration
8 | import com.jetbrains.python.run.PythonRunConfigurationExtension
9 | import com.jetbrains.python.testing.PyAbstractTestConfiguration
10 |
11 | class PythonRunConfigurationExtension : PythonRunConfigurationExtension() {
12 | override fun isApplicableFor(configuration: AbstractPythonRunConfiguration<*>): Boolean = true
13 | override fun isEnabledFor(applicableConfiguration: AbstractPythonRunConfiguration<*>, runnerSettings: RunnerSettings?): Boolean {
14 | val projectEnvService = ProjectEnvService.getInstance(applicableConfiguration.project)
15 |
16 | if (!projectEnvService.includeTestConfiguration && isTestConfiguration(applicableConfiguration)) {
17 | return false
18 | }
19 |
20 | return projectEnvService.enableRunConfiguration
21 | }
22 |
23 | private fun isTestConfiguration(applicableConfiguration: RunConfigurationBase<*>): Boolean {
24 | return applicableConfiguration is PyAbstractTestConfiguration
25 | }
26 |
27 | override fun patchCommandLine(configuration: AbstractPythonRunConfiguration<*>, runnerSettings: RunnerSettings?, cmdLine: GeneralCommandLine, runnerId: String) {
28 | val envService = ProjectEnvService.getInstance(configuration.project)
29 | cmdLine.environment.putAll(envService.getEnvValues())
30 | }
31 | }
--------------------------------------------------------------------------------
/src/main/kotlin/com/bredogen/projectenv/extensions/JavaRunConfigurationExtension.kt:
--------------------------------------------------------------------------------
1 | package com.bredogen.projectenv.extensions
2 |
3 | import com.bredogen.projectenv.services.ProjectEnvService
4 | import com.intellij.execution.JavaTestConfigurationBase
5 | import com.intellij.execution.RunConfigurationExtension
6 | import com.intellij.execution.configurations.JavaParameters
7 | import com.intellij.execution.configurations.RunConfigurationBase
8 | import com.intellij.execution.configurations.RunnerSettings
9 | import com.jetbrains.python.testing.PyAbstractTestConfiguration
10 | import com.jetbrains.python.testing.PyTestConfiguration
11 | import com.jetbrains.python.testing.PythonTestConfigurationType
12 |
13 | class JavaRunConfigurationExtension : RunConfigurationExtension() {
14 | override fun isApplicableFor(configuration: RunConfigurationBase<*>): Boolean = true
15 |
16 | override fun isEnabledFor(applicableConfiguration: RunConfigurationBase<*>, runnerSettings: RunnerSettings?): Boolean {
17 | val projectEnvService = ProjectEnvService.getInstance(applicableConfiguration.project)
18 |
19 | if (!projectEnvService.includeTestConfiguration && isTestConfiguration(applicableConfiguration)) {
20 | return false
21 | }
22 |
23 | return projectEnvService.enableRunConfiguration
24 | }
25 |
26 | private fun isTestConfiguration(applicableConfiguration: RunConfigurationBase<*>): Boolean {
27 | return applicableConfiguration is JavaTestConfigurationBase
28 | }
29 |
30 | override fun > updateJavaParameters(configuration: T, params: JavaParameters, runnerSettings: RunnerSettings?) {
31 | val envService = ProjectEnvService.getInstance(configuration.project)
32 | params.env.putAll(envService.getEnvValues())
33 | }
34 | }
--------------------------------------------------------------------------------
/src/main/kotlin/com/bredogen/projectenv/EnvSourceEntry.kt:
--------------------------------------------------------------------------------
1 | package com.bredogen.projectenv
2 |
3 | import com.bredogen.projectenv.providers.EnvProvider
4 | import com.bredogen.projectenv.providers.EnvProviderFactory
5 | import com.bredogen.projectenv.providers.files.DotEnvFileProvider
6 | import com.bredogen.projectenv.providers.files.YamlFileProvider
7 | import com.intellij.icons.AllIcons
8 | import com.intellij.util.xmlb.annotations.Attribute
9 | import com.intellij.util.xmlb.annotations.MapAnnotation
10 | import com.intellij.util.xmlb.annotations.Tag
11 | import javax.swing.Icon
12 |
13 | @Tag("env-source-entry")
14 | class EnvSourceEntry(
15 | @MapAnnotation(entryTagName = "params") val params: Map = hashMapOf(),
16 | @Attribute("type") val type: EnvType? = null
17 | ) {
18 | enum class EnvType { ENV, JSON, YAML }
19 |
20 | companion object {
21 | fun getProviderFactory(type: EnvType): EnvProviderFactory =
22 | when (type) {
23 | EnvType.ENV -> DotEnvFileProvider
24 | EnvType.YAML -> YamlFileProvider
25 | EnvType.JSON -> YamlFileProvider
26 | }
27 |
28 | val typeTitles: Map = mapOf(
29 | EnvType.ENV to ".env",
30 | EnvType.JSON to "json",
31 | EnvType.YAML to "yaml",
32 | )
33 |
34 | val typeIcons: Map = mapOf(
35 | EnvType.ENV to AllIcons.FileTypes.JsonSchema,
36 | EnvType.JSON to AllIcons.FileTypes.Json,
37 | EnvType.YAML to AllIcons.FileTypes.Yaml,
38 | )
39 | }
40 |
41 | val provider : EnvProvider
42 | get() = getProviderFactory(type!!).newInstance(params)
43 |
44 | val name : String
45 | get() = provider.name
46 |
47 | }
48 |
49 |
--------------------------------------------------------------------------------
/.github/workflows/run-ui-tests.yml:
--------------------------------------------------------------------------------
1 | # GitHub Actions Workflow for launching UI tests on Linux, Windows, and Mac in the following steps:
2 | # - prepare and launch IDE with your plugin and robot-server plugin, which is needed to interact with UI
3 | # - wait for IDE to start
4 | # - run UI tests with separate Gradle task
5 | #
6 | # Please check https://github.com/JetBrains/intellij-ui-test-robot for information about UI tests with IntelliJ Platform
7 | #
8 | # Workflow is triggered manually.
9 |
10 | name: Run UI Tests
11 | on:
12 | workflow_dispatch
13 |
14 | jobs:
15 |
16 | testUI:
17 | runs-on: ${{ matrix.os }}
18 | strategy:
19 | fail-fast: false
20 | matrix:
21 | include:
22 | - os: ubuntu-latest
23 | runIde: |
24 | export DISPLAY=:99.0
25 | Xvfb -ac :99 -screen 0 1920x1080x16 &
26 | gradle runIdeForUiTests &
27 | - os: windows-latest
28 | runIde: start gradlew.bat runIdeForUiTests
29 | - os: macos-latest
30 | runIde: ./gradlew runIdeForUiTests &
31 |
32 | steps:
33 |
34 | # Check out current repository
35 | - name: Fetch Sources
36 | uses: actions/checkout@v2.4.0
37 |
38 | # Setup Java 11 environment for the next steps
39 | - name: Setup Java
40 | uses: actions/setup-java@v2
41 | with:
42 | distribution: zulu
43 | java-version: 11
44 | cache: gradle
45 |
46 | # Run IDEA prepared for UI testing
47 | - name: Run IDE
48 | run: ${{ matrix.runIde }}
49 |
50 | # Wait for IDEA to be started
51 | - name: Health Check
52 | uses: jtalk/url-health-check-action@v2
53 | with:
54 | url: http://127.0.0.1:8082
55 | max-attempts: 15
56 | retry-delay: 30s
57 |
58 | # Run tests
59 | - name: Tests
60 | run: ./gradlew test
61 |
--------------------------------------------------------------------------------
/src/main/kotlin/com/bredogen/projectenv/extensions/GoRunConfigurationExtension.kt:
--------------------------------------------------------------------------------
1 | package com.bredogen.projectenv.extensions
2 |
3 | import com.bredogen.projectenv.services.ProjectEnvService
4 | import com.goide.execution.GoRunConfigurationBase
5 | import com.goide.execution.GoRunningState
6 | import com.goide.execution.extension.GoRunConfigurationExtension
7 | import com.goide.execution.testing.GoTestRunConfiguration
8 | import com.intellij.execution.configurations.RunConfigurationBase
9 | import com.intellij.execution.configurations.RunnerSettings
10 | import com.intellij.execution.target.TargetedCommandLineBuilder
11 |
12 | class GoRunConfigurationExtension : GoRunConfigurationExtension() {
13 | override fun isApplicableFor(configuration: GoRunConfigurationBase<*>): Boolean = true
14 | override fun isEnabledFor(applicableConfiguration: GoRunConfigurationBase<*>, runnerSettings: RunnerSettings?): Boolean {
15 | val projectEnvService = ProjectEnvService.getInstance(applicableConfiguration.getProject())
16 |
17 | if (!projectEnvService.includeTestConfiguration && isTestConfiguration(applicableConfiguration)) {
18 | return false
19 | }
20 |
21 | return projectEnvService.enableRunConfiguration
22 | }
23 |
24 | private fun isTestConfiguration(applicableConfiguration: RunConfigurationBase<*>): Boolean {
25 | return applicableConfiguration is GoTestRunConfiguration
26 | }
27 |
28 | override fun patchCommandLine(configuration: GoRunConfigurationBase<*>, runnerSettings: RunnerSettings?, cmdLine: TargetedCommandLineBuilder, runnerId: String, state: GoRunningState>, commandLineType: GoRunningState.CommandLineType) {
29 | val envService = ProjectEnvService.getInstance(configuration.getProject())
30 | envService.getEnvValues().forEach { env -> cmdLine.addEnvironmentVariable(env.key, env.value) }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/kotlin/com/bredogen/projectenv/providers/files/EnvFileProvider.kt:
--------------------------------------------------------------------------------
1 | package com.bredogen.projectenv.providers.files
2 |
3 | import com.bredogen.projectenv.providers.EnvProvider
4 | import com.intellij.openapi.fileChooser.FileChooser
5 | import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory
6 | import com.intellij.openapi.fileEditor.OpenFileDescriptor
7 | import com.intellij.openapi.project.Project
8 | import com.intellij.openapi.vfs.VfsUtil
9 | import com.intellij.openapi.vfs.VirtualFile
10 | import com.intellij.util.OpenSourceUtil
11 | import java.nio.file.Files
12 | import java.nio.file.Paths
13 |
14 |
15 | abstract class EnvFileProvider(private val params : Map) : EnvProvider {
16 |
17 | override val name : String
18 | get() = params.getOrDefault("path", "")
19 |
20 | override val isFile : Boolean = true
21 |
22 | override val isValid : Boolean
23 | get() = isValidPath
24 |
25 | private val isValidPath : Boolean
26 | get() = Files.isReadable(Paths.get(params.getOrDefault("path", "")))
27 |
28 | private val path : String
29 | get() = params.getOrDefault("path", "")
30 |
31 | companion object {
32 | fun createParams(project: Project): Map {
33 | val fileDescriptor = FileChooserDescriptorFactory.createSingleLocalFileDescriptor().withShowHiddenFiles(true)
34 | fileDescriptor.title = "Choose Env File"
35 |
36 | val file: VirtualFile? = FileChooser.chooseFile(fileDescriptor, project, null)
37 | if (file != null && file.isDirectory.not()) {
38 | return hashMapOf("path" to file.path)
39 | }
40 |
41 | return hashMapOf()
42 | }
43 | }
44 |
45 | override fun handleDoubleClick(project: Project): Boolean {
46 | val file = VfsUtil.findFile(Paths.get(path), true)
47 | if (file != null) {
48 | OpenSourceUtil.navigate(OpenFileDescriptor(project, file))
49 | }
50 | return true
51 | }
52 |
53 | }
--------------------------------------------------------------------------------
/src/main/kotlin/com/bredogen/projectenv/services/ProjectEnvService.kt:
--------------------------------------------------------------------------------
1 | package com.bredogen.projectenv.services
2 |
3 | import com.bredogen.projectenv.EnvSourceEntry
4 | import com.bredogen.projectenv.providers.EnvSourceException
5 | import com.intellij.notification.NotificationGroupManager
6 | import com.intellij.notification.NotificationType
7 |
8 | import com.intellij.openapi.components.*
9 | import com.intellij.openapi.project.Project
10 | import com.intellij.util.xmlb.XmlSerializerUtil
11 |
12 | @State(name = "ProjectEnvService", storages = [Storage("project_env.xml")])
13 | class ProjectEnvService : PersistentStateComponent, BaseState() {
14 | companion object {
15 | @JvmStatic
16 | fun getInstance(project: Project): ProjectEnvService = project.service()
17 | }
18 |
19 | var envFiles by list()
20 |
21 | var enableTerminal by property(true)
22 | var enableRunConfiguration by property(true)
23 | var includeTestConfiguration by property(true)
24 |
25 | override fun getState(): ProjectEnvService {
26 | return this
27 | }
28 |
29 | override fun loadState(state: ProjectEnvService) {
30 | XmlSerializerUtil.copyBean(state, this)
31 | }
32 |
33 | fun getEnvValues(): LinkedHashMap {
34 | val result = linkedMapOf()
35 |
36 | envFiles.forEach { envFile ->
37 | if (envFile.provider.isValid) {
38 | try {
39 | result.putAll(envFile.provider.getEnvValues())
40 | } catch (ex: EnvSourceException) {
41 | NotificationGroupManager.getInstance()
42 | .getNotificationGroup("ProjectEnv")
43 | .createNotification(
44 | "Cannot process ${envFile.name}: ${ex.message}",
45 | NotificationType.WARNING)
46 | .notify(null)
47 | }
48 | }
49 | }
50 |
51 | return result
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/kotlin/com/bredogen/projectenv/providers/files/DotEnvFileProvider.kt:
--------------------------------------------------------------------------------
1 | package com.bredogen.projectenv.providers.files
2 | import com.bredogen.projectenv.providers.EnvProviderFactory
3 | import com.bredogen.projectenv.providers.EnvSourceException
4 | import com.intellij.openapi.project.Project
5 | import java.io.IOException
6 | import java.nio.charset.StandardCharsets
7 | import java.nio.file.Files
8 | import java.nio.file.Paths
9 |
10 | class DotEnvFileProvider(private val params : Map) : EnvFileProvider(params) {
11 |
12 | companion object : EnvProviderFactory {
13 | override fun newInstance(params : Map): DotEnvFileProvider {
14 | return DotEnvFileProvider(params)
15 | }
16 |
17 | override fun createParams(project: Project): Map {
18 | return EnvFileProvider.createParams(project)
19 | }
20 | }
21 |
22 | override fun getEnvValues(): LinkedHashMap {
23 |
24 | val path = params["path"] ?: throw EnvSourceException("No valid path to env file")
25 |
26 | val result: LinkedHashMap = linkedMapOf()
27 | try {
28 | val lines = Files.readAllLines(Paths.get(path), StandardCharsets.UTF_8)
29 | for (l in lines) {
30 | val strippedLine = l.trim { it <= ' ' }
31 | if (!strippedLine.startsWith("#") && strippedLine.contains("=")) {
32 | val tokens = strippedLine.split("=".toRegex(), 2).toTypedArray()
33 | val key = tokens[0]
34 | val value = trim(tokens[1])
35 | result[key] = value
36 | }
37 | }
38 | } catch (ex: IOException) {
39 | throw EnvSourceException(ex)
40 | }
41 | return result
42 | }
43 |
44 | private fun trim(value: String): String {
45 | val trimmed = value.trim { it <= ' ' }
46 | val doubleQuoted = trimmed.startsWith("\"") && trimmed.endsWith("\"")
47 | val singleQuoted = trimmed.startsWith("'") && trimmed.endsWith("'")
48 | return if (doubleQuoted || singleQuoted) {
49 | trimmed.substring(1, trimmed.length - 1)
50 | } else {
51 | trimmed.replace("\\s#.*$".toRegex(), "").replace("(\\s)\\\\#".toRegex(), "$1#").trim { it <= ' ' }
52 | }
53 | }
54 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ProjectEnv
2 |
3 | **THIS PLUGIN IS NOT MAINTAINED ANYMORE. I BELEIVE THE ENV FILE SUPPORT MUST BE IN THE IDEA CORE.**
4 |
5 | **PLEASE VOTE FOR THE TICKET: https://youtrack.jetbrains.com/issue/PY-5543**
6 |
7 | 
8 | [](https://plugins.jetbrains.com/plugin/17044)
9 | [](https://plugins.jetbrains.com/plugin/17044)
10 |
11 |
12 |
13 | ProjectEnv plugin provides settings to configure project-wide .env (dotenv)/json/yaml files.
14 | Environment variables will be applied to:
15 | * Terminal in all IDEA-based products (tested on Linux, macOS)
16 |
17 | Run Configuration support:
18 | * Python Run Configurations, Python / Django Console
19 | * Java Run Configurations (IDEA)
20 | * Go Run Configurations (GoLand)
21 |
22 | [GitHub](https://github.com/BredoGen/ProjectEnv)
23 |
24 | ## Settings
25 | Env Files tool window > Add your .env/json/yaml files
26 |
27 | For JSON/Yaml files only String:String maps are currently supported.
28 |
29 | You can also toggle plugin features: Env Files tool window > ⚙️:
30 | * Enable in Terminal (requires terminal restart)
31 | * Enable in Run Configurations
32 | * Also Enable in Test Run Configurations (special thanks to [lirikooda](https://github.com/lirikooda))
33 |
34 | ## Credits
35 | Source code mostly based on [FileEnv](https://github.com/ashald/EnvFile) plugin by Borys Pierov. Special thanks for his great work.
36 |
37 |
38 | ## Installation
39 |
40 | - Using IDE built-in plugin system:
41 |
42 | Settings/Preferences > Plugins > Marketplace > Search for "ProjectEnv" >
43 | Install Plugin
44 |
45 | - Manually:
46 |
47 | Download the [latest release](https://github.com/BredoGen/ProjectEnv/releases/latest) and install it manually using
48 | Settings/Preferences > Plugins > ⚙️ > Install plugin from disk...
49 |
50 |
51 | ---
52 | **WARNING:** I'm not a Java/Kotlin developer. The plugin purpose is to solve my own inconvenience while working with 12factor apps in PyCharm.
53 |
54 | Plugin based on the [IntelliJ Platform Plugin Template][template].
55 |
56 | [template]: https://github.com/JetBrains/intellij-platform-plugin-template
57 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/.github/workflows/release.yml:
--------------------------------------------------------------------------------
1 | # GitHub Actions Workflow created for handling the release process based on the draft release prepared
2 | # with the Build workflow. Running the publishPlugin task requires the PUBLISH_TOKEN secret provided.
3 |
4 | name: Release
5 | on:
6 | release:
7 | types: [prereleased, released]
8 |
9 | jobs:
10 |
11 | # Prepare and publish the plugin to the Marketplace repository
12 | release:
13 | name: Publish Plugin
14 | runs-on: ubuntu-latest
15 | steps:
16 |
17 | # Check out current repository
18 | - name: Fetch Sources
19 | uses: actions/checkout@v2.4.0
20 | with:
21 | ref: ${{ github.event.release.tag_name }}
22 |
23 | # Setup Java 11 environment for the next steps
24 | - name: Setup Java
25 | uses: actions/setup-java@v2
26 | with:
27 | distribution: zulu
28 | java-version: 11
29 | cache: gradle
30 |
31 | # Set environment variables
32 | - name: Export Properties
33 | id: properties
34 | shell: bash
35 | run: |
36 | CHANGELOG="$(cat << 'EOM' | sed -e 's/^[[:space:]]*$//g' -e '/./,$!d'
37 | ${{ github.event.release.body }}
38 | EOM
39 | )"
40 |
41 | CHANGELOG="${CHANGELOG//'%'/'%25'}"
42 | CHANGELOG="${CHANGELOG//$'\n'/'%0A'}"
43 | CHANGELOG="${CHANGELOG//$'\r'/'%0D'}"
44 |
45 | echo "::set-output name=changelog::$CHANGELOG"
46 |
47 | # Update Unreleased section with the current release note
48 | - name: Patch Changelog
49 | if: ${{ steps.properties.outputs.changelog != '' }}
50 | env:
51 | CHANGELOG: ${{ steps.properties.outputs.changelog }}
52 | run: |
53 | ./gradlew patchChangelog --release-note="$CHANGELOG"
54 |
55 | # Publish the plugin to the Marketplace
56 | - name: Publish Plugin
57 | env:
58 | PUBLISH_TOKEN: ${{ secrets.PUBLISH_TOKEN }}
59 | run: ./gradlew publishPlugin
60 |
61 | # Upload artifact as a release asset
62 | - name: Upload Release Asset
63 | env:
64 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
65 | run: gh release upload ${{ github.event.release.tag_name }} ./build/distributions/*
66 |
67 | # Create pull request
68 | - name: Create Pull Request
69 | if: ${{ steps.properties.outputs.changelog != '' }}
70 | env:
71 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
72 | run: |
73 | VERSION="${{ github.event.release.tag_name }}"
74 | BRANCH="changelog-update-$VERSION"
75 |
76 | git config user.email "action@github.com"
77 | git config user.name "GitHub Action"
78 |
79 | git checkout -b $BRANCH
80 | git commit -am "Changelog update - $VERSION"
81 | git push --set-upstream origin $BRANCH
82 |
83 | gh pr create \
84 | --title "Changelog update - \`$VERSION\`" \
85 | --body "Current pull request contains patched \`CHANGELOG.md\` file for the \`$VERSION\` version." \
86 | --base main \
87 | --head $BRANCH
88 |
--------------------------------------------------------------------------------
/src/main/resources/META-INF/pluginIcon.svg:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/src/main/kotlin/com/bredogen/projectenv/ui/ToolWindowPanel.kt:
--------------------------------------------------------------------------------
1 | package com.bredogen.projectenv.ui
2 |
3 | import com.bredogen.projectenv.EnvSourceEntry
4 | import com.bredogen.projectenv.services.ProjectEnvService
5 | import com.intellij.icons.AllIcons
6 | import com.intellij.openapi.actionSystem.AnAction
7 | import com.intellij.openapi.actionSystem.AnActionEvent
8 | import com.intellij.openapi.actionSystem.DefaultActionGroup
9 | import com.intellij.openapi.project.Project
10 | import com.intellij.openapi.project.guessProjectDir
11 | import com.intellij.openapi.ui.SimpleToolWindowPanel
12 | import com.intellij.openapi.ui.popup.JBPopupFactory
13 | import com.intellij.openapi.ui.popup.ListPopup
14 | import com.intellij.ui.*
15 | import com.intellij.ui.components.JBList
16 | import java.awt.event.MouseEvent
17 | import java.io.File
18 | import javax.swing.JList
19 | import javax.swing.event.ListDataEvent
20 | import javax.swing.event.ListDataListener
21 |
22 |
23 | class ToolWindowPanel(project: Project) : SimpleToolWindowPanel(true, true) {
24 |
25 | private val service: ProjectEnvService
26 |
27 | init {
28 | service = ProjectEnvService.getInstance(project)
29 |
30 | val listModel = CollectionListModel(service.envFiles)
31 | listModel.addListDataListener(object : ListDataListener {
32 | override fun intervalAdded(e: ListDataEvent?) {
33 | service.envFiles = listModel.toList()
34 | }
35 |
36 | override fun intervalRemoved(e: ListDataEvent?) {
37 | service.envFiles = listModel.toList()
38 | }
39 |
40 | override fun contentsChanged(e: ListDataEvent?) {
41 | service.envFiles = listModel.toList()
42 | }
43 |
44 | })
45 |
46 | val list = JBList(listModel)
47 | list.cellRenderer = object : ColoredListCellRenderer() {
48 | override fun customizeCellRenderer(list: JList<*>, value: Any?, index: Int, selected: Boolean, hasFocus: Boolean) {
49 | if (value is EnvSourceEntry) {
50 | icon = EnvSourceEntry.typeIcons[value.type]
51 | val projectPath = (project.guessProjectDir()?.path ?: "") + File.separator
52 | val filePath = value.name.removePrefix(projectPath)
53 |
54 | append(filePath)
55 | append(" ${value.type}", SimpleTextAttributes.GRAY_SMALL_ATTRIBUTES)
56 | }
57 | }
58 | }
59 | object : DoubleClickListener() {
60 | override fun onDoubleClick(event: MouseEvent): Boolean {
61 | if (list.selectedValue == null) return true
62 | list.selectedValue.provider.handleDoubleClick(project)
63 | return true
64 | }
65 | }.installOn(list)
66 |
67 | val toolbarDecorator = ToolbarDecorator.createDecorator(list).apply {
68 |
69 | setAddAction { button ->
70 | val actionGroup = DefaultActionGroup()
71 | EnvSourceEntry.typeTitles.forEach {
72 | (type, name) ->
73 | actionGroup.add(object : AnAction(name, null, AllIcons.Actions.AddFile) {
74 | override fun actionPerformed(e: AnActionEvent) {
75 |
76 | val params = EnvSourceEntry.getProviderFactory(type).createParams(project)
77 | if (params.isNotEmpty()) {
78 | listModel.add(EnvSourceEntry(params, type))
79 | }
80 | }
81 | })
82 | actionGroup.addSeparator()
83 | }
84 |
85 | val popup: ListPopup = JBPopupFactory.getInstance().createActionGroupPopup(
86 | "Add...",
87 | actionGroup,
88 | button.dataContext,
89 | true,
90 | null,
91 | -1
92 | )
93 | popup.show(button.preferredPopupPoint)
94 | }
95 | }
96 | setContent(toolbarDecorator.createPanel())
97 | }
98 | }
--------------------------------------------------------------------------------
/.github/workflows/build.yml:
--------------------------------------------------------------------------------
1 | # GitHub Actions Workflow created for testing and preparing the plugin release in following steps:
2 | # - validate Gradle Wrapper,
3 | # - run 'test' and 'verifyPlugin' tasks,
4 | # - run Qodana inspections,
5 | # - run 'buildPlugin' task and prepare artifact for the further tests,
6 | # - run 'runPluginVerifier' task,
7 | # - create a draft release.
8 | #
9 | # Workflow is triggered on push and pull_request events.
10 | #
11 | # GitHub Actions reference: https://help.github.com/en/actions
12 | #
13 | ## JBIJPPTPL
14 |
15 | name: Build
16 | on:
17 | # Trigger the workflow on pushes to only the 'main' branch (this avoids duplicate checks being run e.g. for dependabot pull requests)
18 | push:
19 | branches: [main]
20 | # Trigger the workflow on any pull request
21 | pull_request:
22 |
23 | jobs:
24 |
25 | # Run Gradle Wrapper Validation Action to verify the wrapper's checksum
26 | # Run verifyPlugin, IntelliJ Plugin Verifier, and test Gradle tasks
27 | # Build plugin and provide the artifact for the next workflow jobs
28 | build:
29 | name: Build
30 | runs-on: ubuntu-latest
31 | outputs:
32 | version: ${{ steps.properties.outputs.version }}
33 | changelog: ${{ steps.properties.outputs.changelog }}
34 | steps:
35 |
36 | # Check out current repository
37 | - name: Fetch Sources
38 | uses: actions/checkout@v2.4.0
39 |
40 | # Validate wrapper
41 | - name: Gradle Wrapper Validation
42 | uses: gradle/wrapper-validation-action@v1.0.4
43 |
44 | # Setup Java 11 environment for the next steps
45 | - name: Setup Java
46 | uses: actions/setup-java@v2
47 | with:
48 | distribution: zulu
49 | java-version: 11
50 | cache: gradle
51 |
52 | # Set environment variables
53 | - name: Export Properties
54 | id: properties
55 | shell: bash
56 | run: |
57 | PROPERTIES="$(./gradlew properties --console=plain -q)"
58 | VERSION="$(echo "$PROPERTIES" | grep "^version:" | cut -f2- -d ' ')"
59 | NAME="$(echo "$PROPERTIES" | grep "^pluginName:" | cut -f2- -d ' ')"
60 | CHANGELOG="$(./gradlew getChangelog --unreleased --no-header --console=plain -q)"
61 | CHANGELOG="${CHANGELOG//'%'/'%25'}"
62 | CHANGELOG="${CHANGELOG//$'\n'/'%0A'}"
63 | CHANGELOG="${CHANGELOG//$'\r'/'%0D'}"
64 |
65 | echo "::set-output name=version::$VERSION"
66 | echo "::set-output name=name::$NAME"
67 | echo "::set-output name=changelog::$CHANGELOG"
68 | echo "::set-output name=pluginVerifierHomeDir::~/.pluginVerifier"
69 |
70 | ./gradlew listProductsReleases # prepare list of IDEs for Plugin Verifier
71 |
72 | # Run tests
73 | - name: Run Tests
74 | run: ./gradlew test
75 |
76 | # Collect Tests Result of failed tests
77 | - name: Collect Tests Result
78 | if: ${{ failure() }}
79 | uses: actions/upload-artifact@v2
80 | with:
81 | name: tests-result
82 | path: ${{ github.workspace }}/build/reports/tests
83 |
84 | # Cache Plugin Verifier IDEs
85 | - name: Setup Plugin Verifier IDEs Cache
86 | uses: actions/cache@v2.1.7
87 | with:
88 | path: ${{ steps.properties.outputs.pluginVerifierHomeDir }}/ides
89 | key: plugin-verifier-${{ hashFiles('build/listProductsReleases.txt') }}
90 |
91 | # Run Verify Plugin task and IntelliJ Plugin Verifier tool
92 | - name: Run Plugin Verification tasks
93 | run: ./gradlew runPluginVerifier -Pplugin.verifier.home.dir=${{ steps.properties.outputs.pluginVerifierHomeDir }}
94 |
95 | # Collect Plugin Verifier Result
96 | - name: Collect Plugin Verifier Result
97 | if: ${{ always() }}
98 | uses: actions/upload-artifact@v2
99 | with:
100 | name: pluginVerifier-result
101 | path: ${{ github.workspace }}/build/reports/pluginVerifier
102 |
103 | # Run Qodana inspections
104 | # - name: Qodana - Code Inspection
105 | # uses: JetBrains/qodana-action@v4.2.5
106 |
107 | # Prepare plugin archive content for creating artifact
108 | - name: Prepare Plugin Artifact
109 | id: artifact
110 | shell: bash
111 | run: |
112 | cd ${{ github.workspace }}/build/distributions
113 | FILENAME=`ls *.zip`
114 | unzip "$FILENAME" -d content
115 |
116 | echo "::set-output name=filename::${FILENAME:0:-4}"
117 |
118 | # Store already-built plugin as an artifact for downloading
119 | - name: Upload artifact
120 | uses: actions/upload-artifact@v2.2.4
121 | with:
122 | name: ${{ steps.artifact.outputs.filename }}
123 | path: ./build/distributions/content/*/*
124 |
125 | # Prepare a draft release for GitHub Releases page for the manual verification
126 | # If accepted and published, release workflow would be triggered
127 | releaseDraft:
128 | name: Release Draft
129 | if: github.event_name != 'pull_request'
130 | needs: build
131 | runs-on: ubuntu-latest
132 | steps:
133 |
134 | # Check out current repository
135 | - name: Fetch Sources
136 | uses: actions/checkout@v2.4.0
137 |
138 | # Remove old release drafts by using the curl request for the available releases with draft flag
139 | - name: Remove Old Release Drafts
140 | env:
141 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
142 | run: |
143 | gh api repos/{owner}/{repo}/releases \
144 | --jq '.[] | select(.draft == true) | .id' \
145 | | xargs -I '{}' gh api -X DELETE repos/{owner}/{repo}/releases/{}
146 |
147 | # Create new release draft - which is not publicly visible and requires manual acceptance
148 | - name: Create Release Draft
149 | env:
150 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
151 | run: |
152 | gh release create v${{ needs.build.outputs.version }} \
153 | --draft \
154 | --title "v${{ needs.build.outputs.version }}" \
155 | --notes "$(cat << 'EOM'
156 | ${{ needs.build.outputs.changelog }}
157 | EOM
158 | )"
159 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | #
4 | # Copyright © 2015-2021 the original authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | #
21 | # Gradle start up script for POSIX generated by Gradle.
22 | #
23 | # Important for running:
24 | #
25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
26 | # noncompliant, but you have some other compliant shell such as ksh or
27 | # bash, then to run this script, type that shell name before the whole
28 | # command line, like:
29 | #
30 | # ksh Gradle
31 | #
32 | # Busybox and similar reduced shells will NOT work, because this script
33 | # requires all of these POSIX shell features:
34 | # * functions;
35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»;
37 | # * compound commands having a testable exit status, especially «case»;
38 | # * various built-in commands including «command», «set», and «ulimit».
39 | #
40 | # Important for patching:
41 | #
42 | # (2) This script targets any POSIX shell, so it avoids extensions provided
43 | # by Bash, Ksh, etc; in particular arrays are avoided.
44 | #
45 | # The "traditional" practice of packing multiple parameters into a
46 | # space-separated string is a well documented source of bugs and security
47 | # problems, so this is (mostly) avoided, by progressively accumulating
48 | # options in "$@", and eventually passing that to Java.
49 | #
50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
52 | # see the in-line comments for details.
53 | #
54 | # There are tweaks for specific operating systems such as AIX, CygWin,
55 | # Darwin, MinGW, and NonStop.
56 | #
57 | # (3) This script is generated from the Groovy template
58 | # https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
59 | # within the Gradle project.
60 | #
61 | # You can find Gradle at https://github.com/gradle/gradle/.
62 | #
63 | ##############################################################################
64 |
65 | # Attempt to set APP_HOME
66 |
67 | # Resolve links: $0 may be a link
68 | app_path=$0
69 |
70 | # Need this for daisy-chained symlinks.
71 | while
72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
73 | [ -h "$app_path" ]
74 | do
75 | ls=$( ls -ld "$app_path" )
76 | link=${ls#*' -> '}
77 | case $link in #(
78 | /*) app_path=$link ;; #(
79 | *) app_path=$APP_HOME$link ;;
80 | esac
81 | done
82 |
83 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
84 |
85 | APP_NAME="Gradle"
86 | APP_BASE_NAME=${0##*/}
87 |
88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
90 |
91 | # Use the maximum available, or set MAX_FD != -1 to use that value.
92 | MAX_FD=maximum
93 |
94 | warn () {
95 | echo "$*"
96 | } >&2
97 |
98 | die () {
99 | echo
100 | echo "$*"
101 | echo
102 | exit 1
103 | } >&2
104 |
105 | # OS specific support (must be 'true' or 'false').
106 | cygwin=false
107 | msys=false
108 | darwin=false
109 | nonstop=false
110 | case "$( uname )" in #(
111 | CYGWIN* ) cygwin=true ;; #(
112 | Darwin* ) darwin=true ;; #(
113 | MSYS* | MINGW* ) msys=true ;; #(
114 | NONSTOP* ) nonstop=true ;;
115 | esac
116 |
117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
118 |
119 |
120 | # Determine the Java command to use to start the JVM.
121 | if [ -n "$JAVA_HOME" ] ; then
122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
123 | # IBM's JDK on AIX uses strange locations for the executables
124 | JAVACMD=$JAVA_HOME/jre/sh/java
125 | else
126 | JAVACMD=$JAVA_HOME/bin/java
127 | fi
128 | if [ ! -x "$JAVACMD" ] ; then
129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
130 |
131 | Please set the JAVA_HOME variable in your environment to match the
132 | location of your Java installation."
133 | fi
134 | else
135 | JAVACMD=java
136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
137 |
138 | Please set the JAVA_HOME variable in your environment to match the
139 | location of your Java installation."
140 | fi
141 |
142 | # Increase the maximum file descriptors if we can.
143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
144 | case $MAX_FD in #(
145 | max*)
146 | MAX_FD=$( ulimit -H -n ) ||
147 | warn "Could not query maximum file descriptor limit"
148 | esac
149 | case $MAX_FD in #(
150 | '' | soft) :;; #(
151 | *)
152 | ulimit -n "$MAX_FD" ||
153 | warn "Could not set maximum file descriptor limit to $MAX_FD"
154 | esac
155 | fi
156 |
157 | # Collect all arguments for the java command, stacking in reverse order:
158 | # * args from the command line
159 | # * the main class name
160 | # * -classpath
161 | # * -D...appname settings
162 | # * --module-path (only if needed)
163 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
164 |
165 | # For Cygwin or MSYS, switch paths to Windows format before running java
166 | if "$cygwin" || "$msys" ; then
167 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
168 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
169 |
170 | JAVACMD=$( cygpath --unix "$JAVACMD" )
171 |
172 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
173 | for arg do
174 | if
175 | case $arg in #(
176 | -*) false ;; # don't mess with options #(
177 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
178 | [ -e "$t" ] ;; #(
179 | *) false ;;
180 | esac
181 | then
182 | arg=$( cygpath --path --ignore --mixed "$arg" )
183 | fi
184 | # Roll the args list around exactly as many times as the number of
185 | # args, so each arg winds up back in the position where it started, but
186 | # possibly modified.
187 | #
188 | # NB: a `for` loop captures its iteration list before it begins, so
189 | # changing the positional parameters here affects neither the number of
190 | # iterations, nor the values presented in `arg`.
191 | shift # remove old arg
192 | set -- "$@" "$arg" # push replacement arg
193 | done
194 | fi
195 |
196 | # Collect all arguments for the java command;
197 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
198 | # shell script including quotes and variable substitutions, so put them in
199 | # double quotes to make sure that they get re-expanded; and
200 | # * put everything else in single quotes, so that it's not re-expanded.
201 |
202 | set -- \
203 | "-Dorg.gradle.appname=$APP_BASE_NAME" \
204 | -classpath "$CLASSPATH" \
205 | org.gradle.wrapper.GradleWrapperMain \
206 | "$@"
207 |
208 | # Use "xargs" to parse quoted args.
209 | #
210 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed.
211 | #
212 | # In Bash we could simply go:
213 | #
214 | # readarray ARGS < <( xargs -n1 <<<"$var" ) &&
215 | # set -- "${ARGS[@]}" "$@"
216 | #
217 | # but POSIX shell has neither arrays nor command substitution, so instead we
218 | # post-process each arg (as a line of input to sed) to backslash-escape any
219 | # character that might be a shell metacharacter, then use eval to reverse
220 | # that process (while maintaining the separation between arguments), and wrap
221 | # the whole thing up as a single "set" statement.
222 | #
223 | # This will of course break if any of these variables contains a newline or
224 | # an unmatched quote.
225 | #
226 |
227 | eval "set -- $(
228 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
229 | xargs -n1 |
230 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
231 | tr '\n' ' '
232 | )" '"$@"'
233 |
234 | exec "$JAVACMD" "$@"
235 |
--------------------------------------------------------------------------------