Skip to content

Commit 5297e89

Browse files
committed
Warning popup when .gwt.xml files are edited that the project must be rebuild.
#27
1 parent 5578460 commit 5297e89

File tree

3 files changed

+127
-0
lines changed

3 files changed

+127
-0
lines changed
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
package com.gmail.blueboxware.libgdxplugin
2+
3+
import com.intellij.ide.highlighter.JavaClassFileType
4+
import com.intellij.notification.Notification
5+
import com.intellij.notification.NotificationDisplayType
6+
import com.intellij.notification.NotificationGroup
7+
import com.intellij.notification.NotificationType
8+
import com.intellij.openapi.application.ApplicationManager
9+
import com.intellij.openapi.project.Project
10+
import com.intellij.openapi.roots.ProjectFileIndex
11+
import com.intellij.openapi.vfs.VfsUtilCore
12+
import com.intellij.openapi.vfs.VirtualFile
13+
import com.intellij.openapi.vfs.newvfs.BulkFileListener
14+
import com.intellij.openapi.vfs.newvfs.events.VFileEvent
15+
16+
17+
/*
18+
* Copyright 2021 Blue Box Ware
19+
*
20+
* Licensed under the Apache License, Version 2.0 (the "License");
21+
* you may not use this file except in compliance with the License.
22+
* You may obtain a copy of the License at
23+
*
24+
* http://www.apache.org/licenses/LICENSE-2.0
25+
*
26+
* Unless required by applicable law or agreed to in writing, software
27+
* distributed under the License is distributed on an "AS IS" BASIS,
28+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29+
* See the License for the specific language governing permissions and
30+
* limitations under the License.
31+
*/
32+
class GwtOutdatedListener(val project: Project):
33+
BulkFileListener {
34+
35+
private var balloon: Notification? = null
36+
37+
private var gwtFile: VirtualFile? = null
38+
39+
override fun after(events: MutableList<out VFileEvent>) {
40+
41+
var doCheck = false
42+
43+
for (event in events) {
44+
event.file?.let { file ->
45+
if (file.name.endsWith(".gwt.xml")) {
46+
VfsUtilCore.findContainingDirectory(file, "html")?.let { html ->
47+
if (ProjectFileIndex.getInstance(project).isInContent(html)) {
48+
if (file.timeStamp >= gwtFile?.timeStamp ?: 0) {
49+
gwtFile = file
50+
doCheck = true
51+
}
52+
}
53+
}
54+
}
55+
}
56+
}
57+
58+
if (doCheck || balloon?.isExpired == false) {
59+
ApplicationManager.getApplication().invokeLater {
60+
gwtFile?.let { gwtFile ->
61+
VfsUtilCore.findContainingDirectory(gwtFile, "html")?.let { html ->
62+
var outDated = false
63+
html.findChild("build")?.let { buildDir ->
64+
VfsUtilCore.processFilesRecursively(buildDir) { file ->
65+
if (file.fileType == JavaClassFileType.INSTANCE) {
66+
if (file.timeStamp < gwtFile.timeStamp) {
67+
outDated = true
68+
return@processFilesRecursively false
69+
}
70+
}
71+
true
72+
}
73+
}
74+
if (!outDated) {
75+
html.findChild("war")?.let { warDir ->
76+
VfsUtilCore.processFilesRecursively(warDir) { file ->
77+
if (!file.isDirectory && file.timeStamp < gwtFile.timeStamp) {
78+
outDated = true
79+
return@processFilesRecursively false
80+
}
81+
true
82+
}
83+
}
84+
}
85+
if (balloon?.isExpired == false) {
86+
if (!outDated) {
87+
balloon?.hideBalloon()
88+
balloon = null
89+
}
90+
} else {
91+
if (outDated) {
92+
balloon = GROUP.createNotification(
93+
message("gwt.build.outdated.title"),
94+
message("gwt.build.outdated.body"),
95+
NotificationType.WARNING)
96+
balloon?.notify(project)
97+
}
98+
}
99+
return@invokeLater
100+
}
101+
}
102+
103+
balloon?.hideBalloon()
104+
}
105+
106+
}
107+
108+
}
109+
110+
companion object {
111+
val GROUP = NotificationGroup(
112+
"Outdated GWT",
113+
NotificationDisplayType.STICKY_BALLOON,
114+
false
115+
)
116+
}
117+
118+
}
119+

src/main/resources/META-INF/plugin.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,11 @@
303303
topic="com.intellij.openapi.project.ProjectManagerListener"/>
304304
</applicationListeners>
305305

306+
<projectListeners>
307+
<listener class="com.gmail.blueboxware.libgdxplugin.GwtOutdatedListener"
308+
topic="com.intellij.openapi.vfs.newvfs.BulkFileListener" />
309+
</projectListeners>
310+
306311
<extensions defaultExtensionNs="com.intellij">
307312

308313
<postStartupActivity implementation="com.gmail.blueboxware.libgdxplugin.LibGDXStartupActivity"/>

src/main/resources/libgdxplugin.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16+
gwt.build.outdated.title=GWT Outdated
17+
gwt.build.outdated.body=*.gwt.xml files have been changed. The module needs a full rebuild.
18+
1619
suppress.object=Suppress for object
1720
suppress.property= Suppress for property
1821
suppress.string=Suppress for string

0 commit comments

Comments
 (0)