Class: Scriptlandia::Launcher

Inherits:
Object
  • Object
show all
Defined in:
lib/scriptlandia.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLauncher

Returns a new instance of Launcher.



24
25
26
27
# File 'lib/scriptlandia.rb', line 24

def initialize
  @settings = YAML::load File.open(File.dirname(__FILE__) + '/settings.yaml')
  @ext_mapping = YAML::load File.open(File.dirname(__FILE__) + '/languages/extension_mapping.yaml')
end

Class Method Details

.extension(name) ⇒ Object



29
30
31
# File 'lib/scriptlandia.rb', line 29

def self.extension name
  name[name.rindex('.')+1, name.length]
end

.language_folder(ext_mapping, name) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/scriptlandia.rb', line 33

def self.language_folder ext_mapping, name
  language_folder = nil

  ext = extension(name)

  ext_mapping.each do |folder, extensions|
    if extensions.include?(ext) or extensions.include?(name)
      language_folder = folder
      break
    end
  end

  language_folder
end

Instance Method Details

#launchObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/scriptlandia.rb', line 48

def launch
  script_name = ARGV[0]

  language = Launcher.language_folder(@ext_mapping, script_name)
  
  if(language == nil) 
    puts "Unsupported language/extension: " + Launcher.extension(script_name)
  else
    lang_config = YAML::load File.open(File.dirname(__FILE__) + '/languages/' + 
                         language + '/config.yaml')

    ENV['JAVA_HOME'] = @settings['java_home']
    local_repository = @settings['repositories']['local']

    vars = {'repositories.local' => local_repository }

    jvm_args = lang_config['jvmargs']
    jvm_args = [] if jvm_args == nil

    jvm_args = jvm_args.collect { |arg| arg.interpolate(vars) }

    classpath = lang_config['classpath']
    classpath = [] if classpath == nil

    lang_config['artifacts'].each do |name, artifact|
      group, id, type,version = artifact.split(':')
      
      file_name = local_repository + '/' + 
                  group.gsub('.', '/') + '/' + 
                  id.gsub('.', '/') + '/' + 
                  version + '/' + 
                  id.gsub('.', '/') + '-' + version + '.' + type

      unless File.exist? file_name
        puts 'File ' + file_name + ' does not exists.'
      else
        classpath << file_name
      end
    end

    pause = false

    if(ARGV.include? '--wait')
      ARGV.delete '--wait'
      pause = true
    end

    Rjb::load(classpath.join(File::PATH_SEPARATOR), jvmargs = jvm_args)       

    ARGV[0, 0] = lang_config['command_line'] if lang_config['command_line']

    Rjb::import(lang_config['start_class']).main(ARGV)
    
    STDIN.gets if pause
  end
end