Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
3 changes: 2 additions & 1 deletion config/components.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
22 changes: 22 additions & 0 deletions config/java_cf_env.yml
Original file line number Diff line number Diff line change
@@ -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 Java CfEnv framework.
# See https://github.com/pivotal-cf/java-cfenv for library information

---
version: 3.+
repository_root: "{default.repository.root}/java-cfenv"
enabled: true
4 changes: 4 additions & 0 deletions config/packaging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)'
Expand Down
19 changes: 19 additions & 0 deletions docs/framework-java-cfenv.md
Original file line number Diff line number Diff line change
@@ -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` <a href="https://github.com/pivotal-cf/java-cfenv">repostitory</a> for more detail.

It also sets the 'cloud' profile for Spring Boot applications, as the Spring AutoReconfiguration framework did.

<table>
<tr>
<td><strong>Detection Criterion</strong></td>
<td>Existence of a <tt>spring-boot-3*.jar</tt> file in the application directory or a `Spring-Boot-Version: 3.*` manifest entry</td>
<td>No existing `java-cfenv` library found</td>
</tr>
<tr>
<td><strong>Tags</strong></td>
<td><tt>java-cf-env=&lt;version&gt;</tt></td>
</tr>
</table>
Tags are printed to standard output by the buildpack detect script
66 changes: 66 additions & 0 deletions lib/java_buildpack/framework/java_cf_env.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# 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)
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
11 changes: 10 additions & 1 deletion lib/java_buildpack/framework/spring_auto_reconfiguration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand All @@ -59,7 +62,13 @@ def spring?
end

def java_cfenv?
(@droplet.root + '**/*java-cfenv*.jar').glob.any?
(@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

def spring_cloud_connectors?
Expand Down
3 changes: 3 additions & 0 deletions spec/fixtures/framework_java_cf_boot_2/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Spring-Boot-Lib: manifest-lib-value/
Main-Class: org.springframework.boot.loader.JarLauncher
Spring-Boot-Version: 2.1.0.RELEASE
3 changes: 3 additions & 0 deletions spec/fixtures/framework_java_cf_boot_3/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Spring-Boot-Lib: manifest-lib-value/
Main-Class: org.springframework.boot.loader.JarLauncher
Spring-Boot-Version: 3.0.0.M1
4 changes: 4 additions & 0 deletions spec/fixtures/framework_java_cf_exists/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Spring-Boot-Lib: manifest-lib-value/
Spring-Boot-Version: 3.2.5.RELEASE
Main-Class: org.springframework.boot.loader.JarLauncher

Binary file added spec/fixtures/stub-java-cfenv.jar
Binary file not shown.
76 changes: 76 additions & 0 deletions spec/java_buildpack/framework/java_cfenv_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# 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

end
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
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
Expand Down Expand Up @@ -104,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 + 'java_cf_env.jar'
end

after do
additional_libraries.delete additional_libs_directory + 'java_cf_env.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