|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +# Cloud Foundry Java Buildpack |
| 4 | +# Copyright 2013-2018 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 'fileutils' |
| 19 | +require 'java_buildpack/component/versioned_dependency_component' |
| 20 | +require 'java_buildpack/framework' |
| 21 | +require 'java_buildpack/util/qualify_path' |
| 22 | + |
| 23 | +module JavaBuildpack |
| 24 | + module Framework |
| 25 | + |
| 26 | + # Encapsulates the functionality for enabling zero-touch JProfiler profiler support. |
| 27 | + class JprofilerProfiler < JavaBuildpack::Component::VersionedDependencyComponent |
| 28 | + include JavaBuildpack::Util |
| 29 | + |
| 30 | + def initialize(context, &version_validator) |
| 31 | + super(context, &version_validator) |
| 32 | + @component_name = 'JProfiler Profiler' |
| 33 | + end |
| 34 | + |
| 35 | + # (see JavaBuildpack::Component::BaseComponent#compile) |
| 36 | + def compile |
| 37 | + download_tar |
| 38 | + end |
| 39 | + |
| 40 | + # (see JavaBuildpack::Component::BaseComponent#release) |
| 41 | + def release |
| 42 | + properties = { 'port' => port } |
| 43 | + properties['nowait'] = nil if nowait |
| 44 | + |
| 45 | + @droplet |
| 46 | + .java_opts |
| 47 | + .add_agentpath_with_props(file_name, properties) |
| 48 | + end |
| 49 | + |
| 50 | + protected |
| 51 | + |
| 52 | + # (see JavaBuildpack::Component::VersionedDependencyComponent#supports?) |
| 53 | + def supports? |
| 54 | + @configuration['enabled'] |
| 55 | + end |
| 56 | + |
| 57 | + private |
| 58 | + |
| 59 | + def file_name |
| 60 | + @droplet.sandbox + 'bin/linux-x64/libjprofilerti.so' |
| 61 | + end |
| 62 | + |
| 63 | + def nowait |
| 64 | + v = @configuration['nowait'] |
| 65 | + v.nil? ? true : v |
| 66 | + end |
| 67 | + |
| 68 | + def port |
| 69 | + @configuration['port'] || 8_849 |
| 70 | + end |
| 71 | + |
| 72 | + end |
| 73 | + |
| 74 | + end |
| 75 | +end |
0 commit comments