Skip to content

Commit 00a908b

Browse files
plumpygoogle-java-format Team
authored andcommitted
Remove uses of deprecated plugin APIs.
PiperOrigin-RevId: 815077151
1 parent d2c676e commit 00a908b

File tree

5 files changed

+91
-72
lines changed

5 files changed

+91
-72
lines changed

idea_plugin/build.gradle.kts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717
import org.jetbrains.intellij.platform.gradle.TestFrameworkType
1818

1919
// https://github.com/JetBrains/intellij-platform-gradle-plugin/releases
20-
plugins { id("org.jetbrains.intellij.platform") version "2.9.0" }
20+
plugins {
21+
id("org.jetbrains.intellij.platform") version "2.9.0"
22+
kotlin("jvm") version "2.2.0"
23+
}
2124

2225
repositories {
2326
mavenCentral()
@@ -27,16 +30,19 @@ repositories {
2730

2831
// https://github.com/google/google-java-format/releases
2932
val googleJavaFormatVersion = "1.29.0"
33+
val pluginPatchVersion = "1"
3034

3135
java {
3236
sourceCompatibility = JavaVersion.VERSION_21
3337
targetCompatibility = JavaVersion.VERSION_21
3438
}
3539

40+
kotlin { jvmToolchain(21) }
41+
3642
intellijPlatform {
3743
pluginConfiguration {
3844
name = "google-java-format"
39-
version = "${googleJavaFormatVersion}.0"
45+
version = "${googleJavaFormatVersion}.${pluginPatchVersion}"
4046
ideaVersion {
4147
sinceBuild = "243"
4248
untilBuild = provider { null }
@@ -80,4 +86,5 @@ dependencies {
8086
testImplementation("junit:junit:4.13.2")
8187
// https://mvnrepository.com/artifact/com.google.truth/truth
8288
testImplementation("com.google.truth:truth:1.4.5")
89+
implementation(kotlin("stdlib-jdk8"))
8390
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright 2025 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.googlejavaformat.intellij
18+
19+
import com.intellij.notification.Notification
20+
import com.intellij.notification.NotificationAction
21+
import com.intellij.notification.NotificationGroupManager
22+
import com.intellij.notification.NotificationType
23+
import com.intellij.openapi.actionSystem.AnActionEvent
24+
import com.intellij.openapi.project.Project
25+
import com.intellij.openapi.startup.ProjectActivity
26+
27+
private class InitialConfigurationNotifier : ProjectActivity {
28+
29+
companion object {
30+
const val NOTIFICATION_TITLE: String = "Enable google-java-format"
31+
}
32+
33+
override suspend fun execute(project: Project) {
34+
val settings = GoogleJavaFormatSettings.getInstance(project)
35+
36+
if (settings.isUninitialized) {
37+
settings.isEnabled = false
38+
displayNewUserNotification(project, settings)
39+
} else if (settings.isEnabled) {
40+
JreConfigurationChecker.checkJreConfiguration(project)
41+
}
42+
}
43+
44+
private fun displayNewUserNotification(project: Project?, settings: GoogleJavaFormatSettings) {
45+
val groupManager = NotificationGroupManager.getInstance()
46+
val group = groupManager.getNotificationGroup(NOTIFICATION_TITLE)
47+
val notification =
48+
Notification(
49+
group.displayId,
50+
NOTIFICATION_TITLE,
51+
"The google-java-format plugin is disabled by default.",
52+
NotificationType.INFORMATION
53+
)
54+
notification.addAction(
55+
object : NotificationAction("Enable for this project") {
56+
override fun actionPerformed(
57+
anActionEvent: AnActionEvent, notification: Notification
58+
) {
59+
settings.isEnabled = true
60+
notification.expire()
61+
}
62+
})
63+
notification.notify(project)
64+
}
65+
}

idea_plugin/src/main/java/com/google/googlejavaformat/intellij/InitialConfigurationStartupActivity.java

Lines changed: 0 additions & 60 deletions
This file was deleted.

idea_plugin/src/main/java/com/google/googlejavaformat/intellij/JreConfigurationChecker.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,15 @@
1717
package com.google.googlejavaformat.intellij;
1818

1919
import com.google.common.base.Suppliers;
20-
import com.intellij.ide.ui.IdeUiService;
20+
import com.intellij.ide.BrowserUtil;
2121
import com.intellij.notification.Notification;
22+
import com.intellij.notification.NotificationAction;
2223
import com.intellij.notification.NotificationType;
24+
import com.intellij.openapi.actionSystem.AnActionEvent;
2325
import com.intellij.openapi.diagnostic.Logger;
2426
import com.intellij.openapi.project.Project;
2527
import java.util.function.Supplier;
28+
import org.jetbrains.annotations.NotNull;
2629

2730
class JreConfigurationChecker {
2831

@@ -89,15 +92,17 @@ private void displayConfigurationErrorNotification() {
8992
new Notification(
9093
"Configure JRE for google-java-format",
9194
"Configure the JRE for google-java-format",
92-
"The google-java-format plugin needs additional configuration before it can be used. "
93-
+ "<a href=\"instructions\">Follow the instructions here</a>.",
95+
"The google-java-format plugin needs additional configuration before it can be used.",
9496
NotificationType.INFORMATION);
95-
notification.setListener(
96-
(n, e) -> {
97-
IdeUiService.getInstance()
98-
.browse(
99-
"https://github.com/google/google-java-format/blob/master/README.md#intellij-jre-config");
100-
n.expire();
97+
notification.addAction(
98+
new NotificationAction("Follow the instructions here") {
99+
@Override
100+
public void actionPerformed(
101+
@NotNull AnActionEvent anActionEvent, @NotNull Notification notification) {
102+
BrowserUtil.browse(
103+
"https://github.com/google/google-java-format/blob/master/README.md#intellij-jre-config");
104+
notification.expire();
105+
}
101106
});
102107
notification.notify(project);
103108
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
]]></description>
3636
<change-notes><![CDATA[
3737
<dl>
38+
<dt>1.29.0.1</dt>
39+
<dd>Remove uses of deprecated IntelliJ plugin APIs.</dd>
3840
<dt>1.29.0.0</dt>
3941
<dd>Updated to use google-java-format 1.29.0.</dd>
4042
<dd>Minimum supported IntelliJ version is now 2024.3.</dd>
@@ -113,7 +115,7 @@
113115
<extensions defaultExtensionNs="com.intellij">
114116
<formattingService
115117
implementation="com.google.googlejavaformat.intellij.GoogleJavaFormatFormattingService"/>
116-
<postStartupActivity implementation="com.google.googlejavaformat.intellij.InitialConfigurationStartupActivity"/>
118+
<postStartupActivity implementation="com.google.googlejavaformat.intellij.InitialConfigurationNotifier"/>
117119
<projectConfigurable
118120
instance="com.google.googlejavaformat.intellij.GoogleJavaFormatConfigurable"
119121
id="google-java-format.settings"

0 commit comments

Comments
 (0)