From 916e98e0b211fdc16dacd5345edda9eddf653799 Mon Sep 17 00:00:00 2001 From: Benny Yen Date: Tue, 2 Jul 2024 21:13:56 +0800 Subject: [PATCH] refactor: remove vite-webmvc modules --- .idea/gradle.xml | 2 - build.gradle.kts | 2 +- gradle.properties | 2 +- settings.gradle.kts | 2 - vite-spring-webmvc-jre8/build.gradle.kts | 118 ---------- .../servlet/annotation/EnableVite.java | 37 ---- .../servlet/annotation/package-info.java | 9 - .../benny123tw/servlet/config/ViteConfig.java | 63 ------ .../servlet/config/ViteProperties.java | 62 ------ .../servlet/config/package-info.java | 20 -- .../benny123tw/servlet/package-info.java | 9 - .../benny123tw/servlet/tags/ViteImport.java | 209 ------------------ .../benny123tw/servlet/tags/package-info.java | 20 -- .../src/main/resources/META-INF/vite.tld | 49 ---- vite-spring-webmvc/README.md | 169 -------------- vite-spring-webmvc/build.gradle.kts | 127 ----------- .../servlet/annotation/EnableVite.java | 37 ---- .../servlet/annotation/package-info.java | 9 - .../benny123tw/servlet/config/ViteConfig.java | 63 ------ .../servlet/config/ViteProperties.java | 62 ------ .../servlet/config/package-info.java | 20 -- .../benny123tw/servlet/package-info.java | 9 - .../benny123tw/servlet/tags/ViteImport.java | 204 ----------------- .../benny123tw/servlet/tags/package-info.java | 20 -- .../src/main/resources/META-INF/vite.tld | 49 ---- .../benny123tw/servlet/TestApplication.java | 15 -- .../servlet/ViteDefaultPropertiesTest.java | 30 --- .../servlet/VitePropertiesTest.java | 29 --- .../servlet/tags/ViteImportTest.java | 79 ------- .../src/test/resources/.vite/manifest.json | 53 ----- .../resources/application-test.properties | 3 - 31 files changed, 2 insertions(+), 1580 deletions(-) delete mode 100644 vite-spring-webmvc-jre8/build.gradle.kts delete mode 100644 vite-spring-webmvc-jre8/src/main/java/io/github/benny123tw/servlet/annotation/EnableVite.java delete mode 100644 vite-spring-webmvc-jre8/src/main/java/io/github/benny123tw/servlet/annotation/package-info.java delete mode 100644 vite-spring-webmvc-jre8/src/main/java/io/github/benny123tw/servlet/config/ViteConfig.java delete mode 100644 vite-spring-webmvc-jre8/src/main/java/io/github/benny123tw/servlet/config/ViteProperties.java delete mode 100644 vite-spring-webmvc-jre8/src/main/java/io/github/benny123tw/servlet/config/package-info.java delete mode 100644 vite-spring-webmvc-jre8/src/main/java/io/github/benny123tw/servlet/package-info.java delete mode 100644 vite-spring-webmvc-jre8/src/main/java/io/github/benny123tw/servlet/tags/ViteImport.java delete mode 100644 vite-spring-webmvc-jre8/src/main/java/io/github/benny123tw/servlet/tags/package-info.java delete mode 100644 vite-spring-webmvc-jre8/src/main/resources/META-INF/vite.tld delete mode 100644 vite-spring-webmvc/README.md delete mode 100644 vite-spring-webmvc/build.gradle.kts delete mode 100644 vite-spring-webmvc/src/main/java/io/github/benny123tw/servlet/annotation/EnableVite.java delete mode 100644 vite-spring-webmvc/src/main/java/io/github/benny123tw/servlet/annotation/package-info.java delete mode 100644 vite-spring-webmvc/src/main/java/io/github/benny123tw/servlet/config/ViteConfig.java delete mode 100644 vite-spring-webmvc/src/main/java/io/github/benny123tw/servlet/config/ViteProperties.java delete mode 100644 vite-spring-webmvc/src/main/java/io/github/benny123tw/servlet/config/package-info.java delete mode 100644 vite-spring-webmvc/src/main/java/io/github/benny123tw/servlet/package-info.java delete mode 100644 vite-spring-webmvc/src/main/java/io/github/benny123tw/servlet/tags/ViteImport.java delete mode 100644 vite-spring-webmvc/src/main/java/io/github/benny123tw/servlet/tags/package-info.java delete mode 100644 vite-spring-webmvc/src/main/resources/META-INF/vite.tld delete mode 100644 vite-spring-webmvc/src/test/java/io/github/benny123tw/servlet/TestApplication.java delete mode 100644 vite-spring-webmvc/src/test/java/io/github/benny123tw/servlet/ViteDefaultPropertiesTest.java delete mode 100644 vite-spring-webmvc/src/test/java/io/github/benny123tw/servlet/VitePropertiesTest.java delete mode 100644 vite-spring-webmvc/src/test/java/io/github/benny123tw/servlet/tags/ViteImportTest.java delete mode 100644 vite-spring-webmvc/src/test/resources/.vite/manifest.json delete mode 100644 vite-spring-webmvc/src/test/resources/application-test.properties diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 809f6a1..3572a64 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -12,8 +12,6 @@ diff --git a/build.gradle.kts b/build.gradle.kts index 62cf135..03ccab5 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ plugins { } description = "Java library for Vite integration." -group = "io.github.benny123tw" +group = "com.javite" allprojects { repositories { diff --git a/gradle.properties b/gradle.properties index 9c71418..11e1aa6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1 +1 @@ -version=0.1.3 +version=0.1.4-alpha diff --git a/settings.gradle.kts b/settings.gradle.kts index fd6e685..7238250 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,7 +1,5 @@ rootProject.name = "javite" -include("vite-spring-webmvc") -include("vite-spring-webmvc-jre8") include("javite-core") include("javite-webmvc") include("javite-webmvc-jre8") diff --git a/vite-spring-webmvc-jre8/build.gradle.kts b/vite-spring-webmvc-jre8/build.gradle.kts deleted file mode 100644 index a9a4c7d..0000000 --- a/vite-spring-webmvc-jre8/build.gradle.kts +++ /dev/null @@ -1,118 +0,0 @@ -import com.vanniktech.maven.publish.JavaLibrary -import com.vanniktech.maven.publish.JavadocJar -import com.vanniktech.maven.publish.SonatypeHost - -plugins { - `java-library` - alias(libs.plugins.publish.maven) -} - -description = "Vite - Spring Web MVC for JRE 8" -group = "io.github.benny123tw" - -java { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 -} - -tasks.withType { - options.release.set(8) -} - -repositories { - mavenCentral() -} - -dependencies { - implementation(libs.jre8.spring.core) - implementation(libs.jre8.spring.webmvc) - implementation(libs.jre8.spring.boot.starter) - implementation(libs.jre8.spring.boot.starter.web) - implementation(libs.jre8.jackson.databind) - - compileOnly(libs.jre8.javax.servlet) - compileOnly(libs.jre8.javax.servlet.jsp) - - annotationProcessor(libs.jre8.spring.boot.configuration.processor) -} - -tasks.jar { - enabled = true - archiveClassifier.set("") - manifest { - attributes( - mapOf( - "Implementation-Title" to project.name, - "Implementation-Version" to project.version, - ), - ) - } -} - -mavenPublishing { - publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL) - - signAllPublications() -} - -object Meta { - const val DESC = "Vite integration with Spring Web MVC for JRE8." - const val LICENSE = "MIT" - const val LICENSE_URL = "https://opensource.org/licenses/mit" - const val GITHUB_REPO = "benny123tw/javite" - const val DEVELOPER_ID = "benny123tw" - const val DEVELOPER_NAME = "Benny Yen" - const val DEVELOPER_ORGANIZATION = "io.github.benny123tw" - const val DEVELOPER_ORGANIZATION_URL = "https://www.github.com/benny123tw" -} - -mavenPublishing { - println("Publish ${project.group}, ${project.name}, ${project.version}") - coordinates(project.group.toString(), project.name, project.version.toString()) - - // Correctly configure JavaLibrary with Javadoc and sources JARs - configure( - JavaLibrary( - javadocJar = JavadocJar.Javadoc(), - sourcesJar = true - ) - ) - - pom { - name.set(project.name) - description.set(Meta.DESC) - inceptionYear.set("2024") - url.set("https://github.com/${Meta.GITHUB_REPO}") - licenses { - license { - name.set(Meta.LICENSE) - url.set(Meta.LICENSE_URL) - } - } - developers { - developer { - id.set(Meta.DEVELOPER_ID) - name.set(Meta.DEVELOPER_NAME) - organization.set(Meta.DEVELOPER_ORGANIZATION) - organizationUrl.set(Meta.DEVELOPER_ORGANIZATION_URL) - } - } - scm { - url.set("https://github.com/${Meta.GITHUB_REPO}.git") - connection.set("scm:git:git://github.com/${Meta.GITHUB_REPO}.git") - developerConnection.set("scm:git:git://github.com/${Meta.GITHUB_REPO}.git") - } - issueManagement { - url.set("https://github.com/${Meta.GITHUB_REPO}/issues") - } - } -} - -// gradle locking of dependency versions -// *required+used for trivy scan -dependencyLocking { - lockAllConfigurations() -} - -// always run subproject task with parent -rootProject.tasks.dependencies { dependsOn(tasks.dependencies) } diff --git a/vite-spring-webmvc-jre8/src/main/java/io/github/benny123tw/servlet/annotation/EnableVite.java b/vite-spring-webmvc-jre8/src/main/java/io/github/benny123tw/servlet/annotation/EnableVite.java deleted file mode 100644 index c060e3d..0000000 --- a/vite-spring-webmvc-jre8/src/main/java/io/github/benny123tw/servlet/annotation/EnableVite.java +++ /dev/null @@ -1,37 +0,0 @@ -package io.github.benny123tw.servlet.annotation; - -import io.github.benny123tw.servlet.config.ViteConfig; -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; -import org.springframework.context.annotation.Import; - -/** - * Annotation to enable Vite integration in a Spring MVC application. - * - *

When this annotation is applied to a {@code @Configuration} class, it imports the - * {@link ViteConfig} configuration, which sets up the necessary beans and configuration - * for using Vite in the application.

- * - *

Usage:

- *
- * @Configuration
- * @EnableVite
- * public class AppConfig {
- *     // Your other Spring configuration
- * }
- * 
- * - *

This annotation is typically applied at the top-level configuration class to ensure - * that Vite's configuration is loaded and available to the application context.

- * - * @see io.github.benny123tw.servlet.config.ViteConfig - */ -@Retention(java.lang.annotation.RetentionPolicy.RUNTIME) -@Target(ElementType.TYPE) -@Documented -@Import(ViteConfig.class) -public @interface EnableVite { - -} diff --git a/vite-spring-webmvc-jre8/src/main/java/io/github/benny123tw/servlet/annotation/package-info.java b/vite-spring-webmvc-jre8/src/main/java/io/github/benny123tw/servlet/annotation/package-info.java deleted file mode 100644 index 046c180..0000000 --- a/vite-spring-webmvc-jre8/src/main/java/io/github/benny123tw/servlet/annotation/package-info.java +++ /dev/null @@ -1,9 +0,0 @@ -/** - * This package contains annotations for enabling Vite integration in Spring MVC applications. - * - *

The primary annotation in this package is {@link EnableVite}, which when applied to a - * configuration class, imports the necessary configuration for Vite.

- * - * @see io.github.benny123tw.servlet.config.ViteConfig - */ -package io.github.benny123tw.servlet.annotation; diff --git a/vite-spring-webmvc-jre8/src/main/java/io/github/benny123tw/servlet/config/ViteConfig.java b/vite-spring-webmvc-jre8/src/main/java/io/github/benny123tw/servlet/config/ViteConfig.java deleted file mode 100644 index 3817bcc..0000000 --- a/vite-spring-webmvc-jre8/src/main/java/io/github/benny123tw/servlet/config/ViteConfig.java +++ /dev/null @@ -1,63 +0,0 @@ -package io.github.benny123tw.servlet.config; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; -import org.springframework.beans.factory.annotation.Value; - -/** - * Provides an out-of-the-box configuration for integrating Vite with Spring MVC applications. - * - *

This configuration class automatically scans the package {@code io.github.benny123tw.servlet.config} - * for components and provides the necessary beans and properties to enable Vite integration.

- * - *

The following properties can be configured in the application's {@code application.properties} file:

- * - * - *

Usage example:

- *
- * @Configuration
- * @EnableVite
- * public class AppConfig {
- *     // Your other Spring configuration
- * }
- * 
- * - * @see io.github.benny123tw.servlet.annotation.EnableVite - */ -@Configuration -@ComponentScan(basePackages = "io.github.benny123tw.servlet.config") -public class ViteConfig { - - @Value("${vite.debug:true}") - private boolean debug; - - @Value("${vite.manifestPath:/WEB-INF/dist/.vite/manifest.json}") - private String manifestPath; - - @Value("${vite.localServerUrl:http://localhost:5173}") - private String localServerUrl; - - @Value("${vite.resourcePath:/resources}") - private String resourcePath; - - /** - * Creates a {@link ViteProperties} bean configured with the application's Vite settings. - * - * @return a configured {@link ViteProperties} instance - */ - @Bean - public ViteProperties viteProperties() { - ViteProperties viteProperties = new ViteProperties(); - viteProperties.setDebug(debug); - viteProperties.setManifestPath(manifestPath); - viteProperties.setLocalServerUrl(localServerUrl); - viteProperties.setResourcePath(resourcePath); - return viteProperties; - } -} diff --git a/vite-spring-webmvc-jre8/src/main/java/io/github/benny123tw/servlet/config/ViteProperties.java b/vite-spring-webmvc-jre8/src/main/java/io/github/benny123tw/servlet/config/ViteProperties.java deleted file mode 100644 index fabde4e..0000000 --- a/vite-spring-webmvc-jre8/src/main/java/io/github/benny123tw/servlet/config/ViteProperties.java +++ /dev/null @@ -1,62 +0,0 @@ -package io.github.benny123tw.servlet.config; - -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.stereotype.Component; - -@Component -@ConfigurationProperties(prefix = "vite") -public class ViteProperties { - - /** - * Whether to enable debug mode in Vite. - */ - private boolean debug = true; - - /** - * The path of the manifest file generated by Vite. - */ - private String manifestPath = "/WEB-INF/dist/.vite/manifest.json"; - - /** - * The local server URL for Vite development. - */ - private String localServerUrl = "http://localhost:5173"; - - /** - * The path to the resources. - */ - private String resourcePath = "/resources"; - - public boolean isDebug() { - return debug; - } - - public void setDebug(boolean debug) { - this.debug = debug; - } - - public String getManifestPath() { - return manifestPath; - } - - public void setManifestPath(String manifestPath) { - this.manifestPath = manifestPath; - } - - public String getLocalServerUrl() { - return localServerUrl; - } - - public void setLocalServerUrl(String localServerUrl) { - this.localServerUrl = localServerUrl; - } - - public String getResourcePath() { - return resourcePath; - } - - public void setResourcePath(String resourcePath) { - this.resourcePath = resourcePath; - } - -} diff --git a/vite-spring-webmvc-jre8/src/main/java/io/github/benny123tw/servlet/config/package-info.java b/vite-spring-webmvc-jre8/src/main/java/io/github/benny123tw/servlet/config/package-info.java deleted file mode 100644 index 5507b9d..0000000 --- a/vite-spring-webmvc-jre8/src/main/java/io/github/benny123tw/servlet/config/package-info.java +++ /dev/null @@ -1,20 +0,0 @@ -/** - * This package contains the configuration classes for integrating Vite with Spring MVC applications. - * - *

Classes in this package provide configuration and beans necessary for setting up Vite in a Spring MVC - * application, including properties for the Vite manifest file, local development server URL, resource paths, - * and debug settings.

- * - *

Usage example:

- *
- * @Configuration
- * @EnableVite
- * public class AppConfig {
- *     // Your other Spring configuration
- * }
- * 
- * - * @see io.github.benny123tw.servlet.annotation.EnableVite - * @see io.github.benny123tw.servlet.config.ViteConfig - */ -package io.github.benny123tw.servlet.config; diff --git a/vite-spring-webmvc-jre8/src/main/java/io/github/benny123tw/servlet/package-info.java b/vite-spring-webmvc-jre8/src/main/java/io/github/benny123tw/servlet/package-info.java deleted file mode 100644 index 48a045e..0000000 --- a/vite-spring-webmvc-jre8/src/main/java/io/github/benny123tw/servlet/package-info.java +++ /dev/null @@ -1,9 +0,0 @@ -/** - * Defines the XML configuration namespace for Spring MVC. - */ -@NonNullApi -@NonNullFields -package io.github.benny123tw.servlet; - -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; diff --git a/vite-spring-webmvc-jre8/src/main/java/io/github/benny123tw/servlet/tags/ViteImport.java b/vite-spring-webmvc-jre8/src/main/java/io/github/benny123tw/servlet/tags/ViteImport.java deleted file mode 100644 index abbd68b..0000000 --- a/vite-spring-webmvc-jre8/src/main/java/io/github/benny123tw/servlet/tags/ViteImport.java +++ /dev/null @@ -1,209 +0,0 @@ -package io.github.benny123tw.servlet.tags; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import io.github.benny123tw.servlet.config.ViteProperties; -//import jakarta.servlet.ServletContext; -//import jakarta.servlet.jsp.JspException; -//import jakarta.servlet.jsp.JspWriter; -//import jakarta.servlet.jsp.PageContext; -//import jakarta.servlet.jsp.tagext.SimpleTagSupport; -import javax.servlet.ServletContext; -import javax.servlet.jsp.JspException; -import javax.servlet.jsp.JspWriter; -import javax.servlet.jsp.PageContext; -import javax.servlet.jsp.tagext.SimpleTagSupport; -import java.io.File; -import java.io.IOException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.lang.Nullable; -import org.springframework.web.context.WebApplicationContext; -import org.springframework.web.context.support.WebApplicationContextUtils; - -/** - * Custom JSP tag to import Vite-generated assets. - */ -public class ViteImport extends SimpleTagSupport { - - private static final Logger log = LoggerFactory.getLogger(ViteImport.class); - - @Nullable - private String entry; - - @Nullable - private String manifestPath; - - @Nullable - private String localServerUrl; - - @Nullable - private Boolean isDebug; - - @Nullable - private String resourcePath; - - /** - * Sets the entry point for the Vite asset. - * - * @param entry the entry point of the Vite asset - */ - public void setEntry(String entry) { - this.entry = entry; - } - - /** - * Sets the path to the Vite manifest file. - * - * @param manifestPath the manifest file path - */ - public void setManifestPath(String manifestPath) { - this.manifestPath = manifestPath; - } - - /** - * Sets the local server URL for Vite development. - * - * @param localServerUrl the local server URL - */ - public void setLocalServerUrl(String localServerUrl) { - this.localServerUrl = localServerUrl; - } - - /** - * Sets the debug flag. - * - * @param isDebug the debug flag - */ - public void setDebug(boolean isDebug) { - this.isDebug = isDebug; - } - - /** - * Sets the resource path. - * - * @param resourcePath the resource path - */ - public void setResourcePath(String resourcePath) { - this.resourcePath = resourcePath; - } - - /** - * Processes the custom tag to import Vite assets based on the environment. - * - * @throws JspException if a JSP error occurs - * @throws IOException if an I/O error occurs - */ - @Override - public void doTag() throws JspException, IOException { - log.info("doTag() called"); - - ServletContext servletContext = ((PageContext) getJspContext()).getServletContext(); - WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext( servletContext); - JspWriter out = getJspContext().getOut(); - - if (ctx == null) { - log.error("No WebApplicationContext found"); - throw new JspException("No WebApplicationContext found"); - } - - ViteProperties viteProperties = ctx.getBean(ViteProperties.class); - - isDebug = isDebug != null ? isDebug : viteProperties.isDebug(); - String effectiveManifestPath = manifestPath != null ? manifestPath : viteProperties.getManifestPath(); - String effectiveLocalServerUrl = localServerUrl != null ? localServerUrl : viteProperties.getLocalServerUrl(); - String effectiveResourcePath = resourcePath != null ? resourcePath : viteProperties.getResourcePath(); - - log.info("isDebug: {}", isDebug); - log.debug("effectiveManifestPath: {}, effectiveLocalServerUrl: {}, effectiveResourcePath: {}", effectiveManifestPath, effectiveLocalServerUrl, - effectiveResourcePath); - - if (isDebug) { - log.info("Handling development environment"); - handleDevEnvironment(out, effectiveLocalServerUrl); - } else { - log.info("Handling production environment"); - handleProdEnvironment(out, servletContext, effectiveManifestPath, effectiveResourcePath); - } - } - - - - /** - * Handles the production environment by loading assets from the manifest file. - * - * @param out the JSP writer - * @param servletContext the servlet context - * @param manifestFilePath the manifest file path - * @param resourcePath the resource path - * @throws IOException if an I/O error occurs - */ - private void handleProdEnvironment(JspWriter out, ServletContext servletContext, String manifestFilePath, String resourcePath) throws IOException { - File manifestFile = new File(servletContext.getRealPath(manifestFilePath)); - log.debug("Looking for manifest file at: {}", manifestFile.getAbsolutePath()); - if (manifestFile.exists()) { - ObjectMapper mapper = new ObjectMapper(); - JsonNode manifest = mapper.readTree(manifestFile); - JsonNode entryNode = manifest.get(entry); - - if (entryNode != null) { - printJsImport(out, servletContext, entryNode, resourcePath); - printCssImports(out, servletContext, entryNode, resourcePath); - } - } else { - log.error("Manifest file not found at: {}", manifestFile.getAbsolutePath()); - } - } - - /** - * Handles the development environment by pointing to the local Vite server. - * - * @param out the JSP writer - * @param localServerUrl the local server URL - * @throws IOException if an I/O error occurs - */ - private void handleDevEnvironment(JspWriter out, String localServerUrl) throws IOException { - log.info("Adding script tags for dev environment"); - out.print(""); - out.print(""); - } - - /** - * Prints the JavaScript import statement. - * - * @param out the JSP writer - * @param servletContext the servlet context - * @param entryNode the manifest entry node - * @param resourcePath the resource path - * @throws IOException if an I/O error occurs - */ - private void printJsImport(JspWriter out, ServletContext servletContext, JsonNode entryNode, String resourcePath) throws IOException { - String jsFile = entryNode.get("file").asText(); - String contextPath = servletContext.getContextPath(); - log.debug("Printing JS import: {}", jsFile); - out.print(""); - log.info("JS import printed"); - } - - /** - * Prints the CSS import statements. - * - * @param out the JSP writer - * @param servletContext the servlet context - * @param entryNode the manifest entry node - * @param resourcePath the resource path - * @throws IOException if an I/O error occurs - */ - private void printCssImports(JspWriter out, ServletContext servletContext, JsonNode entryNode, String resourcePath) throws IOException { - JsonNode cssFiles = entryNode.get("css"); - if (cssFiles != null) { - String contextPath = servletContext.getContextPath(); - for (JsonNode cssFile : cssFiles) { - log.debug("Printing CSS import: {}", cssFile.asText()); - out.print(""); - log.info("CSS import printed"); - } - } - } - -} diff --git a/vite-spring-webmvc-jre8/src/main/java/io/github/benny123tw/servlet/tags/package-info.java b/vite-spring-webmvc-jre8/src/main/java/io/github/benny123tw/servlet/tags/package-info.java deleted file mode 100644 index 97ce55b..0000000 --- a/vite-spring-webmvc-jre8/src/main/java/io/github/benny123tw/servlet/tags/package-info.java +++ /dev/null @@ -1,20 +0,0 @@ -/** - *

This package contains Vite's JSP standard tag library for JSP 2.0+. - * Supports JSP view implementations within Spring's Web MVC framework. - * For more details on each tag, see the list of tags below with links to - * individual tag classes, or check the {@code vite.tld} file: - * - *

- * - *

Please note that the various tags generated by this form tag library are - * compliant with https://www.w3.org/TR/xhtml1/ and attendant - * https://www.w3.org/TR/xhtml1/dtds.html#a_dtd_XHTML-1.0-Strict. - */ -@NonNullApi -@NonNullFields -package io.github.benny123tw.servlet.tags; - -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; diff --git a/vite-spring-webmvc-jre8/src/main/resources/META-INF/vite.tld b/vite-spring-webmvc-jre8/src/main/resources/META-INF/vite.tld deleted file mode 100644 index 83e38a9..0000000 --- a/vite-spring-webmvc-jre8/src/main/resources/META-INF/vite.tld +++ /dev/null @@ -1,49 +0,0 @@ - - - - Vite JSP Tag Library - 1.0 - vite - https://github.com/benny123tw/tags - - - Import a Vite asset. - import - io.github.benny123tw.servlet.tags.ViteImport - empty - - The entry point of the Vite asset to be imported. - entry - true - true - - - The path to the Vite manifest file. - manifestPath - false - true - - - The URL of the local Vite development server. - localServerUrl - false - true - - - Flag to indicate if the debug mode is enabled. - debug - false - true - - - The path to the public resources. - resourcePath - false - true - - - - diff --git a/vite-spring-webmvc/README.md b/vite-spring-webmvc/README.md deleted file mode 100644 index 8ad7cd1..0000000 --- a/vite-spring-webmvc/README.md +++ /dev/null @@ -1,169 +0,0 @@ -# JaVite for JSP and Spring MVC - -This project provides a custom JSP tag for integrating Vite-generated assets with JSP and Spring MVC -applications. It allows you to seamlessly import Vite-built JavaScript and CSS assets into your JSP -views, making it easier to modernize legacy web applications. - -## Features - -- Import Vite-built JavaScript and CSS assets into JSP views. -- Seamlessly switch between development and production environments. -- Customizable paths for the Vite manifest file and public resources. - -## Getting Started - -If you need Java 8 support, please use [vite-spring-webmvc-jre8](https://github.com/benny123tw/javite/tree/main/vite-spring-webmvc-jre8). - -### Prerequisites - -- Java 17 or higher -- Spring MVC -- Vite - -### Installation - -Add the following dependency to your Maven `pom.xml` file: - -```xml - - io.github.benny123tw - vite-spring-webmvc - 0.0.1 - - - - - io.github.benny123tw - vite-spring-webmvc-jre8 - 0.0.1 - -``` - -Or for Gradle: - -```groovy -implementation 'io.github.benny123tw:vite-spring-webmvc:0.0.1' - -// Java 8 support -implementation 'io.github.benny123tw:vite-spring-webmvc-jre8:0.0.1' -``` - -### Configuration - -Configure the `ViteProperties` in your Spring application configuration. - -#### application.properties - -```properties -vite.debug=true -# The path to the Vite manifest file -vite.manifestPath=/WEB-INF/dist/.vite/manifest.json -# The URL of the local Vite development server -vite.localServerUrl=http://localhost:5173 -# The path to the public resources -vite.resourcePath=/resources -``` - -#### application.yaml - -```yaml -vite: - debug: true - manifestPath: /WEB-INF/dist/.vite/manifest.json - localServerUrl: http://localhost:5173 - resourcePath: /resources -``` - -### Usage - -#### Configure Web MVC - -Configure your Spring MVC application to handle resource paths: - -```java - -@Configuration -@EnableWebMvc -@ComponentScan(basePackages = "com.benny", - includeFilters = @ComponentScan.Filter(type = FilterType.ANNOTATION, - value = Controller.class)) -public class WebConfig implements WebMvcConfigurer { - - @Bean - public InternalResourceViewResolver viewResolver() { - InternalResourceViewResolver viewResolver = new InternalResourceViewResolver(); - viewResolver.setPrefix("/WEB-INF/views/"); - viewResolver.setSuffix(".jsp"); - return viewResolver; - } - - @Override - public void addResourceHandlers(ResourceHandlerRegistry registry) { - registry.addResourceHandler("/resources/**") - .addResourceLocations("/WEB-INF/dist/"); - } - -} -``` - -#### Enable Vite Configuration - -Configure your Spring application to enable Vite: - -```java -import io.github.benny123tw.servlet.annotation.EnableVite; - -@Configuration -@ComponentScan(basePackages = "com.benny", - includeFilters = @Filter(type = FilterType.ANNOTATION, value = Configuration.class)) -@EnableVite -public class AppConfig { - - @Bean - public static PropertySourcesPlaceholderConfigurer propertyConfigInDev() { - return new PropertySourcesPlaceholderConfigurer(); - } - - @Configuration - @Profile("dev") - @PropertySource("classpath:application-dev.properties") - static class DevConfig { - - } - -} -``` - -#### Using the `ViteImport` Tag in JSP - -Add the taglib declaration to your JSP file and use the `vite:import` tag to include Vite assets: - -```jsp -<%@ taglib uri="https://github.com/benny123tw/tags" prefix="vite" %> - - - - - My Application - - - -

Welcome to My Application

- - -``` - -Full example available on [benny123tw/vite-jsp-demo](https://github.com/benny123tw/vite-jsp-demo). - -## Contributing - -Contributions are welcome! Please feel free to submit a Pull Request. - -## License - -This project is licensed under the MIT License. See the [LICENSE](../LICENSE) file for details. - -## Acknowledgements - -- [Spring Framework](https://spring.io/projects/spring-framework) -- [Vite](https://vitejs.dev/) diff --git a/vite-spring-webmvc/build.gradle.kts b/vite-spring-webmvc/build.gradle.kts deleted file mode 100644 index 5388e31..0000000 --- a/vite-spring-webmvc/build.gradle.kts +++ /dev/null @@ -1,127 +0,0 @@ -import com.vanniktech.maven.publish.JavaLibrary -import com.vanniktech.maven.publish.JavadocJar -import com.vanniktech.maven.publish.SonatypeHost - -plugins { - `java-library` - alias(libs.plugins.spring.boot) - alias(libs.plugins.spring.dependency.management) - alias(libs.plugins.publish.maven) -} - -description = "Vite - Spring Web MVC" -group = "io.github.benny123tw" - -dependencies { - implementation(libs.spring.core) - implementation(libs.spring.webmvc) - implementation(libs.spring.boot.starter) - implementation(libs.spring.boot.starter.web) - implementation(libs.jackson.databind) - implementation(libs.jakarta.servlet) - implementation(libs.jakarta.servlet.jsp) - annotationProcessor(libs.spring.boot.configuration.processor) - - testImplementation(libs.spring.boot.starter.test) - testImplementation(libs.junit) -} - -configurations.matching { it.name.startsWith("dokka") }.configureEach { - resolutionStrategy.eachDependency { - if (requested.group.startsWith("com.fasterxml.jackson")) { - // override jackson for Dokka as a workaround - // see: https://github.com/Kotlin/dokka/issues/3472 - useVersion("2.15.3") - } - } -} - -tasks.named("test") { - // Use JUnit Platform for unit tests. - useJUnitPlatform() -} - -tasks.bootJar { - enabled = false -} - -tasks.jar { - enabled = true - archiveClassifier.set("") - manifest { - attributes( - mapOf( - "Implementation-Title" to project.name, - "Implementation-Version" to project.version, - ), - ) - } -} - -mavenPublishing { - publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL) - - signAllPublications() -} - -object Meta { - const val DESC = "Vite integration with Spring Web MVC." - const val LICENSE = "MIT" - const val LICENSE_URL = "https://opensource.org/licenses/mit" - const val GITHUB_REPO = "benny123tw/javite" - const val DEVELOPER_ID = "benny123tw" - const val DEVELOPER_NAME = "Benny Yen" - const val DEVELOPER_ORGANIZATION = "io.github.benny123tw" - const val DEVELOPER_ORGANIZATION_URL = "https://www.github.com/benny123tw" -} - -mavenPublishing { - println("Publish ${project.group}, ${project.name}, ${project.version}") - coordinates(project.group.toString(), project.name, project.version.toString()) - - // Correctly configure JavaLibrary with Javadoc and sources JARs - configure( - JavaLibrary( - javadocJar = JavadocJar.Javadoc(), - sourcesJar = true - ) - ) - - pom { - name.set(project.name) - description.set(Meta.DESC) - inceptionYear.set("2024") - url.set("https://github.com/${Meta.GITHUB_REPO}") - licenses { - license { - name.set(Meta.LICENSE) - url.set(Meta.LICENSE_URL) - } - } - developers { - developer { - id.set(Meta.DEVELOPER_ID) - name.set(Meta.DEVELOPER_NAME) - organization.set(Meta.DEVELOPER_ORGANIZATION) - organizationUrl.set(Meta.DEVELOPER_ORGANIZATION_URL) - } - } - scm { - url.set("https://github.com/${Meta.GITHUB_REPO}.git") - connection.set("scm:git:git://github.com/${Meta.GITHUB_REPO}.git") - developerConnection.set("scm:git:git://github.com/${Meta.GITHUB_REPO}.git") - } - issueManagement { - url.set("https://github.com/${Meta.GITHUB_REPO}/issues") - } - } -} - -// gradle locking of dependency versions -// *required+used for trivy scan -dependencyLocking { - lockAllConfigurations() -} - -// always run subproject task with parent -rootProject.tasks.dependencies { dependsOn(tasks.dependencies) } diff --git a/vite-spring-webmvc/src/main/java/io/github/benny123tw/servlet/annotation/EnableVite.java b/vite-spring-webmvc/src/main/java/io/github/benny123tw/servlet/annotation/EnableVite.java deleted file mode 100644 index c060e3d..0000000 --- a/vite-spring-webmvc/src/main/java/io/github/benny123tw/servlet/annotation/EnableVite.java +++ /dev/null @@ -1,37 +0,0 @@ -package io.github.benny123tw.servlet.annotation; - -import io.github.benny123tw.servlet.config.ViteConfig; -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; -import org.springframework.context.annotation.Import; - -/** - * Annotation to enable Vite integration in a Spring MVC application. - * - *

When this annotation is applied to a {@code @Configuration} class, it imports the - * {@link ViteConfig} configuration, which sets up the necessary beans and configuration - * for using Vite in the application.

- * - *

Usage:

- *
- * @Configuration
- * @EnableVite
- * public class AppConfig {
- *     // Your other Spring configuration
- * }
- * 
- * - *

This annotation is typically applied at the top-level configuration class to ensure - * that Vite's configuration is loaded and available to the application context.

- * - * @see io.github.benny123tw.servlet.config.ViteConfig - */ -@Retention(java.lang.annotation.RetentionPolicy.RUNTIME) -@Target(ElementType.TYPE) -@Documented -@Import(ViteConfig.class) -public @interface EnableVite { - -} diff --git a/vite-spring-webmvc/src/main/java/io/github/benny123tw/servlet/annotation/package-info.java b/vite-spring-webmvc/src/main/java/io/github/benny123tw/servlet/annotation/package-info.java deleted file mode 100644 index 046c180..0000000 --- a/vite-spring-webmvc/src/main/java/io/github/benny123tw/servlet/annotation/package-info.java +++ /dev/null @@ -1,9 +0,0 @@ -/** - * This package contains annotations for enabling Vite integration in Spring MVC applications. - * - *

The primary annotation in this package is {@link EnableVite}, which when applied to a - * configuration class, imports the necessary configuration for Vite.

- * - * @see io.github.benny123tw.servlet.config.ViteConfig - */ -package io.github.benny123tw.servlet.annotation; diff --git a/vite-spring-webmvc/src/main/java/io/github/benny123tw/servlet/config/ViteConfig.java b/vite-spring-webmvc/src/main/java/io/github/benny123tw/servlet/config/ViteConfig.java deleted file mode 100644 index 3817bcc..0000000 --- a/vite-spring-webmvc/src/main/java/io/github/benny123tw/servlet/config/ViteConfig.java +++ /dev/null @@ -1,63 +0,0 @@ -package io.github.benny123tw.servlet.config; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; -import org.springframework.beans.factory.annotation.Value; - -/** - * Provides an out-of-the-box configuration for integrating Vite with Spring MVC applications. - * - *

This configuration class automatically scans the package {@code io.github.benny123tw.servlet.config} - * for components and provides the necessary beans and properties to enable Vite integration.

- * - *

The following properties can be configured in the application's {@code application.properties} file:

- *
    - *
  • {@code vite.debug} - Enables or disables debug mode for Vite integration. Default is {@code true}.
  • - *
  • {@code vite.manifestPath} - Specifies the path to the Vite manifest file. Default is {@code /WEB-INF/dist/.vite/manifest.json}.
  • - *
  • {@code vite.localServerUrl} - Specifies the URL of the local Vite development server. Default is {@code http://localhost:5173}.
  • - *
  • {@code vite.resourcePath} - Specifies the path to Vite resources. Default is {@code /resources}.
  • - *
- * - *

Usage example:

- *
- * @Configuration
- * @EnableVite
- * public class AppConfig {
- *     // Your other Spring configuration
- * }
- * 
- * - * @see io.github.benny123tw.servlet.annotation.EnableVite - */ -@Configuration -@ComponentScan(basePackages = "io.github.benny123tw.servlet.config") -public class ViteConfig { - - @Value("${vite.debug:true}") - private boolean debug; - - @Value("${vite.manifestPath:/WEB-INF/dist/.vite/manifest.json}") - private String manifestPath; - - @Value("${vite.localServerUrl:http://localhost:5173}") - private String localServerUrl; - - @Value("${vite.resourcePath:/resources}") - private String resourcePath; - - /** - * Creates a {@link ViteProperties} bean configured with the application's Vite settings. - * - * @return a configured {@link ViteProperties} instance - */ - @Bean - public ViteProperties viteProperties() { - ViteProperties viteProperties = new ViteProperties(); - viteProperties.setDebug(debug); - viteProperties.setManifestPath(manifestPath); - viteProperties.setLocalServerUrl(localServerUrl); - viteProperties.setResourcePath(resourcePath); - return viteProperties; - } -} diff --git a/vite-spring-webmvc/src/main/java/io/github/benny123tw/servlet/config/ViteProperties.java b/vite-spring-webmvc/src/main/java/io/github/benny123tw/servlet/config/ViteProperties.java deleted file mode 100644 index fabde4e..0000000 --- a/vite-spring-webmvc/src/main/java/io/github/benny123tw/servlet/config/ViteProperties.java +++ /dev/null @@ -1,62 +0,0 @@ -package io.github.benny123tw.servlet.config; - -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.stereotype.Component; - -@Component -@ConfigurationProperties(prefix = "vite") -public class ViteProperties { - - /** - * Whether to enable debug mode in Vite. - */ - private boolean debug = true; - - /** - * The path of the manifest file generated by Vite. - */ - private String manifestPath = "/WEB-INF/dist/.vite/manifest.json"; - - /** - * The local server URL for Vite development. - */ - private String localServerUrl = "http://localhost:5173"; - - /** - * The path to the resources. - */ - private String resourcePath = "/resources"; - - public boolean isDebug() { - return debug; - } - - public void setDebug(boolean debug) { - this.debug = debug; - } - - public String getManifestPath() { - return manifestPath; - } - - public void setManifestPath(String manifestPath) { - this.manifestPath = manifestPath; - } - - public String getLocalServerUrl() { - return localServerUrl; - } - - public void setLocalServerUrl(String localServerUrl) { - this.localServerUrl = localServerUrl; - } - - public String getResourcePath() { - return resourcePath; - } - - public void setResourcePath(String resourcePath) { - this.resourcePath = resourcePath; - } - -} diff --git a/vite-spring-webmvc/src/main/java/io/github/benny123tw/servlet/config/package-info.java b/vite-spring-webmvc/src/main/java/io/github/benny123tw/servlet/config/package-info.java deleted file mode 100644 index 5507b9d..0000000 --- a/vite-spring-webmvc/src/main/java/io/github/benny123tw/servlet/config/package-info.java +++ /dev/null @@ -1,20 +0,0 @@ -/** - * This package contains the configuration classes for integrating Vite with Spring MVC applications. - * - *

Classes in this package provide configuration and beans necessary for setting up Vite in a Spring MVC - * application, including properties for the Vite manifest file, local development server URL, resource paths, - * and debug settings.

- * - *

Usage example:

- *
- * @Configuration
- * @EnableVite
- * public class AppConfig {
- *     // Your other Spring configuration
- * }
- * 
- * - * @see io.github.benny123tw.servlet.annotation.EnableVite - * @see io.github.benny123tw.servlet.config.ViteConfig - */ -package io.github.benny123tw.servlet.config; diff --git a/vite-spring-webmvc/src/main/java/io/github/benny123tw/servlet/package-info.java b/vite-spring-webmvc/src/main/java/io/github/benny123tw/servlet/package-info.java deleted file mode 100644 index 48a045e..0000000 --- a/vite-spring-webmvc/src/main/java/io/github/benny123tw/servlet/package-info.java +++ /dev/null @@ -1,9 +0,0 @@ -/** - * Defines the XML configuration namespace for Spring MVC. - */ -@NonNullApi -@NonNullFields -package io.github.benny123tw.servlet; - -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; diff --git a/vite-spring-webmvc/src/main/java/io/github/benny123tw/servlet/tags/ViteImport.java b/vite-spring-webmvc/src/main/java/io/github/benny123tw/servlet/tags/ViteImport.java deleted file mode 100644 index a57b047..0000000 --- a/vite-spring-webmvc/src/main/java/io/github/benny123tw/servlet/tags/ViteImport.java +++ /dev/null @@ -1,204 +0,0 @@ -package io.github.benny123tw.servlet.tags; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import io.github.benny123tw.servlet.config.ViteProperties; -import jakarta.servlet.ServletContext; -import jakarta.servlet.jsp.JspException; -import jakarta.servlet.jsp.JspWriter; -import jakarta.servlet.jsp.PageContext; -import jakarta.servlet.jsp.tagext.SimpleTagSupport; -import java.io.File; -import java.io.IOException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.lang.Nullable; -import org.springframework.web.context.WebApplicationContext; -import org.springframework.web.context.support.WebApplicationContextUtils; - -/** - * Custom JSP tag to import Vite-generated assets. - */ -public class ViteImport extends SimpleTagSupport { - - private static final Logger log = LoggerFactory.getLogger(ViteImport.class); - - @Nullable - private String entry; - - @Nullable - private String manifestPath; - - @Nullable - private String localServerUrl; - - @Nullable - private Boolean isDebug; - - @Nullable - private String resourcePath; - - /** - * Sets the entry point for the Vite asset. - * - * @param entry the entry point of the Vite asset - */ - public void setEntry(String entry) { - this.entry = entry; - } - - /** - * Sets the path to the Vite manifest file. - * - * @param manifestPath the manifest file path - */ - public void setManifestPath(String manifestPath) { - this.manifestPath = manifestPath; - } - - /** - * Sets the local server URL for Vite development. - * - * @param localServerUrl the local server URL - */ - public void setLocalServerUrl(String localServerUrl) { - this.localServerUrl = localServerUrl; - } - - /** - * Sets the debug flag. - * - * @param isDebug the debug flag - */ - public void setDebug(boolean isDebug) { - this.isDebug = isDebug; - } - - /** - * Sets the resource path. - * - * @param resourcePath the resource path - */ - public void setResourcePath(String resourcePath) { - this.resourcePath = resourcePath; - } - - /** - * Processes the custom tag to import Vite assets based on the environment. - * - * @throws JspException if a JSP error occurs - * @throws IOException if an I/O error occurs - */ - @Override - public void doTag() throws JspException, IOException { - log.info("doTag() called"); - - ServletContext servletContext = ((PageContext) getJspContext()).getServletContext(); - WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(servletContext); - JspWriter out = getJspContext().getOut(); - - if (ctx == null) { - log.error("No WebApplicationContext found"); - throw new JspException("No WebApplicationContext found"); - } - - ViteProperties viteProperties = ctx.getBean(ViteProperties.class); - - isDebug = isDebug != null ? isDebug : viteProperties.isDebug(); - String effectiveManifestPath = manifestPath != null ? manifestPath : viteProperties.getManifestPath(); - String effectiveLocalServerUrl = localServerUrl != null ? localServerUrl : viteProperties.getLocalServerUrl(); - String effectiveResourcePath = resourcePath != null ? resourcePath : viteProperties.getResourcePath(); - - log.info("isDebug: {}", isDebug); - log.debug("effectiveManifestPath: {}, effectiveLocalServerUrl: {}, effectiveResourcePath: {}", effectiveManifestPath, effectiveLocalServerUrl, - effectiveResourcePath); - - if (isDebug) { - log.info("Handling development environment"); - handleDevEnvironment(out, effectiveLocalServerUrl); - } else { - log.info("Handling production environment"); - handleProdEnvironment(out, servletContext, effectiveManifestPath, effectiveResourcePath); - } - } - - - - /** - * Handles the production environment by loading assets from the manifest file. - * - * @param out the JSP writer - * @param servletContext the servlet context - * @param manifestFilePath the manifest file path - * @param resourcePath the resource path - * @throws IOException if an I/O error occurs - */ - private void handleProdEnvironment(JspWriter out, ServletContext servletContext, String manifestFilePath, String resourcePath) throws IOException { - File manifestFile = new File(servletContext.getRealPath(manifestFilePath)); - log.debug("Looking for manifest file at: {}", manifestFile.getAbsolutePath()); - if (manifestFile.exists()) { - ObjectMapper mapper = new ObjectMapper(); - JsonNode manifest = mapper.readTree(manifestFile); - JsonNode entryNode = manifest.get(entry); - - if (entryNode != null) { - printJsImport(out, servletContext, entryNode, resourcePath); - printCssImports(out, servletContext, entryNode, resourcePath); - } - } else { - log.error("Manifest file not found at: {}", manifestFile.getAbsolutePath()); - } - } - - /** - * Handles the development environment by pointing to the local Vite server. - * - * @param out the JSP writer - * @param localServerUrl the local server URL - * @throws IOException if an I/O error occurs - */ - private void handleDevEnvironment(JspWriter out, String localServerUrl) throws IOException { - log.info("Adding script tags for dev environment"); - out.print(""); - out.print(""); - } - - /** - * Prints the JavaScript import statement. - * - * @param out the JSP writer - * @param servletContext the servlet context - * @param entryNode the manifest entry node - * @param resourcePath the resource path - * @throws IOException if an I/O error occurs - */ - private void printJsImport(JspWriter out, ServletContext servletContext, JsonNode entryNode, String resourcePath) throws IOException { - String jsFile = entryNode.get("file").asText(); - String contextPath = servletContext.getContextPath(); - log.debug("Printing JS import: {}", jsFile); - out.print(""); - log.info("JS import printed"); - } - - /** - * Prints the CSS import statements. - * - * @param out the JSP writer - * @param servletContext the servlet context - * @param entryNode the manifest entry node - * @param resourcePath the resource path - * @throws IOException if an I/O error occurs - */ - private void printCssImports(JspWriter out, ServletContext servletContext, JsonNode entryNode, String resourcePath) throws IOException { - JsonNode cssFiles = entryNode.get("css"); - if (cssFiles != null) { - String contextPath = servletContext.getContextPath(); - for (JsonNode cssFile : cssFiles) { - log.debug("Printing CSS import: {}", cssFile.asText()); - out.print(""); - log.info("CSS import printed"); - } - } - } - -} diff --git a/vite-spring-webmvc/src/main/java/io/github/benny123tw/servlet/tags/package-info.java b/vite-spring-webmvc/src/main/java/io/github/benny123tw/servlet/tags/package-info.java deleted file mode 100644 index 97ce55b..0000000 --- a/vite-spring-webmvc/src/main/java/io/github/benny123tw/servlet/tags/package-info.java +++ /dev/null @@ -1,20 +0,0 @@ -/** - *

This package contains Vite's JSP standard tag library for JSP 2.0+. - * Supports JSP view implementations within Spring's Web MVC framework. - * For more details on each tag, see the list of tags below with links to - * individual tag classes, or check the {@code vite.tld} file: - * - *

    - *
  • {@link io.github.benny123tw.servlet.tags.ViteImport The import tag} - *
- * - *

Please note that the various tags generated by this form tag library are - * compliant with https://www.w3.org/TR/xhtml1/ and attendant - * https://www.w3.org/TR/xhtml1/dtds.html#a_dtd_XHTML-1.0-Strict. - */ -@NonNullApi -@NonNullFields -package io.github.benny123tw.servlet.tags; - -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; diff --git a/vite-spring-webmvc/src/main/resources/META-INF/vite.tld b/vite-spring-webmvc/src/main/resources/META-INF/vite.tld deleted file mode 100644 index 83e38a9..0000000 --- a/vite-spring-webmvc/src/main/resources/META-INF/vite.tld +++ /dev/null @@ -1,49 +0,0 @@ - - - - Vite JSP Tag Library - 1.0 - vite - https://github.com/benny123tw/tags - - - Import a Vite asset. - import - io.github.benny123tw.servlet.tags.ViteImport - empty - - The entry point of the Vite asset to be imported. - entry - true - true - - - The path to the Vite manifest file. - manifestPath - false - true - - - The URL of the local Vite development server. - localServerUrl - false - true - - - Flag to indicate if the debug mode is enabled. - debug - false - true - - - The path to the public resources. - resourcePath - false - true - - - - diff --git a/vite-spring-webmvc/src/test/java/io/github/benny123tw/servlet/TestApplication.java b/vite-spring-webmvc/src/test/java/io/github/benny123tw/servlet/TestApplication.java deleted file mode 100644 index ac44eb8..0000000 --- a/vite-spring-webmvc/src/test/java/io/github/benny123tw/servlet/TestApplication.java +++ /dev/null @@ -1,15 +0,0 @@ -package io.github.benny123tw.servlet; - -import io.github.benny123tw.servlet.config.ViteProperties; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.context.properties.EnableConfigurationProperties; - -@SpringBootApplication -public class TestApplication { - - public static void main(String[] args) { - SpringApplication.run(TestApplication.class, args); - } - -} diff --git a/vite-spring-webmvc/src/test/java/io/github/benny123tw/servlet/ViteDefaultPropertiesTest.java b/vite-spring-webmvc/src/test/java/io/github/benny123tw/servlet/ViteDefaultPropertiesTest.java deleted file mode 100644 index aa6b06e..0000000 --- a/vite-spring-webmvc/src/test/java/io/github/benny123tw/servlet/ViteDefaultPropertiesTest.java +++ /dev/null @@ -1,30 +0,0 @@ -package io.github.benny123tw.servlet; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import io.github.benny123tw.servlet.config.ViteProperties; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.ActiveProfiles; - -@SpringBootTest(classes = TestApplication.class) -@ActiveProfiles("default") -public class ViteDefaultPropertiesTest { - - private final ViteProperties viteProperties; - - @Autowired - public ViteDefaultPropertiesTest(ViteProperties viteProperties) { - this.viteProperties = viteProperties; - } - - @Test - public void testViteDefaultProperties() { - assertTrue(viteProperties.isDebug()); - assertEquals("/WEB-INF/dist/.vite/manifest.json", viteProperties.getManifestPath()); // Default value - assertEquals("http://localhost:5173", viteProperties.getLocalServerUrl()); // Default value - } - -} diff --git a/vite-spring-webmvc/src/test/java/io/github/benny123tw/servlet/VitePropertiesTest.java b/vite-spring-webmvc/src/test/java/io/github/benny123tw/servlet/VitePropertiesTest.java deleted file mode 100644 index 87181f1..0000000 --- a/vite-spring-webmvc/src/test/java/io/github/benny123tw/servlet/VitePropertiesTest.java +++ /dev/null @@ -1,29 +0,0 @@ -package io.github.benny123tw.servlet; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; - -import io.github.benny123tw.servlet.config.ViteProperties; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.ActiveProfiles; - -@SpringBootTest(classes = TestApplication.class) -@ActiveProfiles("test") -public class VitePropertiesTest { - - private final ViteProperties viteProperties; - - @Autowired - public VitePropertiesTest(ViteProperties viteProperties) { - this.viteProperties = viteProperties; - } - - @Test - public void testViteProperties() { - assertFalse(viteProperties.isDebug()); - assertEquals("/.vite/manifest.json", viteProperties.getManifestPath()); - assertEquals("https://github.com/benny123tw", viteProperties.getLocalServerUrl()); - } -} diff --git a/vite-spring-webmvc/src/test/java/io/github/benny123tw/servlet/tags/ViteImportTest.java b/vite-spring-webmvc/src/test/java/io/github/benny123tw/servlet/tags/ViteImportTest.java deleted file mode 100644 index 2356396..0000000 --- a/vite-spring-webmvc/src/test/java/io/github/benny123tw/servlet/tags/ViteImportTest.java +++ /dev/null @@ -1,79 +0,0 @@ -package io.github.benny123tw.servlet.tags; - -import static org.junit.jupiter.api.Assertions.assertTrue; - -import io.github.benny123tw.servlet.TestApplication; -import jakarta.servlet.jsp.JspWriter; -import jakarta.servlet.jsp.PageContext; -import java.io.StringWriter; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.mock.web.MockJspWriter; -import org.springframework.mock.web.MockPageContext; -import org.springframework.web.context.WebApplicationContext; - -@SpringBootTest(classes = TestApplication.class) -public class ViteImportTest { - - private static final Logger log = LoggerFactory.getLogger(ViteImportTest.class); - - private final WebApplicationContext webApplicationContext; - - @Autowired - public ViteImportTest(WebApplicationContext webApplicationContext) { - this.webApplicationContext = webApplicationContext; - } - - private PageContext pageContext; - private StringWriter stringWriter; - private JspWriter jspWriter; - - @BeforeEach - public void setup() { - log.info("Setting up test"); - stringWriter = new StringWriter(); - jspWriter = new MockJspWriter(stringWriter); - - pageContext = new MockPageContext() { - @Override - public JspWriter getOut() { - return jspWriter; - } - }; - pageContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, webApplicationContext, PageContext.APPLICATION_SCOPE); - } - - @Test - public void testDevViteImportTag() throws Exception { - ViteImport viteImport = new ViteImport(); - viteImport.setEntry("main.js"); - viteImport.setJspContext(pageContext); - - viteImport.doTag(); - - String output = stringWriter.toString(); - assertTrue(output.contains("")); - assertTrue(output.contains("")); - } - - @Test - public void testProdViteImportTag() throws Exception { - ViteImport viteImport = new ViteImport(); - viteImport.setDebug(false); - viteImport.setEntry("src/main.ts"); - viteImport.setLocalServerUrl("http://localhost:5173"); - viteImport.setManifestPath("/.vite/manifest.json"); - viteImport.setResourcePath("/public"); - viteImport.setJspContext(pageContext); - - viteImport.doTag(); - - String output = stringWriter.toString(); - assertTrue(output.contains("")); - } -} diff --git a/vite-spring-webmvc/src/test/resources/.vite/manifest.json b/vite-spring-webmvc/src/test/resources/.vite/manifest.json deleted file mode 100644 index b142e2e..0000000 --- a/vite-spring-webmvc/src/test/resources/.vite/manifest.json +++ /dev/null @@ -1,53 +0,0 @@ -{ - "_number-helper-CBINN9Rp.js": { - "file": "assets/number-helper-CBINN9Rp.js", - "name": "number-helper" - }, - "src/main.ts": { - "file": "assets/main-C7y8ECKo.js", - "name": "main", - "src": "src/main.ts", - "isEntry": true, - "imports": [ - "_number-helper-CBINN9Rp.js" - ], - "css": [ - "assets/main-DnsH5c2P.css" - ], - "assets": [ - "assets/typescript-EnIy2PE5.svg" - ] - }, - "src/typescript.svg": { - "file": "assets/typescript-EnIy2PE5.svg", - "src": "src/typescript.svg" - }, - "src/utils/config-helper.ts": { - "file": "assets/config-helper-BGlegK0Q.js", - "name": "config-helper", - "src": "src/utils/config-helper.ts", - "isDynamicEntry": true - }, - "src/world/main.ts": { - "file": "assets/world\\main-CAFFP_m4.js", - "name": "world\\main", - "src": "src/world/main.ts", - "isEntry": true, - "imports": [ - "_number-helper-CBINN9Rp.js" - ], - "dynamicImports": [ - "src/utils/config-helper.ts", - "vite:asset:public/bg_01.png" - ], - "css": [ - "assets/main-CLXL5IJK.css" - ] - }, - "vite:asset:public/bg_01.png": { - "file": "assets/bg_01-CO4g66lg.js", - "name": "bg_01", - "src": "vite:asset:public/bg_01.png", - "isDynamicEntry": true - } -} diff --git a/vite-spring-webmvc/src/test/resources/application-test.properties b/vite-spring-webmvc/src/test/resources/application-test.properties deleted file mode 100644 index ea965a4..0000000 --- a/vite-spring-webmvc/src/test/resources/application-test.properties +++ /dev/null @@ -1,3 +0,0 @@ -vite.debug=false -vite.manifestPath=/.vite/manifest.json -vite.localServerUrl=https://github.com/benny123tw