Skip to content

Commit

Permalink
Add support for JTE
Browse files Browse the repository at this point in the history
Closes gh-1560
  • Loading branch information
mhalbritter committed Sep 30, 2024
1 parent 3767fe1 commit 412d95d
Show file tree
Hide file tree
Showing 9 changed files with 383 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.spring.start.site.extension.dependency.jte;

import io.spring.initializr.generator.buildsystem.Dependency;
import io.spring.initializr.generator.buildsystem.gradle.GradleBuild;
import io.spring.initializr.generator.spring.build.BuildCustomizer;

/**
* {@link BuildCustomizer} to configure the JTE Gradle plugin.
*
* @author Moritz Halbritter
*/
class JteGradleBuildCustomizer implements BuildCustomizer<GradleBuild> {

@Override
public void customize(GradleBuild build) {
Dependency jteStarter = build.dependencies().get("jte");
build.plugins().add("gg.jte.gradle", (plugin) -> plugin.setVersion(jteStarter.getVersion().getValue()));
build.extensions().customize("jte", (jte) -> {
jte.invoke("generate");
jte.attribute("binaryStaticContent", "true");
});
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.spring.start.site.extension.dependency.jte;

import java.util.Collections;

import io.spring.initializr.generator.spring.documentation.HelpDocument;
import io.spring.initializr.generator.spring.documentation.HelpDocumentCustomizer;

/**
* {@link HelpDocumentCustomizer} to add a JTE section.
*
* @author Moritz Halbritter
*/
class JteHelpDocumentCustomizer implements HelpDocumentCustomizer {

@Override
public void customize(HelpDocument document) {
document.addSection("jte", Collections.emptyMap());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.spring.start.site.extension.dependency.jte;

import io.spring.initializr.generator.buildsystem.Dependency;
import io.spring.initializr.generator.buildsystem.maven.MavenBuild;
import io.spring.initializr.generator.spring.build.BuildCustomizer;

/**
* {@link BuildCustomizer} to configure the JTE Maven plugin.
*
* @author Moritz Halbritter
*/
class JteMavenBuildCustomizer implements BuildCustomizer<MavenBuild> {

@Override
public void customize(MavenBuild build) {
Dependency jteStarter = build.dependencies().get("jte");
build.plugins().add("gg.jte", "jte-maven-plugin", (plugin) -> {
plugin.version(jteStarter.getVersion().getValue());
plugin.execution("jte-generate", (execution) -> {
execution.phase("generate-sources");
execution.goal("generate");
execution.configuration((configuration) -> {
configuration.add("sourceDirectory", "${project.basedir}/src/main/jte");
configuration.add("contentType", "Html");
configuration.add("binaryStaticContent", "true");
configuration.add("targetResourceDirectory", "${project.build.outputDirectory}");
});
});
});
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.spring.start.site.extension.dependency.jte;

import java.nio.file.Files;
import java.nio.file.Path;

import io.spring.initializr.generator.buildsystem.Build;
import io.spring.initializr.generator.buildsystem.Dependency;
import io.spring.initializr.generator.buildsystem.gradle.GradleBuildSystem;
import io.spring.initializr.generator.buildsystem.maven.MavenBuildSystem;
import io.spring.initializr.generator.condition.ConditionalOnBuildSystem;
import io.spring.initializr.generator.condition.ConditionalOnRequestedDependency;
import io.spring.initializr.generator.project.ProjectGenerationConfiguration;
import io.spring.initializr.generator.project.contributor.ProjectContributor;
import io.spring.initializr.generator.spring.build.BuildCustomizer;
import io.spring.initializr.generator.spring.properties.ApplicationPropertiesCustomizer;
import io.spring.initializr.generator.spring.scm.git.GitIgnoreCustomizer;

import org.springframework.context.annotation.Bean;

/**
* {@link ProjectGenerationConfiguration} for JTE.
*
* @author Moritz Halbritter
*/
@ProjectGenerationConfiguration
@ConditionalOnRequestedDependency("jte")
class JteProjectGenerationConfiguration {

@Bean
ProjectContributor jteTemplateDirectoryProjectContributor() {
return (projectRoot) -> {
Path templatesDirectory = projectRoot.resolve("src/main/jte");
Files.createDirectories(templatesDirectory);
};
}

@Bean
ApplicationPropertiesCustomizer jteApplicationPropertiesCustomizer() {
return (properties) -> properties.add("gg.jte.development-mode", true);
}

@Bean
BuildCustomizer<Build> jteBuildCustomizer() {
// https://github.com/casid/jte/issues/381
return (build) -> {
Dependency jteStarter = build.dependencies().get("jte");
build.dependencies()
.add("jte-core", Dependency.withCoordinates("gg.jte", "jte").version(jteStarter.getVersion()).build());
};
}

@Bean
GitIgnoreCustomizer jteGitIgnoreCustomizer() {
return (gitignore) -> gitignore.addSectionIfAbsent("JTE").add("/jte-classes/");
}

@Bean
JteHelpDocumentCustomizer jteHelpDocumentCustomizer() {
return new JteHelpDocumentCustomizer();
}

@Bean
@ConditionalOnBuildSystem(GradleBuildSystem.ID)
JteGradleBuildCustomizer jteGradleBuildCustomizer() {
return new JteGradleBuildCustomizer();
}

@Bean
@ConditionalOnBuildSystem(MavenBuildSystem.ID)
JteMavenBuildCustomizer jteMavenBuildCustomizer() {
return new JteMavenBuildCustomizer();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* Extensions for generation of projects that depend on JTE.
*/
package io.spring.start.site.extension.dependency.jte;
1 change: 1 addition & 0 deletions start-site/src/main/resources/META-INF/spring.factories
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ io.spring.start.site.extension.dependency.flyway.FlywayProjectGenerationConfigur
io.spring.start.site.extension.dependency.graalvm.GraalVmProjectGenerationConfiguration,\
io.spring.start.site.extension.dependency.graphql.SpringGraphQlProjectGenerationConfiguration,\
io.spring.start.site.extension.dependency.htmx.HtmxProjectGenerationConfiguration,\
io.spring.start.site.extension.dependency.jte.JteProjectGenerationConfiguration,\
io.spring.start.site.extension.dependency.mariadb.MariaDbProjectGenerationConfiguration,\
io.spring.start.site.extension.dependency.mongodb.MongoDbProjectGenerationConfiguration,\
io.spring.start.site.extension.dependency.mysql.MysqlProjectGenerationConfiguration,\
Expand Down
10 changes: 10 additions & 0 deletions start-site/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,16 @@ initializr:
links:
- rel: reference
href: https://docs.spring.io/spring-boot/docs/{bootVersion}/reference/htmlsingle/index.html#web.servlet.spring-mvc.template-engines
- name: JTE
id: jte
description: Secure and lightweight template engine for Java and Kotlin.
groupId: gg.jte
artifactId: jte-spring-boot-starter-3
version: 3.1.12
starter: true
links:
- rel: reference
href: https://jte.gg/
- name: Security
content:
- name: Spring Security
Expand Down
19 changes: 19 additions & 0 deletions start-site/src/main/resources/templates/jte.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## JTE

This project has been configured to use [JTE precompiled templates](https://jte.gg/pre-compiling/).

However, to ease development, those are not enabled out of the box.
For production deployments, you should remove

```properties
gg.jte.development-mode=true
```

from the `application.properties` file and set

```properties
gg.jte.use-precompiled-templates=true
```

instead.
For more details, please take a look at [the official documentation](https://jte.gg/spring-boot-starter-3/).
Loading

0 comments on commit 412d95d

Please sign in to comment.