Module: Glimmer::RakeTask::Package

Defined in:
lib/glimmer/rake_task/package.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.javapackager_extra_argsObject Also known as: jpackage_extra_args

Returns the value of attribute javapackager_extra_args.



29
30
31
# File 'lib/glimmer/rake_task/package.rb', line 29

def javapackager_extra_args
  @javapackager_extra_args
end

Class Method Details

.cleanObject



32
33
34
35
36
# File 'lib/glimmer/rake_task/package.rb', line 32

def clean
  require 'fileutils'
  FileUtils.rm_rf('dist')
  FileUtils.rm_rf('packages')
end

.configObject



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
# File 'lib/glimmer/rake_task/package.rb', line 54

def config
  project_name = File.basename(File.expand_path('.'))
  if !File.exists?('config/warble.rb')
    puts 'Generating JAR configuration (config/warble.rb) to use with Warbler...'
    FileUtils.mkdir_p('config')
    if OS.windows?
      system "jruby -S gem install warbler -v2.0.5 --no-document" unless warbler_exists?
    else
      system "bash -c '#{RVM_FUNCTION}\n cd .\n jruby -S gem install warbler -v2.0.5 --no-document\n'" unless warbler_exists?
    end
    if system('warble config')
      new_config = File.read('config/warble.rb').split("\n").inject('') do |output, line|
        if line.include?('config.dirs =')
          line = line.sub('# ', '').sub(/=[^=\n]+$/, '= %w(app bin config db docs fonts icons images lib package script sounds vendor videos)')
        end
        if line.include?('config.includes =')
          line = line.sub('# ', '').sub(/=[^=\n]+$/, "= FileList['LICENSE.txt', 'VERSION']")
        end
        if line.include?('config.autodeploy_dir =')
          line = line.sub('# ', '')
        end
        output + "\n" + line
      end
      File.write('config/warble.rb', new_config)
    else
      puts 'Warbler executable "warble" is missing!'
    end
  end
end

.gemObject



42
43
44
# File 'lib/glimmer/rake_task/package.rb', line 42

def gem
  system 'rake build'
end

.gemspecObject



38
39
40
# File 'lib/glimmer/rake_task/package.rb', line 38

def gemspec
  system 'rake gemspec:generate'
end

.jarObject



84
85
86
87
88
89
# File 'lib/glimmer/rake_task/package.rb', line 84

def jar
  FileUtils.mkdir_p('dist')
  puts "Generating JAR with Warbler..."
  system "jruby -S gem install warbler -v2.0.5 --no-document" unless warbler_exists?
  system('warble')
end

.lock_jarsObject



46
47
48
49
50
51
52
# File 'lib/glimmer/rake_task/package.rb', line 46

def lock_jars
  puts 'Locking gem jar-dependencies by downloading and storing in vendor/jars...'
  FileUtils.mkdir_p('vendor/jars')
  command = "lock_jars --vendor-dir vendor/jars"
  puts command
  system command
end

.native(native_type = nil, native_extra_args) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/glimmer/rake_task/package.rb', line 91

def native(native_type=nil, native_extra_args)
  puts "Generating native executable with javapackager/jpackage..."
  java_version = `jruby -v`
  if java_version.include?('1.8.0_241')
    puts "Java Version 1.8.0_241 Detected!"
  else
    puts "WARNING! Glimmer Packaging Pre-Requisite Java Version 1.8.0_241 Is Not Found!"
  end
  require 'facets/string/titlecase'
  require 'facets/string/underscore'
  require 'facets/string/camelcase'
  project_name = File.basename(File.expand_path('.'))
  version_file = File.expand_path('./VERSION')
  version = (File.read(version_file).strip if File.exists?(version_file) && File.file?(version_file)) rescue nil
  license_file = File.expand_path('./LICENSE.txt')
  license = (File.read(license_file).strip if File.exists?(license_file) && File.file?(license_file)) rescue nil
  copyright = license.split("\n").first
  human_name = project_name.underscore.titlecase
  icon = "package/#{OS.mac? ? 'macosx' : 'windows'}/#{human_name}.#{OS.mac? ? 'icns' : 'ico'}"
  if (`javapackager`.to_s.include?('Usage: javapackager') rescue nil)
    command = "javapackager -deploy -native #{native_type} -outdir packages -outfile \"#{project_name}\" -srcfiles \"dist/#{project_name}.jar\" -appclass JarMain -name \"#{human_name}\" -title \"#{human_name}\" -Bmac.CFBundleName=\"#{human_name}\" -Bmac.CFBundleIdentifier=\"org.#{project_name}.application.#{project_name.camelcase(:upper)}\" -Bmac.category=\"public.app-category.business\" -BinstalldirChooser=true -Bvendor=\"#{human_name}\" -Bwin.menuGroup=\"#{human_name}\" "
    command += " -BsystemWide=false " if OS.windows?
    command += " -BjvmOptions=-XstartOnFirstThread " if OS.mac?
    command += " -BappVersion=#{version} -Bmac.CFBundleVersion=#{version} " if version
    command += " -srcfiles LICENSE.txt -BlicenseFile=LICENSE.txt " if license
    command += " -Bcopyright=\"#{copyright}\" " if copyright
  elsif (`jpackage`.to_s.include?('Usage: jpackage') rescue nil)
    command = "jpackage --type #{native_type} --dest 'packages/bundles' --input 'dist' --main-class JarMain --main-jar '#{project_name}.jar' --name '#{human_name}' --vendor '#{human_name}' --icon '#{icon}' "
    command += " --win-per-user-install --win-dir-chooser --win-menu --win-menu-group '#{human_name}' " if OS.windows?
    command += " --java-options '-XstartOnFirstThread' --mac-package-name '#{human_name}' --mac-package-identifier 'org.#{project_name}.application.#{project_name}' " if OS.mac?
    command += " --app-version \"#{version}\" " if version
    command += " --license-file LICENSE.txt " if license
    command += " --copyright \"#{copyright}\" " if copyright
  else
    puts "Neither javapackager nor jpackage exist in your Java installation. Please ensure javapackager or jpackage is available in PATH environment variable."
    return
  end
  Rake.application.load_rakefile # make sure to load potential javapackager_extra_args config in app Rakefile
  command += " #{javapackager_extra_args} " if javapackager_extra_args
  command += " #{ENV['JAVAPACKAGER_EXTRA_ARGS']} " if ENV['JAVAPACKAGER_EXTRA_ARGS']
  command += " #{native_extra_args} " if native_extra_args
  puts command
  system command
end