detroit-gem 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.ruby +37 -0
- data/COPYING.rdoc +24 -0
- data/LICENSE.txt +674 -0
- data/README.rdoc +27 -0
- data/lib/detroit-gem.rb +230 -0
- data/man/detroit-gem.5 +79 -0
- data/man/detroit-gem.5.html +147 -0
- data/man/detroit-gem.5.ronn +65 -0
- metadata +81 -0
data/README.rdoc
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
= Detroit Gem Tool
|
2
|
+
|
3
|
+
{Website}[http://rubyworks.github.com/detroit-gem] /
|
4
|
+
{Report Issue}[http://github.com/rubyworks/detroit-gem/issues] /
|
5
|
+
{Repository}[http://github.com/rubyworks/detroit-gem]
|
6
|
+
|
7
|
+
|
8
|
+
== Description
|
9
|
+
|
10
|
+
Create `.gem` package for your Ruby project.
|
11
|
+
|
12
|
+
|
13
|
+
== Installation
|
14
|
+
|
15
|
+
Per the usual gem install process:
|
16
|
+
|
17
|
+
$ gem install detroit-rubygems
|
18
|
+
|
19
|
+
|
20
|
+
== Copyrights
|
21
|
+
|
22
|
+
Copyright (c) 2011 Thomas Sawyer
|
23
|
+
|
24
|
+
Detroit Gem is licensed via the terms of the GPL version 3 or greater.
|
25
|
+
|
26
|
+
See COPYING.rdoc and LICENSE.txt files for details.
|
27
|
+
|
data/lib/detroit-gem.rb
ADDED
@@ -0,0 +1,230 @@
|
|
1
|
+
require 'detroit/tool'
|
2
|
+
|
3
|
+
module Detroit
|
4
|
+
|
5
|
+
# Create new Gem tool with the specified +options+.
|
6
|
+
def Gem(options={})
|
7
|
+
Gem.new(options)
|
8
|
+
end
|
9
|
+
|
10
|
+
# The Gem tool is used to generate gemspec and gem packages.
|
11
|
+
class Gem < Tool
|
12
|
+
|
13
|
+
# The .gemspec filename (default looks-up `.gemspec` or `name.gemspec` file).
|
14
|
+
attr_accessor :gemspec
|
15
|
+
|
16
|
+
# True or false whether to write gemspec from project metadata (default is `false`).
|
17
|
+
attr_accessor :autospec
|
18
|
+
|
19
|
+
# Package directory (defaults to `pkg`).
|
20
|
+
# Location of packages. This defaults to Project#pkg.
|
21
|
+
attr_accessor :pkgdir
|
22
|
+
|
23
|
+
# Whether to install the gem.
|
24
|
+
attr_writer :install
|
25
|
+
|
26
|
+
# Whether to install the gem (default `false`).
|
27
|
+
def install?
|
28
|
+
@install
|
29
|
+
end
|
30
|
+
|
31
|
+
# What rvm gemset to install in if installing.
|
32
|
+
#attr_accessor :gemset
|
33
|
+
|
34
|
+
# Version to release. Defaults to current version.
|
35
|
+
attr :version
|
36
|
+
|
37
|
+
# Additional options to pass to gem command.
|
38
|
+
#attr :options
|
39
|
+
|
40
|
+
|
41
|
+
# A S S E M B L Y
|
42
|
+
|
43
|
+
#
|
44
|
+
def assemble?(station, options={})
|
45
|
+
case station
|
46
|
+
when :install then install?
|
47
|
+
when :package then true
|
48
|
+
when :release then true
|
49
|
+
when :reset then true
|
50
|
+
when :purge then true
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# Attach to `package`, `install` and `release`, `reset` and `purge`.
|
55
|
+
def assemble(station, options={})
|
56
|
+
case station
|
57
|
+
when :package then package
|
58
|
+
when :install then install
|
59
|
+
when :release then release
|
60
|
+
when :reset then reset
|
61
|
+
when :purge then purge
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
# S E R V I C E M E T H O D S
|
67
|
+
|
68
|
+
# Write gemspec if +autospec+ is +true+ and then build the gem.
|
69
|
+
def package
|
70
|
+
create_gemspec if autospec # TODO: should autospec be a generate phase?
|
71
|
+
build
|
72
|
+
end
|
73
|
+
|
74
|
+
# Create a gem package.
|
75
|
+
def build
|
76
|
+
trace "gem build #{gemspec}"
|
77
|
+
spec = load_gemspec
|
78
|
+
builder = ::Gem::Builder.new(spec)
|
79
|
+
package = builder.build
|
80
|
+
mkdir_p(pkgdir)
|
81
|
+
mv(package, pkgdir)
|
82
|
+
end
|
83
|
+
|
84
|
+
# Convert metadata to a gemspec and write to +file+.
|
85
|
+
#
|
86
|
+
# file - name of gemspec file (defaults to value of #gemspec).
|
87
|
+
#
|
88
|
+
# Returns [String] file name.
|
89
|
+
def spec(file=nil)
|
90
|
+
create_gemspec(file)
|
91
|
+
end
|
92
|
+
|
93
|
+
#
|
94
|
+
def install
|
95
|
+
return unless install?
|
96
|
+
package_files.each do |file|
|
97
|
+
sh "gem install --no-rdoc --no-ri #{file}"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
# TODO: Gem push programatically instead of shelling out.
|
102
|
+
|
103
|
+
# Push gem package to RubyGems.org (a la Gemcutter).
|
104
|
+
def push
|
105
|
+
if package_files.empty?
|
106
|
+
report "No .gem packages found for version {version} at #{pkgdir}."
|
107
|
+
else
|
108
|
+
package_files.each do |file|
|
109
|
+
sh "gem push #{file}"
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
#
|
115
|
+
alias_method :release, :push
|
116
|
+
|
117
|
+
# Mark package files as outdated.
|
118
|
+
def reset
|
119
|
+
package_files.each do |f|
|
120
|
+
utime(0 ,0, f)
|
121
|
+
report "Reset #{f}"
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
# Remove package file(s).
|
126
|
+
#--
|
127
|
+
# TODO: This is a little loose. Can we be more specific about which
|
128
|
+
# gem file(s) to remove?
|
129
|
+
#++
|
130
|
+
def purge
|
131
|
+
package_files.each do |f|
|
132
|
+
rm(f)
|
133
|
+
report "Removed #{f}"
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
private
|
138
|
+
|
139
|
+
#
|
140
|
+
def initialize_defaults
|
141
|
+
@autospec = false
|
142
|
+
|
143
|
+
@pkgdir ||= project.pkg
|
144
|
+
@gemspec ||= lookup_gemspec
|
145
|
+
|
146
|
+
@version = project.metadata.version
|
147
|
+
end
|
148
|
+
|
149
|
+
#
|
150
|
+
def package_files
|
151
|
+
Pathname.new(pkgdir).glob("*-#{version}.gem")
|
152
|
+
end
|
153
|
+
|
154
|
+
# Create gemspec if +autospec+ is +true+.
|
155
|
+
def prepackage
|
156
|
+
create_gemspec if autospec
|
157
|
+
end
|
158
|
+
|
159
|
+
# Create a gemspec file from project metadata.
|
160
|
+
def create_gemspec(file=nil)
|
161
|
+
file = gemspec if !file
|
162
|
+
require 'pom/gemspec'
|
163
|
+
yaml = project.to_gemspec.to_yaml
|
164
|
+
File.open(file, 'w') do |f|
|
165
|
+
f << yaml
|
166
|
+
end
|
167
|
+
status File.basename(file) + " updated."
|
168
|
+
return file
|
169
|
+
end
|
170
|
+
|
171
|
+
# Lookup gemspec file. If not found returns default path.
|
172
|
+
#
|
173
|
+
# Returns String of file path.
|
174
|
+
def lookup_gemspec
|
175
|
+
dot_gemspec = (project.root + '.gemspec').to_s
|
176
|
+
if File.exist?(dot_gemspec)
|
177
|
+
dot_gemspec.to_s
|
178
|
+
else
|
179
|
+
project.metadata.name + '.gemspec'
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
# Load gemspec file.
|
184
|
+
#
|
185
|
+
# Returns a ::Gem::Specification.
|
186
|
+
def load_gemspec
|
187
|
+
file = gemspec
|
188
|
+
if yaml?(file)
|
189
|
+
::Gem::Specification.from_yaml(File.new(file))
|
190
|
+
else
|
191
|
+
::Gem::Specification.load(file)
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
# If the gemspec a YAML gemspec?
|
196
|
+
def yaml?(file)
|
197
|
+
line = open(file) { |f| line = f.gets }
|
198
|
+
line.index "!ruby/object:Gem::Specification"
|
199
|
+
end
|
200
|
+
|
201
|
+
# TODO: Should we be rescuing this?
|
202
|
+
def initialize_requires
|
203
|
+
begin
|
204
|
+
require 'rubygems'
|
205
|
+
rescue LoadError
|
206
|
+
$stderr.puts "Could not load `rubygems'."
|
207
|
+
end
|
208
|
+
# can't do this b/c options not set yet
|
209
|
+
#require 'pom/gemspec' if autospec
|
210
|
+
end
|
211
|
+
|
212
|
+
## Require rubygems library
|
213
|
+
#def require_rubygems
|
214
|
+
# begin
|
215
|
+
# require 'rubygems/specification'
|
216
|
+
# ::Gem::manage_gems
|
217
|
+
# rescue LoadError
|
218
|
+
# raise LoadError, "RubyGems is not installed."
|
219
|
+
# end
|
220
|
+
#end
|
221
|
+
|
222
|
+
public
|
223
|
+
|
224
|
+
def self.man_page
|
225
|
+
File.dirname(__FILE__)+'/../man/detroit-gem.5'
|
226
|
+
end
|
227
|
+
|
228
|
+
end
|
229
|
+
|
230
|
+
end
|
data/man/detroit-gem.5
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
.\" generated with Ronn/v0.7.3
|
2
|
+
.\" http://github.com/rtomayko/ronn/tree/0.7.3
|
3
|
+
.
|
4
|
+
.TH "DETROIT\-GEM" "5" "October 2011" "" ""
|
5
|
+
.
|
6
|
+
.SH "NAME"
|
7
|
+
\fBdetroit\-gem\fR \- build gem package with detroit
|
8
|
+
.
|
9
|
+
.SH "DESCRIPTION"
|
10
|
+
The Gem plug\-in for Detroit utilizes the \fBgem\fR command line tool to build a \fB\.gem\fR package for a project during the standard \fBpackage\fR phase\.
|
11
|
+
.
|
12
|
+
.SH "OPTIONS"
|
13
|
+
The following options can be used in the Detroit assembly file for defining a Gem service\.
|
14
|
+
.
|
15
|
+
.IP "\(bu" 4
|
16
|
+
\fBgemspec\fR \- The \.gemspec file\. The default is the first \fB\.gemspec\fR file found\.
|
17
|
+
.
|
18
|
+
.IP "\(bu" 4
|
19
|
+
\fBautospec\fR \- Setting this option to \fBtrue\fR will have the plug\-in create a gemspec using a project\'s metadata\. Default is \fBfalse\fR\.
|
20
|
+
.
|
21
|
+
.IP "\(bu" 4
|
22
|
+
\fBpkgdir\fR \- Directory to save generated gem file\. The default is \fBpkg/\fR\.
|
23
|
+
.
|
24
|
+
.IP "\(bu" 4
|
25
|
+
\fBinstall\fR \- Should the gem be installed after being generated? Default is \fBfalse\fR\.
|
26
|
+
.
|
27
|
+
.IP "" 0
|
28
|
+
.
|
29
|
+
.SH "EXAMPLES"
|
30
|
+
Becuase the default options are all that is likely to be need the common exmaple something like:
|
31
|
+
.
|
32
|
+
.IP "" 4
|
33
|
+
.
|
34
|
+
.nf
|
35
|
+
|
36
|
+
gem:
|
37
|
+
active: true
|
38
|
+
.
|
39
|
+
.fi
|
40
|
+
.
|
41
|
+
.IP "" 0
|
42
|
+
.
|
43
|
+
.P
|
44
|
+
A fuller example might look something like this\.
|
45
|
+
.
|
46
|
+
.IP "" 4
|
47
|
+
.
|
48
|
+
.nf
|
49
|
+
|
50
|
+
gem:
|
51
|
+
gemspec: myapp\-extra\.gemspec
|
52
|
+
install: true
|
53
|
+
.
|
54
|
+
.fi
|
55
|
+
.
|
56
|
+
.IP "" 0
|
57
|
+
.
|
58
|
+
.P
|
59
|
+
The above examples use the YAML\-base assembly format\. Assembly files can also be Ruby\-based\. See Detroit documentation for more details\.
|
60
|
+
.
|
61
|
+
.SH "RESOURCES"
|
62
|
+
For more information:
|
63
|
+
.
|
64
|
+
.IP "\(bu" 4
|
65
|
+
API Documentation \fIhttp://rubydoc\.info/gems/detroit\-rubygems\fR
|
66
|
+
.
|
67
|
+
.IP "\(bu" 4
|
68
|
+
Development Site \fIhttp://github\.com/detroit/detroit\-rubygems\fR
|
69
|
+
.
|
70
|
+
.IP "" 0
|
71
|
+
.
|
72
|
+
.SH "COPYRIGHT"
|
73
|
+
Copyright (c) 2010 Thomas Sawyer, Rubyworks
|
74
|
+
.
|
75
|
+
.P
|
76
|
+
Detroit RubyGems is distributable in accordance with the GPLv3 license\.
|
77
|
+
.
|
78
|
+
.SH "SEE ALSO"
|
79
|
+
dnote(1), gem(1)
|
@@ -0,0 +1,147 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta http-equiv='content-type' value='text/html;charset=utf8'>
|
5
|
+
<meta name='generator' value='Ronn/v0.7.3 (http://github.com/rtomayko/ronn/tree/0.7.3)'>
|
6
|
+
<title>detroit-gem(5) - build gem package with detroit</title>
|
7
|
+
<style type='text/css' media='all'>
|
8
|
+
/* style: man */
|
9
|
+
body#manpage {margin:0}
|
10
|
+
.mp {max-width:100ex;padding:0 9ex 1ex 4ex}
|
11
|
+
.mp p,.mp pre,.mp ul,.mp ol,.mp dl {margin:0 0 20px 0}
|
12
|
+
.mp h2 {margin:10px 0 0 0}
|
13
|
+
.mp > p,.mp > pre,.mp > ul,.mp > ol,.mp > dl {margin-left:8ex}
|
14
|
+
.mp h3 {margin:0 0 0 4ex}
|
15
|
+
.mp dt {margin:0;clear:left}
|
16
|
+
.mp dt.flush {float:left;width:8ex}
|
17
|
+
.mp dd {margin:0 0 0 9ex}
|
18
|
+
.mp h1,.mp h2,.mp h3,.mp h4 {clear:left}
|
19
|
+
.mp pre {margin-bottom:20px}
|
20
|
+
.mp pre+h2,.mp pre+h3 {margin-top:22px}
|
21
|
+
.mp h2+pre,.mp h3+pre {margin-top:5px}
|
22
|
+
.mp img {display:block;margin:auto}
|
23
|
+
.mp h1.man-title {display:none}
|
24
|
+
.mp,.mp code,.mp pre,.mp tt,.mp kbd,.mp samp,.mp h3,.mp h4 {font-family:monospace;font-size:14px;line-height:1.42857142857143}
|
25
|
+
.mp h2 {font-size:16px;line-height:1.25}
|
26
|
+
.mp h1 {font-size:20px;line-height:2}
|
27
|
+
.mp {text-align:justify;background:#fff}
|
28
|
+
.mp,.mp code,.mp pre,.mp pre code,.mp tt,.mp kbd,.mp samp {color:#131211}
|
29
|
+
.mp h1,.mp h2,.mp h3,.mp h4 {color:#030201}
|
30
|
+
.mp u {text-decoration:underline}
|
31
|
+
.mp code,.mp strong,.mp b {font-weight:bold;color:#131211}
|
32
|
+
.mp em,.mp var {font-style:italic;color:#232221;text-decoration:none}
|
33
|
+
.mp a,.mp a:link,.mp a:hover,.mp a code,.mp a pre,.mp a tt,.mp a kbd,.mp a samp {color:#0000ff}
|
34
|
+
.mp b.man-ref {font-weight:normal;color:#434241}
|
35
|
+
.mp pre {padding:0 4ex}
|
36
|
+
.mp pre code {font-weight:normal;color:#434241}
|
37
|
+
.mp h2+pre,h3+pre {padding-left:0}
|
38
|
+
ol.man-decor,ol.man-decor li {margin:3px 0 10px 0;padding:0;float:left;width:33%;list-style-type:none;text-transform:uppercase;color:#999;letter-spacing:1px}
|
39
|
+
ol.man-decor {width:100%}
|
40
|
+
ol.man-decor li.tl {text-align:left}
|
41
|
+
ol.man-decor li.tc {text-align:center;letter-spacing:4px}
|
42
|
+
ol.man-decor li.tr {text-align:right;float:right}
|
43
|
+
</style>
|
44
|
+
</head>
|
45
|
+
<!--
|
46
|
+
The following styles are deprecated and will be removed at some point:
|
47
|
+
div#man, div#man ol.man, div#man ol.head, div#man ol.man.
|
48
|
+
|
49
|
+
The .man-page, .man-decor, .man-head, .man-foot, .man-title, and
|
50
|
+
.man-navigation should be used instead.
|
51
|
+
-->
|
52
|
+
<body id='manpage'>
|
53
|
+
<div class='mp' id='man'>
|
54
|
+
|
55
|
+
<div class='man-navigation' style='display:none'>
|
56
|
+
<a href="#NAME">NAME</a>
|
57
|
+
<a href="#DESCRIPTION">DESCRIPTION</a>
|
58
|
+
<a href="#OPTIONS">OPTIONS</a>
|
59
|
+
<a href="#EXAMPLES">EXAMPLES</a>
|
60
|
+
<a href="#RESOURCES">RESOURCES</a>
|
61
|
+
<a href="#COPYRIGHT">COPYRIGHT</a>
|
62
|
+
<a href="#SEE-ALSO">SEE ALSO</a>
|
63
|
+
</div>
|
64
|
+
|
65
|
+
<ol class='man-decor man-head man head'>
|
66
|
+
<li class='tl'>detroit-gem(5)</li>
|
67
|
+
<li class='tc'></li>
|
68
|
+
<li class='tr'>detroit-gem(5)</li>
|
69
|
+
</ol>
|
70
|
+
|
71
|
+
<h2 id="NAME">NAME</h2>
|
72
|
+
<p class="man-name">
|
73
|
+
<code>detroit-gem</code> - <span class="man-whatis">build gem package with detroit</span>
|
74
|
+
</p>
|
75
|
+
|
76
|
+
<h2 id="DESCRIPTION">DESCRIPTION</h2>
|
77
|
+
|
78
|
+
<p>The Gem plug-in for Detroit utilizes the <code>gem</code> command line tool
|
79
|
+
to build a <code>.gem</code> package for a project during the standard <code>package</code>
|
80
|
+
phase.</p>
|
81
|
+
|
82
|
+
<h2 id="OPTIONS">OPTIONS</h2>
|
83
|
+
|
84
|
+
<p>The following options can be used in the Detroit assembly file
|
85
|
+
for defining a Gem service.</p>
|
86
|
+
|
87
|
+
<ul>
|
88
|
+
<li><p><code>gemspec</code> - The .gemspec file. The default is the first <code>.gemspec</code>
|
89
|
+
file found.</p></li>
|
90
|
+
<li><p><code>autospec</code> - Setting this option to <code>true</code> will have the plug-in
|
91
|
+
create a gemspec using a project's metadata. Default is <code>false</code>.</p></li>
|
92
|
+
<li><p><code>pkgdir</code> - Directory to save generated gem file. The default is <code>pkg/</code>.</p></li>
|
93
|
+
<li><p><code>install</code> - Should the gem be installed after being generated? Default
|
94
|
+
is <code>false</code>.</p></li>
|
95
|
+
</ul>
|
96
|
+
|
97
|
+
|
98
|
+
<h2 id="EXAMPLES">EXAMPLES</h2>
|
99
|
+
|
100
|
+
<p>Becuase the default options are all that is likely to be need the
|
101
|
+
common exmaple something like:</p>
|
102
|
+
|
103
|
+
<pre><code>gem:
|
104
|
+
active: true
|
105
|
+
</code></pre>
|
106
|
+
|
107
|
+
<p>A fuller example might look something like this.</p>
|
108
|
+
|
109
|
+
<pre><code> gem:
|
110
|
+
gemspec: myapp-extra.gemspec
|
111
|
+
install: true
|
112
|
+
</code></pre>
|
113
|
+
|
114
|
+
<p>The above examples use the YAML-base assembly format. Assembly
|
115
|
+
files can also be Ruby-based. See Detroit documentation for more
|
116
|
+
details.</p>
|
117
|
+
|
118
|
+
<h2 id="RESOURCES">RESOURCES</h2>
|
119
|
+
|
120
|
+
<p>For more information:</p>
|
121
|
+
|
122
|
+
<ul>
|
123
|
+
<li><p><a href="http://rubydoc.info/gems/detroit-rubygems">API Documentation</a></p></li>
|
124
|
+
<li><p><a href="http://github.com/detroit/detroit-rubygems">Development Site</a></p></li>
|
125
|
+
</ul>
|
126
|
+
|
127
|
+
|
128
|
+
<h2 id="COPYRIGHT">COPYRIGHT</h2>
|
129
|
+
|
130
|
+
<p>Copyright (c) 2010 Thomas Sawyer, Rubyworks</p>
|
131
|
+
|
132
|
+
<p>Detroit RubyGems is distributable in accordance with the GPLv3 license.</p>
|
133
|
+
|
134
|
+
<h2 id="SEE-ALSO">SEE ALSO</h2>
|
135
|
+
|
136
|
+
<p><span class="man-ref">dnote<span class="s">(1)</span></span>, <span class="man-ref">gem<span class="s">(1)</span></span></p>
|
137
|
+
|
138
|
+
|
139
|
+
<ol class='man-decor man-foot man foot'>
|
140
|
+
<li class='tl'></li>
|
141
|
+
<li class='tc'>October 2011</li>
|
142
|
+
<li class='tr'>detroit-gem(5)</li>
|
143
|
+
</ol>
|
144
|
+
|
145
|
+
</div>
|
146
|
+
</body>
|
147
|
+
</html>
|