Class: TorqueBox::CLI::Archive

Inherits:
Object
  • Object
show all
Defined in:
core/lib/torquebox/cli/archive.rb

Instance Method Summary (collapse)

Constructor Details

- (Archive) initialize(argv)

Returns a new instance of Archive



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'core/lib/torquebox/cli/archive.rb', line 21

def initialize(argv)
  @argv = argv
  @main = ENV['TORQUEBOX_MAIN']
  @rackup = ENV['TORQUEBOX_RACKUP']

  if @main
    @parser = OptionParser.new
    @parser.on('-h', '--help', 'Show this message') do |arg|
      puts @parser
      exit 1
    end
  else
    @cli = TorqueBox::CLI.new(['run'] + @argv)
    @parser = @cli.parser
  end

  @parser.separator ""
  @parser.separator "Archive options:"
  @parser.on('-S SCRIPT',
             'Run a script from inside the archive (rake tasks, etc)') do |arg|
    # Treat any unprocessed args as belonging to -S so that things like
    # "java -jar foo.jar -S torquebox help" work without quotes
    arg = ([arg] + @argv).join(' ')
    app_jar = java.lang.System.get_property("torquebox.app_jar")
    lib_dir = RbConfig::CONFIG['libdir']
    load_path = $LOAD_PATH.map { |entry| "-I#{entry}" }.join(' ')
    jars = Dir.glob("../jars/*.jar").map { |j| "-r#{j}" }.join(' ')
    # PWD is $tmpdir/app and jruby.jar is $tmpdir/jars/jruby.jar
    Kernel.exec("java -Dtorquebox.app_jar=#{app_jar} \
                -Djava.io.tmpdir=#{java.lang.System.get_property('java.io.tmpdir')} \
                -Djruby.lib=#{lib_dir} \
                -jar ../jars/jruby.jar #{load_path} -r#{app_jar} \
                #{jars} -rbundler/setup -rtorquebox/cli/archive_cleaner \
                -S #{arg}")
  end
end

Instance Method Details

- (Object) run



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'core/lib/torquebox/cli/archive.rb', line 58

def run
  @parser.parse!(@argv)

  if @main
    require @main
  else
    require 'torquebox-web'
    if TorqueBox.in_wildfly?
      TorqueBox::Web.run(:rackup => @rackup)
    else
      @cli.run
    end
  end
rescue OptionParser::InvalidOption => e
  puts e.message
  puts
  puts @parser
  exit 1
end