-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Detect Vaadin projects if dependencies are updated (#97)
* Use ModuleRootListener to detect Vaadin project * Use single Vaadin detection
- Loading branch information
1 parent
6fe7726
commit 13df6d9
Showing
7 changed files
with
126 additions
and
53 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
src/main/kotlin/com/vaadin/plugin/VaadinProjectDetector.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.vaadin.plugin | ||
|
||
import com.intellij.openapi.diagnostic.Logger | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.roots.ModuleRootEvent | ||
import com.intellij.openapi.roots.ModuleRootListener | ||
import com.intellij.openapi.startup.ProjectActivity | ||
import com.vaadin.plugin.listeners.VaadinProjectListener | ||
import com.vaadin.plugin.utils.VaadinProjectUtil.Companion.isVaadinProject | ||
|
||
class VaadinProjectDetector : ModuleRootListener, ProjectActivity { | ||
|
||
private val LOG: Logger = Logger.getInstance(VaadinProjectDetector::class.java) | ||
|
||
override fun rootsChanged(event: ModuleRootEvent) { | ||
if (isVaadinProject(event.project)) { | ||
doNotifyAboutVaadinProject(event.project) | ||
LOG.info("Vaadin detected in dependencies of " + event.project.name) | ||
} | ||
} | ||
|
||
override suspend fun execute(project: Project) { | ||
if (isVaadinProject(project)) { | ||
doNotifyAboutVaadinProject(project) | ||
LOG.info("Vaadin detected during startup of " + project.name) | ||
} | ||
} | ||
|
||
private fun doNotifyAboutVaadinProject(project: Project) { | ||
val publisher: VaadinProjectListener = project.messageBus.syncPublisher(VaadinProjectListener.TOPIC) | ||
publisher.vaadinProjectDetected(project) | ||
} | ||
} |
35 changes: 0 additions & 35 deletions
35
src/main/kotlin/com/vaadin/plugin/copilot/activity/CopilotPostStartupProjectActivity.kt
This file was deleted.
Oops, something went wrong.
40 changes: 40 additions & 0 deletions
40
src/main/kotlin/com/vaadin/plugin/copilot/listeners/CopilotVaadinProjectListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.vaadin.plugin.copilot.listeners | ||
|
||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.project.ProjectManager | ||
import com.intellij.openapi.project.ProjectManagerListener | ||
import com.vaadin.plugin.copilot.CopilotPluginUtil | ||
import com.vaadin.plugin.listeners.VaadinProjectListener | ||
|
||
class CopilotVaadinProjectListener : VaadinProjectListener { | ||
|
||
private var triggered = false | ||
|
||
override fun vaadinProjectDetected(project: Project) { | ||
if (!triggered) { | ||
triggered = true | ||
createDotFile(project) | ||
removeDotFileOnExit(project) | ||
} | ||
} | ||
|
||
private fun createDotFile(project: Project) { | ||
val dotFileDirectory = CopilotPluginUtil.getDotFileDirectory(project) | ||
if (dotFileDirectory == null) { | ||
CopilotPluginUtil.createIdeaDirectoryIfMissing(project) | ||
} | ||
CopilotPluginUtil.saveDotFile(project) | ||
} | ||
|
||
private fun removeDotFileOnExit(project: Project) { | ||
ProjectManager.getInstance() | ||
.addProjectManagerListener( | ||
project, | ||
object : ProjectManagerListener { | ||
override fun projectClosing(project: Project) { | ||
CopilotPluginUtil.removeDotFile(project) | ||
} | ||
}, | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/main/kotlin/com/vaadin/plugin/listeners/VaadinProjectListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.vaadin.plugin.listeners | ||
|
||
import com.intellij.openapi.project.Project | ||
import com.intellij.util.messages.Topic | ||
import com.intellij.util.messages.Topic.ProjectLevel | ||
import java.util.* | ||
|
||
interface VaadinProjectListener : EventListener { | ||
|
||
companion object { | ||
@ProjectLevel | ||
val TOPIC: Topic<VaadinProjectListener> = | ||
Topic.create("Vaadin project detected", VaadinProjectListener::class.java) | ||
} | ||
|
||
fun vaadinProjectDetected(project: Project) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters