Skip to content

Commit

Permalink
fix(kte): kte now working without development mode on (#25)
Browse files Browse the repository at this point in the history
* fix(kte): kte now working without development mode on

* fix(local-development): upgraded version, kte creates now custom jteviewresolver and viewcomponent annotation now can override bean name of component annotation

* Update version to 0.8.4-SNAPSHOT

Changed all dependencies and version properties from 0.8.4 to 0.8.4-SNAPSHOT for ongoing development. This ensures the project uses the latest snapshot versions during development phases.

---------

Co-authored-by: Christoph Hagelkruys <christophhagelkruys@MBPvonChristoph.home>
Co-authored-by: tschuehly <tschuehly@outlook.com>
  • Loading branch information
3 people authored Aug 27, 2024
1 parent 69c8580 commit 09f2e5f
Show file tree
Hide file tree
Showing 15 changed files with 74 additions and 52 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ spring.view-component.local-development=true
<summary>Gradle</summary>

```kotlin
implementation("de.tschuehly:spring-view-component-thymeleaf:0.8.3")
implementation("de.tschuehly:spring-view-component-thymeleaf:0.8.4-SNAPSHOT")
sourceSets {
main {
resources {
Expand All @@ -249,7 +249,7 @@ sourceSets {
<dependency>
<groupId>de.tschuehly</groupId>
<artifactId>spring-view-component-thymeleaf</artifactId>
<version>0.8.3</version>
<version>0.8.4-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
Expand Down Expand Up @@ -286,7 +286,7 @@ plugins {
id("gg.jte.gradle") version("3.1.12")
}

implementation("de.tschuehly:spring-view-component-jte:0.8.3")
implementation("de.tschuehly:spring-view-component-jte:0.8.4-SNAPSHOT")

jte{
generate()
Expand All @@ -305,7 +305,7 @@ jte{
<dependency>
<groupId>de.tschuehly</groupId>
<artifactId>spring-view-component-jte</artifactId>
<version>0.8.3</version>
<version>0.8.4-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
Expand Down Expand Up @@ -343,7 +343,7 @@ jte{
<summary>Gradle</summary>

```kotlin
implementation("de.tschuehly:spring-view-component-kte:0.8.3")
implementation("de.tschuehly:spring-view-component-kte:0.8.4-SNAPSHOT")
jte{
generate()
sourceDirectory = Path("src/main/kotlin")
Expand Down
2 changes: 1 addition & 1 deletion core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ plugins {
}

group = "de.tschuehly"
version = "0.8.3"
version = "0.8.4-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_17

repositories {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package de.tschuehly.spring.viewcomponent.core.component

import org.springframework.core.annotation.AliasFor
import org.springframework.stereotype.Component


@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.RUNTIME)
@Component
annotation class ViewComponent
annotation class ViewComponent(@get:AliasFor(annotation = Component::class, attribute = "value") val value: String = "")

4 changes: 2 additions & 2 deletions examples/jte-example/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ repositories {
dependencies {
implementation("org.springframework.boot:spring-boot-starter-web")

implementation("de.tschuehly:spring-view-component-jte:0.8.3")
implementation("de.tschuehly:spring-view-component-jte:0.8.4-SNAPSHOT")

implementation("org.webjars.npm:htmx.org:1.9.11")
implementation("org.webjars:webjars-locator-core:0.58")

testImplementation("org.springframework.boot:spring-boot-starter-test")
testRuntimeOnly("org.springframework.boot:spring-boot-devtools")
testImplementation(testFixtures("de.tschuehly:spring-view-component-core:0.8.3"))
testImplementation(testFixtures("de.tschuehly:spring-view-component-core:0.8.4-SNAPSHOT"))
}

tasks.withType<Test> {
Expand Down
2 changes: 1 addition & 1 deletion examples/jte-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<description>JTE Example</description>
<properties>
<java.version>17</java.version>
<view.component.version>0.8.3</view.component.version>
<view.component.version>0.8.4-SNAPSHOT</view.component.version>
</properties>
<dependencies>
<dependency>
Expand Down
6 changes: 3 additions & 3 deletions examples/kte-example/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ repositories {
}

dependencies {
implementation("de.tschuehly:spring-view-component-kte:0.8.3")
implementation("de.tschuehly:spring-view-component-core:0.8.3")
implementation("de.tschuehly:spring-view-component-kte:0.8.4-SNAPSHOT")
implementation("de.tschuehly:spring-view-component-core:0.8.4-SNAPSHOT")
implementation("io.github.wimdeblauwe:htmx-spring-boot:3.1.1")

implementation("org.webjars.npm:htmx.org:1.9.11")
Expand All @@ -47,7 +47,7 @@ dependencies {

testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.springframework.boot:spring-boot-devtools")
testImplementation(testFixtures("de.tschuehly:spring-view-component-core:0.8.3"))
testImplementation(testFixtures("de.tschuehly:spring-view-component-core:0.8.4-SNAPSHOT"))
}

tasks.withType<KotlinCompile> {
Expand Down
4 changes: 2 additions & 2 deletions examples/thymeleaf-java-example/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ repositories {

dependencies {
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("de.tschuehly:spring-view-component-thymeleaf:0.8.3")
implementation("de.tschuehly:spring-view-component-thymeleaf:0.8.4-SNAPSHOT")

implementation("org.webjars.npm:htmx.org:1.9.11")
implementation("org.webjars:webjars-locator-core:0.58")

testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.springframework.boot:spring-boot-devtools")
testImplementation(testFixtures("de.tschuehly:spring-view-component-core:0.8.3"))
testImplementation(testFixtures("de.tschuehly:spring-view-component-core:0.8.4-SNAPSHOT"))
}

tasks.withType<Test> {
Expand Down
2 changes: 1 addition & 1 deletion examples/thymeleaf-java-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<description>Thymeleaf Java Example</description>
<properties>
<java.version>17</java.version>
<view.component.version>0.8.3</view.component.version>
<view.component.version>0.8.4-SNAPSHOT</view.component.version>
</properties>
<dependencies>
<dependency>
Expand Down
6 changes: 3 additions & 3 deletions examples/thymeleaf-kotlin-example/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ repositories {
}

dependencies {
implementation("de.tschuehly:spring-view-component-thymeleaf:0.8.3")
implementation("de.tschuehly:spring-view-component-core:0.8.3")
implementation("de.tschuehly:spring-view-component-thymeleaf:0.8.4-SNAPSHOT")
implementation("de.tschuehly:spring-view-component-core:0.8.4-SNAPSHOT")

implementation("org.webjars.npm:htmx.org:1.9.2")
implementation("org.webjars:webjars-locator:0.47")
Expand All @@ -35,7 +35,7 @@ dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")

testImplementation("org.springframework.boot:spring-boot-devtools")
testImplementation(testFixtures("de.tschuehly:spring-view-component-core:0.8.3"))
testImplementation(testFixtures("de.tschuehly:spring-view-component-core:0.8.4-SNAPSHOT"))
}

tasks.withType<KotlinCompile> {
Expand Down
4 changes: 2 additions & 2 deletions jte/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ plugins {
}

group = "de.tschuehly"
version = "0.8.3"
version = "0.8.4-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_17

repositories {
Expand All @@ -22,7 +22,7 @@ repositories {
}
dependencies {
api("gg.jte:jte:3.1.12")
api("de.tschuehly:spring-view-component-core:0.8.3")
api("de.tschuehly:spring-view-component-core:0.8.4-SNAPSHOT")

implementation("gg.jte:jte-spring-boot-starter-3:3.1.12")
implementation("org.springframework.boot:spring-boot-starter-web")
Expand Down
4 changes: 2 additions & 2 deletions kte/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ plugins {
}

group = "de.tschuehly"
version = "0.8.3"
version = "0.8.4-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_17

repositories {
mavenCentral()
}
dependencies {
api("gg.jte:jte-kotlin:3.1.12")
api("de.tschuehly:spring-view-component-core:0.8.3")
api("de.tschuehly:spring-view-component-core:0.8.4-SNAPSHOT")

implementation("gg.jte:jte-spring-boot-starter-3:3.1.12")
implementation("org.springframework.boot:spring-boot-starter-web")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,55 +1,76 @@
package de.tschuehly.spring.viewcomponent.kte

import de.tschuehly.spring.viewcomponent.core.component.ViewComponentProperties
import gg.jte.CodeResolver
import gg.jte.ContentType
import gg.jte.TemplateEngine
import gg.jte.resolve.DirectoryCodeResolver
import gg.jte.springframework.boot.autoconfigure.JteProperties
import gg.jte.springframework.boot.autoconfigure.JteViewResolver
import org.springframework.beans.factory.BeanClassLoaderAware
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
import org.springframework.context.ApplicationContext
import org.springframework.context.annotation.*
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Primary
import java.nio.file.FileSystems
import java.nio.file.Path
import java.nio.file.Paths

@Configuration
class KteConfiguration {
class KteConfiguration : BeanClassLoaderAware {
var classLoader: ClassLoader? = null

@Bean
fun kteViewContextAspect(templateEngine: TemplateEngine, jteProperties: JteProperties): KteViewContextAspect {
fun kteViewContextAspect(
templateEngine: TemplateEngine,
jteProperties: JteProperties
): KteViewContextAspect {
return KteViewContextAspect(templateEngine, jteProperties)
}

@Bean
@ConditionalOnMissingBean(TemplateEngine::class)
fun jteTemplateEngine(viewComponentProperties: ViewComponentProperties,applicationContext: ApplicationContext): TemplateEngine {
if (!viewComponentProperties.localDevelopment) {
return TemplateEngine.createPrecompiled(
/* classDirectory = */ Path.of(this.javaClass.classLoader.getResource("").toURI()),
/* contentType = */ ContentType.Html,
/* parentClassLoader = */ this.javaClass.classLoader
fun kteNonLocalTemplateEngine(viewComponentProperties: ViewComponentProperties): TemplateEngine {
if (viewComponentProperties.localDevelopment) {
val split = getViewComponentRootPath(viewComponentProperties).split("/")
.toTypedArray()
val codeResolver: CodeResolver =
DirectoryCodeResolver(FileSystems.getDefault().getPath("", *split))
return TemplateEngine.create(
codeResolver,
Paths.get("jte-classes"),
ContentType.Html,
classLoader
)
}
val split = getViewComponentRootPath(viewComponentProperties).split("/").toTypedArray()
val codeResolver: CodeResolver = DirectoryCodeResolver(FileSystems.getDefault().getPath("", *split))
return TemplateEngine.create(
codeResolver,
Paths.get("jte-classes"),
ContentType.Html,
Thread.currentThread().contextClassLoader
return TemplateEngine.createPrecompiled(
/* classDirectory = */ Path.of(
classLoader?.getResource("")?.toURI()
?: throw RuntimeException("ClassLoader is null")
),
/* contentType = */ ContentType.Html,
/* parentClassLoader = */ classLoader
)
}

@Bean
fun kteViewResolver(templateEngine: TemplateEngine?): JteViewResolver {
return JteViewResolver(templateEngine, ".kte")
}

@Bean
@Primary
fun jteProperties(viewComponentProperties: ViewComponentProperties) = JteProperties().also {
it.templateSuffix = ".kte"
it.templateLocation = getViewComponentRootPath(viewComponentProperties)
it.isDevelopmentMode = viewComponentProperties.localDevelopment
fun jteProperties(viewComponentProperties: ViewComponentProperties) =
JteProperties().also {
it.templateSuffix = ".kte"
it.templateLocation = getViewComponentRootPath(viewComponentProperties)
it.isDevelopmentMode = viewComponentProperties.localDevelopment
}

override fun setBeanClassLoader(classLoader: ClassLoader) {
this.classLoader = classLoader
}

private fun getViewComponentRootPath(viewComponentProperties: ViewComponentProperties): String =
if (viewComponentProperties.viewComponentRoot == "src/main/java") "src/main/kotlin" else viewComponentProperties.viewComponentRoot


}
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ class KteViewContextAspect(
//
}

@Pointcut("execution(public de.tschuehly.spring.viewcomponent.kte.ViewContext+ *(..))")
@Pointcut("execution(de.tschuehly.spring.viewcomponent.kte.ViewContext+ *(..))")
fun isRenderOrGetMethod() {
//
}

@AfterReturning(pointcut = "isViewComponent() && isRenderOrGetMethod()", returning = "viewContext")
fun renderInject(viewContext: ViewContext): ViewContext {
ViewContext.templateEngine = jteTemplateEngine
ViewContext.templateSuffx = jteProperties.templateSuffix
ViewContext.templateSuffix = jteProperties.templateSuffix
return viewContext
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import gg.jte.TemplateOutput

interface ViewContext : Content, IViewContext {
companion object{
var templateSuffx: String? = null
var templateSuffix: String? = null
var templateEngine: TemplateEngine? = null
}
override fun writeTo(output: TemplateOutput) {
templateEngine?.render(
IViewContext.getViewComponentTemplateWithoutSuffix(this) + templateSuffx
IViewContext.getViewComponentTemplateWithoutSuffix(this) + templateSuffix
, this,
output
) ?: throw RenderException("Template Engine not initialized")
Expand Down
4 changes: 2 additions & 2 deletions thymeleaf/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ plugins {
}

group = "de.tschuehly"
version = "0.8.3"
version = "0.8.4-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_17

repositories {
mavenCentral()
}

dependencies {
api("de.tschuehly:spring-view-component-core:0.8.3")
api("de.tschuehly:spring-view-component-core:0.8.4-SNAPSHOT")
api("org.springframework.boot:spring-boot-devtools")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-thymeleaf")
Expand Down

0 comments on commit 09f2e5f

Please sign in to comment.