seabass 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION ADDED
@@ -0,0 +1,2 @@
1
+ 0.1.0
2
+
@@ -0,0 +1,28 @@
1
+ require 'rubygems'
2
+ require 'rubygems/gem_runner'
3
+ require 'rubygems/exceptions'
4
+
5
+ required_version = Gem::Requirement.new "> 1.8.5"
6
+
7
+ unless required_version.satisfied_by? Gem.ruby_version then
8
+ abort "Expected Ruby Version #{required_version}, was #{Gem.ruby_version}"
9
+ end
10
+
11
+ def install(lib)
12
+ begin
13
+ matches = Gem.source_index.find_name(lib)
14
+ if matches.empty?
15
+ puts "Installing #{lib}"
16
+ Gem::GemRunner.new.run ['install', lib]
17
+ else
18
+ puts "Found #{lib} gem - skipping"
19
+ end
20
+ rescue Gem::SystemExitException => e
21
+ end
22
+ end
23
+
24
+ puts "Installing required dependencies"
25
+ install 'rake'
26
+ install 'albacore'
27
+ install 'jeweler'
28
+ install 'rspec'
@@ -0,0 +1,3 @@
1
+ create_task :robocopy, Proc.new { Robocopy.new } do |r|
2
+ r.execute
3
+ end
@@ -0,0 +1,17 @@
1
+ class Env
2
+ attr_reader :tools
3
+
4
+ def initialize(tools = Tools.new)
5
+ @tools = tools
6
+ end
7
+
8
+
9
+ class Tools
10
+ attr_accessor :robocopy
11
+ def initialize()
12
+ tools_dir = File.dirname(__FILE__) + '/../tools/'
13
+ @robocopy = tools_dir + 'robocopy.exe'
14
+ end
15
+ end
16
+ end
17
+
@@ -0,0 +1,5 @@
1
+ class Log
2
+ def self.message(message, type)
3
+ puts message
4
+ end
5
+ end
@@ -0,0 +1,55 @@
1
+ require 'albacore/support/albacore_helper'
2
+
3
+ class Robocopy
4
+ include RunCommand
5
+ include YAMLConfig
6
+ include Logging
7
+
8
+ attr_accessor :files, :directories, :destination, :mirror
9
+
10
+ def initialize(env = @@env, executor = Executor.new)
11
+ @env = env
12
+ @files = []
13
+ @directories = []
14
+ @executor = executor
15
+ @mirror = false
16
+ end
17
+
18
+ def execute()
19
+ raise "No files or directories were specified" if @files.length == 0 and @directories.length == 0
20
+ raise "Destination folder was not specified" if @destination.nil?
21
+
22
+ copy = lambda { |type, collection|
23
+ collection.each do |f|
24
+ command = "#{@env.tools.robocopy} " + case type
25
+ when 'file' then file_command(f, @destination)
26
+ when 'directory' then directory_command(f, @destination)
27
+ else raise "Unknown copy type"
28
+ end
29
+ command += " /MIR" if @mirror
30
+
31
+ Log.message("Copying #{f} #{destination}; #{command}", :info)
32
+ @executor.run(command)
33
+ end
34
+ }
35
+
36
+ copy.call('file', @files)
37
+ copy.call('directory', @directories)
38
+ end
39
+
40
+ private
41
+
42
+ def file_command(path, destination)
43
+ "#{File.dirname(path)} #{destination} #{File.basename(path)}"
44
+ end
45
+
46
+ def directory_command(path, destination)
47
+ "#{path} #{destination} /E"
48
+ end
49
+ end
50
+
51
+ class Executor
52
+ def run(command)
53
+ %x[#{command}]
54
+ end
55
+ end
data/lib/seabass.rb ADDED
@@ -0,0 +1,13 @@
1
+ $: << File.expand_path(File.dirname(__FILE__))
2
+ $: << File.expand_path(File.join(File.dirname(__FILE__), "seabass"))
3
+ $: << File.expand_path(File.join(File.dirname(__FILE__), "rake"))
4
+
5
+ require 'albacore'
6
+
7
+ include_files = lambda { |p|
8
+ Dir.glob(File.join(File.expand_path(File.dirname(__FILE__)), p)).each {|f| require f }
9
+ }
10
+
11
+ include_files.call('seabass/*.rb')
12
+ include_files.call('rake/*.rb')
13
+ @@env = Env.new
Binary file
data/rakefile.rb ADDED
@@ -0,0 +1,46 @@
1
+ require 'lib/seabass'
2
+
3
+ namespace :specs do
4
+ require 'spec/rake/spectask'
5
+
6
+ @spec_opts = '--colour --format specdoc'
7
+
8
+ desc "Run functional specs for Albacore"
9
+ Spec::Rake::SpecTask.new :all do |t|
10
+ t.spec_files = FileList['specs/*_spec.rb']
11
+ t.spec_opts << @spec_opts
12
+ end
13
+ end
14
+
15
+ namespace :example do
16
+ require 'rubygems'
17
+
18
+ robocopy do |r|
19
+ r.files << "foo.txt"
20
+ r.files << "bar.txt"
21
+ r.directories << "baz"
22
+ r.destination = "foo"
23
+ end
24
+ end
25
+
26
+ namespace :jeweler do
27
+ begin
28
+ require 'jeweler'
29
+ Jeweler::Tasks.new do |gs|
30
+ gs.name = "seabass"
31
+ gs.summary = "Seabass-Safe Rake Tasks For The Deployment Of .NET Systems"
32
+ gs.description = "Easily deploy your .NET solutions with Ruby and Rake, using this suite of Rake tasks."
33
+ gs.email = "jamiehollingworth@gmail.com"
34
+ gs.homepage = "http://github.com/jhollingworth/seabass"
35
+ gs.authors = ["James Hollingworth"]
36
+ gs.has_rdoc = false
37
+ gs.files.exclude("seabass.gemspec", ".gitignore")
38
+ gs.add_dependency('rake', '>= 0.1.5')
39
+ gs.add_development_dependency('rspec', '>= 1.2.8')
40
+ gs.add_development_dependency('jeweler', '>= 1.2.1')
41
+ end
42
+ Jeweler::GemcutterTasks.new
43
+ rescue LoadError
44
+ puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
45
+ end
46
+ end
data/readme.textile ADDED
@@ -0,0 +1,25 @@
1
+ h1. Seabass
2
+
3
+ A suite of Seabass-safe Rake tasks for deploying .NET applications
4
+
5
+ h1. Installation
6
+
7
+ To install the gem you just need to run
8
+
9
+ <pre>
10
+ gem install seabass
11
+ </pre>
12
+
13
+ h1. Example
14
+
15
+ <pre>
16
+ require 'rubygems'
17
+ require 'seabass'
18
+
19
+ robocopy do |r|
20
+ r.files << "foo.txt"
21
+ r.files << "bar.txt"
22
+ r.directories << "c:/temp/source/baz"
23
+ r.destination = "c:/temp/destination"
24
+ end
25
+ </pre>
@@ -0,0 +1,16 @@
1
+ class MockEnv
2
+
3
+ attr_reader :tools
4
+
5
+ def initialize()
6
+ @tools = MockTools.new
7
+ end
8
+
9
+ class MockTools
10
+ attr_reader :robocopy
11
+
12
+ def initialize()
13
+ @robocopy = 'robocopy'
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,10 @@
1
+ class MockExecutor
2
+ attr_accessor :commands
3
+
4
+ def initialize()
5
+ @commands = []
6
+ end
7
+ def run(command)
8
+ @commands << command
9
+ end
10
+ end
@@ -0,0 +1,13 @@
1
+ require File.dirname(__FILE__) + '/mock_env'
2
+ require File.dirname(__FILE__) + '/mock_executor'
3
+
4
+ class MockRobocopy < Robocopy
5
+
6
+ attr_accessor :executor
7
+
8
+ def initialize()
9
+ @executor = MockExecutor.new
10
+ super(MockEnv.new, @executor)
11
+ end
12
+ end
13
+
@@ -0,0 +1,86 @@
1
+ require "spec"
2
+ require File.dirname(__FILE__) + '/../lib/seabass'
3
+ require File.dirname(__FILE__) + '/mocks/mock_robocopy'
4
+
5
+ describe "When I do not specify a destination" do
6
+
7
+ before(:all) do
8
+ @command = MockRobocopy.new
9
+ @command.destination = ""
10
+ end
11
+
12
+ it "should raise an exception" do
13
+ lambda { @command.execute }.should raise_error
14
+ end
15
+ end
16
+
17
+ describe "When I do not specify either files or directories" do
18
+
19
+ before(:all) do
20
+ @command = MockRobocopy.new
21
+ @command.destination = "c:\foo"
22
+ end
23
+
24
+ it "should raise an exception" do
25
+ lambda { @command.execute }.should raise_error
26
+ end
27
+ end
28
+
29
+ describe "When I copy a single file" do
30
+
31
+ before(:all) do
32
+ @command = MockRobocopy.new
33
+ @command.files << "c:/foo.zip"
34
+ @command.destination = "c:/foo"
35
+ @command.execute
36
+ end
37
+
38
+ it "should copy the file" do
39
+ @command.executor.commands.length.should == 1
40
+ @command.executor.commands[0].should include('robocopy c:/ c:/foo foo.zip')
41
+ end
42
+ end
43
+
44
+ describe "When I copy multiple files" do
45
+ before(:all) do
46
+ @command = MockRobocopy.new
47
+ @command.files << "c:/foo.zip"
48
+ @command.files << "c:/bar.zip"
49
+ @command.destination = "c:/foo"
50
+ @command.execute
51
+ end
52
+
53
+ it "should copy all the files" do
54
+ @command.executor.commands.length.should == 2
55
+ @command.executor.commands[0].should include 'robocopy c:/ c:/foo foo.zip'
56
+ @command.executor.commands[1].should include 'robocopy c:/ c:/foo bar.zip'
57
+ end
58
+ end
59
+
60
+ describe "When I copy a directory" do
61
+ before(:all) do
62
+ @command = MockRobocopy.new
63
+ @command.directories << "c:/bar"
64
+ @command.destination = "c:/foo"
65
+ @command.execute
66
+ end
67
+
68
+ it "should copy the directory" do
69
+ @command.executor.commands.length.should == 1
70
+ @command.executor.commands[0].should include 'robocopy c:/bar c:/foo /E'
71
+ end
72
+ end
73
+
74
+ describe "when I want to mirror two folders" do
75
+ before(:all) do
76
+ @command = MockRobocopy.new
77
+ @command.directories << "c:/bar"
78
+ @command.destination = "c:/foo"
79
+ @command.mirror = true
80
+ @command.execute
81
+ end
82
+
83
+ it "should include the mirror switch" do
84
+ @command.executor.commands[0].should include '/MIR'
85
+ end
86
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: seabass
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - James Hollingworth
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-07-28 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rake
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 17
30
+ segments:
31
+ - 0
32
+ - 1
33
+ - 5
34
+ version: 0.1.5
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: rspec
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 15
46
+ segments:
47
+ - 1
48
+ - 2
49
+ - 8
50
+ version: 1.2.8
51
+ type: :development
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: jeweler
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 29
62
+ segments:
63
+ - 1
64
+ - 2
65
+ - 1
66
+ version: 1.2.1
67
+ type: :development
68
+ version_requirements: *id003
69
+ description: Easily deploy your .NET solutions with Ruby and Rake, using this suite of Rake tasks.
70
+ email: jamiehollingworth@gmail.com
71
+ executables: []
72
+
73
+ extensions: []
74
+
75
+ extra_rdoc_files:
76
+ - readme.textile
77
+ files:
78
+ - VERSION
79
+ - install_dependencies.rb
80
+ - lib/rake/robocopy_task.rb
81
+ - lib/seabass.rb
82
+ - lib/seabass/env.rb
83
+ - lib/seabass/log.rb
84
+ - lib/seabass/robocopy.rb
85
+ - lib/tools/robocopy.exe
86
+ - rakefile.rb
87
+ - readme.textile
88
+ - specs/mocks/mock_env.rb
89
+ - specs/mocks/mock_executor.rb
90
+ - specs/mocks/mock_robocopy.rb
91
+ - specs/robocopy_spec.rb
92
+ has_rdoc: true
93
+ homepage: http://github.com/jhollingworth/seabass
94
+ licenses: []
95
+
96
+ post_install_message:
97
+ rdoc_options:
98
+ - --charset=UTF-8
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ hash: 3
107
+ segments:
108
+ - 0
109
+ version: "0"
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ hash: 3
116
+ segments:
117
+ - 0
118
+ version: "0"
119
+ requirements: []
120
+
121
+ rubyforge_project:
122
+ rubygems_version: 1.3.7
123
+ signing_key:
124
+ specification_version: 3
125
+ summary: Seabass-Safe Rake Tasks For The Deployment Of .NET Systems
126
+ test_files: []
127
+