From bcbbf13e8319854bf2c1d0f7376c25207a8b6810 Mon Sep 17 00:00:00 2001 From: Supratik Das Date: Sat, 30 Mar 2024 15:33:00 +0530 Subject: [PATCH 01/15] Add plugin token based auth and module variant selection --- build.gradle.kts | 2 +- .../com/dashwave/plugin/PluginStartup.kt | 60 +++++++++++- .../dashwave/plugin/dialogbox/LoginDialog.kt | 91 +++++++++++++++++++ .../com/dashwave/plugin/utils/DwBuild.kt | 15 ++- .../com/dashwave/plugin/utils/DwCmds.kt | 18 ++++ .../com/dashwave/plugin/utils/Process.kt | 7 ++ .../dashwave/plugin/windows/DashwaveWindow.kt | 65 ++++++++++++- 7 files changed, 250 insertions(+), 8 deletions(-) create mode 100644 src/main/kotlin/com/dashwave/plugin/dialogbox/LoginDialog.kt diff --git a/build.gradle.kts b/build.gradle.kts index 387ce14..4d61aca 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,7 +5,7 @@ plugins { } group = "com.dashwave" -version = "2.0.1" +version = "2.2.0" repositories { mavenCentral() diff --git a/src/main/kotlin/com/dashwave/plugin/PluginStartup.kt b/src/main/kotlin/com/dashwave/plugin/PluginStartup.kt index 8a82c6a..6791b76 100644 --- a/src/main/kotlin/com/dashwave/plugin/PluginStartup.kt +++ b/src/main/kotlin/com/dashwave/plugin/PluginStartup.kt @@ -29,8 +29,9 @@ class PluginStartup: StartupActivity { } fun checkDW(project: Project) { - val dwCmd = DwCmds("check-update", "", true) + val dwCmd = DwCmds("check-update -e dev", "", true) val exitCode = dwCmd.executeWithExitCode() + DashwaveWindow.displayInfo(Messages.DW_INSTALLED_ALREADY) if (exitCode == 0) { DashwaveWindow.displayInfo(Messages.DW_INSTALLED_ALREADY) verifyLogin(project?.basePath) @@ -92,6 +93,7 @@ fun verifyLogin(pwd:String?){ fun checkProjectConnected(pwd:String?){ if (doesFileExist("$pwd/dashwave.yml")){ DashwaveWindow.enableRunButton() + listModulesAndVariants(pwd) DashwaveWindow.displayOutput("✅ Project is successfully connected to dashwave. Run a cloud build using dashwave icon on toolbar\n\n", ConsoleViewContentType.NORMAL_OUTPUT) val dd = ReadyForBuildDialog() dd.show() @@ -102,7 +104,12 @@ fun checkProjectConnected(pwd:String?){ } fun loginUser(pwd:String?) { - val loginUserCmd = "login" + val loginDialog = LoginDialog() + var accessCode: String = "" + if (loginDialog.showAndGet()) { + accessCode = loginDialog.getAccessCode() + } + val loginUserCmd = "login -e local $accessCode" val exitCode = DwCmds(loginUserCmd, "", true).executeWithExitCode() if (exitCode == 0) { checkProjectConnected(pwd) @@ -119,6 +126,54 @@ fun doesFileExist(path: String): Boolean { return file.exists() } +fun listModulesAndVariants(pwd:String?) { + val configsCmd = DwCmds("build configs", pwd, true) + var output = configsCmd.executeWithOutput() + val ansiEscapeRegex = "\\x1B\\[[;\\d]*m".toRegex() + output = output.replace(ansiEscapeRegex, "") + + val map = mutableMapOf>() + var defaultModule: String = "" + var defaultVariant: String = "" + var foundDefault = false + + // Split the input string by lines + val lines = output.split("\n") + + for (line in lines) { + // Split each line by ':' + val parts = line.split(":").map { it.trim() } // Trim to remove leading/trailing whitespace + + if (parts.size == 2) { + // The first part is the project name, and the second part contains the build types + val projectName = parts[0] + val buildTypes = parts[1].trim('[', ']').split(" ").filter { it.isNotEmpty() } + + // Populate the map + if (projectName == "default") { + if (buildTypes.size >= 2) { + defaultModule = buildTypes[0] + defaultVariant = buildTypes[1] + foundDefault = true + } else { + println("Warning: 'default' project does not contain enough build types.") + } + } else { + map[projectName] = buildTypes + } + } + } + + if (!foundDefault && map.isNotEmpty()) { + map.entries.first().let { firstEntry -> + defaultModule = firstEntry.key + defaultVariant = firstEntry.value.firstOrNull() ?: "" + } + } + + DashwaveWindow.addModulesAndVariants(map, defaultModule, defaultVariant) +} + fun openCreateProjectDialog(pwd:String?, openTip:Boolean):Boolean{ val createProjectDialog = CreateProjectDialog() if (createProjectDialog.showAndGet()){ @@ -144,6 +199,7 @@ fun createProject(projectName: String, devStack:String, rootDir:String,pwd:Strin val exitCode = DwCmds(createProjectCmd, pwd, true).executeWithExitCode() if(exitCode == 0){ DashwaveWindow.enableRunButton() + listModulesAndVariants(pwd) Notifications.Bus.notify( Notification( "YourPluginNotificationGroup", diff --git a/src/main/kotlin/com/dashwave/plugin/dialogbox/LoginDialog.kt b/src/main/kotlin/com/dashwave/plugin/dialogbox/LoginDialog.kt new file mode 100644 index 0000000..a98a479 --- /dev/null +++ b/src/main/kotlin/com/dashwave/plugin/dialogbox/LoginDialog.kt @@ -0,0 +1,91 @@ +package com.dashwave.plugin + +import com.intellij.ide.BrowserUtil +import com.intellij.openapi.ui.DialogWrapper +import com.intellij.openapi.util.IconLoader +import java.awt.* +import java.awt.event.MouseAdapter +import java.awt.event.MouseEvent +import javax.swing.* + + +class LoginDialog : DialogWrapper(true) { + private val accessCodeTextField = JPasswordField(20) + + + init { + title = "Log in to Dashwave Cloud" + init() + } + + override fun createCenterPanel(): JComponent? { + val panel = JPanel(GridBagLayout()) + val gbc = GridBagConstraints() + + gbc.insets = Insets(4, 4, 4, 4) // You can adjust padding here + gbc.fill = GridBagConstraints.HORIZONTAL + gbc.gridx = 0 + gbc.gridy = 0 + gbc.gridwidth = 2 + + val icon = IconLoader.getIcon("/icons/dashwave13.svg") // Make sure to provide the correct path + val labelWithIcon = JLabel("Login to Dashwave Cloud by entering your access code", icon, SwingConstants.LEFT) + panel.add(labelWithIcon, gbc) + + val linkHeadLabel = JLabel("Visit this link to view your access code on Dashwave's console:") + gbc.gridy+=20 + gbc.gridx = 0 + gbc.gridwidth = 2 + linkHeadLabel.preferredSize = Dimension(600, linkHeadLabel.preferredSize.height+10) + panel.add(linkHeadLabel, gbc) + + val linkLabel = JLabel("https://console.dashwave.io/home?profile=true") + linkLabel.cursor = Cursor(Cursor.HAND_CURSOR) // Change the cursor to a hand cursor + + linkLabel.addMouseListener(object : MouseAdapter() { + override fun mouseClicked(e: MouseEvent?) { + BrowserUtil.browse("https://console.dashwave.io/home?profile=true") + } + + override fun mouseEntered(e: MouseEvent?) { + linkLabel.text = "https://console.dashwave.io/home?profile=true" // Underline on hover + } + + override fun mouseExited(e: MouseEvent?) { + linkLabel.text = "https://console.dashwave.io/home?profile=true" // Remove underline when not hovering + } + }) + + gbc.gridx = 0 + gbc.gridy+=1 + gbc.gridwidth = 10 + linkLabel.preferredSize = Dimension(600, linkLabel.preferredSize.height) + panel.add(linkLabel, gbc) + + gbc.gridy+=200 + gbc.gridwidth = 1 + panel.add(JLabel("Access Code:"), gbc) + + gbc.gridx++ + gbc.gridwidth = 1 + accessCodeTextField.preferredSize = Dimension(200, accessCodeTextField.preferredSize.height) // Adjust width as needed + panel.add(accessCodeTextField, gbc) + +// if (accessCodeTextField.text.isEmpty()) { +// setErrorText("Please enter your access code") +// } + + // change the ok button to login + setOKButtonText("Login") + + return panel + } + + fun getAccessCode(): String { + if (accessCodeTextField.text.isEmpty()) { + return "" + } + return accessCodeTextField.text + } +} + diff --git a/src/main/kotlin/com/dashwave/plugin/utils/DwBuild.kt b/src/main/kotlin/com/dashwave/plugin/utils/DwBuild.kt index 7d70b1c..bdf92b4 100644 --- a/src/main/kotlin/com/dashwave/plugin/utils/DwBuild.kt +++ b/src/main/kotlin/com/dashwave/plugin/utils/DwBuild.kt @@ -7,11 +7,13 @@ import com.intellij.openapi.project.Project import okhttp3.internal.wait import kotlin.concurrent.thread -class DwBuildConfig(clean:Boolean,debug:Boolean,openEmulator:Boolean, pwd:String?){ +class DwBuildConfig(clean:Boolean,debug:Boolean,openEmulator:Boolean,module:String,variant:String, pwd:String?){ var clean:Boolean = clean var debug:Boolean = debug var openEmulator:Boolean = openEmulator var pwd:String? = pwd + var module:String = module + var variant:String = variant } class DwBuild(config: DwBuildConfig){ @@ -25,6 +27,15 @@ class DwBuild(config: DwBuildConfig){ if(config.debug){ cmd += " --debug" } + + if (config.module != ""){ + cmd += " --module ${config.module}" + } + + if (config.variant != ""){ + cmd += " --variant ${config.variant}" + } + pwd = config.pwd openEmulator = config.openEmulator } @@ -36,7 +47,7 @@ class DwBuild(config: DwBuildConfig){ private fun execute(){ // DashwaveWindow.displayInfo() val buildCmd = DwCmds(cmd, pwd, true) - buildCmd.executeBuild(pwd, openEmulator) +// buildCmd.executeBuild(pwd, openEmulator) } fun killEmulator(){ diff --git a/src/main/kotlin/com/dashwave/plugin/utils/DwCmds.kt b/src/main/kotlin/com/dashwave/plugin/utils/DwCmds.kt index 6be2842..01e5174 100644 --- a/src/main/kotlin/com/dashwave/plugin/utils/DwCmds.kt +++ b/src/main/kotlin/com/dashwave/plugin/utils/DwCmds.kt @@ -10,6 +10,8 @@ import com.intellij.openapi.keymap.impl.ui.Hyperlink import com.intellij.openapi.project.Project import com.intellij.util.Futures.thenRunAsync import okhttp3.internal.wait +import java.io.BufferedReader +import java.io.InputStreamReader import java.util.concurrent.CompletableFuture import java.util.concurrent.Executors import kotlin.system.exitProcess @@ -37,6 +39,22 @@ class DwCmds(execCmd:String, wd:String?, log: Boolean){ return exitCode } + fun executeWithOutput():String{ + this.p.start() + val exitCode = this.p.wait() + if(exitCode == 11){ + DashwaveWindow.displayError("Dashwave has a major update, you need to update dependencies\n") + val hyperlink = HyperlinkInfo { p: Project -> + installDW(this.pwd) + } + DashwaveWindow.console.printHyperlink("Click here to update\n\n", hyperlink) + } + + // get the stdout as string + return this.p.getOutput() + } + + fun exit(){ this.p.exit() } diff --git a/src/main/kotlin/com/dashwave/plugin/utils/Process.kt b/src/main/kotlin/com/dashwave/plugin/utils/Process.kt index 58d3da9..e3a5995 100644 --- a/src/main/kotlin/com/dashwave/plugin/utils/Process.kt +++ b/src/main/kotlin/com/dashwave/plugin/utils/Process.kt @@ -8,6 +8,7 @@ import com.intellij.openapi.util.Key import okhttp3.internal.wait import java.io.BufferedReader import java.io.File +import java.io.InputStreamReader import java.util.concurrent.CountDownLatch import java.util.concurrent.ExecutorService import java.util.concurrent.Executors @@ -16,6 +17,7 @@ import kotlin.concurrent.thread class Process(cmd:String, pwd:String?, log:Boolean){ private var ph:ProcessHandler private val latch = CountDownLatch(1) + private val outputBuilder = StringBuilder() init { val cmd = GeneralCommandLine("/bin/bash","-c",cmd) if(pwd != null && pwd != ""){ @@ -27,6 +29,7 @@ class Process(cmd:String, pwd:String?, log:Boolean){ ph = OSProcessHandler(cmd) ph.addProcessListener(object:ProcessAdapter(){ override fun onTextAvailable(event: ProcessEvent, outputType: Key<*>) { + outputBuilder.append(event.text) if(log) { decodeAndPrintString(event.text, outputType) } @@ -50,6 +53,10 @@ class Process(cmd:String, pwd:String?, log:Boolean){ fun exit(){ ph.destroyProcess() } + + fun getOutput(): String { + return outputBuilder.toString() + } } private fun decodeAndPrintString(s:String, p: Key<*>){ val decoder = AnsiEscapeDecoder() diff --git a/src/main/kotlin/com/dashwave/plugin/windows/DashwaveWindow.kt b/src/main/kotlin/com/dashwave/plugin/windows/DashwaveWindow.kt index aa3accd..a1d45db 100644 --- a/src/main/kotlin/com/dashwave/plugin/windows/DashwaveWindow.kt +++ b/src/main/kotlin/com/dashwave/plugin/windows/DashwaveWindow.kt @@ -22,10 +22,15 @@ import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.util.IconLoader import com.intellij.openapi.wm.ToolWindowManager import com.intellij.ui.AnimatedIcon +import com.intellij.ui.components.JBList +import com.jetbrains.rd.util.first +import java.awt.Dimension import java.awt.event.ItemEvent import java.awt.event.ItemListener import javax.swing.Icon +import javax.swing.JComboBox import javax.swing.JLabel +import javax.swing.JList class DashwaveWindow : ToolWindowFactory { companion object { @@ -41,6 +46,8 @@ class DashwaveWindow : ToolWindowFactory { private var cleanBuildCheckbox:JCheckBox = JCheckBox("Clean Build") private var debugEnabledCheckBox: JCheckBox = JCheckBox("Enable Debug") private var openEmulatorCheckbox:JCheckBox = JCheckBox("Open Emulator") + private var modulesList: JComboBox = JComboBox() + private var variantsList: JComboBox = JComboBox() fun show(){ val toolWindowManager = ToolWindowManager.getInstance(p) @@ -62,8 +69,10 @@ class DashwaveWindow : ToolWindowFactory { val cleanBuild = cleanBuildCheckbox.isSelected val debugEnabled = debugEnabledCheckBox.isSelected val openEmulator = openEmulatorCheckbox.isSelected + val module: String = modulesList.selectedItem?.toString() ?: "app" + val variant: String = variantsList.selectedItem?.toString() ?: "Debug" DashwaveWindow.displayInfo("open emulator is $openEmulator") - return DwBuildConfig(cleanBuild, debugEnabled, openEmulator,p.basePath) + return DwBuildConfig(cleanBuild, debugEnabled, openEmulator, module, variant, p.basePath) } fun displayOutput(s:String, type:ConsoleViewContentType){ @@ -100,9 +109,36 @@ class DashwaveWindow : ToolWindowFactory { fun enableCancelButton(){ cancelButton.isEnabled = true } - } - + fun addModulesAndVariants(modulesVariants: Map>, defaultModule: String, defaultVariant: String){ + modulesList.removeAllItems() + variantsList.removeAllItems() + + modulesList.addItem(defaultModule) + variantsList.addItem(defaultVariant) + + modulesVariants.keys.toTypedArray().forEach { module -> + modulesList.addItem(module) + } + + modulesList.addItemListener(ItemListener { + if (it.stateChange == ItemEvent.SELECTED) { + val selectedModule = modulesList.selectedItem as String + + variantsList.removeAllItems() + modulesVariants[selectedModule]?.forEach { variant -> + variantsList.addItem(variant) + } + } + }) + + variantsList.addItemListener(ItemListener { + if (it.stateChange == ItemEvent.SELECTED) { + val selectedVariant = variantsList.selectedItem as String + } + }) + } + } override fun createToolWindowContent(project: Project, toolWindow: ToolWindow) { println("\n\ncretate tool window content is called") @@ -137,6 +173,29 @@ class DashwaveWindow : ToolWindowFactory { optionToolbar.add(cleanBuildCheckbox) optionToolbar.add(debugEnabledCheckBox) optionToolbar.add(openEmulatorCheckbox) + + modulesList.addItemListener(ItemListener { + if (it.stateChange == ItemEvent.SELECTED) { + val selectedModule = modulesList.selectedItem as String +// displayInfo("Selected module is $selectedModule") + } + }) + variantsList.addItemListener(ItemListener { + if (it.stateChange == ItemEvent.SELECTED) { + val selectedVariant = variantsList.selectedItem as String +// displayInfo("Selected variant is $selectedVariant") + } + }) + + modulesList.preferredSize = Dimension(100, modulesList.preferredSize.height) + variantsList.preferredSize = Dimension(100, variantsList.preferredSize.height) + + // add non-item label to modules and variants + optionToolbar.add(JLabel("Modules")) + optionToolbar.add(modulesList) + + optionToolbar.add(JLabel("Variants")) + optionToolbar.add(variantsList) openEmulatorCheckbox.isSelected = true panel.add(actionToolbar, BorderLayout.NORTH) From 5323030f4b22511b0a4e4782adffff1402d113cb Mon Sep 17 00:00:00 2001 From: Supratik Das Date: Sat, 30 Mar 2024 15:39:49 +0530 Subject: [PATCH 02/15] Remove dev and local mode --- src/main/kotlin/com/dashwave/plugin/PluginStartup.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/com/dashwave/plugin/PluginStartup.kt b/src/main/kotlin/com/dashwave/plugin/PluginStartup.kt index 6791b76..a9e24f0 100644 --- a/src/main/kotlin/com/dashwave/plugin/PluginStartup.kt +++ b/src/main/kotlin/com/dashwave/plugin/PluginStartup.kt @@ -29,7 +29,7 @@ class PluginStartup: StartupActivity { } fun checkDW(project: Project) { - val dwCmd = DwCmds("check-update -e dev", "", true) + val dwCmd = DwCmds("check-update", "", true) val exitCode = dwCmd.executeWithExitCode() DashwaveWindow.displayInfo(Messages.DW_INSTALLED_ALREADY) if (exitCode == 0) { @@ -109,7 +109,7 @@ fun loginUser(pwd:String?) { if (loginDialog.showAndGet()) { accessCode = loginDialog.getAccessCode() } - val loginUserCmd = "login -e local $accessCode" + val loginUserCmd = "login $accessCode" val exitCode = DwCmds(loginUserCmd, "", true).executeWithExitCode() if (exitCode == 0) { checkProjectConnected(pwd) From 569f5e2e87817d98e4d6b17c3e12f735f275ae8b Mon Sep 17 00:00:00 2001 From: Supratik Das Date: Sat, 30 Mar 2024 15:46:56 +0530 Subject: [PATCH 03/15] Remove stray window message --- src/main/kotlin/com/dashwave/plugin/PluginStartup.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/kotlin/com/dashwave/plugin/PluginStartup.kt b/src/main/kotlin/com/dashwave/plugin/PluginStartup.kt index a9e24f0..ab809d4 100644 --- a/src/main/kotlin/com/dashwave/plugin/PluginStartup.kt +++ b/src/main/kotlin/com/dashwave/plugin/PluginStartup.kt @@ -31,7 +31,6 @@ class PluginStartup: StartupActivity { fun checkDW(project: Project) { val dwCmd = DwCmds("check-update", "", true) val exitCode = dwCmd.executeWithExitCode() - DashwaveWindow.displayInfo(Messages.DW_INSTALLED_ALREADY) if (exitCode == 0) { DashwaveWindow.displayInfo(Messages.DW_INSTALLED_ALREADY) verifyLogin(project?.basePath) From 1e1d2146daeb70dd2cc439bf77e6cf3d1a486223 Mon Sep 17 00:00:00 2001 From: Aviral Jain Date: Wed, 3 Apr 2024 17:08:14 +0530 Subject: [PATCH 04/15] change login dialog messages --- .../dashwave/plugin/dialogbox/LoginDialog.kt | 17 +++++++++++++---- src/main/resources/META-INF/plugin.xml | 4 ++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/com/dashwave/plugin/dialogbox/LoginDialog.kt b/src/main/kotlin/com/dashwave/plugin/dialogbox/LoginDialog.kt index a98a479..96cd06d 100644 --- a/src/main/kotlin/com/dashwave/plugin/dialogbox/LoginDialog.kt +++ b/src/main/kotlin/com/dashwave/plugin/dialogbox/LoginDialog.kt @@ -14,7 +14,8 @@ class LoginDialog : DialogWrapper(true) { init { - title = "Log in to Dashwave Cloud" + // TODO: add logo to title + title = "Authenticate with Dashwave Cloud" init() } @@ -29,16 +30,24 @@ class LoginDialog : DialogWrapper(true) { gbc.gridwidth = 2 val icon = IconLoader.getIcon("/icons/dashwave13.svg") // Make sure to provide the correct path + this.createTitlePane() + val labelWithIcon = JLabel("Login to Dashwave Cloud by entering your access code", icon, SwingConstants.LEFT) - panel.add(labelWithIcon, gbc) +// panel.add(labelWithIcon, gbc) - val linkHeadLabel = JLabel("Visit this link to view your access code on Dashwave's console:") + val linkHeadLabel = JLabel("Authenticate the plugin with Dashwave cloud using your personal access code") + // TODO: add - to view your access code, visit this link: gbc.gridy+=20 gbc.gridx = 0 gbc.gridwidth = 2 linkHeadLabel.preferredSize = Dimension(600, linkHeadLabel.preferredSize.height+10) panel.add(linkHeadLabel, gbc) + val label = JLabel("To view your access code, visit this link:") + gbc.gridy+=20 + gbc.gridwidth = 2 + panel.add(label, gbc) + val linkLabel = JLabel("https://console.dashwave.io/home?profile=true") linkLabel.cursor = Cursor(Cursor.HAND_CURSOR) // Change the cursor to a hand cursor @@ -76,7 +85,7 @@ class LoginDialog : DialogWrapper(true) { // } // change the ok button to login - setOKButtonText("Login") + setOKButtonText("Authenticate") return panel } diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 058f333..8bc0336 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -58,8 +58,8 @@ - com.intellij.modules.androidstudio - + + com.intellij.modules.all From c0c2e05a494b26b48928c8b67f1c3c48b916294f Mon Sep 17 00:00:00 2001 From: Aviral Jain Date: Thu, 4 Apr 2024 23:57:52 +0530 Subject: [PATCH 05/15] change plugin design and fix functionality --- build.gradle.kts | 2 +- .../com/dashwave/plugin/PluginStartup.kt | 84 ++++---- .../plugin/components/CollapseMenu.kt | 40 ++++ .../dashwave/plugin/dialogbox/LoginDialog.kt | 8 +- .../com/dashwave/plugin/utils/DwBuild.kt | 2 +- .../com/dashwave/plugin/utils/DwCmds.kt | 15 +- .../com/dashwave/plugin/utils/Process.kt | 15 +- .../dashwave/plugin/windows/DashwaveWindow.kt | 179 ++++++++++++++---- src/main/resources/META-INF/plugin.xml | 4 +- 9 files changed, 264 insertions(+), 85 deletions(-) create mode 100644 src/main/kotlin/com/dashwave/plugin/components/CollapseMenu.kt diff --git a/build.gradle.kts b/build.gradle.kts index 4d61aca..44cab0c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,7 +5,7 @@ plugins { } group = "com.dashwave" -version = "2.2.0" +version = "2.3.0" repositories { mavenCentral() diff --git a/src/main/kotlin/com/dashwave/plugin/PluginStartup.kt b/src/main/kotlin/com/dashwave/plugin/PluginStartup.kt index ab809d4..34d5fd3 100644 --- a/src/main/kotlin/com/dashwave/plugin/PluginStartup.kt +++ b/src/main/kotlin/com/dashwave/plugin/PluginStartup.kt @@ -12,6 +12,8 @@ import com.intellij.notification.* import com.intellij.openapi.editor.markup.TextAttributes import com.intellij.openapi.project.Project import com.intellij.openapi.startup.StartupActivity +import com.intellij.openapi.ui.DialogWrapper +import kotlinx.serialization.json.* import java.awt.Color import java.io.File import java.io.IOException @@ -58,7 +60,7 @@ fun installDW(pwd: String?){ // Execute the script val process = Process("curl -sSL https://cli.dashwave.io | bash", pwd, true) - process.start() + process.start(false) Thread{ val exitCode = process.wait() if (exitCode == 0) { @@ -79,6 +81,8 @@ fun installDW(pwd: String?){ } fun verifyLogin(pwd:String?){ + listUsers(pwd) + DashwaveWindow.addModulesAndVariants(HashMap>(), "", "") val currentUserLoginCmd = DwCmds("user", "", true) val exitCode = currentUserLoginCmd.executeWithExitCode() if (exitCode == 0){ @@ -90,9 +94,12 @@ fun verifyLogin(pwd:String?){ } fun checkProjectConnected(pwd:String?){ + listUsers(pwd) if (doesFileExist("$pwd/dashwave.yml")){ DashwaveWindow.enableRunButton() + listModulesAndVariants(pwd) + DashwaveWindow.displayOutput("✅ Project is successfully connected to dashwave. Run a cloud build using dashwave icon on toolbar\n\n", ConsoleViewContentType.NORMAL_OUTPUT) val dd = ReadyForBuildDialog() dd.show() @@ -105,9 +112,16 @@ fun checkProjectConnected(pwd:String?){ fun loginUser(pwd:String?) { val loginDialog = LoginDialog() var accessCode: String = "" - if (loginDialog.showAndGet()) { + + loginDialog.show() + + if (loginDialog.exitCode == DialogWrapper.OK_EXIT_CODE) { accessCode = loginDialog.getAccessCode() + }else if (loginDialog.exitCode == DialogWrapper.CANCEL_EXIT_CODE){ + // handle cancellation logic if any + return } + val loginUserCmd = "login $accessCode" val exitCode = DwCmds(loginUserCmd, "", true).executeWithExitCode() if (exitCode == 0) { @@ -125,42 +139,49 @@ fun doesFileExist(path: String): Boolean { return file.exists() } -fun listModulesAndVariants(pwd:String?) { - val configsCmd = DwCmds("build configs", pwd, true) - var output = configsCmd.executeWithOutput() - val ansiEscapeRegex = "\\x1B\\[[;\\d]*m".toRegex() - output = output.replace(ansiEscapeRegex, "") +fun listUsers(pwd: String?){ + val usersCmd = DwCmds("user ls", pwd, false) + val cmdOutput = usersCmd.executeWithOutput() + if(cmdOutput.first != 0){ + DashwaveWindow.displayError("❌ Could not find logged in users\n"+cmdOutput.second) + return + } + val jsonText = cmdOutput.second.trim() + val cleanedJsonString = jsonText.dropWhile { it.code <= 32 } + println(cleanedJsonString) + val jsonObject = Json.parseToJsonElement(cleanedJsonString).jsonObject + + val users = jsonObject["users"]?.jsonArray?.mapNotNull { it.jsonPrimitive.contentOrNull } + val activeUser = jsonObject["active_user"]?.toString() + DashwaveWindow.addUsers(users, activeUser?:"",pwd) +} +fun listModulesAndVariants(pwd:String?) { + val configsCmd = DwCmds("build configs", pwd, false) + var cmdOutput = configsCmd.executeWithOutput() + if(cmdOutput.first != 0){ + DashwaveWindow.displayError("❌ Could not find modules and in variants\n"+cmdOutput.second) + return + } + val jsonText = cmdOutput.second.trim() + val cleanedJsonString = jsonText.dropWhile { it.code <= 32 } + val jsonObject = Json.parseToJsonElement(cleanedJsonString).jsonObject val map = mutableMapOf>() var defaultModule: String = "" var defaultVariant: String = "" - var foundDefault = false - - // Split the input string by lines - val lines = output.split("\n") - - for (line in lines) { - // Split each line by ':' - val parts = line.split(":").map { it.trim() } // Trim to remove leading/trailing whitespace - - if (parts.size == 2) { - // The first part is the project name, and the second part contains the build types - val projectName = parts[0] - val buildTypes = parts[1].trim('[', ']').split(" ").filter { it.isNotEmpty() } - - // Populate the map - if (projectName == "default") { - if (buildTypes.size >= 2) { - defaultModule = buildTypes[0] - defaultVariant = buildTypes[1] - foundDefault = true - } else { - println("Warning: 'default' project does not contain enough build types.") - } + var foundDefault:Boolean = false + jsonObject.forEach { (key, value) -> + val list = value.jsonArray.mapNotNull { it.jsonPrimitive.contentOrNull } + if (key == "default"){ + if (list.size >= 2){ + defaultModule = list[0] + defaultVariant = list[1] + foundDefault = true } else { - map[projectName] = buildTypes + println("Warning: 'default' project does not contain enough build types.") } } + map[key] = list } if (!foundDefault && map.isNotEmpty()) { @@ -198,7 +219,6 @@ fun createProject(projectName: String, devStack:String, rootDir:String,pwd:Strin val exitCode = DwCmds(createProjectCmd, pwd, true).executeWithExitCode() if(exitCode == 0){ DashwaveWindow.enableRunButton() - listModulesAndVariants(pwd) Notifications.Bus.notify( Notification( "YourPluginNotificationGroup", diff --git a/src/main/kotlin/com/dashwave/plugin/components/CollapseMenu.kt b/src/main/kotlin/com/dashwave/plugin/components/CollapseMenu.kt new file mode 100644 index 0000000..47d6966 --- /dev/null +++ b/src/main/kotlin/com/dashwave/plugin/components/CollapseMenu.kt @@ -0,0 +1,40 @@ +package com.dashwave.plugin.components + +import com.intellij.icons.AllIcons +import javax.swing.JButton +import javax.swing.JComponent +import javax.swing.JPopupMenu + +class CollapseMenu(label:String){ + private val menu:JPopupMenu = JPopupMenu() + private val btn:JButton = JButton() + private var displayOn:Boolean = false + lateinit var components:List + init { + val label:String = label + btn.apply { + text = label + icon = AllIcons.General.ArrowDown + addActionListener{ + if(displayOn){ + menu.setSize(0,0) + }else{ + menu.show(this, 0, this.height) + menu.setSize(preferredSize.width, preferredSize.height) + } + displayOn = !displayOn + } + } + + } + + fun add(comp:JComponent){ + menu.add(comp) + } + + fun getComponent():JComponent{ + return btn + } + + +} \ No newline at end of file diff --git a/src/main/kotlin/com/dashwave/plugin/dialogbox/LoginDialog.kt b/src/main/kotlin/com/dashwave/plugin/dialogbox/LoginDialog.kt index 96cd06d..5ba0572 100644 --- a/src/main/kotlin/com/dashwave/plugin/dialogbox/LoginDialog.kt +++ b/src/main/kotlin/com/dashwave/plugin/dialogbox/LoginDialog.kt @@ -3,6 +3,7 @@ package com.dashwave.plugin import com.intellij.ide.BrowserUtil import com.intellij.openapi.ui.DialogWrapper import com.intellij.openapi.util.IconLoader +import com.intellij.util.IconUtil import java.awt.* import java.awt.event.MouseAdapter import java.awt.event.MouseEvent @@ -17,6 +18,10 @@ class LoginDialog : DialogWrapper(true) { // TODO: add logo to title title = "Authenticate with Dashwave Cloud" init() + +// val icon = IconLoader.getIcon("/icons/dashwave13.svg") // Make sure to provide the correct path +// val image = IconUtil.toImage(icon) +// window.setIconImage(image) } override fun createCenterPanel(): JComponent? { @@ -29,10 +34,9 @@ class LoginDialog : DialogWrapper(true) { gbc.gridy = 0 gbc.gridwidth = 2 - val icon = IconLoader.getIcon("/icons/dashwave13.svg") // Make sure to provide the correct path this.createTitlePane() - val labelWithIcon = JLabel("Login to Dashwave Cloud by entering your access code", icon, SwingConstants.LEFT) +// val labelWithIcon = JLabel("Login to Dashwave Cloud by entering your access code", icon, SwingConstants.LEFT) // panel.add(labelWithIcon, gbc) val linkHeadLabel = JLabel("Authenticate the plugin with Dashwave cloud using your personal access code") diff --git a/src/main/kotlin/com/dashwave/plugin/utils/DwBuild.kt b/src/main/kotlin/com/dashwave/plugin/utils/DwBuild.kt index bdf92b4..08d6eef 100644 --- a/src/main/kotlin/com/dashwave/plugin/utils/DwBuild.kt +++ b/src/main/kotlin/com/dashwave/plugin/utils/DwBuild.kt @@ -47,7 +47,7 @@ class DwBuild(config: DwBuildConfig){ private fun execute(){ // DashwaveWindow.displayInfo() val buildCmd = DwCmds(cmd, pwd, true) -// buildCmd.executeBuild(pwd, openEmulator) + buildCmd.executeBuild(pwd, openEmulator) } fun killEmulator(){ diff --git a/src/main/kotlin/com/dashwave/plugin/utils/DwCmds.kt b/src/main/kotlin/com/dashwave/plugin/utils/DwCmds.kt index 01e5174..8af0ded 100644 --- a/src/main/kotlin/com/dashwave/plugin/utils/DwCmds.kt +++ b/src/main/kotlin/com/dashwave/plugin/utils/DwCmds.kt @@ -1,6 +1,7 @@ package com.dashwave.plugin.utils import com.dashwave.plugin.installDW +import com.dashwave.plugin.listModulesAndVariants import com.dashwave.plugin.notif.BalloonNotif import com.dashwave.plugin.windows.DashwaveWindow import com.intellij.execution.filters.HyperlinkInfo @@ -20,14 +21,16 @@ class DwCmds(execCmd:String, wd:String?, log: Boolean){ private var cmd:String private var p:Process private var pwd:String? + private var shouldLog:Boolean init { + shouldLog = log cmd = "dw $execCmd --plugin" pwd = wd p = com.dashwave.plugin.utils.Process(cmd, pwd, log) } fun executeWithExitCode():Int{ - this.p.start() + this.p.start(this.shouldLog) val exitCode = this.p.wait() if(exitCode == 11){ DashwaveWindow.displayError("Dashwave has a major update, you need to update dependencies\n") @@ -39,8 +42,8 @@ class DwCmds(execCmd:String, wd:String?, log: Boolean){ return exitCode } - fun executeWithOutput():String{ - this.p.start() + fun executeWithOutput():Pair{ + this.p.start(this.shouldLog) val exitCode = this.p.wait() if(exitCode == 11){ DashwaveWindow.displayError("Dashwave has a major update, you need to update dependencies\n") @@ -51,7 +54,7 @@ class DwCmds(execCmd:String, wd:String?, log: Boolean){ } // get the stdout as string - return this.p.getOutput() + return Pair(exitCode, this.p.getOutput()) } @@ -61,7 +64,7 @@ class DwCmds(execCmd:String, wd:String?, log: Boolean){ fun executeBuild(pwd:String?, openEmulator:Boolean){ - this.p.start() + this.p.start(this.shouldLog) DashwaveWindow.disableRunButton() DashwaveWindow.enableCancelButton() DashwaveWindow.currentBuild = this @@ -124,6 +127,8 @@ class DwCmds(execCmd:String, wd:String?, log: Boolean){ ){}.show() } } + // common post build flow + listModulesAndVariants(pwd) }.start() } } diff --git a/src/main/kotlin/com/dashwave/plugin/utils/Process.kt b/src/main/kotlin/com/dashwave/plugin/utils/Process.kt index e3a5995..fc48b71 100644 --- a/src/main/kotlin/com/dashwave/plugin/utils/Process.kt +++ b/src/main/kotlin/com/dashwave/plugin/utils/Process.kt @@ -18,7 +18,9 @@ class Process(cmd:String, pwd:String?, log:Boolean){ private var ph:ProcessHandler private val latch = CountDownLatch(1) private val outputBuilder = StringBuilder() + private var command:String init { + command = cmd val cmd = GeneralCommandLine("/bin/bash","-c",cmd) if(pwd != null && pwd != ""){ cmd.setWorkDirectory(pwd) @@ -29,9 +31,13 @@ class Process(cmd:String, pwd:String?, log:Boolean){ ph = OSProcessHandler(cmd) ph.addProcessListener(object:ProcessAdapter(){ override fun onTextAvailable(event: ProcessEvent, outputType: Key<*>) { - outputBuilder.append(event.text) + val text = event.text.trim() + if (text.contains(cmd.commandLineString)){ + return + } + outputBuilder.append(text) if(log) { - decodeAndPrintString(event.text, outputType) + decodeAndPrintString("$text\n", outputType) } } override fun processTerminated(event: ProcessEvent) { @@ -41,7 +47,10 @@ class Process(cmd:String, pwd:String?, log:Boolean){ }) } - fun start(){ + fun start(log: Boolean){ + if(log){ + DashwaveWindow.displayInfo("${this.command}\n\n") + } ph.startNotify() } diff --git a/src/main/kotlin/com/dashwave/plugin/windows/DashwaveWindow.kt b/src/main/kotlin/com/dashwave/plugin/windows/DashwaveWindow.kt index a1d45db..7b8c510 100644 --- a/src/main/kotlin/com/dashwave/plugin/windows/DashwaveWindow.kt +++ b/src/main/kotlin/com/dashwave/plugin/windows/DashwaveWindow.kt @@ -1,5 +1,7 @@ package com.dashwave.plugin.windows +import com.dashwave.plugin.components.CollapseMenu +import com.dashwave.plugin.loginUser import com.dashwave.plugin.utils.DwBuild import com.dashwave.plugin.utils.DwBuildConfig import com.dashwave.plugin.utils.DwCmds @@ -13,10 +15,6 @@ import com.intellij.openapi.wm.ToolWindowAnchor import com.intellij.openapi.wm.ToolWindowFactory import com.intellij.ui.content.ContentFactory import java.awt.BorderLayout -import javax.swing.JButton -import javax.swing.JCheckBox -import javax.swing.JPanel -import javax.swing.JToolBar import com.intellij.icons.AllIcons; import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.util.IconLoader @@ -24,13 +22,14 @@ import com.intellij.openapi.wm.ToolWindowManager import com.intellij.ui.AnimatedIcon import com.intellij.ui.components.JBList import com.jetbrains.rd.util.first +import com.sun.xml.bind.v2.Messages +import java.awt.Color import java.awt.Dimension +import java.awt.RenderingHints import java.awt.event.ItemEvent import java.awt.event.ItemListener -import javax.swing.Icon -import javax.swing.JComboBox -import javax.swing.JLabel -import javax.swing.JList +import java.awt.image.BufferedImage +import javax.swing.* class DashwaveWindow : ToolWindowFactory { companion object { @@ -46,8 +45,14 @@ class DashwaveWindow : ToolWindowFactory { private var cleanBuildCheckbox:JCheckBox = JCheckBox("Clean Build") private var debugEnabledCheckBox: JCheckBox = JCheckBox("Enable Debug") private var openEmulatorCheckbox:JCheckBox = JCheckBox("Open Emulator") + private var buildOpts = CollapseMenu("Build opts") private var modulesList: JComboBox = JComboBox() private var variantsList: JComboBox = JComboBox() + private var usersList: JComboBox = JComboBox() + private var selectedUser: String = "" + private var lastSelectedUser: String = "" + var selectedModule:String="" + var selectedVariant:String="" fun show(){ val toolWindowManager = ToolWindowManager.getInstance(p) @@ -69,8 +74,8 @@ class DashwaveWindow : ToolWindowFactory { val cleanBuild = cleanBuildCheckbox.isSelected val debugEnabled = debugEnabledCheckBox.isSelected val openEmulator = openEmulatorCheckbox.isSelected - val module: String = modulesList.selectedItem?.toString() ?: "app" - val variant: String = variantsList.selectedItem?.toString() ?: "Debug" + val module: String = selectedModule + val variant: String = selectedVariant DashwaveWindow.displayInfo("open emulator is $openEmulator") return DwBuildConfig(cleanBuild, debugEnabled, openEmulator, module, variant, p.basePath) } @@ -110,10 +115,66 @@ class DashwaveWindow : ToolWindowFactory { cancelButton.isEnabled = true } + private fun addNewUserButton(pwd:String?):JButton{ + val addUserButton = JButton(createPlusIcon(16,Color.GRAY)).apply { + toolTipText = "Add user" + addActionListener{ + loginUser(pwd) + } + } + addUserButton.setSize(10,10) + return addUserButton + } + + fun switchUser(user:String, wd:String?){ + val switchUserCmd = DwCmds("user switch $user", wd, true) + val exitCode = switchUserCmd.executeWithExitCode() + if (exitCode != 0){ + displayError("❌ Could not switch to user: $user\n\n") + return + } + displayInfo("✅ Successfully switched to user: $user\n\n") + } + + fun addUsers(users: List?,activeUser:String, wd:String?){ + usersList.removeAllItems() + + if(users == null || users.size == 0){ + usersList.isEnabled = false + usersList.addItem("No users logged in") + return + } + usersList.isEnabled = true + users?.forEach{ user -> + usersList.addItem(user) + } + this.selectedUser = activeUser + usersList.selectedItem = activeUser + + usersList.addItemListener(ItemListener { + if (this.selectedUser == it.item.toString()){ + return@ItemListener + } + this.lastSelectedUser = selectedUser + this.selectedUser = it.item.toString() + switchUser(this.selectedUser, wd) + }) + } + fun addModulesAndVariants(modulesVariants: Map>, defaultModule: String, defaultVariant: String){ modulesList.removeAllItems() variantsList.removeAllItems() + if (modulesVariants.size == 0){ + modulesList.addItem("No modules detected yet") + variantsList.addItem("No variants detected yet") + modulesList.isEnabled = false + variantsList.isEnabled = false + return + } + modulesList.isEnabled = true + variantsList.isEnabled = true + modulesList.addItem(defaultModule) variantsList.addItem(defaultVariant) @@ -123,8 +184,11 @@ class DashwaveWindow : ToolWindowFactory { modulesList.addItemListener(ItemListener { if (it.stateChange == ItemEvent.SELECTED) { - val selectedModule = modulesList.selectedItem as String - + if(it.item.toString().contains("modules detected")){ + selectedModule = "" + return@ItemListener + } + selectedModule = modulesList.selectedItem as String variantsList.removeAllItems() modulesVariants[selectedModule]?.forEach { variant -> variantsList.addItem(variant) @@ -134,7 +198,11 @@ class DashwaveWindow : ToolWindowFactory { variantsList.addItemListener(ItemListener { if (it.stateChange == ItemEvent.SELECTED) { - val selectedVariant = variantsList.selectedItem as String + if(it.item.toString() == "variants detected"){ + selectedVariant = "" + return@ItemListener + } + selectedVariant = variantsList.selectedItem as String } }) } @@ -162,44 +230,61 @@ class DashwaveWindow : ToolWindowFactory { enableRunButton() } + + actionToolbar.add(runButton) actionToolbar.add(cancelButton) disableCancelButton() disableRunButton() - val optionToolbar = JToolBar(JToolBar.VERTICAL) - val optionTitle = JLabel("Build Options") - optionToolbar.add(optionTitle) - optionToolbar.add(cleanBuildCheckbox) - optionToolbar.add(debugEnabledCheckBox) - optionToolbar.add(openEmulatorCheckbox) - - modulesList.addItemListener(ItemListener { - if (it.stateChange == ItemEvent.SELECTED) { - val selectedModule = modulesList.selectedItem as String -// displayInfo("Selected module is $selectedModule") - } - }) - variantsList.addItemListener(ItemListener { - if (it.stateChange == ItemEvent.SELECTED) { - val selectedVariant = variantsList.selectedItem as String -// displayInfo("Selected variant is $selectedVariant") - } - }) + actionToolbar.add(Box.createHorizontalStrut(50)) + val optsGroup = JPanel().apply { + layout = BoxLayout(this, BoxLayout.X_AXIS) + border = BorderFactory.createEtchedBorder() + } - modulesList.preferredSize = Dimension(100, modulesList.preferredSize.height) - variantsList.preferredSize = Dimension(100, variantsList.preferredSize.height) +// val optionToolbar = JToolBar(JToolBar.VERTICAL) +// val optionTitle = JLabel("Build Options") +// optionToolbar.add(optionTitle) + buildOpts.add(cleanBuildCheckbox) + buildOpts.add(debugEnabledCheckBox) + buildOpts.add(openEmulatorCheckbox) + + optsGroup.add(buildOpts.getComponent()) + + modulesList.preferredSize = Dimension(20, modulesList.preferredSize.height) + variantsList.preferredSize = Dimension(20, variantsList.preferredSize.height) + usersList.preferredSize = Dimension(20, usersList.preferredSize.height) // add non-item label to modules and variants - optionToolbar.add(JLabel("Modules")) - optionToolbar.add(modulesList) +// optionToolbar.add(JLabel("Modules")) + optsGroup.add(modulesList) + +// optionToolbar.add(JLabel("Variants")) + optsGroup.add(variantsList) + + actionToolbar.add(optsGroup) + + val userGroup = JPanel().apply { + layout = BoxLayout(this, BoxLayout.X_AXIS) + border = BorderFactory.createEtchedBorder() + } + + actionToolbar.add(Box.createHorizontalStrut(300)) + + userGroup.add(usersList) + + val addUserBtn = addNewUserButton(project.basePath) + addUserBtn.setSize(10,10) + userGroup.add(addUserBtn) + actionToolbar.add(userGroup) - optionToolbar.add(JLabel("Variants")) - optionToolbar.add(variantsList) openEmulatorCheckbox.isSelected = true + + panel.add(actionToolbar, BorderLayout.NORTH) - panel.add(optionToolbar, BorderLayout.WEST) +// panel.add(optionToolbar, BorderLayout.WEST) // Set up the console view @@ -212,3 +297,19 @@ class DashwaveWindow : ToolWindowFactory { } } + +fun createPlusIcon(size: Int, color: Color): Icon { + val image = BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB) + val g2d = image.createGraphics() + g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON) + g2d.color = color + + // Draw plus sign + val thickness = size / 8 // Adjust thickness as desired + val pad = size / 4 + g2d.fillRect(pad, size / 2 - thickness / 2, size - 2 * pad, thickness) + g2d.fillRect(size / 2 - thickness / 2, pad, thickness, size - 2 * pad) + + g2d.dispose() + return ImageIcon(image) +} \ No newline at end of file diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 8bc0336..058f333 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -58,8 +58,8 @@ - - com.intellij.modules.all + com.intellij.modules.androidstudio + From 239221f1c396d7f4347f92702aed24015294c39e Mon Sep 17 00:00:00 2001 From: Aviral Jain Date: Wed, 3 Apr 2024 15:54:30 +0530 Subject: [PATCH 06/15] provide support for multiple projects and check for .git folder --- build.gradle.kts | 2 +- .../com/dashwave/plugin/PluginStartup.kt | 187 ++++++---- .../dashwave/plugin/actions/BuildAction.kt | 15 +- .../plugin/dialogbox/CreateProjectDialog.kt | 7 +- .../dialogbox/GitNotConfiguredDialog.kt | 27 ++ .../com/dashwave/plugin/messages/Messages.kt | 1 + .../com/dashwave/plugin/notif/NotifAlert.kt | 4 +- .../com/dashwave/plugin/utils/DwBuild.kt | 25 +- .../com/dashwave/plugin/utils/DwCmds.kt | 78 ++-- .../com/dashwave/plugin/utils/Process.kt | 12 +- .../dashwave/plugin/windows/DashwaveWindow.kt | 333 +++++++++--------- src/main/resources/META-INF/plugin.xml | 10 +- 12 files changed, 403 insertions(+), 298 deletions(-) create mode 100644 src/main/kotlin/com/dashwave/plugin/dialogbox/GitNotConfiguredDialog.kt diff --git a/build.gradle.kts b/build.gradle.kts index 44cab0c..99c1db3 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,7 +5,7 @@ plugins { } group = "com.dashwave" -version = "2.3.0" +version = "2.3.1" repositories { mavenCentral() diff --git a/src/main/kotlin/com/dashwave/plugin/PluginStartup.kt b/src/main/kotlin/com/dashwave/plugin/PluginStartup.kt index 34d5fd3..a1a571f 100644 --- a/src/main/kotlin/com/dashwave/plugin/PluginStartup.kt +++ b/src/main/kotlin/com/dashwave/plugin/PluginStartup.kt @@ -1,46 +1,60 @@ package com.dashwave.plugin +import com.dashwave.plugin.actions.BuildAction import com.dashwave.plugin.dialogbox.CreateProjectDialog +import com.dashwave.plugin.dialogbox.GitNotConfiguredDialog import com.dashwave.plugin.dialogbox.ReadyForBuildDialog import com.dashwave.plugin.messages.Messages +import com.dashwave.plugin.notif.BalloonNotif import com.dashwave.plugin.utils.DwCmds import com.dashwave.plugin.utils.Process import com.dashwave.plugin.windows.DashwaveWindow import com.intellij.execution.filters.HyperlinkInfo import com.intellij.execution.ui.ConsoleViewContentType import com.intellij.notification.* +import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.editor.markup.TextAttributes import com.intellij.openapi.project.Project import com.intellij.openapi.startup.StartupActivity import com.intellij.openapi.ui.DialogWrapper import kotlinx.serialization.json.* +import com.intellij.openapi.wm.ToolWindowManager import java.awt.Color import java.io.File import java.io.IOException import okhttp3.OkHttpClient import okhttp3.Request +import com.intellij.openapi.actionSystem.ActionManager +import com.intellij.openapi.actionSystem.Anchor +import com.intellij.openapi.actionSystem.Constraints +import com.intellij.openapi.actionSystem.DefaultActionGroup +import io.ktor.util.* import java.awt.Font class PluginStartup: StartupActivity { + companion object { + var dwWindows:HashMap = HashMap() + } override fun runActivity(project: Project) { - DashwaveWindow.p = project - DashwaveWindow.show() - checkDW(project) + val dwWindow = DashwaveWindow(project) + dwWindow.show() + dwWindows[project.name] = dwWindow + checkDW(project, dwWindow) } } -fun checkDW(project: Project) { - val dwCmd = DwCmds("check-update", "", true) +fun checkDW(project: Project, dwWindow: DashwaveWindow) { + val dwCmd = DwCmds("check-update", project.basePath, true, dwWindow) val exitCode = dwCmd.executeWithExitCode() if (exitCode == 0) { - DashwaveWindow.displayInfo(Messages.DW_INSTALLED_ALREADY) - verifyLogin(project?.basePath) + dwWindow.displayInfo(Messages.DW_INSTALLED_ALREADY) + verifyLogin(project?.basePath, dwWindow) }else if(exitCode == 11){ }else{ - DashwaveWindow.displayInfo(Messages.DW_NOT_INSTALLED) + dwWindow.displayInfo(Messages.DW_NOT_INSTALLED) showInstallDW(project) - installDW(project?.basePath) + installDW(project?.basePath, dwWindow) } } @@ -55,61 +69,76 @@ fun showInstallDW(project: Project){ notification.notify(project) } -fun installDW(pwd: String?){ - DashwaveWindow.displayOutput("🔨 Setting up plugin...\n\n", ConsoleViewContentType.NORMAL_OUTPUT) +fun installDW(pwd: String?, dwWindow: DashwaveWindow){ + dwWindow.displayOutput("🔨 Setting up plugin...\n\n", ConsoleViewContentType.NORMAL_OUTPUT) // Execute the script - val process = Process("curl -sSL https://cli.dashwave.io | bash", pwd, true) + val process = Process("curl -sSL https://cli.dashwave.io | bash", pwd, true, dwWindow) process.start(false) Thread{ val exitCode = process.wait() if (exitCode == 0) { - DashwaveWindow.displayInfo(Messages.DW_DEPS_INSTALL_SUCCESS) - DashwaveWindow.displayInfo(Messages.DW_DEPS_CONFIGURING) - val configCmd = DwCmds("config", pwd, true) + dwWindow.displayInfo(Messages.DW_DEPS_INSTALL_SUCCESS) + dwWindow.displayInfo(Messages.DW_DEPS_CONFIGURING) + val configCmd = DwCmds("config", pwd, true, dwWindow) val exitcode = configCmd.executeWithExitCode() if(exitcode == 0){ - DashwaveWindow.displayInfo(Messages.DW_DEPS_CONFIGURE_SUCCESS) - verifyLogin(pwd) + dwWindow.displayInfo(Messages.DW_DEPS_CONFIGURE_SUCCESS) + verifyLogin(pwd, dwWindow) }else{ - DashwaveWindow.displayError(Messages.DW_DEPS_CONFIGURE_FAILED) + dwWindow.displayError(Messages.DW_DEPS_CONFIGURE_FAILED) } } else { - DashwaveWindow.displayError(Messages.DW_DEPS_INSTALL_FAILED) + dwWindow.displayError(Messages.DW_DEPS_INSTALL_FAILED) } }.start() } -fun verifyLogin(pwd:String?){ - listUsers(pwd) - DashwaveWindow.addModulesAndVariants(HashMap>(), "", "") - val currentUserLoginCmd = DwCmds("user", "", true) +fun verifyLogin(pwd:String?, dwWindow: DashwaveWindow){ + listUsers(pwd, dwWindow) + dwWindow.addModulesAndVariants(HashMap>(), "", "") + val currentUserLoginCmd = DwCmds("user", pwd, true, dwWindow) val exitCode = currentUserLoginCmd.executeWithExitCode() if (exitCode == 0){ - DashwaveWindow.enableRunButton() - checkProjectConnected(pwd) + dwWindow.enableRunButton() + checkProjectConnected(pwd, dwWindow) }else{ - loginUser(pwd) + loginUser(pwd, dwWindow) } } -fun checkProjectConnected(pwd:String?){ - listUsers(pwd) - if (doesFileExist("$pwd/dashwave.yml")){ - DashwaveWindow.enableRunButton() +fun checkProjectConnected(pwd:String?, dwWindow: DashwaveWindow){ + listUsers(pwd, dwWindow) + // check if .git folder exists + val gitConfigFilepath = "$pwd/.git" + if (!doesFileExist(gitConfigFilepath)){ + dwWindow.displayOutput("❌ ${Messages.GIT_NOT_CONFIGURED}", ConsoleViewContentType.ERROR_OUTPUT) + val notif = BalloonNotif( + "Could not find .git folder", + "", + "This is not a git repository, initialise git and push codebase to proceed ", + NotificationType.ERROR, + ){} + notif.show(dwWindow.p) - listModulesAndVariants(pwd) + val dialog = GitNotConfiguredDialog() + dialog.show() + return + } - DashwaveWindow.displayOutput("✅ Project is successfully connected to dashwave. Run a cloud build using dashwave icon on toolbar\n\n", ConsoleViewContentType.NORMAL_OUTPUT) + if (doesFileExist("$pwd/dashwave.yml")){ + dwWindow.enableRunButton() + listModulesAndVariants(pwd, dwWindow) + dwWindow.displayOutput("✅ Project is successfully connected to dashwave. Run a cloud build using dashwave icon on toolbar\n\n", ConsoleViewContentType.NORMAL_OUTPUT) val dd = ReadyForBuildDialog() dd.show() }else { - DashwaveWindow.displayOutput("⚠️ This project is not connected to dashwave, create a new project on dashwave\n\n", ConsoleViewContentType.NORMAL_OUTPUT) - openCreateProjectDialog(pwd, true) + dwWindow.displayOutput("⚠️ This project is not connected to dashwave, create a new project on dashwave\n\n", ConsoleViewContentType.NORMAL_OUTPUT) + openCreateProjectDialog(pwd, true, dwWindow){} } } -fun loginUser(pwd:String?) { +fun loginUser(pwd:String?, dwWindow: DashwaveWindow) { val loginDialog = LoginDialog() var accessCode: String = "" @@ -123,14 +152,15 @@ fun loginUser(pwd:String?) { } val loginUserCmd = "login $accessCode" - val exitCode = DwCmds(loginUserCmd, "", true).executeWithExitCode() + val exitCode = DwCmds(loginUserCmd, pwd, true, dwWindow).executeWithExitCode() if (exitCode == 0) { - checkProjectConnected(pwd) + dwWindow.enableRunButton() + checkProjectConnected(pwd, dwWindow) }else{ var hyperlink = HyperlinkInfo { p: Project -> - loginUser(pwd) + loginUser(pwd, dwWindow) } - DashwaveWindow.console.printHyperlink(Messages.DW_LOGIN_FAILED, hyperlink) + dwWindow.console.printHyperlink(Messages.DW_LOGIN_FAILED, hyperlink) } } @@ -139,11 +169,11 @@ fun doesFileExist(path: String): Boolean { return file.exists() } -fun listUsers(pwd: String?){ - val usersCmd = DwCmds("user ls", pwd, false) +fun listUsers(pwd: String?, dwWindow: DashwaveWindow){ + val usersCmd = DwCmds("user ls", pwd, false, dwWindow) val cmdOutput = usersCmd.executeWithOutput() if(cmdOutput.first != 0){ - DashwaveWindow.displayError("❌ Could not find logged in users\n"+cmdOutput.second) + dwWindow.displayError("❌ Could not find logged in users\n"+cmdOutput.second) return } val jsonText = cmdOutput.second.trim() @@ -154,13 +184,13 @@ fun listUsers(pwd: String?){ val users = jsonObject["users"]?.jsonArray?.mapNotNull { it.jsonPrimitive.contentOrNull } val activeUser = jsonObject["active_user"]?.toString() - DashwaveWindow.addUsers(users, activeUser?:"",pwd) + dwWindow.addUsers(users, activeUser?:"",pwd) } -fun listModulesAndVariants(pwd:String?) { - val configsCmd = DwCmds("build configs", pwd, false) +fun listModulesAndVariants(pwd:String?, dwWindow: DashwaveWindow) { + val configsCmd = DwCmds("build configs", pwd, false, dwWindow) var cmdOutput = configsCmd.executeWithOutput() if(cmdOutput.first != 0){ - DashwaveWindow.displayError("❌ Could not find modules and in variants\n"+cmdOutput.second) + dwWindow.displayError("❌ Could not find modules and in variants\n"+cmdOutput.second) return } val jsonText = cmdOutput.second.trim() @@ -191,34 +221,40 @@ fun listModulesAndVariants(pwd:String?) { } } - DashwaveWindow.addModulesAndVariants(map, defaultModule, defaultVariant) + dwWindow.addModulesAndVariants(map, defaultModule, defaultVariant) } -fun openCreateProjectDialog(pwd:String?, openTip:Boolean):Boolean{ - val createProjectDialog = CreateProjectDialog() - if (createProjectDialog.showAndGet()){ - val projectName = createProjectDialog.getProjectName() - val rootDir = createProjectDialog.getRootDir() - val techStack = createProjectDialog.getSelectedTechStack() - val success = createProject(projectName, techStack, rootDir,pwd, openTip) - return success - } - DashwaveWindow.show() - val yellowOutput = ConsoleViewContentType("YellowOutput", TextAttributes(Color.YELLOW, null,null, null, Font.PLAIN)) - DashwaveWindow.displayOutput("⚠️ You must create a new project to be able to run builds on dashwave\n\n", yellowOutput) - var hyperlink = HyperlinkInfo { p: Project -> - openCreateProjectDialog(pwd, openTip) +fun openCreateProjectDialog(pwd:String?, openTip:Boolean, dwWindow: DashwaveWindow,buildAction:()->Unit){ + ApplicationManager.getApplication().invokeLater{ + val createProjectDialog = CreateProjectDialog(dwWindow.p) + if (createProjectDialog.showAndGet()){ + val projectName = createProjectDialog.getProjectName() + val rootDir = createProjectDialog.getRootDir() + val techStack = createProjectDialog.getSelectedTechStack() + val success = createProject(projectName, techStack, rootDir,pwd, openTip, dwWindow) + if(success){ + buildAction() + } + }else{ +// dwWindow.show() + dwWindow.enableRunButton() + dwWindow.disableCancelButton() + val yellowOutput = ConsoleViewContentType("YellowOutput", TextAttributes(Color.YELLOW, null,null, null, Font.PLAIN)) + dwWindow.displayOutput("⚠️ You must create a new project to be able to run builds on dashwave\n\n", yellowOutput) + var hyperlink = HyperlinkInfo { p: Project -> + openCreateProjectDialog(pwd, openTip, dwWindow,buildAction) + } + dwWindow.console.printHyperlink("Click here", hyperlink) + dwWindow.displayOutput(" to create a new dashwave project\n\n", ConsoleViewContentType.NORMAL_OUTPUT) + } } - DashwaveWindow.console.printHyperlink("Click here", hyperlink) - DashwaveWindow.displayOutput(" to create a new dashwave project\n\n", ConsoleViewContentType.NORMAL_OUTPUT) - return false } -fun createProject(projectName: String, devStack:String, rootDir:String,pwd:String?, openTip: Boolean) :Boolean{ +fun createProject(projectName: String, devStack:String, rootDir:String,pwd:String?, openTip: Boolean, dwWindow: DashwaveWindow) :Boolean{ val createProjectCmd = "create-project --no-prompt --name=$projectName --dev-stack=$devStack --root-dir=$rootDir" - val exitCode = DwCmds(createProjectCmd, pwd, true).executeWithExitCode() + val exitCode = DwCmds(createProjectCmd, pwd, true, dwWindow).executeWithExitCode() if(exitCode == 0){ - DashwaveWindow.enableRunButton() + dwWindow.enableRunButton() Notifications.Bus.notify( Notification( "YourPluginNotificationGroup", @@ -227,8 +263,8 @@ fun createProject(projectName: String, devStack:String, rootDir:String,pwd:Strin NotificationType.INFORMATION ) ) - DashwaveWindow.show() - DashwaveWindow.displayInfo(Messages.PROJECT_CONNECTION_SUCCESS) +// dwWindow.show() + dwWindow.displayInfo(Messages.PROJECT_CONNECTION_SUCCESS) if(openTip) { val dd = ReadyForBuildDialog() @@ -236,10 +272,17 @@ fun createProject(projectName: String, devStack:String, rootDir:String,pwd:Strin } return true } - DashwaveWindow.displayError(Messages.PROJECT_CONNECTION_FAILED) + dwWindow.displayError(Messages.PROJECT_CONNECTION_FAILED) + if(exitCode == 13){ + var hyperlink = HyperlinkInfo { p: Project -> + loginUser(pwd, dwWindow) + } + dwWindow.console.printHyperlink("Login here\n\n", hyperlink) + return false + } var hyperlink = HyperlinkInfo { p: Project -> - openCreateProjectDialog(pwd, openTip) + openCreateProjectDialog(pwd, openTip, dwWindow){} } - DashwaveWindow.console.printHyperlink("Please try again\n\n", hyperlink) + dwWindow.console.printHyperlink("Please try again\n\n", hyperlink) return false } \ No newline at end of file diff --git a/src/main/kotlin/com/dashwave/plugin/actions/BuildAction.kt b/src/main/kotlin/com/dashwave/plugin/actions/BuildAction.kt index 0321e95..1a80ccb 100644 --- a/src/main/kotlin/com/dashwave/plugin/actions/BuildAction.kt +++ b/src/main/kotlin/com/dashwave/plugin/actions/BuildAction.kt @@ -1,29 +1,28 @@ package com.dashwave.plugin.actions +import com.dashwave.plugin.PluginStartup import com.dashwave.plugin.windows.DashwaveWindow import com.dashwave.plugin.utils.DwBuild import com.intellij.openapi.actionSystem.AnAction import com.intellij.openapi.actionSystem.AnActionEvent +import com.intellij.openapi.project.Project +import com.intellij.openapi.util.IconLoader +import javax.swing.Icon class BuildAction: AnAction() { - override fun update(e: AnActionEvent) { super.update(e) val presentation = e.presentation // Enable or disable the action based on your condition - presentation.isEnabled = DashwaveWindow.runEnabled + + presentation.isEnabled = PluginStartup.dwWindows?.get(e.project?.name)?.runEnabled?:false presentation.text = "Run build on dashwave" presentation.description = "Run build on dashwave" } override fun actionPerformed(e: AnActionEvent) { - val project = e.project - if(project != null){ - val buildConfigs = DashwaveWindow.getBuildConfigs(project) - val build = DwBuild(buildConfigs) - build.run(project) - } + PluginStartup.dwWindows?.get(e.project?.name)?.runButton?.doClick() } } \ No newline at end of file diff --git a/src/main/kotlin/com/dashwave/plugin/dialogbox/CreateProjectDialog.kt b/src/main/kotlin/com/dashwave/plugin/dialogbox/CreateProjectDialog.kt index 8f9774b..d922970 100644 --- a/src/main/kotlin/com/dashwave/plugin/dialogbox/CreateProjectDialog.kt +++ b/src/main/kotlin/com/dashwave/plugin/dialogbox/CreateProjectDialog.kt @@ -1,5 +1,6 @@ package com.dashwave.plugin.dialogbox +import com.intellij.openapi.project.Project import com.intellij.openapi.ui.ComboBox import com.intellij.openapi.ui.DialogWrapper import com.intellij.openapi.ui.LabeledComponent @@ -8,7 +9,7 @@ import com.intellij.ui.layout.panel import java.awt.* import javax.swing.* -class CreateProjectDialog: DialogWrapper(true) { +class CreateProjectDialog(project: Project): DialogWrapper(project) { private val projectNameTextField = JTextField() private val rootModulePathTextField = JTextField("./") private val nativeRadioButton = JRadioButton("Native (Java/Kotlin)") @@ -17,12 +18,12 @@ class CreateProjectDialog: DialogWrapper(true) { private val projectTypeButtonGroup = ButtonGroup() init { + init() title = "New Dashwave Project" projectTypeButtonGroup.add(nativeRadioButton) projectTypeButtonGroup.add(flutterRadioButton) projectTypeButtonGroup.add(rNativeRadioButton) nativeRadioButton.isSelected = true - init() } override fun createCenterPanel(): JComponent? { @@ -84,7 +85,7 @@ class CreateProjectDialog: DialogWrapper(true) { return when{ nativeRadioButton.isSelected -> "GRADLE" flutterRadioButton.isSelected -> "FLUTTER" - nativeRadioButton.isSelected -> "REACTNATIVE" + rNativeRadioButton.isSelected -> "REACTNATIVE" else -> "" } } diff --git a/src/main/kotlin/com/dashwave/plugin/dialogbox/GitNotConfiguredDialog.kt b/src/main/kotlin/com/dashwave/plugin/dialogbox/GitNotConfiguredDialog.kt new file mode 100644 index 0000000..dce66da --- /dev/null +++ b/src/main/kotlin/com/dashwave/plugin/dialogbox/GitNotConfiguredDialog.kt @@ -0,0 +1,27 @@ +package com.dashwave.plugin.dialogbox + +import com.dashwave.plugin.messages.Messages +import com.intellij.openapi.ui.DialogWrapper +import com.intellij.openapi.util.IconLoader +import javax.swing.JComponent +import javax.swing.JLabel +import javax.swing.JPanel +import javax.swing.Action + +class GitNotConfiguredDialog : DialogWrapper(true) { + init { + init() + title = "Git not configured" + } + + override fun createCenterPanel(): JComponent? { + val dialogPanel = JPanel() + dialogPanel.add(JLabel(Messages.GIT_NOT_CONFIGURED)) + return dialogPanel + } + + override fun createActions(): Array { + val okButton = okAction + return arrayOf(okButton) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/dashwave/plugin/messages/Messages.kt b/src/main/kotlin/com/dashwave/plugin/messages/Messages.kt index 5742818..8e65dda 100644 --- a/src/main/kotlin/com/dashwave/plugin/messages/Messages.kt +++ b/src/main/kotlin/com/dashwave/plugin/messages/Messages.kt @@ -12,5 +12,6 @@ class Messages { val DW_LOGIN_FAILED = "⚠️ Login failed. Click here to retry\n\n" val PROJECT_CONNECTION_SUCCESS = "✅ Project is successfully connected to dashwave\n\n" val PROJECT_CONNECTION_FAILED = "❌ Dashwave project creation failed\n" + val GIT_NOT_CONFIGURED = "Your local codebase is not currently hosted on a Git repository (GitHub/GitLab). Please ensure your codebase is hosted on Git to use this plugin.\n" } } \ No newline at end of file diff --git a/src/main/kotlin/com/dashwave/plugin/notif/NotifAlert.kt b/src/main/kotlin/com/dashwave/plugin/notif/NotifAlert.kt index 64781a3..db6e708 100644 --- a/src/main/kotlin/com/dashwave/plugin/notif/NotifAlert.kt +++ b/src/main/kotlin/com/dashwave/plugin/notif/NotifAlert.kt @@ -23,7 +23,7 @@ class BalloonNotif(title:String, actionTitle:String ,description:String,type: No this.type = type this.actionTitle = actionTitle } - fun show() { + fun show(project:Project) { val notification = Notification( "YourPluginNotificationGroup", this.title, @@ -37,6 +37,6 @@ class BalloonNotif(title:String, actionTitle:String ,description:String,type: No } }) } - Notifications.Bus.notify(notification, DashwaveWindow.p) + Notifications.Bus.notify(notification, project) } } \ No newline at end of file diff --git a/src/main/kotlin/com/dashwave/plugin/utils/DwBuild.kt b/src/main/kotlin/com/dashwave/plugin/utils/DwBuild.kt index 08d6eef..d301958 100644 --- a/src/main/kotlin/com/dashwave/plugin/utils/DwBuild.kt +++ b/src/main/kotlin/com/dashwave/plugin/utils/DwBuild.kt @@ -16,10 +16,11 @@ class DwBuildConfig(clean:Boolean,debug:Boolean,openEmulator:Boolean,module:Stri var variant:String = variant } -class DwBuild(config: DwBuildConfig){ +class DwBuild(config: DwBuildConfig, dwWindow: DashwaveWindow){ private var cmd:String = "plugin-build" private val openEmulator:Boolean private var pwd:String? + private var dwWindow:DashwaveWindow init { if(config.clean){ cmd += " --clean" @@ -38,15 +39,16 @@ class DwBuild(config: DwBuildConfig){ pwd = config.pwd openEmulator = config.openEmulator + this.dwWindow = dwWindow } private fun activateDashwaveWindow(){ - DashwaveWindow.show() +// this.dwWindow.show() } private fun execute(){ // DashwaveWindow.displayInfo() - val buildCmd = DwCmds(cmd, pwd, true) + val buildCmd = DwCmds(cmd, pwd, true, this.dwWindow) buildCmd.executeBuild(pwd, openEmulator) } @@ -56,18 +58,17 @@ class DwBuild(config: DwBuildConfig){ fun run(p:Project){ activateDashwaveWindow() - DashwaveWindow.clearConsole() - DashwaveWindow.disableRunButton() - DashwaveWindow.enableCancelButton() - if(DashwaveWindow.lastEmulatorProcess != null){ - DashwaveWindow.lastEmulatorProcess!!.exit() + this.dwWindow.clearConsole() + this.dwWindow.disableRunButton() + this.dwWindow.enableCancelButton() + if(this.dwWindow.lastEmulatorProcess != null){ + this.dwWindow.lastEmulatorProcess!!.exit() } if (!doesFileExist("${pwd}/dashwave.yml")){ - if(!openCreateProjectDialog(pwd, false)){ - DashwaveWindow.enableRunButton() - DashwaveWindow.disableCancelButton() - return + openCreateProjectDialog(pwd, false, this.dwWindow){ + execute() } + return } execute() } diff --git a/src/main/kotlin/com/dashwave/plugin/utils/DwCmds.kt b/src/main/kotlin/com/dashwave/plugin/utils/DwCmds.kt index 8af0ded..7cbde4a 100644 --- a/src/main/kotlin/com/dashwave/plugin/utils/DwCmds.kt +++ b/src/main/kotlin/com/dashwave/plugin/utils/DwCmds.kt @@ -2,6 +2,8 @@ package com.dashwave.plugin.utils import com.dashwave.plugin.installDW import com.dashwave.plugin.listModulesAndVariants +import com.dashwave.plugin.listUsers +import com.dashwave.plugin.loginUser import com.dashwave.plugin.notif.BalloonNotif import com.dashwave.plugin.windows.DashwaveWindow import com.intellij.execution.filters.HyperlinkInfo @@ -17,27 +19,29 @@ import java.util.concurrent.CompletableFuture import java.util.concurrent.Executors import kotlin.system.exitProcess -class DwCmds(execCmd:String, wd:String?, log: Boolean){ +class DwCmds(execCmd:String, wd:String?, log: Boolean, dwWindow: DashwaveWindow){ private var cmd:String private var p:Process private var pwd:String? private var shouldLog:Boolean + private var dwWindow:DashwaveWindow init { shouldLog = log cmd = "dw $execCmd --plugin" pwd = wd - p = com.dashwave.plugin.utils.Process(cmd, pwd, log) + p = com.dashwave.plugin.utils.Process(cmd, pwd, log, dwWindow) + this.dwWindow = dwWindow } fun executeWithExitCode():Int{ this.p.start(this.shouldLog) val exitCode = this.p.wait() if(exitCode == 11){ - DashwaveWindow.displayError("Dashwave has a major update, you need to update dependencies\n") + this.dwWindow.displayError("Dashwave has a major update, you need to update dependencies\n") val hyperlink = HyperlinkInfo { p: Project -> - installDW(this.pwd) + installDW(this.pwd, this.dwWindow) } - DashwaveWindow.console.printHyperlink("Click here to update\n\n", hyperlink) + this.dwWindow.console.printHyperlink("Click here to update\n\n", hyperlink) } return exitCode } @@ -46,11 +50,11 @@ class DwCmds(execCmd:String, wd:String?, log: Boolean){ this.p.start(this.shouldLog) val exitCode = this.p.wait() if(exitCode == 11){ - DashwaveWindow.displayError("Dashwave has a major update, you need to update dependencies\n") + this.dwWindow.displayError("Dashwave has a major update, you need to update dependencies\n") val hyperlink = HyperlinkInfo { p: Project -> - installDW(this.pwd) + installDW(this.pwd, this.dwWindow) } - DashwaveWindow.console.printHyperlink("Click here to update\n\n", hyperlink) + this.dwWindow.console.printHyperlink("Click here to update\n\n", hyperlink) } // get the stdout as string @@ -65,23 +69,25 @@ class DwCmds(execCmd:String, wd:String?, log: Boolean){ fun executeBuild(pwd:String?, openEmulator:Boolean){ this.p.start(this.shouldLog) - DashwaveWindow.disableRunButton() - DashwaveWindow.enableCancelButton() - DashwaveWindow.currentBuild = this + this.dwWindow.disableRunButton() + this.dwWindow.enableCancelButton() + this.dwWindow.currentBuild = this BalloonNotif( "Build started", "", "Build started on dashwave. Your build is running on a remote machine. You can view the logs in console and view emulation after build completes", NotificationType.INFORMATION - ){}.show() - DashwaveWindow.changeIcon(DashwaveWindow.loadIcon) + ){}.show(dwWindow.p) + this.dwWindow.changeIcon(this.dwWindow.loadIcon) Thread{ var ex = this.p.wait() - DashwaveWindow.currentBuild = null - DashwaveWindow.changeIcon(DashwaveWindow.dwIcon) - DashwaveWindow.enableRunButton() - DashwaveWindow.disableCancelButton() -// DashwaveWindow.show() + this.dwWindow.currentBuild = null + this.dwWindow.changeIcon(this.dwWindow.dwIcon) + this.dwWindow.enableRunButton() + this.dwWindow.disableCancelButton() + listModulesAndVariants(pwd, this.dwWindow) +// listUsers(pwd, this.dwWindow) + this.dwWindow.show() when(ex){ 0 -> { BalloonNotif( @@ -91,20 +97,20 @@ class DwCmds(execCmd:String, wd:String?, log: Boolean){ NotificationType.INFORMATION ){ // BrowserUtil.browse("https://console.dashwave.io/home?profile=true") - }.show() + }.show(dwWindow.p) if(openEmulator){ - val emulatorCmd = DwCmds("emulator", pwd, false) - DashwaveWindow.lastEmulatorProcess = emulatorCmd + val emulatorCmd = DwCmds("emulator", pwd, false, this.dwWindow) + this.dwWindow.lastEmulatorProcess = emulatorCmd val ex = emulatorCmd.executeWithExitCode() } } 11 -> { - DashwaveWindow.displayError("Dashwave has a major update, you need to update dependencies\n") + this.dwWindow.displayError("Dashwave has a major update, you need to update dependencies\n") val hyperlink = HyperlinkInfo { p: Project -> - installDW(pwd) + installDW(pwd, this.dwWindow) } - DashwaveWindow.console.printHyperlink("Click here to update\n\n", hyperlink) + this.dwWindow.console.printHyperlink("Click here to update\n\n", hyperlink) } // exitcode = 12 means authorize scm failed 12 -> { @@ -114,8 +120,24 @@ class DwCmds(execCmd:String, wd:String?, log: Boolean){ "We could not fetch your project from github/gitlab. Please authorize to provide access", NotificationType.ERROR ){ - BrowserUtil.browse("https://console.dashwave.io/home?profile=true") - }.show() + BrowserUtil.browse("https://consoledev.dashwave.io/home?profile=true") + }.show(dwWindow.p) + } + 13 -> { + BalloonNotif( + "Not Authorized", + "Login here", + "Your auth token may have expired. Click here to login again", + NotificationType.ERROR + ){ + loginUser(pwd, dwWindow) + }.show(dwWindow.p) + + this.dwWindow.displayError("Your auth token seems to have expired. Click below to login again\n") + val hyperlink = HyperlinkInfo { p: Project -> + loginUser(pwd, this.dwWindow) + } + this.dwWindow.console.printHyperlink("Login here\n\n", hyperlink) } else -> { // add try again @@ -124,11 +146,9 @@ class DwCmds(execCmd:String, wd:String?, log: Boolean){ "", "Your build failed. Please check for logs in the console", NotificationType.ERROR - ){}.show() + ){}.show(dwWindow.p) } } - // common post build flow - listModulesAndVariants(pwd) }.start() } } diff --git a/src/main/kotlin/com/dashwave/plugin/utils/Process.kt b/src/main/kotlin/com/dashwave/plugin/utils/Process.kt index fc48b71..e5db568 100644 --- a/src/main/kotlin/com/dashwave/plugin/utils/Process.kt +++ b/src/main/kotlin/com/dashwave/plugin/utils/Process.kt @@ -14,13 +14,15 @@ import java.util.concurrent.ExecutorService import java.util.concurrent.Executors import kotlin.concurrent.thread -class Process(cmd:String, pwd:String?, log:Boolean){ +class Process(cmd:String, pwd:String?, log:Boolean, dwWindow: DashwaveWindow){ private var ph:ProcessHandler private val latch = CountDownLatch(1) private val outputBuilder = StringBuilder() private var command:String + private var dwWind:DashwaveWindow init { command = cmd + dwWind = dwWindow val cmd = GeneralCommandLine("/bin/bash","-c",cmd) if(pwd != null && pwd != ""){ cmd.setWorkDirectory(pwd) @@ -37,7 +39,7 @@ class Process(cmd:String, pwd:String?, log:Boolean){ } outputBuilder.append(text) if(log) { - decodeAndPrintString("$text\n", outputType) + decodeAndPrintString(event.text, outputType, dwWindow) } } override fun processTerminated(event: ProcessEvent) { @@ -49,7 +51,7 @@ class Process(cmd:String, pwd:String?, log:Boolean){ fun start(log: Boolean){ if(log){ - DashwaveWindow.displayInfo("${this.command}\n\n") + this.dwWind.displayInfo("${this.command}\n\n") } ph.startNotify() } @@ -67,10 +69,10 @@ class Process(cmd:String, pwd:String?, log:Boolean){ return outputBuilder.toString() } } -private fun decodeAndPrintString(s:String, p: Key<*>){ +private fun decodeAndPrintString(s:String, p: Key<*>, dwWindow: DashwaveWindow){ val decoder = AnsiEscapeDecoder() val outputListener = AnsiEscapeDecoder.ColoredTextAcceptor { text, attributes -> - DashwaveWindow.displayOutput(text, ConsoleViewContentType.getConsoleViewType(attributes)) + dwWindow.displayOutput(text, ConsoleViewContentType.getConsoleViewType(attributes)) } decoder.escapeText(s, p, outputListener) } \ No newline at end of file diff --git a/src/main/kotlin/com/dashwave/plugin/windows/DashwaveWindow.kt b/src/main/kotlin/com/dashwave/plugin/windows/DashwaveWindow.kt index 7b8c510..ea40be0 100644 --- a/src/main/kotlin/com/dashwave/plugin/windows/DashwaveWindow.kt +++ b/src/main/kotlin/com/dashwave/plugin/windows/DashwaveWindow.kt @@ -2,6 +2,7 @@ package com.dashwave.plugin.windows import com.dashwave.plugin.components.CollapseMenu import com.dashwave.plugin.loginUser +import com.dashwave.plugin.actions.BuildAction import com.dashwave.plugin.utils.DwBuild import com.dashwave.plugin.utils.DwBuildConfig import com.dashwave.plugin.utils.DwCmds @@ -31,193 +32,204 @@ import java.awt.event.ItemListener import java.awt.image.BufferedImage import javax.swing.* -class DashwaveWindow : ToolWindowFactory { - companion object { - var lastEmulatorProcess:DwCmds? = null - var currentBuild:DwCmds? = null - lateinit var console: ConsoleView - lateinit var runButton: JButton - lateinit var cancelButton: JButton - lateinit var p: Project - var dwIcon: Icon = IconLoader.getIcon("/icons/dashwave13.svg") - var loadIcon: Icon = AnimatedIcon.Default() - var runEnabled = false - private var cleanBuildCheckbox:JCheckBox = JCheckBox("Clean Build") - private var debugEnabledCheckBox: JCheckBox = JCheckBox("Enable Debug") - private var openEmulatorCheckbox:JCheckBox = JCheckBox("Open Emulator") - private var buildOpts = CollapseMenu("Build opts") - private var modulesList: JComboBox = JComboBox() - private var variantsList: JComboBox = JComboBox() - private var usersList: JComboBox = JComboBox() - private var selectedUser: String = "" - private var lastSelectedUser: String = "" - var selectedModule:String="" - var selectedVariant:String="" - - fun show(){ - val toolWindowManager = ToolWindowManager.getInstance(p) - val myWindow = toolWindowManager.getToolWindow("Dashwave") - myWindow?.show() - } +class DashwaveWindow(project: Project){ + var lastEmulatorProcess:DwCmds? = null + var currentBuild:DwCmds? = null + lateinit var console: ConsoleView + lateinit var runButton: JButton + lateinit var cancelButton: JButton + lateinit var p: Project + var dwIcon: Icon = IconLoader.getIcon("/icons/dashwave13.svg") + var loadIcon: Icon = AnimatedIcon.Default() + var runEnabled = false + private var cleanBuildCheckbox:JCheckBox = JCheckBox("Clean Build") + private var debugEnabledCheckBox: JCheckBox = JCheckBox("Enable Debug") + private var openEmulatorCheckbox:JCheckBox = JCheckBox("Open Emulator") + var window:ToolWindow? = null + private var buildOpts = CollapseMenu("Build opts") + private var modulesList: JComboBox = JComboBox() + private var variantsList: JComboBox = JComboBox() + private var usersList: JComboBox = JComboBox() + private var selectedUser: String = "" + private var lastSelectedUser: String = "" + var selectedModule:String="" + var selectedVariant:String="" + + init { + p = project + val toolWindowManager = ToolWindowManager.getInstance(project) + val toolWindow = toolWindowManager.registerToolWindow( + "Dashwave", // ID of the tool window + false, // canCloseContent - whether the tool window can be closed + ToolWindowAnchor.BOTTOM // The anchor location + ) + window = toolWindow + toolWindow.setIcon(IconLoader.getIcon("/icons/dashwave13.svg")) + createToolWindowContent() + } - fun changeIcon(icon:Icon){ - val toolWindowManager = ToolWindowManager.getInstance(p) - val myWindow = toolWindowManager.getToolWindow("Dashwave") - myWindow?.setIcon(icon) - } - fun clearConsole(){ - console.clear() - } + fun show(){ + window?.show() + } + fun changeIcon(icon:Icon){ + window?.setIcon(icon) + } - fun getBuildConfigs(p:Project):DwBuildConfig{ - val cleanBuild = cleanBuildCheckbox.isSelected - val debugEnabled = debugEnabledCheckBox.isSelected - val openEmulator = openEmulatorCheckbox.isSelected - val module: String = selectedModule - val variant: String = selectedVariant - DashwaveWindow.displayInfo("open emulator is $openEmulator") - return DwBuildConfig(cleanBuild, debugEnabled, openEmulator, module, variant, p.basePath) - } + fun clearConsole(){ + console.clear() + } - fun displayOutput(s:String, type:ConsoleViewContentType){ - console.print(s, type) - } + fun getBuildConfigs(p:Project):DwBuildConfig{ + val cleanBuild = cleanBuildCheckbox.isSelected + val debugEnabled = debugEnabledCheckBox.isSelected + val openEmulator = openEmulatorCheckbox.isSelected + val module: String = selectedModule + val variant: String = selectedVariant + this.displayInfo("open emulator is $openEmulator") + return DwBuildConfig(cleanBuild, debugEnabled, openEmulator, module, variant, p.basePath) + } - fun displayInfo(s:String){ - console.print(s, ConsoleViewContentType.NORMAL_OUTPUT) - } + fun displayOutput(s:String, type:ConsoleViewContentType){ + console.print(s, type) + } - fun displayError(s:String){ - console.print(s, ConsoleViewContentType.ERROR_OUTPUT) - } + fun displayInfo(s:String){ + console.print(s, ConsoleViewContentType.NORMAL_OUTPUT) + } - fun disableRunButton(){ - runEnabled = false - runButton.isEnabled = false - cleanBuildCheckbox.isEnabled = false - debugEnabledCheckBox.isEnabled = false - openEmulatorCheckbox.isEnabled = false - } + fun displayError(s:String){ + console.print(s, ConsoleViewContentType.ERROR_OUTPUT) + } - fun enableRunButton(){ - runEnabled = true - runButton.isEnabled = true - cleanBuildCheckbox.isEnabled = true - debugEnabledCheckBox.isEnabled = true - openEmulatorCheckbox.isEnabled = true - } + fun disableRunButton(){ + runEnabled = false + runButton.isEnabled = false + cleanBuildCheckbox.isEnabled = false + debugEnabledCheckBox.isEnabled = false + openEmulatorCheckbox.isEnabled = false + } - fun disableCancelButton(){ - cancelButton.isEnabled = false - } - fun enableCancelButton(){ - cancelButton.isEnabled = true - } + fun enableRunButton(){ + runEnabled = true + runButton.isEnabled = true + cleanBuildCheckbox.isEnabled = true + debugEnabledCheckBox.isEnabled = true + openEmulatorCheckbox.isEnabled = true + } - private fun addNewUserButton(pwd:String?):JButton{ - val addUserButton = JButton(createPlusIcon(16,Color.GRAY)).apply { - toolTipText = "Add user" - addActionListener{ - loginUser(pwd) - } + fun disableCancelButton(){ + cancelButton.isEnabled = false + } + fun enableCancelButton(){ + cancelButton.isEnabled = true + } + + private fun addNewUserButton(pwd:String?):JButton{ + val dwWindow:DashwaveWindow = this + val addUserButton = JButton(createPlusIcon(16,Color.GRAY)).apply { + toolTipText = "Add user" + addActionListener{ + loginUser(pwd, dwWindow) } - addUserButton.setSize(10,10) - return addUserButton } + addUserButton.setSize(10,10) + return addUserButton + } - fun switchUser(user:String, wd:String?){ - val switchUserCmd = DwCmds("user switch $user", wd, true) - val exitCode = switchUserCmd.executeWithExitCode() - if (exitCode != 0){ - displayError("❌ Could not switch to user: $user\n\n") - return - } - displayInfo("✅ Successfully switched to user: $user\n\n") + fun switchUser(user:String, wd:String?){ + val switchUserCmd = DwCmds("user switch $user", wd, true, this) + val exitCode = switchUserCmd.executeWithExitCode() + if (exitCode != 0){ + displayError("❌ Could not switch to user: $user\n\n") + return } + displayInfo("✅ Successfully switched to user: $user\n\n") + } - fun addUsers(users: List?,activeUser:String, wd:String?){ - usersList.removeAllItems() + fun addUsers(users: List?,activeUser:String, wd:String?){ + usersList.removeAllItems() - if(users == null || users.size == 0){ - usersList.isEnabled = false - usersList.addItem("No users logged in") - return - } - usersList.isEnabled = true - users?.forEach{ user -> - usersList.addItem(user) - } - this.selectedUser = activeUser - usersList.selectedItem = activeUser - - usersList.addItemListener(ItemListener { - if (this.selectedUser == it.item.toString()){ - return@ItemListener - } - this.lastSelectedUser = selectedUser - this.selectedUser = it.item.toString() - switchUser(this.selectedUser, wd) - }) + if(users == null || users.size == 0){ + usersList.isEnabled = false + usersList.addItem("No users logged in") + return + } + usersList.isEnabled = true + users?.forEach{ user -> + usersList.addItem(user) } + this.selectedUser = activeUser + usersList.selectedItem = activeUser - fun addModulesAndVariants(modulesVariants: Map>, defaultModule: String, defaultVariant: String){ - modulesList.removeAllItems() - variantsList.removeAllItems() + usersList.addItemListener(ItemListener { + if (this.selectedUser == it.item.toString()){ + return@ItemListener + } + this.lastSelectedUser = selectedUser + this.selectedUser = it.item.toString() + switchUser(this.selectedUser, wd) + }) + } - if (modulesVariants.size == 0){ - modulesList.addItem("No modules detected yet") - variantsList.addItem("No variants detected yet") - modulesList.isEnabled = false - variantsList.isEnabled = false - return - } - modulesList.isEnabled = true - variantsList.isEnabled = true + fun addModulesAndVariants(modulesVariants: Map>, defaultModule: String, defaultVariant: String){ + modulesList.removeAllItems() + variantsList.removeAllItems() - modulesList.addItem(defaultModule) - variantsList.addItem(defaultVariant) + if (modulesVariants.size == 0){ + modulesList.addItem("No modules detected yet") + variantsList.addItem("No variants detected yet") + modulesList.isEnabled = false + variantsList.isEnabled = false + return + } + modulesList.isEnabled = true + variantsList.isEnabled = true - modulesVariants.keys.toTypedArray().forEach { module -> - modulesList.addItem(module) - } + modulesList.addItem(defaultModule) + variantsList.addItem(defaultVariant) + + modulesVariants.keys.toTypedArray().forEach { module -> + modulesList.addItem(module) + } - modulesList.addItemListener(ItemListener { - if (it.stateChange == ItemEvent.SELECTED) { - if(it.item.toString().contains("modules detected")){ - selectedModule = "" - return@ItemListener - } - selectedModule = modulesList.selectedItem as String - variantsList.removeAllItems() - modulesVariants[selectedModule]?.forEach { variant -> - variantsList.addItem(variant) - } + modulesList.addItemListener(ItemListener { + if (it.stateChange == ItemEvent.SELECTED) { + if(it.item.toString().contains("modules detected")){ + selectedModule = "" + return@ItemListener } - }) - - variantsList.addItemListener(ItemListener { - if (it.stateChange == ItemEvent.SELECTED) { - if(it.item.toString() == "variants detected"){ - selectedVariant = "" - return@ItemListener - } - selectedVariant = variantsList.selectedItem as String + selectedModule = modulesList.selectedItem as String + variantsList.removeAllItems() + modulesVariants[selectedModule]?.forEach { variant -> + variantsList.addItem(variant) } - }) - } + } + }) + + variantsList.addItemListener(ItemListener { + if (it.stateChange == ItemEvent.SELECTED) { + if(it.item.toString() == "variants detected"){ + selectedVariant = "" + return@ItemListener + } + selectedVariant = variantsList.selectedItem as String + } + }) } - override fun createToolWindowContent(project: Project, toolWindow: ToolWindow) { - println("\n\ncretate tool window content is called") - console = TextConsoleBuilderFactory.getInstance().createBuilder(project).console + + private fun createToolWindowContent() { + println("\n\ncretate tool window content is called\n\n") + console = TextConsoleBuilderFactory.getInstance().createBuilder(p).console + val contentFactory = ContentFactory.getInstance() val panel = JPanel(BorderLayout()) // Set up the toolbar with a button val actionToolbar = JToolBar(JToolBar.HORIZONTAL) runButton = JButton(AllIcons.Actions.RunAll) runButton.addActionListener { - val configs = getBuildConfigs(p) - val build = DwBuild(configs) + val configs = getBuildConfigs(this.p) + val build = DwBuild(configs, this) build.run(p) } @@ -225,7 +237,7 @@ class DashwaveWindow : ToolWindowFactory { cancelButton.addActionListener{ disableCancelButton() currentBuild?.exit() - val stopBuild = DwCmds("stop-build", p.basePath, true) + val stopBuild = DwCmds("stop-build", p.basePath, true, this) stopBuild.executeWithExitCode() enableRunButton() } @@ -274,7 +286,7 @@ class DashwaveWindow : ToolWindowFactory { userGroup.add(usersList) - val addUserBtn = addNewUserButton(project.basePath) + val addUserBtn = addNewUserButton(this.p.basePath) addUserBtn.setSize(10,10) userGroup.add(addUserBtn) actionToolbar.add(userGroup) @@ -290,10 +302,9 @@ class DashwaveWindow : ToolWindowFactory { panel.add(console.component, BorderLayout.CENTER) - val contentFactory = ContentFactory.getInstance() val content = contentFactory.createContent(panel, "", false) - toolWindow.setAnchor(ToolWindowAnchor.BOTTOM, null) - toolWindow.contentManager.addContent(content) + window?.setAnchor(ToolWindowAnchor.BOTTOM, null) + window?.contentManager?.addContent(content) } } diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 058f333..240d86b 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -64,11 +64,11 @@ - + + + + + From 6a4818868d68e155f98c09136f8e60e8c88f0b23 Mon Sep 17 00:00:00 2001 From: Aviral Jain Date: Tue, 23 Apr 2024 19:10:51 +0530 Subject: [PATCH 07/15] add env variable in configuration --- build.gradle.kts | 2 +- .../dashwave/plugin/PluginConfiguration.kt | 35 +++++++++++++ .../com/dashwave/plugin/PluginStartup.kt | 49 ++++++++++++++++++- .../com/dashwave/plugin/utils/DwBuild.kt | 4 ++ .../dashwave/plugin/windows/DashwaveWindow.kt | 11 ++++- src/main/resources/META-INF/plugin.xml | 6 +++ 6 files changed, 104 insertions(+), 3 deletions(-) create mode 100644 src/main/kotlin/com/dashwave/plugin/PluginConfiguration.kt diff --git a/build.gradle.kts b/build.gradle.kts index 99c1db3..43ad1ce 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,7 +5,7 @@ plugins { } group = "com.dashwave" -version = "2.3.1" +version = "2.3.3" repositories { mavenCentral() diff --git a/src/main/kotlin/com/dashwave/plugin/PluginConfiguration.kt b/src/main/kotlin/com/dashwave/plugin/PluginConfiguration.kt new file mode 100644 index 0000000..1df9f86 --- /dev/null +++ b/src/main/kotlin/com/dashwave/plugin/PluginConfiguration.kt @@ -0,0 +1,35 @@ +package com.dashwave.plugin + +import com.intellij.openapi.components.PersistentStateComponent +import com.intellij.openapi.components.Service +import com.intellij.openapi.components.ServiceManager +import com.intellij.openapi.components.State +import com.intellij.openapi.components.Storage + +@Service +@State( + name = "PluginSettings", + storages = [Storage("PluginSettings.xml")] +) +class PluginConfiguration: PersistentStateComponent { + data class State( + var pluginMode:String = "local", + var pluginEnv:String = "" + ) + + private var myState = State() + + override fun getState(): State { + return myState + } + + override fun loadState(state: State) { + myState = state + } + + companion object { + fun getInstance(): PluginConfiguration { + return ServiceManager.getService(PluginConfiguration::class.java) + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/dashwave/plugin/PluginStartup.kt b/src/main/kotlin/com/dashwave/plugin/PluginStartup.kt index a1a571f..28c1a35 100644 --- a/src/main/kotlin/com/dashwave/plugin/PluginStartup.kt +++ b/src/main/kotlin/com/dashwave/plugin/PluginStartup.kt @@ -28,12 +28,24 @@ import com.intellij.openapi.actionSystem.ActionManager import com.intellij.openapi.actionSystem.Anchor import com.intellij.openapi.actionSystem.Constraints import com.intellij.openapi.actionSystem.DefaultActionGroup +import com.intellij.openapi.application.PathManager +import com.intellij.openapi.components.ServiceManager import io.ktor.util.* import java.awt.Font +var PluginMode:String = "" +var PluginEnv:String = "" class PluginStartup: StartupActivity { companion object { var dwWindows:HashMap = HashMap() + var pluginMode:String = "" + var pluginEnv:String = "" + } + + init { + val pluginConfig = PluginConfiguration.getInstance() + pluginMode = pluginConfig.state.pluginMode + pluginEnv = pluginConfig.state.pluginEnv } override fun runActivity(project: Project) { @@ -41,6 +53,8 @@ class PluginStartup: StartupActivity { dwWindow.show() dwWindows[project.name] = dwWindow checkDW(project, dwWindow) + PluginMode = pluginMode + PluginEnv = pluginEnv } } @@ -80,14 +94,32 @@ fun installDW(pwd: String?, dwWindow: DashwaveWindow){ if (exitCode == 0) { dwWindow.displayInfo(Messages.DW_DEPS_INSTALL_SUCCESS) dwWindow.displayInfo(Messages.DW_DEPS_CONFIGURING) + val configCmd = DwCmds("config", pwd, true, dwWindow) val exitcode = configCmd.executeWithExitCode() if(exitcode == 0){ + if(PluginMode == "workspace"){ + dwWindow.displayInfo("🔨 Setting up workspace plugin...\n") + var workspaceCmd = "setup-workspace" + if(PluginEnv != ""){ + workspaceCmd += " -e ${PluginEnv}" + } + val setupWorkspaceCmd = DwCmds(workspaceCmd, pwd, true, dwWindow) + val exitCode = setupWorkspaceCmd.executeWithExitCode() + if(exitCode == 0){ + verifyLogin(pwd, dwWindow) + }else{ + dwWindow.displayError("❌ Could not setup plugin. Please contact us at hello@dashwave.io") + } + return@Thread + } + dwWindow.displayInfo(Messages.DW_DEPS_CONFIGURE_SUCCESS) verifyLogin(pwd, dwWindow) }else{ dwWindow.displayError(Messages.DW_DEPS_CONFIGURE_FAILED) } + } else { dwWindow.displayError(Messages.DW_DEPS_INSTALL_FAILED) } @@ -103,6 +135,10 @@ fun verifyLogin(pwd:String?, dwWindow: DashwaveWindow){ dwWindow.enableRunButton() checkProjectConnected(pwd, dwWindow) }else{ + if(PluginMode == "workspace") { + dwWindow.displayError("❌ User is not setup correctly. Please contact us at hello@dashwave.io") + return + } loginUser(pwd, dwWindow) } } @@ -112,6 +148,10 @@ fun checkProjectConnected(pwd:String?, dwWindow: DashwaveWindow){ // check if .git folder exists val gitConfigFilepath = "$pwd/.git" if (!doesFileExist(gitConfigFilepath)){ + if(PluginMode == "workspace"){ + dwWindow.displayError("❌ There is some issue in setting up your project (.git doesn't exist), please contact us at hello@dashwave.io") + return + } dwWindow.displayOutput("❌ ${Messages.GIT_NOT_CONFIGURED}", ConsoleViewContentType.ERROR_OUTPUT) val notif = BalloonNotif( "Could not find .git folder", @@ -133,6 +173,10 @@ fun checkProjectConnected(pwd:String?, dwWindow: DashwaveWindow){ val dd = ReadyForBuildDialog() dd.show() }else { + if(PluginMode == "worksapce"){ + dwWindow.displayError("❌ There is some issue in setting up your project (dashwave.yml doesn't exist), please contact us at hello@dashwave.io") + return + } dwWindow.displayOutput("⚠️ This project is not connected to dashwave, create a new project on dashwave\n\n", ConsoleViewContentType.NORMAL_OUTPUT) openCreateProjectDialog(pwd, true, dwWindow){} } @@ -151,7 +195,10 @@ fun loginUser(pwd:String?, dwWindow: DashwaveWindow) { return } - val loginUserCmd = "login $accessCode" + var loginUserCmd = "login $accessCode" + if(PluginEnv != ""){ + loginUserCmd += " -e $PluginEnv" + } val exitCode = DwCmds(loginUserCmd, pwd, true, dwWindow).executeWithExitCode() if (exitCode == 0) { dwWindow.enableRunButton() diff --git a/src/main/kotlin/com/dashwave/plugin/utils/DwBuild.kt b/src/main/kotlin/com/dashwave/plugin/utils/DwBuild.kt index d301958..d7ff161 100644 --- a/src/main/kotlin/com/dashwave/plugin/utils/DwBuild.kt +++ b/src/main/kotlin/com/dashwave/plugin/utils/DwBuild.kt @@ -1,5 +1,6 @@ package com.dashwave.plugin.utils +import com.dashwave.plugin.PluginMode import com.dashwave.plugin.doesFileExist import com.dashwave.plugin.openCreateProjectDialog import com.dashwave.plugin.windows.DashwaveWindow @@ -22,6 +23,9 @@ class DwBuild(config: DwBuildConfig, dwWindow: DashwaveWindow){ private var pwd:String? private var dwWindow:DashwaveWindow init { + if(PluginMode == "workspace"){ + cmd += " --workspace" + } if(config.clean){ cmd += " --clean" } diff --git a/src/main/kotlin/com/dashwave/plugin/windows/DashwaveWindow.kt b/src/main/kotlin/com/dashwave/plugin/windows/DashwaveWindow.kt index ea40be0..c8de594 100644 --- a/src/main/kotlin/com/dashwave/plugin/windows/DashwaveWindow.kt +++ b/src/main/kotlin/com/dashwave/plugin/windows/DashwaveWindow.kt @@ -1,5 +1,6 @@ package com.dashwave.plugin.windows +import com.dashwave.plugin.PluginStartup import com.dashwave.plugin.components.CollapseMenu import com.dashwave.plugin.loginUser import com.dashwave.plugin.actions.BuildAction @@ -18,6 +19,7 @@ import com.intellij.ui.content.ContentFactory import java.awt.BorderLayout import com.intellij.icons.AllIcons; import com.intellij.openapi.application.ApplicationManager +import com.intellij.openapi.fileEditor.FileDocumentManager import com.intellij.openapi.util.IconLoader import com.intellij.openapi.wm.ToolWindowManager import com.intellij.ui.AnimatedIcon @@ -155,7 +157,9 @@ class DashwaveWindow(project: Project){ usersList.addItem("No users logged in") return } - usersList.isEnabled = true + if(PluginStartup.pluginMode != "workspace"){ + usersList.isEnabled = true + } users?.forEach{ user -> usersList.addItem(user) } @@ -228,6 +232,7 @@ class DashwaveWindow(project: Project){ val actionToolbar = JToolBar(JToolBar.HORIZONTAL) runButton = JButton(AllIcons.Actions.RunAll) runButton.addActionListener { + FileDocumentManager.getInstance().saveAllDocuments(); val configs = getBuildConfigs(this.p) val build = DwBuild(configs, this) build.run(p) @@ -290,6 +295,10 @@ class DashwaveWindow(project: Project){ addUserBtn.setSize(10,10) userGroup.add(addUserBtn) actionToolbar.add(userGroup) + if(PluginStartup.pluginMode == "workspace") { + addUserBtn.isEnabled = false + usersList.isEnabled = false + } openEmulatorCheckbox.isSelected = true diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 240d86b..6a3f7f4 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -10,6 +10,12 @@ Dashwave + + + com.dashwave.plugin.PluginConfiguration + + + From b4ee9b8605a713b3a58079e93fc8e1f85316be1e Mon Sep 17 00:00:00 2001 From: Aviral Jain Date: Fri, 10 May 2024 12:48:02 +0530 Subject: [PATCH 08/15] update plugin compatibility --- build.gradle.kts | 8 ++++---- .../com/dashwave/plugin/dialogbox/CreateProjectDialog.kt | 2 +- .../com/dashwave/plugin/dialogbox/ReadyForBuildDialog.kt | 2 +- src/main/kotlin/com/dashwave/plugin/utils/DwCmds.kt | 8 -------- .../kotlin/com/dashwave/plugin/windows/DashwaveWindow.kt | 4 ++-- 5 files changed, 8 insertions(+), 16 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 43ad1ce..cbeefbf 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,7 +5,7 @@ plugins { } group = "com.dashwave" -version = "2.3.3" +version = "3.0.0" repositories { mavenCentral() @@ -18,7 +18,7 @@ dependencies { // Configure Gradle IntelliJ Plugin // Read more: https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html intellij { - version.set("2022.2.5") + version.set("2024.1.1") type.set("IC") // Target IDE Platform plugins.set(listOf(/* Plugin Dependencies */)) @@ -35,8 +35,8 @@ tasks { } patchPluginXml { - sinceBuild.set("222") - untilBuild.set("232.*") + sinceBuild.set("201.*") + untilBuild.set("241.*") } signPlugin { diff --git a/src/main/kotlin/com/dashwave/plugin/dialogbox/CreateProjectDialog.kt b/src/main/kotlin/com/dashwave/plugin/dialogbox/CreateProjectDialog.kt index d922970..b11558f 100644 --- a/src/main/kotlin/com/dashwave/plugin/dialogbox/CreateProjectDialog.kt +++ b/src/main/kotlin/com/dashwave/plugin/dialogbox/CreateProjectDialog.kt @@ -35,7 +35,7 @@ class CreateProjectDialog(project: Project): DialogWrapper(project) { gbc.gridx = 0 gbc.gridy = 0 gbc.gridwidth = 2 - val icon = IconLoader.getIcon("/icons/dashwave13.svg") // Make sure to provide the correct path + val icon = IconLoader.getIcon("/icons/dashwave13.svg", CreateProjectDialog::class.java.classLoader) // Make sure to provide the correct path val labelWithIcon = JLabel("Create a new project to be able to run builds on dashwave", icon, SwingConstants.LEFT) panel.add(labelWithIcon, gbc) diff --git a/src/main/kotlin/com/dashwave/plugin/dialogbox/ReadyForBuildDialog.kt b/src/main/kotlin/com/dashwave/plugin/dialogbox/ReadyForBuildDialog.kt index e190d52..e95c618 100644 --- a/src/main/kotlin/com/dashwave/plugin/dialogbox/ReadyForBuildDialog.kt +++ b/src/main/kotlin/com/dashwave/plugin/dialogbox/ReadyForBuildDialog.kt @@ -17,7 +17,7 @@ class ReadyForBuildDialog : DialogWrapper(true) { val dialogPanel = JPanel() // Load the image icon - val icon = IconLoader.getIcon("/icons/dashwave13.svg") + val icon = IconLoader.getIcon("/icons/dashwave13.svg", ReadyForBuildDialog::class.java.classLoader) val iconLabel = JLabel(icon) // Add components to the panel diff --git a/src/main/kotlin/com/dashwave/plugin/utils/DwCmds.kt b/src/main/kotlin/com/dashwave/plugin/utils/DwCmds.kt index 7cbde4a..a527315 100644 --- a/src/main/kotlin/com/dashwave/plugin/utils/DwCmds.kt +++ b/src/main/kotlin/com/dashwave/plugin/utils/DwCmds.kt @@ -9,15 +9,7 @@ import com.dashwave.plugin.windows.DashwaveWindow import com.intellij.execution.filters.HyperlinkInfo import com.intellij.ide.BrowserUtil import com.intellij.notification.NotificationType -import com.intellij.openapi.keymap.impl.ui.Hyperlink import com.intellij.openapi.project.Project -import com.intellij.util.Futures.thenRunAsync -import okhttp3.internal.wait -import java.io.BufferedReader -import java.io.InputStreamReader -import java.util.concurrent.CompletableFuture -import java.util.concurrent.Executors -import kotlin.system.exitProcess class DwCmds(execCmd:String, wd:String?, log: Boolean, dwWindow: DashwaveWindow){ private var cmd:String diff --git a/src/main/kotlin/com/dashwave/plugin/windows/DashwaveWindow.kt b/src/main/kotlin/com/dashwave/plugin/windows/DashwaveWindow.kt index c8de594..76139f9 100644 --- a/src/main/kotlin/com/dashwave/plugin/windows/DashwaveWindow.kt +++ b/src/main/kotlin/com/dashwave/plugin/windows/DashwaveWindow.kt @@ -41,7 +41,7 @@ class DashwaveWindow(project: Project){ lateinit var runButton: JButton lateinit var cancelButton: JButton lateinit var p: Project - var dwIcon: Icon = IconLoader.getIcon("/icons/dashwave13.svg") + var dwIcon: Icon = IconLoader.getIcon("/icons/dashwave13.svg", DashwaveWindow::class.java.classLoader) var loadIcon: Icon = AnimatedIcon.Default() var runEnabled = false private var cleanBuildCheckbox:JCheckBox = JCheckBox("Clean Build") @@ -66,7 +66,7 @@ class DashwaveWindow(project: Project){ ToolWindowAnchor.BOTTOM // The anchor location ) window = toolWindow - toolWindow.setIcon(IconLoader.getIcon("/icons/dashwave13.svg")) + toolWindow.setIcon(IconLoader.getIcon("/icons/dashwave13.svg", DashwaveWindow::class.java.classLoader)) createToolWindowContent() } From aa0899066ef8f923a9255acb8e5c52a89e9aabf8 Mon Sep 17 00:00:00 2001 From: Aviral Jain Date: Wed, 15 May 2024 18:33:34 +0530 Subject: [PATCH 09/15] change compatibility from 222-241 --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index cbeefbf..c854492 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -35,7 +35,7 @@ tasks { } patchPluginXml { - sinceBuild.set("201.*") + sinceBuild.set("222.*") untilBuild.set("241.*") } From f6f04ed04078677ce67867d50418b43f87baa3b6 Mon Sep 17 00:00:00 2001 From: Aviral Jain Date: Wed, 15 May 2024 18:34:06 +0530 Subject: [PATCH 10/15] add debugger functionality --- build.gradle.kts | 2 +- .../dashwave/plugin/actions/RunDebugAction.kt | 22 +++++++++++++ .../com/dashwave/plugin/utils/DwBuild.kt | 8 ++++- .../com/dashwave/plugin/utils/DwCmds.kt | 30 ++++++++++++++++-- .../dashwave/plugin/windows/DashwaveWindow.kt | 31 +++++++++++++------ src/main/resources/META-INF/plugin.xml | 8 +++-- 6 files changed, 86 insertions(+), 15 deletions(-) create mode 100644 src/main/kotlin/com/dashwave/plugin/actions/RunDebugAction.kt diff --git a/build.gradle.kts b/build.gradle.kts index c854492..cb42c4f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,7 +5,7 @@ plugins { } group = "com.dashwave" -version = "3.0.0" +version = "3.1.0" repositories { mavenCentral() diff --git a/src/main/kotlin/com/dashwave/plugin/actions/RunDebugAction.kt b/src/main/kotlin/com/dashwave/plugin/actions/RunDebugAction.kt new file mode 100644 index 0000000..be89a7f --- /dev/null +++ b/src/main/kotlin/com/dashwave/plugin/actions/RunDebugAction.kt @@ -0,0 +1,22 @@ +package com.dashwave.plugin.actions + +import com.dashwave.plugin.PluginStartup +import com.intellij.openapi.actionSystem.AnAction +import com.intellij.openapi.actionSystem.AnActionEvent + +class RunDebugAction : AnAction(){ + override fun update(e: AnActionEvent) { + super.update(e) + val presentation = e.presentation + + // Enable or disable the action based on your condition + + presentation.isEnabled = PluginStartup.dwWindows?.get(e.project?.name)?.runEnabled?:false + presentation.text = "Run build on dashwave" + presentation.description = "Run build on dashwave" + } + + override fun actionPerformed(e: AnActionEvent) { + PluginStartup.dwWindows?.get(e.project?.name)?.runButton?.doClick() + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/dashwave/plugin/utils/DwBuild.kt b/src/main/kotlin/com/dashwave/plugin/utils/DwBuild.kt index d7ff161..338b8cc 100644 --- a/src/main/kotlin/com/dashwave/plugin/utils/DwBuild.kt +++ b/src/main/kotlin/com/dashwave/plugin/utils/DwBuild.kt @@ -15,6 +15,7 @@ class DwBuildConfig(clean:Boolean,debug:Boolean,openEmulator:Boolean,module:Stri var pwd:String? = pwd var module:String = module var variant:String = variant + var attachDebugger:Boolean = false } class DwBuild(config: DwBuildConfig, dwWindow: DashwaveWindow){ @@ -22,6 +23,7 @@ class DwBuild(config: DwBuildConfig, dwWindow: DashwaveWindow){ private val openEmulator:Boolean private var pwd:String? private var dwWindow:DashwaveWindow + private var attachDebugger:Boolean = false init { if(PluginMode == "workspace"){ cmd += " --workspace" @@ -40,9 +42,13 @@ class DwBuild(config: DwBuildConfig, dwWindow: DashwaveWindow){ if (config.variant != ""){ cmd += " --variant ${config.variant}" } + if (config.attachDebugger){ + cmd += " --attach-debugger" + } pwd = config.pwd openEmulator = config.openEmulator + attachDebugger = config.attachDebugger this.dwWindow = dwWindow } @@ -53,7 +59,7 @@ class DwBuild(config: DwBuildConfig, dwWindow: DashwaveWindow){ private fun execute(){ // DashwaveWindow.displayInfo() val buildCmd = DwCmds(cmd, pwd, true, this.dwWindow) - buildCmd.executeBuild(pwd, openEmulator) + buildCmd.executeBuild(pwd, openEmulator,attachDebugger) } fun killEmulator(){ diff --git a/src/main/kotlin/com/dashwave/plugin/utils/DwCmds.kt b/src/main/kotlin/com/dashwave/plugin/utils/DwCmds.kt index a527315..8bfccfd 100644 --- a/src/main/kotlin/com/dashwave/plugin/utils/DwCmds.kt +++ b/src/main/kotlin/com/dashwave/plugin/utils/DwCmds.kt @@ -58,8 +58,14 @@ class DwCmds(execCmd:String, wd:String?, log: Boolean, dwWindow: DashwaveWindow) this.p.exit() } + fun executeBg(){ + Thread{ + this.p.start(this.shouldLog) + }.start() + } - fun executeBuild(pwd:String?, openEmulator:Boolean){ + + fun executeBuild(pwd:String?, openEmulator:Boolean, attachDebugger:Boolean){ this.p.start(this.shouldLog) this.dwWindow.disableRunButton() this.dwWindow.enableCancelButton() @@ -91,7 +97,7 @@ class DwCmds(execCmd:String, wd:String?, log: Boolean, dwWindow: DashwaveWindow) // BrowserUtil.browse("https://console.dashwave.io/home?profile=true") }.show(dwWindow.p) - if(openEmulator){ + if(!attachDebugger && openEmulator){ val emulatorCmd = DwCmds("emulator", pwd, false, this.dwWindow) this.dwWindow.lastEmulatorProcess = emulatorCmd val ex = emulatorCmd.executeWithExitCode() @@ -131,6 +137,26 @@ class DwCmds(execCmd:String, wd:String?, log: Boolean, dwWindow: DashwaveWindow) } this.dwWindow.console.printHyperlink("Login here\n\n", hyperlink) } + 14 -> { + BalloonNotif( + "Build Successful", + "", + "Build completed, attaching debugger", + NotificationType.INFORMATION + ){ +// BrowserUtil.browse("https://console.dashwave.io/home?profile=true") + }.show(dwWindow.p) + println("attaching debugger") + if(attachDebugger){ + val debuggerCmd = DwCmds("get-debugger", pwd, true, this.dwWindow) + debuggerCmd.executeBg() + } + if(openEmulator){ + val emulatorCmd = DwCmds("emulator", pwd, false, this.dwWindow) + this.dwWindow.lastEmulatorProcess = emulatorCmd + val ex = emulatorCmd.executeWithExitCode() + } + } else -> { // add try again BalloonNotif( diff --git a/src/main/kotlin/com/dashwave/plugin/windows/DashwaveWindow.kt b/src/main/kotlin/com/dashwave/plugin/windows/DashwaveWindow.kt index 76139f9..6b75407 100644 --- a/src/main/kotlin/com/dashwave/plugin/windows/DashwaveWindow.kt +++ b/src/main/kotlin/com/dashwave/plugin/windows/DashwaveWindow.kt @@ -39,13 +39,14 @@ class DashwaveWindow(project: Project){ var currentBuild:DwCmds? = null lateinit var console: ConsoleView lateinit var runButton: JButton + lateinit var debugButton: JButton lateinit var cancelButton: JButton lateinit var p: Project var dwIcon: Icon = IconLoader.getIcon("/icons/dashwave13.svg", DashwaveWindow::class.java.classLoader) var loadIcon: Icon = AnimatedIcon.Default() var runEnabled = false private var cleanBuildCheckbox:JCheckBox = JCheckBox("Clean Build") - private var debugEnabledCheckBox: JCheckBox = JCheckBox("Enable Debug") + private var verboseEnabledCheckBox: JCheckBox = JCheckBox("Verbose") private var openEmulatorCheckbox:JCheckBox = JCheckBox("Open Emulator") var window:ToolWindow? = null private var buildOpts = CollapseMenu("Build opts") @@ -84,7 +85,7 @@ class DashwaveWindow(project: Project){ fun getBuildConfigs(p:Project):DwBuildConfig{ val cleanBuild = cleanBuildCheckbox.isSelected - val debugEnabled = debugEnabledCheckBox.isSelected + val debugEnabled = verboseEnabledCheckBox.isSelected val openEmulator = openEmulatorCheckbox.isSelected val module: String = selectedModule val variant: String = selectedVariant @@ -107,16 +108,18 @@ class DashwaveWindow(project: Project){ fun disableRunButton(){ runEnabled = false runButton.isEnabled = false + debugButton.isEnabled = false cleanBuildCheckbox.isEnabled = false - debugEnabledCheckBox.isEnabled = false + verboseEnabledCheckBox.isEnabled = false openEmulatorCheckbox.isEnabled = false } fun enableRunButton(){ runEnabled = true runButton.isEnabled = true + debugButton.isEnabled = true cleanBuildCheckbox.isEnabled = true - debugEnabledCheckBox.isEnabled = true + verboseEnabledCheckBox.isEnabled = true openEmulatorCheckbox.isEnabled = true } @@ -190,11 +193,11 @@ class DashwaveWindow(project: Project){ modulesList.isEnabled = true variantsList.isEnabled = true - modulesList.addItem(defaultModule) - variantsList.addItem(defaultVariant) + modulesList.addItem(defaultModule.lowercase()) + variantsList.addItem(defaultVariant.lowercase()ri ) modulesVariants.keys.toTypedArray().forEach { module -> - modulesList.addItem(module) + modulesList.addItem(module.lowercase()) } modulesList.addItemListener(ItemListener { @@ -206,7 +209,7 @@ class DashwaveWindow(project: Project){ selectedModule = modulesList.selectedItem as String variantsList.removeAllItems() modulesVariants[selectedModule]?.forEach { variant -> - variantsList.addItem(variant) + variantsList.addItem(variant.lowercase()) } } }) @@ -238,6 +241,15 @@ class DashwaveWindow(project: Project){ build.run(p) } + debugButton = JButton(AllIcons.Actions.StartDebugger) + debugButton.addActionListener { + FileDocumentManager.getInstance().saveAllDocuments(); + val configs = getBuildConfigs(this.p) + configs.attachDebugger = true + val build = DwBuild(configs, this) + build.run(p) + } + cancelButton = JButton(AllIcons.Actions.Cancel) cancelButton.addActionListener{ disableCancelButton() @@ -250,6 +262,7 @@ class DashwaveWindow(project: Project){ actionToolbar.add(runButton) + actionToolbar.add(debugButton) actionToolbar.add(cancelButton) disableCancelButton() disableRunButton() @@ -264,8 +277,8 @@ class DashwaveWindow(project: Project){ // val optionTitle = JLabel("Build Options") // optionToolbar.add(optionTitle) buildOpts.add(cleanBuildCheckbox) - buildOpts.add(debugEnabledCheckBox) buildOpts.add(openEmulatorCheckbox) + buildOpts.add(verboseEnabledCheckBox) optsGroup.add(buildOpts.getComponent()) diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 6a3f7f4..767b265 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -64,8 +64,8 @@ - com.intellij.modules.androidstudio - + + com.intellij.modules.all @@ -83,5 +83,9 @@ description="dw-build" icon="icons/dashwave16.svg"> + + + \ No newline at end of file From 4da50ac5a2e52a2ade5f97c3266afe2e83c554f8 Mon Sep 17 00:00:00 2001 From: Aviral Jain Date: Wed, 15 May 2024 18:34:06 +0530 Subject: [PATCH 11/15] add debugger functionality --- src/main/kotlin/com/dashwave/plugin/windows/DashwaveWindow.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/dashwave/plugin/windows/DashwaveWindow.kt b/src/main/kotlin/com/dashwave/plugin/windows/DashwaveWindow.kt index 6b75407..3334f73 100644 --- a/src/main/kotlin/com/dashwave/plugin/windows/DashwaveWindow.kt +++ b/src/main/kotlin/com/dashwave/plugin/windows/DashwaveWindow.kt @@ -194,7 +194,7 @@ class DashwaveWindow(project: Project){ variantsList.isEnabled = true modulesList.addItem(defaultModule.lowercase()) - variantsList.addItem(defaultVariant.lowercase()ri ) + variantsList.addItem(defaultVariant.lowercase()) modulesVariants.keys.toTypedArray().forEach { module -> modulesList.addItem(module.lowercase()) From 85ad6a019dc5216a534a1b226d7b0075e49ec99b Mon Sep 17 00:00:00 2001 From: Aviral Jain Date: Fri, 17 May 2024 16:04:27 +0530 Subject: [PATCH 12/15] change debugger icon --- .../dashwave/plugin/actions/RunDebugAction.kt | 6 +++--- src/main/resources/META-INF/plugin.xml | 2 +- src/main/resources/icons/debugger16.svg | 21 +++++++++++++++++++ 3 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 src/main/resources/icons/debugger16.svg diff --git a/src/main/kotlin/com/dashwave/plugin/actions/RunDebugAction.kt b/src/main/kotlin/com/dashwave/plugin/actions/RunDebugAction.kt index be89a7f..c92fa14 100644 --- a/src/main/kotlin/com/dashwave/plugin/actions/RunDebugAction.kt +++ b/src/main/kotlin/com/dashwave/plugin/actions/RunDebugAction.kt @@ -12,11 +12,11 @@ class RunDebugAction : AnAction(){ // Enable or disable the action based on your condition presentation.isEnabled = PluginStartup.dwWindows?.get(e.project?.name)?.runEnabled?:false - presentation.text = "Run build on dashwave" - presentation.description = "Run build on dashwave" + presentation.text = "Run debugger on dashwave" + presentation.description = "Run debugger on dashwave" } override fun actionPerformed(e: AnActionEvent) { - PluginStartup.dwWindows?.get(e.project?.name)?.runButton?.doClick() + PluginStartup.dwWindows?.get(e.project?.name)?.debugButton?.doClick() } } \ No newline at end of file diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 767b265..1c34112 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -84,7 +84,7 @@ + description="dw-run-debugger" icon="icons/debugger16.svg"> diff --git a/src/main/resources/icons/debugger16.svg b/src/main/resources/icons/debugger16.svg new file mode 100644 index 0000000..d760f37 --- /dev/null +++ b/src/main/resources/icons/debugger16.svg @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + From 83f61267425c874fd310de69391a6d1479e422f9 Mon Sep 17 00:00:00 2001 From: Aviral Jain Date: Thu, 11 Jul 2024 12:44:45 +0530 Subject: [PATCH 13/15] remove git deps --- src/main/kotlin/com/dashwave/plugin/PluginStartup.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/com/dashwave/plugin/PluginStartup.kt b/src/main/kotlin/com/dashwave/plugin/PluginStartup.kt index 28c1a35..2d4def6 100644 --- a/src/main/kotlin/com/dashwave/plugin/PluginStartup.kt +++ b/src/main/kotlin/com/dashwave/plugin/PluginStartup.kt @@ -149,7 +149,9 @@ fun checkProjectConnected(pwd:String?, dwWindow: DashwaveWindow){ val gitConfigFilepath = "$pwd/.git" if (!doesFileExist(gitConfigFilepath)){ if(PluginMode == "workspace"){ - dwWindow.displayError("❌ There is some issue in setting up your project (.git doesn't exist), please contact us at hello@dashwave.io") + listModulesAndVariants(pwd, dwWindow); + // workspaces from template don't need .git folder +// dwWindow.displayError("❌ There is some issue in setting up your project (.git doesn't exist), please contact us at hello@dashwave.io") return } dwWindow.displayOutput("❌ ${Messages.GIT_NOT_CONFIGURED}", ConsoleViewContentType.ERROR_OUTPUT) @@ -237,7 +239,7 @@ fun listModulesAndVariants(pwd:String?, dwWindow: DashwaveWindow) { val configsCmd = DwCmds("build configs", pwd, false, dwWindow) var cmdOutput = configsCmd.executeWithOutput() if(cmdOutput.first != 0){ - dwWindow.displayError("❌ Could not find modules and in variants\n"+cmdOutput.second) +// dwWindow.displayError("❌ Could not find modules and in variants\n"+cmdOutput.second) return } val jsonText = cmdOutput.second.trim() From 01479a4af9e300c9454e4785f098c7f6d73a6f0f Mon Sep 17 00:00:00 2001 From: Supratik Das <30755453+supra08@users.noreply.github.com> Date: Thu, 11 Jul 2024 15:36:13 +0530 Subject: [PATCH 14/15] [ES-1066] Implementation of worker to stop Gradle Sync (#6) * Add worker to attempt stopping gradle sync * Terminate only if plugin mode is workspace * Remove redundant terminate function * Add newline to messages --- .../com/dashwave/plugin/PluginStartup.kt | 60 ++++++++++++++++++- .../com/dashwave/plugin/messages/Messages.kt | 3 +- 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/com/dashwave/plugin/PluginStartup.kt b/src/main/kotlin/com/dashwave/plugin/PluginStartup.kt index 2d4def6..91a92b0 100644 --- a/src/main/kotlin/com/dashwave/plugin/PluginStartup.kt +++ b/src/main/kotlin/com/dashwave/plugin/PluginStartup.kt @@ -32,6 +32,10 @@ import com.intellij.openapi.application.PathManager import com.intellij.openapi.components.ServiceManager import io.ktor.util.* import java.awt.Font +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.delay +import kotlinx.coroutines.launch +import javax.swing.SwingUtilities var PluginMode:String = "" var PluginEnv:String = "" @@ -53,11 +57,65 @@ class PluginStartup: StartupActivity { dwWindow.show() dwWindows[project.name] = dwWindow checkDW(project, dwWindow) + +// start terminate gradle sync worker if pluginMode is 'workspace' + if(pluginMode == "workspace"){ + terminateGradleSync(project.basePath, dwWindow) + } PluginMode = pluginMode PluginEnv = pluginEnv } } +fun terminateGradleSync(pwd: String?, dwWindow: DashwaveWindow) { + println("Attempting to terminate Gradle sync...") + + GlobalScope.launch { + var attempt = 0 + val maxAttempts = 5 + val delayTime = 500L // 1 seconds delay + + while (attempt < maxAttempts) { + try { + val processBuilder = ProcessBuilder("./gradlew", "--stop") + if (pwd != null) { + processBuilder.directory(File(pwd)) + } + processBuilder.redirectErrorStream(true) + val process = processBuilder.start() + + val exitCode = process.waitFor() + println("Process exit code: $exitCode") + + SwingUtilities.invokeLater { + if (exitCode == 0) { + println("Rendering Dashwave window to hide sync") + dwWindow.show() +// break + } else { + dwWindow.displayInfo(Messages.GRADLE_SYNC_CANCELLATION_FAILED) + } + } + } catch (e: Exception) { + println("Exception occurred: ${e.message}") + dwWindow.displayInfo("Failed to start the process: ${e.message}") + } + + attempt++ + if (attempt < maxAttempts) { + println("Retrying in $delayTime milliseconds... (Attempt $attempt of $maxAttempts)") + delay(delayTime) + } else { + println("Max retry attempts reached.") + } + } + } + + SwingUtilities.invokeLater { + dwWindow.show() + } +} + fun checkDW(project: Project, dwWindow: DashwaveWindow) { val dwCmd = DwCmds("check-update", project.basePath, true, dwWindow) val exitCode = dwCmd.executeWithExitCode() @@ -175,7 +233,7 @@ fun checkProjectConnected(pwd:String?, dwWindow: DashwaveWindow){ val dd = ReadyForBuildDialog() dd.show() }else { - if(PluginMode == "worksapce"){ + if(PluginMode == "workspace"){ dwWindow.displayError("❌ There is some issue in setting up your project (dashwave.yml doesn't exist), please contact us at hello@dashwave.io") return } diff --git a/src/main/kotlin/com/dashwave/plugin/messages/Messages.kt b/src/main/kotlin/com/dashwave/plugin/messages/Messages.kt index 8e65dda..f7368ae 100644 --- a/src/main/kotlin/com/dashwave/plugin/messages/Messages.kt +++ b/src/main/kotlin/com/dashwave/plugin/messages/Messages.kt @@ -13,5 +13,6 @@ class Messages { val PROJECT_CONNECTION_SUCCESS = "✅ Project is successfully connected to dashwave\n\n" val PROJECT_CONNECTION_FAILED = "❌ Dashwave project creation failed\n" val GIT_NOT_CONFIGURED = "Your local codebase is not currently hosted on a Git repository (GitHub/GitLab). Please ensure your codebase is hosted on Git to use this plugin.\n" + val GRADLE_SYNC_CANCELLATION_FAILED = "Gradle sync needs to cancelled before proceeding. Please stop it manually.\n" } -} \ No newline at end of file +} From 438b629ecc429685db759f9670ca40e225cf1bb0 Mon Sep 17 00:00:00 2001 From: Aviral Jain Date: Thu, 11 Jul 2024 19:45:23 +0530 Subject: [PATCH 15/15] fix bug for empty variant and module value initially --- src/main/kotlin/com/dashwave/plugin/windows/DashwaveWindow.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/kotlin/com/dashwave/plugin/windows/DashwaveWindow.kt b/src/main/kotlin/com/dashwave/plugin/windows/DashwaveWindow.kt index 3334f73..510a127 100644 --- a/src/main/kotlin/com/dashwave/plugin/windows/DashwaveWindow.kt +++ b/src/main/kotlin/com/dashwave/plugin/windows/DashwaveWindow.kt @@ -204,6 +204,7 @@ class DashwaveWindow(project: Project){ if (it.stateChange == ItemEvent.SELECTED) { if(it.item.toString().contains("modules detected")){ selectedModule = "" + selectedVariant = "" return@ItemListener } selectedModule = modulesList.selectedItem as String @@ -218,6 +219,7 @@ class DashwaveWindow(project: Project){ if (it.stateChange == ItemEvent.SELECTED) { if(it.item.toString() == "variants detected"){ selectedVariant = "" + selectedModule = "" return@ItemListener } selectedVariant = variantsList.selectedItem as String