rubygems-tasks 0.1.0.pre1

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.
@@ -0,0 +1,47 @@
1
+ require 'rubygems/tasks/task'
2
+
3
+ module Gem
4
+ class Tasks
5
+ #
6
+ # The `install` task.
7
+ #
8
+ class Install < Task
9
+
10
+ #
11
+ # Initializes the `install` task.
12
+ #
13
+ # @param [Hash] options
14
+ # Additional options.
15
+ #
16
+ def initialize(options={})
17
+ super()
18
+
19
+ yield self if block_given?
20
+ define
21
+ end
22
+
23
+ #
24
+ # Defines the `install` task.
25
+ #
26
+ def define
27
+ namespace :install do
28
+ @project.builds.each do |build,packages|
29
+ path = packages[:gem]
30
+
31
+ task build => path do
32
+ status "Installing #{File.basename(path)} ..."
33
+
34
+ run 'gem', 'install', '-q', path
35
+ end
36
+ end
37
+ end
38
+
39
+ desc "Installs all built gem packages"
40
+ gemspec_tasks :install
41
+
42
+ task :install_gem => :install # backwards compatibility with Hoe
43
+ end
44
+
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,80 @@
1
+ module Gem
2
+ class Tasks
3
+ #
4
+ # Provides helper methods for printing messages.
5
+ #
6
+ module Printing
7
+
8
+ # ANSI 'bright' color code
9
+ ANSI_BRIGHT = "\e[1m"
10
+
11
+ # ANSI 'clear' color code
12
+ ANSI_CLEAR = "\e[0m"
13
+
14
+ # ANSI 'green' color code
15
+ ANSI_GREEN = "\e[32m"
16
+
17
+ # ANSI 'yellow' color code
18
+ ANSI_YELLOW = "\e[33m"
19
+
20
+ # ANSI 'red' color code
21
+ ANSI_RED = "\e[31m"
22
+
23
+ # Prefix for all status messages
24
+ STATUS_PREFIX = if $stdout.tty?
25
+ "#{ANSI_GREEN}#{ANSI_BRIGHT}>>>#{ANSI_CLEAR}"
26
+ else
27
+ ">>>"
28
+ end
29
+
30
+ # Prefix for all debugging messages
31
+ DEBUG_PREFIX = if $stderr.tty?
32
+ "#{ANSI_YELLOW}#{ANSI_BRIGHT}>>>#{ANSI_CLEAR}"
33
+ else
34
+ ">>>"
35
+ end
36
+
37
+ # Prefix for all error messages
38
+ ERROR_PREFIX = if $stderr.tty?
39
+ "#{ANSI_RED}#{ANSI_BRIGHT}!!!#{ANSI_CLEAR}"
40
+ else
41
+ "!!!"
42
+ end
43
+
44
+ protected
45
+
46
+ #
47
+ # Prints a status message.
48
+ #
49
+ # @param [String] message
50
+ # The message to print.
51
+ #
52
+ def status(message)
53
+ $stdout.puts "#{STATUS_PREFIX} #{message}"
54
+ end
55
+
56
+ #
57
+ # Prints a debugging message.
58
+ #
59
+ # @param [String] message
60
+ # The message to print.
61
+ #
62
+ def debug(message)
63
+ if Rake.application.options.trace
64
+ $stderr.puts "#{DEBUG_PREFIX} #{message}"
65
+ end
66
+ end
67
+
68
+ #
69
+ # Prints an error message and exits.
70
+ #
71
+ # @param [String] message
72
+ # The message to print.
73
+ #
74
+ def error(message)
75
+ $stderr.puts "#{ERROR_PREFIX} #{message}"
76
+ end
77
+
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,113 @@
1
+ require 'rake/tasklib'
2
+
3
+ require 'set'
4
+
5
+ module Gem
6
+ class Tasks
7
+ class Project
8
+
9
+ # Supported SCMs and their control directories.
10
+ SCM_DIRS = {
11
+ :git => '.git',
12
+ :hg => '.hg',
13
+ :svn => '.svn'
14
+ }
15
+
16
+ # The `pkg/` directory.
17
+ PKG_DIR = 'pkg'
18
+
19
+ #
20
+ # The project directory.
21
+ #
22
+ # @return [String]
23
+ # The path to the project.
24
+ #
25
+ attr_reader :root
26
+
27
+ #
28
+ # The name of the project.
29
+ #
30
+ # @return [String]
31
+ # The project name.
32
+ #
33
+ attr_reader :name
34
+
35
+ #
36
+ # @return [Symbol, nil]
37
+ # The SCM the project is using.
38
+ #
39
+ attr_reader :scm
40
+
41
+ #
42
+ # The builds and gemspecs of the project.
43
+ #
44
+ # @return [Hash{String => Gem::Specification}]
45
+ # The hash of builds and their gemspecs.
46
+ #
47
+ attr_reader :gemspecs
48
+
49
+ #
50
+ # The builds and their packages.
51
+ #
52
+ # @return [Hash{String => Hash{String => String}}]
53
+ # The hash of builds and their respective packages.
54
+ #
55
+ attr_reader :builds
56
+
57
+ #
58
+ # Initializes the project.
59
+ #
60
+ # @param [String] root
61
+ # The root directory of the project.
62
+ #
63
+ def initialize(root=Dir.pwd)
64
+ @root = root
65
+ @name = File.basename(@root)
66
+
67
+ @scm, _ = SCM_DIRS.find do |scm,dir|
68
+ File.directory?(File.join(@root,dir))
69
+ end
70
+
71
+ Dir.chdir(@root) do
72
+ @gemspecs = Hash[Dir['*.gemspec'].map { |path|
73
+ [File.basename(path).chomp('.gemspec'), Specification.load(path)]
74
+ }]
75
+ end
76
+
77
+ @builds = {}
78
+
79
+ @gemspecs.each do |name,gemspec|
80
+ @builds[name] = Hash.new do |packages,format|
81
+ packages[format] = File.join(PKG_DIR,"#{gemspec.full_name}.#{format}")
82
+ end
83
+ end
84
+
85
+ @bundler = File.file?(File.join(@root,'Gemfile'))
86
+ end
87
+
88
+ #
89
+ # Maps project directories to projects.
90
+ #
91
+ # @return [Hash{String => Project}]
92
+ # Project directories and project objects.
93
+ #
94
+ # @api semipublic
95
+ #
96
+ def self.directories
97
+ @@directories ||= Hash.new do |hash,key|
98
+ hash[key] = new(key)
99
+ end
100
+ end
101
+
102
+ #
103
+ # Specifies whether the project uses Bundler.
104
+ #
105
+ # @return [Boolean]
106
+ #
107
+ def bundler?
108
+ @bundler
109
+ end
110
+
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,63 @@
1
+ require 'rubygems/tasks/task'
2
+
3
+ module Gem
4
+ class Tasks
5
+ #
6
+ # The `push` task.
7
+ #
8
+ class Push < Task
9
+
10
+ # The Gemcutter host to push gems to.
11
+ attr_accessor :host
12
+
13
+ #
14
+ # Initializes the `push` task.
15
+ #
16
+ # @param [Hash] options
17
+ # Additional options.
18
+ #
19
+ # @option options [String] :host
20
+ # The Gemcutter host to push gems to.
21
+ #
22
+ def initialize(options={})
23
+ super()
24
+
25
+ @host = options[:host]
26
+
27
+ yield self if block_given?
28
+ define
29
+ end
30
+
31
+ #
32
+ # Defines the `push` task.
33
+ #
34
+ def define
35
+ namespace :push do
36
+ @project.builds.each do |build,packages|
37
+ path = packages[:gem]
38
+
39
+ task build => path do
40
+ arguments = []
41
+
42
+ if @host
43
+ arguments << '--host' << @host
44
+
45
+ status "Pushing #{File.basename(path)} to #{@host} ..."
46
+ else
47
+ status "Pushing #{File.basename(path)} ..."
48
+ end
49
+
50
+ run 'gem', 'push', path, *arguments
51
+ end
52
+ end
53
+ end
54
+
55
+ gemspec_tasks :push
56
+
57
+ # backwards compatibility for Hoe
58
+ task :publish => :push
59
+ end
60
+
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,49 @@
1
+ require 'rubygems/tasks/task'
2
+
3
+ module Gem
4
+ class Tasks
5
+ #
6
+ # The `release` task.
7
+ #
8
+ class Release < Task
9
+
10
+ #
11
+ # Initializes the `release` task.
12
+ #
13
+ # @param [Hash] options
14
+ # Additional options for the `release` task.
15
+ #
16
+ def initialize(options={})
17
+ super()
18
+
19
+ yield self if block_given?
20
+ define
21
+ end
22
+
23
+ #
24
+ # Defines the `release` task.
25
+ #
26
+ def define
27
+ @project.gemspecs.each_key do |name|
28
+ task :release => [
29
+ "build:#{name}",
30
+ 'scm:tag',
31
+ 'scm:push',
32
+ "push:#{name}",
33
+ "sign:#{name}"
34
+ ].select { |name| task?(name) }
35
+ end
36
+
37
+ desc "Performs a release"
38
+ task :release => [
39
+ :build,
40
+ 'scm:tag',
41
+ 'scm:push',
42
+ :push,
43
+ :sign
44
+ ].select { |name| task?(name) }
45
+ end
46
+
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,3 @@
1
+ require 'rubygems/tasks/scm/status'
2
+ require 'rubygems/tasks/scm/tag'
3
+ require 'rubygems/tasks/scm/push'
@@ -0,0 +1,56 @@
1
+ require 'rubygems/tasks/task'
2
+
3
+ module Gem
4
+ class Tasks
5
+ module SCM
6
+ #
7
+ # The `scm:push` task.
8
+ #
9
+ class Push < Task
10
+
11
+ #
12
+ # Initializes the `scm:push` task.
13
+ #
14
+ # @param [Hash] options
15
+ # Additional options.
16
+ #
17
+ def initialize(options={})
18
+ super()
19
+
20
+ yield self if block_given?
21
+ define
22
+ end
23
+
24
+ #
25
+ # Defines the `scm:push` task.
26
+ #
27
+ def define
28
+ namespace :scm do
29
+ task :push do
30
+ status "Pushing commits ..."
31
+
32
+ unless push!
33
+ error "Could not push commits"
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ #
40
+ # Pushes commits.
41
+ #
42
+ # @return [Boolean]
43
+ # Specifies whether the commits were successfully pushed.
44
+ #
45
+ def push!
46
+ case @project.scm
47
+ when :git then run 'git', 'push', '--tags'
48
+ when :hg then run 'hg', 'push'
49
+ else true
50
+ end
51
+ end
52
+
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,67 @@
1
+ require 'rubygems/tasks/task'
2
+
3
+ module Gem
4
+ class Tasks
5
+ module SCM
6
+ #
7
+ # The `scm:status` task.
8
+ #
9
+ class Status < Task
10
+
11
+ #
12
+ # Initializes the `status` task.
13
+ #
14
+ # @param [Hash] options
15
+ # Additional options.
16
+ #
17
+ def initialize(options={})
18
+ super()
19
+
20
+ yield self if block_given?
21
+ define
22
+ end
23
+
24
+ #
25
+ # Defines the `status` task.
26
+ #
27
+ def define
28
+ namespace :scm do
29
+ task :status do
30
+ status = self.status
31
+
32
+ unless status.strip.empty?
33
+ puts status
34
+ fail "Project has uncommitted changes!"
35
+ end
36
+ end
37
+ end
38
+
39
+ # do not allow tagging releases when the repository is dirty
40
+ task 'scm:tag' => 'scm:status'
41
+
42
+ # do not allow pushing commits when the repository is dirty
43
+ task 'scm:push' => 'scm:status'
44
+
45
+ # do not allow pushing gems when the repository is dirty
46
+ task :push => 'scm:status'
47
+ end
48
+
49
+ #
50
+ # Checks the status of the project repository.
51
+ #
52
+ # @return [String]
53
+ # The status of the project repository.
54
+ #
55
+ def status
56
+ case @project.scm
57
+ when :git then `git status --porcelain`
58
+ when :hg then `hg status`
59
+ when :svn then `svn status`
60
+ else ''
61
+ end
62
+ end
63
+
64
+ end
65
+ end
66
+ end
67
+ end