From 3d4d37cee43af61126503776c721f66a6f50f480 Mon Sep 17 00:00:00 2001 From: LabyStudio Date: Mon, 6 Mar 2023 16:34:57 +0100 Subject: [PATCH] always complete the background task, even if an error occurs, version 2.4 --- build.gradle.kts | 2 +- .../actions/SingleHotswapAction.java | 104 ++++++++---------- src/main/resources/META-INF/plugin.xml | 32 +++--- 3 files changed, 67 insertions(+), 71 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 715ea96..8e92604 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,6 +1,6 @@ plugins { id("java") - id("org.jetbrains.intellij") version "1.10.0" + id("org.jetbrains.intellij") version "1.13.1" } group = "net.labymod.intellij" diff --git a/src/main/java/net/labymod/intellij/singlehotswap/actions/SingleHotswapAction.java b/src/main/java/net/labymod/intellij/singlehotswap/actions/SingleHotswapAction.java index 0a68373..b088e9f 100644 --- a/src/main/java/net/labymod/intellij/singlehotswap/actions/SingleHotswapAction.java +++ b/src/main/java/net/labymod/intellij/singlehotswap/actions/SingleHotswapAction.java @@ -117,66 +117,58 @@ public void actionPerformed(@NotNull AnActionEvent event) { DebuggerSession debugger = debuggerManager.getContext().getDebuggerSession(); assert debugger != null; + // Save the opened documents + FileDocumentManager.getInstance().saveAllDocuments(); + + // Create compiler and progress + boolean forceDefault = event.getInputEvent().isShiftDown() + && this.configuration.isForceDefaultCompilerShift(); + AbstractCompiler compiler = context.compiler(this.configuration, forceDefault); + ClassFile outputFile = context.getClassFile(psiFile); + VirtualFile sourceFile = psiFile.getVirtualFile(); + + // Execute progress HotSwapProgressImpl progress = new HotSwapProgressImpl(project); - try { - progress.setTitle("Saving opened documents..."); - - // Save the opened documents - FileDocumentManager.getInstance().saveAllDocuments(); - - progress.setTitle("Initialize hotswap task..."); - - // Create compiler and progress - boolean forceDefault = event.getInputEvent().isShiftDown() - && this.configuration.isForceDefaultCompilerShift(); - AbstractCompiler compiler = context.compiler(this.configuration, forceDefault); - ClassFile outputFile = context.getClassFile(psiFile); - VirtualFile sourceFile = psiFile.getVirtualFile(); - - // Execute application thread - Application application = ApplicationManager.getApplication(); - application.executeOnPooledThread(() -> { - ProgressManager.getInstance().runProcess(() -> { - progress.setTitle("Compile classes..."); - - try { - long start = System.currentTimeMillis(); - - // Compile the current opened file - List classFiles = compiler.compile(sourceFile, outputFile); - if (classFiles.isEmpty()) { - String message = "Could not compile " + psiFile.getName(); - progress.addMessage(debugger, MessageCategory.ERROR, message); - return; - } - - // Show compile duration - long duration = System.currentTimeMillis() - start; - if (this.configuration.isShowCompileDuration()) { - String message = "Compiled " + classFiles.size() + " classes in " + duration + "ms"; - progress.addMessage(debugger, MessageCategory.STATISTICS, message); - } - progress.setTitle("Hotswap classes..."); - - // Hotswap the file - if (!context.hotswap(debugger, progress, classFiles)) { - String message = "Could not hotswap " + psiFile.getName(); - progress.addMessage(debugger, MessageCategory.ERROR, message); - } - } catch (Exception e) { - String message = "Error during hotswap: " + e.getMessage(); + Application application = ApplicationManager.getApplication(); + application.executeOnPooledThread(() -> { + ProgressManager.getInstance().runProcess(() -> { + progress.setTitle("Compile classes..."); + + // Compile + try { + long start = System.currentTimeMillis(); + + // Compile the current opened file + List classFiles = compiler.compile(sourceFile, outputFile); + if (classFiles.isEmpty()) { + String message = "Could not compile " + psiFile.getName(); progress.addMessage(debugger, MessageCategory.ERROR, message); + return; } - progress.setTitle("Hotswap completed"); - progress.finished(); - }, progress.getProgressIndicator()); - }); - } catch (Exception e) { - String message = "Can't initialize hotswap task: " + e.getMessage(); - progress.addMessage(debugger, MessageCategory.ERROR, message); - progress.finished(); - } + // Show compile duration + long duration = System.currentTimeMillis() - start; + if (this.configuration.isShowCompileDuration()) { + String message = "Compiled " + classFiles.size() + " classes in " + duration + "ms"; + progress.addMessage(debugger, MessageCategory.STATISTICS, message); + } + progress.setTitle("Hotswap classes..."); + + // Hotswap the file + if (!context.hotswap(debugger, progress, classFiles)) { + String message = "Could not hotswap " + psiFile.getName(); + progress.addMessage(debugger, MessageCategory.ERROR, message); + } + } catch (Exception e) { + String message = "Error during hotswap: " + e.getMessage(); + progress.addMessage(debugger, MessageCategory.ERROR, message); + } + + // Finish the progress + progress.setTitle("Hotswap completed"); + progress.finished(); + }, progress.getProgressIndicator()); + }); } catch (Exception e) { this.notifyUser("Can't setup hotswap task: " + e.getMessage(), NotificationType.ERROR); } diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index e5068bb..4f479e1 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -1,7 +1,7 @@ net.labymod.intellij.singlehotswap Single Hotswap - 2.3 + 2.4 LabyMedia @@ -27,7 +27,7 @@ - +
  • Fixed an issue where the background task wouldn't finish if an error occurred
  • + + v2.3 (2022-12-27):
    • Added option to disable forcing the default compiler
    - v2.2 (15.12.2022): + v2.2 (2022-12-15):
    • Added hotswap button to new UI
    • Added option to force the default compiler when holding shift while clicking on the hotswap button
    - v2.1 (17.07.2022): + v2.1 (2022-07-17):
    • Fixed support for kotlin & inner classes
    - v2.0 (16.07.2022): + v2.0 (2022-07-16):
    • Implemented the built-in java compiler to speed up the compile process
    - v1.7 (06.01.2022): + v1.7 (2022-01-06):
    • Disabled Gradle runner during hotswap to speed up the compile process
    - v1.6 (13.06.2021): + v1.6 (2021-06-13):
    • Groovy, Kotlin and Java are no longer required plugins
    - v1.5 (11.05.2021): + v1.5 (2021-05-11):
    • Support for groovy and kotlin files
    - v1.4 (22.02.2021): + v1.4 (2021-02-22):
    • Fixed an exception that occurred when exiting the debugger during hotswapping
    - v1.3 (17.02.2021): + v1.3 (2021-02-17):
    • Fixed an exception during hotswap
    - v1.2 (19.01.2021): + v1.2 (2021-01-19):
    • Support for inner classes
    - v1.1 (05.01.2021): + v1.1 (2021-01-05):
    • Updated to latest IntelliJ version
    • Published on GitHub
    - v1.0 (06.08.2020): + v1.0 (2020-08-06):
    • First version published