| 38 | | ARTIFACTS_DIR = Pathname.new( ENV['CC_BUILD_ARTIFACTS'] || '' ) |
| 39 | | |
| 40 | | TEXT_FILES = %w( Rakefile ChangeLog INSTALL README LICENSE ). |
| 41 | | collect {|filename| BASEDIR + filename } |
| 42 | | |
| 43 | | BUILD_FILES = %w( convertdb.rb utils.rb ) |
| | 42 | |
| | 43 | PKG_NAME = 'wordnet' |
| | 44 | PKG_SUMMARY = '' |
| | 45 | VERSION_FILE = LIBDIR + 'wordnet.rb' |
| | 46 | PKG_VERSION = VERSION_FILE.read[ /VERSION = '(\d+\.\d+\.\d+)'/, 1 ] |
| | 47 | PKG_FILE_NAME = "#{PKG_NAME.downcase}-#{PKG_VERSION}" |
| | 48 | GEM_FILE_NAME = "#{PKG_FILE_NAME}.gem" |
| | 49 | |
| | 50 | RELEASE_NAME = "RELEASE_#{PKG_VERSION.gsub(/\./, '_')}" |
| | 51 | |
| | 52 | ARTIFACTS_DIR = Pathname.new( ENV['CC_BUILD_ARTIFACTS'] || 'artifacts' ) |
| | 53 | |
| | 54 | TEXT_FILES = %w( Rakefile ChangeLog README LICENSE ).collect {|filename| BASEDIR + filename } |
| | 55 | LIB_FILES = Pathname.glob( LIBDIR + '**/*.rb' ).delete_if {|item| item =~ /\.svn/ } |
| | 56 | EXT_FILES = Pathname.glob( EXTDIR + '**/*.{c,h,rb}' ).delete_if {|item| item =~ /\.svn/ } |
| | 78 | |
| | 79 | # Define some constants that depend on the 'svn' tasklib |
| | 80 | PKG_BUILD = get_svn_rev( BASEDIR ) || 0 |
| | 81 | SNAPSHOT_PKG_NAME = "#{PKG_FILE_NAME}.#{PKG_BUILD}" |
| | 82 | SNAPSHOT_GEM_NAME = "#{SNAPSHOT_PKG_NAME}.gem" |
| | 83 | |
| | 84 | # Documentation constants |
| | 85 | RDOC_OPTIONS = [ |
| | 86 | '-w', '4', |
| | 87 | '-SHN', |
| | 88 | '-i', '.', |
| | 89 | '-m', 'README', |
| | 90 | '-W', 'http://deveiate.org/projects/Ruby-WordNet/browser/trunk/' |
| | 91 | ] |
| | 92 | |
| | 93 | # Release constants |
| | 94 | SMTP_HOST = 'mail.faeriemud.org' |
| | 95 | SMTP_PORT = 465 # SMTP + SSL |
| | 96 | |
| | 97 | # Project constants |
| | 98 | PROJECT_HOST = 'deveiate.org' |
| | 99 | PROJECT_PUBDIR = "/usr/local/www/public/code" |
| | 100 | PROJECT_DOCDIR = "#{PROJECT_PUBDIR}/#{PKG_NAME}" |
| | 101 | PROJECT_SCPURL = "#{PROJECT_HOST}:#{PROJECT_DOCDIR}" |
| | 102 | |
| | 103 | # Gem dependencies: gemname => version |
| | 104 | DEPENDENCIES = { |
| | 105 | # 'mongrel' => '', |
| | 106 | } |
| | 107 | |
| | 108 | # Non-gem requirements: packagename => version |
| | 109 | REQUIREMENTS = { |
| | 110 | # 'Apache' => '>= 2.2.6', |
| | 111 | } |
| | 112 | |
| | 113 | # RubyGem specification |
| | 114 | GEMSPEC = Gem::Specification.new do |gem| |
| | 115 | gem.name = PKG_NAME.downcase |
| | 116 | gem.version = PKG_VERSION |
| | 117 | |
| | 118 | gem.summary = PKG_SUMMARY |
| | 119 | gem.description = <<-EOD |
| | 120 | |
| | 121 | A Ruby implementation of the WordNet lexical dictionary |
| | 122 | |
| | 123 | EOD |
| | 124 | |
| | 125 | gem.authors = 'Michael Granger' |
| | 126 | gem.email = 'ged@FaerieMUD.org' |
| | 127 | gem.homepage = 'http://deveiate.org/projects/Ruby-WordNet' |
| | 128 | gem.rubyforge_project = 'deveiate' |
| | 129 | |
| | 130 | gem.has_rdoc = true |
| | 131 | gem.rdoc_options = RDOC_OPTIONS |
| | 132 | |
| | 133 | gem.files = RELEASE_FILES. |
| | 134 | collect {|f| f.relative_path_from(BASEDIR).to_s } |
| | 135 | gem.test_files = SPEC_FILES. |
| | 136 | collect {|f| f.relative_path_from(BASEDIR).to_s } |
| | 137 | |
| | 138 | DEPENDENCIES.each do |name, version| |
| | 139 | version = '>= 0' if version.length.zero? |
| | 140 | gem.add_dependency( name, version ) |
| | 141 | end |
| | 142 | |
| | 143 | REQUIREMENTS.each do |name, version| |
| | 144 | gem.requirements << [ name, version ].compact.join(' ') |
| | 145 | end |
| | 146 | end |
| | 147 | |
| | 148 | |
| | 149 | # Load any remaining task libraries |
| 100 | | desc "Clean pkg, coverage, and rdoc; remove .bak files" |
| 101 | | task :clean => [ :clobber_rdoc, :clobber_package, :clobber_coverage, :clobber_manual ] do |
| 102 | | files = FileList['**/*.bak'] |
| 103 | | files.clear_exclude |
| 104 | | File.rm( files ) unless files.empty? |
| 105 | | FileUtils.rm_rf( 'artifacts' ) |
| 106 | | end |
| 107 | | |
| 108 | | |
| 109 | | ### Task: docs -- Convenience task for rebuilding dynamic docs, including coverage, api |
| 110 | | ### docs, and manual |
| 111 | | task :docs => [ :manual, :coverage, :rdoc ] |
| 112 | | |
| 113 | | |
| 114 | | ### Task: rdoc |
| 115 | | Rake::RDocTask.new do |rdoc| |
| 116 | | rdoc.rdoc_dir = 'docs' |
| 117 | | rdoc.title = "Ruby WordNet" |
| 118 | | |
| 119 | | rdoc.options += [ |
| 120 | | '-w', '4', |
| 121 | | '-SHN', |
| 122 | | '-i', 'docs', |
| 123 | | '-f', 'darkfish', |
| 124 | | '-m', 'README', |
| 125 | | '-W', 'http://deveiate.org/projects/Ruby-WordNet/browser/trunk/' |
| 126 | | ] |
| 127 | | |
| 128 | | rdoc.rdoc_files.include 'README' |
| 129 | | rdoc.rdoc_files.include LIB_FILES.collect {|f| f.relative_path_from(BASEDIR).to_s } |
| 130 | | end |
| 131 | | |
| 132 | | |
| 133 | | ### Task: gem |
| 134 | | gemspec = Gem::Specification.new do |gem| |
| 135 | | pkg_build = get_svn_rev( BASEDIR ) || 0 |
| 136 | | |
| 137 | | gem.name = PKG_NAME |
| 138 | | gem.version = "%s.%s" % [ PKG_VERSION, pkg_build ] |
| 139 | | |
| 140 | | gem.summary = "Ruby-WordNet is a Ruby interface to the WordNet® Lexical Database" |
| 141 | | gem.description = <<-EOD |
| 142 | | Ruby-WordNet is a Ruby interface to the WordNet® Lexical Database. WordNet |
| 143 | | is an online lexical reference system whose design is inspired by current |
| 144 | | psycholinguistic theories of human lexical memory. English nouns, verbs, |
| 145 | | adjectives and adverbs are organized into synonym sets, each representing |
| 146 | | one underlying lexical concept. Different relations link the synonym sets. |
| 147 | | EOD |
| 148 | | |
| 149 | | gem.authors = "Michael Granger" |
| 150 | | gem.homepage = "http://deveiate.org/projects/Ruby-WordNet/" |
| 151 | | |
| 152 | | gem.has_rdoc = true |
| 153 | | |
| 154 | | gem.files = RELEASE_FILES. |
| 155 | | collect {|f| f.relative_path_from(BASEDIR).to_s } |
| 156 | | gem.test_files = SPEC_FILES. |
| 157 | | collect {|f| f.relative_path_from(BASEDIR).to_s } |
| 158 | | |
| 159 | | gem.add_dependency( 'sequel' ) |
| 160 | | end |
| 161 | | Rake::GemPackageTask.new( gemspec ) do |task| |
| 162 | | task.gem_spec = gemspec |
| 163 | | task.need_tar = false |
| 164 | | task.need_tar_gz = true |
| 165 | | task.need_tar_bz2 = true |
| 166 | | task.need_zip = true |
| 167 | | end |
| 168 | | |
| 169 | | |
| 170 | | ### Task: install |
| 171 | | task :install_gem => [:package] do |
| 172 | | $stderr.puts |
| 173 | | installer = Gem::Installer.new( %{pkg/#{PKG_FILE_NAME}.gem} ) |
| 174 | | installer.install |
| 175 | | end |
| 176 | | |
| 177 | | ### Task: uninstall |
| 178 | | task :uninstall_gem => [:clean] do |
| 179 | | uninstaller = Gem::Uninstaller.new( PKG_FILE_NAME ) |
| 180 | | uninstaller.uninstall |
| 181 | | end |
| 182 | | |
| | 187 | CLEAN.include 'coverage' |
| | 188 | CLOBBER.include 'artifacts', 'coverage.info', PKGDIR |
| 200 | | ### RSpec tasks |
| 201 | | begin |
| 202 | | gem 'rspec', '>= 1.1.3' |
| 203 | | require 'spec/rake/spectask' |
| 204 | | |
| 205 | | COMMON_SPEC_OPTS = ['-c', '-f', 's'] |
| 206 | | |
| 207 | | ### Task: spec |
| 208 | | Spec::Rake::SpecTask.new( :spec ) do |task| |
| 209 | | task.spec_files = SPEC_FILES |
| 210 | | task.libs += [LIBDIR] |
| 211 | | task.spec_opts = COMMON_SPEC_OPTS |
| 212 | | end |
| 213 | | task :test => [:spec] |
| 214 | | |
| 215 | | |
| 216 | | namespace :spec do |
| 217 | | desc "Run rspec every time there's a change to one of the files" |
| 218 | | task :autotest do |
| 219 | | require 'autotest/rspec' |
| 220 | | |
| 221 | | autotester = Autotest::Rspec.new |
| 222 | | autotester.exceptions = %r{\.svn|\.skel} |
| 223 | | autotester.run |
| 224 | | end |
| 225 | | |
| 226 | | |
| 227 | | desc "Generate HTML output for a spec run" |
| 228 | | Spec::Rake::SpecTask.new( :html ) do |task| |
| 229 | | task.spec_files = SPEC_FILES |
| 230 | | task.spec_opts = ['-f','h', '-D'] |
| 231 | | end |
| 232 | | |
| 233 | | desc "Generate plain-text output for a CruiseControl.rb build" |
| 234 | | Spec::Rake::SpecTask.new( :text ) do |task| |
| 235 | | task.spec_files = SPEC_FILES |
| 236 | | task.spec_opts = ['-f','p'] |
| 237 | | end |
| 238 | | end |
| 239 | | rescue LoadError => err |
| 240 | | task :no_rspec do |
| 241 | | $stderr.puts "Testing tasks not defined: RSpec rake tasklib not available: %s" % |
| 242 | | [ err.message ] |
| 243 | | end |
| 244 | | |
| 245 | | task :spec => :no_rspec |
| 246 | | namespace :spec do |
| 247 | | task :autotest => :no_rspec |
| 248 | | task :html => :no_rspec |
| 249 | | task :text => :no_rspec |
| 250 | | end |
| 251 | | end |
| 252 | | |
| 253 | | |
| 254 | | ### RCov (via RSpec) tasks |
| 255 | | begin |
| 256 | | gem 'rcov' |
| 257 | | gem 'rspec', '>= 1.1.3' |
| 258 | | |
| 259 | | RCOV_OPTS = ['--exclude', SPEC_EXCLUDES, '--xrefs', '--save'] |
| 260 | | |
| 261 | | ### Task: coverage (via RCov) |
| 262 | | ### Task: spec |
| 263 | | desc "Build test coverage reports" |
| 264 | | Spec::Rake::SpecTask.new( :coverage ) do |task| |
| 265 | | task.spec_files = SPEC_FILES |
| 266 | | task.libs += [LIBDIR] |
| 267 | | task.spec_opts = ['-f', 'p', '-b'] |
| 268 | | task.rcov_opts = RCOV_OPTS |
| 269 | | task.rcov = true |
| 270 | | end |
| 271 | | |
| 272 | | task :rcov => [:coverage] do; end |
| 273 | | |
| 274 | | ### Other coverage tasks |
| 275 | | namespace :coverage do |
| 276 | | desc "Generate a detailed text coverage report" |
| 277 | | Spec::Rake::SpecTask.new( :text ) do |task| |
| 278 | | task.spec_files = SPEC_FILES |
| 279 | | task.rcov_opts = RCOV_OPTS + ['--text-report'] |
| 280 | | task.rcov = true |
| 281 | | end |
| 282 | | |
| 283 | | desc "Show differences in coverage from last run" |
| 284 | | Spec::Rake::SpecTask.new( :diff ) do |task| |
| 285 | | task.spec_files = SPEC_FILES |
| 286 | | task.rcov_opts = ['--text-coverage-diff'] |
| 287 | | task.rcov = true |
| 288 | | end |
| 289 | | |
| 290 | | ### Task: verify coverage |
| 291 | | desc "Build coverage statistics" |
| 292 | | VerifyTask.new( :verify => :rcov ) do |task| |
| 293 | | task.threshold = 85.0 |
| 294 | | end |
| 295 | | |
| 296 | | desc "Run RCov in 'spec-only' mode to check coverage from specs" |
| 297 | | Spec::Rake::SpecTask.new( :speconly ) do |task| |
| 298 | | task.spec_files = SPEC_FILES |
| 299 | | task.rcov_opts = ['--exclude', SPEC_EXCLUDES, '--text-report', '--save'] |
| 300 | | task.rcov = true |
| 301 | | end |
| 302 | | end |
| 303 | | |
| 304 | | rescue LoadError => err |
| 305 | | task :no_rcov do |
| 306 | | $stderr.puts "Coverage tasks not defined: RSpec+RCov tasklib not available: %s" % |
| 307 | | [ err.message ] |
| 308 | | end |
| 309 | | |
| 310 | | task :coverage => :no_rcov |
| 311 | | task :clobber_coverage |
| 312 | | task :rcov => :no_rcov |
| 313 | | namespace :coverage do |
| 314 | | task :text => :no_rcov |
| 315 | | task :diff => :no_rcov |
| 316 | | end |
| 317 | | task :verify => :no_rcov |
| 318 | | end |
| 319 | | |
| 320 | | |
| 321 | | |
| 322 | | ### Coding style checks and fixes |
| 323 | | namespace :style do |
| 324 | | |
| 325 | | BLANK_LINE = /^\s*$/ |
| 326 | | GOOD_INDENT = /^(\t\s*)?\S/ |
| 327 | | |
| 328 | | # A list of the files that have legitimate leading whitespace, etc. |
| 329 | | PROBLEM_FILES = [] |
| 330 | | |
| 331 | | desc "Check source files for inconsistent indent and fix them" |
| 332 | | task :fix_indent do |
| 333 | | files = LIB_FILES + SPEC_FILES |
| 334 | | |
| 335 | | badfiles = Hash.new {|h,k| h[k] = [] } |
| 336 | | |
| 337 | | trace "Checking files for indentation" |
| 338 | | files.each do |file| |
| 339 | | if PROBLEM_FILES.include?( file ) |
| 340 | | trace " skipping problem file #{file}..." |
| 341 | | next |
| 342 | | end |
| 343 | | |
| 344 | | trace " #{file}" |
| 345 | | linecount = 0 |
| 346 | | file.each_line do |line| |
| 347 | | linecount += 1 |
| 348 | | |
| 349 | | # Skip blank lines |
| 350 | | next if line =~ BLANK_LINE |
| 351 | | |
| 352 | | # If there's a line with incorrect indent, note it and skip to the |
| 353 | | # next file |
| 354 | | if line !~ GOOD_INDENT |
| 355 | | trace " Bad line %d: %p" % [ linecount, line ] |
| 356 | | badfiles[file] << [ linecount, line ] |
| 357 | | end |
| 358 | | end |
| 359 | | end |
| 360 | | |
| 361 | | if badfiles.empty? |
| 362 | | log "No indentation problems found." |
| 363 | | else |
| 364 | | log "Found incorrect indent in #{badfiles.length} files:\n " |
| 365 | | badfiles.each do |file, badlines| |
| 366 | | log " #{file}:\n" + |
| 367 | | " " + badlines.collect {|badline| "%5d: %p" % badline }.join( "\n " ) |
| 368 | | end |
| 369 | | end |
| 370 | | end |
| 371 | | |
| 372 | | end |
| 373 | | |
| 374 | | |