Skip to content

Commit

Permalink
migrate to the IntelliJ platform gradle plugin 2.x, solve deprecated …
Browse files Browse the repository at this point in the history
…method warning, fix #23, version 2.8
  • Loading branch information
LabyStudio committed Aug 29, 2024
1 parent d7628b2 commit bdbff77
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 29 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
out
.gradle
build
project/
project/
.intellijPlatform
35 changes: 26 additions & 9 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,27 +1,44 @@
plugins {
id("java")
id("org.jetbrains.intellij") version "1.13.1"
id("org.jetbrains.intellij.platform") version "2.0.1"
}

group = "net.labymod.intellij"

repositories {
mavenCentral()

intellijPlatform {
releases()
marketplace()
defaultRepositories()
}
}

// Configure Gradle IntelliJ Plugin
intellij {
pluginName.set("Single Hotswap")
version.set("2023.1")
type.set("IC") // Target IDE Platform
plugins.set(listOf("Kotlin", "Groovy", "java", "properties"))

// Compatibility with future IDE versions
updateSinceUntilBuild.set(false)
intellijPlatform {
pluginConfiguration {
name = "Single Hotswap"

ideaVersion {
sinceBuild = "203"
untilBuild = provider { null }
}
}
}

dependencies {
intellijPlatform {
intellijIdeaCommunity("2024.2.0.2")

// https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html#bundled-and-other-plugins
bundledPlugin("com.intellij.java")
bundledPlugin("org.jetbrains.kotlin")
bundledPlugin("org.intellij.groovy")
bundledPlugin("com.intellij.properties")

instrumentationTools()
}
}

tasks {
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion src/main/java/icons/ResourceIcon.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class ResourceIcon implements Icon {
private final Icon baseIcon;

public ResourceIcon(String path) {
this.baseIcon = IconManager.getInstance().getIcon(path, ResourceIcon.class);
this.baseIcon = IconManager.getInstance().getIcon(path, ResourceIcon.class.getClassLoader());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ public enum FileType {
"org.jetbrains.kotlin"
);

private final String className;

private final String requiredPluginId;

/**
* Hotswap implementation
*/
Expand All @@ -38,40 +42,56 @@ public enum FileType {
* @param requiredPluginId The required plugin for this hotswap type. This can be null to skip the requirement.
*/
FileType(String className, String requiredPluginId) {
if (className == null) {
return;
this.className = className;
this.requiredPluginId = requiredPluginId;
this.context = null;
}

/**
* Get the context implementation for the current type
*
* @return Context implementation
*/
public Context context() {
if (this.context == null) {
// Create context instance if not available
this.context = this.createContext();
}
return this.context;
}

/**
* Create context instance
*
* @return Context instance or null if not available
*/
private Context createContext() {
if (this.className == null) {
return null;
}

try {
// Check if plugin is required
if (requiredPluginId != null) {
if (this.requiredPluginId != null) {

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

// Skip implementation if not plugin is not available
if (plugin == null || !plugin.isEnabled()) {
return;
return null;
}
}

// Load implementation
this.context = (Context) Class.forName(className).getConstructor().newInstance();
return (Context) Class.forName(this.className).getConstructor().newInstance();
} catch (Exception e) {
e.printStackTrace();
return null;
}
}


/**
* Get the context implementation for the current type
*
* @return Context implementation
*/
public Context context() {
return this.context;
}

/**
* Find context implementation using the PSI file
*
Expand Down
6 changes: 5 additions & 1 deletion src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<idea-plugin>
<id>net.labymod.intellij.singlehotswap</id>
<name>Single Hotswap</name>
<version>2.7</version>
<version>2.8</version>
<vendor email="[email protected]" url="https://www.labymod.net">LabyMedia</vendor>

<idea-version since-build="203.000"/>
Expand Down Expand Up @@ -53,6 +53,10 @@

<change-notes>
<![CDATA[
v2.8 (2024-08-29):
<ul>
<li>Added support for newer IntelliJ versions</li>
</ul>
v2.7 (2024-06-17):
<ul>
<li>Fixed an issue where the breakpoints couldn't find the local variables after a hotswap</li>
Expand Down

0 comments on commit bdbff77

Please sign in to comment.