Sha256: 0a63fda16cf5cc0c312d10f0ab0d38766e6797f36cebf5e6f807c58943373890

Contents?: true

Size: 1.92 KB

Versions: 9

Compression:

Stored size: 1.92 KB

Contents

# frozen_string_literal: true

require_relative 'native_folder'
require_relative 'native_loader'

require 'pathname'

# This class knows where to find JRubyArt libraries
class Library
  require_relative '../jruby_art'
  require_relative './config'
  attr_reader :name, :path, :dir, :ppath

  def initialize(name)
    @name = name
    @ruby = true
  end

  def locate
    return if (@path = Pathname.new(
      File.join(SKETCH_ROOT, 'library', name, "#{name}.rb")
    )).exist?
    return if (@path = Pathname.new(
      File.join(K9_ROOT, 'library', name, "#{name}.rb")
    )).exist?

    locate_java
  end

  def locate_java
    @dir = Pathname.new(
      File.join(SKETCH_ROOT, 'library', name)
    )
    return @path = dir.join(Pathname.new("#{name}.jar")) if dir.directory?

    locate_installed_java
  end

  def locate_installed_java
    return if dir.directory?

    if Processing::RP_CONFIG.fetch('processing_ide', false)
      prefix = library_path
      @dir = Pathname.new(File.join(prefix, 'libraries', name, 'library'))
      @path = dir.join(Pathname.new("#{name}.jar"))
    else
      @dir = Pathname.new(
        File.join(ENV['HOME'], '.jruby_art', 'libraries', name, 'library')
      )
    end
    @path = dir.join(Pathname.new("#{name}.jar"))
  end

  def library_path
    Processing::RP_CONFIG.fetch('library_path', "#{ENV['HOME']}/.jruby_art")
  end

  def ruby?
    path.extname == '.rb'
  end

  def exist?
    path.exist?
  end

  def load_jars
    Dir.glob("#{dir}/*.jar").sort.each do |jar|
      require jar
    end
    return unless native_binaries?

    add_binaries_to_classpath
  end

  def native_binaries?
    native_folder = NativeFolder.new
    native = native_folder.name
    @ppath = File.join(dir, native)
    File.directory?(ppath) &&
      !Dir.glob(File.join(ppath, native_folder.extension)).empty?
  end

  def add_binaries_to_classpath
    native_loader = NativeLoader.new
    native_loader.add_native_path(ppath)
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
jruby_art-2.6.1 lib/jruby_art/library.rb
jruby_art-2.6.0 lib/jruby_art/library.rb
jruby_art-2.5.1 lib/jruby_art/library.rb
jruby_art-2.5.0 lib/jruby_art/library.rb
jruby_art-2.4.3 lib/jruby_art/library.rb
jruby_art-2.4.2 lib/jruby_art/library.rb
jruby_art-2.4.1 lib/jruby_art/library.rb
jruby_art-2.4.0 lib/jruby_art/library.rb
jruby_art-2.3.0 lib/jruby_art/library.rb