@@ -13,10 +13,7 @@ import com.intellij.openapi.components.service
13
13
import com.intellij.openapi.diagnostic.Logger
14
14
import com.intellij.openapi.extensions.PluginId
15
15
import com.intellij.openapi.fileTypes.FileTypeManager
16
- import com.intellij.openapi.module.ModuleManager
17
16
import com.intellij.openapi.project.Project
18
- import com.intellij.openapi.roots.ModuleRootManager
19
- import com.intellij.openapi.roots.libraries.Library
20
17
import com.intellij.openapi.util.IconLoader
21
18
import com.intellij.openapi.vfs.VfsUtil
22
19
import com.intellij.psi.PsiDirectory
@@ -30,7 +27,9 @@ import com.vaadin.plugin.copilot.service.CopilotServerService
30
27
import java.io.BufferedWriter
31
28
import java.io.File
32
29
import java.io.StringWriter
30
+ import java.nio.file.Files
33
31
import java.util.*
32
+ import kotlin.io.path.Path
34
33
35
34
36
35
class CopilotPluginUtil {
@@ -51,7 +50,7 @@ class CopilotPluginUtil {
51
50
52
51
private val COPILOT_ICON = IconLoader .getIcon(" /icons/copilot.svg" , CopilotPluginUtil ::class .java)
53
52
54
- private var isVaadinProject = false
53
+ private var isVaadinProject: Boolean? = null
55
54
56
55
private enum class HANDLERS (val command : String ) {
57
56
WRITE (" write" ),
@@ -63,28 +62,45 @@ class CopilotPluginUtil {
63
62
private val pluginVersion = PluginManagerCore .getPlugin(PluginId .getId(" com.vaadin.intellij-plugin" ))?.version
64
63
65
64
fun isVaadinProject (project : Project ): Boolean {
66
- // after first opening project, when libs are not analyzed yet this will return false
67
- if (! isVaadinProject) {
68
- for (module in ModuleManager .getInstance(project).modules) {
69
- ModuleRootManager .getInstance(module).orderEntries().forEachLibrary { library: Library ->
70
- if (library.name?.contains(VAADIN_LIB_PREFIX ) == true ) {
71
- isVaadinProject = true
72
- return @forEachLibrary true
73
- }
74
- true
75
- }
76
- }
65
+ if (project.basePath == null ) {
66
+ return false
67
+ }
68
+
69
+ if (isVaadinProject != null ) {
70
+ return isVaadinProject!!
77
71
}
78
- return isVaadinProject
72
+
73
+ val containsVaadinDeps = fun (file : String ): Boolean {
74
+ return Files .readString(Path (project.basePath!! , file)).contains(VAADIN_LIB_PREFIX )
75
+ }
76
+
77
+ // Maven projects
78
+ if (File (project.basePath, " pom.xml" ).exists()) {
79
+ isVaadinProject = containsVaadinDeps(" pom.xml" )
80
+ }
81
+
82
+ // Gradle projects
83
+ if (File (project.basePath, " build.gradle" ).exists()) {
84
+ isVaadinProject = containsVaadinDeps(" build.gradle" )
85
+ }
86
+
87
+ // Gradle Kotlin projects
88
+ if (File (project.basePath, " build.gradle.kts" ).exists()) {
89
+ isVaadinProject = containsVaadinDeps(" build.gradle.kts" )
90
+ }
91
+
92
+ return isVaadinProject ? : false
79
93
}
80
94
81
95
fun notify (content : String , type : NotificationType ) {
82
96
notify(content, type, null )
83
97
}
84
98
85
99
fun notify (content : String , type : NotificationType , project : Project ? ) {
86
- Notifications .Bus .notify(Notification (NOTIFICATION_GROUP , content, type)
87
- .setIcon(COPILOT_ICON ), project)
100
+ Notifications .Bus .notify(
101
+ Notification (NOTIFICATION_GROUP , content, type)
102
+ .setIcon(COPILOT_ICON ), project
103
+ )
88
104
}
89
105
90
106
fun isServerRunning (project : Project ): Boolean {
0 commit comments