Permalink
Browse files

Remove redundant code (first pass)

  • Loading branch information...
1 parent 44c01ba commit 80cea367b349694532f7e878e4d39dad0d0a4d93 Maria Shaldibina and Tim Labeeuw committed Feb 20, 2013
Showing with 2 additions and 102 deletions.
  1. +2 −9 bin/run_plugin
  2. +0 −93 lib/vcap/staging/plugin/staging_plugin.rb
View
@@ -4,13 +4,6 @@ require "bundler/setup"
$:.unshift(File.expand_path("../../lib", __FILE__))
require "vcap/staging/plugin/staging_plugin"
+require "vcap/staging/plugin/buildpack/plugin"
-unless ARGV.length == 2
- puts "Usage: run_plugin [plugin name] [plugin config file]"
- exit 1
-end
-
-plugin_name, config_path = ARGV
-
-plugin = StagingPlugin.load_plugin_for(plugin_name).from_file(config_path)
-plugin.stage_application
+BuildpackPlugin.stage_application
@@ -20,35 +20,11 @@ class StagingPlugin
attr_accessor :source_directory, :destination_directory, :environment_json
- def self.staging_root
- File.expand_path('..', __FILE__)
- end
-
def self.platform_config
config_path = ENV['PLATFORM_CONFIG']
YAML.load_file(config_path)
end
- # Transforms lowercased/underscored word into camelcase.
- #
- # EX: camelize('foo_bar') returns 'FooBar'
- #
- def self.camelize(word)
- uc_parts = []
- for part in word.split('_')
- uc_part = part[0].upcase
- uc_part += part[1, part.length - 1] if part.length > 1
- uc_parts << uc_part
- end
- uc_parts.join
- end
-
- def self.load_plugin_for
- plugin_path = File.join(staging_root, 'buildpack', 'plugin.rb')
- require plugin_path
- BuildpackPlugin
- end
-
# Exits the process with a nonzero status if ARGV does not contain valid
# staging args. If you call this in-process in an app server you deserve your fate.
def self.validate_arguments!(*args)
@@ -157,15 +133,6 @@ def start_command
raise NotImplementedError, "subclasses must implement a 'start_command' method that returns a string"
end
- def stop_command
- cmds = []
- cmds << 'APP_PID=$1'
- cmds << 'APP_PPID=`ps -o ppid= -p $APP_PID`'
- cmds << 'kill -9 $APP_PID'
- cmds << 'kill -9 $APP_PPID'
- cmds.join("\n")
- end
-
def application_memory
if environment[:resources] && environment[:resources][:memory]
environment[:resources][:memory]
@@ -208,15 +175,6 @@ def generate_startup_script(env_vars = {})
ERB.new(template).result(binding).lines.reject {|l| l =~ /^\s*$/}.join
end
- def generate_stop_script(env_vars = {})
- template = <<-SCRIPT
-#!/bin/bash
-<%= environment_statements_for(env_vars) %>
-<%= stop_command %>
- SCRIPT
- ERB.new(template).result(binding)
- end
-
# Generates newline-separated exports for the specified environment variables.
# If the value of one of the keys is false or nil, it will be an 'unset' instead of an 'export'
def environment_statements_for(vars)
@@ -240,14 +198,6 @@ def create_app_directories
FileUtils.mkdir_p(tmp_dir)
end
- def create_stop_script()
- path = File.join(script_dir, 'stop')
- File.open(path, 'wb') do |f|
- f.puts stop_script
- end
- FileUtils.chmod(0500, path)
- end
-
def create_startup_script
path = File.join(script_dir, 'startup')
File.open(path, 'wb') do |f|
@@ -269,47 +219,4 @@ def bound_services
def ruby
File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])
end
-
- # Returns a set of environment clauses, only allowing the names specified.
- def minimal_env(*allowed)
- env = ''
- allowed.each do |var|
- next unless ENV.key?(var)
- env << "#{var}=#{ENV[var]} "
- end
- env.strip
- end
-
- def get_ruby_version(exe)
- get_ver = %{-e "print RUBY_VERSION,'p',RUBY_PATCHLEVEL"}
- `env -i PATH=#{ENV['PATH']} #{exe} #{get_ver}`
- end
-
- def insight_agent
- StagingPlugin.platform_config['insight_agent']
- end
-
- def scan_files(base_dir, glob)
- found = []
- base_dir << '/' unless base_dir.end_with?('/')
- Dir[glob].each do |full_path|
- matched = block_given? ? yield(full_path) : true
- if matched
- relative_path = full_path.dup
- relative_path[base_dir] = ''
- found.push(relative_path)
- end
- end
- found
- end
-
- def scan_files_for_regexp(base_dir, glob, pattern)
- scan_files(base_dir, glob) do |path|
- matched = false
- File.open(path, 'rb') do |f|
- matched = true if f.read.match(pattern)
- end
- matched
- end
- end
end

0 comments on commit 80cea36

Please sign in to comment.