Skip to content

Commit

Permalink
feat: Add support for usage and config (#9)
Browse files Browse the repository at this point in the history
- **feat: add usage and config file support**
- **enhance: bring back the settings**
  • Loading branch information
Owen authored Jul 2, 2024
1 parent 43b3f04 commit deb133e
Show file tree
Hide file tree
Showing 25 changed files with 755 additions and 633 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

## [Unreleased]

## [1.1.0] - 2024-07-02
### Added
- Support for config files
- Support for usage files

## [1.0.2] - 2024-07-01
### Fixed
- Update linux binaries path
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
pluginGroup = io.infracost.plugins
pluginName = Infracost
pluginRepositoryUrl = https://github.com/infracost/jetbrains-infracost
pluginVersion = 1.0.2
pluginVersion = 1.1.0

pluginSinceBuild = 232
pluginUntilBuild = 242.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,37 @@ import javax.swing.SwingUtilities

/** RunInfracostAction executes infracost then calls update results */
class CheckAuthAction : AnAction() {
private var project: Project? = null
private var project: Project? = null

override fun actionPerformed(e: AnActionEvent) {
this.project = e.project
override fun actionPerformed(e: AnActionEvent) {
this.project = e.project

if (this.project == null) {
return
}
if (this.project == null) {
return
}

checkAuth(this.project!!)
}
checkAuth(this.project!!)
}

companion object {
var isAuthenticated: Boolean = false
companion object {
var isAuthenticated: Boolean = false

fun checkAuth(project: Project) {
val runner =
InfracostCheckAuthRunTask(project) { apiKey: String ->
// redraw the explorer with the updated content
val toolWindow = ToolWindowManager.getInstance(project).getToolWindow(TOOL_WINDOW_ID)
val content = toolWindow!!.contentManager.getContent(0)
(content!!.component as InfracostWindow).apply {
isAuthenticated = apiKey.isNotEmpty() && apiKey.startsWith("ico")
updatePanel(isAuthenticated)
fun checkAuth(project: Project) {
val runner =
InfracostCheckAuthRunTask(project) { apiKey: String ->
// redraw the explorer with the updated content
val toolWindow = ToolWindowManager.getInstance(project).getToolWindow(TOOL_WINDOW_ID)
val content = toolWindow!!.contentManager.getContent(0)
(content!!.component as InfracostWindow).apply {
isAuthenticated = apiKey.isNotEmpty() && apiKey.startsWith("ico")
updatePanel(isAuthenticated)
}
}
if (SwingUtilities.isEventDispatchThread()) {
ProgressManager.getInstance().run(runner)
} else {
ApplicationManager.getApplication().invokeLater(runner)
}
}
if (SwingUtilities.isEventDispatchThread()) {
ProgressManager.getInstance().run(runner)
} else {
ApplicationManager.getApplication().invokeLater(runner)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ import io.infracost.plugins.infracost.ui.TOOL_WINDOW_ID

/** ClearResultsAction removes the tree and findings */
class ClearResultsAction : AnAction() {
private var project: Project? = null
private var project: Project? = null

override fun actionPerformed(e: AnActionEvent) {
this.project = e.project
override fun actionPerformed(e: AnActionEvent) {
this.project = e.project

if (project == null) {
return
}
val toolWindow = ToolWindowManager.getInstance(project!!).getToolWindow(TOOL_WINDOW_ID)
val content = toolWindow!!.contentManager.getContent(0)
val infracostWindow = content!!.component as InfracostWindow
infracostWindow.clearModel()
if (project == null) {
return
}
val toolWindow = ToolWindowManager.getInstance(project!!).getToolWindow(TOOL_WINDOW_ID)
val content = toolWindow!!.contentManager.getContent(0)
val infracostWindow = content!!.component as InfracostWindow
infracostWindow.clearModel()

infracostWindow.redraw()
}
infracostWindow.redraw()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,32 @@ import java.io.IOException
*/
object ResultProcessor {

var model: InfracostModel? = null
private set
var model: InfracostModel? = null
private set

fun updateResults(project: Project?, resultFile: File?) {
try {
val resultsMapper = ObjectMapper()
resultsMapper.disable(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES)
resultsMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
val results = resultsMapper.readValue(resultFile, Results::class.java)
this.model = InfracostModel(results)
} catch (e: IOException) {
InfracostNotificationGroup.notifyError(
project, String.format("Failed to deserialize the results file. %s", e.localizedMessage))
return
} finally {
resultFile?.deleteOnExit()
}
fun updateResults(project: Project?, resultFile: File?) {
try {
val resultsMapper = ObjectMapper()
resultsMapper.disable(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES)
resultsMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
val results = resultsMapper.readValue(resultFile, Results::class.java)
this.model = InfracostModel(results, project?.basePath!!)
} catch (e: IOException) {
InfracostNotificationGroup.notifyError(
project, String.format("Failed to deserialize the results file. %s", e.localizedMessage)
)
return
} finally {
resultFile?.deleteOnExit()
}

// redraw the explorer with the updated content
val toolWindow = ToolWindowManager.getInstance(project!!).getToolWindow(TOOL_WINDOW_ID)
val content = toolWindow!!.contentManager.getContent(0)
(content!!.component as InfracostWindow).apply {
refreshModel()
redraw()
refresh(project)
// redraw the explorer with the updated content
val toolWindow = ToolWindowManager.getInstance(project!!).getToolWindow(TOOL_WINDOW_ID)
val content = toolWindow!!.contentManager.getContent(0)
(content!!.component as InfracostWindow).apply {
refreshModel()
redraw()
refresh(project)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,34 @@ import javax.swing.SwingUtilities

/** RunInfracostAction executes infracost then calls update results */
class RunAuthAction : AnAction() {
private var project: Project? = null
private var project: Project? = null

override fun actionPerformed(e: AnActionEvent) {
this.project = e.project
override fun actionPerformed(e: AnActionEvent) {
this.project = e.project

if (this.project == null) {
return
}
if (this.project == null) {
return
}

runAuth(this.project!!)
}
runAuth(this.project!!)
}

companion object {
fun runAuth(project: Project) {
val runner =
InfracostAuthRunTask(project) { isAuthenticated ->
run {
// redraw the explorer with the updated content
val toolWindow = ToolWindowManager.getInstance(project).getToolWindow(TOOL_WINDOW_ID)
val content = toolWindow!!.contentManager.getContent(0)
(content!!.component as InfracostWindow).apply { updatePanel(isAuthenticated) }
companion object {
fun runAuth(project: Project) {
val runner =
InfracostAuthRunTask(project) { isAuthenticated ->
run {
// redraw the explorer with the updated content
val toolWindow = ToolWindowManager.getInstance(project).getToolWindow(TOOL_WINDOW_ID)
val content = toolWindow!!.contentManager.getContent(0)
(content!!.component as InfracostWindow).apply { updatePanel(isAuthenticated) }
}
}
if (SwingUtilities.isEventDispatchThread()) {
ProgressManager.getInstance().run(runner)
} else {
ApplicationManager.getApplication().invokeLater(runner)
}
}
if (SwingUtilities.isEventDispatchThread()) {
ProgressManager.getInstance().run(runner)
} else {
ApplicationManager.getApplication().invokeLater(runner)
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.infracost.plugins.infracost.actions

import com.intellij.openapi.actionSystem.ActionUpdateThread
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.application.ApplicationManager
Expand All @@ -13,42 +14,46 @@ import javax.swing.SwingUtilities

/** RunInfracostAction executes infracost then calls update results */
class RunInfracostAction : AnAction() {
private var project: Project? = null
private var project: Project? = null

override fun update(e: AnActionEvent) {
super.update(e)
e.presentation.isEnabled = CheckAuthAction.isAuthenticated
}
override fun getActionUpdateThread(): ActionUpdateThread {
return ActionUpdateThread.BGT
}

override fun update(e: AnActionEvent) {
super.update(e)
e.presentation.isEnabled = CheckAuthAction.isAuthenticated
}

override fun actionPerformed(e: AnActionEvent) {
this.project = e.project

override fun actionPerformed(e: AnActionEvent) {
this.project = e.project
if (this.project == null) {
return
}

if (this.project == null) {
return
runInfracost(this.project!!)
}

runInfracost(this.project!!)
}

companion object {

fun runInfracost(project: Project) {
var resultFile: File? = null
try {
resultFile = File.createTempFile("infracost", ".json")
} catch (ex: IOException) {
InfracostNotificationGroup.notifyError(project, ex.localizedMessage)
}

val runner =
InfracostBackgroundRunTask(project, resultFile!!) { proj: Project, project: File? ->
ResultProcessor.updateResults(proj, project)
}
if (SwingUtilities.isEventDispatchThread()) {
ProgressManager.getInstance().run(runner)
} else {
ApplicationManager.getApplication().invokeLater(runner)
}
companion object {

fun runInfracost(project: Project) {
var resultFile: File? = null
try {
resultFile = File.createTempFile("infracost", ".json")
} catch (ex: IOException) {
InfracostNotificationGroup.notifyError(project, ex.localizedMessage)
}

val runner =
InfracostBackgroundRunTask(project, resultFile!!) { proj: Project, f: File? ->
ResultProcessor.updateResults(proj, f)
}
if (SwingUtilities.isEventDispatchThread()) {
ProgressManager.getInstance().run(runner)
} else {
ApplicationManager.getApplication().invokeLater(runner)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ const val INFRACOST_SETTINGS_ID = "Infracost: Settings"

class ShowInfracostSettingsAction : AnAction() {

override fun actionPerformed(e: AnActionEvent) {
val project = e.project ?: return
override fun actionPerformed(e: AnActionEvent) {
val project = e.project ?: return

ShowSettingsUtil.getInstance().showSettingsDialog(project, INFRACOST_SETTINGS_ID)
}
ShowSettingsUtil.getInstance().showSettingsDialog(project, INFRACOST_SETTINGS_ID)
}
}
Loading

0 comments on commit deb133e

Please sign in to comment.