Skip to content

Commit

Permalink
fix: don't leak deployment jar classes
Browse files Browse the repository at this point in the history
Signed-off-by: Fred Bricon <[email protected]>
  • Loading branch information
fbricon committed Aug 4, 2023
1 parent cfa3f27 commit f88f734
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -153,17 +152,17 @@ private static MicroProfileProjectInfo createInfo(Module module, ClasspathKind c
return info;
}

private SearchScope createSearchScope(Module module, List<MicroProfilePropertiesScope> scopes,
private SearchScope createSearchScope(@NotNull Module module, List<MicroProfilePropertiesScope> 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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private static void addLibrary(ModifiableRootModel model, List<VirtualFile>[] 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -138,10 +127,10 @@ public void sourceFilesChanged(Set<com.intellij.openapi.util.Pair<VirtualFile, M
}

public void processModules(com.intellij.openapi.progress.ProgressIndicator progressIndicator) {
for (var module : ModuleManager.getInstance(project).getModules()) {
LOGGER.info("Calling ensure from processModules");
QuarkusModuleUtil.ensureQuarkusLibrary(module, progressIndicator);
}
// for (var module : ModuleManager.getInstance(project).getModules()) {
// LOGGER.info("Calling ensure from processModules");
// QuarkusModuleUtil.ensureQuarkusLibrary(module, progressIndicator);
// }
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
******************************************************************************/
package com.redhat.devtools.intellij.quarkus.lang;

import com.intellij.codeInspection.unused.ImplicitPropertyUsageProvider;
import com.intellij.lang.properties.codeInspection.unused.ImplicitPropertyUsageProvider;
import com.intellij.lang.properties.psi.Property;
import com.redhat.devtools.intellij.quarkus.QuarkusModuleUtil;

public class QuarkusImplicitPropertyUsageProvider extends ImplicitPropertyUsageProvider {
public class QuarkusImplicitPropertyUsageProvider implements ImplicitPropertyUsageProvider {
@Override
public boolean isUsed(Property property) {
return QuarkusModuleUtil.isQuarkusPropertiesFile(property.getContainingFile().getVirtualFile(), property.getProject());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
package com.redhat.devtools.intellij.quarkus.lsp;

import com.intellij.openapi.module.Module;
import com.intellij.openapi.progress.EmptyProgressIndicator;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.vfs.VirtualFile;
Expand Down Expand Up @@ -112,10 +113,23 @@ private boolean isConfigSource(VirtualFile file) {

@Override
public CompletableFuture<MicroProfileProjectInfo> getProjectInfo(MicroProfileProjectInfoParams params) {
String filePath = getFilePath(params.getUri());
return runAsBackground("Computing MicroProfile properties for '" + filePath + "'.", monitor ->
PropertiesManager.getInstance().getMicroProfileProjectInfo(params, PsiUtilsLSImpl.getInstance(getProject()), monitor)
);
return CompletableFuture.runAsync(() -> {
try {
IPsiUtils utils = PsiUtilsLSImpl.getInstance(getProject());
VirtualFile file = utils.findFile(params.getUri());
Module module = utils.getModule(file);
QuarkusModuleUtil.ensureQuarkusLibrary(module, new EmptyProgressIndicator());
}
catch(Exception e) {
e.printStackTrace();
}
}).thenCompose(Void -> {
String filePath = getFilePath(params.getUri());
return runAsBackground("Computing MicroProfile properties for '" + filePath + "'.", monitor ->
PropertiesManager.getInstance().getMicroProfileProjectInfo(params, PsiUtilsLSImpl.getInstance(getProject()), monitor)
);
});

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,22 @@ private List<MavenArtifact> 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<MavenArtifactInfo> 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;
}

Expand Down

0 comments on commit f88f734

Please sign in to comment.