diff --git a/README.md b/README.md index ba1e07c..9fdc313 100644 --- a/README.md +++ b/README.md @@ -14,10 +14,6 @@ There is a reference application at https://github.com/DatekWireless/slim-spring ### build.gradle ```groovy -plugins { - id "com.github.jruby-gradle.base" version "2.1.0-alpha.2" -} - dependencies { implementation 'no.datek:slim-spring-webmvc:0.+' } diff --git a/build.gradle b/build.gradle index 7914f37..eb993e6 100644 --- a/build.gradle +++ b/build.gradle @@ -4,10 +4,11 @@ plugins { id "org.springframework.boot" version "2.7.18" id 'maven-publish' id 'signing' + id "com.github.jruby-gradle.base" version "2.1.0-alpha.2" } group 'no.datek' -version '0.19.0' +version '0.19.1' final String JRUBY_VERSION = '9.4.6.0'; repositories { @@ -90,3 +91,44 @@ publishing { } } } + +import com.github.jrubygradle.JRubyExec + +tasks.register('installGems', JRubyExec) { + group 'gems' + description "Install gems" + script "${projectDir}/bin/bundle" + scriptArgs 'install' + finalizedBy 'copyGems' + jvmArgs '--add-opens=java.base/sun.nio.ch=ALL-UNNAMED', '--add-opens=java.base/java.io=ALL-UNNAMED' +} + +tasks.register('updateGems', JRubyExec) { + group 'gems' + description "Update gems" + script "${projectDir}/bin/bundle" + scriptArgs 'update' + finalizedBy 'cleanGems', 'copyGems' + jvmArgs '--add-opens=java.base/sun.nio.ch=ALL-UNNAMED', '--add-opens=java.base/java.io=ALL-UNNAMED' +} + +tasks.register('cleanGems', JRubyExec) { + group 'gems' + description "Clean gems" + script "${projectDir}/bin/bundle" + scriptArgs 'clean', '--force' + jvmArgs '--add-opens=java.base/sun.nio.ch=ALL-UNNAMED', '--add-opens=java.base/java.io=ALL-UNNAMED' +} + +tasks.register('copyGems', Sync) { + group 'gems' + description 'Copies gems from vendor/bundle to src/main/resources/gems' + mustRunAfter 'cleanGems' + from "build/.gems/gems" + include "*/lib/**/*" + includeEmptyDirs = false + into("src/main/resources/gems") + eachFile { fcd -> fcd.relativePath = new RelativePath(true, fcd.relativePath.segments.drop(2)) } +} + +jruby { jrubyVersion JRUBY_VERSION } diff --git a/src/main/resources/ruby/request_context.rb b/src/main/resources/ruby/request_context.rb index c4c79a9..d780c68 100644 --- a/src/main/resources/ruby/request_context.rb +++ b/src/main/resources/ruby/request_context.rb @@ -29,7 +29,7 @@ def self.default_context(locale, params, rendering_context, request) session: request.getSession(), } if defined?(SecurityContextHolder) - context.merge({ + context.merge!({ current_user: SecurityContextHolder.context&.authentication&.principal, user: request.session.getAttribute("user") || SecurityContextHolder.context&.authentication&.principal, })