Sha256: 4c3e1afbf0dda74f832dc19840e98dd3d0a4b90d1fc1baf3bc9512e2931ed789

Contents?: true

Size: 1.63 KB

Versions: 3

Compression:

Stored size: 1.63 KB

Contents

#--
# Copyright (c) 2010-2012 Engine Yard, Inc.
# Copyright (c) 2007-2009 Sun Microsystems, Inc.
# This source code is available under the MIT license.
# See the file LICENSE.txt for details.
#++

require 'stringio'
require 'ostruct'

module Warbler
  module Traits
    # The Jar trait sets up the archive layout for an executable jar
    # project, and adds the JRuby jar files and a JarMain class to the
    # archive.
    class Jar
      include Trait

      def self.detect?
        !War.detect?
      end

      def before_configure
        config.gem_path      = '/'
        config.pathmaps      = default_pathmaps
        config.java_libs     = default_jar_files
        config.manifest_file = 'MANIFEST.MF' if File.exist?('MANIFEST.MF')
        config.init_contents << "#{config.warbler_templates}/jar.erb"
      end

      def after_configure
        config.init_contents << StringIO.new("require 'rubygems'\n")
      end

      def update_archive(jar)
        jar.files['META-INF/MANIFEST.MF'] = StringIO.new(Warbler::Jar::DEFAULT_MANIFEST.chomp + "Main-Class: JarMain\n") unless config.manifest_file
        jar.files['JarMain.class'] = jar.entry_in_jar("#{WARBLER_HOME}/lib/warbler_jar.jar", "JarMain.class")
      end

      def default_pathmaps
        p = OpenStruct.new
        p.java_libs    = ["META-INF/lib/%f"]
        p.java_classes = ["%p"]
        p.application  = ["#{config.jar_name}/%p"]
        p.gemspecs     = ["specifications/%f"]
        p.gems         = ["gems/%p"]
        p
      end

      def default_jar_files
        require 'jruby-jars'
        FileList[JRubyJars.core_jar_path, JRubyJars.stdlib_jar_path]
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
warbler-1.3.6 lib/warbler/traits/jar.rb
warbler-1.3.5 lib/warbler/traits/jar.rb
warbler-1.3.4 lib/warbler/traits/jar.rb