diff --git a/packages/java/hilla-dev-mode/pom.xml b/packages/java/hilla-dev-mode/pom.xml index 5389480bcf..6d3d889457 100644 --- a/packages/java/hilla-dev-mode/pom.xml +++ b/packages/java/hilla-dev-mode/pom.xml @@ -32,10 +32,6 @@ vaadin-dev-server ${flow.version} - - org.springframework.boot - spring-boot-autoconfigure - org.hotswapagent hotswap-agent diff --git a/packages/java/hilla-dev-mode/src/main/java/com/vaadin/hilla/devmode/devtools/DevToolsDatabase.java b/packages/java/hilla-dev-mode/src/main/java/com/vaadin/hilla/devmode/devtools/DevToolsDatabase.java deleted file mode 100644 index b861a3a7d6..0000000000 --- a/packages/java/hilla-dev-mode/src/main/java/com/vaadin/hilla/devmode/devtools/DevToolsDatabase.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.vaadin.hilla.devmode.devtools; - -import javax.sql.DataSource; - -import java.sql.Connection; -import java.util.Optional; - -import com.vaadin.hilla.ApplicationContextProvider; -import org.springframework.beans.factory.ObjectProvider; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.h2.H2ConsoleProperties; - -import com.vaadin.base.devserver.DevToolsInterface; -import com.vaadin.base.devserver.DevToolsMessageHandler; - -import elemental.json.Json; -import elemental.json.JsonObject; - -public class DevToolsDatabase implements DevToolsMessageHandler { - - private boolean autowired = false; - @Autowired - private Optional h2ConsoleProperties; - @Autowired - private ObjectProvider dataSource; - - @Override - public void handleConnect(DevToolsInterface devToolsInterface) { - initIfNeeded(); - JsonObject data = Json.createObject(); - - if (h2ConsoleProperties.isPresent() - && h2ConsoleProperties.get().getEnabled()) { - DataSource ds = dataSource.getIfAvailable(); - if (ds != null) { - JsonObject h2 = Json.createObject(); - h2.put("path", h2ConsoleProperties.get().getPath()); - h2.put("jdbcUrl", getConnectionUrl(ds)); - data.put("h2", h2); - } - } - devToolsInterface.send("devtools-database-init", data); - } - - private void initIfNeeded() { - if (!autowired) { - ApplicationContextProvider.getApplicationContext() - .getAutowireCapableBeanFactory().autowireBean(this); - autowired = true; - } - } - - private String getConnectionUrl(DataSource dataSource) { - try (Connection connection = dataSource.getConnection()) { - return connection.getMetaData().getURL(); - } catch (Exception ex) { - return null; - } - } - - @Override - public boolean handleMessage(String command, JsonObject data, - DevToolsInterface devToolsInterface) { - return false; - } - -} diff --git a/packages/java/hilla-dev-mode/src/main/java/com/vaadin/hilla/devmode/devtools/DevToolsDatabaseLoader.java b/packages/java/hilla-dev-mode/src/main/java/com/vaadin/hilla/devmode/devtools/DevToolsDatabaseLoader.java deleted file mode 100644 index 08badacf36..0000000000 --- a/packages/java/hilla-dev-mode/src/main/java/com/vaadin/hilla/devmode/devtools/DevToolsDatabaseLoader.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.vaadin.hilla.devmode.devtools; - -import java.util.Arrays; -import java.util.List; - -import com.vaadin.flow.server.frontend.TypeScriptBootstrapModifier; - -public class DevToolsDatabaseLoader implements TypeScriptBootstrapModifier { - - @Override - public void modify(List bootstrapTypeScript, - boolean productionMode) { - if (productionMode) { - return; - } - String lines = """ - //@ts-ignore - if (import.meta.env.DEV) { - import("Frontend/generated/jar-resources/dev-tools-database.js"); - } - """; - - bootstrapTypeScript.addAll(Arrays.asList(lines.split("\n"))); - } - -} diff --git a/packages/java/hilla-dev-mode/src/main/resources/META-INF/resources/frontend/dev-tools-database.ts b/packages/java/hilla-dev-mode/src/main/resources/META-INF/resources/frontend/dev-tools-database.ts deleted file mode 100644 index 747f2e31f9..0000000000 --- a/packages/java/hilla-dev-mode/src/main/resources/META-INF/resources/frontend/dev-tools-database.ts +++ /dev/null @@ -1,66 +0,0 @@ -import { LitElement, type TemplateResult, html } from 'lit'; -import { loginUsingUrl, waitForConsole } from './h2-util'; -import type { - DevToolsInterface, - DevToolsPlugin, - MessageHandler, - ServerMessage, -} from 'Frontend/generated/jar-resources/vaadin-dev-tools/vaadin-dev-tools'; - -let devTools: DevToolsInterface; - -type H2Data = { - path: string; - jdbcUrl: string; -}; -export class DevToolsDatabase extends LitElement implements MessageHandler { - declare h2path?: string; - - declare h2jdbcUrl?: string; - - static properties = { h2path: { type: String }, h2jdbcUrl: { type: String } }; - - connectedCallback(): void { - super.connectedCallback(); - this.style.width = '100%'; - } - - handleMessage(message: ServerMessage): boolean { - if (message.command === 'devtools-database-init') { - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access - const data = message.data.h2 as H2Data | undefined; - if (data) { - this.h2path = data.path; - this.h2jdbcUrl = data.jdbcUrl; - } - return true; - } - return false; - } - - render(): TemplateResult { - return html`
- ${!this.h2path - ? 'H2 is not in use' - : ''} -
`; - } - - async openH2Console(): Promise { - const h2Window = window.open(this.h2path)!; - await waitForConsole(h2Window); - loginUsingUrl(h2Window, this.h2jdbcUrl); - } -} - -const plugin: DevToolsPlugin = { - init(devToolsInterface: DevToolsInterface): void { - devTools = devToolsInterface; - devTools.addTab('Database', 'devtools-database'); - }, -}; - -// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access -(window as any).Vaadin.devToolsPlugins.push(plugin); - -customElements.define('devtools-database', DevToolsDatabase); diff --git a/packages/java/hilla-dev-mode/src/main/resources/META-INF/resources/frontend/h2-util.ts b/packages/java/hilla-dev-mode/src/main/resources/META-INF/resources/frontend/h2-util.ts deleted file mode 100644 index e60a6147cd..0000000000 --- a/packages/java/hilla-dev-mode/src/main/resources/META-INF/resources/frontend/h2-util.ts +++ /dev/null @@ -1,22 +0,0 @@ -export async function waitForConsole(h2Win: Window): Promise { - const isLoaded = (): boolean => { - return !!h2Win.document.querySelector("[name='url']"); - }; - let resolve; - const promise = new Promise((r) => { - resolve = r; - }); - const intervalId = setInterval(() => { - if (isLoaded()) { - clearInterval(intervalId); - resolve!(); - } - }, 10); - return promise; -} - -export function loginUsingUrl(h2Window: Window, jdbcUrl: string | undefined) { - const h2Document = h2Window.document; - (h2Document.querySelector("[name='url']") as any).value = jdbcUrl; - (h2Document.querySelector("[type='submit']") as HTMLElement).click(); -} diff --git a/packages/java/hilla-dev-mode/src/main/resources/META-INF/services/com.vaadin.base.devserver.DevToolsMessageHandler b/packages/java/hilla-dev-mode/src/main/resources/META-INF/services/com.vaadin.base.devserver.DevToolsMessageHandler deleted file mode 100644 index b31b186dd4..0000000000 --- a/packages/java/hilla-dev-mode/src/main/resources/META-INF/services/com.vaadin.base.devserver.DevToolsMessageHandler +++ /dev/null @@ -1 +0,0 @@ -com.vaadin.hilla.devmode.devtools.DevToolsDatabase