|
| 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 | + end |
| 45 | + |
| 46 | + protected |
| 47 | + |
| 48 | + # (see JavaBuildpack::Component::VersionedDependencyComponent#supports?) |
| 49 | + def supports? |
| 50 | + @configuration['enabled'] && spring_boot_3? && !java_cfenv? |
| 51 | + end |
| 52 | + |
| 53 | + private |
| 54 | + |
| 55 | + def spring_boot_3? |
| 56 | + @spring_boot_utils.is?(@application) && Gem::Version.new((@spring_boot_utils.version @application)).release >= |
| 57 | + Gem::Version.new('3.0.0') |
| 58 | + end |
| 59 | + |
| 60 | + def java_cfenv? |
| 61 | + (@droplet.root + '**/*java-cfenv*.jar').glob.any? |
| 62 | + end |
| 63 | + |
| 64 | + end |
| 65 | + end |
| 66 | +end |
0 commit comments