From 858622ad0235bcc61fb98d7fa48b505eade3fb4a Mon Sep 17 00:00:00 2001 From: Daniel Mikusa Date: Mon, 3 Jan 2022 15:42:36 -0500 Subject: [PATCH 1/2] Add Luna API shared library to library path for Java 9+ With Java 9, the extension directory functionality was dropped. This means the buildpack has to handle installation different for Java 8 and Java 9+. With Java 8, we add the required files to the extension directory. With Java 9, we add the required JAR file to the classpath, but this was not sufficient to load the required shared library. To fix this, we are adding the Luna API shared library to the LD_LIBRARY_PATH environment variable. The JVM uses this to locate shared libraries, so it can now find the shared library. Signed-off-by: Daniel Mikusa --- .../framework/luna_security_provider.rb | 8 ++++++++ .../framework/luna_security_provider_spec.rb | 12 +++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/java_buildpack/framework/luna_security_provider.rb b/lib/java_buildpack/framework/luna_security_provider.rb index 8b3f15aba9..3a41d30a5d 100644 --- a/lib/java_buildpack/framework/luna_security_provider.rb +++ b/lib/java_buildpack/framework/luna_security_provider.rb @@ -62,6 +62,10 @@ def release if @droplet.java_home.java_9_or_later? @droplet.root_libraries << luna_provider_jar + + @droplet.environment_variables.add_environment_variable( + 'LD_LIBRARY_PATH', "$LD_LIBRARY_PATH:#{ld_lib_path}" + ) else @droplet.extension_directories << ext_dir end @@ -128,6 +132,10 @@ def lib_cklog @droplet.sandbox + 'libs/64/libcklog2.so' end + def ld_lib_path + qualify_path(@droplet.sandbox, @droplet.root) + '/jsp/64/' + end + def setup_ext_dir FileUtils.mkdir ext_dir [luna_provider_jar, luna_api_so].each do |file| diff --git a/spec/java_buildpack/framework/luna_security_provider_spec.rb b/spec/java_buildpack/framework/luna_security_provider_spec.rb index d6458de672..6a1810c88a 100644 --- a/spec/java_buildpack/framework/luna_security_provider_spec.rb +++ b/spec/java_buildpack/framework/luna_security_provider_spec.rb @@ -219,7 +219,7 @@ delegate end - it 'adds JAR to classpath during compile in Java 9', + it 'adds JAR to classpath during compile in Java 9+', cache_fixture: 'stub-luna-security-provider.tar' do component.compile @@ -227,18 +227,24 @@ expect(root_libraries).to include(droplet.sandbox + 'jsp/LunaProvider.jar') end - it 'adds JAR to classpath during release in Java 9' do + it 'adds JAR to classpath during release in Java 9+' do component.release expect(root_libraries).to include(droplet.sandbox + 'jsp/LunaProvider.jar') end - it 'adds does not add extension directory in Java 9' do + it 'adds does not add extension directory in Java 9+' do component.release expect(extension_directories).not_to include(droplet.sandbox + 'ext') end + it 'updates environment variables for Java 9+' do + component.release + expect(environment_variables).to include( + 'LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD/.java-buildpack/luna_security_provider/jsp/64/' + ) + end end context do From 507158c5c616fd1584981098c0eb73c26edb4465 Mon Sep 17 00:00:00 2001 From: Daniel Mikusa Date: Tue, 4 Jan 2022 08:30:43 -0500 Subject: [PATCH 2/2] Update spec/java_buildpack/framework/luna_security_provider_spec.rb Co-authored-by: David O'Sullivan <31728678+pivotal-david-osullivan@users.noreply.github.com> --- spec/java_buildpack/framework/luna_security_provider_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/java_buildpack/framework/luna_security_provider_spec.rb b/spec/java_buildpack/framework/luna_security_provider_spec.rb index 6a1810c88a..b38b7e7333 100644 --- a/spec/java_buildpack/framework/luna_security_provider_spec.rb +++ b/spec/java_buildpack/framework/luna_security_provider_spec.rb @@ -233,7 +233,7 @@ expect(root_libraries).to include(droplet.sandbox + 'jsp/LunaProvider.jar') end - it 'adds does not add extension directory in Java 9+' do + it 'does not add extension directory in Java 9+' do component.release expect(extension_directories).not_to include(droplet.sandbox + 'ext')