diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/PropertiesManager.java b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/PropertiesManager.java index 4086f91b0..81a4b7b7b 100644 --- a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/PropertiesManager.java +++ b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/PropertiesManager.java @@ -104,7 +104,6 @@ public MicroProfileProjectInfo getMicroProfileProjectInfo(Module module, .collect(Collectors.joining("+")) // + "'"); long startTime = System.currentTimeMillis(); - boolean excludeTestCode = classpathKind == ClasspathKind.SRC; PropertiesCollector collector = new PropertiesCollector(info, scopes); if (module != null) { SearchScope scope = createSearchScope(module, scopes, classpathKind == ClasspathKind.TEST); @@ -153,17 +152,17 @@ private static MicroProfileProjectInfo createInfo(Module module, ClasspathKind c return info; } - private SearchScope createSearchScope(Module module, List scopes, + private SearchScope createSearchScope(@NotNull Module module, List scopes, boolean excludeTestCode) { - SearchScope searchScope = GlobalSearchScope.EMPTY_SCOPE; + SearchScope searchScope = GlobalSearchScope.moduleRuntimeScope(module, !excludeTestCode); for (MicroProfilePropertiesScope scope : scopes) { switch (scope) { case sources: - searchScope = module != null ? searchScope.union(module.getModuleScope(!excludeTestCode)) : searchScope; + searchScope = searchScope.union(module.getModuleScope(!excludeTestCode)); break; case dependencies: - searchScope = module != null ? searchScope.union(module.getModuleWithLibrariesScope()) : searchScope; + searchScope = searchScope.union(module.getModuleWithLibrariesScope()); break; /*added missing default case */ default: diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/project/PsiMicroProfileProject.java b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/project/PsiMicroProfileProject.java index de88dd155..adcd762e5 100644 --- a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/project/PsiMicroProfileProject.java +++ b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/project/PsiMicroProfileProject.java @@ -118,8 +118,7 @@ public Integer getPropertyAsInteger(String key, Integer defaultValue) { return defaultValue; } try { - int intValue = Integer.parseInt(value); - return intValue; + return Integer.parseInt(value); } catch (NumberFormatException nfe) { return defaultValue; } diff --git a/src/main/java/com/redhat/devtools/intellij/quarkus/QuarkusModuleUtil.java b/src/main/java/com/redhat/devtools/intellij/quarkus/QuarkusModuleUtil.java index 1d05e0a73..3e0f219d9 100644 --- a/src/main/java/com/redhat/devtools/intellij/quarkus/QuarkusModuleUtil.java +++ b/src/main/java/com/redhat/devtools/intellij/quarkus/QuarkusModuleUtil.java @@ -126,7 +126,7 @@ private static void addLibrary(ModifiableRootModel model, List[] fi LibraryOrderEntry entry = model.findLibraryOrderEntry(library); assert entry != null : library; - entry.setScope(DependencyScope.PROVIDED); + entry.setScope(DependencyScope.RUNTIME); entry.setExported(false); ApplicationManager.getApplication().invokeAndWait(() -> { WriteAction.run(libraryModel::commit); diff --git a/src/main/java/com/redhat/devtools/intellij/quarkus/QuarkusProjectService.java b/src/main/java/com/redhat/devtools/intellij/quarkus/QuarkusProjectService.java index 234725a2a..2cb9448af 100644 --- a/src/main/java/com/redhat/devtools/intellij/quarkus/QuarkusProjectService.java +++ b/src/main/java/com/redhat/devtools/intellij/quarkus/QuarkusProjectService.java @@ -62,17 +62,6 @@ public QuarkusProjectService(Project project) { connection = project.getMessageBus().connect(); connection.subscribe(ClasspathResourceChangedManager.TOPIC, this); connection.subscribe(ProjectTopics.MODULES, this); - // Add the Quarkus deployment preprocessor - ClasspathResourceChangedManager.getInstance(project) - .addPreprocessor( - (progressIndicator) -> { - processModules(progressIndicator); - }); - } - - @Override - public void moduleAdded(@NotNull Project project, @NotNull Module module) { - QuarkusModuleUtil.ensureQuarkusLibrary(module, new EmptyProgressIndicator()); } public VirtualFile getSchema(Module module) { @@ -138,10 +127,10 @@ public void sourceFilesChanged(Set> sources) { List> info = sources.stream() .filter(pair -> isJavaFile(pair.getFirst()) || isConfigSource(pair.getFirst())) .map(pair -> Pair.pair(PsiUtilsLSImpl.getProjectURI(pair.getSecond()), getScope(pair.getFirst()))). - collect(Collectors.toList()); + collect(Collectors.toList()); if (!info.isEmpty()) { sendPropertiesChangeEvent(info.stream().map(p -> p.getSecond()).collect(Collectors.toList()), info.stream().map(p -> p.getFirst()).collect(Collectors.toSet())); @@ -112,10 +118,39 @@ private boolean isConfigSource(VirtualFile file) { @Override public CompletableFuture getProjectInfo(MicroProfileProjectInfoParams params) { - String filePath = getFilePath(params.getUri()); - return runAsBackground("Computing MicroProfile properties for '" + filePath + "'.", monitor -> - PropertiesManager.getInstance().getMicroProfileProjectInfo(params, PsiUtilsLSImpl.getInstance(getProject()), monitor) - ); + CompletableFuture future = new CompletableFuture<>(); + CompletableFuture.runAsync(() -> { + Runnable task = () -> ProgressManager.getInstance().run(new Task.Backgroundable(getProject(), "Computing deployment jars...") { + @Override + public void run(@NotNull ProgressIndicator indicator) { + IPsiUtils utils = PsiUtilsLSImpl.getInstance(getProject()); + try { + VirtualFile file = utils.findFile(params.getUri()); + Module module = utils.getModule(file); + QuarkusModuleUtil.ensureQuarkusLibrary(module, indicator); + future.complete(true); + } catch (Exception e) { + future.completeExceptionally(e); + } + } + + @Override + public boolean isHeadless() { + return true; + } + }); + if (DumbService.getInstance(getProject()).isDumb()) { + DumbService.getInstance(getProject()).runWhenSmart(task); + } else { + task.run(); + } + }); + return future.thenCompose(Boolean -> { + String filePath = getFilePath(params.getUri()); + return runAsBackground("Computing MicroProfile properties for '" + filePath + "'.", monitor -> + PropertiesManager.getInstance().getMicroProfileProjectInfo(params, PsiUtilsLSImpl.getInstance(getProject()), monitor) + ); + }); } @Override diff --git a/src/main/java/com/redhat/devtools/intellij/quarkus/maven/MavenToolDelegate.java b/src/main/java/com/redhat/devtools/intellij/quarkus/maven/MavenToolDelegate.java index d3b72a53e..cdea91e31 100644 --- a/src/main/java/com/redhat/devtools/intellij/quarkus/maven/MavenToolDelegate.java +++ b/src/main/java/com/redhat/devtools/intellij/quarkus/maven/MavenToolDelegate.java @@ -162,17 +162,22 @@ private List ensureDownloaded(Module module, MavenProject mavenPr long start = System.currentTimeMillis(); try { MavenEmbedderWrapper serverWrapper = createEmbedderWrapper(module.getProject(), mavenProject.getDirectory()); + if (serverWrapper == null) { + return Collections.emptyList(); + } if (classifier != null) { for(MavenId id : deploymentIds) { result.add(serverWrapper.resolve(new MavenArtifactInfo(id, "jar", classifier), mavenProject.getRemoteRepositories())); } } else { List infos = deploymentIds.stream().map(id -> new MavenArtifactInfo(id, "jar", classifier)).collect(Collectors.toList()); - result = serverWrapper.resolveTransitively(infos, mavenProject.getRemoteRepositories()); + result = serverWrapper.resolveArtifactTransitively(infos, mavenProject.getRemoteRepositories()).mavenResolvedArtifacts; } } catch (MavenProcessCanceledException | RuntimeException e) { LOGGER.warn(e.getLocalizedMessage(), e); } + long elapsed = System.currentTimeMillis() - start; + System.out.println("ensureDownloaded took "+elapsed+ "ms"); return result; }