Skip to content

Commit

Permalink
feat(hotswap): always generate new detected endpoints (#3241)
Browse files Browse the repository at this point in the history
  • Loading branch information
cromoteca authored Feb 17, 2025
1 parent 80570f2 commit bac20d0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@

import java.io.IOException;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import com.vaadin.flow.server.VaadinContext;
import com.vaadin.flow.server.frontend.FrontendTools;
Expand Down Expand Up @@ -79,8 +82,12 @@ public static EndpointCodeGenerator getInstance() {
/**
* Re-generates the endpoint TypeScript and re-registers the endpoints in
* Java.
*
* @param proposedNewBrowserCallables
* Some classes that might be new browser callables, for example
* coming from a hotswap event.
*/
public void update() {
public void update(String... proposedNewBrowserCallables) {
initIfNeeded();
if (configuration.isProductionMode()) {
throw new IllegalStateException(
Expand All @@ -90,6 +97,24 @@ public void update() {
ApplicationContextProvider.runOnContext(applicationContext -> {
List<Class<?>> browserCallables = findBrowserCallables(
engineConfiguration, applicationContext);

browserCallables = Stream.concat(browserCallables.stream(), Arrays
.stream(proposedNewBrowserCallables).map(className -> {
try {
Class<?> cls = Class.forName(className);
if (cls.getAnnotation(Endpoint.class) != null
|| cls.getAnnotation(
BrowserCallable.class) != null) {
return cls;
}

} catch (ClassNotFoundException e) {
LOGGER.error("Unable to find class " + className,
e);
}
return null;
})).filter(Objects::nonNull).distinct().toList();

ParserProcessor parser = new ParserProcessor(engineConfiguration);
parser.process(browserCallables);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static void onHotswap(Boolean redefined, String[] changedClasses) {
getLogger().debug("Regenerating endpoints because "
+ changed + " were " + operation);
}
EndpointCodeGenerator.getInstance().update();
EndpointCodeGenerator.getInstance().update(changedClasses);
}
} catch (IOException e) {
getLogger().error("Failed to re-generated TypeScript code");
Expand Down Expand Up @@ -130,7 +130,7 @@ private static boolean affectsEndpoints(String[] changedClasses)
|| cls.getAnnotation(EndpointExposed.class) != null) {
getLogger().debug(
"An endpoint annotation has been added to the class "
+ classesUsedInEndpoints);
+ changedClass);
return true;
}

Expand Down

0 comments on commit bac20d0

Please sign in to comment.