From ddaa8564470aea1b7143a57c53f6809786fc49ec Mon Sep 17 00:00:00 2001 From: David O'Sullivan Date: Wed, 16 Aug 2023 17:22:14 +0100 Subject: [PATCH 1/5] adds java-cfenv framework --- README.md | 1 + config/components.yml | 3 +- config/java_cf_env.yml | 22 +++++ config/packaging.yml | 4 + docs/framework-java-cfenv.md | 19 ++++ lib/java_buildpack/framework/java_cf_env.rb | 67 ++++++++++++++ .../framework/spring_auto_reconfiguration.rb | 5 +- .../WEB-INF/lib/spring-boot-3.2.3.RELEASE.jar | 0 .../META-INF/MANIFEST.MF | 3 + .../WEB-INF/lib/spring-boot-1.0.0.RELEASE.jar | 0 .../META-INF/MANIFEST.MF | 3 + .../WEB-INF/lib/spring-boot-3.0.0.M1.jar | 0 .../META-INF/MANIFEST.MF | 4 + .../WEB-INF/lib/java-cfenv-2.1.2.RELEASE.jar | 0 .../lib/java-cfenv-boot-2.1.2.RELEASE.jar | 0 .../lib/java-cfenv-jdbc-2.1.2.RELEASE.jar | 0 .../WEB-INF/lib/spring-boot-3.2.3.RELEASE.jar | 0 spec/fixtures/stub-java-cfenv.jar | Bin 0 -> 341 bytes .../framework/java_cfenv_spec.rb | 84 ++++++++++++++++++ .../spring_auto_reconfiguration_spec.rb | 8 +- 20 files changed, 220 insertions(+), 3 deletions(-) create mode 100644 config/java_cf_env.yml create mode 100644 docs/framework-java-cfenv.md create mode 100644 lib/java_buildpack/framework/java_cf_env.rb create mode 100644 spec/fixtures/framework_auto_reconfiguration_java_cfenv_bp/WEB-INF/lib/spring-boot-3.2.3.RELEASE.jar create mode 100644 spec/fixtures/framework_java_cf_boot_2/META-INF/MANIFEST.MF create mode 100644 spec/fixtures/framework_java_cf_boot_2/WEB-INF/lib/spring-boot-1.0.0.RELEASE.jar create mode 100644 spec/fixtures/framework_java_cf_boot_3/META-INF/MANIFEST.MF create mode 100644 spec/fixtures/framework_java_cf_boot_3/WEB-INF/lib/spring-boot-3.0.0.M1.jar create mode 100644 spec/fixtures/framework_java_cf_exists/META-INF/MANIFEST.MF create mode 100644 spec/fixtures/framework_java_cf_exists/WEB-INF/lib/java-cfenv-2.1.2.RELEASE.jar create mode 100644 spec/fixtures/framework_java_cf_exists/WEB-INF/lib/java-cfenv-boot-2.1.2.RELEASE.jar create mode 100644 spec/fixtures/framework_java_cf_exists/WEB-INF/lib/java-cfenv-jdbc-2.1.2.RELEASE.jar create mode 100644 spec/fixtures/framework_java_cf_exists/WEB-INF/lib/spring-boot-3.2.3.RELEASE.jar create mode 100644 spec/fixtures/stub-java-cfenv.jar create mode 100644 spec/java_buildpack/framework/java_cfenv_spec.rb diff --git a/README.md b/README.md index e563ea745d..e562ea1a34 100644 --- a/README.md +++ b/README.md @@ -126,6 +126,7 @@ The buildpack supports extension through the use of Git repository forking. The * [Google Stackdriver Profiler](docs/framework-google_stackdriver_profiler.md) ([Configuration](docs/framework-google_stackdriver_profiler.md#configuration)) * [Introscope Agent](docs/framework-introscope_agent.md) ([Configuration](docs/framework-introscope_agent.md#configuration)) * [JaCoCo Agent](docs/framework-jacoco_agent.md) ([Configuration](docs/framework-jacoco_agent.md#configuration)) + * [Java CfEnv](docs/framework-java-cfenv.md) ([Configuration](docs/framework-java-cfenv.md#configuration)) * [Java Memory Assistant](docs/framework-java_memory_assistant.md) ([Configuration](docs/framework-java_memory_assistant.md#configuration)) * [Java Options](docs/framework-java_opts.md) ([Configuration](docs/framework-java_opts.md#configuration)) * [JProfiler Profiler](docs/framework-jprofiler_profiler.md) ([Configuration](docs/framework-jprofiler_profiler.md#configuration)) diff --git a/config/components.yml b/config/components.yml index 41d7bc1b73..79a60156fd 100644 --- a/config/components.yml +++ b/config/components.yml @@ -54,10 +54,11 @@ frameworks: - "JavaBuildpack::Framework::Debug" - "JavaBuildpack::Framework::DynatraceOneAgent" - "JavaBuildpack::Framework::ElasticApmAgent" -# - "JavaBuildpack::Framework::GoogleStackdriverDebugger" +# - "JavaBuildpack::Framework::GoogleStackdriverDebugger" - "JavaBuildpack::Framework::GoogleStackdriverProfiler" - "JavaBuildpack::Framework::IntroscopeAgent" - "JavaBuildpack::Framework::JacocoAgent" + - "JavaBuildpack::Framework::JavaCfEnv" - "JavaBuildpack::Framework::JavaMemoryAssistant" - "JavaBuildpack::Framework::Jmx" - "JavaBuildpack::Framework::JprofilerProfiler" diff --git a/config/java_cf_env.yml b/config/java_cf_env.yml new file mode 100644 index 0000000000..e0494369c8 --- /dev/null +++ b/config/java_cf_env.yml @@ -0,0 +1,22 @@ +# Cloud Foundry Java Buildpack +# Copyright 2013-2023 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 +# +# http://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. + +# Configuration for the Spring Auto Reconfiguration framework. +# Note that the repository is shared with the Play Auto Reconfiguration framework and should be kept in step to +# avoid conflicts. +--- +version: 3.+ +repository_root: "{default.repository.root}/java-cfenv" +enabled: true diff --git a/config/packaging.yml b/config/packaging.yml index aed29fdc22..8818f0c517 100644 --- a/config/packaging.yml +++ b/config/packaging.yml @@ -82,6 +82,10 @@ jacoco_agent: name: JaCoCo Agent release_notes: '[Release Notes](https://github.com/jacoco/jacoco/releases)' +java_cf_env: + name: Java CFEnv + release_notes: '[Release Notes](https://github.com/pivotal-cf/java-cfenv/releases)' + jprofiler_profiler: name: JProfiler Profiler release_notes: '[ChangeLog](https://www.ej-technologies.com/download/jprofiler/changelog.html)' diff --git a/docs/framework-java-cfenv.md b/docs/framework-java-cfenv.md new file mode 100644 index 0000000000..1e1fe474a7 --- /dev/null +++ b/docs/framework-java-cfenv.md @@ -0,0 +1,19 @@ +# Java CfEnv Framework +The Java CfEnv Framework provides the `java-cfenv` library for Spring Boot 3+ applications. This library sets various Spring Boot properties by parsing CloudFoundry variables such as `VCAP_SERVICES`, allowing Spring Boot's autoconfiguration to kick in. + +This is the recommended replacement for Spring AutoReconfiguration library which is deprecated. See the `java-cfenv` repostitory for more detail. + +It also sets the 'cloud' profile for Spring Boot applications, as the Spring AutoReconfiguration framework did. + + + + + + + + + + + +
Detection CriterionExistence of a spring-boot-3*.jar file in the application directory or a `Spring-Boot-Version: 3.*` manifest entryNo existing `java-cfenv` library found
Tagsjava-cf-env=<version>
+Tags are printed to standard output by the buildpack detect script diff --git a/lib/java_buildpack/framework/java_cf_env.rb b/lib/java_buildpack/framework/java_cf_env.rb new file mode 100644 index 0000000000..b89c913a07 --- /dev/null +++ b/lib/java_buildpack/framework/java_cf_env.rb @@ -0,0 +1,67 @@ +# frozen_string_literal: true + +# Cloud Foundry Java Buildpack +# Copyright 2013-2020 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 +# +# http://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. + +require 'java_buildpack/component/versioned_dependency_component' +require 'java_buildpack/framework' +require 'java_buildpack/util/spring_boot_utils' + +module JavaBuildpack + module Framework + + # Encapsulates the detect, compile, and release functionality for enabling cloud auto-reconfiguration in Spring + # applications. + class JavaCfEnv < JavaBuildpack::Component::VersionedDependencyComponent + include JavaBuildpack::Util + + def initialize(context) + @spring_boot_utils = JavaBuildpack::Util::SpringBootUtils.new + super(context) + end + + # (see JavaBuildpack::Component::BaseComponent#compile) + def compile + download_jar + @droplet.additional_libraries << (@droplet.sandbox + jar_name) + end + + # (see JavaBuildpack::Component::BaseComponent#release) + def release + @droplet.additional_libraries << (@droplet.sandbox + jar_name) + @droplet.environment_variables.add_environment_variable 'SPRING_PROFILES_INCLUDE', 'cloud' + end + + protected + + # (see JavaBuildpack::Component::VersionedDependencyComponent#supports?) + def supports? + @configuration['enabled'] && spring_boot_3? && !java_cfenv? + end + + private + + def spring_boot_3? + @spring_boot_utils.is?(@application) && Gem::Version.new((@spring_boot_utils.version @application)).release >= + Gem::Version.new('3.0.0') + end + + def java_cfenv? + (@droplet.root + '**/*java-cfenv*.jar').glob.any? + end + + end + end +end diff --git a/lib/java_buildpack/framework/spring_auto_reconfiguration.rb b/lib/java_buildpack/framework/spring_auto_reconfiguration.rb index 80b20ca027..ece570f3f9 100644 --- a/lib/java_buildpack/framework/spring_auto_reconfiguration.rb +++ b/lib/java_buildpack/framework/spring_auto_reconfiguration.rb @@ -59,7 +59,10 @@ def spring? end def java_cfenv? - (@droplet.root + '**/*java-cfenv*.jar').glob.any? + (@droplet.root + '**/*java-cfenv*.jar').glob.any? || + @droplet.additional_libraries.sort.map do |additional_library| + return false unless (additional_library.dirname + '*java-cfenv*.jar').glob.any? + end end def spring_cloud_connectors? diff --git a/spec/fixtures/framework_auto_reconfiguration_java_cfenv_bp/WEB-INF/lib/spring-boot-3.2.3.RELEASE.jar b/spec/fixtures/framework_auto_reconfiguration_java_cfenv_bp/WEB-INF/lib/spring-boot-3.2.3.RELEASE.jar new file mode 100644 index 0000000000..e69de29bb2 diff --git a/spec/fixtures/framework_java_cf_boot_2/META-INF/MANIFEST.MF b/spec/fixtures/framework_java_cf_boot_2/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..ce0077f4ce --- /dev/null +++ b/spec/fixtures/framework_java_cf_boot_2/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Spring-Boot-Lib: manifest-lib-value/ +Main-Class: org.springframework.boot.loader.JarLauncher +Spring-Boot-Version: 2.1.0.RELEASE diff --git a/spec/fixtures/framework_java_cf_boot_2/WEB-INF/lib/spring-boot-1.0.0.RELEASE.jar b/spec/fixtures/framework_java_cf_boot_2/WEB-INF/lib/spring-boot-1.0.0.RELEASE.jar new file mode 100644 index 0000000000..e69de29bb2 diff --git a/spec/fixtures/framework_java_cf_boot_3/META-INF/MANIFEST.MF b/spec/fixtures/framework_java_cf_boot_3/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..a64827339d --- /dev/null +++ b/spec/fixtures/framework_java_cf_boot_3/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Spring-Boot-Lib: manifest-lib-value/ +Main-Class: org.springframework.boot.loader.JarLauncher +Spring-Boot-Version: 3.0.0.M1 diff --git a/spec/fixtures/framework_java_cf_boot_3/WEB-INF/lib/spring-boot-3.0.0.M1.jar b/spec/fixtures/framework_java_cf_boot_3/WEB-INF/lib/spring-boot-3.0.0.M1.jar new file mode 100644 index 0000000000..e69de29bb2 diff --git a/spec/fixtures/framework_java_cf_exists/META-INF/MANIFEST.MF b/spec/fixtures/framework_java_cf_exists/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..47eb0c27e7 --- /dev/null +++ b/spec/fixtures/framework_java_cf_exists/META-INF/MANIFEST.MF @@ -0,0 +1,4 @@ +Spring-Boot-Lib: manifest-lib-value/ +Spring-Boot-Version: 3.2.5.RELEASE +Main-Class: org.springframework.boot.loader.JarLauncher + diff --git a/spec/fixtures/framework_java_cf_exists/WEB-INF/lib/java-cfenv-2.1.2.RELEASE.jar b/spec/fixtures/framework_java_cf_exists/WEB-INF/lib/java-cfenv-2.1.2.RELEASE.jar new file mode 100644 index 0000000000..e69de29bb2 diff --git a/spec/fixtures/framework_java_cf_exists/WEB-INF/lib/java-cfenv-boot-2.1.2.RELEASE.jar b/spec/fixtures/framework_java_cf_exists/WEB-INF/lib/java-cfenv-boot-2.1.2.RELEASE.jar new file mode 100644 index 0000000000..e69de29bb2 diff --git a/spec/fixtures/framework_java_cf_exists/WEB-INF/lib/java-cfenv-jdbc-2.1.2.RELEASE.jar b/spec/fixtures/framework_java_cf_exists/WEB-INF/lib/java-cfenv-jdbc-2.1.2.RELEASE.jar new file mode 100644 index 0000000000..e69de29bb2 diff --git a/spec/fixtures/framework_java_cf_exists/WEB-INF/lib/spring-boot-3.2.3.RELEASE.jar b/spec/fixtures/framework_java_cf_exists/WEB-INF/lib/spring-boot-3.2.3.RELEASE.jar new file mode 100644 index 0000000000..e69de29bb2 diff --git a/spec/fixtures/stub-java-cfenv.jar b/spec/fixtures/stub-java-cfenv.jar new file mode 100644 index 0000000000000000000000000000000000000000..0878c3ccb50e0696f38ae356e9854c75199158f3 GIT binary patch literal 341 zcmWIWW@Zs#;Nak3$ZLM$#DD}i8CV#6T|*poJ^kGD|D9rBU}gyLX6FE@V1gx0>v$BCyF#%yMkUj+BFaQAGLPY%l literal 0 HcmV?d00001 diff --git a/spec/java_buildpack/framework/java_cfenv_spec.rb b/spec/java_buildpack/framework/java_cfenv_spec.rb new file mode 100644 index 0000000000..e06dc4fbbf --- /dev/null +++ b/spec/java_buildpack/framework/java_cfenv_spec.rb @@ -0,0 +1,84 @@ +# frozen_string_literal: true + +# Cloud Foundry Java Buildpack +# Copyright 2013-2020 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 +# +# http://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. + +require 'spec_helper' +require 'component_helper' +require 'logging_helper' +require 'java_buildpack/framework/java_cf_env' + +describe JavaBuildpack::Framework::JavaCfEnv do + include_context 'with component help' + include_context 'with console help' + include_context 'with logging help' + + let(:configuration) { { 'enabled' => true } } + + it 'detects with Spring Boot 3 JAR', + app_fixture: 'framework_java_cf_boot_3' do + + expect(component.detect).to eq("java-cf-env=#{version}") + end + + it 'does not detect with Spring Boot < 3', + app_fixture: 'framework_java_cf_boot_2' do + + expect(component.detect).to be_nil + end + + it 'does not detect with Spring Boot 3 & java-cfenv present', + app_fixture: 'framework_java_cf_exists' do + + expect(component.detect).to be_nil + end + + context do + let(:configuration) { { 'enabled' => false } } + + it 'does not detect if disabled', + app_fixture: 'framework_java_cf_boot_3' do + + expect(component.detect).to be_nil + end + end + + it 'downloads additional libraries', + app_fixture: 'framework_java_cf_boot_3', + cache_fixture: 'stub-java-cfenv.jar' do + + component.compile + + expect(sandbox + "java_cf_env-#{version}.jar").to exist + end + + it 'adds to additional libraries', + app_fixture: 'framework_java_cf_boot_3', + cache_fixture: 'stub-java-cfenv.jar' do + + component.release + + expect(additional_libraries).to include(sandbox + "java_cf_env-#{version}.jar") + end + + it 'activates the cloud profile', + app_fixture: 'framework_java_cf_boot_3', + cache_fixture: 'stub-java-cfenv.jar' do + + component.release + + expect(environment_variables).to include('SPRING_PROFILES_INCLUDE=cloud') + end +end diff --git a/spec/java_buildpack/framework/spring_auto_reconfiguration_spec.rb b/spec/java_buildpack/framework/spring_auto_reconfiguration_spec.rb index d3f5cec59c..672b53fd78 100644 --- a/spec/java_buildpack/framework/spring_auto_reconfiguration_spec.rb +++ b/spec/java_buildpack/framework/spring_auto_reconfiguration_spec.rb @@ -39,12 +39,18 @@ expect(component.detect).to eq("spring-auto-reconfiguration=#{version}") end - it 'does not detect with Spring JAR and java-cfenv', + it 'does not detect with Spring JAR and user java-cfenv', app_fixture: 'framework_auto_reconfiguration_java_cfenv' do expect(component.detect).to be_nil end + it 'does not detect with Spring JAR and buildpack java-cfenv', + app_fixture: 'framework_auto_reconfiguration_java_cfenv_bp' do + + expect(component.detect).to be_nil + end + it 'does not detect without Spring JAR' do expect(component.detect).to be_nil end From b0c4bfe02105eb61a7cfbbf30111399f55d8ef7e Mon Sep 17 00:00:00 2001 From: David O'Sullivan Date: Wed, 30 Aug 2023 12:55:56 +0100 Subject: [PATCH 2/5] addresses comments on java-cfenv framework --- config/java_cf_env.yml | 6 +++--- lib/java_buildpack/framework/java_cf_env.rb | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/config/java_cf_env.yml b/config/java_cf_env.yml index e0494369c8..a021138ff7 100644 --- a/config/java_cf_env.yml +++ b/config/java_cf_env.yml @@ -13,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -# Configuration for the Spring Auto Reconfiguration framework. -# Note that the repository is shared with the Play Auto Reconfiguration framework and should be kept in step to -# avoid conflicts. +# Configuration for the Java CfEnv framework. +# See https://github.com/pivotal-cf/java-cfenv for library information + --- version: 3.+ repository_root: "{default.repository.root}/java-cfenv" diff --git a/lib/java_buildpack/framework/java_cf_env.rb b/lib/java_buildpack/framework/java_cf_env.rb index b89c913a07..5b78128fe8 100644 --- a/lib/java_buildpack/framework/java_cf_env.rb +++ b/lib/java_buildpack/framework/java_cf_env.rb @@ -48,7 +48,7 @@ def release # (see JavaBuildpack::Component::VersionedDependencyComponent#supports?) def supports? - @configuration['enabled'] && spring_boot_3? && !java_cfenv? + @configuration['enabled'] && spring_boot_3? && !java_cfenv? end private From 00238912f0cadce25b7c8211f2201e792360fbfd Mon Sep 17 00:00:00 2001 From: David O'Sullivan Date: Wed, 6 Sep 2023 16:44:08 +0100 Subject: [PATCH 3/5] fixes bug with supports logic for cfenv --- .../framework/spring_auto_reconfiguration.rb | 7 +++--- .../WEB-INF/lib/spring-boot-3.2.3.RELEASE.jar | 0 .../spring_auto_reconfiguration_spec.rb | 23 ++++++++++++++----- 3 files changed, 20 insertions(+), 10 deletions(-) delete mode 100644 spec/fixtures/framework_auto_reconfiguration_java_cfenv_bp/WEB-INF/lib/spring-boot-3.2.3.RELEASE.jar diff --git a/lib/java_buildpack/framework/spring_auto_reconfiguration.rb b/lib/java_buildpack/framework/spring_auto_reconfiguration.rb index ece570f3f9..bbc2383b97 100644 --- a/lib/java_buildpack/framework/spring_auto_reconfiguration.rb +++ b/lib/java_buildpack/framework/spring_auto_reconfiguration.rb @@ -59,10 +59,9 @@ def spring? end def java_cfenv? - (@droplet.root + '**/*java-cfenv*.jar').glob.any? || - @droplet.additional_libraries.sort.map do |additional_library| - return false unless (additional_library.dirname + '*java-cfenv*.jar').glob.any? - end + (@droplet.root + '**/*java-cfenv*.jar').glob.any? || @droplet.additional_libraries.any? do |additional_library| + additional_library.instance_variable_get(:@pathname).fnmatch?('*java-cfenv*.jar') + end end def spring_cloud_connectors? diff --git a/spec/fixtures/framework_auto_reconfiguration_java_cfenv_bp/WEB-INF/lib/spring-boot-3.2.3.RELEASE.jar b/spec/fixtures/framework_auto_reconfiguration_java_cfenv_bp/WEB-INF/lib/spring-boot-3.2.3.RELEASE.jar deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/spec/java_buildpack/framework/spring_auto_reconfiguration_spec.rb b/spec/java_buildpack/framework/spring_auto_reconfiguration_spec.rb index 672b53fd78..b366130ee9 100644 --- a/spec/java_buildpack/framework/spring_auto_reconfiguration_spec.rb +++ b/spec/java_buildpack/framework/spring_auto_reconfiguration_spec.rb @@ -45,12 +45,6 @@ expect(component.detect).to be_nil end - it 'does not detect with Spring JAR and buildpack java-cfenv', - app_fixture: 'framework_auto_reconfiguration_java_cfenv_bp' do - - expect(component.detect).to be_nil - end - it 'does not detect without Spring JAR' do expect(component.detect).to be_nil end @@ -110,4 +104,21 @@ expect(additional_libraries).to include(sandbox + "spring_auto_reconfiguration-#{version}.jar") end + context('when java-cfenv injects its lib') do + + before do + additional_libraries.insert 0, additional_libs_directory + 'stub-java-cfenv.jar' + end + + after do + additional_libraries.delete additional_libs_directory + 'stub-java-cfenv.jar' + end + + it 'does not detect with Spring JAR and injected cfenv', + app_fixture: 'framework_auto_reconfiguration_servlet_3' do + + expect(component.detect).to be_nil + end + + end end From dbcaf77ac0ce1258927ffb67456fa276e7527325 Mon Sep 17 00:00:00 2001 From: David O'Sullivan Date: Fri, 8 Sep 2023 14:30:30 +0100 Subject: [PATCH 4/5] fixes bug with logic for SAR --- lib/java_buildpack/framework/java_cf_env.rb | 3 ++- .../framework/spring_auto_reconfiguration.rb | 11 +++++++++-- spec/java_buildpack/framework/java_cfenv_spec.rb | 2 +- .../framework/spring_auto_reconfiguration_spec.rb | 4 ++-- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/java_buildpack/framework/java_cf_env.rb b/lib/java_buildpack/framework/java_cf_env.rb index 5b78128fe8..3335dfba50 100644 --- a/lib/java_buildpack/framework/java_cf_env.rb +++ b/lib/java_buildpack/framework/java_cf_env.rb @@ -41,7 +41,8 @@ def compile # (see JavaBuildpack::Component::BaseComponent#release) def release @droplet.additional_libraries << (@droplet.sandbox + jar_name) - @droplet.environment_variables.add_environment_variable 'SPRING_PROFILES_INCLUDE', 'cloud' + @droplet.environment_variables.add_environment_variable \ + 'SPRING_PROFILES_INCLUDE', '$SPRING_PROFILES_INCLUDE,cloud' end protected diff --git a/lib/java_buildpack/framework/spring_auto_reconfiguration.rb b/lib/java_buildpack/framework/spring_auto_reconfiguration.rb index bbc2383b97..f53646e240 100644 --- a/lib/java_buildpack/framework/spring_auto_reconfiguration.rb +++ b/lib/java_buildpack/framework/spring_auto_reconfiguration.rb @@ -33,6 +33,7 @@ def initialize(context) # (see JavaBuildpack::Component::BaseComponent#compile) def compile log_warning_scc_manual if spring_cloud_connectors? + return if java_cf_env_framework? download_jar @droplet.additional_libraries << (@droplet.sandbox + jar_name) @@ -42,6 +43,8 @@ def compile # (see JavaBuildpack::Component::BaseComponent#release) def release + return if java_cf_env_framework? + @droplet.additional_libraries << (@droplet.sandbox + jar_name) end @@ -59,8 +62,12 @@ def spring? end def java_cfenv? - (@droplet.root + '**/*java-cfenv*.jar').glob.any? || @droplet.additional_libraries.any? do |additional_library| - additional_library.instance_variable_get(:@pathname).fnmatch?('*java-cfenv*.jar') + (@droplet.root + '**/*java-cfenv*.jar').glob.any? || java_cf_env_framework? + end + + def java_cf_env_framework? + @droplet.additional_libraries.any? do |additional_library| + additional_library.instance_variable_get(:@pathname).fnmatch?('*java_cf_env*.jar') end end diff --git a/spec/java_buildpack/framework/java_cfenv_spec.rb b/spec/java_buildpack/framework/java_cfenv_spec.rb index e06dc4fbbf..6e75a8145b 100644 --- a/spec/java_buildpack/framework/java_cfenv_spec.rb +++ b/spec/java_buildpack/framework/java_cfenv_spec.rb @@ -79,6 +79,6 @@ component.release - expect(environment_variables).to include('SPRING_PROFILES_INCLUDE=cloud') + expect(environment_variables).to include('SPRING_PROFILES_INCLUDE=$SPRING_PROFILES_INCLUDE,cloud') end end diff --git a/spec/java_buildpack/framework/spring_auto_reconfiguration_spec.rb b/spec/java_buildpack/framework/spring_auto_reconfiguration_spec.rb index b366130ee9..17a2946b04 100644 --- a/spec/java_buildpack/framework/spring_auto_reconfiguration_spec.rb +++ b/spec/java_buildpack/framework/spring_auto_reconfiguration_spec.rb @@ -107,11 +107,11 @@ context('when java-cfenv injects its lib') do before do - additional_libraries.insert 0, additional_libs_directory + 'stub-java-cfenv.jar' + additional_libraries.insert 0, additional_libs_directory + 'java_cf_env.jar' end after do - additional_libraries.delete additional_libs_directory + 'stub-java-cfenv.jar' + additional_libraries.delete additional_libs_directory + 'java_cf_env.jar' end it 'does not detect with Spring JAR and injected cfenv', From a58b76fa39e64756e328734022c0643ad2ebff7a Mon Sep 17 00:00:00 2001 From: Anthony Dahanne Date: Mon, 11 Sep 2023 14:44:27 -0400 Subject: [PATCH 5/5] Remove profile inclusion --- lib/java_buildpack/framework/java_cf_env.rb | 2 -- spec/java_buildpack/framework/java_cfenv_spec.rb | 8 -------- 2 files changed, 10 deletions(-) diff --git a/lib/java_buildpack/framework/java_cf_env.rb b/lib/java_buildpack/framework/java_cf_env.rb index 3335dfba50..3b3644a040 100644 --- a/lib/java_buildpack/framework/java_cf_env.rb +++ b/lib/java_buildpack/framework/java_cf_env.rb @@ -41,8 +41,6 @@ def compile # (see JavaBuildpack::Component::BaseComponent#release) def release @droplet.additional_libraries << (@droplet.sandbox + jar_name) - @droplet.environment_variables.add_environment_variable \ - 'SPRING_PROFILES_INCLUDE', '$SPRING_PROFILES_INCLUDE,cloud' end protected diff --git a/spec/java_buildpack/framework/java_cfenv_spec.rb b/spec/java_buildpack/framework/java_cfenv_spec.rb index 6e75a8145b..bfd67e7729 100644 --- a/spec/java_buildpack/framework/java_cfenv_spec.rb +++ b/spec/java_buildpack/framework/java_cfenv_spec.rb @@ -73,12 +73,4 @@ expect(additional_libraries).to include(sandbox + "java_cf_env-#{version}.jar") end - it 'activates the cloud profile', - app_fixture: 'framework_java_cf_boot_3', - cache_fixture: 'stub-java-cfenv.jar' do - - component.release - - expect(environment_variables).to include('SPRING_PROFILES_INCLUDE=$SPRING_PROFILES_INCLUDE,cloud') - end end