Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!(generator): load endpoints from Spring components and stop using Maven/Gradle at each generation #2616

Merged
merged 160 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
160 commits
Select commit Hold shift + click to select a range
b299278
First version
cromoteca Jul 16, 2024
bbca209
Check for inactive application contexts
cromoteca Jul 16, 2024
d8f54a2
Remove `configure`mojo
cromoteca Jul 17, 2024
52ac8b3
Support production mode (needs process-aot in pom.xml)
cromoteca Jul 17, 2024
9bbcdbf
Avoid adding new goal to pom.xml in projects
cromoteca Jul 24, 2024
5edbd61
Simplify code a bit
cromoteca Jul 24, 2024
7a99883
Some code improvements
cromoteca Jul 25, 2024
7093a3a
Make sure we use the available classpath
cromoteca Jul 25, 2024
4000a32
Move classpath
cromoteca Jul 26, 2024
20e4cf5
Get more config from Maven
cromoteca Jul 29, 2024
88d9d01
Refactor annotations configuration
cromoteca Jul 30, 2024
6c702af
Revert import change
cromoteca Jul 30, 2024
0b40ef8
Remove direct references to the endpoint annotations
cromoteca Jul 30, 2024
23814a7
support build dir
cromoteca Jul 31, 2024
d5fb531
Restore check for acl annotations
cromoteca Jul 31, 2024
ca9c6a0
Refactor annotations
cromoteca Aug 1, 2024
474bd56
Extract Aot code and use it for hotswap
cromoteca Aug 1, 2024
d64a6cf
Start fixing Gradle plugin
cromoteca Aug 2, 2024
8403ed1
Refactor configuration to not be static
cromoteca Aug 3, 2024
fc64cb9
Refactorings while fixing tests
cromoteca Aug 6, 2024
4023bde
Keep fixing tests
cromoteca Aug 6, 2024
a704d81
Merge branch 'main' into feat/avoid-running-maven
cromoteca Aug 8, 2024
cb5971c
Remove moduleinfo
cromoteca Aug 8, 2024
91d6a30
Add some necessary comments
cromoteca Aug 8, 2024
122ad38
Merge branch 'main' into feat/avoid-running-maven
cromoteca Sep 2, 2024
3927ebc
Merge branch 'main' into feat/avoid-running-maven
cromoteca Sep 12, 2024
dc3cdcc
Merge branch 'main' into feat/avoid-running-maven
cromoteca Oct 15, 2024
ee8698b
Merge branch 'main' into feat/avoid-running-maven
cromoteca Oct 17, 2024
8ed48c4
Merge remote-tracking branch 'origin/main' into feat/avoid-running-maven
cromoteca Oct 22, 2024
be6888b
Merge branch 'main' into feat/avoid-running-maven
cromoteca Oct 30, 2024
c2221e7
chore(annotations): bump version
platosha Nov 13, 2024
a6081ee
text(parser-jvm-plugin-backbone): update test fixture
platosha Nov 13, 2024
2d851aa
fix(gradle-plugin): make it build
platosha Nov 13, 2024
81b2a27
Merge branch 'main' into feat/avoid-running-maven
cromoteca Nov 18, 2024
7db7ff9
Add missing endpoint in test
cromoteca Nov 18, 2024
801e122
Merge branch 'main' into feat/avoid-running-maven
cromoteca Nov 18, 2024
d31aadc
fix(annotations): add module declaration
platosha Nov 19, 2024
dac7549
test(parser-jvm-plugin-backbone): fix backbone tests
platosha Nov 19, 2024
68c8e90
test(parser-jvm-plugin-transfertypes): add annotations module
platosha Nov 19, 2024
26c0427
test(engine-runtime): use SpringBootTest for tasks
platosha Nov 19, 2024
5b19b4a
Revert "test(parser-jvm-plugin-transfertypes): add annotations module"
cromoteca Nov 19, 2024
39873fd
Revert "test(parser-jvm-plugin-backbone): fix backbone tests"
cromoteca Nov 19, 2024
b371072
Revert "fix(annotations): add module declaration"
cromoteca Nov 19, 2024
3469569
Fix some tests
cromoteca Nov 19, 2024
2ede348
Remove class loader from parser
cromoteca Nov 20, 2024
7264098
Merge branch 'main' into feat/avoid-running-maven
platosha Nov 20, 2024
1e1cd08
fix(gradle-plugin): remove classLoader
platosha Nov 20, 2024
8cb42b8
fix(maven-plugin): dependencyConvergence issue
platosha Nov 20, 2024
c8cf885
Fix number of expected params
cromoteca Nov 20, 2024
6413272
Fix some tests
cromoteca Nov 21, 2024
df20ab7
refactor!: make EngineConfiguration read-only, simplify parser/genera…
platosha Nov 22, 2024
1caea88
Override `executeInternal`
cromoteca Nov 25, 2024
2311c25
fix(engine-core): use regular classes directory to find main class
platosha Nov 25, 2024
10944e5
chore: improve javadoc example (#2917)
taefi Nov 21, 2024
47a3e7e
chore(release): npm version 24.6.0-beta1
vaadin-bot Nov 21, 2024
aac187a
feat(file-router): add skipLayouts feature (#2915)
Lodin Nov 22, 2024
d9ff17e
chore: update package[-lock].json (main) (#2914)
vaadin-bot Nov 22, 2024
4e0b408
chore: update spring-boot to 3.3.6 (#2918)
vaadin-bot Nov 22, 2024
c763d05
Formatting
cromoteca Nov 25, 2024
9343989
Keep fixing tests
cromoteca Nov 25, 2024
d9cf95c
Merge branch 'main' into feat/avoid-running-maven
cromoteca Nov 25, 2024
12bada9
Restore class location in finder
cromoteca Nov 25, 2024
8ce5cc2
change where main class is searched
cromoteca Nov 25, 2024
7469072
Simplify syntax
cromoteca Nov 25, 2024
5a70f51
Restore missing super call
cromoteca Nov 25, 2024
8b0a7b8
Restore main class param
cromoteca Nov 25, 2024
574c94a
Get classpath from mojo
cromoteca Nov 25, 2024
8e20262
Merge branch 'main' into feat/avoid-running-maven
cromoteca Nov 25, 2024
c0777cd
Fix when proxies are found by Spring
cromoteca Nov 26, 2024
d211264
Merge branch 'main' into feat/avoid-running-maven
cromoteca Nov 26, 2024
e2ed3c2
Change how main class is configured
cromoteca Nov 26, 2024
30d9ca3
Fetch main class from spring plugin
cromoteca Nov 26, 2024
ee6b0f9
Merge branch 'main' into feat/avoid-running-maven
cromoteca Nov 26, 2024
c4b5f84
Rename AotEndpointFinder
cromoteca Nov 27, 2024
32566b7
Skip endpoints in csrf tests
cromoteca Nov 27, 2024
de3cc1a
Merge branch 'main' into feat/avoid-running-maven
cromoteca Nov 27, 2024
ccf1c35
Make endpoint provider emit a simple warning
cromoteca Nov 27, 2024
0c53988
Apply changes from Maven plugin to Gradle plugin
cromoteca Nov 27, 2024
97b6925
chore: add web-test-runner for react-auth (#2926)
Lodin Nov 27, 2024
0a76f68
Fix NullableTest
cromoteca Nov 27, 2024
fb721fc
Upgrade Kotlin version
cromoteca Nov 27, 2024
77e2ad1
Fix NullableTest again
cromoteca Nov 27, 2024
434ea00
fix(file-router): get back Flow AutoLayout (#2931)
Lodin Nov 27, 2024
5d4d92c
chore(release): npm version 24.6.0-beta3
vaadin-bot Nov 27, 2024
4f04d98
chore: update package[-lock].json (main) (#2932)
vaadin-bot Nov 27, 2024
2253a97
chore: Opt-in React Router v7 features (#2929)
mshabarov Nov 27, 2024
6e1b758
Merge branch 'main' into feat/avoid-running-maven
cromoteca Nov 27, 2024
259f0d1
Restore removed dependency in Gradle task
cromoteca Nov 28, 2024
57dde0a
Merge branch 'main' into feat/avoid-running-maven
cromoteca Nov 28, 2024
2161c58
Change how Kotlin handles Java version
cromoteca Nov 29, 2024
e4710dc
Fix single module test
cromoteca Nov 29, 2024
a904050
Change how the classpath is fetched
cromoteca Nov 29, 2024
8392552
Restore classesDir
cromoteca Nov 29, 2024
8564eb0
Change classloader and annotation detection
cromoteca Dec 2, 2024
ab03bcc
Merge branch 'main' into feat/avoid-running-maven
cromoteca Dec 2, 2024
a525a09
Add parent classloader
cromoteca Dec 2, 2024
c991cc1
Filter out internal endpoints
cromoteca Dec 2, 2024
0643acc
Use "unspecified" as default groupId in Gradle
cromoteca Dec 3, 2024
1542230
Add stacktrace to Gradle command in test
cromoteca Dec 3, 2024
bd627b7
Upgrade Spring Boot in test
cromoteca Dec 3, 2024
4648844
Fix Gradle plugin
cromoteca Dec 3, 2024
88255fc
Change where internal endpoints are filtered out
cromoteca Dec 3, 2024
c711292
Try publishing to Maven Local
cromoteca Dec 4, 2024
d8486d1
Merge branch 'main' into feat/avoid-running-maven
cromoteca Dec 4, 2024
6a690f2
Put classpath in env variable
cromoteca Dec 5, 2024
9eb168f
Merge branch 'main' into feat/avoid-running-maven
cromoteca Dec 5, 2024
031f6b5
Use a file for all arguments in AOT
cromoteca Dec 5, 2024
14296ae
Report error from process
cromoteca Dec 5, 2024
a18b8e0
Refactor quoting
cromoteca Dec 5, 2024
057229b
Merge branch 'main' into feat/avoid-running-maven
cromoteca Dec 5, 2024
368f415
Merge branch 'main' into feat/avoid-running-maven
cromoteca Dec 9, 2024
d5875c4
Only take loader tools from the plugin classpath
cromoteca Dec 9, 2024
8d9b8fb
Merge branch 'main' into feat/avoid-running-maven
cromoteca Dec 9, 2024
3e066ef
Update package versions
cromoteca Dec 9, 2024
1d8fce8
Merge branch 'main' into feat/avoid-running-maven
cromoteca Dec 9, 2024
a79453e
Rename annotation package
cromoteca Dec 9, 2024
590b42b
Merge branch 'main' into feat/avoid-running-maven
cromoteca Dec 10, 2024
01d52c6
Merge branch 'main' into feat/avoid-running-maven
cromoteca Dec 10, 2024
ba62d7c
Reduce the number of changes in the PR
cromoteca Dec 10, 2024
42b8688
Bump Spring Boot in tests
cromoteca Dec 10, 2024
03951fe
Restore some deleted test files
cromoteca Dec 11, 2024
406679a
Use restored classes
cromoteca Dec 12, 2024
257aff7
Merge branch 'main' into feat/avoid-running-maven
cromoteca Dec 12, 2024
92b70aa
Refactor configuration
cromoteca Dec 12, 2024
bd5dffa
Hardcode default endpoint annotations
cromoteca Dec 12, 2024
bf2e29b
Try to remove dependency
cromoteca Dec 13, 2024
821c655
Remove wrong imports
cromoteca Dec 13, 2024
d62383d
Retrieve mainClass from Spring
cromoteca Dec 13, 2024
9637d10
Address some review comments
cromoteca Dec 13, 2024
8531a2b
Address some review comments
cromoteca Dec 13, 2024
55f860e
Merge branch 'main' into feat/avoid-running-maven
cromoteca Dec 16, 2024
4966032
Add Javadoc
cromoteca Dec 16, 2024
aa5c503
Refactor endpoint finder
cromoteca Dec 16, 2024
d9c601c
Move task dependency
cromoteca Dec 16, 2024
84b660e
Remove the not used exception type
taefi Dec 18, 2024
4d1454c
Rename create to build
cromoteca Dec 18, 2024
6e3d4cc
Remove unused logger
cromoteca Dec 18, 2024
4c28c6d
Improve error message
cromoteca Dec 18, 2024
2a6e4b8
Change how baseDir is computed
cromoteca Dec 18, 2024
4b703d3
Remove TODO
cromoteca Dec 18, 2024
de85683
Use browser callable as much as possible in code
cromoteca Dec 18, 2024
dfdec9f
Code parity with other implementation
cromoteca Dec 18, 2024
438af8b
Extract common code
cromoteca Dec 18, 2024
7507ca0
Apply suggestions from review
taefi Dec 19, 2024
5c30795
Merge branch 'main' into feat/avoid-running-maven
cromoteca Dec 19, 2024
33d101d
Merge branch 'main' into feat/avoid-running-maven
cromoteca Dec 19, 2024
e062d6a
Merge branch 'main' into feat/avoid-running-maven
cromoteca Dec 19, 2024
b6fd839
Merge branch 'main' into feat/avoid-running-maven
cromoteca Dec 19, 2024
bfa0900
Merge branch 'main' into feat/avoid-running-maven
cromoteca Dec 19, 2024
1da59cf
Extract engine configuration to companion object
cromoteca Dec 19, 2024
d6c3e5f
Move when annotations are configured
cromoteca Dec 20, 2024
65828ec
Fix missing annotations in dev mode
cromoteca Dec 20, 2024
cc0aa70
Add annotations to test
cromoteca Dec 20, 2024
61af983
Move configuration again in Gradle
cromoteca Dec 20, 2024
f492845
Remove exposed packages
cromoteca Dec 20, 2024
4ec360b
Merge branch 'main' into feat/avoid-running-maven
cromoteca Dec 20, 2024
28e67fe
Merge branch 'main' into feat/avoid-running-maven
cromoteca Dec 20, 2024
1cadbde
Merge branch 'main' into feat/avoid-running-maven
cromoteca Dec 22, 2024
c669751
remove unneeded lines
taefi Dec 23, 2024
78441c8
Merge branch 'main' into feat/avoid-running-maven
taefi Dec 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,21 +1,50 @@
package com.vaadin.hilla;

import javax.annotation.Nonnull;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;

@Component
public class ApplicationContextProvider implements ApplicationContextAware {
private static ApplicationContext applicationContext;
private static final List<Consumer<ApplicationContext>> pendingActions = new ArrayList<>();

@Override
public void setApplicationContext(ApplicationContext applicationContext)
public void setApplicationContext(
@Nonnull ApplicationContext applicationContext)
throws BeansException {
ApplicationContextProvider.applicationContext = applicationContext;
pendingActions.forEach(action -> action.accept(applicationContext));
pendingActions.clear();
}

public static ApplicationContext getApplicationContext() {
return applicationContext;
}

/**
* Allows scheduling actions that should be run when the application context
* is available, or to run them immediately if the context is already
* available and still active.
*
* @param action
* the action to be scheduled or run immediately
*/
public static void runOnContext(Consumer<ApplicationContext> action) {
if (applicationContext == null
|| (applicationContext instanceof ConfigurableApplicationContext
&& !((ConfigurableApplicationContext) applicationContext)
.isActive())) {
pendingActions.add(action);
} else {
action.accept(applicationContext);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
* Makes the methods of the annotated class available to the browser.
* <p>
* For each class, a corresponding TypeScript class is generated in
* {@code frontend/generated} with TypeScript methods for invoking the methods
* in this class.
* {@code src/main/frontend/generated} with TypeScript methods for invoking the
* methods in this class.
* <p>
* This is an alias for {@link Endpoint}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,27 @@

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

import com.vaadin.flow.server.VaadinContext;
import com.vaadin.flow.server.frontend.FrontendTools;
import com.vaadin.flow.server.frontend.FrontendUtils;
import com.vaadin.flow.server.startup.ApplicationConfiguration;
import com.vaadin.hilla.engine.EngineConfiguration;
import com.vaadin.hilla.engine.GeneratorProcessor;
import com.vaadin.hilla.engine.ParserProcessor;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.aop.framework.AopProxyUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

import com.vaadin.flow.server.VaadinContext;
import com.vaadin.flow.server.frontend.FrontendTools;
import com.vaadin.flow.server.startup.ApplicationConfiguration;

/**
* Handles (re)generation of the TypeScript code.
*/
Expand All @@ -43,11 +49,10 @@ public class EndpointCodeGenerator {

private final EndpointController endpointController;
private final VaadinContext context;
private Path buildDirectory;

private ApplicationConfiguration configuration;
private String nodeExecutable;
private Set<String> classesUsedInOpenApi = null;
private EngineConfiguration engineConfiguration;

/**
* Creates the singleton.
Expand All @@ -74,71 +79,91 @@ public static EndpointCodeGenerator getInstance() {
/**
* Re-generates the endpoint TypeScript and re-registers the endpoints in
* Java.
*
* @throws IOException
* if something went wrong
*/
public void update() throws IOException {
public void update() {
initIfNeeded();
if (configuration.isProductionMode()) {
throw new IllegalStateException(
"This method is not available in production mode");
}

EngineConfiguration engineConfiguration = EngineConfiguration
.loadDirectory(buildDirectory);
ParserProcessor parser = new ParserProcessor(engineConfiguration,
getClass().getClassLoader(), false);
parser.process();
GeneratorProcessor generator = new GeneratorProcessor(
engineConfiguration, nodeExecutable, false);
generator.process();

OpenAPIUtil.getCurrentOpenAPIPath(buildDirectory, false)
.ifPresent(openApiPath -> {
try {
this.endpointController
.registerEndpoints(openApiPath.toUri().toURL());
} catch (IOException e) {
LOGGER.error(
"Endpoints could not be registered due to an exception: ",
e);
}
});
ApplicationContextProvider.runOnContext(applicationContext -> {
List<Class<?>> browserCallables = findBrowserCallables(
engineConfiguration, applicationContext);
ParserProcessor parser = new ParserProcessor(engineConfiguration);
parser.process(browserCallables);

GeneratorProcessor generator = new GeneratorProcessor(
engineConfiguration);
generator.process();

try {
var openApiPath = engineConfiguration.getOpenAPIFile();
this.endpointController
.registerEndpoints(openApiPath.toUri().toURL());
} catch (IOException e) {
throw new RuntimeException(e);
}
});
}

/**
* Finds all beans in the application context that have a browser callable
* annotation.
*
* @param engineConfiguration
* the engine configuration that provides the annotations to
* search for
* @param applicationContext
* the application context to search for beans in
* @return a list of classes that qualify as browser callables
*/
public static List<Class<?>> findBrowserCallables(
EngineConfiguration engineConfiguration,
ApplicationContext applicationContext) {
return engineConfiguration.getEndpointAnnotations().stream()
.map(applicationContext::getBeansWithAnnotation)
.map(Map::values).flatMap(Collection::stream)
// maps to original class when proxies are found
// (also converts to class in all cases)
.map(AopProxyUtils::ultimateTargetClass).distinct()
.collect(Collectors.toList());
}

private void initIfNeeded() {
if (configuration == null) {
configuration = ApplicationConfiguration.get(context);

Path projectFolder = configuration.getProjectFolder().toPath();
buildDirectory = projectFolder
.resolve(configuration.getBuildFolder());

FrontendTools tools = new FrontendTools(configuration,
var frontendTools = new FrontendTools(configuration,
configuration.getProjectFolder());
nodeExecutable = tools.getNodeBinary();
engineConfiguration = new EngineConfiguration.Builder()
.baseDir(configuration.getProjectFolder().toPath())
.buildDir(configuration.getBuildFolder())
.outputDir(
FrontendUtils
.getFrontendGeneratedFolder(
configuration.getFrontendFolder())
.toPath())
.productionMode(false).withDefaultAnnotations()
.nodeCommand(frontendTools.getNodeBinary()).build();
}
}

public Optional<Set<String>> getClassesUsedInOpenApi() throws IOException {
if (classesUsedInOpenApi == null) {
initIfNeeded();
OpenAPIUtil.getCurrentOpenAPIPath(buildDirectory, false)
.ifPresent(openApiPath -> {
if (openApiPath.toFile().exists()) {
try {
classesUsedInOpenApi = OpenAPIUtil
.findOpenApiClasses(
Files.readString(openApiPath));
} catch (IOException e) {
throw new RuntimeException(e);
}
} else {
LOGGER.debug(
"No OpenAPI file is available yet ...");
}
});
var conf = EngineConfiguration.getDefault();
var openApiPath = conf.getOpenAPIFile();
if (openApiPath != null && openApiPath.toFile().exists()) {
try {
classesUsedInOpenApi = OpenAPIUtil
.findOpenApiClasses(Files.readString(openApiPath));
} catch (IOException e) {
throw new RuntimeException(e);
}
} else {
LOGGER.debug("No OpenAPI file is available yet ...");
}
}
return Optional.ofNullable(classesUsedInOpenApi);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,10 @@

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URL;
import java.util.Map;
import java.util.Optional;
import java.util.TreeMap;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -130,10 +124,6 @@ public void registerEndpoints(URL openApiResource) {
endpointBeans
.putAll(context.getBeansWithAnnotation(BrowserCallable.class));

// By default, only register those endpoints included in the Hilla
// OpenAPI definition file
registerEndpointsFromApiDefinition(endpointBeans, openApiResource);

if (endpointRegistry.isEmpty() && !endpointBeans.isEmpty()) {
LOGGER.debug("No endpoints found in openapi.json:"
+ " registering all endpoints found using the Spring context");
Expand Down Expand Up @@ -310,46 +300,6 @@ private ResponseEntity<String> buildEnforcementResponseEntity(
}
}

/**
* Parses the <code>openapi.json</code> file to discover defined endpoints.
*
* @param knownEndpointBeans
* the endpoint beans found in the Spring context
*/
private void registerEndpointsFromApiDefinition(
Map<String, Object> knownEndpointBeans, URL openApiResource) {

if (openApiResource == null) {
LOGGER.debug(
"Resource 'hilla-openapi.json' is not available: endpoints cannot be registered yet");
} else {
try (var stream = openApiResource.openStream()) {
// Read the openapi.json file and extract the tags, which in
// turn define the endpoints and their implementation classes
var rootNode = new ObjectMapper().readTree(stream);
var tagsNode = (ArrayNode) rootNode.get("tags");

if (tagsNode != null) {
// Declared endpoints are first searched as Spring Beans. If
// not found, they are, if possible, instantiated as regular
// classes using their default constructor
tagsNode.forEach(tag -> {
Optional.ofNullable(tag.get("name"))
.map(JsonNode::asText)
.map(knownEndpointBeans::get)
.or(() -> Optional
.ofNullable(tag.get("x-class-name"))
.map(JsonNode::asText)
.map(this::instantiateEndpointByClassName))
.ifPresent(endpointRegistry::registerEndpoint);
});
}
} catch (IOException e) {
LOGGER.warn("Failed to read openapi.json", e);
}
}
}

/**
* Instantiates an endpoint by its class name. Nothing special here, the
* main purpose is to allow to instantiate in a lambda expression and log
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
Expand All @@ -13,7 +12,6 @@
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.vaadin.hilla.engine.EngineConfiguration;
import com.vaadin.hilla.engine.ParserProcessor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -61,35 +59,10 @@ public static String getCurrentOpenAPI(Path buildDirectory,
*/
public static Optional<Path> getCurrentOpenAPIPath(Path buildDirectory,
boolean isProductionMode) throws IOException {
EngineConfiguration engineConfiguration = EngineConfiguration
.loadDirectory(buildDirectory);
if (engineConfiguration == null) {
return Optional.empty();
}
return Optional
.of(engineConfiguration.getOpenAPIFile(isProductionMode));
}

/**
* Generate a new openapi.json and return it, based on the classes in the
* build directory.
*
* @param buildDirectory
* the build directory, {@code target} if running with Maven
* @param isProductionMode
* whether to generate the openapi for production mode
* @return the contents of the generated openapi.json
* @throws IOException
* if something went wrong
*/
public static String generateOpenAPI(Path buildDirectory,
boolean isProductionMode) throws IOException {
EngineConfiguration engineConfiguration = EngineConfiguration
.loadDirectory(buildDirectory);
ParserProcessor parserProcessor = new ParserProcessor(
engineConfiguration, OpenAPIUtil.class.getClassLoader(),
isProductionMode);
return parserProcessor.createOpenAPI();
var engineConfiguration = new EngineConfiguration.Builder()
.buildDir(buildDirectory).productionMode(isProductionMode)
.withDefaultAnnotations().build();
return Optional.of(engineConfiguration.getOpenAPIFile());
}

/**
Expand Down
Loading
Loading