5 |
5 |
6 require 'rubygems' |
6 require 'rubygems' |
7 require 'pathname' |
7 require 'pathname' |
8 |
8 |
9 require 'rake' |
9 require 'rake' |
|
10 require 'rake/packagetask' |
10 require 'rake/gempackagetask' |
11 require 'rake/gempackagetask' |
11 require 'spec/rake/spectask' |
12 require 'spec/rake/spectask' |
|
13 require 'rubygems/installer' |
|
14 require 'rubygems/uninstaller' |
12 |
15 |
13 |
16 |
14 ###################################################################### |
17 ###################################################################### |
15 ### P A T H S |
18 ### P A T H S A N D F I L E S |
16 ###################################################################### |
19 ###################################################################### |
17 |
20 |
18 BASEDIR = Pathname.new( __FILE__ ).expand_path.dirname.relative_path_from( Pathname.getwd ) |
21 BASEDIR = Pathname.new( __FILE__ ).expand_path.dirname.relative_path_from( Pathname.getwd ) |
|
22 |
|
23 TEXT_FILES = %w{ Rakefile README LICENSE }.collect {|f| BASEDIR + f } |
|
24 |
19 SPECDIR = BASEDIR + 'spec' |
25 SPECDIR = BASEDIR + 'spec' |
20 LIBDIR = BASEDIR + 'lib' |
|
21 SPEC_FILES = Pathname.glob( SPECDIR + '**/*_spec.rb' ).reject {|f| f =~ /^\.svn/ } |
26 SPEC_FILES = Pathname.glob( SPECDIR + '**/*_spec.rb' ).reject {|f| f =~ /^\.svn/ } |
|
27 |
|
28 LIBDIR = BASEDIR + 'lib' |
|
29 LIB_FILES = Pathname.glob( LIBDIR + '**/*.rb').reject {|i| i =~ /\.svn/ } |
|
30 |
|
31 RELEASE_FILES = TEXT_FILES + LIB_FILES + SPEC_FILES |
|
32 |
22 |
33 |
23 ###################################################################### |
34 ###################################################################### |
24 ### H E L P E R S |
35 ### H E L P E R S |
25 ###################################################################### |
36 ###################################################################### |
26 |
37 |
35 end |
46 end |
36 end |
47 end |
37 return ver.is_a?( String ) ? ver : 'UNKNOWN' |
48 return ver.is_a?( String ) ? ver : 'UNKNOWN' |
38 end |
49 end |
39 |
50 |
|
51 |
40 ###################################################################### |
52 ###################################################################### |
41 ### P A C K A G E C O N S T A N T S |
53 ### P A C K A G E C O N S T A N T S |
42 ###################################################################### |
54 ###################################################################### |
43 |
55 |
44 PKG_NAME = 'chunker' |
56 PKG_NAME = 'chunker' |
45 PKG_VERSION = find_pattern( LIBDIR + 'chunker.rb', /VERSION = ['"](\d\.\d(?:\/\d)?)['"]/ ) |
57 PKG_VERSION = find_pattern( LIBDIR + 'chunker.rb', /VERSION = ['"](\d\.\d(?:\/\d)?)['"]/ ) |
46 PKG_REVISION = find_pattern( LIBDIR + 'chunker.rb', /SVNRev = .+Rev: (\d+)/ ) |
58 PKG_REVISION = find_pattern( LIBDIR + 'chunker.rb', /SVNRev = .+Rev: (\d+)/ ) |
47 PKG_VERSION = begin |
59 PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}.#{PKG_REVISION}" |
48 ver = nil |
|
49 File.open( LIBDIR + 'chunker.rb' ) do |f| |
|
50 ver = f.each do |line| |
|
51 break $1 if line =~ /VERSION = ['"](\d\.\d(?:\/\d)?)['"]/ |
|
52 end |
|
53 end |
|
54 ver.is_a?( String ) ? ver : 'UNKNOWN' |
|
55 end |
|
56 RELEASE_NAME = "REL #{PKG_VERSION}" |
|
57 PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}" |
|
58 |
60 |
59 |
61 |
60 ###################################################################### |
62 ###################################################################### |
61 ### T A S K S |
63 ### T A S K S |
62 ###################################################################### |
64 ###################################################################### |
63 |
65 |
64 task :default => [:test] |
66 task :default => [ :test, :package ] |
65 |
67 |
66 |
68 |
67 ### Task: run rspec tests |
69 ### Task: run rspec tests |
68 ### |
70 ### |
69 desc "Run tests" |
71 desc "Run tests" |
70 Spec::Rake::SpecTask.new('test') do |task| |
72 Spec::Rake::SpecTask.new('test') do |task| |
71 task.spec_files = FileList['spec/**/*.rb'] |
73 task.spec_files = SPEC_FILES |
72 task.spec_opts = %w{ -c -fs } |
74 task.spec_opts = %w{ -c -fs } |
73 end |
75 end |
74 |
76 |
75 |
77 |
76 ### Task: generate ctags |
78 ### Task: generate ctags |
83 |
85 |
84 |
86 |
85 ### Task: Create gem from source |
87 ### Task: Create gem from source |
86 ### |
88 ### |
87 gem = Gem::Specification.new do |gem| |
89 gem = Gem::Specification.new do |gem| |
|
90 pkg_build = PKG_REVISION || 0 |
|
91 |
|
92 gem.summary = "A convenience library for parsing __END__ tokens consistently." |
|
93 gem.name = PKG_NAME |
|
94 gem.version = "%s.%s" % [ PKG_VERSION, pkg_build ] |
|
95 gem.author = 'Mahlon E. Smith' |
|
96 gem.email = 'mahlon@martini.nu' |
|
97 gem.homepage = 'http://projects.martini.nu/ruby-modules/wiki/chunker' |
|
98 gem.rubyforge_project = 'mahlon' |
|
99 gem.has_rdoc = true |
|
100 |
|
101 gem.files = RELEASE_FILES. |
|
102 collect {|f| f.relative_path_from(BASEDIR).to_s } |
|
103 gem.test_files = SPEC_FILES. |
|
104 collect {|f| f.relative_path_from(BASEDIR).to_s } |
|
105 |
|
106 gem.description = <<-EOF |
|
107 Ruby provides an automatic constant called DATA, which is an IO object |
|
108 that references all text in the current file under an __END__ token. |
|
109 |
|
110 I find it convenient to use the __END__ area to store all sorts of |
|
111 stuff, rather than have to worry about distributing separate files. |
|
112 |
|
113 The DATA constant is determined from whatever ruby believes $0 to be. |
|
114 It doesn't work inside of other required libraries, so you'll see stuff |
|
115 like this all the time: |
|
116 |
|
117 END = File.open( __FILE__ ).read.split( /^__END__/, 2 ).last |
|
118 |
|
119 It works, but it's more work than I want to do. |
|
120 |
|
121 Chunker solves this by parsing __END__ tokens for you, and making it |
|
122 available in the form of a 'DATA_END' constant. It installs this |
|
123 constant into the class that includes Chunker, so you can use it again |
|
124 and again, assuming you use a different file for each class. |
|
125 |
|
126 It also automatically parses out other things that look like tokens, so |
|
127 you can easily have multiple, distinct documents all embedded into the |
|
128 __END__ block. |
|
129 EOF |
88 end |
130 end |
89 |
131 |
90 Rake::GemPackageTask.new( gem ) do |pkg| |
132 Rake::GemPackageTask.new( gem ) do |pkg| |
91 pkg.need_zip = true |
133 pkg.need_zip = true |
92 pkg.need_tar = true |
134 pkg.need_tar = true |
93 end |
135 pkg.need_tar_bz2 = true |
94 |
|
95 |
|
96 |
|
97 __END__ |
|
98 |
|
99 spec = Gem::Specification.new do |s| |
|
100 s.platform = Gem::Platform::RUBY |
|
101 s.summary = "Ruby based make-like utility." |
|
102 s.name = 'rake' |
|
103 s.version = PKG_VERSION |
|
104 s.requirements << 'none' |
|
105 s.require_path = 'lib' |
|
106 s.autorequire = 'rake' |
|
107 s.files = PKG_FILES |
|
108 s.description = <<EOF |
|
109 Rake is a Make-like program implemented in Ruby. Tasks |
|
110 and dependencies are specified in standard Ruby syntax. |
|
111 EOF |
|
112 end |
|
113 |
|
114 Rake::GemPackageTask.new(spec) do |pkg| |
|
115 pkg.need_zip = true |
|
116 pkg.need_tar = true |
|
117 end |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 require 'rake/packagetask' |
|
125 require 'rake/gempackagetask' |
|
126 |
|
127 ### Task: gem |
|
128 gemspec = Gem::Specification.new do |gem| |
|
129 pkg_build = get_svn_rev( BASEDIR ) || 0 |
|
130 |
|
131 gem.name = PKG_NAME |
|
132 gem.version = "%s.%s" % [ PKG_VERSION, pkg_build ] |
|
133 |
|
134 gem.summary = "ThingFish - A highly-accessable network datastore" |
|
135 gem.description = "ThingFish is a network-accessable, searchable, extensible " + |
|
136 "datastore. It can be used to store chunks of data on the " + |
|
137 "network in an application-independent way, associate the chunks " + |
|
138 "with other chunks through metadata, and then search for the chunk " + |
|
139 "you need later and fetch it again, all through a REST API over HTTP." |
|
140 |
|
141 gem.authors = "Michael Granger and Mahlon E. Smith" |
|
142 gem.email = "mgranger@laika.com, mahlon@laika.com" |
|
143 gem.homepage = "http://opensource.laika.com/wiki/ThingFish" |
|
144 |
|
145 gem.rubyforge_project = 'laika' |
|
146 |
|
147 gem.has_rdoc = true |
|
148 |
|
149 gem.files = RELEASE_FILES. |
|
150 collect {|f| f.relative_path_from(BASEDIR).to_s } |
|
151 gem.test_files = SPEC_FILES. |
|
152 collect {|f| f.relative_path_from(BASEDIR).to_s } |
|
153 gem.executables = BIN_FILES . |
|
154 collect {|f| f.relative_path_from(BINDIR).to_s } |
|
155 |
|
156 gem.add_dependency( 'uuidtools', '>= 1.0.0' ) |
|
157 gem.add_dependency( 'pluginfactory', '>= 1.0.3' ) |
|
158 end |
|
159 Rake::GemPackageTask.new( gemspec ) do |task| |
|
160 task.gem_spec = gemspec |
|
161 task.need_tar = false |
|
162 task.need_tar_gz = true |
|
163 task.need_tar_bz2 = true |
|
164 task.need_zip = true |
|
165 end |
|
166 |
|
167 |
|
168 desc "Build the ThingFish gem and gems for all the standard plugins" |
|
169 task :gems => [:gem] do |
|
170 log "Building gems for plugins in: %s" % [PLUGINS.join(', ')] |
|
171 PLUGINS.each do |plugindir| |
|
172 log plugindir.basename |
|
173 cp BASEDIR + 'LICENSE', plugindir |
|
174 Dir.chdir( plugindir ) do |
|
175 system 'rake', 'gem' |
|
176 end |
|
177 |
|
178 fail unless $?.success? |
|
179 |
|
180 pkgdir = plugindir + 'pkg' |
|
181 gems = Pathname.glob( pkgdir + '*.gem' ) |
|
182 cp gems, PKGDIR |
|
183 end |
|
184 end |
136 end |
185 |
137 |
186 |
138 |
187 ### Task: install |
139 ### Task: install |
188 task :install_gem => [:package] do |
140 ### |
189 $stderr.puts |
141 task :install_gem => [ :package ] do |
190 installer = Gem::Installer.new( %{pkg/#{PKG_FILE_NAME}.gem} ) |
142 $stderr.puts |
|
143 installer = Gem::Installer.new( "pkg/#{PKG_FILE_NAME}.gem" ) |
191 installer.install |
144 installer.install |
192 end |
145 end |
|
146 task :install => [ :install_gem ] |
|
147 |
193 |
148 |
194 ### Task: uninstall |
149 ### Task: uninstall |
195 task :uninstall_gem => [:clean] do |
150 ### |
196 uninstaller = Gem::Uninstaller.new( PKG_FILE_NAME ) |
151 task :uninstall_gem do |
|
152 uninstaller = Gem::Uninstaller.new( PKG_NAME ) |
197 uninstaller.uninstall |
153 uninstaller.uninstall |
198 end |
154 end |
|
155 task :uninstall => [ :uninstall_gem ] |
199 |
156 |
200 |
|
201 |
|
202 |
|