Class: Jars::MavenExec

Inherits:
Object
  • Object
show all
Defined in:
lib/jars/maven_exec.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(spec = nil) ⇒ MavenExec

Returns a new instance of MavenExec.



23
24
25
26
27
28
29
30
# File 'lib/jars/maven_exec.rb', line 23

def initialize(spec = nil)
  @options = {}
  setup(spec)
rescue StandardError, LoadError => e
  # If spec load fails, skip looking for jar-dependencies
  warn "jar-dependencies: #{e}"
  warn e.backtrace.join("\n") if Jars.verbose?
end

Instance Attribute Details

#basedirObject (readonly)

Returns the value of attribute basedir.



21
22
23
# File 'lib/jars/maven_exec.rb', line 21

def basedir
  @basedir
end

#specObject (readonly)

Returns the value of attribute spec.



21
22
23
# File 'lib/jars/maven_exec.rb', line 21

def spec
  @spec
end

#specfileObject (readonly)

Returns the value of attribute specfile.



21
22
23
# File 'lib/jars/maven_exec.rb', line 21

def specfile
  @specfile
end

Instance Method Details

#resolve_dependencies_list(file) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/jars/maven_exec.rb', line 67

def resolve_dependencies_list(file)
  factory = MavenFactory.new(@options)
  maven = factory.maven_new(File.expand_path('gemspec_pom.rb', __dir__))

  is_local_file = File.expand_path(File.dirname(@specfile)) == File.expand_path(Dir.pwd)
  maven.attach_jars(@spec, all_dependencies: is_local_file)

  maven['jars.specfile'] = @specfile.to_s
  maven['outputAbsoluteArtifactFilename'] = 'true'
  maven['includeTypes'] = 'jar'
  maven['outputScope'] = 'true'
  maven['useRepositoryLayout'] = 'true'
  maven['outputDirectory'] = Jars.home.to_s
  maven['outputFile'] = file.to_s

  maven.exec('dependency:copy-dependencies', 'dependency:list')
end

#ruby_maven_install_options=(options) ⇒ Object



63
64
65
# File 'lib/jars/maven_exec.rb', line 63

def ruby_maven_install_options=(options)
  @options = options
end

#setup(spec = nil, allow_no_file: false) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/jars/maven_exec.rb', line 32

def setup(spec = nil, allow_no_file: false)
  spec ||= find_spec(allow_no_file)

  case spec
  when String
    @specfile = File.expand_path(spec)
    @basedir = File.dirname(@specfile)
    Dir.chdir(@basedir) do
      spec = eval(File.read(@specfile), TOPLEVEL_BINDING, @specfile) # rubocop:disable Security/Eval
    end
  when Gem::Specification
    if File.exist?(spec.loaded_from)
      @basedir = spec.gem_dir
      @specfile = spec.loaded_from
    else
      # this happens with bundle and local gems
      # there the spec_file is "not installed" but inside
      # the gem_dir directory
      Dir.chdir(spec.gem_dir) do
        setup(nil, allow_no_file: true)
      end
    end
  when nil
    # ignore
  else
    Jars.debug('spec must be either String or Gem::Specification. ' \
               'File an issue on github if you need it.')
  end
  @spec = spec
end