Skip to content

Commit ddaa856

Browse files
author
David O'Sullivan
committed
adds java-cfenv framework
1 parent 194ecce commit ddaa856

File tree

20 files changed

+220
-3
lines changed

20 files changed

+220
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ The buildpack supports extension through the use of Git repository forking. The
126126
* [Google Stackdriver Profiler](docs/framework-google_stackdriver_profiler.md) ([Configuration](docs/framework-google_stackdriver_profiler.md#configuration))
127127
* [Introscope Agent](docs/framework-introscope_agent.md) ([Configuration](docs/framework-introscope_agent.md#configuration))
128128
* [JaCoCo Agent](docs/framework-jacoco_agent.md) ([Configuration](docs/framework-jacoco_agent.md#configuration))
129+
* [Java CfEnv](docs/framework-java-cfenv.md) ([Configuration](docs/framework-java-cfenv.md#configuration))
129130
* [Java Memory Assistant](docs/framework-java_memory_assistant.md) ([Configuration](docs/framework-java_memory_assistant.md#configuration))
130131
* [Java Options](docs/framework-java_opts.md) ([Configuration](docs/framework-java_opts.md#configuration))
131132
* [JProfiler Profiler](docs/framework-jprofiler_profiler.md) ([Configuration](docs/framework-jprofiler_profiler.md#configuration))

config/components.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,11 @@ frameworks:
5454
- "JavaBuildpack::Framework::Debug"
5555
- "JavaBuildpack::Framework::DynatraceOneAgent"
5656
- "JavaBuildpack::Framework::ElasticApmAgent"
57-
# - "JavaBuildpack::Framework::GoogleStackdriverDebugger"
57+
# - "JavaBuildpack::Framework::GoogleStackdriverDebugger"
5858
- "JavaBuildpack::Framework::GoogleStackdriverProfiler"
5959
- "JavaBuildpack::Framework::IntroscopeAgent"
6060
- "JavaBuildpack::Framework::JacocoAgent"
61+
- "JavaBuildpack::Framework::JavaCfEnv"
6162
- "JavaBuildpack::Framework::JavaMemoryAssistant"
6263
- "JavaBuildpack::Framework::Jmx"
6364
- "JavaBuildpack::Framework::JprofilerProfiler"

config/java_cf_env.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Cloud Foundry Java Buildpack
2+
# Copyright 2013-2023 the original author or authors.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
# Configuration for the Spring Auto Reconfiguration framework.
17+
# Note that the repository is shared with the Play Auto Reconfiguration framework and should be kept in step to
18+
# avoid conflicts.
19+
---
20+
version: 3.+
21+
repository_root: "{default.repository.root}/java-cfenv"
22+
enabled: true

config/packaging.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ jacoco_agent:
8282
name: JaCoCo Agent
8383
release_notes: '[Release Notes](https://github.com/jacoco/jacoco/releases)'
8484

85+
java_cf_env:
86+
name: Java CFEnv
87+
release_notes: '[Release Notes](https://github.com/pivotal-cf/java-cfenv/releases)'
88+
8589
jprofiler_profiler:
8690
name: JProfiler Profiler
8791
release_notes: '[ChangeLog](https://www.ej-technologies.com/download/jprofiler/changelog.html)'

docs/framework-java-cfenv.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Java CfEnv Framework
2+
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.
3+
4+
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.
5+
6+
It also sets the 'cloud' profile for Spring Boot applications, as the Spring AutoReconfiguration framework did.
7+
8+
<table>
9+
<tr>
10+
<td><strong>Detection Criterion</strong></td>
11+
<td>Existence of a <tt>spring-boot-3*.jar</tt> file in the application directory or a `Spring-Boot-Version: 3.*` manifest entry</td>
12+
<td>No existing `java-cfenv` library found</td>
13+
</tr>
14+
<tr>
15+
<td><strong>Tags</strong></td>
16+
<td><tt>java-cf-env=&lt;version&gt;</tt></td>
17+
</tr>
18+
</table>
19+
Tags are printed to standard output by the buildpack detect script
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# frozen_string_literal: true
2+
3+
# Cloud Foundry Java Buildpack
4+
# Copyright 2013-2020 the original author or authors.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
require 'java_buildpack/component/versioned_dependency_component'
19+
require 'java_buildpack/framework'
20+
require 'java_buildpack/util/spring_boot_utils'
21+
22+
module JavaBuildpack
23+
module Framework
24+
25+
# Encapsulates the detect, compile, and release functionality for enabling cloud auto-reconfiguration in Spring
26+
# applications.
27+
class JavaCfEnv < JavaBuildpack::Component::VersionedDependencyComponent
28+
include JavaBuildpack::Util
29+
30+
def initialize(context)
31+
@spring_boot_utils = JavaBuildpack::Util::SpringBootUtils.new
32+
super(context)
33+
end
34+
35+
# (see JavaBuildpack::Component::BaseComponent#compile)
36+
def compile
37+
download_jar
38+
@droplet.additional_libraries << (@droplet.sandbox + jar_name)
39+
end
40+
41+
# (see JavaBuildpack::Component::BaseComponent#release)
42+
def release
43+
@droplet.additional_libraries << (@droplet.sandbox + jar_name)
44+
@droplet.environment_variables.add_environment_variable 'SPRING_PROFILES_INCLUDE', 'cloud'
45+
end
46+
47+
protected
48+
49+
# (see JavaBuildpack::Component::VersionedDependencyComponent#supports?)
50+
def supports?
51+
@configuration['enabled'] && spring_boot_3? && !java_cfenv?
52+
end
53+
54+
private
55+
56+
def spring_boot_3?
57+
@spring_boot_utils.is?(@application) && Gem::Version.new((@spring_boot_utils.version @application)).release >=
58+
Gem::Version.new('3.0.0')
59+
end
60+
61+
def java_cfenv?
62+
(@droplet.root + '**/*java-cfenv*.jar').glob.any?
63+
end
64+
65+
end
66+
end
67+
end

lib/java_buildpack/framework/spring_auto_reconfiguration.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ def spring?
5959
end
6060

6161
def java_cfenv?
62-
(@droplet.root + '**/*java-cfenv*.jar').glob.any?
62+
(@droplet.root + '**/*java-cfenv*.jar').glob.any? ||
63+
@droplet.additional_libraries.sort.map do |additional_library|
64+
return false unless (additional_library.dirname + '*java-cfenv*.jar').glob.any?
65+
end
6366
end
6467

6568
def spring_cloud_connectors?

spec/fixtures/framework_auto_reconfiguration_java_cfenv_bp/WEB-INF/lib/spring-boot-3.2.3.RELEASE.jar

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Spring-Boot-Lib: manifest-lib-value/
2+
Main-Class: org.springframework.boot.loader.JarLauncher
3+
Spring-Boot-Version: 2.1.0.RELEASE

spec/fixtures/framework_java_cf_boot_2/WEB-INF/lib/spring-boot-1.0.0.RELEASE.jar

Whitespace-only changes.

0 commit comments

Comments
 (0)