Module: RubyMaven

Defined in:
lib/ruby_maven.rb

Class Method Summary collapse

Class Method Details

.dirObject



51
52
53
# File 'lib/ruby_maven.rb', line 51

def self.dir
  @dir ||= File.expand_path( '../../', __FILE__ )
end

.exec(*args) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/ruby_maven.rb', line 27

def self.exec( *args )
  if File.exist?('settings.xml') and not args.member?('-s') and not args.member?('--settings')
    args << '-s'
    args << 'settings.xml'
  end
  if args.member?('-version') or args.member?('--version') or args.member?('-v')
    launch( '--version' )
  elsif defined? Bundler
    # it can be switching from ruby to jruby with invoking maven
    # just keep it clean
    if Bundler.respond_to?(:with_unbundled_env)
      Bundler.with_unbundled_env do
        launch( *args )
      end
    else
      Bundler.with_clean_env do
        launch( *args )
      end
    end
  else
    launch( *args )
  end
end

.launch(*args) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/ruby_maven.rb', line 64

def self.launch( *args )
  if args.member?('--version') or args.member?('--show-version')
    warn "Polyglot Maven Extension #{Maven::Ruby::POLYGLOT_VERSION} via ruby-maven #{Maven::Ruby::VERSION}"
  end
  old_maven_home = ENV['M2_HOME']
  ENV['M2_HOME'] = Maven.home
  ext_dir = File.join(Maven.lib, 'ext')
  FileUtils.mkdir_p(ext_dir)
  local_dir = File.join(__dir__, 'extensions')
  Dir.new(local_dir).select do |file|
    file =~ /.*\.jar$/
  end.each do |jar|
    source = File.join(local_dir, jar)
    if jar =~ /polyglot-.*-#{Maven::Ruby::POLYGLOT_VERSION}.jar/
      # ruby maven defines the polyglot version and this jar sets up its classpath
      # i.e. on upgrade or downgrade the right version will be picked
      FileUtils.cp(source, File.join(ext_dir, jar.sub(/-[0-9.]*(-SNAPSHOT)?.jar$/, '.jar')))
    elsif not File.exist?(File.join(ext_dir, jar)) and not jar =~ /jruby-(core|stdlib).*/
      # jar files are immutable as they carry the version
      warn jar
      FileUtils.cp(source, File.join(ext_dir, jar.sub(/-9.4.5.0/, '')))
    end
  end

  Maven.exec( *args )

ensure
  ENV['M2_HOME'] = old_maven_home
end

.versionObject



55
56
57
58
59
60
61
62
# File 'lib/ruby_maven.rb', line 55

def self.version
  polyglot_version = begin
                       xml = File.read( File.join( dir, '.mvn/extensions.xml' ) )
                       xml.sub( /.*<version>/m, '' ).sub(/<\/version>.*/m, '' )
                     rescue Errno::ENOENT => e
                       Maven::Ruby::POLYGLOT_VERSION
                     end
end