dependency_wiring 0.0.28

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.
data/.flow ADDED
@@ -0,0 +1,8 @@
1
+ [branchname]
2
+ master = default
3
+ develop = develop
4
+ feature = feature/
5
+ release = release/
6
+ hotfix = hotfix/
7
+ support = support/
8
+
data/.hgignore ADDED
@@ -0,0 +1,20 @@
1
+ syntax:regexp
2
+ ^\.bundle
3
+ ^\.config
4
+ ^\.yardoc
5
+ ^Gemfile\.lock
6
+ ^InstalledFiles
7
+ ^_yardoc
8
+ ^coverage
9
+ ^doc/
10
+ ^lib/bundler/man
11
+ ^pkg
12
+ ^rdoc
13
+ ^spec/reports
14
+ ^test/tmp
15
+ ^test/version_tmp
16
+ ^tmp
17
+ ^\.rvmrc
18
+ syntax:glob
19
+ *.gem
20
+ *.rbc
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dependency_wiring.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Alessio Caiazza
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # DependencyWiring
2
+
3
+ **Pay attention! Very alpha development stage**
4
+
5
+ Many times I had to manage dependencies versioning for build chains that didn't implement a proper dependencies management process.
6
+
7
+ Sometimes I wrote a ruby script to automatically fetch them, sometimes I used mercurial suberepositories and sometimes I also added them under my own revision control system :(
8
+
9
+ Now DependecyWiring is here. It know nothing about your build chain, it only needs to know sources and destinations!
10
+
11
+ ## Installation
12
+
13
+ Install it yourself as:
14
+
15
+ $ gem install dependency_wiring
16
+
17
+ ## Usage
18
+
19
+ Create a file named `deps.rb` in the root of your project, it's plain ruby but you can use a simple DSL to define your dependencies.
20
+
21
+ mount "/home/nolith/projects/libs/js/jquery-1.78", "deps/jquery"
22
+ hg 'https://bitbucket.org/yujiewu/hgflow', 'deps/lib1', tag: 'v0.9.5'
23
+ git 'git://github.com/rails/rails.git', 'deps/rails', branch: '3-2-stable'
24
+
25
+ Now simply execute `dw wire` and you are done ;)
26
+
27
+ ## Contributing
28
+
29
+ 1. Fork it
30
+ 2. Make your development on develop branch (`hg update develop`) (using HgFlow[1] is greatly appreciated)
31
+ 3. Create new Pull Request
32
+
33
+ [1]: https://bitbucket.org/yujiewu/hgflow
data/Rakefile ADDED
@@ -0,0 +1,59 @@
1
+ require 'rspec/core/rake_task'
2
+ require "bundler/gem_tasks"
3
+
4
+ #monkeypatching - use hg instead of git
5
+ module Bundler
6
+ class GemHelper
7
+ protected
8
+ def hg_clean?
9
+ !(sh("hg su | grep commit:") =~ /^commit: \(clean\)/).nil?
10
+ end
11
+ alias_method :clean?, :hg_clean?
12
+
13
+ def hg_guard_already_tagged
14
+ if sh('hg tags').split(/\n/).include?(version_tag)
15
+ raise("This tag has already been committed to the repo.")
16
+ end
17
+ end
18
+ alias_method :guard_already_tagged, :hg_guard_already_tagged
19
+
20
+ def hg_tag_version
21
+ #sh "hg tag -m \"Version #{version}\" #{version_tag}"
22
+ #Bundler.ui.confirm "Tagged #{version_tag}"
23
+ yield if block_given?
24
+ #rescue
25
+ #Bundler.ui.error "Untagged #{version_tag} due to error"
26
+ #sh_with_code "hg tag --remove #{version_tag}"
27
+ #raise
28
+ end
29
+ alias_method :tag_version, :hg_tag_version
30
+
31
+ def hg_push
32
+ #cmd = "hg push"
33
+ #out, code = sh_with_code(cmd)
34
+ #raise "Couldn't hg push. `#{cmd}' failed with the following output:\n\n#{out}\n" unless code == 0
35
+ #Bundler.ui.confirm "Pushed hg commits and tags"
36
+ end
37
+ alias_method :git_push, :hg_push
38
+ end
39
+ end
40
+
41
+ RSpec::Core::RakeTask.new('spec')
42
+
43
+ def load_dw(args)
44
+ lib = File.expand_path('../lib', __FILE__)
45
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
46
+ puts "executing with #{lib} in $LOAD_PATH"
47
+ require 'dependency_wiring/thor_app'
48
+ DependencyWiring::ThorApp.start(args, {})
49
+ end
50
+
51
+
52
+ desc "Run dw from the development environment"
53
+ task :run, :dw_params do |t, args|
54
+ params = args[:dw_params]
55
+ params = '' if params.nil?
56
+ load_dw params.split(' ')
57
+ end
58
+
59
+ task :run
data/bin/dw ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ require "rubygems"
3
+ require "bundler/setup"
4
+ require 'dependency_wiring/thor_app'
5
+
6
+
7
+ begin
8
+ DependencyWiring::ThorApp.start
9
+ rescue Exception => e
10
+ STDERR.puts e
11
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dependency_wiring/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "dependency_wiring"
8
+ gem.version = DependencyWiring::VERSION
9
+ gem.authors = ["Alessio Caiazza"]
10
+ gem.email = ["nolith@abisso.org"]
11
+ gem.description = %q{Dependency Wiring Tool}
12
+ gem.summary = %q{An agnostic dependency wiring system for project management.}
13
+ gem.homepage = "https://bitbucket.org/nolith/dependency-wiring"
14
+
15
+ gem.files = `hg manifest`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ gem.add_development_dependency "rspec", ">= 2.0.0"
20
+ gem.add_dependency "thor"
21
+ end
@@ -0,0 +1,35 @@
1
+ require 'dependency_wiring/dsl'
2
+
3
+ module DependencyWiring
4
+ class Configuration
5
+ include DSL
6
+
7
+ def initialize(src_file, config={})
8
+ @src_file = src_file
9
+ @config = config
10
+ end
11
+
12
+ def load_dependencies
13
+ init()
14
+ instance_eval(read(), @src_file)
15
+ end
16
+
17
+ def show
18
+ puts "Dependencies list"
19
+ deps().each { |d| puts d }
20
+ end
21
+
22
+ def wire_all
23
+ deps().each do |dep|
24
+ puts "wiring #{dep}"
25
+ dep.prepare_dest
26
+ dep.wire
27
+ end
28
+ end
29
+
30
+ private
31
+ def read()
32
+ File.open(@src_file, 'r') { |f| f.read }
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,29 @@
1
+ require 'dependency_wiring/mount_point'
2
+ require 'dependency_wiring/mercurial'
3
+ require 'dependency_wiring/git'
4
+
5
+
6
+ module DependencyWiring
7
+ module DSL
8
+ @deps = []
9
+ def init
10
+ @deps = []
11
+ end
12
+
13
+ def deps
14
+ @deps
15
+ end
16
+
17
+ def mount(src, dest)
18
+ @deps << MountPoint.new(src, dest)
19
+ end
20
+
21
+ def hg(src,dest, opts={})
22
+ @deps << Mercurial.new(src, dest, opts)
23
+ end
24
+
25
+ def git(src,dest, opts={})
26
+ @deps << Git.new(src, dest, opts)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,77 @@
1
+ require 'dependency_wiring/scm'
2
+
3
+ module DependencyWiring
4
+ class Git < SCM
5
+
6
+ def clone
7
+ ret = sh_with_code("git clone #{git_opts} #{@src} .")
8
+ raise("GIT: Cannot clone #{@src} into #{@dest}! Output: #{ret[0]}") if ret[1] != 0
9
+ rev = git_revision
10
+ update if (rev != @opts[:branc] && rev != default_opts[:rev])
11
+ end
12
+
13
+ def pull
14
+ ret = sh_with_code("git fetch #{@src}")
15
+ raise("GIT: Cannot fetch #{@dest}! Output: #{ret[0]}") if ret[1] != 0
16
+ end
17
+
18
+ def update
19
+ ret = sh_with_code("git checkout #{git_revision}")
20
+ if ret[1] != 0
21
+ raise("GIT: Cannot update #{@dest} to #{git_revision}! Output: #{ret[0]}")
22
+ end
23
+ end
24
+
25
+ def wire
26
+ super
27
+ pull
28
+ update
29
+ end
30
+
31
+ def to_s
32
+ "git(#{@src}, #{@opts}) -> #{@dest}"
33
+ end
34
+
35
+ def default_opts
36
+ { rev: 'HEAD' }
37
+ end
38
+
39
+ def valid_destination?
40
+ if File.directory? @dest
41
+ Dir.chdir(@dest) {
42
+ File.exists? '.git'
43
+ }
44
+ else
45
+ false
46
+ end
47
+ end
48
+
49
+ protected
50
+ def git_opts
51
+ branch = @opts[:branch]
52
+ return "-b #{branch} " unless branch.nil?
53
+ ""
54
+ end
55
+
56
+ def git_revision
57
+ branch = @opts[:branch]
58
+ rev = @opts[:rev]
59
+ tag = @opts[:tag]
60
+ if rev == default_opts[:rev]
61
+ if(!branch.nil? && !tag.nil?)
62
+ raise("Cannot specify tag and branch")
63
+ elsif branch.nil? && !tag.nil?
64
+ tag
65
+ elsif tag.nil? && !branch.nil?
66
+ branch
67
+ else
68
+ rev
69
+ end
70
+ elsif(branch.nil? && tag.nil?)
71
+ rev
72
+ else
73
+ raise("Cannot specify tag, rev and branch")
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,76 @@
1
+ require 'dependency_wiring/scm'
2
+ require 'stringio'
3
+
4
+ module DependencyWiring
5
+ class Mercurial < SCM
6
+
7
+ def clone
8
+ ret = sh_with_code("hg clone #{hg_opts} #{@src} .")
9
+ raise("HG: Cannot clone #{@src} into #{@dest}! Output: #{ret[0]}") if ret[1] != 0
10
+ end
11
+
12
+ def pull
13
+ ret = sh_with_code("hg pull #{hg_opts} #{@src}")
14
+ raise("HG: Cannot pull #{@dest}! Output: #{ret[0]}") if ret[1] != 0
15
+ end
16
+
17
+ def update
18
+ ret = sh_with_code("hg update -C #{hg_revision}")
19
+ if ret[1] != 0
20
+ raise("HG: Cannot update #{@dest} to #{hg_revision}! Output: #{ret[0]}")
21
+ end
22
+ end
23
+
24
+ def wire
25
+ super
26
+ pull
27
+ update
28
+ end
29
+
30
+ def to_s
31
+ "hg(#{@src}, #{@opts}) -> #{@dest}"
32
+ end
33
+
34
+ def default_opts
35
+ { branch: 'default' }
36
+ end
37
+
38
+ def valid_destination?
39
+ ret = sh_with_code('hg su')
40
+ ret[1] == 0
41
+ end
42
+
43
+ protected
44
+ def hg_opts
45
+ opts = StringIO.new
46
+ branch = @opts[:branch]
47
+ opts << "-b #{branch} " unless branch.nil?
48
+ rev = @opts[:rev]
49
+ opts << "-r #{rev} " unless rev.nil?
50
+ tag = @opts[:tag]
51
+ opts << "-r #{tag} " unless tag.nil?
52
+ opts.string
53
+ end
54
+
55
+ def hg_revision
56
+ branch = @opts[:branch]
57
+ rev = @opts[:rev]
58
+ tag = @opts[:tag]
59
+ if branch == default_opts[:branch]
60
+ if(!rev.nil? && !tag.nil?)
61
+ raise("Cannot specify tag, rev")
62
+ elsif rev.nil? && !tag.nil?
63
+ tag
64
+ elsif tag.nil? && !rev.nil?
65
+ rev
66
+ else
67
+ branch
68
+ end
69
+ elsif(rev.nil? && tag.nil?)
70
+ branch
71
+ else
72
+ raise("Cannot specify tag, rev and branch")
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,31 @@
1
+ require 'dependency_wiring/wiring'
2
+ require 'fileutils'
3
+
4
+ module DependencyWiring
5
+ class MountPoint
6
+ include DependencyWiring::Wiring
7
+
8
+ def prepare_dest
9
+ parent = File.split(@dest)[0]
10
+ FileUtils.mkdir_p(parent)
11
+ end
12
+
13
+ def wire
14
+ prepare_dest
15
+ relink
16
+ end
17
+
18
+ protected
19
+
20
+ def relink
21
+ if(File.exists? @dest)
22
+ if(File.symlink? @dest)
23
+ File.delete(@dest)
24
+ else
25
+ raise("#{@dest} already exists!")
26
+ end
27
+ end
28
+ FileUtils.ln_s(@src, @dest)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,44 @@
1
+ require 'dependency_wiring/wiring'
2
+ require 'dependency_wiring/shell_command'
3
+
4
+ module DependencyWiring
5
+ class SCM
6
+ include DependencyWiring::Wiring
7
+ include DependencyWiring::ShellCommand
8
+
9
+ attr_accessor :opts
10
+ def initialize(src, dest, opts = {})
11
+ super(src, dest)
12
+ @opts = default_opts().merge(opts)
13
+ end
14
+
15
+ # def clone
16
+ # end
17
+
18
+ # def pull
19
+ # end
20
+
21
+ # def update
22
+ # end
23
+
24
+ def default_opts
25
+ {}
26
+ end
27
+
28
+ def prepare_dest
29
+ if File.exists?(@dest) && File.directory?(@dest)
30
+ unless valid_destination?
31
+ raise("#{@dest} doesn't seems to be a working copy.")
32
+ end
33
+ else
34
+ super()
35
+ begin
36
+ clone
37
+ rescue Exception => e
38
+ Dir.delete(@dest) if File.exists?(@dest) && File.directory?(@dest)
39
+ raise e
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,21 @@
1
+ module DependencyWiring
2
+ module ShellCommand
3
+ protected
4
+ def sh(cmd, &block)
5
+ out, code = sh_with_code(cmd, &block)
6
+ code == 0 ? out : raise(out.empty? ? "Running `#{cmd}' failed. Run this command directly for more detailed output." : out)
7
+ end
8
+
9
+ def sh_with_code(cmd, &block)
10
+ cmd << " 2>&1"
11
+ outbuf = ''
12
+ Dir.chdir(@dest) {
13
+ outbuf = `#{cmd}`
14
+ if $? == 0
15
+ block.call(outbuf) if block
16
+ end
17
+ }
18
+ [outbuf, $?]
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,30 @@
1
+ require 'dependency_wiring/configuration'
2
+ require 'thor'
3
+
4
+ module DependencyWiring
5
+ class ThorApp < Thor
6
+ DEFAULT_CONF = "deps.rb"
7
+
8
+ desc "version", "print version number"
9
+ def version
10
+ puts "dw tool ver. #{DependencyWiring::VERSION}"
11
+ end
12
+
13
+ desc "show", "prints dependencies mount points"
14
+ def show(file=DEFAULT_CONF)
15
+ load_config(file).show
16
+ end
17
+
18
+ desc "wire", "update all the dependencies"
19
+ def wire(file=DEFAULT_CONF)
20
+ load_config(file).wire_all
21
+ end
22
+
23
+ protected
24
+ def load_config(file)
25
+ c = Configuration.new(file)
26
+ c.load_dependencies
27
+ c
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ module DependencyWiring
2
+ VERSION = "0.0.28"
3
+ end
@@ -0,0 +1,23 @@
1
+ require 'fileutils'
2
+
3
+ module DependencyWiring
4
+ module Wiring
5
+ attr_accessor :src, :dest
6
+ def initialize(src, dest)
7
+ @src = src
8
+ @dest = dest
9
+ end
10
+
11
+ def to_s
12
+ "#{src} -> #{dest}"
13
+ end
14
+
15
+ def prepare_dest
16
+ FileUtils.mkdir_p(@dest)
17
+ end
18
+
19
+ def wire
20
+ prepare_dest
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,5 @@
1
+ require "dependency_wiring/version"
2
+
3
+ module DependencyWiring
4
+
5
+ end
data/spec/git_spec.rb ADDED
@@ -0,0 +1,149 @@
1
+ require "spec_helper"
2
+ require 'dependency_wiring/git'
3
+ require 'fileutils'
4
+ require 'tmpdir'
5
+
6
+ describe DependencyWiring do
7
+ describe 'Git' do
8
+ include FileUtils
9
+
10
+ BRANCH = 'develop'
11
+ TAG = 'v0.0.1'
12
+
13
+ def check_head
14
+ cd(@dest) do
15
+ File.open('test', 'r') do |f|
16
+ f.readline.strip.should == "master-head"
17
+ end
18
+ end
19
+ end
20
+
21
+ def check_branch
22
+ cd(@dest) do
23
+ File.open('test', 'r') do |f|
24
+ f.readline.strip.should == "test"
25
+ f.readline.strip.should == "dev branch"
26
+ end
27
+ end
28
+ end
29
+
30
+ def check_tag
31
+ cd(@dest) do
32
+ File.open('test', 'r') do |f|
33
+ f.readline.strip.should == "test"
34
+ f.eof?.should be true
35
+ end
36
+ end
37
+ end
38
+
39
+ before(:all) do
40
+ @src = Dir.mktmpdir
41
+ cd(@src) do
42
+ `git init .`
43
+ `echo test > test`
44
+ `git add test`
45
+ `git commit -m "test"`
46
+ `git checkout -b develop`
47
+ `echo "dev branch" >> test`
48
+ `git commit -am "dev b"`
49
+ `git checkout master; git tag v0.0.1`
50
+ `echo master-head > test; git commit -am "final"`
51
+ end
52
+ @dest = File.join('test', 'tmp', 'git', 'working_copy')
53
+ end
54
+
55
+ after(:all) do
56
+ rm_rf @src
57
+ rm_rf @dest
58
+ end
59
+
60
+ context "missing git working copy and static repo" do
61
+ before(:each) do
62
+ rm_rf @dest
63
+ @git = DependencyWiring::Git.new(@src, @dest)
64
+ end
65
+ it 'should clone the repo' do
66
+ File.exists?(@dest).should be false
67
+ @git.wire
68
+ File.exists?(@dest).should be true
69
+ end
70
+
71
+ it 'should clone the HEAD' do
72
+ File.exists?(@dest).should be false
73
+ @git.wire
74
+ File.exists?(@dest).should be true
75
+ check_head
76
+ end
77
+
78
+ it 'should clone the devlop branch' do
79
+ File.exists?(@dest).should be false
80
+ @git.opts[:branch] = BRANCH
81
+ @git.wire
82
+ File.exists?(@dest).should be true
83
+ check_branch
84
+ end
85
+
86
+ it 'should clone the v0.0.1 tag' do
87
+ File.exists?(@dest).should be false
88
+ @git.opts[:tag] = TAG
89
+ @git.wire
90
+ File.exists?(@dest).should be true
91
+ check_tag
92
+ end
93
+
94
+ it 'should detect an existing destination that isn\'t a working copy (file)' do
95
+ File.open(@dest, 'w') { |f| f << 'occupied' }
96
+ expect { @git.wire }.to raise_error
97
+ end
98
+
99
+ it 'should detect an existing destination that isn\'t a working copy (folder)' do
100
+ mkdir_p(@dest)
101
+ expect { @git.wire }.to raise_error
102
+ end
103
+ end
104
+
105
+ context "cloned at HEAD" do
106
+ before(:each) do
107
+ rm_rf @dest
108
+ @git = DependencyWiring::Git.new(@src, @dest)
109
+ @git.wire
110
+ check_head
111
+ end
112
+
113
+ it 'should switch to branch on wire' do
114
+ @git.opts[:branch] = 'develop'
115
+ @git.wire
116
+ check_branch
117
+ end
118
+
119
+ it 'should switch to tag on wire' do
120
+ @git.opts[:tag] = 'v0.0.1'
121
+ @git.wire
122
+ check_tag
123
+ end
124
+ end
125
+
126
+ context "cloned at branch" do
127
+ before(:each) do
128
+ rm_rf @dest
129
+ @git = DependencyWiring::Git.new(@src, @dest, branch: 'develop')
130
+ @git.wire
131
+ check_branch
132
+ end
133
+
134
+ it 'should switch to HEAD on wire' do
135
+ @git.opts[:branch] = 'master'
136
+ @git.opts[:rev] = 'HEAD'
137
+ @git.wire
138
+ check_head
139
+ end
140
+
141
+ it 'should switch to tag on wire' do
142
+ @git.opts[:branch] = nil
143
+ @git.opts[:tag] = 'v0.0.1'
144
+ @git.wire
145
+ check_tag
146
+ end
147
+ end
148
+ end
149
+ end
@@ -0,0 +1,150 @@
1
+ require "spec_helper"
2
+ require 'dependency_wiring/mercurial'
3
+ require 'fileutils'
4
+ require 'tmpdir'
5
+
6
+ describe DependencyWiring do
7
+ describe 'Mercurial' do
8
+ include FileUtils
9
+
10
+ BRANCH = 'develop'
11
+ TAG = 'v0.0.1'
12
+
13
+ def check_head
14
+ cd(@dest) do
15
+ File.open('test', 'r') do |f|
16
+ f.readline.strip.should == "master-head"
17
+ end
18
+ end
19
+ end
20
+
21
+ def check_branch
22
+ cd(@dest) do
23
+ File.open('test', 'r') do |f|
24
+ f.readline.strip.should == "test"
25
+ f.readline.strip.should == "dev branch"
26
+ end
27
+ end
28
+ end
29
+
30
+ def check_tag
31
+ cd(@dest) do
32
+ File.open('test', 'r') do |f|
33
+ f.readline.strip.should == "test"
34
+ f.eof?.should be true
35
+ end
36
+ end
37
+ end
38
+
39
+ before(:all) do
40
+ @src = Dir.mktmpdir
41
+ cd(@src) do
42
+ `hg init .`
43
+ `echo test > test`
44
+ `hg add test`
45
+ `hg commit -m "test"`
46
+ `hg branch develop`
47
+ `echo "dev branch" >> test`
48
+ `hg commit -m "dev b"`
49
+ `hg update default; hg tag v0.0.1`
50
+ `echo master-head > test; hg commit -m "final"`
51
+ end
52
+ @dest = File.join('test', 'tmp', 'hg', 'working_copy')
53
+ end
54
+
55
+ after(:all) do
56
+ rm_rf @src
57
+ rm_rf @dest
58
+ end
59
+
60
+ context "missing Mercurial working copy and static repo" do
61
+ before(:each) do
62
+ rm_rf @dest
63
+ @hg = DependencyWiring::Mercurial.new(@src, @dest)
64
+ end
65
+ it 'should clone the repo' do
66
+ File.exists?(@dest).should be false
67
+ @hg.wire
68
+ File.exists?(@dest).should be true
69
+ end
70
+
71
+ it 'should clone the tip' do
72
+ File.exists?(@dest).should be false
73
+ @hg.wire
74
+ File.exists?(@dest).should be true
75
+ check_head
76
+ end
77
+
78
+ it 'should clone the devlop branch' do
79
+ File.exists?(@dest).should be false
80
+ @hg.opts[:branch] = BRANCH
81
+ @hg.wire
82
+ File.exists?(@dest).should be true
83
+ check_branch
84
+ end
85
+
86
+ it 'should clone the v0.0.1 tag' do
87
+ File.exists?(@dest).should be false
88
+ @hg.opts[:tag] = TAG
89
+ @hg.wire
90
+ File.exists?(@dest).should be true
91
+ check_tag
92
+ end
93
+
94
+ it 'should detect an existing destination that isn\'t a working copy (file)' do
95
+ File.open(@dest, 'w') { |f| f << 'occupied' }
96
+ expect { @hg.wire }.to raise_error
97
+ end
98
+
99
+ it 'should detect an existing destination that isn\'t a working copy (folder)' do
100
+ mkdir_p(@dest)
101
+ expect { @hg.wire }.to raise_error
102
+ end
103
+ end
104
+
105
+ context "cloned at tip" do
106
+ before(:each) do
107
+ rm_rf @dest
108
+ @hg = DependencyWiring::Mercurial.new(@src, @dest)
109
+ @hg.wire
110
+ check_head
111
+ end
112
+
113
+ it 'should switch to branch on wire' do
114
+ @hg.opts[:branch] = BRANCH
115
+ @hg.wire
116
+ check_branch
117
+ end
118
+
119
+ it 'should switch to tag on wire' do
120
+ @hg.opts[:tag] = 'v0.0.1'
121
+ @hg.wire
122
+ check_tag
123
+ end
124
+ end
125
+
126
+ context "cloned at branch" do
127
+ before(:each) do
128
+ rm_rf @dest
129
+ @hg = DependencyWiring::Mercurial.new(@src, @dest, branch: BRANCH)
130
+ @hg.wire
131
+ check_branch
132
+ end
133
+
134
+ it 'should switch to tip on wire' do
135
+ @hg.opts[:branch] = 'default'
136
+ #@hg.opts[:rev] = 'tip'
137
+ #puts @hg
138
+ @hg.wire
139
+ check_head
140
+ end
141
+
142
+ it 'should switch to tag on wire' do
143
+ @hg.opts[:branch] = 'default'
144
+ @hg.opts[:tag] = 'v0.0.1'
145
+ @hg.wire
146
+ check_tag
147
+ end
148
+ end
149
+ end
150
+ end
@@ -0,0 +1,49 @@
1
+ require "spec_helper"
2
+ require 'dependency_wiring/mount_point'
3
+ require 'fileutils'
4
+ require 'tmpdir'
5
+
6
+ describe DependencyWiring do
7
+ describe 'MountPoint' do
8
+ include FileUtils
9
+
10
+ before(:all) do
11
+ @src = Dir.mktmpdir
12
+ cd(@src) do
13
+ `echo test > test`
14
+ `echo "dev branch" > branch`
15
+ end
16
+ @dest = File.join('test', 'tmp', 'mount', 'working_copy')
17
+ end
18
+
19
+ after(:all) do
20
+ rm_rf @src
21
+ rm_rf @dest
22
+ end
23
+
24
+ context "first wiring request" do
25
+ before(:each) do
26
+ rm_rf @dest
27
+ @m = DependencyWiring::MountPoint.new(@src, @dest)
28
+ end
29
+
30
+ it 'should link the folder' do
31
+ File.exists?(@dest).should be false
32
+ @m.wire
33
+ File.exists?(@dest).should be true
34
+ end
35
+
36
+ it 'should not fail on second wiring request' do
37
+ File.exists?(@dest).should be false
38
+ @m.wire
39
+ File.exists?(@dest).should be true
40
+ @m.wire
41
+ end
42
+
43
+ it 'should fail if the destination folder exists and isn\'t a symlink' do
44
+ File.open(@dest,'w') { |f| f << "prova" }
45
+ expect { @m.wire }.to raise_error
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,22 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+
8
+ lib = File.expand_path('../../lib', __FILE__)
9
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
10
+ require 'dependency_wiring'
11
+
12
+ RSpec.configure do |config|
13
+ config.treat_symbols_as_metadata_keys_with_true_values = true
14
+ config.run_all_when_everything_filtered = true
15
+ config.filter_run :focus
16
+
17
+ # Run specs in random order to surface order dependencies. If you find an
18
+ # order dependency and want to debug it, you can fix the order by providing
19
+ # the seed, which is printed after each run.
20
+ # --seed 1234
21
+ config.order = 'random'
22
+ end
@@ -0,0 +1,9 @@
1
+ require "spec_helper"
2
+
3
+ describe DependencyWiring do
4
+ context '#VERSION' do
5
+ it 'should exists' do
6
+ DependencyWiring.const_defined?('VERSION').should be_true
7
+ end
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dependency_wiring
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.28
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Alessio Caiazza
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 2.0.0
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 2.0.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: thor
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Dependency Wiring Tool
47
+ email:
48
+ - nolith@abisso.org
49
+ executables:
50
+ - dw
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .flow
55
+ - .hgignore
56
+ - .rspec
57
+ - Gemfile
58
+ - LICENSE.txt
59
+ - README.md
60
+ - Rakefile
61
+ - bin/dw
62
+ - dependency_wiring.gemspec
63
+ - lib/dependency_wiring.rb
64
+ - lib/dependency_wiring/configuration.rb
65
+ - lib/dependency_wiring/dsl.rb
66
+ - lib/dependency_wiring/git.rb
67
+ - lib/dependency_wiring/mercurial.rb
68
+ - lib/dependency_wiring/mount_point.rb
69
+ - lib/dependency_wiring/scm.rb
70
+ - lib/dependency_wiring/shell_command.rb
71
+ - lib/dependency_wiring/thor_app.rb
72
+ - lib/dependency_wiring/version.rb
73
+ - lib/dependency_wiring/wiring.rb
74
+ - spec/git_spec.rb
75
+ - spec/mercurial_spec.rb
76
+ - spec/mount_point_spec.rb
77
+ - spec/spec_helper.rb
78
+ - spec/version_spec.rb
79
+ homepage: https://bitbucket.org/nolith/dependency-wiring
80
+ licenses: []
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ! '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 1.8.25
100
+ signing_key:
101
+ specification_version: 3
102
+ summary: An agnostic dependency wiring system for project management.
103
+ test_files:
104
+ - spec/git_spec.rb
105
+ - spec/mercurial_spec.rb
106
+ - spec/mount_point_spec.rb
107
+ - spec/spec_helper.rb
108
+ - spec/version_spec.rb