Skip to content

Commit

Permalink
fix: quarkus.kubernetes.* properties not shown or validated (redhat-d…
Browse files Browse the repository at this point in the history
…eveloper#858)

Fixes redhat-developer#858

Signed-off-by: azerr <azerr@redhat.com>
  • Loading branch information
angelozerr committed Jul 24, 2023
1 parent 093d7e6 commit 138152c
Show file tree
Hide file tree
Showing 15 changed files with 350 additions and 389 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,72 +56,10 @@ class ClasspathResourceChangedListener extends PsiTreeChangeAdapter implements B

private final ClasspathResourceChangedManager manager;

private final Set<Module> modulesBeingEnsured = new HashSet<>();

ClasspathResourceChangedListener(ClasspathResourceChangedManager manager) {
this.manager = manager;
}

// Track modules changed

public CompletableFuture<Void> processModules() {
var overriders = manager.getOverriders();
if (overriders.isEmpty()) {
return CompletableFuture.completedFuture(null);
}
// Loop for each modules and process the load of libraries by using Classpath overrider.
return CompletableFuture.runAsync(() -> {
for (var module : ModuleManager.getInstance(manager.getProject()).getModules()) {
LOGGER.info("Calling ensure from processModules");
checkOverridedLibrary(module, true);
}
}, manager.getExecutor());
}

private CompletableFuture<Void> processModule(Module module) {
return checkOverridedLibrary(module, false);
}

private CompletableFuture<Void> checkOverridedLibrary(Module module, boolean sync) {
var overriders = manager.getOverriders();
if (modulesBeingEnsured.add(module)) {
if (sync) {
for (var overrider : overriders) {
overrider.overrideClasspath(module);
}
modulesBeingEnsured.remove(module);
return CompletableFuture.completedFuture(null);
} else {
return CompletableFuture.runAsync(() -> {
for (var overrider : overriders) {
overrider.overrideClasspath(module);
}
modulesBeingEnsured.remove(module);
}, manager.getExecutor());
}
}
return CompletableFuture.completedFuture(null);
}

@Override
public void moduleAdded(@NotNull Project project, @NotNull Module module) {
moduleChanged(module);
}

@Override
public void moduleRemoved(@NotNull Project project, @NotNull Module module) {
moduleChanged(module);
}

private void moduleChanged(Module module) {
LOGGER.info("Calling ensure from moduleChanged for module " + module.getName());
var overriders = manager.getOverriders();
if (!overriders.isEmpty()) {
// A module has changed, process the load of libraries by using Classpath overrider.
checkOverridedLibrary(module, false);
}
}

// Track library changes

@Override
Expand All @@ -136,27 +74,9 @@ public void afterLibraryRemoved(@NotNull Library library) {

private void handleLibraryUpdate(Library library) {
LOGGER.info("handleLibraryUpdate called " + library.getName());
var project = manager.getProject();

// Notify that a library has changed.
final var notifier = manager.getResourceChangedNotifier();
notifier.addLibrary(library);

// Process classpath overriders.
var overriders = manager.getOverriders();
if (overriders.isEmpty()) {
if (library instanceof LibraryEx && ((LibraryEx) library).getModule() != null) {
var module = ((LibraryEx) library).getModule();
processModule(module).thenRun(() -> {
project.getMessageBus().syncPublisher(ClasspathResourceChangedManager.TOPIC).moduleUpdated(module);
});
} else {
processModules().thenRun(() -> {
notifier.addLibrary(library);
project.getMessageBus().syncPublisher(ClasspathResourceChangedManager.TOPIC).modulesUpdated();
});
}
}
}

// Track Psi file changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.*;
import java.util.function.Consumer;

/**
* Classpath resource change manager provides the capability to track update of libraries changed and Java, microprofile-config properties files
Expand All @@ -61,34 +59,29 @@ public class ClasspathResourceChangedManager implements Disposable {
private final MessageBusConnection projectConnection;
private final MessageBusConnection appConnection;
private final ClasspathResourceChangedListener listener;
private final List<ClasspathOverrider> overriders;

public static ClasspathResourceChangedManager getInstance(Project project) {
return ServiceManager.getService(project, ClasspathResourceChangedManager.class);
}

public interface Listener {

void librariesChanged();

void sourceFilesChanged(Set<Pair<VirtualFile, Module>> sources);

void moduleUpdated(Module module);
default void beforeLibrariesChanged() {

void modulesUpdated();
}

public interface ClasspathOverrider {
}

void overrideClasspath(Module module);
void librariesChanged();

void sourceFilesChanged(Set<Pair<VirtualFile, Module>> sources);
}

private final Project project;

private final List<RunnableProgress> processBeforeLibrariesChanged;

public ClasspathResourceChangedManager(Project project) {
this.project = project;
this.overriders = new ArrayList<>();
this.processBeforeLibrariesChanged = new ArrayList<>();
if (ApplicationManager.getApplication().isUnitTestMode()) {
this.executor = ConcurrencyUtil.newSameThreadExecutorService();
} else {
Expand All @@ -97,7 +90,7 @@ public ClasspathResourceChangedManager(Project project) {
r -> new Thread(r, "Quarkus lib pool " + project.getName()));
}
// Send source files changed in debounce mode
this.resourceChangedNotifier = new ClasspathResourceChangedNotifier(project);
this.resourceChangedNotifier = new ClasspathResourceChangedNotifier(project, processBeforeLibrariesChanged);
listener = new ClasspathResourceChangedListener(this);
projectConnection = project.getMessageBus().connect();
// Track end of Java libraries update
Expand All @@ -109,15 +102,6 @@ public ClasspathResourceChangedManager(Project project) {
// Track delete, create, update of file
appConnection = ApplicationManager.getApplication().getMessageBus().connect(project);
appConnection.subscribe(VirtualFileManager.VFS_CHANGES, listener);
processModules();
}

public void processModules() {
listener.processModules();
}

public void addClasspathOverrider(ClasspathOverrider overrider) {
overriders.add(overrider);
}

@Override
Expand All @@ -142,7 +126,7 @@ ExecutorService getExecutor() {
return executor;
}

List<ClasspathOverrider> getOverriders() {
return overriders;
public void addPreprocessor(RunnableProgress preprocessor) {
processBeforeLibrariesChanged.add(preprocessor);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,23 @@
package com.redhat.devtools.intellij.lsp4mp4ij.classpath;

import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.progress.EmptyProgressIndicator;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;

import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;
import java.util.stream.Collectors;

/**
* Source file change notifier with a debounce mode.
Expand All @@ -37,9 +46,11 @@ public class ClasspathResourceChangedNotifier implements Disposable {

private final Set<Pair<VirtualFile, Module>> sourceFiles;
private boolean librariesChanged;
private final List<RunnableProgress> processBeforeLibrariesChanged;

public ClasspathResourceChangedNotifier(Project project) {
public ClasspathResourceChangedNotifier(Project project, List<RunnableProgress> processBeforeLibrariesChanged) {
this.project = project;
this.processBeforeLibrariesChanged = processBeforeLibrariesChanged;
sourceFiles = new HashSet<>();
}

Expand Down Expand Up @@ -87,8 +98,32 @@ private void notifyChanges() {
sourceFiles.clear();
}
if (librariesChanged) {
project.getMessageBus().syncPublisher(ClasspathResourceChangedManager.TOPIC).librariesChanged();
librariesChanged = false;
if (processBeforeLibrariesChanged.isEmpty() || ApplicationManager.getApplication().isUnitTestMode()) {
for (var runnable : processBeforeLibrariesChanged) {
runnable.run(new EmptyProgressIndicator());
}
project.getMessageBus().syncPublisher(ClasspathResourceChangedManager.TOPIC).librariesChanged();
librariesChanged = false;
} else {
ApplicationManager.getApplication().invokeLater(() -> {
new Task.Backgroundable(project, "Overriding MicroProfile classpath...", true) {
@Override
public void run(@NotNull ProgressIndicator progressIndicator) {
try {
progressIndicator.setIndeterminate(false);
progressIndicator.checkCanceled();
for (var runnable : processBeforeLibrariesChanged) {
runnable.run(progressIndicator);
}
}
finally {
project.getMessageBus().syncPublisher(ClasspathResourceChangedManager.TOPIC).librariesChanged();
librariesChanged = false;
}
}
}.queue();
}, ModalityState.defaultModalityState(), project.getDisposed());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*******************************************************************************
* Copyright (c) 2023 Red Hat Inc. and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
*
* Contributors:
* Red Hat Inc. - initial API and implementation
*******************************************************************************/
package com.redhat.devtools.intellij.lsp4mp4ij.classpath;

import com.intellij.openapi.progress.ProgressIndicator;

/**
* Runnable with progress indicator.
*
* @author Angelo ZERR
*/
public interface RunnableProgress {

void run(ProgressIndicator progressIndicator);
}
Loading

0 comments on commit 138152c

Please sign in to comment.