Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

Commit

Permalink
Adding Json and Xml components (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
i328638 authored and amiramw committed Dec 12, 2017
1 parent c7ea4a2 commit fe8c2c6
Show file tree
Hide file tree
Showing 7 changed files with 202 additions and 0 deletions.
2 changes: 2 additions & 0 deletions config/components.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,7 @@ frameworks:
- "JavaBuildpack::Framework::JavaOpts"
- "JavaBuildpack::Framework::LanguageServerBinExecJDT"
- "JavaBuildpack::Framework::LanguageServerNodeESLINT"
- "JavaBuildpack::Framework::LanguageServerNodeJSON"
- "JavaBuildpack::Framework::LanguageServerNodeXML"

# - "JavaBuildpack::Framework::LanguageServerNodeCDX"
11 changes: 11 additions & 0 deletions config/language_server_node_json.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# TODO License.

# Configuration for the JSON LSP server component
---
version: 0.0.+
repository_root: "https://lsp-component-json.cfapps.eu10.hana.ondemand.com/"
env:
workdir: language_server_node_json/server
exec: language_server_node_json/launcher.sh
ipc:
protocol: "stream"
11 changes: 11 additions & 0 deletions config/language_server_node_xml.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# TODO License.

# Configuration for the JAVA LSP server component
---
version: 0.0.+
repository_root: "https://lsp-component-xml.cfapps.sap.hana.ondemand.com/"
env:
workdir: language_server_node_xml/server/
exec: language_server_node_xml/launcher.sh
ipc:
protocol: "stream"
86 changes: 86 additions & 0 deletions lib/java_buildpack/framework/language_server_node_json.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Encoding: utf-8
# TODO License.

require 'java_buildpack/component/versioned_dependency_component'
require 'java_buildpack/framework'
require 'fileutils'
require 'java_buildpack/util/qualify_path'
require 'java_buildpack/logging/logger_factory'

module JavaBuildpack
module Framework

# Installs JSON based LSP server component.
class LanguageServerNodeJSON < JavaBuildpack::Component::VersionedDependencyComponent

# Creates an instance
#
# @param [Hash] context a collection of utilities used the component
def initialize(context)
super(context)
@logger = JavaBuildpack::Logging::LoggerFactory.instance.get_logger LanguageServerNodeJSON
end


# (see JavaBuildpack::Component::BaseComponent#compile)
def compile
@logger.debug { "Compile JSON" }
# Install node js
FileUtils.mkdir_p @droplet.root + "nodejs"
nodedir = @droplet.sandbox + "nodejs"
comp_version = @version
comp_uri = @uri
@version="8.0.0"
@uri="https://buildpacks.cloudfoundry.org/dependencies/node/node-8.0.0-linux-x64-ade5a8e5.tgz"
download_tar( target_directory=nodedir )
@version = comp_version
@uri = comp_uri
download_zip strip_top_level = false
@droplet.copy_resources

end

# (see JavaBuildpack::Component::BaseComponent#release)
def release

@logger.debug { "Release JSON" }
environment_variables = @droplet.environment_variables
myWorkdir = @configuration["env"]["workdir"]
environment_variables.add_environment_variable(ENV_PREFIX + "workdir", myWorkdir)
myExec = @configuration["env"]["exec"]
environment_variables.add_environment_variable(ENV_PREFIX + "exec", myExec)

myIpc = @configuration["env"]["ipc"]
@logger.debug { "JSON Env vars IPC:#{myIpc}" }
myIpc.each do |key, value|
environment_variables.add_environment_variable(ENV_PREFIX + key, value)
end

environment_variables.add_environment_variable 'PATH', "/home/vcap/app/.java-buildpack/#{@droplet.component_id}/nodejs/bin:$PATH"
end

protected

# (see JavaBuildpack::Component::VersionedDependencyComponent#supports?)
def supports?
@application.environment.key?(LSPSERVERS) && @application.environment[LSPSERVERS].split(',').include?("json")
end

private

LSPSERVERS = 'lspservers'.freeze

private_constant :LSPSERVERS

BINEXEC = 'exec'.freeze

private_constant :BINEXEC

ENV_PREFIX = 'LSPJSON_'.freeze

private_constant :ENV_PREFIX

end

end
end
86 changes: 86 additions & 0 deletions lib/java_buildpack/framework/language_server_node_xml.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Encoding: utf-8
# TODO License.

require 'java_buildpack/component/versioned_dependency_component'
require 'java_buildpack/framework'
require 'fileutils'
require 'java_buildpack/util/qualify_path'
require 'java_buildpack/logging/logger_factory'

module JavaBuildpack
module Framework

# Installs XML based LSP server component.
class LanguageServerNodeXML < JavaBuildpack::Component::VersionedDependencyComponent

# Creates an instance
#
# @param [Hash] context a collection of utilities used the component
def initialize(context)
super(context)
@logger = JavaBuildpack::Logging::LoggerFactory.instance.get_logger LanguageServerNodeXML
end


# (see JavaBuildpack::Component::BaseComponent#compile)
def compile
@logger.debug { "Compile XML" }
# Install node js
FileUtils.mkdir_p @droplet.root + "nodejs"
nodedir = @droplet.sandbox + "nodejs"
comp_version = @version
comp_uri = @uri
@version="8.0.0"
@uri="https://buildpacks.cloudfoundry.org/dependencies/node/node-8.0.0-linux-x64-ade5a8e5.tgz"
download_tar( target_directory=nodedir )
@version = comp_version
@uri = comp_uri
download_zip strip_top_level = false
@droplet.copy_resources

end

# (see JavaBuildpack::Component::BaseComponent#release)
def release

@logger.debug { "Release XML" }
environment_variables = @droplet.environment_variables
myWorkdir = @configuration["env"]["workdir"]
environment_variables.add_environment_variable(ENV_PREFIX + "workdir", myWorkdir)
myExec = @configuration["env"]["exec"]
environment_variables.add_environment_variable(ENV_PREFIX + "exec", myExec)

myIpc = @configuration["env"]["ipc"]
@logger.debug { "XML Env vars IPC:#{myIpc}" }
myIpc.each do |key, value|
environment_variables.add_environment_variable(ENV_PREFIX + key, value)
end

environment_variables.add_environment_variable 'PATH', "/home/vcap/app/.java-buildpack/#{@droplet.component_id}/nodejs/bin:$PATH"
end

protected

# (see JavaBuildpack::Component::VersionedDependencyComponent#supports?)
def supports?
@application.environment.key?(LSPSERVERS) && @application.environment[LSPSERVERS].split(',').include?("xml")
end

private

LSPSERVERS = 'lspservers'.freeze

private_constant :LSPSERVERS

BINEXEC = 'exec'.freeze

private_constant :BINEXEC

ENV_PREFIX = 'LSPXML_'.freeze

private_constant :ENV_PREFIX

end

end
end
3 changes: 3 additions & 0 deletions resources/language_server_node_json/launcher.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

exec ../nodejs/bin/node ./out/jsonServerMain.js --stdio
3 changes: 3 additions & 0 deletions resources/language_server_node_xml/launcher.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

exec ../nodejs/bin/node ./out/xmlServerMain.js --stdio

0 comments on commit fe8c2c6

Please sign in to comment.