Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don’t worry, you can still create the pull request.
  • 8 commits
  • 20 files changed
  • 0 commit comments
  • 1 contributor
View
3 .gitignore
@@ -1,2 +1,3 @@
pkg
-*.gemspec
+.bundle
+Gemfile.lock
View
1 .rspec
@@ -0,0 +1 @@
+--color
View
1 .rvmrc
@@ -0,0 +1 @@
+rvm @maven_gem
View
2 Gemfile
@@ -0,0 +1,2 @@
+source "http://rubygems.org"
+gemspec
View
42 Rakefile
@@ -1,39 +1,9 @@
require 'rubygems'
-require 'rake'
+require 'bundler'
+Bundler.setup
+Bundler::GemHelper.install_tasks
-begin
- require 'jeweler'
- Jeweler::Tasks.new do |gem|
- gem.name = "maven_gem"
- gem.summary = %Q{Packaging Maven artifacts as Rubygems.}
- gem.description = %Q{MavenGem is a command and RubyGems plugin for packaging Maven artifacts as gems.}
- gem.email = "headius@headius.com"
- gem.homepage = "http://github.com/jruby/maven_gem"
- gem.authors = ["Charles Nutter", "David Calavera"]
+require 'rspec/core/rake_task'
+RSpec::Core::RakeTask.new(:rspec)
- gem.files = FileList['bin/*', 'lib/**/*.rb', 'History.txt', 'LICENSE', 'Rakefile', 'README.rdoc', 'VERSION']
-
- gem.add_development_dependency 'rspec'
- gem.add_development_dependency 'mocha'
- end
-
- Jeweler::GemcutterTasks.new
-rescue LoadError
- puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
-end
-
-require 'spec/rake/spectask'
-Spec::Rake::SpecTask.new(:spec) do |spec|
- spec.libs << 'lib' << 'spec'
- spec.spec_opts = ['--options', "spec/spec.opts"]
- spec.spec_files = FileList['spec/**/*_spec.rb']
-end
-
-Spec::Rake::SpecTask.new(:rcov) do |spec|
- spec.libs << 'lib' << 'spec'
- spec.spec_opts = ['--options', "spec/spec.opts"]
- spec.pattern = 'spec/**/*_spec.rb'
- spec.rcov = true
-end
-
-task :default => :spec
+task :default => :rspec
View
1 VERSION
@@ -1 +0,0 @@
-0.0.3
View
4 bin/maven_gem 100644 → 100755
@@ -15,10 +15,10 @@ maven_gem_error unless ARGV.length >= 1
case ARGV.shift
when 'install'
maven_gem_error unless ARGV.length >= 1
- MavenGem.install *ARGV
+ MavenGem.install *(ARGV.dup + [{}])
when 'build'
maven_gem_error unless ARGV.length >= 1
- MavenGem.build *ARGV
+ MavenGem.build *(ARGV.dup + [{}])
else
maven_gem_error
end
View
17 lib/maven_gem.rb
@@ -8,19 +8,22 @@
require 'rubygems/gem_runner'
module MavenGem
- def self.install(group, artifact = nil, version = nil)
- gem = build(group, artifact, version)
+ def self.install(*args)
+ gem = build(*args)
Gem::GemRunner.new.run(["install", gem])
ensure
FileUtils.rm_f(gem) if gem
end
- def self.build(group, artifact = nil, version = nil)
- gem = if artifact
- url = MavenGem::PomSpec.to_maven_url(group, artifact, version)
- MavenGem::PomSpec.build(url)
+ def self.build(*args)
+ options = args.pop if Hash === args[-1]
+ if args.length == 1
+ url = args[0]
+ elsif args.length == 3
+ url = MavenGem::PomSpec.to_maven_url(*args)
else
- MavenGem::PomSpec.build(group)
+ raise "Pass <group id> <artifact id> <version> or <pom URL> or <pom FILE>"
end
+ MavenGem::PomSpec.build(url, options)
end
end
View
26 lib/maven_gem/pom_fetcher.rb
@@ -1,31 +1,15 @@
-require 'net/http'
-require 'uri'
+require 'open-uri'
module MavenGem
class PomFetcher
-
- def self.fetch(path, options = {})
- puts "Reading POM from #{path}" if options[:verbose]
-
- fetch_pom(path, options)
- end
-
- def self.clean_pom(pom) #avoid namespaces errors and gotchas
- pom.gsub(/<project[^>]+/, '<project>')
- end
-
- def self.fetch_pom(path, options = {})
- path =~ /^http:\/\// ? fetch_from_url(path, options) :
- fetch_from_file(path, options)
+ def self.fetch(uri)
+ clean_pom(Kernel.open(uri).read)
end
private
- def self.fetch_from_url(path, options = {})
- Net::HTTP.get(URI.parse(path))
- end
- def self.fetch_from_file(path, options = {})
- File.read(path)
+ def self.clean_pom(pom) #avoid namespaces errors and gotchas
+ pom.gsub(/<project\s[^>]+/, '<project>')
end
end
end
View
44 lib/maven_gem/pom_spec.rb
@@ -5,11 +5,11 @@ module MavenGem
class PomSpec
extend MavenGem::XmlUtils
- def self.build(location)
+ def self.build(location, options)
pom_doc = MavenGem::PomFetcher.fetch(location)
- pom = MavenGem::PomSpec.parse_pom(pom_doc)
- spec = MavenGem::PomSpec.generate_spec(pom)
- MavenGem::PomSpec.create_gem(spec, pom)
+ pom = MavenGem::PomSpec.parse_pom(pom_doc, options)
+ spec = MavenGem::PomSpec.generate_spec(pom, options)
+ MavenGem::PomSpec.create_gem(spec, pom, options)
end
# Unless the maven version string is a valid Gem version string create a substitute
@@ -75,6 +75,7 @@ def self.parse_pom(pom_doc, options = {})
pom.name = maven_to_gem_name(pom.group, pom.artifact)
pom.lib_name = "#{pom.artifact}.rb"
pom.gem_name = "#{pom.name}-#{pom.version}"
+ pom.gemspec_file = "#{pom.name}.gemspec"
pom.jar_file = "#{pom.artifact}-#{pom.maven_version}.jar"
pom.remote_dir = "#{pom.group.gsub('.', '/')}/#{pom.artifact}/#{pom.version}"
pom.remote_jar_url = "#{maven_base_url}/#{pom.remote_dir}/#{pom.jar_file}"
@@ -90,6 +91,7 @@ def self.generate_spec(pom, options = {})
pom.dependencies.each {|dep| specification.dependencies << dep}
specification.authors = pom.authors
specification.description = pom.description
+ specification.summary = "#{pom.name}-#{pom.version}"
specification.homepage = pom.url
specification.files = ["lib/#{pom.lib_name}", "lib/#{pom.jar_file}"]
@@ -97,9 +99,11 @@ def self.generate_spec(pom, options = {})
end
def self.create_gem(spec, pom, options = {})
- gem_dir = create_files(spec, pom, options)
- ensure
- FileUtils.rm_r(gem_dir) if gem_dir
+ gem_path = create_files(spec, pom, options)
+ dir = options[:dir] || '.'
+ raise "Not a dir: #{to_dir}" unless File.directory?(dir)
+ FileUtils.mv(gem_path, dir)
+ File.join(dir, File.basename(gem_path))
end
def self.to_maven_url(group, artifact, version)
@@ -117,10 +121,9 @@ def self.create_files(specification, pom, options = {})
ruby_file_contents(gem_dir, pom, options)
jar_file_contents(gem_dir, pom, options)
- metadata_contents(gem_dir, specification, pom, options)
- gem_contents(gem_dir, pom, options)
-
- gem_dir
+ gemspec_contents(gem_dir, specification, pom, options)
+ gem_base_name = build_gem(gem_dir, pom, options)
+ File.join(gem_dir, gem_base_name)
end
def self.create_tmp_directories(pom, options = {})
@@ -163,21 +166,20 @@ def self.jar_file_contents(gem_dir, pom, options = {})
File.open("#{gem_dir}/lib/#{pom.jar_file}", 'w') {|f| f.write(jar_contents)}
end
- def self.metadata_contents(gem_dir, spec, pom, options = {})
- metadata_file = "#{gem_dir}/metadata"
- puts "Writing #{metadata_file}" if options[:verbose]
- File.open(metadata_file, 'w') do |file|
- file.write(spec.to_yaml)
+ def self.gemspec_contents(gem_dir, spec, pom, options = {})
+ gemspec_file = "#{gem_dir}/#{pom.gemspec_file}"
+ puts "Writing #{gemspec_file}" if options[:verbose]
+ File.open(gemspec_file, 'w') do |file|
+ file.write(spec.to_ruby)
end
end
- def self.gem_contents(gem_dir, pom, options = {})
+ # Builds the gem and returns its base filename
+ def self.build_gem(gem_dir, pom, options = {})
puts "Building #{pom.gem_file}" if options[:verbose]
Dir.chdir(gem_dir) do
- fail unless
- system('gzip metadata') and
- system('tar czf data.tar.gz lib/*') and
- system("tar cf ../#{pom.gem_file} data.tar.gz metadata.gz")
+ spec = Gem::Specification.load(pom.gemspec_file)
+ Gem::Builder.new(spec).build
end
end
View
22 lib/rubygems/commands/maven_command.rb
@@ -4,14 +4,28 @@
class Gem::Commands::MavenCommand < Gem::Command
def initialize
- super 'maven', 'Install a Maven-published Java library as a gem'
+ super('maven', 'Install a Maven-published Java library as a gem', {:dir => '.', :keep => false, :verbose => false})
+
+ add_option('-d', '--dir DIR', 'Directory where temporary gem gets created') do |dir, options|
+ options[:dir] = dir
+ end
+
+ add_option('-k', '--keep', 'Do not delete the temporary gem file') do |value, options|
+ options[:keep] = trye
+ end
+
+ add_option('-v', '--verbose', 'Be extra verbose') do |value, options|
+ options[:verbose] = true
+ end
+ end
+
+ def defaults_str # :nodoc:
+ "--dir . --no-keep"
end
def execute
args = options[:args]
-
- raise "usage: gem maven <group id> <artifact id> <version>" unless args.length == 3
- MavenGem.install(*options[:args])
+ MavenGem.install(*(args + [options]))
end
end
View
24 maven_gem.gemspec
@@ -0,0 +1,24 @@
+# -*- encoding: utf-8 -*-
+$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
+
+Gem::Specification.new do |s|
+ s.name = 'maven_gem'
+ s.version = '0.0.4'
+ s.authors = ["Charles Nutter", "David Calavera"]
+ s.description = 'MavenGem is a command and RubyGems plugin for packaging Maven artifacts as gems.'
+ s.summary = "Packaging Maven artifacts as Rubygems."
+ s.email = 'headius@headius.com'
+ s.homepage = 'http://github.com/jruby/maven_gem'
+
+ s.add_development_dependency 'rspec', '~> 2.0.0.beta.22'
+ s.add_development_dependency 'mocha', '~> 0.9.8'
+ s.add_development_dependency 'webmock', '~> 1.3.5'
+
+ s.rubygems_version = "1.3.7"
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.extra_rdoc_files = ["LICENSE.txt", "README.txt"]
+ s.rdoc_options = ["--charset=UTF-8"]
+ s.require_path = "lib"
+end
View
0 spec/fixtures/ant.pom → spec/fixtures/ant/ant/1.6.5/ant-1.6.5.pom
File renamed without changes.
View
125 spec/fixtures/gherkin/gherkin/2.2.4/gherkin-2.2.4.pom
@@ -0,0 +1,125 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
+ http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>gherkin</groupId>
+ <artifactId>gherkin</artifactId>
+ <version>2.2.4</version>
+
+ <packaging>jar</packaging>
+ <name>Gherkin</name>
+ <description>Pure Java Gherkin</description>
+
+ <scm>
+ <connection>scm:git:git://github.com/aslakhellesoy/cuke4duke.git</connection>
+ </scm>
+
+ <distributionManagement>
+ <repository>
+ <id>cukes</id>
+ <name>Cucumber Maven Repo</name>
+ <url>scp://cukes.info/home/6664/users/.home/domains/cukes.info/html/maven</url>
+ </repository>
+ </distributionManagement>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>com.googlecode.json-simple</groupId>
+ <artifactId>json-simple</artifactId>
+ <version>1.1</version>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.8.1</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <version>1.8.4</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <resources>
+ <resource>
+ <directory>${basedir}/../lib</directory>
+ <includes>
+ <include>gherkin/parser/*.txt</include>
+ </includes>
+ </resource>
+ <resource>
+ <directory>${basedir}/src/main/resources</directory>
+ <includes>
+ <include>gherkin/*.properties</include>
+ </includes>
+ </resource>
+ </resources>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <encoding>UTF-8</encoding>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <configuration>
+ <archive>
+ <manifest>
+ <mainClass>gherkin.Main</mainClass>
+ </manifest>
+ </archive>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-source-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>bind-sources</id>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <configuration>
+ <tasks>
+ <copy file="${project.build.directory}/${project.build.finalName}.jar"
+ tofile="${basedir}/../lib/gherkin.jar"/>
+ </tasks>
+ </configuration>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
View
0 spec/fixtures/hudson-rake.pom → ...s/rake/1.7-SNAPSHOT/rake-1.7-SNAPSHOT.pom
File renamed without changes.
View
14 spec/maven_gem/maven_gem_spec.rb
@@ -1,17 +1,11 @@
-require File.dirname(__FILE__) + '/../spec_helper'
+require 'spec_helper'
describe MavenGem do
describe "build" do
it "creates a gem with group, artifact and version" do
- begin
- lambda {
- MavenGem.build('ant', 'ant', '1.6.5')
- }.should_not raise_error
- File.exist?('ant.ant-1.6.5-java.gem').should be_true
- ensure
- require 'fileutils'
- FileUtils.rm_f('ant.ant-1.6.5-java.gem')
- end
+ gem_file = MavenGem.build('ant', 'ant', '1.6.5', {:verbose => true, :dir => 'tmp'})
+ gem_file.should == 'tmp/ant.ant-1.6.5-java.gem'
+ File.should exist(gem_file)
end
end
end
View
25 spec/maven_gem/pom_fetcher_spec.rb
@@ -1,29 +1,16 @@
-require File.dirname(__FILE__) + '/../spec_helper'
+require 'spec_helper'
describe MavenGem::PomFetcher do
- before(:each) do
- @ant_path = File.join(FIXTURES, 'ant.pom')
- @ant_pom = File.read(@ant_path)
- end
-
it "removes namespaces from pom file" do
- pom = MavenGem::PomFetcher.clean_pom(@ant_pom)
+ ant_url = "http://mirrors.ibiblio.org/pub/mirrors/maven2/ant/ant/1.6.5/ant-1.6.5.pom"
+ pom = MavenGem::PomFetcher.fetch(ant_url)
pom.should =~ /<project>/
end
- it "reads the pom file from a url when the protocol is http" do
- ant_url = "http://mirrors.ibiblio.org/pub/mirrors/maven2/ant/ant/1.6.5/ant.pom"
- Net::HTTP.expects(:get).with(URI.parse(ant_url)).returns(@ant_pom)
-
- pom = MavenGem::PomFetcher.fetch_pom(ant_url)
- pom.should == @ant_pom
- end
-
it "reads the pom file from the system when the path is not an url" do
- File.expects(:read).with(@ant_path).returns(@ant_pom)
-
- pom = MavenGem::PomFetcher.fetch_pom(@ant_path)
- pom.should == @ant_pom
+ ant_url = File.dirname(__FILE__) + "/../fixtures/ant/ant/1.6.5/ant-1.6.5.pom"
+ pom = MavenGem::PomFetcher.fetch(ant_url)
+ pom.should =~ /<project>/
end
end
View
38 spec/maven_gem/pom_spec_spec.rb
@@ -1,11 +1,12 @@
-require File.dirname(__FILE__) + '/../spec_helper'
+require 'spec_helper'
require 'fileutils'
describe MavenGem::PomSpec do
before(:each) do
- ant_path = File.join(FIXTURES, 'ant.pom')
- @pom = MavenGem::PomFetcher.fetch(ant_path)
+ @pom = MavenGem::PomFetcher.fetch("http://mirrors.ibiblio.org/pub/mirrors/maven2/ant/ant/1.6.5/ant-1.6.5.pom")
+ @hudson_rake_pom = MavenGem::PomFetcher.fetch('http://mirrors.ibiblio.org/pub/mirrors/maven2/org/jvnet/hudson/plugins/rake/1.7-SNAPSHOT/rake-1.7-SNAPSHOT.pom')
+ @gherkin_pom = MavenGem::PomFetcher.fetch('http://mirrors.ibiblio.org/pub/mirrors/maven2/gherkin/gherkin/2.2.4/gherkin-2.2.4.pom')
end
describe "maven_to_gem_version" do
@@ -37,6 +38,10 @@
MavenGem::PomSpec.parse_pom(with_non_numeric_version).maven_version.should == '1.6.6-SNAPSHOT'
end
+ it "doesn't kill project.build.sourceEncoding elements" do
+ gherkin_pom.description.should == 'Pure Java Gherkin'
+ end
+
it "keeps the version number as version" do
ant_pom.version.should == '1.6.5'
with_non_numeric_version = @pom.gsub(/<version>1.6.5<\/version>/, '<version>1.6.6-SNAPSHOT</version>')
@@ -78,7 +83,7 @@
end
it "doesn't add authors when the node doesn't exist" do
- ant_pom.authors.should be_empty
+ ant_pom.authors.should be_empty
end
it "uses parent groupId when groupId node doesn't exist" do
@@ -113,8 +118,7 @@
end
it "uses the version from the parent when its version doesn't exit" do
- pom = MavenGem::PomFetcher.fetch(File.join(FIXTURES, 'hudson-rake.pom'))
- pom_without_version = pom.gsub(/<version>1.7-SNAPSHOT<\/version>/, '')
+ pom_without_version = @hudson_rake_pom.gsub(/<version>1.7-SNAPSHOT<\/version>/, '')
pom_spec = MavenGem::PomSpec.parse_pom(pom_without_version)
pom_spec.version.should == '1.319'
@@ -143,16 +147,11 @@
describe "create_gem" do
it "creates the gem file" do
- begin
- pom = ant_pom
- spec = MavenGem::PomSpec.generate_spec(pom)
- lambda {
- MavenGem::PomSpec.create_gem(spec, pom)
- }.should_not raise_error
- File.exist?('ant.ant-1.6.5-java.gem').should be_true
- ensure
- FileUtils.rm_f('ant.ant-1.6.5-java.gem')
- end
+ pom = ant_pom
+ spec = MavenGem::PomSpec.generate_spec(pom)
+ gem_file = MavenGem::PomSpec.create_gem(spec, pom, {:dir => 'tmp'})
+ gem_file.should == 'tmp/ant.ant-1.6.5-java.gem'
+ File.should exist(gem_file)
end
it "creates a ruby module with the artifact name" do
@@ -188,14 +187,17 @@ def pom_with_dependencies
end
def hudson_rake_pom
- pom = MavenGem::PomFetcher.fetch(File.join(FIXTURES, 'hudson-rake.pom'))
- MavenGem::PomSpec.parse_pom(pom)
+ MavenGem::PomSpec.parse_pom(@hudson_rake_pom)
end
def ant_pom
MavenGem::PomSpec.parse_pom(@pom)
end
+ def gherkin_pom
+ MavenGem::PomSpec.parse_pom(@gherkin_pom)
+ end
+
def within_tmp_directory
tmp_dir = '/tmp/maven_gem_spec'
begin
View
2 spec/spec.opts
@@ -1,2 +0,0 @@
---colour
---format specdoc
View
38 spec/spec_helper.rb
@@ -1,19 +1,29 @@
-begin
- require 'spec'
-rescue LoadError
- require 'rubygems'
- gem 'rspec'
- require 'spec'
-end
-
-$:.unshift(File.dirname(__FILE__) + '/../lib')
-
require 'maven_gem'
-require 'rubygems'
require 'mocha'
+require 'webmock'
+require 'fileutils'
-Spec::Runner.configure do |config|
+RSpec.configure do |config|
config.mock_with :mocha
-end
-FIXTURES = File.join(File.dirname(__FILE__), 'fixtures')
+ config.before do
+ Dir['tmp/*.gem'].each{|gem| FileUtils.rm(gem)}
+
+ WebMock.reset_webmock
+
+ maven_repo = File.join(File.dirname(__FILE__), 'fixtures')
+ Dir["#{maven_repo}/**/*.pom"].each do |pom|
+ relative_path = pom[maven_repo.length+1..-1]
+ pom_url = "http://mirrors.ibiblio.org/pub/mirrors/maven2/#{relative_path}"
+ jar_url = pom_url.gsub(/\.pom$/, '.jar')
+
+ WebMock.stub_request(:get, pom_url).to_return do |request|
+ {:body => IO.read(pom)}
+ end
+
+ WebMock.stub_request(:get, jar_url).to_return do |request|
+ {:body => "A fake jar for #{jar_url}"}
+ end
+ end
+ end
+end

No commit comments for this range

Something went wrong with that request. Please try again.