Skip to content

Commit

Permalink
Merge pull request #11 from jruby/using-polyglot-extension
Browse files Browse the repository at this point in the history
Using polyglot extension
  • Loading branch information
headius authored Oct 29, 2024
2 parents df949a4 + a68e7e4 commit 72e6b8b
Show file tree
Hide file tree
Showing 13 changed files with 589 additions and 33 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ pom*xml
pom*xml.bkp
*.gem
*.lock
lib/extensions/
2 changes: 1 addition & 1 deletion .mvn/extensions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
<extension>
<groupId>io.takari.polyglot</groupId>
<artifactId>polyglot-ruby</artifactId>
<version>0.4.8</version>
<version>0.7.1</version>
</extension>
</extensions>
Binary file added .mvn/wrapper/maven-wrapper.jar
Binary file not shown.
18 changes: 18 additions & 0 deletions .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar
19 changes: 18 additions & 1 deletion Mavenfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
# -*- mode:ruby -*-

gemspec

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

load File.join( basedir,'lib/maven/ruby/version.rb')

jar "io.takari.polyglot:polyglot-ruby:#{Maven::Ruby::POLYGLOT_VERSION}", scope: :provided

execute 'cleanup extensions', 'initialize' do |ctx|
FileUtils.rm_rf "#{ctx.project.build.directory}/../lib/extensions"
end

plugin :dependency do

execute_goal(:"copy-dependencies",
phase: 'prepare-package',
includeScope: :provided,
includeGroupIds: 'io.takari.polyglot',
outputDirectory: '${project.build.directory}/../lib/extensions')

end

profile :id => :release do
properties 'maven.test.skip' => true, 'invoker.skip' => true
properties 'push.skip' => false
Expand Down
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,19 @@ other is closer to maven in its naming.

it is licensed under (EPL-1.0)[https://www.eclipse.org/legal/epl-v10.html]

## contributing #
## building ##

Prepare and pack the gem under ./pkg
```
./mvnw install
```

Push the gem to rubygems.org
```
./mvnw deploy -Prelease
```

## contributing ##

1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
Expand Down
3 changes: 2 additions & 1 deletion lib/maven/ruby/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module Maven
module Ruby
VERSION = '3.3.12'.freeze
VERSION = '3.9.0'.freeze
POLYGLOT_VERSION = "0.7.1".freeze
end
end
Empty file added lib/polyglot_jars/.keep
Empty file.
46 changes: 21 additions & 25 deletions lib/ruby_maven.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@
#
require 'maven'
require 'maven/ruby/maven'
require 'maven/ruby/version'

module RubyMaven
POLYGLOT_VERSION = "0.1.15"

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')
warn "Polyglot Maven Extension #{version}"
launch( '--version' )
elsif defined? Bundler
# it can be switching from ruby to jruby with invoking maven
Expand Down Expand Up @@ -58,40 +57,37 @@ def self.version
xml = File.read( File.join( dir, '.mvn/extensions.xml' ) )
xml.sub( /.*<version>/m, '' ).sub(/<\/version>.*/m, '' )
rescue Errno::ENOENT => e
nil
Maven::Ruby::POLYGLOT_VERSION
end
POLYGLOT_VERSION.replace(polyglot_version) if polyglot_version
POLYGLOT_VERSION
end

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

extensions = File.join( '.mvn/extensions.xml' )
if has_extensions = File.exist?( extensions )
# tests need copy instead of move
FileUtils.cp( extensions, extensions + ".orig" )
else
FileUtils.mkdir_p( '.mvn' )
ext_dir = File.join(Maven.lib, 'ext')
FileUtils.mkdir_p(ext_dir)
local_dir = File.join(__dir__, 'polyglot_jars')
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.exists?(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
FileUtils.cp( File.join( dir, extensions ), extensions ) rescue nil

# setup version
self.version

Maven.exec( *args )

ensure
ENV['M2_HOME'] = old_maven_home

FileUtils.rm_f( extensions )
if has_extensions
FileUtils.move( extensions + '.orig', extensions )
else
dir = File.dirname( extensions )
# delete empty .mvn directory
FileUtils.rm_rf( dir ) if Dir[File.join(dir, '*')].size == 0
end
end
end
Loading

0 comments on commit 72e6b8b

Please sign in to comment.