Skip to content

Commit bdbff77

Browse files
committed
migrate to the IntelliJ platform gradle plugin 2.x, solve deprecated method warning, fix #23, version 2.8
1 parent d7628b2 commit bdbff77

File tree

6 files changed

+71
-29
lines changed

6 files changed

+71
-29
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77
out
88
.gradle
99
build
10-
project/
10+
project/
11+
.intellijPlatform

build.gradle.kts

+26-9
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,44 @@
11
plugins {
22
id("java")
3-
id("org.jetbrains.intellij") version "1.13.1"
3+
id("org.jetbrains.intellij.platform") version "2.0.1"
44
}
55

66
group = "net.labymod.intellij"
77

88
repositories {
99
mavenCentral()
10+
11+
intellijPlatform {
12+
releases()
13+
marketplace()
14+
defaultRepositories()
15+
}
1016
}
1117

1218
// Configure Gradle IntelliJ Plugin
13-
intellij {
14-
pluginName.set("Single Hotswap")
15-
version.set("2023.1")
16-
type.set("IC") // Target IDE Platform
17-
plugins.set(listOf("Kotlin", "Groovy", "java", "properties"))
18-
19-
// Compatibility with future IDE versions
20-
updateSinceUntilBuild.set(false)
19+
intellijPlatform {
20+
pluginConfiguration {
21+
name = "Single Hotswap"
22+
23+
ideaVersion {
24+
sinceBuild = "203"
25+
untilBuild = provider { null }
26+
}
27+
}
2128
}
2229

2330
dependencies {
31+
intellijPlatform {
32+
intellijIdeaCommunity("2024.2.0.2")
33+
34+
// https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html#bundled-and-other-plugins
35+
bundledPlugin("com.intellij.java")
36+
bundledPlugin("org.jetbrains.kotlin")
37+
bundledPlugin("org.intellij.groovy")
38+
bundledPlugin("com.intellij.properties")
2439

40+
instrumentationTools()
41+
}
2542
}
2643

2744
tasks {
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

src/main/java/icons/ResourceIcon.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class ResourceIcon implements Icon {
1111
private final Icon baseIcon;
1212

1313
public ResourceIcon(String path) {
14-
this.baseIcon = IconManager.getInstance().getIcon(path, ResourceIcon.class);
14+
this.baseIcon = IconManager.getInstance().getIcon(path, ResourceIcon.class.getClassLoader());
1515
}
1616

1717
@Override

src/main/java/net/labymod/intellij/singlehotswap/hotswap/FileType.java

+36-16
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ public enum FileType {
2626
"org.jetbrains.kotlin"
2727
);
2828

29+
private final String className;
30+
31+
private final String requiredPluginId;
32+
2933
/**
3034
* Hotswap implementation
3135
*/
@@ -38,40 +42,56 @@ public enum FileType {
3842
* @param requiredPluginId The required plugin for this hotswap type. This can be null to skip the requirement.
3943
*/
4044
FileType(String className, String requiredPluginId) {
41-
if (className == null) {
42-
return;
45+
this.className = className;
46+
this.requiredPluginId = requiredPluginId;
47+
this.context = null;
48+
}
49+
50+
/**
51+
* Get the context implementation for the current type
52+
*
53+
* @return Context implementation
54+
*/
55+
public Context context() {
56+
if (this.context == null) {
57+
// Create context instance if not available
58+
this.context = this.createContext();
59+
}
60+
return this.context;
61+
}
62+
63+
/**
64+
* Create context instance
65+
*
66+
* @return Context instance or null if not available
67+
*/
68+
private Context createContext() {
69+
if (this.className == null) {
70+
return null;
4371
}
4472

4573
try {
4674
// Check if plugin is required
47-
if (requiredPluginId != null) {
75+
if (this.requiredPluginId != null) {
4876

4977
// Find plugin by plugin id
50-
@Nullable IdeaPluginDescriptor plugin = PluginManager.getInstance().findEnabledPlugin(PluginId.getId(requiredPluginId));
78+
// Note: Access plugin manager here because of #23
79+
@Nullable IdeaPluginDescriptor plugin = PluginManager.getInstance().findEnabledPlugin(PluginId.getId(this.requiredPluginId));
5180

5281
// Skip implementation if not plugin is not available
5382
if (plugin == null || !plugin.isEnabled()) {
54-
return;
83+
return null;
5584
}
5685
}
5786

5887
// Load implementation
59-
this.context = (Context) Class.forName(className).getConstructor().newInstance();
88+
return (Context) Class.forName(this.className).getConstructor().newInstance();
6089
} catch (Exception e) {
6190
e.printStackTrace();
91+
return null;
6292
}
6393
}
6494

65-
66-
/**
67-
* Get the context implementation for the current type
68-
*
69-
* @return Context implementation
70-
*/
71-
public Context context() {
72-
return this.context;
73-
}
74-
7595
/**
7696
* Find context implementation using the PSI file
7797
*

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<idea-plugin>
22
<id>net.labymod.intellij.singlehotswap</id>
33
<name>Single Hotswap</name>
4-
<version>2.7</version>
4+
<version>2.8</version>
55
<vendor email="[email protected]" url="https://www.labymod.net">LabyMedia</vendor>
66

77
<idea-version since-build="203.000"/>
@@ -53,6 +53,10 @@
5353

5454
<change-notes>
5555
<![CDATA[
56+
v2.8 (2024-08-29):
57+
<ul>
58+
<li>Added support for newer IntelliJ versions</li>
59+
</ul>
5660
v2.7 (2024-06-17):
5761
<ul>
5862
<li>Fixed an issue where the breakpoints couldn't find the local variables after a hotswap</li>

0 commit comments

Comments
 (0)