maven_gem 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.txt ADDED
@@ -0,0 +1,6 @@
1
+ === 1.0.0 / 2008-09-12
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
6
+
data/Manifest.txt ADDED
@@ -0,0 +1,12 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ bin/maven_gem
6
+ lib/maven_gem.rb
7
+ lib/mvn_gem.rb
8
+ lib/pom2gem.rb
9
+ lib/rubygems_plugin.rb
10
+ lib/rubygems/commands/maven_command.rb
11
+ test/test_maven_gem.rb
12
+ examples/hello_pdf.rb
data/README.txt ADDED
@@ -0,0 +1,40 @@
1
+ = MavenGem
2
+
3
+ * http://www.jruby.org
4
+
5
+ == DESCRIPTION:
6
+
7
+ MavenGem is a tool, library, and gem plugin to install any Maven-published
8
+ Java library as though it were a gem.
9
+
10
+ == FEATURES:
11
+
12
+ * First release!
13
+ * maven_gem executable to install
14
+ ** use pom file location, pom file URL, or group ID, artifact ID, and version
15
+ * gem plugin for "maven" command, same params (RubyGems 1.3.2+)
16
+
17
+ == PROBLEMS:
18
+
19
+ * No dependency tracking using Maven dependencies
20
+ * No ability to output a .gem file rather than install
21
+ * No support for gems with more than one group ID
22
+ * No support for gems with alphanumeric version numbers
23
+ * No tests, minimal docs :)
24
+
25
+ == SYNOPSIS:
26
+
27
+ maven_gem <pom url>
28
+ maven_gem <pom file>
29
+ maven_gem <group ID> <artifact ID> <version>
30
+
31
+ or "gem maven" with same args (RubyGems 1.3.2+)
32
+
33
+ == REQUIREMENTS:
34
+
35
+ JRuby 1.2.0 or higher. RubyGems 1.3.2 or higher for gem plugin.
36
+
37
+ == INSTALL:
38
+
39
+ gem install maven_gem
40
+
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+ require './lib/maven_gem.rb'
6
+
7
+ Hoe.new('maven_gem', MavenGem::VERSION) do |p|
8
+ p.rubyforge_name = 'jruby_extras'
9
+ p.developer('Charles Oliver Nutter', 'charles.nutter@sun.com')
10
+ end
11
+
12
+ # vim: syntax=Ruby
data/bin/maven_gem ADDED
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env jruby
2
+ require 'rubygems'
3
+ require 'mvn_gem'
4
+
5
+ def maven_gem_error
6
+ raise "usage:
7
+ \tmaven_gem install <group id> <artifact id> <version>
8
+ \tmaven_gem install <pom URL>
9
+ \tmaven_gem install <pom file>"
10
+ end
11
+
12
+ maven_gem_error unless ARGV.length >= 1
13
+
14
+ case ARGV.shift
15
+ when 'install'
16
+ maven_gem_error unless ARGV.length >= 1
17
+ MavenGem.install *ARGV
18
+ else
19
+ maven_gem_error
20
+ end
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+ require 'itext'
3
+
4
+ import com.lowagie.text.pdf.PdfWriter
5
+ import com.lowagie.text.Document
6
+ import com.lowagie.text.Paragraph
7
+
8
+ file = File.open('Hello.pdf', 'w')
9
+ document = Document.new
10
+ writer = PdfWriter.get_instance(document, file.to_outputstream)
11
+ paragraph = Paragraph.new('Hello iText!')
12
+
13
+ document.open
14
+ document.add(paragraph)
15
+ document.close
data/lib/maven_gem.rb ADDED
@@ -0,0 +1,3 @@
1
+ class MavenGem
2
+ VERSION = '0.0.1'
3
+ end
data/lib/mvn_gem.rb ADDED
@@ -0,0 +1,29 @@
1
+ require 'net/http'
2
+ require 'pom2gem'
3
+ require 'rubygems/gem_runner'
4
+
5
+ module MavenGem
6
+ def MavenGem.install(group, artifact = nil, version = nil)
7
+ begin
8
+ if artifact
9
+ # fetch pom and install
10
+ url = MavenGem::PomSpec.maven_base_url + "/#{group}/#{artifact}/#{version}/#{artifact}-#{version}.pom"
11
+ gem = PomSpec.from_url(url)
12
+ else
13
+ if group =~ %r[^http://]
14
+ gem = PomSpec.from_url(pom_location)
15
+ else
16
+ gem = PomSpec.from_file(pom_location)
17
+ end
18
+ end
19
+ Gem::GemRunner.new.run(["install", gem])
20
+ ensure
21
+ FileUtils.rm_f gem
22
+ end
23
+ end
24
+ end
25
+
26
+ case ARGV.shift
27
+ when 'install'
28
+ MavenGem.install *ARGV
29
+ end
data/lib/pom2gem.rb ADDED
@@ -0,0 +1,136 @@
1
+ #!/usr/bin/env jruby
2
+ require 'rexml/document'
3
+ require 'net/http'
4
+ require 'rubygems'
5
+ require 'yaml'
6
+ require 'fileutils'
7
+
8
+ module MavenGem
9
+ module PomSpec
10
+ def self.from_file(filename, options = {})
11
+ puts "Reading POM from #{filename}" if options[:verbose]
12
+ pom_doc = REXML::Document.new(File.read(filename))
13
+ from_doc(pom_doc, options)
14
+ end
15
+
16
+ def self.from_url(url, options = {})
17
+ uri = URI.parse(url)
18
+ puts "Retrieving POM from #{url}" if options[:verbose]
19
+ pom_doc = REXML::Document.new(Net::HTTP.get(uri))
20
+ from_doc(pom_doc, options)
21
+ end
22
+
23
+ def self.from_doc(pom_doc, options = {})
24
+ begin
25
+ spec = Gem::Specification.new
26
+
27
+ spec.platform = "java"
28
+
29
+ artifact = nil
30
+ group = nil
31
+ version = nil
32
+
33
+ puts "Processing POM" if options[:verbose]
34
+ pom_doc.elements.each("/project/*") do |element|
35
+ case element.name
36
+ when "artifactId"
37
+ spec.name = element.text
38
+ artifact = element.text
39
+ when "groupId"
40
+ group = element.text
41
+ when "version"
42
+ spec.version = element.text
43
+ version = element.text
44
+ when "description"
45
+ spec.description = element.text
46
+ when "dependencies"
47
+ element.elements.each do |dependency|
48
+ dep_artifact = dependency.elements[2].text
49
+ dep_version = dependency.elements[3].text
50
+
51
+ new_dep = Gem::Dependency.new(dep_artifact, "=#{dep_version}")
52
+ spec.dependencies << new_dep
53
+ end
54
+ when "developers"
55
+ element.elements.each("developer") do |developer|
56
+ spec.authors << developer.elements[2].text
57
+ end
58
+ when "url"
59
+ spec.homepage = element.text
60
+ end
61
+ end
62
+
63
+ group_dir = group.gsub('.', '/')
64
+ spec.lib_files << "#{artifact}.rb"
65
+ gem_name = "#{artifact}-#{version}"
66
+ gem_dir = "#{gem_name}.#{$$}"
67
+ remote_dir = "#{group_dir}/#{artifact}/#{version}"
68
+ jar_file = "#{gem_name}.jar"
69
+ spec.lib_files << jar_file
70
+
71
+ puts "Using #{gem_dir} work dir" if options[:verbose]
72
+ FileUtils.mkdir_p(gem_dir)
73
+ FileUtils.mkdir_p("#{gem_dir}/lib")
74
+
75
+ full_url = "#{maven_base_url}/#{remote_dir}/#{jar_file}"
76
+ puts "Fetching #{full_url}" if options[:verbose]
77
+ uri = URI.parse(full_url)
78
+ jar_contents = Net::HTTP.get(uri)
79
+ File.open("#{gem_dir}/lib/#{jar_file}", 'w') {|f| f.write(jar_contents)}
80
+
81
+ ruby_file_contents = <<END
82
+ begin
83
+ require 'java'
84
+ require File.dirname(__FILE__) + '/#{jar_file}'
85
+ rescue LoadError
86
+ puts 'JAR-based gems require JRuby to load. Please visit www.jruby.org.'
87
+ raise
88
+ end
89
+ END
90
+ ruby_file = "#{gem_dir}/lib/#{artifact}.rb"
91
+ puts "Writing #{ruby_file}" if options[:verbose]
92
+ File.open(ruby_file, 'w') do |file|
93
+ file.write(ruby_file_contents)
94
+ end
95
+
96
+ metadata_file = "#{gem_dir}/metadata"
97
+ puts "Writing #{metadata_file}" if options[:verbose]
98
+ File.open(metadata_file, 'w') do |file|
99
+ file.write(spec.to_yaml)
100
+ end
101
+
102
+ gem_file = "#{gem_name}-java.gem"
103
+
104
+ puts "Building #{gem_file}" if options[:verbose]
105
+ Dir.chdir(gem_dir) do
106
+ fail unless
107
+ system('gzip metadata') and
108
+ system('tar czf data.tar.gz lib/*') and
109
+ system("tar cf ../#{gem_file} data.tar.gz metadata.gz")
110
+ end
111
+
112
+ puts "Done!" if options[:verbose]
113
+ ensure
114
+ FileUtils.rm_rf(gem_dir)
115
+ end
116
+
117
+ "#{gem_name}-java.gem"
118
+ end
119
+
120
+ def self.maven_base_url
121
+ "http://mirrors.ibiblio.org/pub/mirrors/maven2"
122
+ end
123
+ end
124
+ end
125
+
126
+ if __FILE__ == $0
127
+ if ARGV[0]
128
+ if ARGV[0] =~ %r[^http://]
129
+ spec = MavenGem::PomSpec.from_url(ARGV[0])
130
+ else
131
+ spec = MavenGem::PomSpec.from_file(ARGV[0])
132
+ end
133
+ else
134
+ raise ArgumentError, "specify filename or URL on command line"
135
+ end
136
+ end
@@ -0,0 +1,18 @@
1
+ require 'rubygems/command'
2
+ require 'mvn_gem'
3
+
4
+ class Gem::Commands::MavenCommand < Gem::Command
5
+
6
+ def initialize
7
+ super 'maven', 'Install a Maven-published Java library as a gem'
8
+ end
9
+
10
+ def execute
11
+ args = options[:args]
12
+
13
+ raise "usage: gem maven <group id> <artifact id> <version>" unless args.length == 3
14
+ MavenGem.install(*options[:args])
15
+ end
16
+
17
+ end
18
+
@@ -0,0 +1,4 @@
1
+ require 'rubygems/command_manager'
2
+
3
+ Gem::CommandManager.instance.register_command :maven
4
+
File without changes
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ required_ruby_version: !ruby/object:Gem::Requirement
3
+ requirements:
4
+ - - '>='
5
+ - !ruby/object:Gem::Version
6
+ version: "0"
7
+ version:
8
+ email:
9
+ - charles.nutter@sun.com
10
+ cert_chain: []
11
+
12
+ summary: MavenGem is a tool, library, and gem plugin to install any Maven-published
13
+ Java library as though it were a gem.
14
+ post_install_message:
15
+ extra_rdoc_files:
16
+ - History.txt
17
+ - Manifest.txt
18
+ - README.txt
19
+ homepage: http://www.jruby.org
20
+ signing_key:
21
+ name: maven_gem
22
+ rdoc_options:
23
+ - --main
24
+ - README.txt
25
+ rubyforge_project: jruby_extras
26
+ autorequire:
27
+ licenses: []
28
+
29
+ executables:
30
+ - maven_gem
31
+ description: |-
32
+ MavenGem is a tool, library, and gem plugin to install any Maven-published
33
+ Java library as though it were a gem.
34
+ specification_version: 3
35
+ default_executable:
36
+ files:
37
+ - History.txt
38
+ - Manifest.txt
39
+ - README.txt
40
+ - Rakefile
41
+ - bin/maven_gem
42
+ - lib/maven_gem.rb
43
+ - lib/mvn_gem.rb
44
+ - lib/pom2gem.rb
45
+ - lib/rubygems_plugin.rb
46
+ - lib/rubygems/commands/maven_command.rb
47
+ - test/test_maven_gem.rb
48
+ - examples/hello_pdf.rb
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - '>='
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ extensions: []
56
+
57
+ rubygems_version: 1.3.2
58
+ requirements: []
59
+
60
+ authors:
61
+ - Charles Oliver Nutter
62
+ date: 2009-04-17 05:00:00 +00:00
63
+ platform: ruby
64
+ test_files:
65
+ - test/test_maven_gem.rb
66
+ version: !ruby/object:Gem::Version
67
+ version: 0.0.1
68
+ require_paths:
69
+ - lib
70
+ dependencies:
71
+ - !ruby/object:Gem::Dependency
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '>='
75
+ - !ruby/object:Gem::Version
76
+ version: 1.12.1
77
+ version:
78
+ type: :development
79
+ version_requirement:
80
+ name: hoe
81
+ bindir: bin
82
+ has_rdoc: true