linkparser 1.0.4 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,14 +1,27 @@
1
- #
2
- # Packaging Rake Tasks
3
- # $Id: packaging.rb 102 2009-05-23 21:40:00Z deveiant $
4
- #
1
+ #####################################################################
2
+ ### P A C K A G I N G T A S K S
3
+ #####################################################################
5
4
 
6
5
  require 'rbconfig'
7
- require 'rake/packagetask'
8
- require 'rake/gempackagetask'
6
+ require 'pathname'
7
+ require 'rubygems/package_task'
8
+
9
9
 
10
10
  include Config
11
11
 
12
+ ### Task: prerelease
13
+ desc "Append the package build number to package versions"
14
+ task :prerelease do
15
+ GEMSPEC.version.version << "pre#{PKG_BUILD}"
16
+ Rake::Task[:gem].clear
17
+
18
+ Gem::PackageTask.new( GEMSPEC ) do |pkg|
19
+ pkg.need_zip = true
20
+ pkg.need_tar = true
21
+ end
22
+ end
23
+
24
+
12
25
  ### Task: gem
13
26
  ### Task: package
14
27
  Rake::PackageTask.new( PKG_NAME, PKG_VERSION ) do |task|
@@ -21,35 +34,9 @@ end
21
34
  task :package => [:gem]
22
35
 
23
36
 
24
- ### Task: gem
25
- gempath = PKGDIR + GEM_FILE_NAME
26
-
27
- desc "Build a RubyGem package (#{GEM_FILE_NAME})"
28
- task :gem => gempath.to_s
29
- file gempath.to_s => [PKGDIR.to_s] + GEMSPEC.files do
30
- when_writing( "Creating GEM" ) do
31
- Gem::Builder.new( GEMSPEC ).build
32
- verbose( true ) do
33
- mv GEM_FILE_NAME, gempath
34
- end
35
- end
36
- end
37
-
38
- svnrev = get_svn_rev()
39
- prerelease_gem_file_name = "#{PKG_FILE_NAME}.#{svnrev}.gem"
40
- prerelease_gempath = PKGDIR + prerelease_gem_file_name
41
-
42
- desc "Build a pre-release RubyGem package"
43
- task :prerelease_gem => prerelease_gempath.to_s
44
- file prerelease_gempath.to_s => [PKGDIR.to_s] + GEMSPEC.files do
45
- when_writing( "Creating prerelease GEM" ) do
46
- gemspec = GEMSPEC.clone
47
- gemspec.version = Gem::Version.create( "%s.%d" % [GEMSPEC.version, svnrev] )
48
- Gem::Builder.new( gemspec ).build
49
- verbose( true ) do
50
- mv prerelease_gem_file_name, prerelease_gempath
51
- end
52
- end
37
+ Gem::PackageTask.new( GEMSPEC ) do |pkg|
38
+ pkg.need_zip = true
39
+ pkg.need_tar = true
53
40
  end
54
41
 
55
42
 
@@ -60,7 +47,7 @@ task :install => "spec:quiet" do
60
47
  sitelib = Pathname.new( CONFIG['sitelibdir'] )
61
48
  sitearch = Pathname.new( CONFIG['sitearchdir'] )
62
49
  Dir.chdir( LIBDIR ) do
63
- LIB_FILES.each do |libfile|
50
+ LIB_FILES.collect {|path| Pathname(path) }.each do |libfile|
64
51
  relpath = libfile.relative_path_from( LIBDIR )
65
52
  target = sitelib + relpath
66
53
  FileUtils.mkpath target.dirname,
@@ -101,7 +88,7 @@ task :uninstall do
101
88
  sitearch = Pathname.new( CONFIG['sitearchdir'] )
102
89
 
103
90
  Dir.chdir( LIBDIR ) do
104
- LIB_FILES.each do |libfile|
91
+ LIB_FILES.collect {|path| Pathname(path) }.each do |libfile|
105
92
  relpath = libfile.relative_path_from( LIBDIR )
106
93
  target = sitelib + relpath
107
94
  FileUtils.rm_f target, :verbose => true, :noop => $dryrun
@@ -131,3 +118,12 @@ end
131
118
 
132
119
 
133
120
 
121
+ desc "Add development depdendencies to the gemspec -- this is meant to be chained " +
122
+ "together with :gem"
123
+ task :include_dev_dependencies do
124
+ DEVELOPMENT_DEPENDENCIES.each do |name, version|
125
+ version = '>= 0' if version.length.zero?
126
+ GEMSPEC.add_development_dependency( name, version )
127
+ end
128
+ end
129
+
@@ -5,6 +5,8 @@
5
5
  RELEASE_NOTES_FILE = 'release.notes'
6
6
  RELEASE_ANNOUNCE_FILE = 'release.ann'
7
7
 
8
+ GEM_PUBHOST = '' unless defined?( GEM_PUBHOST )
9
+
8
10
  require 'net/smtp'
9
11
  require 'net/protocol'
10
12
  require 'openssl'
@@ -13,6 +15,7 @@ $publish_privately = false
13
15
 
14
16
  ### Add SSL to Net::SMTP
15
17
  class Net::SMTP
18
+
16
19
  def ssl_start( helo='localhost.localdomain', user=nil, secret=nil, authtype=nil )
17
20
  if block_given?
18
21
  begin
@@ -34,7 +37,13 @@ class Net::SMTP
34
37
 
35
38
  def do_ssl_start( helodomain, user, secret, authtype )
36
39
  raise IOError, 'SMTP session already started' if @started
37
- check_auth_args user, secret, authtype if user or secret
40
+ if user or secret
41
+ if self.method( :check_auth_args ).arity == 3
42
+ check_auth_args( user, secret, authtype )
43
+ else
44
+ check_auth_args( user, secret )
45
+ end
46
+ end
38
47
 
39
48
  # Open the connection
40
49
  @debug_output << "opening connection to #{@address}...\n" if @debug_output
@@ -85,9 +94,11 @@ begin
85
94
  require 'tmail'
86
95
  require 'net/smtp'
87
96
  require 'etc'
88
- require 'rubyforge'
89
97
  require 'socket'
90
98
  require 'text/format'
99
+ require 'rubygems/gemcutter_utilities'
100
+
101
+ include Gem::GemcutterUtilities
91
102
 
92
103
  ### Generate a valid RFC822 message-id
93
104
  def gen_message_id
@@ -99,8 +110,50 @@ begin
99
110
  end
100
111
 
101
112
 
113
+ ### Fetch the rubygems API token if it hasn't been already.
114
+ def sign_in_to_rubygems
115
+ return if Gem.configuration.rubygems_api_key
116
+
117
+ log "Enter your RubyGems.org credentials."
118
+
119
+ email = prompt " Email: "
120
+ password = prompt_for_password( "Password: " )
121
+
122
+ response = rubygems_api_request( :get, "api/v1/api_key" ) do |request|
123
+ request.basic_auth( email, password )
124
+ end
125
+
126
+ with_response( response ) do |resp|
127
+ log "Signed in."
128
+ Gem.configuration.rubygems_api_key = resp.body
129
+ end
130
+ end
131
+
132
+
133
+ ### Push the gem at the specified +path+ to the rubygems server at +gemhost+.
134
+ def push_gem( path, gemhost )
135
+ ENV['RUBYGEMS_HOST'] = "http://#{gemhost}"
136
+
137
+ sign_in_to_rubygems()
138
+
139
+ response = rubygems_api_request( :post, "api/v1/gems" ) do |request|
140
+ request.body = Gem.read_binary( path )
141
+ request.add_field "Content-Length", request.body.size
142
+ request.add_field "Content-Type", "application/octet-stream"
143
+ request.add_field "Authorization", Gem.configuration.rubygems_api_key
144
+ end
145
+
146
+ case response
147
+ when Net::HTTPSuccess
148
+ log( response.body )
149
+ else
150
+ fail( response.body )
151
+ end
152
+ end
153
+
154
+
102
155
  namespace :release do
103
- task :default => [ 'svn:release', :upload, :publish, :announce ]
156
+ task :default => [ :prep_release, :upload, :publish, :announce ]
104
157
 
105
158
  desc "Re-publish the release with the current version number"
106
159
  task :rerelease => [ :upload, :publish, :announce ]
@@ -116,183 +169,149 @@ begin
116
169
  desc "Generate the release notes"
117
170
  task :notes => [RELEASE_NOTES_FILE]
118
171
  file RELEASE_NOTES_FILE do |task|
119
- last_rel_tag = get_latest_release_tag() or
120
- fail ">>> No releases tagged! Try running 'rake svn:release' first"
121
- trace "Last release tag is: %p" % [ last_rel_tag ]
122
- start = get_last_changed_rev( last_rel_tag ) || 1
123
- trace "Starting rev is: %p" % [ start ]
124
- log_output = make_svn_log( '.', start, 'HEAD' )
172
+ last_tag = MercurialHelpers.get_tags.grep( /\d+\.\d+\.\d+/ ).
173
+ collect {|ver| vvec(ver) }.sort.last.unpack( 'N*' ).join('.')
125
174
 
126
175
  File.open( task.name, File::WRONLY|File::TRUNC|File::CREAT ) do |fh|
127
- fh.print( log_output )
176
+ fh.puts "Release Notes for #{PKG_VERSION}",
177
+ "--------------------------------", '', ''
128
178
  end
129
179
 
130
180
  edit task.name
131
181
  end
132
182
  CLOBBER.include( RELEASE_NOTES_FILE )
133
183
 
184
+ # Only define upload tasks if there's an upload host
185
+ if PROJECT_HOST.empty?
186
+ task :no_upload_host do
187
+ log "Skipping upload: no upload host."
188
+ end
189
+ task :upload => :no_upload_host
190
+ task :upload_docs => :no_upload_host
191
+ task :upload_packages => :no_upload_host
192
+ else
193
+ desc "Upload project documentation and packages to #{PROJECT_HOST}"
194
+ task :upload => [ :upload_docs, :upload_packages ]
195
+ task :project => :upload # the old name
196
+
197
+ desc "Publish the project docs to #{PROJECT_HOST}"
198
+ task :upload_docs => [ :apidocs ] do
199
+ when_writing( "Publishing docs to #{PROJECT_SCPDOCURL}" ) do
200
+ log "Uploading API documentation to %s:%s" % [ PROJECT_HOST, PROJECT_DOCDIR ]
201
+ run 'ssh', PROJECT_HOST, "rm -rf #{PROJECT_DOCDIR}"
202
+ run 'scp', '-qCr', API_DOCSDIR, PROJECT_SCPDOCURL
203
+ end
204
+ end
134
205
 
135
- desc "Upload project documentation and packages to #{PROJECT_HOST}"
136
- task :upload => [ :upload_docs, :upload_packages ]
137
- task :project => :upload # the old name
138
-
139
- desc "Publish the project docs to #{PROJECT_HOST}"
140
- task :upload_docs => [ :rdoc ] do
141
- when_writing( "Publishing docs to #{PROJECT_SCPDOCURL}" ) do
142
- log "Uploading API documentation to %s:%s" % [ PROJECT_HOST, PROJECT_DOCDIR ]
143
- run 'ssh', PROJECT_HOST, "rm -rf #{PROJECT_DOCDIR}"
144
- run 'scp', '-qCr', RDOCDIR, PROJECT_SCPDOCURL
206
+ desc "Publish the project packages to #{PROJECT_HOST}"
207
+ task :upload_packages => [ :package ] do
208
+ when_writing( "Uploading packages") do
209
+ pkgs = Pathname.glob( PKGDIR + "#{PKG_FILE_NAME}.{gem,tar.gz,tar.bz2,zip}" )
210
+ log "Uploading %d packages to #{PROJECT_SCPPUBURL}" % [ pkgs.length ]
211
+ pkgs.each do |pkgfile|
212
+ run 'scp', '-qC', pkgfile, PROJECT_SCPPUBURL
213
+ end
214
+ end
145
215
  end
146
216
  end
147
217
 
148
- desc "Publish the project packages to #{PROJECT_HOST}"
149
- task :upload_packages => [ :package ] do
150
- when_writing( "Uploading packages") do
151
- pkgs = Pathname.glob( PKGDIR + "#{PKG_FILE_NAME}.{gem,tar.gz,tar.bz2,zip}" )
152
- log "Uploading %d packages to #{PROJECT_SCPPUBURL}" % [ pkgs.length ]
153
- pkgs.each do |pkgfile|
154
- run 'scp', '-qC', pkgfile, PROJECT_SCPPUBURL
155
- end
156
- end
157
- end
218
+ # Only define the announcement tasks if there are addresses to announce to
219
+ if RELEASE_ANNOUNCE_ADDRESSES.empty?
220
+ task :no_announce_addresses do
221
+ log "Skipping announcement: no announce addresses"
222
+ end
223
+ task :announce => :no_announce_addresses
158
224
 
225
+ else
226
+ file RELEASE_ANNOUNCE_FILE => [RELEASE_NOTES_FILE] do |task|
227
+ relnotes = File.read( RELEASE_NOTES_FILE )
228
+ announce_body = %{
159
229
 
160
- file RELEASE_ANNOUNCE_FILE => [RELEASE_NOTES_FILE] do |task|
161
- relnotes = File.read( RELEASE_NOTES_FILE )
162
- announce_body = %{
230
+ Version #{PKG_VERSION} of #{PKG_NAME} has been released.
163
231
 
164
- Version #{PKG_VERSION} of #{PKG_NAME} has been released.
232
+ #{Text::Format.new(:first_indent => 0).format_one_paragraph(GEMSPEC.description)}
165
233
 
166
- #{Text::Format.new(:first_indent => 0).format_one_paragraph(GEMSPEC.description)}
234
+ == Project Page
167
235
 
168
- == Project Page
236
+ #{GEMSPEC.homepage}
169
237
 
170
- #{GEMSPEC.homepage}
238
+ == Installation
171
239
 
172
- == Installation
240
+ $ sudo gem install #{GEMSPEC.name}
173
241
 
174
- Via gems:
242
+ == Changes
243
+ #{relnotes}
244
+ }.gsub( /^\t+/, '' )
175
245
 
176
- $ sudo gem install #{GEMSPEC.name}
246
+ File.open( task.name, File::WRONLY|File::TRUNC|File::CREAT ) do |fh|
247
+ fh.print( announce_body )
248
+ end
177
249
 
178
- or from source:
250
+ edit task.name
251
+ end
252
+ CLOBBER.include( RELEASE_ANNOUNCE_FILE )
179
253
 
180
- $ wget http://deveiate.org/code/#{PKG_FILE_NAME}.tar.gz
181
- $ tar -xzvf #{PKG_FILE_NAME}.tar.gz
182
- $ cd #{PKG_FILE_NAME}
183
- $ sudo rake install
184
254
 
185
- == Changes
186
- #{relnotes}
187
- }.gsub( /^\t+/, '' )
255
+ desc 'Send out a release announcement'
256
+ task :announce => [RELEASE_ANNOUNCE_FILE] do
257
+ email = TMail::Mail.new
188
258
 
189
- File.open( task.name, File::WRONLY|File::TRUNC|File::CREAT ) do |fh|
190
- fh.print( announce_body )
191
- end
259
+ if $publish_privately || RELEASE_ANNOUNCE_ADDRESSES.empty?
260
+ trace "Sending private announce mail"
261
+ email.to = 'rubymage@gmail.com'
262
+ else
263
+ trace "Sending public announce mail"
264
+ email.to = RELEASE_ANNOUNCE_ADDRESSES
265
+ email.bcc = 'rubymage@gmail.com'
266
+ end
192
267
 
193
- edit task.name
194
- end
195
- CLOBBER.include( RELEASE_ANNOUNCE_FILE )
268
+ from = prompt_with_default( "Send announcement as:",
269
+ 'Michael Granger <ged@FaerieMUD.org>' ) or fail
196
270
 
271
+ email.from = from
272
+ email.subject = "[ANN] #{PKG_NAME} #{PKG_VERSION}"
273
+ email.body = File.read( RELEASE_ANNOUNCE_FILE )
274
+ email.date = Time.new
197
275
 
198
- desc 'Send out a release announcement'
199
- task :announce => [RELEASE_ANNOUNCE_FILE] do
200
- email = TMail::Mail.new
201
- if $publish_privately
202
- trace "Sending private announce mail"
203
- email.to = 'rubymage@gmail.com'
204
- else
205
- trace "Sending public announce mail"
206
- email.to = 'Ruby-Talk List <ruby-talk@ruby-lang.org>'
207
- email.bcc = 'rubymage@gmail.com'
208
- end
209
- email.from = GEMSPEC.email
210
- email.subject = "[ANN] #{PKG_NAME} #{PKG_VERSION}"
211
- email.body = File.read( RELEASE_ANNOUNCE_FILE )
212
- email.date = Time.new
213
-
214
- email.message_id = gen_message_id()
215
-
216
- log "About to send the following email:"
217
- puts '---',
218
- email.to_s,
219
- '---'
220
-
221
- ask_for_confirmation( "Will send via #{SMTP_HOST}." ) do
222
- pwent = Etc.getpwuid( Process.euid )
223
- curuser = pwent ? pwent.name : 'unknown'
224
- username = prompt_with_default( "SMTP user", curuser )
225
- password = prompt_for_password()
226
-
227
- trace "Creating SMTP connection to #{SMTP_HOST}:#{SMTP_PORT}"
228
- smtp = Net::SMTP.new( SMTP_HOST, SMTP_PORT )
229
- smtp.set_debug_output( $stdout )
230
- smtp.esmtp = true
231
-
232
- trace "connecting..."
233
- smtp.ssl_start( Socket.gethostname, username, password, :plain ) do |smtp|
234
- trace "sending message..."
235
- smtp.send_message( email.to_s, email.from, email.to )
236
- end
237
- trace "done."
238
- end
239
- end
276
+ email.message_id = gen_message_id()
240
277
 
278
+ log "About to send the following email:"
279
+ puts '---',
280
+ email.to_s,
281
+ '---'
241
282
 
242
- desc 'Publish the new release to RubyForge'
243
- task :publish => [:clean, :package, :notes] do |task|
244
- project = GEMSPEC.rubyforge_project
283
+ ask_for_confirmation( "Will send via #{SMTP_HOST}." ) do
284
+ pwent = Etc.getpwuid( Process.euid )
285
+ curuser = pwent ? pwent.name : 'unknown'
286
+ username = prompt_with_default( "SMTP user", curuser )
287
+ password = prompt_for_password()
245
288
 
246
- if $publish_privately
247
- log "Skipping push of release files to RubyForge"
248
- else
249
- rf = RubyForge.new
250
- log "Loading RubyForge config"
251
- rf.configure
252
-
253
- group_id = rf.autoconfig['group_ids'][RUBYFORGE_GROUP] or
254
- fail "Your configuration doesn't have a group id for '#{RUBYFORGE_GROUP}'"
255
-
256
- # If this project doesn't yet exist, create it
257
- unless rf.autoconfig['package_ids'].key?( project )
258
- ask_for_confirmation( "Package '#{project}' doesn't exist on RubyForge. Create it?" ) do
259
- log "Creating new package '#{project}'"
260
- rf.create_package( group_id, project )
289
+ trace "Creating SMTP connection to #{SMTP_HOST}:#{SMTP_PORT}"
290
+ smtp = Net::SMTP.new( SMTP_HOST, SMTP_PORT )
291
+ smtp.set_debug_output( $stdout )
292
+ smtp.esmtp = true
293
+
294
+ trace "connecting..."
295
+ smtp.ssl_start( Socket.gethostname, username, password, :plain ) do |smtp|
296
+ trace "sending message..."
297
+ smtp.send_message( email.to_s, email.from, email.to )
261
298
  end
299
+ trace "done."
262
300
  end
301
+ end
302
+ end
263
303
 
264
- package_id = rf.autoconfig['package_ids'][ project ]
265
-
266
- # Make sure this release doesn't already exist
267
- releases = rf.autoconfig['release_ids']
268
- if releases.key?( GEMSPEC.name ) && releases[ GEMSPEC.name ].key?( PKG_VERSION )
269
- log "Rubyforge seems to already have #{ PKG_FILE_NAME }"
270
- else
271
- config = rf.userconfig or
272
- fail "You apparently haven't set up your RubyForge credentials on this machine."
273
- config['release_notes'] = GEMSPEC.description
274
- config['release_changes'] = File.read( RELEASE_NOTES_FILE )
275
-
276
- files = FileList[ PKGDIR + GEM_FILE_NAME ]
277
- files.include PKGDIR + "#{PKG_FILE_NAME}.tar.gz"
278
- files.include PKGDIR + "#{PKG_FILE_NAME}.tar.bz2"
279
- files.include PKGDIR + "#{PKG_FILE_NAME}.zip"
280
-
281
- log "Releasing #{PKG_FILE_NAME}"
282
- when_writing do
283
- log "Publishing to RubyForge: \n",
284
- "\tproject: #{RUBYFORGE_GROUP}\n",
285
- "\tpackage: #{PKG_NAME.downcase}\n",
286
- "\tpackage version: #{PKG_VERSION}\n",
287
- "\tfiles: " + files.collect {|f| f.to_s }.join(', ') + "\n"
288
-
289
- ask_for_confirmation( "Publish to RubyForge?" ) do
290
- log 'Logging in...'
291
- rf.login
292
- log "Adding the new release to the '#{project}' project"
293
- rf.add_release( group_id, package_id, PKG_VERSION, *files )
294
- end
295
- end
304
+ if GEM_PUBHOST.empty?
305
+ task :no_gem_host do
306
+ log "Skipping gem push: no gem publication host."
307
+ end
308
+ task :publish => :no_gem_host
309
+ else
310
+ desc 'Publish the new gem to #{GEM_PUBHOST}'
311
+ task :publish => [:clean, :gem, :notes] do |task|
312
+ ask_for_confirmation( "Publish #{GEM_FILE_NAME} to #{GEM_PUBHOST}?", false ) do
313
+ gempath = PKGDIR + GEM_FILE_NAME
314
+ push_gem( gempath, GEM_PUBHOST )
296
315
  end
297
316
  end
298
317
  end
@@ -309,6 +328,7 @@ rescue LoadError => err
309
328
  end
310
329
 
311
330
  task :release => :no_release_tasks
331
+ task "release:rerelease" => :no_release_tasks
312
332
  task "release:announce" => :no_release_tasks
313
333
  task "release:publish" => :no_release_tasks
314
334
  task "release:notes" => :no_release_tasks