Skip to content

Commit

Permalink
Merge pull request #7 from LabyStudio/develop
Browse files Browse the repository at this point in the history
always complete the background task, even if an error occurs
  • Loading branch information
LabyStudio committed Mar 6, 2023
2 parents 9d3c54c + 3d4d37c commit 8856d72
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 71 deletions.
2 changes: 1 addition & 1 deletion 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"
Expand Down
Expand Up @@ -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<ClassFile> 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<ClassFile> 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);
}
Expand Down
32 changes: 18 additions & 14 deletions src/main/resources/META-INF/plugin.xml
@@ -1,7 +1,7 @@
<idea-plugin>
<id>net.labymod.intellij.singlehotswap</id>
<name>Single Hotswap</name>
<version>2.3</version>
<version>2.4</version>
<vendor email="labystudio@gmail.com" url="https://www.labymod.net">LabyMedia</vendor>

<idea-version since-build="203.000"/>
Expand All @@ -27,7 +27,7 @@
<notificationGroup id="SingleHotswap" displayType="BALLOON"/>

<!-- Settings Configuration -->
<applicationService id="CDSLanguageConfiguration"
<applicationService id="SingleHotswapConfiguration"
serviceImplementation="net.labymod.intellij.singlehotswap.storage.SingleHotswapConfiguration"/>
<applicationConfigurable instance="net.labymod.intellij.singlehotswap.storage.SingleHotswapConfigurationGui"
id="debugger.singlehotswap" parentId="project.propDebugger"
Expand All @@ -53,53 +53,57 @@

<change-notes>
<![CDATA[
v2.3 (27.12.2022):
v2.4 (2022-03-06):
<ul>
<li>Fixed an issue where the background task wouldn't finish if an error occurred</li>
</ul>
v2.3 (2022-12-27):
<ul>
<li>Added option to disable forcing the default compiler</li>
</ul>
v2.2 (15.12.2022):
v2.2 (2022-12-15):
<ul>
<li>Added hotswap button to new UI</li>
<li>Added option to force the default compiler when holding shift while clicking on the hotswap button</li>
</ul>
v2.1 (17.07.2022):
v2.1 (2022-07-17):
<ul>
<li>Fixed support for kotlin & inner classes</li>
</ul>
v2.0 (16.07.2022):
v2.0 (2022-07-16):
<ul>
<li>Implemented the built-in java compiler to speed up the compile process</li>
</ul>
v1.7 (06.01.2022):
v1.7 (2022-01-06):
<ul>
<li>Disabled Gradle runner during hotswap to speed up the compile process</li>
</ul>
v1.6 (13.06.2021):
v1.6 (2021-06-13):
<ul>
<li>Groovy, Kotlin and Java are no longer required plugins</li>
</ul>
v1.5 (11.05.2021):
v1.5 (2021-05-11):
<ul>
<li>Support for groovy and kotlin files</li>
</ul>
v1.4 (22.02.2021):
v1.4 (2021-02-22):
<ul>
<li>Fixed an exception that occurred when exiting the debugger during hotswapping</li>
</ul>
v1.3 (17.02.2021):
v1.3 (2021-02-17):
<ul>
<li>Fixed an exception during hotswap</li>
</ul>
v1.2 (19.01.2021):
v1.2 (2021-01-19):
<ul>
<li>Support for inner classes</li>
</ul>
v1.1 (05.01.2021):
v1.1 (2021-01-05):
<ul>
<li>Updated to latest IntelliJ version</li>
<li>Published on GitHub</li>
</ul>
v1.0 (06.08.2020):
v1.0 (2020-08-06):
<ul>
<li>First version published</li>
</ul>
Expand Down

0 comments on commit 8856d72

Please sign in to comment.