|
| 1 | +# Encoding: utf-8 |
| 2 | +# TODO License. |
| 3 | + |
| 4 | +require 'java_buildpack/component/versioned_dependency_component' |
| 5 | +require 'java_buildpack/framework' |
| 6 | +require 'fileutils' |
| 7 | +require 'java_buildpack/util/qualify_path' |
| 8 | +require 'java_buildpack/logging/logger_factory' |
| 9 | + |
| 10 | +module JavaBuildpack |
| 11 | + module Framework |
| 12 | + |
| 13 | + # Installs JSON based LSP server component. |
| 14 | + class LanguageServerNodeJSON < JavaBuildpack::Component::VersionedDependencyComponent |
| 15 | + |
| 16 | + # Creates an instance |
| 17 | + # |
| 18 | + # @param [Hash] context a collection of utilities used the component |
| 19 | + def initialize(context) |
| 20 | + super(context) |
| 21 | + @logger = JavaBuildpack::Logging::LoggerFactory.instance.get_logger LanguageServerNodeJSON |
| 22 | + end |
| 23 | + |
| 24 | + |
| 25 | + # (see JavaBuildpack::Component::BaseComponent#compile) |
| 26 | + def compile |
| 27 | + @logger.debug { "Compile JSON" } |
| 28 | + # Install node js |
| 29 | + FileUtils.mkdir_p @droplet.root + "nodejs" |
| 30 | + nodedir = @droplet.sandbox + "nodejs" |
| 31 | + comp_version = @version |
| 32 | + comp_uri = @uri |
| 33 | + @version="8.0.0" |
| 34 | + @uri="https://buildpacks.cloudfoundry.org/dependencies/node/node-8.0.0-linux-x64-ade5a8e5.tgz" |
| 35 | + download_tar( target_directory=nodedir ) |
| 36 | + @version = comp_version |
| 37 | + @uri = comp_uri |
| 38 | + download_zip strip_top_level = false |
| 39 | + @droplet.copy_resources |
| 40 | + |
| 41 | + end |
| 42 | + |
| 43 | + # (see JavaBuildpack::Component::BaseComponent#release) |
| 44 | + def release |
| 45 | + |
| 46 | + @logger.debug { "Release JSON" } |
| 47 | + environment_variables = @droplet.environment_variables |
| 48 | + myWorkdir = @configuration["env"]["workdir"] |
| 49 | + environment_variables.add_environment_variable(ENV_PREFIX + "workdir", myWorkdir) |
| 50 | + myExec = @configuration["env"]["exec"] |
| 51 | + environment_variables.add_environment_variable(ENV_PREFIX + "exec", myExec) |
| 52 | + |
| 53 | + myIpc = @configuration["env"]["ipc"] |
| 54 | + @logger.debug { "JSON Env vars IPC:#{myIpc}" } |
| 55 | + myIpc.each do |key, value| |
| 56 | + environment_variables.add_environment_variable(ENV_PREFIX + key, value) |
| 57 | + end |
| 58 | + |
| 59 | + environment_variables.add_environment_variable 'PATH', "/home/vcap/app/.java-buildpack/#{@droplet.component_id}/nodejs/bin:$PATH" |
| 60 | + end |
| 61 | + |
| 62 | + protected |
| 63 | + |
| 64 | + # (see JavaBuildpack::Component::VersionedDependencyComponent#supports?) |
| 65 | + def supports? |
| 66 | + @application.environment.key?(LSPSERVERS) && @application.environment[LSPSERVERS].split(',').include?("json") |
| 67 | + end |
| 68 | + |
| 69 | + private |
| 70 | + |
| 71 | + LSPSERVERS = 'lspservers'.freeze |
| 72 | + |
| 73 | + private_constant :LSPSERVERS |
| 74 | + |
| 75 | + BINEXEC = 'exec'.freeze |
| 76 | + |
| 77 | + private_constant :BINEXEC |
| 78 | + |
| 79 | + ENV_PREFIX = 'LSPJSON_'.freeze |
| 80 | + |
| 81 | + private_constant :ENV_PREFIX |
| 82 | + |
| 83 | + end |
| 84 | + |
| 85 | + end |
| 86 | +end |
0 commit comments