|
| 1 | +# Encoding: utf-8 |
| 2 | +# Cloud Foundry Java Buildpack |
| 3 | +# Copyright 2013 the original author or authors. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +require 'fileutils' |
| 18 | +require 'java_buildpack/component/versioned_dependency_component' |
| 19 | +require 'java_buildpack/framework' |
| 20 | + |
| 21 | +module JavaBuildpack |
| 22 | + module Framework |
| 23 | + |
| 24 | + # Encapsulates the functionality for enabling zero-touch JRebel support. |
| 25 | + class JrebelAgent < JavaBuildpack::Component::VersionedDependencyComponent |
| 26 | + |
| 27 | + # (see JavaBuildpack::Component::BaseComponent#compile) |
| 28 | + def compile |
| 29 | + download_zip false |
| 30 | + FileUtils.mv(download_location + 'jrebel.jar', @droplet.sandbox + jar_name) |
| 31 | + FileUtils.remove_dir(download_location, true) |
| 32 | + end |
| 33 | + |
| 34 | + # (see JavaBuildpack::Component::BaseComponent#release) |
| 35 | + def release |
| 36 | + @droplet.java_opts |
| 37 | + .add_javaagent(@droplet.sandbox + jar_name) |
| 38 | + .add_bootclasspath_p(@droplet.sandbox + jar_name) |
| 39 | + .add_system_property('rebel.remoting_plugin', true) |
| 40 | + end |
| 41 | + |
| 42 | + protected |
| 43 | + |
| 44 | + # (see JavaBuildpack::Component::VersionedDependencyComponent#supports?) |
| 45 | + def supports? |
| 46 | + jrebel_configured?(@application.root) || jrebel_configured?(@application.root + 'WEB-INF/classes') |
| 47 | + end |
| 48 | + |
| 49 | + private |
| 50 | + |
| 51 | + def jrebel_configured?(root_path) |
| 52 | + (root_path + 'rebel.xml').exist? && (root_path + 'rebel-remote.xml').exist? |
| 53 | + end |
| 54 | + |
| 55 | + def download_location |
| 56 | + @droplet.sandbox + 'jrebel' |
| 57 | + end |
| 58 | + |
| 59 | + end |
| 60 | + |
| 61 | + end |
| 62 | +end |
0 commit comments