Module: Glimmer::RakeTask::Package

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

Constant Summary collapse

JDK_VERSION =
' 18'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.jpackage_extra_argsObject

Returns the value of attribute jpackage_extra_args.



31
32
33
# File 'lib/glimmer/rake_task/package.rb', line 31

def jpackage_extra_args
  @jpackage_extra_args
end

Class Method Details

.cleanObject



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

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

.configObject



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

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



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

def gem
  system 'rake build'
end

.gemspecObject



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

def gemspec
  system 'rake gemspec:generate'
end

.jarObject



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

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



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

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



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 92

def native(native_type=nil, native_extra_args)
  puts "Generating native executable with jpackage..."
  java_version = `jruby -v`
  if java_version.include?(JDK_VERSION)
    puts "Java Version #{JDK_VERSION} Detected!"
  else
    puts "WARNING! Glimmer Packaging Pre-Requisite Java Version #{JDK_VERSION} 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 = "icons/#{OS.mac? ? 'macosx' : (OS.linux? ? 'linux' : 'windows')}/#{human_name}.#{OS.mac? ? 'icns' : (OS.linux? ? 'png' : 'ico')}"
  native_type = 'app-image' if native_type.to_s.strip.empty?
  if (`jpackage`.to_s.include?('Usage: jpackage') rescue nil)
    FileUtils.rm_rf("packages/bundles")
    FileUtils.mkdir_p('packages/bundles')
    command = "jpackage"
    command += " --type #{native_type}"
    command += " --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? && native_type != 'app-image'
    command += " --linux-menu-group '#{human_name}' " if OS.linux? && native_type != 'app-image'
    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 && native_type != 'app-image'
    command += " --copyright \"#{copyright}\" " if copyright
  else
    puts "jpackage does not exist in your Java installation. Please ensure jpackage is available in PATH environment variable."
    return
  end
  Rake.application.load_rakefile # make sure to load potential jpackage_extra_args config in app Rakefile
  command += " #{jpackage_extra_args} " if jpackage_extra_args
  command += " #{ENV['JPACKAGE_EXTRA_ARGS']} " if ENV['JPACKAGE_EXTRA_ARGS']
  command += " #{native_extra_args} " if native_extra_args
  puts command
  system command
end