-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: Improve performance of Quarkus deployment jar support
Fixes #1143 Signed-off-by: azerr <[email protected]>
- Loading branch information
1 parent
7d107b0
commit 9c72598
Showing
6 changed files
with
171 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...n/java/com/redhat/devtools/intellij/quarkus/deployment/QuarkusDeploymentModuleLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.redhat.devtools.intellij.quarkus.deployment; | ||
|
||
import com.intellij.openapi.module.Module; | ||
import com.intellij.openapi.progress.ProgressIndicator; | ||
import com.intellij.openapi.vfs.VirtualFile; | ||
import com.redhat.devtools.intellij.lsp4ij.client.CoalesceByKey; | ||
import com.redhat.devtools.intellij.lsp4ij.internal.PromiseToCompletableFuture; | ||
import com.redhat.devtools.intellij.quarkus.tool.ToolDelegate; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.List; | ||
|
||
import static com.redhat.devtools.intellij.quarkus.QuarkusModuleUtil.isQuarkusModule; | ||
|
||
public class QuarkusDeploymentModuleLoader extends PromiseToCompletableFuture<List<VirtualFile>[]> { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(QuarkusDeploymentModuleLoader.class); | ||
|
||
public QuarkusDeploymentModuleLoader(@NotNull Module module) { | ||
super(progressIndicator -> { | ||
return collectDeploymentFiles(module, progressIndicator); | ||
}, "Quarkus deployment module loader", module.getProject(), module, new CoalesceByKey(QuarkusDeploymentModuleLoader.class.getName(), module.getName())); | ||
init(); | ||
} | ||
|
||
private static List<VirtualFile>[] collectDeploymentFiles(Module module, ProgressIndicator progressIndicator) { | ||
if (module.isDisposed()) | ||
return null; | ||
LOGGER.info("Ensuring library to " + module.getName()); | ||
long start = System.currentTimeMillis(); | ||
ToolDelegate toolDelegate = ToolDelegate.getDelegate(module); | ||
if (toolDelegate == null) { | ||
return null; | ||
} | ||
LOGGER.info("Tool delegate found for " + module.getName()); | ||
if (!isQuarkusModule(module)) { | ||
return null; | ||
} | ||
LOGGER.info("isQuarkus module " + module.getName()); | ||
return toolDelegate.getDeploymentFiles(module, progressIndicator); | ||
} | ||
|
||
} |
79 changes: 79 additions & 0 deletions
79
src/main/java/com/redhat/devtools/intellij/quarkus/deployment/QuarkusDeploymentSupport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package com.redhat.devtools.intellij.quarkus.deployment; | ||
|
||
import com.intellij.openapi.application.ApplicationManager; | ||
import com.intellij.openapi.application.WriteAction; | ||
import com.intellij.openapi.module.Module; | ||
import com.intellij.openapi.progress.ProcessCanceledException; | ||
import com.intellij.openapi.progress.ProgressIndicator; | ||
import com.intellij.openapi.progress.ProgressManager; | ||
import com.intellij.openapi.progress.Task; | ||
import com.intellij.openapi.project.DumbService; | ||
import com.intellij.openapi.roots.*; | ||
import com.intellij.openapi.roots.impl.libraries.LibraryEx; | ||
import com.intellij.openapi.util.Key; | ||
import com.intellij.openapi.vfs.VirtualFile; | ||
import com.redhat.devtools.intellij.quarkus.QuarkusConstants; | ||
import com.redhat.devtools.intellij.quarkus.QuarkusModuleUtil; | ||
import com.redhat.devtools.intellij.quarkus.tool.ToolDelegate; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.CancellationException; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
public class QuarkusDeploymentSupport { | ||
|
||
|
||
private static final Key<CompletableFuture<Void>> QUARKUS_DEPLOYMENT_LOADER_KEY = new Key<>(QuarkusDeploymentSupport.class.getName()); | ||
|
||
public static CompletableFuture<Void> updateClasspathWithQuarkusDeployment(Module module) { | ||
CompletableFuture<Void> loader = module.getUserData(QUARKUS_DEPLOYMENT_LOADER_KEY); | ||
if (isOutOfDated(loader)) { | ||
return updateClasspathWithQuarkusDeploymentSync(module); | ||
} | ||
return loader; | ||
} | ||
|
||
private static boolean isOutOfDated(CompletableFuture<Void> loader) { | ||
return loader == null || loader.isCancelled() || loader.isCompletedExceptionally(); | ||
} | ||
|
||
@NotNull | ||
private synchronized static CompletableFuture<Void> updateClasspathWithQuarkusDeploymentSync(Module module) { | ||
CompletableFuture<Void> loader = module.getUserData(QUARKUS_DEPLOYMENT_LOADER_KEY); | ||
if (!isOutOfDated(loader)) { | ||
return loader; | ||
} | ||
var project = module.getProject(); | ||
final CompletableFuture<Void> future = new CompletableFuture<>(); | ||
CompletableFuture.runAsync(() -> { | ||
Runnable task = () -> ProgressManager.getInstance().run(new Task.Backgroundable(project, "Computing deployment jars...") { | ||
@Override | ||
public void run(@NotNull ProgressIndicator indicator) { | ||
System.out.println("Computing deployment jars..."); | ||
try { | ||
long start = System.currentTimeMillis(); | ||
QuarkusModuleUtil.ensureQuarkusLibrary(module, indicator); | ||
long elapsed = System.currentTimeMillis() - start; | ||
System.out.println("Ensured QuarkusLibrary in " + elapsed + " ms"); | ||
future.complete(null); | ||
} catch (CancellationException | ProcessCanceledException e) { | ||
future.cancel(true); | ||
} catch (Exception e) { | ||
if (module != null) { | ||
} | ||
future.completeExceptionally(e); | ||
} | ||
} | ||
}); | ||
if (DumbService.getInstance(project).isDumb()) { | ||
DumbService.getInstance(project).runWhenSmart(task); | ||
} else { | ||
task.run(); | ||
} | ||
}); | ||
module.putUserData(QUARKUS_DEPLOYMENT_LOADER_KEY, future); | ||
return future; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters