Permalink
Browse files

get cucumber support and little fixes

  • Loading branch information...
1 parent e98b50f commit 306b61e19c20cb029eabde51425a9164c0421a22 @mkristian committed Oct 5, 2011
View
25 pom.xml
@@ -22,7 +22,7 @@
<groupId>rubygems</groupId>
<artifactId>ruby-maven</artifactId>
- <version>${maven.version}.${jruby.plugins.version}.1</version>
+ <version>${maven.version}.${jruby.plugins.version}</version>
<packaging>gem</packaging>
<name>ruby wrapper around maven and more</name>
@@ -49,9 +49,11 @@
</dependencies>
<properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- if some more gem releases are needed you can append some number
here with the gem.version -->
- <jruby.plugins.version>0.28.4</jruby.plugins.version>
+ <jruby.plugins.version>0.28.5</jruby.plugins.version>
+ <jruby.plugins.version.postfix>-SNAPSHOT</jruby.plugins.version.postfix>
<maven.version>3.0.3</maven.version>
<gem.basedir>${project.build.directory}/ruby-maven-${project.version}</gem.basedir>
</properties>
@@ -86,7 +88,7 @@
<artifactItem>
<groupId>de.saumya.mojo</groupId>
<artifactId>ruby-tools</artifactId>
- <version>${jruby.plugins.version}</version>
+ <version>${jruby.plugins.version}${jruby.plugins.version.postfix}</version>
<outputDirectory>${gem.basedir}/apache-maven-${maven.version}/lib/ruby</outputDirectory>
</artifactItem>
</artifactItems>
@@ -98,14 +100,29 @@
<plugin>
<groupId>de.saumya.mojo</groupId>
<artifactId>gem-maven-plugin</artifactId>
- <version>${jruby.plugins.version}</version>
+ <version>${jruby.plugins.version}${jruby.plugins.version.postfix}</version>
<extensions>true</extensions>
<configuration>
<gemspec>${project.basedir}/src/main/gemspec/maven.gemspec</gemspec>
<launchDirectory>${gem.basedir}/apache-maven-${maven.version}</launchDirectory>
<includeOpenSSL>true</includeOpenSSL>
</configuration>
</plugin>
+ <plugin>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>2.3.2</version>
+ <configuration>
+ <outputDirectory>${gem.basedir}/apache-maven-${maven.version}/lib</outputDirectory>
+ </configuration>
+ <executions>
+ <execution>
+ <phase>prepare-package</phase>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
</build>
@@ -22,6 +22,7 @@ Gem::Specification.new do |s|
Dir.glob("lib/*") +
Dir.glob("lib/ext/*") +
Dir.glob("lib/ruby/ruby_maven.rb") +
+ Dir.glob("lib/ruby/ruby-maven.rb") +
Dir.glob("lib/ruby/maven/**/*")
ext = Dir.glob("ext/*ruby*")
ext.delete(ext.detect{ |f| f =~ /jruby-complete/ })
@@ -0,0 +1,161 @@
+require 'fileutils'
+require 'ruby-maven'
+module Maven
+ class CucumberSteps
+
+ def initialize(options = {})
+ @options = {:ruby_version => RUBY_VERSION }
+ @options[:jruby_version] = JRUBY_VERSION if defined? JRUBY_VERSION
+
+ @options.merge!(options || {})
+ end
+
+ def rmvn
+ @rmvn ||= Maven::RubyMaven.new
+ end
+
+ def copy_tests(tests)
+ FileUtils.mkdir_p(@app_directory)
+ FileUtils.cp_r(File.join('templates', "tests-#{tests}", "."),
+ File.join(@app_directory, 'test'),
+ :remove_destination => true)
+ end
+
+ def copy_specs(specs)
+ FileUtils.mkdir_p(@app_directory)
+ FileUtils.cp_r(File.join('templates', "specs-#{specs}", "."),
+ File.join(@app_directory, 'spec'),
+ :remove_destination => true)
+ end
+
+ def copy_files(files)
+ FileUtils.mkdir_p(@app_directory)
+ FileUtils.cp_r(File.join('templates', "files-#{files}", "."),
+ @app_directory,
+ :remove_destination => true)
+ end
+
+ def create_rails_application(template)
+ name = template.sub(/.template$/, '')
+ @app_directory = File.join('target', name)
+
+ # rails version from gemspec
+ gemspec = File.read(Dir.glob("*.gemspec")[0])
+ rails_version = gemspec.split("\n").detect { |l| l =~ /development_dep.*rails/ }.sub(/'$/, '').sub(/.*'/, '')
+
+ rmvn.options['-Dplugin.version'] = @options[:plugin_version] if @options[:plugin_version]
+ rmvn.options['-Djruby.version'] = @options[:jruby_version] if @options[:jruby_version]
+ if @options[:ruby_version]
+ rversion = @options[:ruby_version] =~ /^1.8./ ? '--1.8': '--1.9'
+ rmvn.options['-Djruby.switches'] = rversion
+ end
+
+ rmvn.options['-Drails.version'] = rails_version
+ rmvn.options['-Dgem.home'] = ENV['GEM_HOME']
+ rmvn.options['-Dgem.path'] = ENV['GEM_PATH']
+ rmvn.options['-o'] = nil
+
+ FileUtils.rm_rf(@app_directory)
+
+ template_file = File.expand_path("templates/#{template}")
+ rmvn.exec("rails", "new", @app_directory, "-f", '--', '-e', "-Dtemplate=#{template_file}")
+ end
+
+ def given_template(template)
+ create_rails_application(template)
+ end
+
+ def given_template_and_tests(template, tests)
+ create_rails_application(template)
+ copy_tests(tests)
+ end
+
+ def given_template_and_specs(template, specs)
+ create_rails_application(template)
+ copy_specs(specs)
+ end
+
+ def given_template_and_files(template, files)
+ create_rails_application(template)
+ copy_files(files)
+ end
+
+ def given_application(name)
+ @app_directory = File.join('target', name)
+ end
+
+ def given_application_and_tests(name, tests)
+ @app_directory = File.join('target', name)
+ copy_tests(tests)
+ end
+
+ def given_application_and_specs(name, specs)
+ @app_directory = File.join('target', name)
+ copy_specs(specs)
+ end
+
+ def given_application_and_files(name, files)
+ @app_directory = File.join('target', name)
+ copy_files(files)
+ end
+
+ def execute(args)
+ rmvn.options['-l'] = "output.log"
+ rmvn.exec_in(@app_directory, args.split(' '))
+ end
+
+ def expected_output(expected)
+ result = File.read(File.join(@app_directory, "output.log"))
+ expected.split(/\"?\s+and\s+\"?/).each do |exp|
+ puts exp
+ yield(result =~ /.*#{exp}.*/)
+ end
+ end
+ end
+end
+
+
+steps = Maven::CucumberSteps.new(:plugin_version => '0.28.5-SNAPSHOT')
+
+Given /^I create new rails application with template "(.*)"$/ do |template|
+ steps.given_template(template)
+end
+
+Given /^I create new rails application with template "(.*)" and "(.*)" tests$/ do |template, tests|
+ steps.given_template_and_tests(template, tests)
+end
+
+Given /^I create new rails application with template "(.*)" and "(.*)" specs$/ do |template, specs|
+ steps.given_template_and_specs(template, specs)
+end
+
+Given /^I create new rails application with template "(.*)" and "(.*)" files$/ do |template, files|
+ steps.given_template_and_files(template, files)
+end
+
+Given /^me an existing rails application "(.*)"$/ do |name|
+ steps.given_application(name)
+end
+
+Given /^me an existing rails application "(.*)" and "(.*)" tests$/ do |name, tests|
+ steps.given_application_and_tests(name, tests)
+end
+
+Given /^me an existing rails application "(.*)" and "(.*)" specs$/ do |name, specs|
+ steps.given_application_and_specs(name, specs)
+end
+
+Given /^me an existing rails application "(.*)" and "(.*)" files$/ do |name, files|
+ steps.given_application_and_files(name, files)
+end
+
+And /^I execute \"(.*)\"$/ do |args|
+ steps.execute(args)
+end
+
+Then /^the output should contain \"(.*)\"$/ do |expected|
+ steps.expected_output(expected) do |exp|
+ exp.should_not be_nil
+ end
+end
+
@@ -0,0 +1 @@
+require 'ruby_maven'
@@ -71,10 +71,11 @@ def prepare(args)
version = args.detect do |a|
a =~ /^-Dplugin.version=/
end
+ version ||= options['-Dplugin.version']
if version
args.delete(version)
- version = version.sub(/^-Dplugin.version=/, ':')
+ version = ":" + version.sub(/^-Dplugin.version=/, '')
end
aa = if index = args.index("--")
args[(index + 1)..-1]
@@ -193,7 +194,8 @@ def exec(*args)
a = generate_pom(*a)
puts a.join ' '
if defined? JRUBY_VERSION
- launch_jruby(a)
+ # TODO use a setup like maven_gemify from jruby to launch maven
+ launch_java(a)
else
launch_java(a)
end

0 comments on commit 306b61e

Please sign in to comment.