fig 0.1.24-universal-darwin9.0

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,46 @@
1
+ # Keeping Windows-specific implementation details here.
2
+
3
+ require 'erb'
4
+ require 'fileutils'
5
+
6
+ # I don't know how to set environment variables so that a sub-shell will
7
+ # be able to use them. Therefore, I'm punting, and creating a batch script
8
+ # on the fly to run a user supplied command.
9
+
10
+ module Fig
11
+ class Windows
12
+
13
+ BATCH_SCRIPT_TEMPLATE = <<EOF
14
+ @echo off
15
+ % ENV.each do |k,v|
16
+ set <%= k %>=<%= v %>
17
+ % end
18
+
19
+ cmd /C <%= command %>
20
+ EOF
21
+
22
+
23
+ def self.with_generated_batch_script(cmd)
24
+ command = cmd.join(' ')
25
+ template = ERB.new(BATCH_SCRIPT_TEMPLATE, 0, "%")
26
+ output = template.result(binding)
27
+ begin
28
+ tf = File.new("C:/tmp/fig_command.bat", "w")
29
+ FileUtils.chmod(0755, tf.path)
30
+ File.open(tf.path, "w") do |fh|
31
+ fh.puts output
32
+ end
33
+ tf.close
34
+ yield tf.path
35
+ ensure
36
+ # tf.delete
37
+ end
38
+ end
39
+
40
+ def self.shell_exec_windows(cmd)
41
+ with_generated_batch_script(cmd) do |f|
42
+ Kernel.exec(f)
43
+ end
44
+ end
45
+ end
46
+ end
data/spec/fig_spec.rb ADDED
@@ -0,0 +1,331 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ require 'rubygems'
4
+ require 'fig/os'
5
+ require 'rake'
6
+ require 'fileutils'
7
+
8
+ class Popen
9
+ if Fig::OS.windows?
10
+ require 'win32/open3'
11
+ def self.popen(*cmd)
12
+ Open3.popen3(*cmd) { |stdin,stdout,stderr|
13
+ yield stdin, stdout, stderr
14
+ }
15
+ end
16
+ elsif Fig::OS.java?
17
+ require 'open3'
18
+ def self.popen(*cmd)
19
+ Open3.popen3(*cmd) { |stdin,stdout,stderr|
20
+ yield stdin, stdout, stderr
21
+ }
22
+ end
23
+ else
24
+ require 'open4'
25
+ def self.popen(*cmd)
26
+ Open4::popen4(*cmd) { |pid, stdin, stdout, stderr|
27
+ yield stdin, stdout, stderr
28
+ }
29
+ end
30
+ end
31
+ end
32
+
33
+ FIG_HOME = File.expand_path(File.dirname(__FILE__) + '/../tmp/fighome')
34
+ FileUtils.mkdir_p(FIG_HOME)
35
+ ENV['FIG_HOME'] = FIG_HOME
36
+
37
+ FIG_REMOTE_DIR = File.expand_path(File.dirname(__FILE__) + '/../tmp/remote')
38
+ FileUtils.mkdir_p(FIG_REMOTE_DIR)
39
+ ENV['FIG_REMOTE_URL'] = "ssh://#{ENV['USER']}@localhost#{FIG_REMOTE_DIR}"
40
+
41
+ FIG_EXE = File.expand_path(File.dirname(__FILE__) + '/../bin/fig')
42
+
43
+ def fig(args, input=nil)
44
+ args = "--file - #{args}" if input
45
+ out = nil
46
+ err = nil
47
+ Popen.popen("#{RUBY} #{FIG_EXE} #{args}") do |stdin, stdout, stderr|
48
+ if input
49
+ stdin.puts input
50
+ stdin.close
51
+ end
52
+ err = stderr.read.strip
53
+ out = stdout.read.strip
54
+ if err != ""
55
+ $stderr.puts err
56
+ end
57
+ end
58
+ return out, err, $?.exitstatus
59
+ end
60
+
61
+ describe "Fig" do
62
+ it "set environment variable from command line" do
63
+ fig('-s FOO=BAR -g FOO')[0].should == 'BAR'
64
+ fig('--set FOO=BAR -g FOO')[0].should == 'BAR'
65
+ end
66
+
67
+ it "set environment variable from fig file" do
68
+ input = <<-END
69
+ config default
70
+ set FOO=BAR
71
+ end
72
+ END
73
+ fig('-g FOO', input)[0].should == 'BAR'
74
+ end
75
+
76
+ it "append environment variable from command line" do
77
+ fig('-p PATH=foo -g PATH').should == ["foo#{File::PATH_SEPARATOR}#{ENV['PATH']}","",0]
78
+ end
79
+
80
+ it "append environment variable from fig file" do
81
+ input = <<-END
82
+ config default
83
+ add PATH=foo
84
+ end
85
+ END
86
+ fig('-g PATH', input).should == ["foo#{File::PATH_SEPARATOR}#{ENV['PATH']}","",0]
87
+ end
88
+
89
+ it "append empty environment variable" do
90
+ fig('-p XYZZY=foo -g XYZZY').should == ["foo","",0]
91
+ end
92
+
93
+ it "should ignore comments" do
94
+ input = <<-END
95
+ #/usr/bin/env fig
96
+
97
+ # Some comment
98
+ config default
99
+ set FOO=BAR # Another comment
100
+ end
101
+ END
102
+ fig('-g FOO', input)[0].should == 'BAR'
103
+ end
104
+
105
+ it "publish to remote repository" do
106
+ FileUtils.rm_rf(FIG_HOME)
107
+ FileUtils.rm_rf(FIG_REMOTE_DIR)
108
+ input = <<-END
109
+ config default
110
+ set FOO=BAR
111
+ end
112
+ END
113
+ fig('--publish foo/1.2.3', input)
114
+ fail unless File.exists? FIG_HOME + "/repos/foo/1.2.3/.fig"
115
+ fail unless File.exists? FIG_REMOTE_DIR + "/foo/1.2.3/.fig"
116
+ fig('-u -i foo/1.2.3 -g FOO')[0].should == 'BAR'
117
+ end
118
+
119
+ it "publish resource to remote repository" do
120
+ FileUtils.rm_rf(FIG_HOME)
121
+ FileUtils.rm_rf(FIG_REMOTE_DIR)
122
+ FileUtils.mkdir_p("tmp/bin")
123
+ File.open("tmp/bin/hello", "w") { |f| f << "echo bar" }
124
+ fail unless system "chmod +x tmp/bin/hello"
125
+ input = <<-END
126
+ resource tmp/bin/hello
127
+ config default
128
+ append PATH=@/tmp/bin
129
+ end
130
+ END
131
+ fig('--publish foo/1.2.3', input)
132
+ fail unless File.exists? FIG_HOME + "/repos/foo/1.2.3/.fig"
133
+ fail unless File.exists? FIG_REMOTE_DIR + "/foo/1.2.3/.fig"
134
+ fig('-u -i foo/1.2.3 -- hello')[0].should == 'bar'
135
+ end
136
+
137
+ it "publish resource to remote repository using command line" do
138
+ FileUtils.rm_rf(FIG_HOME)
139
+ FileUtils.rm_rf(FIG_REMOTE_DIR)
140
+ FileUtils.mkdir_p("tmp/bin")
141
+ File.open("tmp/bin/hello", "w") { |f| f << "echo bar" }
142
+ fail unless system "chmod +x tmp/bin/hello"
143
+ fig('--publish foo/1.2.3 --resource tmp/bin/hello --append PATH=@/tmp/bin')
144
+ fail unless File.exists? FIG_HOME + "/repos/foo/1.2.3/.fig"
145
+ fail unless File.exists? FIG_REMOTE_DIR + "/foo/1.2.3/.fig"
146
+ fig('-u -i foo/1.2.3 -- hello')[0].should == 'bar'
147
+ end
148
+
149
+ it "refuses to overwrite existing version in remote repository without being forced" do
150
+ FileUtils.rm_rf(FIG_HOME)
151
+ FileUtils.rm_rf(FIG_REMOTE_DIR)
152
+ input = <<-END
153
+ config default
154
+ set FOO=SHEEP
155
+ end
156
+ END
157
+ fig('--publish foo/1.2.3', input)
158
+ fail unless File.exists? FIG_HOME + "/repos/foo/1.2.3/.fig"
159
+ fail unless File.exists? FIG_REMOTE_DIR + "/foo/1.2.3/.fig"
160
+ fig('-u -i foo/1.2.3 -g FOO')[0].should == 'SHEEP'
161
+
162
+ input = <<-END
163
+ config default
164
+ set FOO=CHEESE
165
+ end
166
+ END
167
+ (out, err, exitstatus) = fig('--publish foo/1.2.3', input)
168
+ exitstatus.should == 1
169
+ fig('-u -i foo/1.2.3 -g FOO')[0].should == 'SHEEP'
170
+
171
+ (out, err, exitstatus) = fig('--publish foo/1.2.3 --force', input)
172
+ exitstatus.should == 0
173
+ fig('-u -i foo/1.2.3 -g FOO')[0].should == 'CHEESE'
174
+ end
175
+
176
+ it "publishes to the local repo only when told to" do
177
+ FileUtils.rm_rf(FIG_HOME)
178
+ FileUtils.rm_rf(FIG_REMOTE_DIR)
179
+ FileUtils.mkdir_p("tmp/bin")
180
+ File.open("tmp/bin/hello", "w") { |f| f << "echo bar" }
181
+ fail unless system "chmod +x tmp/bin/hello"
182
+ fig('--publish-local foo/1.2.3 --resource tmp/bin/hello --append PATH=@/tmp/bin')
183
+ fail if File.exists? FIG_REMOTE_DIR + "/foo/1.2.3/.fig"
184
+ fig('-m -i foo/1.2.3 -- hello')[0].should == 'bar'
185
+ end
186
+
187
+ it "retrieve resource" do
188
+ FileUtils.rm_rf(FIG_HOME)
189
+ FileUtils.rm_rf(FIG_REMOTE_DIR)
190
+ FileUtils.rm_rf("tmp")
191
+ FileUtils.mkdir_p("tmp/lib")
192
+ File.open("tmp/lib/hello", "w") { |f| f << "some library" }
193
+ input = <<-END
194
+ resource tmp/lib/hello
195
+ config default
196
+ append FOOPATH=@/tmp/lib/hello
197
+ end
198
+ END
199
+ fig('--publish foo/1.2.3', input)
200
+ input = <<-END
201
+ retrieve FOOPATH->tmp/lib2/[package]
202
+ config default
203
+ include foo/1.2.3
204
+ end
205
+ END
206
+ fig('-m', input)
207
+ File.read("tmp/lib2/foo/hello").should == "some library"
208
+ end
209
+
210
+ it "retrieves resource that is a directory" do
211
+ FileUtils.rm_rf(FIG_HOME)
212
+ FileUtils.rm_rf(FIG_REMOTE_DIR)
213
+ FileUtils.rm_rf("tmp")
214
+ FileUtils.mkdir_p("tmp/lib")
215
+ File.open("tmp/lib/hello", "w") { |f| f << "some library" }
216
+ # To copy the contents of a directory, instead of the directory itself,
217
+ # use '/.' as a suffix to the directory name in 'append'.
218
+ input = <<-END
219
+ resource tmp/lib/hello
220
+ config default
221
+ append FOOPATH=@/tmp/lib/.
222
+ end
223
+ END
224
+ fig('--publish foo/1.2.3', input)
225
+ input = <<-END
226
+ retrieve FOOPATH->tmp/lib2/[package]
227
+ config default
228
+ include foo/1.2.3
229
+ end
230
+ END
231
+ fig('-m', input)
232
+ File.read("tmp/lib2/foo/hello").should == "some library"
233
+ end
234
+
235
+ it "retrieve preserves the path after '//' when copying files into your project directory" do
236
+ FileUtils.rm_rf(FIG_HOME)
237
+ FileUtils.rm_rf(FIG_REMOTE_DIR)
238
+ FileUtils.rm_rf("tmp")
239
+ FileUtils.mkdir_p("tmp/include")
240
+ File.open("tmp/include/hello.h", "w") { |f| f << "a header file" }
241
+ File.open("tmp/include/hello2.h", "w") { |f| f << "another header file" }
242
+ input = <<-END
243
+ resource tmp/include/hello.h
244
+ resource tmp/include/hello2.h
245
+ config default
246
+ append INCLUDE=@/tmp//include/hello.h
247
+ append INCLUDE=@/tmp//include/hello2.h
248
+ end
249
+ END
250
+ fig('--publish foo/1.2.3', input)
251
+
252
+ input = <<-END
253
+ retrieve INCLUDE->tmp/include2/[package]
254
+ config default
255
+ include foo/1.2.3
256
+ end
257
+ END
258
+ fig('-u', input)
259
+
260
+ File.read("tmp/include2/foo/include/hello.h").should == "a header file"
261
+ File.read("tmp/include2/foo/include/hello2.h").should == "another header file"
262
+ end
263
+
264
+ it "package multiple resources" do
265
+ FileUtils.rm_rf(FIG_HOME)
266
+ FileUtils.rm_rf(FIG_REMOTE_DIR)
267
+ FileUtils.rm_rf("tmp")
268
+ FileUtils.mkdir_p("tmp/lib")
269
+ File.open("tmp/lib/hello", "w") { |f| f << "some library" }
270
+ File.open("tmp/lib/hello2", "w") { |f| f << "some other library" }
271
+ input = <<-END
272
+ resource tmp/lib/hello
273
+ resource tmp/lib/hello2
274
+ config default
275
+ append FOOPATH=@/tmp/lib/hello
276
+ append FOOPATH=@/tmp/lib/hello2
277
+ end
278
+ END
279
+ fig('--publish foo/1.2.3', input)
280
+ input = <<-END
281
+ retrieve FOOPATH->tmp/lib2/[package]
282
+ config default
283
+ include foo/1.2.3
284
+ end
285
+ END
286
+ fig('-m', input)
287
+ File.read("tmp/lib2/foo/hello").should == "some library"
288
+ File.read("tmp/lib2/foo/hello2").should == "some other library"
289
+ end
290
+
291
+ it "packages multiple resources with wildcards" do
292
+ FileUtils.rm_rf(FIG_HOME)
293
+ FileUtils.rm_rf(FIG_REMOTE_DIR)
294
+ FileUtils.rm_rf("tmp")
295
+ FileUtils.mkdir_p("tmp/lib")
296
+ File.open("tmp/lib/foo.jar", "w") { |f| f << "some library" }
297
+ File.open("tmp/lib/bar.jar", "w") { |f| f << "some other library" }
298
+ input = <<-END
299
+ resource tmp/**/*.jar
300
+ config default
301
+ append FOOPATH=@/tmp/lib/foo.jar
302
+ end
303
+ END
304
+ fig('--publish foo/1.2.3', input)
305
+ input = <<-END
306
+ retrieve FOOPATH->tmp/lib2/[package]
307
+ config default
308
+ include foo/1.2.3
309
+ end
310
+ END
311
+ fig('-m', input)
312
+ File.read("tmp/lib2/foo/foo.jar").should == "some library"
313
+ end
314
+
315
+ it "update local packages if they already exist" do
316
+ FileUtils.rm_rf(FIG_HOME)
317
+ FileUtils.rm_rf(FIG_REMOTE_DIR)
318
+ FileUtils.mkdir_p("tmp/bin")
319
+ File.open("tmp/bin/hello", "w") { |f| f << "echo sheep" }
320
+ fail unless system "chmod +x tmp/bin/hello"
321
+ fig('--publish-local foo/1.2.3 --resource tmp/bin/hello --append PATH=@/tmp/bin')
322
+ fail if File.exists? FIG_REMOTE_DIR + "/foo/1.2.3/.fig"
323
+ fig('-m -i foo/1.2.3 -- hello')[0].should == 'sheep'
324
+
325
+ File.open("tmp/bin/hello", "w") { |f| f << "echo cheese" }
326
+ fail unless system "chmod +x tmp/bin/hello"
327
+ fig('--publish-local foo/1.2.3 --resource tmp/bin/hello --append PATH=@/tmp/bin')
328
+ fail if File.exists? FIG_REMOTE_DIR + "/foo/1.2.3/.fig"
329
+ fig('-m -i foo/1.2.3 -- hello')[0].should == 'cheese'
330
+ end
331
+ end
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'fig'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
data/spec/win_spec.rb ADDED
@@ -0,0 +1,21 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require 'fig/os'
3
+ require 'fig/windows'
4
+
5
+
6
+ # Only run on Windows...
7
+ if Fig::OS.windows?
8
+ describe "Fig on Windows" do
9
+ it "batch script should exist" do
10
+ Fig::Windows.with_generated_batch_script(["echo", "Hello World"]) do |filename|
11
+ File.exist?(filename).should == true
12
+ end
13
+ end
14
+
15
+ it "batch script should say 'Hello World' when executed" do
16
+ Fig::Windows.with_generated_batch_script(["echo", "Hello World"]) do |filename|
17
+ %x[#{filename}].should == "Hello World\n"
18
+ end
19
+ end
20
+ end
21
+ end
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fig
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.24
5
+ platform: universal-darwin9.0
6
+ authors:
7
+ - Matthew Foemmel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2011-04-26 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: libarchive
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.1.1
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: net-ssh
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.0.15
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: net-sftp
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 2.0.2
44
+ version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: polyglot
47
+ type: :runtime
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 0.2.9
54
+ version:
55
+ - !ruby/object:Gem::Dependency
56
+ name: treetop
57
+ type: :runtime
58
+ version_requirement:
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 1.4.2
64
+ version:
65
+ - !ruby/object:Gem::Dependency
66
+ name: rspec
67
+ type: :development
68
+ version_requirement:
69
+ version_requirements: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ~>
72
+ - !ruby/object:Gem::Version
73
+ version: "1.3"
74
+ version:
75
+ - !ruby/object:Gem::Dependency
76
+ name: open4
77
+ type: :development
78
+ version_requirement:
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: 1.0.1
84
+ version:
85
+ description: Fig is a utility for configuring environments and managing dependencies across a team of developers. You give it a list of packages and a shell command to run; it creates an environment that includes those packages, then executes the shell command in it (the caller's environment is not affected).
86
+ email: git@foemmel.com
87
+ executables:
88
+ - fig
89
+ - fig-download
90
+ extensions: []
91
+
92
+ extra_rdoc_files:
93
+ - LICENSE
94
+ - README.md
95
+ files:
96
+ - bin/fig
97
+ - bin/fig-download
98
+ - lib/fig.rb
99
+ - lib/fig/environment.rb
100
+ - lib/fig/grammar.treetop
101
+ - lib/fig/options.rb
102
+ - lib/fig/os.rb
103
+ - lib/fig/package.rb
104
+ - lib/fig/parser.rb
105
+ - lib/fig/repository.rb
106
+ - lib/fig/windows.rb
107
+ - LICENSE
108
+ - README.md
109
+ has_rdoc: true
110
+ homepage: http://github.com/mfoemmel/fig
111
+ licenses: []
112
+
113
+ post_install_message:
114
+ rdoc_options:
115
+ - --charset=UTF-8
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: "0"
123
+ version:
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: "0"
129
+ version:
130
+ requirements: []
131
+
132
+ rubyforge_project:
133
+ rubygems_version: 1.3.5
134
+ signing_key:
135
+ specification_version: 3
136
+ summary: Fig is a utility for configuring environments and managing dependencies across a team of developers..
137
+ test_files:
138
+ - spec/fig_spec.rb
139
+ - spec/spec_helper.rb
140
+ - spec/win_spec.rb