Skip to content

Commit 8571726

Browse files
committed
setup extension inside maven dist
1 parent df949a4 commit 8571726

File tree

6 files changed

+36
-40
lines changed

6 files changed

+36
-40
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ pom*xml
33
pom*xml.bkp
44
*.gem
55
*.lock
6+
lib/extensions/

.mvn/extensions.xml

Lines changed: 0 additions & 13 deletions
This file was deleted.

Mavenfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@ gemspec
44

55
properties 'push.skip': true, 'jruby.version': '9.3.1.0'
66

7+
load File.join( basedir,'lib/maven/ruby/version.rb')
8+
9+
jar "io.takari.polyglot:polyglot-ruby:#{Maven::Ruby::POLYGLOT_VERSION}", scope: :provided
10+
11+
plugin :dependency do
12+
13+
execute_goal(:"copy-dependencies",
14+
includeScope: :provided,
15+
outputDirectory: '${project.build.directory}/../lib/extensions')
16+
17+
end
18+
719
profile :id => :release do
820
properties 'maven.test.skip' => true, 'invoker.skip' => true
921
properties 'push.skip' => false

lib/maven/ruby/version.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module Maven
22
module Ruby
3-
VERSION = '3.3.12'.freeze
3+
VERSION = '3.9.14'.freeze
4+
POLYGLOT_VERSION = "0.7.2-SNAPSHOT".freeze
45
end
56
end

lib/ruby_maven.rb

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,19 @@
2020
#
2121
require 'maven'
2222
require 'maven/ruby/maven'
23+
require 'maven/ruby/version'
24+
require 'jruby-jars'
2325

2426
module RubyMaven
25-
POLYGLOT_VERSION = "0.1.15"
2627

2728
def self.exec( *args )
2829
if File.exist?('settings.xml') and not args.member?('-s') and not args.member?('--settings')
2930
args << '-s'
3031
args << 'settings.xml'
3132
end
3233
if args.member?('-version') or args.member?('--version') or args.member?('-v')
33-
warn "Polyglot Maven Extension #{version}"
34+
warn "here"
35+
warn "Polyglot Maven Extension #{Maven::Ruby::POLYGLOT_VERSION} via ruby-maven #{Maven::Ruby::VERSION}"
3436
launch( '--version' )
3537
elsif defined? Bundler
3638
# it can be switching from ruby to jruby with invoking maven
@@ -58,40 +60,33 @@ def self.version
5860
xml = File.read( File.join( dir, '.mvn/extensions.xml' ) )
5961
xml.sub( /.*<version>/m, '' ).sub(/<\/version>.*/m, '' )
6062
rescue Errno::ENOENT => e
61-
nil
63+
Maven::Ruby::POLYGLOT_VERSION
6264
end
63-
POLYGLOT_VERSION.replace(polyglot_version) if polyglot_version
64-
POLYGLOT_VERSION
6565
end
6666

6767
def self.launch( *args )
6868
old_maven_home = ENV['M2_HOME']
6969
ENV['M2_HOME'] = Maven.home
70-
71-
extensions = File.join( '.mvn/extensions.xml' )
72-
if has_extensions = File.exist?( extensions )
73-
# tests need copy instead of move
74-
FileUtils.cp( extensions, extensions + ".orig" )
75-
else
76-
FileUtils.mkdir_p( '.mvn' )
70+
ext_dir = File.join(Maven.lib, 'ext')
71+
FileUtils.mkdir_p(ext_dir)
72+
local_dir = File.join(__dir__, 'extensions')
73+
Dir.new(local_dir).select do |file|
74+
file =~ /.*\.jar$/
75+
end.each do |jar|
76+
source = File.join(local_dir, jar)
77+
if jar == "polyglot-ruby-#{Maven::Ruby::POLYGLOT_VERSION}.jar"
78+
# ruby maven defines the polyglot version and this jar sets up its classpath
79+
# i.e. on upgrade or downgrade the right version will be picked
80+
FileUtils.cp(source, File.join(ext_dir, "polyglot-ruby.jar"))
81+
elsif not File.exists?(File.join(ext_dir, jar))
82+
# jar files are immutable as they carry the version
83+
FileUtils.cp(source, ext_dir)
84+
end
7785
end
78-
FileUtils.cp( File.join( dir, extensions ), extensions ) rescue nil
79-
80-
# setup version
81-
self.version
8286

8387
Maven.exec( *args )
8488

8589
ensure
8690
ENV['M2_HOME'] = old_maven_home
87-
88-
FileUtils.rm_f( extensions )
89-
if has_extensions
90-
FileUtils.move( extensions + '.orig', extensions )
91-
else
92-
dir = File.dirname( extensions )
93-
# delete empty .mvn directory
94-
FileUtils.rm_rf( dir ) if Dir[File.join(dir, '*')].size == 0
95-
end
9691
end
9792
end

ruby-maven.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
2121

2222
s.rdoc_options = ["--main", "README.md"]
2323

24-
s.add_dependency 'ruby-maven-libs', "~> 3.3.9"
24+
s.add_dependency 'ruby-maven-libs', "~> 3.9.6"
2525
s.add_development_dependency 'minitest', '~> 5.3'
2626
s.add_development_dependency 'rake', '~> 12.3'
2727
end

0 commit comments

Comments
 (0)