2
0
Fork 0
mirror of https://github.com/ethauvin/rife2-hello.git synced 2025-04-28 16:38:12 -07:00

Compare commits

...

51 commits

Author SHA1 Message Date
7a3d44a412 Updated RIFE2 Gradle plugin version 2023-03-06 20:11:56 -05:00
4999c040c0 Merge branch 'develop' 2023-03-06 19:48:35 -05:00
a39fb686c3 Build file tweaks 2023-03-06 19:48:12 -05:00
7e1dcd82ec Updated war task 2023-03-06 19:27:20 -05:00
f10a228097 Merge branch 'develop' 2023-03-06 18:39:56 -05:00
8e249a3f50 Specify uberjar main class specifically 2023-03-06 18:39:39 -05:00
e3df16c5df Merge branch 'develop' 2023-03-06 18:29:48 -05:00
122db8a40e Small cleanup to match the manual better 2023-03-06 18:29:18 -05:00
b74de8c59a
Updated GitHub workflow actions to latest versions (#10) 2023-03-06 16:52:58 -05:00
02d5b610be Updated GitHub workflow actions to latest versions 2023-03-06 16:43:04 -05:00
fbad18e011 Updated Gradle plugin version to 1.0.4 2023-03-06 16:41:00 -05:00
f777a40a99 Updated plugin version to 1.0.3 2023-03-06 12:12:33 -05:00
d4f9bb9ad4 Updated plugin version to 1.0.2 2023-03-06 09:37:02 -05:00
e97239207a Updated to not use mavenLocal 2023-03-06 09:27:51 -05:00
6bb4fcedd4 Updated RIFE2 gradle plugin version 2023-03-05 14:17:33 -05:00
17a6fee9bb Use published gradle plugin 2023-03-05 14:10:24 -05:00
7f82944093 Aligned with Gradle plugin source state 2023-03-05 13:19:23 -05:00
794f614e57 Minor cleanup 2023-03-05 11:16:32 -05:00
1d45241fae Minor cleanup 2023-03-05 11:12:19 -05:00
938372addc Made GraalVM plugin work with Jetty and JDK 19 2023-03-05 10:56:37 -05:00
a3a5c7c380 Made "src/main/resources/templates" the only default template dir.
Made the template excludes adapt to the template types that are pre-compiled and use a more restrictive pattern.
2023-03-05 10:52:34 -05:00
b51e36ee73
Merge pull request #8 from melix/cc/configurable-templates
Make the template directories configurable
2023-03-05 10:39:48 -05:00
83e52c0e06
Merge pull request #7 from melix/cc/use-official-graalvm-plugin
Use the official GraalVM plugin
2023-03-05 10:39:39 -05:00
Cedric Champeau
d06124c26d
Make the template directories configurable
Adding a directory can be done via the extension:

```gradle
rife2 {
   templateDirectories.from(file("my-template-dir"))
}
```

By default the template directories include both `src/main/templates`
and `src/main/resources/templates`. If you want to ignore those,
then you need to clear the default:

```gradle
rife2 {
    templateDirectories.from.clear()
    templateDirectories.from(file("my-template-dir"))
}
```
2023-03-05 16:36:31 +01:00
Cedric Champeau
a79e616d79
Use the official GraalVM plugin 2023-03-05 16:23:48 +01:00
de5c974f15
Merge pull request #6 from melix/cc/additional-template-dirs
Add support for extra template directories
2023-03-05 09:59:57 -05:00
0a2b061679 Reverted dependencies back to the explicit version 2023-03-05 09:12:58 -05:00
Cedric Champeau
21c85ea93b
Add support for extra template directories
By default, the template was using `src/main/templates` as the source directory
for templates. This has the benefit of properly isolating the templates from
the application classpath: the framework is then responsible for injecting them
to the app runtime in whatever suitable form: either untouched as sources (in
development mode), or precompiled (for production).

With this change, it is also possible to use `src/main/resources/templates` as
a source directory. It _may_ feel more natural to users (although I would disagree),
but it has the drawback that the jars have to be configured to _exclude_ those
resources, because by default whatever is in `src/main/resources` MUST be included
in a jar (independently of the run mode).

It is also possible for the user to configure additional source directories should
they want to.
2023-03-05 15:10:46 +01:00
cf4870745c Made precompiledTemplateTypes plugin option not use HTML by default
Cleanup minimal test project.
2023-03-05 09:07:29 -05:00
5ca1fa305b Gradle plugin test fix 2023-03-05 08:51:14 -05:00
d8c41b45d9
Merge pull request #5 from melix/cc/fix-template-reloading
Fix template reloading
2023-03-05 08:15:10 -05:00
Cedric Champeau
c9f286132c
Fix reloading of templates
This commit fixes how templates were reloaded. There was a bug in
the plugin which used the output of the precompiled templates for
development only dependencies, instead of the templates directory.
This caused the templates to be always compiled and added as a
resource on runtime classpath, when we only wanted the raw templates.

This commit also adds functional tests to the build logic, which
can be executed by running `./gradlew build-logic:test`.
2023-03-05 13:44:10 +01:00
Cedric Champeau
65e579966c
Revert RunTask 2023-03-05 11:22:28 +01:00
86b7ec21d9 Added serialVersionUID to TemplateType 2023-03-04 12:09:59 -05:00
aeaadfb1cc Added support for configurable precompiled template types 2023-03-04 11:53:59 -05:00
ed8046e83d More minor cleanups 2023-03-04 10:39:37 -05:00
c8f47a935e Minor cleanups 2023-03-04 10:22:04 -05:00
d3dedfe189 Updated to RIFE2 1.4.0 2023-03-04 10:21:35 -05:00
a54ab9b23e
Merge pull request #4 from ethauvin/develop
Develop
2023-03-03 23:05:53 -05:00
f8b3078ba1 Reverted cleanup, it wasn't necessary. 2023-03-02 05:28:18 -08:00
57a604c599 Minor cleanup 2023-02-28 23:46:10 -08:00
c33235a1ac Added description and group for the uberJar task. 2023-02-27 19:14:36 -08:00
269971663b Minor cleanup 2023-02-27 18:48:12 -08:00
d954e75cf5 Added a RunTask which includes the templates directory in the runtime classspath 2023-02-26 17:58:21 -08:00
834c75492b
Merge pull request #3 from melix/cc/publishing-compatibility
Add support for publishing the fat jar
2023-02-22 08:21:50 -05:00
5e70147765
Merge pull request #2 from melix/cc/build-feedback
Fix reload of templates in dev mode
2023-02-22 08:21:40 -05:00
Cedric Champeau
f6deafda3a
Add support for publishing the fat jar
This commit adds compatibility with the Maven publish plugin, by
making sure that if the application is published, then the uber
jar is published as a classified artifact (`-uber`) in addition
to the regular jar.

A sample publishing configuration was added to the `app`, with
a "local" publishing repository in <rootproject>/build/repo.

For example, calling `./gradlew pAPTBR` will create the
`build/repo` directory with the corresponding Maven repository
structure after publishing.
2023-02-22 13:49:25 +01:00
Cedric Champeau
c8b3cc7890
Fix reload of templates in dev mode
The `run` task is considered a development mode, where the templates
should be reloaded live. This means that the `run` task will not
use the precompiled templates, but the source templates instead.

The `test` task will also use precompiled templates, while the
`jar` and `uberJar` tasks will also make sure to bundle precompiled
templates and not the source ones.
2023-02-22 13:32:30 +01:00
0d3f587bb4 Minor cleanups 2023-02-21 18:20:14 -05:00
e02ed25b5a
Merge pull request #1 from melix/cc/rework-build
Rework Gradle build
2023-02-21 18:05:44 -05:00
Cedric Champeau
2e025cd693 Rework Gradle build
This commit introduces a _convention plugin_ for RIFE2 support.
It provides a number of advantages:

- the build logic is clearly separated from the build script,
which now only contains user-specific configuration, like the
framework version or how to configure test logging
- it fixes a number of issues like hardcoded dependencies
(`dependsOn` is in general a mistake)
- it removes the need to resolve the agent path eagerly
- it makes the agent configurable
- it clearly separates the user classpath from the RIFE
classpath (both for precompiling templates and for the agent)
- template compilation is cached
- it avoids the abuse of `src/main/resources` to put
templates and uses a dedicated directory instead, which
removes the need for exclusions

In addition, this should make it relatively straightforward
to convert the convention plugin into a proper RIFE2 plugin,
by extracting the code in `build-logic` into its own
repository then publishing to the Gradle plugin portal.
2023-02-21 23:52:36 +01:00
10 changed files with 73 additions and 120 deletions

View file

@ -11,7 +11,7 @@ jobs:
strategy:
matrix:
java-version: [ 17 ]
java-version: [ 17, 19 ]
steps:
- name: Checkout source repository
@ -20,7 +20,7 @@ jobs:
fetch-depth: 0
- name: Set up JDK ${{ matrix.java-version }}
uses: actions/setup-java@v2
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: ${{ matrix.java-version }}
@ -28,20 +28,7 @@ jobs:
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Cache Gradle packages
uses: actions/cache@v2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ matrix.java-version }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-${{ matrix.java-version }}-
- name: Test with Gradle
run: ./gradlew build check --stacktrace
- name: Cleanup Gradle Cache
run: |
rm -f ~/.gradle/caches/modules-2/modules-2.lock
rm -f ~/.gradle/caches/modules-2/gc.properties
uses: gradle/gradle-build-action@v2
with:
arguments: build check --stacktrace

View file

@ -92,18 +92,23 @@ GraalVM supports creating a single Ahead-Of-Time
[native executable](https://www.graalvm.org/native-image/) from your java
bytecode.
Once you have at least GraalVM 22.3.1 Java 19 installed, you can generate the
UberJar as above, then create your native binary as such:
Once you have at least GraalVM 22.3.1 Java 17 installed, you can generate the native binary with:
```bash
native-image --no-fallback --enable-preview -jar app/build/libs/hello-uber-1.0.jar
./gradlew nativeCompile
```
You'll end up with a `hello-uber-1.0` file that can be executed directly without
You'll end up with a `hello-1.0` file that can be executed directly without
the need of a JVM:
```bash
./hello-uber-1.0
./app/build/native/nativeCompile/hello-1.0
```
Alternatively, you can run the native executable directly with:
```bash
./gradlew nativeRun
```
> **NOTE:** RIFE2 support for GraalVM native-image is still in preliminary

View file

@ -1,13 +1,32 @@
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
import com.uwyn.rife2.gradle.TemplateType.*
plugins {
java
application
id("com.uwyn.rife2") version "1.0.6"
`maven-publish`
id("org.graalvm.buildtools.native") version "0.9.20"
}
version = 1.0
group = "com.example"
rife2 {
version.set("1.4.0")
uberMainClass.set("hello.AppUber")
useAgent.set(true)
precompiledTemplateTypes.add(HTML)
}
base {
archivesName.set("hello")
version = 1.0
}
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}
repositories {
@ -16,90 +35,40 @@ repositories {
maven { url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots") } // only needed for SNAPSHOT
}
sourceSets {
main {
runtimeClasspath = files(file("src/main/resources"), runtimeClasspath);
}
}
sourceSets.main {
resources.exclude("templates/**")
}
dependencies {
implementation("com.uwyn.rife2:rife2:1.3.0")
runtimeOnly("com.uwyn.rife2:rife2:1.3.0:agent")
runtimeOnly("org.eclipse.jetty:jetty-server:11.0.13")
runtimeOnly("org.eclipse.jetty:jetty-servlet:11.0.13")
runtimeOnly("org.slf4j:slf4j-simple:2.0.5")
testImplementation("org.jsoup:jsoup:1.15.3")
testImplementation("org.junit.jupiter:junit-jupiter:5.9.1")
}
tasks {
val dependencies = configurations
.runtimeClasspath.get().files;
val rifeAgentJar = dependencies
.filter { it.toString().contains("rife2") }
.filter { it.toString().endsWith("-agent.jar") }[0]
application {
mainClass.set("hello.App")
}
tasks {
test {
jvmArgs = listOf("-javaagent:$rifeAgentJar")
useJUnitPlatform()
testLogging {
exceptionFormat = TestExceptionFormat.FULL
events = setOf(TestLogEvent.PASSED, TestLogEvent.SKIPPED, TestLogEvent.FAILED)
}
}
}
// Pre-compile the RIFE2 templates to bytecode for deployment
register<JavaExec>("precompileHtmlTemplates") {
classpath = sourceSets["main"].runtimeClasspath
mainClass.set("rife.template.TemplateDeployer")
args = listOf(
"-verbose",
"-t", "html",
"-d", "${projectDir}/build/classes/java/main",
"-encoding", "UTF-8", "${projectDir}/src/main/resources/templates"
)
}
register("precompileTemplates") {
dependsOn("precompileHtmlTemplates")
}
// Ensure that the templates are pre-compiled before building the jar
jar {
dependsOn("precompileTemplates")
}
// Replace the run task with one that uses the RIFE2 agent
register<JavaExec>("run") {
classpath = sourceSets["main"].runtimeClasspath
mainClass.set("hello.App")
jvmArgs = listOf("-javaagent:$rifeAgentJar")
}
// These two tasks create a self-container UberJar
register<Copy>("copyWebapp") {
from("src/main/")
include("webapp/**")
into("$buildDir/webapp")
}
register<Jar>("uberJar") {
dependsOn("jar")
dependsOn("copyWebapp")
archiveBaseName.set("hello-uber")
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
manifest {
attributes["Main-Class"] = "hello.AppUber"
publishing {
repositories {
maven {
name = "Build"
url = uri(rootProject.layout.buildDirectory.dir("repo"))
}
val uberDependencies = dependencies
.filter { !it.toString().matches("rife2-.*agent\\.jar".toRegex()) }
.map(::zipTree)
from(uberDependencies, "$buildDir/webapp")
with(jar.get())
}
}
publications {
create<MavenPublication>("maven") {
from(components["java"])
}
}
}
graalvmNative.binaries.all {
buildArgs.add("--enable-preview") // support for Jetty virtual threads with JDK 19
imageName.set("hello-$version")
}

View file

@ -13,4 +13,4 @@ public class App extends Site {
.staticResourceBase("src/main/webapp")
.start(new App());
}
}
}

View file

@ -1,6 +1,6 @@
[
{
"name":"rife.template.html.hello",
"methods":[{"name":"<init>","parameterTypes":[] }]
}
{
"name":"rife.template.html.hello",
"methods":[{"name":"<init>","parameterTypes":[] }]
}
]

View file

@ -1,8 +0,0 @@
{
"resources":{
"includes":[
{"pattern":"^webapp/.*$"}
]
},
"bundles":[]
}

View file

@ -8,4 +8,4 @@
<body>
<p>Hello World</p>
</body>
</html>
</html>

2
gradle.properties Normal file
View file

@ -0,0 +1,2 @@
org.gradle.parallel=true
org.gradle.caching=true

View file

@ -1,11 +1,9 @@
/*
* This file was generated by the Gradle 'init' task.
*
* The settings file is used to specify which projects to include in your build.
*
* Detailed information about configuring a multi-project build in Gradle can be found
* in the user manual at https://docs.gradle.org/7.6/userguide/multi_project_builds.html
*/
pluginManagement {
repositories {
mavenCentral()
gradlePluginPortal()
}
}
rootProject.name = "hello"
include("app","war")

View file

@ -2,9 +2,10 @@ plugins {
war
}
version = 1.0
base {
archivesName.set("hello")
version = 1.0
}
repositories {
@ -19,5 +20,4 @@ dependencies {
tasks.war {
webAppDirectory.set(file("../app/src/main/webapp"))
webXml = file("src/web.xml")
rootSpec.exclude("**/jetty*.jar", "**/slf4j*.jar", "**/rife2*-agent.jar")
}