Skip to content

Commit

Permalink
make plugin loadable even without Groovy, Kotlin or Java plugin.
Browse files Browse the repository at this point in the history
increase minimum build from 201 to 203
version 1.6
  • Loading branch information
LabyStudio committed Jun 13, 2021
1 parent 7b5c867 commit e5e1386
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 22 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ dependencies {
}

intellij {
version = "IC-2020.3.2"
version = "IC-2020.3.3"
plugins = ["Kotlin", "Groovy", "java", "properties"]
pluginName "Single Hotswap"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ public void update( @NotNull AnActionEvent event ) {
*/
@Override
public void actionPerformed( @NotNull AnActionEvent event ) {
Project project = event.getProject();
PsiFile file = event.getData( CommonDataKeys.PSI_FILE );
Project project = file == null ? null : file.getProject();
IHotswap hotswap = EnumFileType.find( file );

// Is the target file a valid java file?
if ( project != null && file != null && hotswap.isPossible( file ) ) {
if ( project != null && hotswap.isPossible( file ) ) {

// Compile a single file
compileSingleFile( project, file.getVirtualFile(), success -> {
Expand Down Expand Up @@ -135,7 +135,7 @@ private void compileSingleFile( Project project, VirtualFile virtualFile, Consum
settings.RUN_HOTSWAP_AFTER_COMPILE = prevRunHotswap;

// Run callback with success state
callback.accept( !result.hasErrors() );
callback.accept( result != null && !result.hasErrors() );
} );
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,58 @@
package net.labymod.intellij.singlehotswap.hotswap;

import com.intellij.ide.plugins.IdeaPluginDescriptor;
import com.intellij.ide.plugins.PluginManager;
import com.intellij.openapi.extensions.PluginId;
import com.intellij.psi.PsiFile;
import net.labymod.intellij.singlehotswap.hotswap.impl.DefaultHotswap;
import net.labymod.intellij.singlehotswap.hotswap.impl.psi.type.GroovyHotswap;
import net.labymod.intellij.singlehotswap.hotswap.impl.psi.type.JavaHotswap;
import net.labymod.intellij.singlehotswap.hotswap.impl.psi.type.KotlinHotswap;
import org.jetbrains.annotations.Nullable;

/**
* All available file types for single hot-swapping
*
* @author LabyStudio
*/
public enum EnumFileType {
NONE( DefaultHotswap.class ),
JAVA( JavaHotswap.class ),
GROOVY( GroovyHotswap.class ),
KOTLIN( KotlinHotswap.class );
NONE(
"net.labymod.intellij.singlehotswap.hotswap.impl.DefaultHotswap",
null
),
JAVA(
"net.labymod.intellij.singlehotswap.hotswap.impl.psi.type.JavaHotswap",
"com.intellij.java"
),
GROOVY(
"net.labymod.intellij.singlehotswap.hotswap.impl.psi.type.GroovyHotswap",
"org.intellij.groovy"
),
KOTLIN(
"net.labymod.intellij.singlehotswap.hotswap.impl.psi.type.KotlinHotswap",
"org.jetbrains.kotlin"
);

/**
* Hotswap implementation
*/
private IHotswap hotswap;

/**
* Creates and instance of the given implementation class for hot-swapping
* Creates and instance of the given implementation class for hot-swapping if the required plugin is available
*
* @param clazz Hotswap implementation class
* @param className Hotswap implementation class
* @param requiredPluginId The required plugin for this hotswap type
*/
EnumFileType( Class<? extends IHotswap> clazz ) {
EnumFileType( String className, String requiredPluginId ) {
try {
this.hotswap = clazz.getConstructor().newInstance();
// Find plugin by plugin id
@Nullable IdeaPluginDescriptor plugin = requiredPluginId == null ? null :
PluginManager.getInstance().findEnabledPlugin( PluginId.getId( requiredPluginId ) );

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

// Load implementation
this.hotswap = (IHotswap) Class.forName( className ).getConstructor().newInstance();
} catch ( Exception e ) {
e.printStackTrace();
}
Expand All @@ -54,7 +77,7 @@ public static IHotswap find( PsiFile file ) {
if ( file != null ) {
for ( EnumFileType type : values() ) {
IHotswap instance = type.getInstance();
if ( instance.isPossible( file ) ) {
if ( instance != null && instance.isPossible( file ) ) {
return instance;
}
}
Expand Down
14 changes: 9 additions & 5 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<idea-plugin>
<id>net.labymod.intellij.singlehotswap</id>
<name>Single Hotswap</name>
<version>1.5</version>
<version>1.6</version>
<vendor email="labystudio@gmail.com" url="https://www.labymod.net">LabyMedia</vendor>

<idea-version since-build="201.000"/>
<idea-version since-build="203.000"/>

<description><![CDATA[
With this plugin you can hotswap <b>way faster</b> than usual by hotswapping <b>only the file opened</b> in the editor.<br>
Expand All @@ -17,9 +17,9 @@
]]></description>

<depends>com.intellij.modules.platform</depends>
<depends>com.intellij.modules.java</depends>
<depends>org.intellij.groovy</depends>
<depends>org.jetbrains.kotlin</depends>
<depends optional="true" config-file="singleHotSwap-java.xml">com.intellij.modules.java</depends>
<depends optional="true" config-file="singleHotSwap-groovy.xml">org.intellij.groovy</depends>
<depends optional="true" config-file="singleHotSwap-kotlin.xml">org.jetbrains.kotlin</depends>

<extensions defaultExtensionNs="com.intellij">
<notificationGroup id="SingleHotswap" displayType="BALLOON"/>
Expand All @@ -37,6 +37,10 @@

<change-notes>
<![CDATA[
v1.6 (13.06.2021):
<ul>
<li>Groovy, Kotlin and Java are no longer required plugins</li>
</ul>
v1.5 (11.05.2021):
<ul>
<li>Support for groovy and kotlin files</li>
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/META-INF/singleHotSwap-groovy.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<idea-plugin></idea-plugin>
1 change: 1 addition & 0 deletions src/main/resources/META-INF/singleHotSwap-java.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<idea-plugin></idea-plugin>
1 change: 1 addition & 0 deletions src/main/resources/META-INF/singleHotSwap-kotlin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<idea-plugin></idea-plugin>

0 comments on commit e5e1386

Please sign in to comment.