Skip to content
Browse files

added specs and basic test for execution of maven

  • Loading branch information...
1 parent 838591b commit 62def8db75942776edb20b6ef31bc876bcb41699 @mkristian committed
Showing with 90 additions and 13 deletions.
  1. +2 −0 Gemfile
  2. +23 −0 Gemfile.lock
  3. +15 −0 Rakefile
  4. +23 −11 lib/ruby/maven/ruby/maven.rb
  5. +4 −2 ruby-maven.gemspec
  6. +23 −0 spec/maven_spec.rb
View
2 Gemfile
@@ -0,0 +1,2 @@
+source :rubygems
+gemspec
View
23 Gemfile.lock
@@ -0,0 +1,23 @@
+PATH
+ remote: .
+ specs:
+ ruby-maven (3.0.4.1)
+ maven-tools (~> 0.29.1)
+ thor (>= 0.14.6, < 2.0)
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ maven-tools (0.29.3)
+ minitest (3.3.0)
+ rake (0.9.2.2)
+ thor (0.15.4)
+
+PLATFORMS
+ java
+ ruby
+
+DEPENDENCIES
+ minitest (= 3.3.0)
+ rake (= 0.9.2.2)
+ ruby-maven!
View
15 Rakefile
@@ -0,0 +1,15 @@
+# -*- mode: ruby -*-
+
+task :default => [ :spec ]
+
+task :spec do
+ require 'rubygems'
+ require 'bundler/setup'
+ require 'minitest/autorun'
+
+ $LOAD_PATH << "spec"
+
+ Dir['spec/*_spec.rb'].each { |f| require File.expand_path(f).sub(/.rb$/, '') }
+end
+
+# vim: syntax=Ruby
View
34 lib/ruby/maven/ruby/maven.rb
@@ -8,24 +8,32 @@ class Maven
private
def launch_jruby(args)
- classpath_array.each do |path|
- require path
- end
-
java.lang.System.setProperty("classworlds.conf",
- File.join(@maven_home, 'bin', "m2.conf"))
+ File.join(self.class.maven_home, 'bin', "m2.conf"))
- java.lang.System.setProperty("maven.home", @maven_home)
+ java.lang.System.setProperty("maven.home", self.class.maven_home)
- org.codehaus.plexus.classworlds.launcher.Launcher.main(args)
+ cw = self.class.class_world
+ org.apache.maven.cli.MavenCli.doMain( args, cw ) == 0
end
- def classpath_array
- Dir.glob(File.join(@maven_home, "boot", "*jar"))
+ def self.class_world
+ @class_world ||= class_world!
+ end
+
+ def self.class_world!
+ (classpath_array + classpath_array('lib')).each do |path|
+ require path
+ end
+ org.codehaus.plexus.classworlds.ClassWorld.new("plexus.core", java.lang.Thread.currentThread().getContextClassLoader())
+ end
+
+ def self.classpath_array(dir = 'boot')
+ Dir.glob(File.join(maven_home, dir, "*jar"))
end
def launch_java(*args)
- system "java -cp #{classpath_array.join(':')} -Dmaven.home=#{File.expand_path(@maven_home)} -Dclassworlds.conf=#{File.expand_path(File.join(@maven_home, 'bin', 'm2.conf'))} org.codehaus.plexus.classworlds.launcher.Launcher #{args.join ' '}"
+ system "java -cp #{self.class.classpath_array.join(':')} -Dmaven.home=#{File.expand_path(self.class.maven_home)} -Dclassworlds.conf=#{File.expand_path(File.join(self.class.maven_home, 'bin', 'm2.conf'))} org.codehaus.plexus.classworlds.launcher.Launcher #{args.join ' '}"
end
def options_string
@@ -45,7 +53,11 @@ def options_array
public
- def maven_home
+ def self.class_world
+ @class_world ||= class_world!
+ end
+
+ def self.maven_home
@maven_home = File.expand_path(File.join(File.dirname(__FILE__),
'..',
'..',
View
6 ruby-maven.gemspec
@@ -27,8 +27,10 @@ Gem::Specification.new do |s|
s.require_paths = ['lib/ruby']
s.rubygems_version = %q{1.3.5}
s.summary = %q{maven support for ruby projects with gemspec, Gemfile}
- s.add_dependency 'thor', '~> 0.14.6'
- s.add_dependency 'maven-tools', "~> 0.29.1"
+ s.add_dependency 'thor', '>= 0.14.6', '< 2.0' # mimic rails
+ s.add_dependency 'maven-tools', "~> 0.29.1"
+ s.add_development_dependency 'minitest', '3.3.0'
+ s.add_development_dependency 'rake', '= 0.9.2.2'
File.chmod(0755, File.join("bin", "mvn"))
end
View
23 spec/maven_spec.rb
@@ -0,0 +1,23 @@
+require 'ruby_maven'
+require 'stringio'
+
+describe Maven::Ruby::Maven do
+
+ subject { Maven::Ruby::Maven.new }
+ let(:log){ 'target/output.log' }
+ let(:out){ StringIO.new }
+
+ it 'should show maven' do
+ subject.exec('--version').must_equal true
+ end
+
+ it 'should launch maven' do
+ subject.exec('-l', log)
+ File.read(log).must_match /BUILD FAILURE/
+ end
+
+ it 'should launch maven with dependency:resolve' do
+ subject.exec('dependency:resolve', '-l', log)
+ File.read(log).must_match /BUILD SUCCESS/
+ end
+end

0 comments on commit 62def8d

Please sign in to comment.
Something went wrong with that request. Please try again.