bones 1.0.0
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 +4 -0
- data/Manifest.txt +30 -0
- data/README.txt +157 -0
- data/Rakefile +26 -0
- data/bin/bones +7 -0
- data/data/History.txt.erb +4 -0
- data/data/Manifest.txt +0 -0
- data/data/README.txt.erb +48 -0
- data/data/Rakefile.erb +23 -0
- data/data/bin/NAME.erb +8 -0
- data/data/lib/NAME.rb.erb +7 -0
- data/data/spec/NAME_spec.rb +0 -0
- data/data/tasks/annotations.rake +29 -0
- data/data/tasks/doc.rake +47 -0
- data/data/tasks/gem.rake +87 -0
- data/data/tasks/manifest.rake +41 -0
- data/data/tasks/rubyforge.rake +57 -0
- data/data/tasks/setup.rb +129 -0
- data/data/tasks/spec.rake +37 -0
- data/data/tasks/test.rake +35 -0
- data/data/test/test_NAME.rb +0 -0
- data/lib/bones.rb +177 -0
- data/tasks/annotations.rake +29 -0
- data/tasks/doc.rake +47 -0
- data/tasks/gem.rake +87 -0
- data/tasks/manifest.rake +41 -0
- data/tasks/rubyforge.rake +57 -0
- data/tasks/setup.rb +129 -0
- data/tasks/spec.rake +37 -0
- data/tasks/test.rake +35 -0
- metadata +85 -0
@@ -0,0 +1,41 @@
|
|
1
|
+
# $Id$
|
2
|
+
|
3
|
+
require 'find'
|
4
|
+
|
5
|
+
namespace :manifest do
|
6
|
+
|
7
|
+
desc 'Verify the manfiest'
|
8
|
+
task :check do
|
9
|
+
fn = 'Manifest.tmp'
|
10
|
+
files = []
|
11
|
+
exclude = Regexp.new(PROJ.exclude.join('|'))
|
12
|
+
Find.find '.' do |path|
|
13
|
+
path.sub! %r/^(\.\/|\/)/o, ''
|
14
|
+
next unless test ?f, path
|
15
|
+
next if path =~ exclude
|
16
|
+
files << path
|
17
|
+
end
|
18
|
+
|
19
|
+
File.open(fn, 'w') {|fp| fp.puts files.sort}
|
20
|
+
system "#{DIFF} -du Manifest.txt #{fn}"
|
21
|
+
rm fn rescue nil
|
22
|
+
end
|
23
|
+
|
24
|
+
desc 'Create a new manifest'
|
25
|
+
task :create do
|
26
|
+
fn = 'Manifest.txt'
|
27
|
+
files = []
|
28
|
+
exclude = Regexp.new(PROJ.exclude.join('|'))
|
29
|
+
Find.find '.' do |path|
|
30
|
+
path.sub! %r/^(\.\/|\/)/o, ''
|
31
|
+
next unless test ?f, path
|
32
|
+
next if path =~ exclude
|
33
|
+
files << path
|
34
|
+
end
|
35
|
+
|
36
|
+
files << fn unless test ?f, fn
|
37
|
+
File.open(fn, 'w') {|fp| fp.puts files.sort}
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# EOF
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# $Id$
|
2
|
+
|
3
|
+
if PROJ.rubyforge_name && HAVE_RUBYFORGE
|
4
|
+
|
5
|
+
require 'rubyforge'
|
6
|
+
require 'rake/contrib/sshpublisher'
|
7
|
+
|
8
|
+
namespace :gem do
|
9
|
+
desc 'Package and upload to RubyForge'
|
10
|
+
task :release => [:clobber, :package] do |t|
|
11
|
+
v = ENV['VERSION'] or abort 'Must supply VERSION=x.y.z'
|
12
|
+
abort "Versions don't match #{v} vs #{PROJ.version}" if v != PROJ.version
|
13
|
+
pkg = "pkg/#{PROJ.spec.full_name}"
|
14
|
+
|
15
|
+
if $DEBUG then
|
16
|
+
puts "release_id = rf.add_release #{PROJ.rubyforge_name.inspect}, #{PROJ.name.inspect}, #{PROJ.version.inspect}, \"#{pkg}.tgz\""
|
17
|
+
puts "rf.add_file #{PROJ.rubyforge_name.inspect}, #{PROJ.name.inspect}, release_id, \"#{pkg}.gem\""
|
18
|
+
end
|
19
|
+
|
20
|
+
rf = RubyForge.new
|
21
|
+
puts 'Logging in'
|
22
|
+
rf.login
|
23
|
+
|
24
|
+
c = rf.userconfig
|
25
|
+
c['release_notes'] = PROJ.description if PROJ.description
|
26
|
+
c['release_changes'] = PROJ.changes if PROJ.changes
|
27
|
+
c['preformatted'] = true
|
28
|
+
|
29
|
+
files = [(PROJ.need_tar ? "#{pkg}.tgz" : nil),
|
30
|
+
(PROJ.need_zip ? "#{pkg}.zip" : nil),
|
31
|
+
"#{pkg}.gem"].compact
|
32
|
+
|
33
|
+
puts "Releasing #{PROJ.name} v. #{PROJ.version}"
|
34
|
+
rf.add_release PROJ.rubyforge_name, PROJ.name, PROJ.version, *files
|
35
|
+
end
|
36
|
+
end # namespace :gem
|
37
|
+
|
38
|
+
|
39
|
+
namespace :doc do
|
40
|
+
desc "Publish RDoc to RubyForge"
|
41
|
+
task :release => %w(doc:clobber_rdoc doc:rdoc) do
|
42
|
+
config = YAML.load(
|
43
|
+
File.read(File.expand_path('~/.rubyforge/user-config.yml'))
|
44
|
+
)
|
45
|
+
|
46
|
+
host = "#{config['username']}@rubyforge.org"
|
47
|
+
remote_dir = "/var/www/gforge-projects/#{PROJ.rubyforge_name}/"
|
48
|
+
remote_dir << PROJ.rdoc_remote_dir || PROJ.name
|
49
|
+
local_dir = PROJ.rdoc_dir
|
50
|
+
|
51
|
+
Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
|
52
|
+
end
|
53
|
+
end # namespace :doc
|
54
|
+
|
55
|
+
end # if HAVE_RUBYFORGE
|
56
|
+
|
57
|
+
# EOF
|
data/data/tasks/setup.rb
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
# $Id$
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'rake'
|
5
|
+
require 'fileutils'
|
6
|
+
require 'ostruct'
|
7
|
+
|
8
|
+
PROJ = OpenStruct.new
|
9
|
+
|
10
|
+
PROJ.name = nil
|
11
|
+
PROJ.summary = nil
|
12
|
+
PROJ.description = nil
|
13
|
+
PROJ.changes = nil
|
14
|
+
PROJ.authors = nil
|
15
|
+
PROJ.email = nil
|
16
|
+
PROJ.url = nil
|
17
|
+
PROJ.version = ENV['VERSION'] || '0.0.0'
|
18
|
+
PROJ.rubyforge_name = nil
|
19
|
+
PROJ.exclude = %w(tmp$ bak$ ~$ CVS \.svn)
|
20
|
+
|
21
|
+
# Rspec
|
22
|
+
PROJ.specs = FileList['spec/**/*_spec.rb']
|
23
|
+
PROJ.spec_opts = []
|
24
|
+
|
25
|
+
# Test::Unit
|
26
|
+
PROJ.tests = FileList['test/**/test_*.rb']
|
27
|
+
PROJ.test_file = 'test/all.rb'
|
28
|
+
PROJ.test_opts = []
|
29
|
+
|
30
|
+
# Rcov
|
31
|
+
PROJ.rcov_opts = ['--sort', 'coverage', '-T']
|
32
|
+
|
33
|
+
# Rdoc
|
34
|
+
PROJ.rdoc_opts = []
|
35
|
+
PROJ.rdoc_include = %w(^lib ^bin ^ext txt$)
|
36
|
+
PROJ.rdoc_exclude = %w(extconf\.rb$ ^Manifest\.txt$)
|
37
|
+
PROJ.rdoc_main = 'README.txt'
|
38
|
+
PROJ.rdoc_dir = 'doc'
|
39
|
+
PROJ.rdoc_remote_dir = nil
|
40
|
+
|
41
|
+
# Extensions
|
42
|
+
PROJ.extensions = FileList['ext/**/extconf.rb']
|
43
|
+
PROJ.ruby_opts = %w(-w)
|
44
|
+
PROJ.libs = []
|
45
|
+
%w(lib ext).each {|dir| PROJ.libs << dir if test ?d, dir}
|
46
|
+
|
47
|
+
# Gem Packaging
|
48
|
+
PROJ.files =
|
49
|
+
if test ?f, 'Manifest.txt'
|
50
|
+
files = File.readlines('Manifest.txt').map {|fn| fn.chomp.strip}
|
51
|
+
files.delete ''
|
52
|
+
files
|
53
|
+
else [] end
|
54
|
+
PROJ.executables = PROJ.files.find_all {|fn| fn =~ %r/^bin/}
|
55
|
+
PROJ.dependencies = []
|
56
|
+
PROJ.need_tar = true
|
57
|
+
PROJ.need_zip = false
|
58
|
+
|
59
|
+
# Load the other rake files in the tasks folder
|
60
|
+
Dir.glob('tasks/*.rake').sort.each {|fn| import fn}
|
61
|
+
|
62
|
+
# Setup some constants
|
63
|
+
WIN32 = %r/win32/ =~ RUBY_PLATFORM unless defined? WIN32
|
64
|
+
|
65
|
+
DEV_NULL = WIN32 ? 'NUL:' : '/dev/null'
|
66
|
+
|
67
|
+
def quiet( &block )
|
68
|
+
io = [STDOUT.dup, STDERR.dup]
|
69
|
+
STDOUT.reopen DEV_NULL
|
70
|
+
STDERR.reopen DEV_NULL
|
71
|
+
block.call
|
72
|
+
ensure
|
73
|
+
STDOUT.reopen io.first
|
74
|
+
STDERR.reopen io.last
|
75
|
+
end
|
76
|
+
|
77
|
+
DIFF = if WIN32 then 'diff.exe'
|
78
|
+
else
|
79
|
+
if quiet {system "gdiff", __FILE__, __FILE__} then 'gdiff'
|
80
|
+
else 'diff' end
|
81
|
+
end unless defined? DIFF
|
82
|
+
|
83
|
+
SUDO = if WIN32 then ''
|
84
|
+
else
|
85
|
+
if quiet {system 'which sudo'} then 'sudo'
|
86
|
+
else '' end
|
87
|
+
end
|
88
|
+
|
89
|
+
RCOV = WIN32 ? 'rcov.cmd' : 'rcov'
|
90
|
+
GEM = WIN32 ? 'gem.cmd' : 'gem'
|
91
|
+
|
92
|
+
%w(rcov spec rubyforge source_annotation_extractor).each do |lib|
|
93
|
+
begin
|
94
|
+
require lib
|
95
|
+
Object.instance_eval {const_set "HAVE_#{lib.upcase}", true}
|
96
|
+
rescue LoadError
|
97
|
+
Object.instance_eval {const_set "HAVE_#{lib.upcase}", false}
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
# Reads a file at +path+ and spits out an array of the +paragraphs+
|
102
|
+
# specified.
|
103
|
+
#
|
104
|
+
# changes = paragraphs_of('History.txt', 0..1).join("\n\n")
|
105
|
+
# summary, *description = paragraphs_of('README.txt', 3, 3..8)
|
106
|
+
#
|
107
|
+
def paragraphs_of(path, *paragraphs)
|
108
|
+
File.read(path).delete("\r").split(/\n\n+/).values_at(*paragraphs)
|
109
|
+
end
|
110
|
+
|
111
|
+
# Adds the given gem _name_ to the current project's dependency list. An
|
112
|
+
# optional gem _version_ can be given. If omitted, the newest gem version
|
113
|
+
# will be used.
|
114
|
+
#
|
115
|
+
def depend_on( name, version = nil )
|
116
|
+
spec = Gem.source_index.find_name(name).last
|
117
|
+
version = spec.version.to_s if version.nil? and !spec.nil?
|
118
|
+
|
119
|
+
PROJ.dependencies << (version.nil? ? [name] : [name, ">= #{version}"])
|
120
|
+
end
|
121
|
+
|
122
|
+
# Adds the given _path_ to the include path if it is not already there
|
123
|
+
#
|
124
|
+
def ensure_in_path( path )
|
125
|
+
path = File.expand_path(path)
|
126
|
+
$:.unshift(path) if test(?d, path) and not $:.include?(path)
|
127
|
+
end
|
128
|
+
|
129
|
+
# EOF
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# $Id$
|
2
|
+
|
3
|
+
if HAVE_SPEC
|
4
|
+
|
5
|
+
require 'spec/rake/spectask'
|
6
|
+
|
7
|
+
namespace :spec do
|
8
|
+
|
9
|
+
desc 'Run all specs with basic output'
|
10
|
+
Spec::Rake::SpecTask.new(:run) do |t|
|
11
|
+
t.spec_opts = PROJ.spec_opts
|
12
|
+
t.spec_files = PROJ.specs
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'Run all specs with text output'
|
16
|
+
Spec::Rake::SpecTask.new(:specdoc) do |t|
|
17
|
+
t.spec_opts = PROJ.spec_opts + ['--format', 'specdoc']
|
18
|
+
t.spec_files = PROJ.specs
|
19
|
+
end
|
20
|
+
|
21
|
+
if HAVE_RCOV
|
22
|
+
desc 'Run all specs with RCov'
|
23
|
+
Spec::Rake::SpecTask.new(:rcov) do |t|
|
24
|
+
t.spec_opts = PROJ.spec_opts
|
25
|
+
t.spec_files = PROJ.specs
|
26
|
+
t.rcov = true
|
27
|
+
t.rcov_opts = PROJ.rcov_opts + ['--exclude', 'spec']
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end # namespace :spec
|
32
|
+
|
33
|
+
task :clobber => 'spec:clobber_rcov' if HAVE_RCOV
|
34
|
+
|
35
|
+
end # if HAVE_SPEC
|
36
|
+
|
37
|
+
# EOF
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# $Id$
|
2
|
+
|
3
|
+
require 'rake/testtask'
|
4
|
+
|
5
|
+
namespace :test do
|
6
|
+
|
7
|
+
Rake::TestTask.new(:run) do |t|
|
8
|
+
t.libs = PROJ.libs
|
9
|
+
t.test_files = if test ?f, PROJ.test_file then [PROJ.test_file]
|
10
|
+
else PROJ.tests end
|
11
|
+
t.ruby_opts += PROJ.ruby_opts
|
12
|
+
t.ruby_opts += PROJ.test_opts
|
13
|
+
end
|
14
|
+
|
15
|
+
if HAVE_RCOV
|
16
|
+
desc 'Run rcov on the unit tests'
|
17
|
+
task :rcov => :clobber_rcov do
|
18
|
+
opts = PROJ.rcov_opts.join(' ')
|
19
|
+
files = if test ?f, PROJ.test_file then [PROJ.test_file]
|
20
|
+
else PROJ.tests end
|
21
|
+
files = files.join(' ')
|
22
|
+
sh "#{RCOV} #{files} #{opts}"
|
23
|
+
end
|
24
|
+
|
25
|
+
desc 'Remove rcov products'
|
26
|
+
task :clobber_rcov do
|
27
|
+
rm_r 'coverage' rescue nil
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end # namespace :test
|
32
|
+
|
33
|
+
task :clobber => 'test:clobber_rcov' if HAVE_RCOV
|
34
|
+
|
35
|
+
# EOF
|
File without changes
|
data/lib/bones.rb
ADDED
@@ -0,0 +1,177 @@
|
|
1
|
+
# $Id: bones.rb 420 2007-12-29 04:45:29Z tim_pease $
|
2
|
+
|
3
|
+
require 'fileutils'
|
4
|
+
require 'optparse'
|
5
|
+
require 'erb'
|
6
|
+
|
7
|
+
module Bones
|
8
|
+
|
9
|
+
VERSION = '1.0.0' # :nodoc:
|
10
|
+
PATH = File.expand_path(File.join(File.dirname(__FILE__), '..')) # :nodoc:
|
11
|
+
|
12
|
+
class Main
|
13
|
+
|
14
|
+
attr_writer :update
|
15
|
+
attr_accessor :name, :data
|
16
|
+
|
17
|
+
# Create a new instance of Main, and run the +bones+ application given
|
18
|
+
# the command line _args_.
|
19
|
+
#
|
20
|
+
def self.run( args )
|
21
|
+
bones = self.new
|
22
|
+
bones.parse args
|
23
|
+
|
24
|
+
if bones.update? then bones.update
|
25
|
+
else bones.create end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Parse the command line arguments and store the values for later use by
|
29
|
+
# the +create+ and +update+ methods.
|
30
|
+
#
|
31
|
+
def parse( args )
|
32
|
+
self.data = File.join(::Bones::PATH, 'data')
|
33
|
+
self.update = false
|
34
|
+
|
35
|
+
opts = OptionParser.new
|
36
|
+
opts.banner << ' project_name'
|
37
|
+
|
38
|
+
opts.separator ''
|
39
|
+
opts.on('-u', '--update',
|
40
|
+
'update the rake tasks for the project') {self.update = true}
|
41
|
+
|
42
|
+
opts.separator ''
|
43
|
+
opts.separator 'common options:'
|
44
|
+
|
45
|
+
opts.on_tail( '-h', '--help', 'show this message' ) {puts opts; exit}
|
46
|
+
opts.on_tail( '--version', 'show version' ) do
|
47
|
+
puts "Bones #{::Bones::VERSION}"
|
48
|
+
exit
|
49
|
+
end
|
50
|
+
|
51
|
+
# parse the command line arguments
|
52
|
+
opts.parse! args
|
53
|
+
self.name = args.shift
|
54
|
+
|
55
|
+
if name.nil?
|
56
|
+
puts opts
|
57
|
+
::Kernel.abort
|
58
|
+
end
|
59
|
+
nil
|
60
|
+
end
|
61
|
+
|
62
|
+
# Returns +true+ if we are updating an already existing project. Returns
|
63
|
+
# +false+ if we are creating a new project.
|
64
|
+
#
|
65
|
+
def update?
|
66
|
+
@update
|
67
|
+
end
|
68
|
+
|
69
|
+
# Returns the project name but converted to be useable as a Ruby class
|
70
|
+
# name.
|
71
|
+
#
|
72
|
+
def classname
|
73
|
+
name.split('_').map {|x| x.capitalize}.join
|
74
|
+
end
|
75
|
+
|
76
|
+
#
|
77
|
+
#
|
78
|
+
def create
|
79
|
+
# see if the directory already exists
|
80
|
+
abort "'#{name}' already exists" if test ?e, name
|
81
|
+
|
82
|
+
files_to_copy.each {|fn| cp fn}
|
83
|
+
|
84
|
+
pwd = File.expand_path(FileUtils.pwd)
|
85
|
+
begin
|
86
|
+
FileUtils.cd name
|
87
|
+
system "rake manifest:create 2>&1 > /dev/null"
|
88
|
+
ensure
|
89
|
+
FileUtils.cd pwd
|
90
|
+
end
|
91
|
+
|
92
|
+
# * copy files from either
|
93
|
+
# 1) the user's '.bones/data' directory or
|
94
|
+
# 2) the Bones 'data' directory
|
95
|
+
#
|
96
|
+
# TODO - figure out if this really is the best way of doing this
|
97
|
+
# should I just use either the .bones data or the gem data, not
|
98
|
+
# both
|
99
|
+
end
|
100
|
+
|
101
|
+
# Archive any existing tasks in the project's tasks folder, and then
|
102
|
+
# copy in new tasks from the bones/data directory.
|
103
|
+
#
|
104
|
+
def update
|
105
|
+
abort "'#{name}' does no exist" unless test ?e, name
|
106
|
+
|
107
|
+
task_dir = File.join(name, 'tasks')
|
108
|
+
abort "no tasks directory found in '#{name}'" unless test ?d, task_dir
|
109
|
+
|
110
|
+
archive_dir = File.join(task_dir, 'archive')
|
111
|
+
FileUtils.rm_rf archive_dir
|
112
|
+
FileUtils.mkdir archive_dir
|
113
|
+
|
114
|
+
Dir.glob(File.join(task_dir, '*')).each do |fn|
|
115
|
+
next if fn == archive_dir
|
116
|
+
FileUtils.cp fn, archive_dir
|
117
|
+
end
|
118
|
+
|
119
|
+
files_to_copy.each do |fn|
|
120
|
+
next unless 'tasks' == File.basename(File.dirname(fn))
|
121
|
+
cp fn
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
|
126
|
+
private
|
127
|
+
|
128
|
+
# Copy a file from the Bones prototype project location to the user
|
129
|
+
# specified project location. A message will be displayed to the screen
|
130
|
+
# indicating tha the file is being created.
|
131
|
+
#
|
132
|
+
def cp( file )
|
133
|
+
dir = File.join(name, File.dirname(file))
|
134
|
+
dst = File.join(dir, File.basename(file, '.erb').sub('NAME', name))
|
135
|
+
src = File.join(data, file)
|
136
|
+
|
137
|
+
FileUtils.mkdir_p(dir)
|
138
|
+
|
139
|
+
if '.erb' == File.extname(file)
|
140
|
+
txt = ERB.new(File.read(src), nil, '-').result(binding)
|
141
|
+
File.open(dst, 'w') {|fd| fd.write(txt)}
|
142
|
+
else
|
143
|
+
FileUtils.cp src, dst
|
144
|
+
end
|
145
|
+
|
146
|
+
FileUtils.chmod(File.stat(src).mode, dst)
|
147
|
+
end
|
148
|
+
|
149
|
+
# Prints an abort _msg_ to the screen and then exits the Ruby interpreter.
|
150
|
+
#
|
151
|
+
def abort( msg )
|
152
|
+
STDERR.puts msg
|
153
|
+
exit 1
|
154
|
+
end
|
155
|
+
|
156
|
+
# Returns a list of the files to copy from the bones/data directory to
|
157
|
+
# the new project directory
|
158
|
+
#
|
159
|
+
def files_to_copy
|
160
|
+
rgxp = %r/\A#{data}\/?/o
|
161
|
+
exclude = %r/tmp$|bak$|~$|CVS|\.svn/o
|
162
|
+
|
163
|
+
ary = Dir.glob(File.join(data, '**', '*')).map do |filename|
|
164
|
+
next if exclude =~ filename
|
165
|
+
next if test(?d, filename)
|
166
|
+
filename.sub rgxp, ''
|
167
|
+
end
|
168
|
+
|
169
|
+
ary.compact!
|
170
|
+
ary.sort!
|
171
|
+
ary
|
172
|
+
end
|
173
|
+
|
174
|
+
end # class Main
|
175
|
+
end # module Bones
|
176
|
+
|
177
|
+
# EOF
|