Sha256: fb8dec88bfa786aaf5d86a9b1058868f1d6c36a1b1f52e4dc87799cd6f58d8a0

Contents?: true

Size: 2 KB

Versions: 1

Compression:

Stored size: 2 KB

Contents

# encoding: UTF-8

module Expert
  autoload :ClasspathFile,    'expert/classpath_file'
  autoload :Cli,              'expert/cli'
  autoload :Environment,      'expert/environment'
  autoload :Jarfile,          'expert/jarfile'
  autoload :JarDependency,    'expert/jar_dependency'
  autoload :JarfileParser,    'expert/jarfile_parser'
  autoload :JarfileTokenizer, 'expert/jarfile_tokenizer'
  autoload :Maven,            'expert/maven'
  autoload :PomFile,          'expert/pom_file'

  # The Jarfile declares dependencies. The pom/classpath function like a
  # Gemfile.lock or Jarfile.lock.
  DEFAULT_JARFILE_PATH = './Jarfile'
  DEFAULT_POM_PATH = './pom.xml'
  DEFAULT_CLASSPATH_FILE = './classpath.txt'
  MAVEN_VERSION = '3.3.3'

  class << self
    def environment
      @environment ||= begin
        check_bundler_required
        check_jarfile_exists

        Environment.new(load_jarfile, load_pom, load_classpath)
      end
    end

    def jarfile_path
      ENV.fetch('EXPERT_JARFILE', DEFAULT_JARFILE_PATH)
    end

    def pom_path
      ENV.fetch('EXPERT_POM', DEFAULT_POM_PATH)
    end

    def classpath_file_path
      ENV.fetch('EXPERT_CLASSPATH_FILE', DEFAULT_CLASSPATH_FILE)
    end

    protected

    def check_bundler_required
      unless defined?(Bundler)
        raise "Bundler hasn't been required. Please run expert in the context "\
          "of your bundle."
      end
    end

    def check_jarfile_exists
      unless File.exist?(jarfile_path)
        raise "Couldn't find a Jarfile at #{jarfile_path}. A Jarfile is "\
          "required to declare jar dependencies. You can manually specify a "\
          "Jarfile location via the EXPERT_JARFILE environment variable."
      end
    end

    def load_jarfile
      Jarfile.from_path(jarfile_path)
    end

    def load_pom
      if File.exist?(pom_path)
        PomFile.from_path(pom_path)
      end
    end

    def load_classpath
      if File.exist?(classpath_file_path)
        ClasspathFile.from_path(classpath_file_path)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
expert-1.0.0 lib/expert.rb