Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial commit.

  • Loading branch information...
commit f93f24e62d616a6594b0059ea2f70578f8f06d89 0 parents
@postmodern authored
5 .document
@@ -0,0 +1,5 @@
+lib/**/*.rb
+bin/*
+-
+ChangeLog.*
+LICENSE.txt
2  .gitignore
@@ -0,0 +1,2 @@
+doc/
+pkg/
1  .rspec
@@ -0,0 +1 @@
+--colour --format documentation
1  .yardopts
@@ -0,0 +1 @@
+--markup markdown --title "Project::Tasks Documentation" --protected
4 ChangeLog.md
@@ -0,0 +1,4 @@
+### 0.1.0 / 2011-08-30
+
+* Initial release:
+
20 LICENSE.txt
@@ -0,0 +1,20 @@
+Copyright (c) 2011 Hal Brodigan
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
57 README.md
@@ -0,0 +1,57 @@
+# project-tasks
+
+* [Source](http://github.com/ruby-ore/project-tasks)
+* [Issues](http://github.com/ruby-ore/project-tasks/issues)
+* [Email](mailto:postmodern.mod3 at gmail.com)
+
+## Description
+
+Project Tasks provides simple Rake tasks for managing and releasing RubyGem
+projects.
+
+## Features
+
+* Provides tasks to build, install and push Gems to
+ [rubygems.org](http://rubygems.org/).
+* Supports Git, Mercurial and SubVersion.
+* Provides the `console` task for jumping right into your code.
+* **Does not** automatically modify or commit changes to your code.
+
+## Requirements
+
+* [scm](http://github.com/postmodern/scm) ~> 0.1.0
+
+## Install
+
+ $ gem install project-tasks
+
+## Examples
+
+ require 'project/tasks'
+ Project::Tasks.new
+
+Enable pushing gems to an in-house
+[gemcutter](http://github.com/rubygems/gemcutter#readme) server:
+
+ Project::Tasks.new(:gemcutter => 'internal.example.com')
+
+Disable pushing gems:
+
+ Project::Tasks.new(:gemcutter => false)
+
+## Synopsis
+
+ rake build # Builds project-tasks-0.1.0
+ rake console[script] # Start IRB with all runtime dependencies loaded
+ rake install # Installs project-tasks-0.1.0
+ rake install:deps # Installs missing dependencies
+ rake release # Releases project-tasks-0.1.0
+ rake spec # Run RSpec code examples
+ rake version # Displays the current version
+ rake yard # Generate YARD Documentation
+
+## Copyright
+
+Copyright (c) 2011 Hal Brodigan
+
+See {file:LICENSE.txt} for details.
32 Rakefile
@@ -0,0 +1,32 @@
+require 'rubygems'
+require 'rake'
+
+lib_dir = File.expand_path('lib',File.dirname(__FILE__))
+$LOAD_PATH << lib_dir unless $LOAD_PATH.include?(lib_dir)
+
+require 'project/tasks'
+Project::Tasks.new
+
+begin
+ gem 'rspec', '~> 2.4'
+ require 'rspec/core/rake_task'
+
+ RSpec::Core::RakeTask.new
+rescue LoadError
+ task :spec do
+ abort "Please run `gem install rspec` to install RSpec."
+ end
+end
+task :test => :spec
+task :default => :spec
+
+begin
+ gem 'yard', '~> 0.7'
+ require 'yard'
+
+ YARD::Rake::YardocTask.new
+rescue LoadError => e
+ task :yard do
+ abort 'Please run `gem install yard` to install YARD.'
+ end
+end
17 gemspec.yml
@@ -0,0 +1,17 @@
+name: project-tasks
+version: 0.0.0
+summary: Rake tasks for managing and releasing Ruby projects.
+description:
+ Simple Rake tasks for managing and releasing Ruby projects.
+
+authors: Postmodern
+email: postmodern.mod3@gmail.com
+homepage: http://github.com/postmodern/project-tasks
+has_yard: true
+
+runtime_dependencies:
+ scm: ~> 0.1.0.pre2
+
+development_dependencies:
+ rspec: ~> 2.4
+ yard: ~> 0.7
340 lib/project/tasks.rb
@@ -0,0 +1,340 @@
+require 'scm'
+
+require 'rake/tasklib'
+require 'digest/sha1'
+require 'set'
+
+module Project
+ #
+ # Defines basic Rake tasks for managing and releasing projects.
+ #
+ class Tasks < Rake::TaskLib
+
+ # Specifies the [gemcutter](http://github.com/rubygems/gemcutter#readme)
+ # host or if pushing gems to [rubygems.org](http://rubygems.org/)
+ # is enabled.
+ attr_accessor :gemcutter
+
+ # Prefix for release tags (default: `v`).
+ attr_accessor :tag_prefix
+
+ # The loaded gemspec of the project.
+ attr_reader :gemspec
+
+ # The files of the project.
+ attr_reader :files
+
+ # The directories to add to `$LOAD_PATHS`.
+ attr_reader :load_paths
+
+ # The SCM the project uses.
+ attr_reader :scm
+
+ #
+ # Initializes the project tasks.
+ #
+ # @param [Hash] options
+ # Additional options for the tasks.
+ #
+ # @option options [String] :root (Dir.pwd)
+ # The optional root directory for the project.
+ #
+ # @option options [String, Boolean] :gemcutter (true)
+ # Specifies the
+ # [gemcutter](http://github.com/rubygems/gemcutter#readme)
+ # server to push built Gems to. If `:gemcutter` is a Boolean value, it
+ # will enable or disable pushing to
+ # [rubygems.org](http://rubygems.org/).
+ #
+ # @yield [tasks]
+ # If a block is given, it will be passed the newly created tasks,
+ # before they are fully defined.
+ #
+ # @yieldparam [Tasks] tasks
+ # The newly created tasks.
+ #
+ def initialize(options={})
+ @root = File.join(Dir.pwd,options.fetch(:root,''))
+ @scm = begin
+ SCM.new(@root)
+ rescue
+ end
+
+ @name = File.basename(@root)
+ @version = options[:version]
+
+ @files = Set[]
+ @load_paths = []
+
+ @gemcutter = options.fetch(:gemcutter,true)
+ @bundler = File.file?('Gemfile')
+
+ @tag_prefix = options.fetch(:tag_prefix,'v')
+
+ if (@gemspec = load_gemspec)
+ @name = @gemspec.name
+ @version = @gemspec.version
+
+ @gemspec.files.each { |path| @files << path }
+ @load_paths += @gemspec.require_paths
+ else
+ if @scm
+ @scm.files { |path| @files << path }
+ else
+ Dir.glob('{**/}{.*,*}') do |path|
+ @files << path if File.file?(path)
+ end
+ end
+
+ @load_paths += Dir['{ext,lib}']
+ end
+
+ @release_name = "#{@name}-#{@version}"
+
+ define
+ end
+
+ protected
+
+ def load_gemspec
+ require 'rubygems'
+
+ paths = ["#{@name}.gemspec"] + Dir['*.gemspec']
+
+ paths.each do |path|
+ if File.file?(path)
+ return Gem::Specification.load(path)
+ end
+ end
+
+ return nil
+ end
+
+ #
+ # Defines tasks used during development.
+ #
+ def define_core_tasks
+ namespace :build do
+ directory 'pkg'
+
+ task :tar => ['pkg'] do
+ run 'tar', '-czf', pkg_file('tar.gz'), *@files
+ end
+ end
+
+ desc "Builds #{@release_name}"
+ task :build
+
+ desc "Installs #{@release_name}"
+ task :install => :build
+
+ desc "Releases #{@release_name}"
+ task :release => :build
+
+ desc "Start IRB with all runtime dependencies loaded"
+ task :console, [:script] do |t,args|
+ original_load_path = $LOAD_PATH
+
+ if @bundler
+ require 'bundler'
+ Bundler.setup(:default)
+ end
+
+ # add the project code directories to the $LOAD_PATH
+ @load_paths.each do |dir|
+ $LOAD_PATH.unshift(File.join(@root,dir))
+ end
+
+ # clear ARGV so IRB is not confused
+ ARGV.clear
+
+ require 'irb'
+
+ # set the optional script to run
+ IRB.conf[:SCRIPT] = args.script
+ IRB.start
+
+ # return the $LOAD_PATH to it's original state
+ $LOAD_PATH.reject! do |path|
+ !(original_load_path.include?(path))
+ end
+ end
+
+ desc 'Displays the current version'
+ task :version do
+ puts @version
+ end
+ end
+
+ def define_scm_tasks
+ task :status do
+ changes = @scm.status
+
+ unless changes.empty?
+ legend = @scm.class::STATUSES.invert
+
+ puts "The following files were modified:"
+ changes.each do |path,status|
+ puts "#{legend[status]}\t#{path}"
+ end
+ puts
+
+ abort "The project has uncommitted changes!"
+ end
+ end
+ task :build => :status
+
+ namespace :release do
+ task :tag do
+ # ensure the repository is not out-of-sync
+ unless @scm.push
+ abort "Could not push changes"
+ end
+
+ tag_name = "#{@tag_prefix}#{@version}"
+
+ unless @scm.tag(tag_name)
+ abort "Could not create tag #{tag_name}"
+ end
+
+ @scm.push(:tags => true)
+ end
+ end
+ task :release => 'release:tag'
+ end
+
+ #
+ # Defines the RubyGems specific tasks.
+ #
+ def define_rubygem_tasks
+ @gem_pkg = pkg_file('gem')
+
+ namespace :build do
+ task :gem => ['pkg'] do
+ builder = Gem::Builder.new(@gemspec)
+
+ mv builder.build, @gem_pkg
+ end
+ end
+
+ task :build => 'build:gem'
+ task :gem => 'build:gem' # backwards compatibility with Hoe
+
+ namespace :install do
+ task :gem => ['build:gem'] do
+ unless File.file?(@gem_pkg)
+ abort "Could not find #{@gem_pkg}!"
+ end
+
+ gem 'install', @gem_pkg
+ end
+
+ unless @bundler
+ desc 'Installs missing dependencies'
+ task :deps do
+ install_missing_dependency = lambda { |dep|
+ install_dependency(dep) unless Gem.available?(dep)
+ }
+
+ @gemspec.runtime_dependencies.each(&install_missing_dependency)
+ @gemspec.development_dependencies.each(&install_missing_dependency)
+ end
+ end
+ end
+ task :install => 'install:gem'
+ task :install_gem => 'install:gem' # backwards compatibility with Hoe
+
+ if @gemcutter
+ namespace :release do
+ task :gem => 'build:gem' do
+ unless File.file?(@gem_pkg)
+ abort "Could not find #{@gem_pkg}!"
+ end
+
+ arguments = []
+
+ if @gemcutter.kind_of?(String)
+ arguments << '--host' << @gemcutter
+ end
+
+ gem 'push', @gem_pkg, *arguments
+ end
+ end
+
+ task :release => ['release:gem']
+ end
+ end
+
+ #
+ # Defines the project tasks.
+ #
+ def define
+ define_core_tasks
+ define_scm_tasks if @scm
+ define_rubygem_tasks if @gemspec
+ end
+
+ def pkg_file(ext)
+ File.join('pkg',"#{@name}-#{@version}.#{ext}")
+ end
+
+ #
+ # Runs a program with optional arguments.
+ #
+ # @param [String] program
+ # The program to run.
+ #
+ # @param [Array<String>] arguments
+ # Optional arguments.
+ #
+ # @return [true]
+ # The program was executed successfully.
+ #
+ def run(program,*arguments)
+ show_command = ([program] + arguments).join(' ')
+
+ unless rake_system(program,*arguments)
+ abort "Command failed: #{show_command}"
+ end
+
+ return true
+ end
+
+ #
+ # Runs a RubyGems command.
+ #
+ # @param [Array<String>]
+ # The arguments to pass to RubyGems.
+ #
+ # @return [true]
+ # The command was executed successfully.
+ #
+ # @see #run
+ #
+ def gem(*arguments)
+ run(RUBY,'-S','gem',*arguments)
+ end
+
+ #
+ # Installs a dependency.
+ #
+ # @param [Gem::Dependency] dep
+ # The RubyGems dependency to be installed.
+ #
+ # @return [true]
+ # Specifies that the dependency was successfully installed.
+ #
+ def install_dependency(dep)
+ arguments = []
+
+ # enable install pre-releases
+ arguments << '--prerelease' if dep.prerelease?
+
+ # specify the version requirements
+ dep.versions.each { |v| arguments << '--version' << v }
+
+ gem 'install', dep.name, *arguments
+ end
+
+ end
+end
127 project-tasks.gemspec
@@ -0,0 +1,127 @@
+# encoding: utf-8
+
+require 'yaml'
+
+Gem::Specification.new do |gemspec|
+ files = if File.directory?('.git')
+ `git ls-files`.split($/)
+ elsif File.directory?('.hg')
+ `hg manifest`.split($/)
+ elsif File.directory?('.svn')
+ `svn ls -R`.split($/).select { |path| File.file?(path) }
+ else
+ Dir['{**/}{.*,*}'].select { |path| File.file?(path) }
+ end
+
+ filter_files = lambda { |paths|
+ case paths
+ when Array
+ (files & paths)
+ when String
+ (files & Dir[paths])
+ end
+ }
+
+ version = {
+ :file => 'lib/ore/tasks/version.rb',
+ :constant => 'Ore::Tasks::VERSION'
+ }
+
+ defaults = {
+ 'name' => File.basename(File.dirname(__FILE__)),
+ 'files' => files,
+ 'executables' => filter_files['bin/*'].map { |path| File.basename(path) },
+ 'test_files' => filter_files['{test/{**/}*_test.rb,spec/{**/}*_spec.rb}'],
+ 'extra_doc_files' => filter_files['*.{txt,rdoc,md,markdown,tt,textile}'],
+ }
+
+ metadata = defaults.merge(YAML.load_file('gemspec.yml'))
+
+ gemspec.name = metadata.fetch('name',defaults[:name])
+ gemspec.version = if metadata['version']
+ metadata['version']
+ elsif File.file?(version[:file])
+ require File.join('.',version[:file])
+ eval(version[:constant])
+ end
+
+ gemspec.summary = metadata.fetch('summary',metadata['description'])
+ gemspec.description = metadata.fetch('description',metadata['summary'])
+
+ case metadata['license']
+ when Array
+ gemspec.licenses = metadata['license']
+ when String
+ gemspec.license = metadata['license']
+ end
+
+ case metadata['authors']
+ when Array
+ gemspec.authors = metadata['authors']
+ when String
+ gemspec.author = metadata['authors']
+ end
+
+ gemspec.email = metadata['email']
+ gemspec.homepage = metadata['homepage']
+
+ case metadata['require_paths']
+ when Array
+ gemspec.require_paths = metadata['require_paths']
+ when String
+ gemspec.require_path = metadata['require_paths']
+ end
+
+ gemspec.files = filter_files[metadata['files']]
+
+ gemspec.executables = metadata['executables']
+ gemspec.extensions = metadata['extensions']
+
+ if Gem::VERSION < '1.7.'
+ gemspec.default_executable = gemspec.executables.first
+ end
+
+ gemspec.test_files = filter_files[metadata['test_files']]
+
+ unless gemspec.files.include?('.document')
+ gemspec.extra_rdoc_files = metadata['extra_doc_files']
+ end
+
+ gemspec.post_install_message = metadata['post_install_message']
+ gemspec.requirements = metadata['requirements']
+
+ if gemspec.respond_to?(:required_ruby_version=)
+ gemspec.required_ruby_version = metadata['required_ruby_version']
+ end
+
+ if gemspec.respond_to?(:required_rubygems_version=)
+ gemspec.required_rubygems_version = metadata['required_ruby_version']
+ end
+
+ parse_versions = lambda { |versions|
+ case versions
+ when Array
+ versions.map { |v| v.to_s }
+ when String
+ versions.split(/,\s*/)
+ end
+ }
+
+ if metadata['dependencies']
+ metadata['dependencies'].each do |name,versions|
+ gemspec.add_dependency(name,parse_versions[versions])
+ end
+ end
+
+ if metadata['runtime_dependencies']
+ metadata['runtime_dependencies'].each do |name,versions|
+ gemspec.add_runtime_dependency(name,parse_versions[versions])
+ end
+ end
+
+ if metadata['development_dependencies']
+ metadata['development_dependencies'].each do |name,versions|
+ gemspec.add_development_dependency(name,parse_versions[versions])
+ end
+ end
+end
2  spec/spec_helper.rb
@@ -0,0 +1,2 @@
+gem 'rspec', '~> 2.4'
+require 'rspec'
Please sign in to comment.
Something went wrong with that request. Please try again.