dev 2.0.99 → 2.0.100

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/lib/dev_commands.rb DELETED
@@ -1,1104 +0,0 @@
1
- require 'open3'
2
- #require_relative('./array.rb')
3
- #require_relative('./hash.rb')
4
- #require_relative('./timer.rb')
5
-
6
- BUFFER_SIZE=1024 if(!defined?(BUFFER_SIZE))
7
-
8
- # = Command
9
- #
10
- # execution of system commands
11
- #
12
- # = Keys
13
- #
14
- # - :input The input of the commands.
15
- # - :timeout The timeout in seconds.
16
- # a value of zero is to infinite timeout.
17
- # defaults to zero
18
- # - :directory The working directory for the command.
19
- # defaults to the current directory
20
- # - :exit_code The exit code of the command
21
- # - :output The output contains the stdout output of the command
22
- # - :error The error contains stderr output of the command
23
- # - :machine The name of the machine the command executed on
24
- # - :user The user name
25
- # - :start_time
26
- # - :end_time
27
- #
28
- class Command < Hash
29
- def initialize command
30
-
31
- self[:input] = ''
32
- self[:timeout] = 0
33
- self[:directory] = ''
34
- self[:exit_code] = 0
35
- self[:output] = ''
36
- self[:error] = ''
37
- self[:machine] = ''
38
- self[:user] = ''
39
- self[:start_time] = nil
40
- self[:end_time] = nil
41
-
42
- if(command.kind_of?(String))
43
- self[:input] = command
44
- end
45
-
46
- if(command.kind_of?(Hash))
47
- command.each{|k,v|
48
- self[k.to_sym]=v
49
- }
50
- end
51
- end
52
-
53
- def quiet?
54
- (self.has_key?(:quiet) && self[:quiet])
55
- end
56
-
57
- def execute value=nil
58
-
59
- if(!value.nil? && value.is_a?(Hash))
60
- value.each{|k,v|self[k]=v}
61
- end
62
-
63
- pwd=Dir.pwd
64
- self[:directory] = pwd if(!self.has_key?(:directory) || self[:directory].length==0)
65
-
66
- if(self[:timeout] > 0)
67
- puts "#{self[:input]} (#{self[:directory]}) timeout #{self[:timeout].to_s}" if(!quiet?)
68
- else
69
- puts "#{self[:input]} (#{self[:directory]})" if(!quiet?)
70
- end
71
-
72
- self[:machine] = Command.machine
73
- self[:user] = Command.user
74
-
75
- self[:start_time]=Time.now
76
- timer=Timer.new
77
-
78
- Dir.chdir(self[:directory]) do
79
- if self[:input].include?('<%') && self[:input].include?('%>')
80
- ruby = self[:input].gsub("<%","").gsub("%>","")
81
-
82
- begin
83
- self[:output]=eval(ruby)
84
- rescue
85
- self[:exit_code]=1
86
- self[:error]="unable to eval(#{ruby})"
87
- end
88
-
89
- self[:elapsed] = timer.elapsed_str
90
- self[:end_time] = Time.now
91
- else
92
- begin
93
- if(self[:timeout] <= 0)
94
- self[:output],self[:error],status= Open3.capture3(self[:input])
95
- self[:exit_code]=status.to_i
96
- self[:elapsed] = timer.elapsed_str
97
- self[:end_time] = Time.now
98
- else
99
- require_relative 'timeout.rb'
100
- #puts run_with_timeout(self[:input], self[:timeout], 1).to_s
101
- #self[:output] = run_with_timeout(self[:input], self[:timeout], 1)
102
- result=run_with_timeout2(self[:directory],self[:input], self[:timeout], 2)
103
- self[:output]=result[0]
104
- self[:error]=result[1]
105
- self[:exit_code]=result[2]
106
-
107
- self[:elapsed] = timer.elapsed_str
108
- self[:end_time] = Time.now
109
-
110
- if(timer.elapsed >= self[:timeout])
111
- self[:exit_code]=1
112
- self[:error] = self[:error] + "timed out"
113
- end
114
- end
115
- rescue Exception => e
116
- self[:elapsed] = timer.elapsed_str
117
- self[:end_time] = Time.now
118
- self[:error] = "Exception: " + e.to_s
119
- self[:exit_code]=1
120
- end
121
- end
122
- end
123
-
124
-
125
- if(self[:exit_code] != 0)
126
- if(!quiet?)
127
- puts "exit_code=#{self[:exit_code]}"
128
- puts self[:output]
129
- puts self[:error]
130
- end
131
- if(!self.has_key?(:ignore_failure) || !self[:ignore_failure])
132
- raise "#{self[:input]} failed"
133
- end #unless (self.has_key?(:ignore_failure) && self[:ignore_failure]==true)
134
- end
135
-
136
- end
137
-
138
- def self.machine
139
- if !ENV['COMPUTERNAME'].nil?
140
- return ENV['COMPUTERNAME']
141
- end
142
-
143
- machine = `hostname`
144
- machine = machine.split('.')[0] if machine.include?('.')
145
- return machine.strip
146
- end
147
-
148
- def self.user
149
- ENV['USER'].nil? ? ENV['USERNAME'] : ENV['USER']
150
- end
151
-
152
- def self.home
153
- ["USERPROFILE","HOME"].each {|v|
154
- return ENV[v].gsub('\\','/') unless ENV[v].nil?
155
- }
156
- dir="~"
157
- dir=ENV["HOME"] unless ENV["HOME"].nil?
158
- dir=ENV["USERPROFILE"].gsub('\\','/') unless ENV["USERPROFILE"].nil?
159
- return dir
160
- end
161
-
162
- def self.dev_root
163
- ["DEV_HOME","DEV_ROOT"].each {|v|
164
- return ENV[v].gsub('\\','/') unless ENV[v].nil?
165
- }
166
- dir=home
167
- #dir=ENV["DEV_ROOT"].gsub('\\','/') unless ENV["DEV_ROOT"].nil?
168
- return dir
169
- end
170
-
171
- def self.exit_code command
172
- cmd = Command.new(command)
173
- cmd[:ignore_failure]=true
174
- cmd[:quiet]=true
175
- cmd.execute
176
- cmd[:exit_code]
177
- end
178
-
179
- def self.output command
180
- cmd = Command.new(command)
181
- cmd[:ignore_failure]=true
182
- cmd[:quiet]=true
183
- cmd.execute
184
- cmd[:output]
185
- end
186
-
187
- def getFormattedTimeSpan timespan
188
- seconds = timespan
189
- seconds.to_s + " sec"
190
- end
191
-
192
- def summary
193
- duration=""
194
- duration=getFormattedTimeSpan(self[:end_time]-[:start_time]) + " - " if(!self[:end_time].nil?)
195
- duration + "#{self[:exit_code].to_s} #{self[:input]} (#{self[:directory]})"
196
- end
197
-
198
- def to_html
199
- if self[:exit_code] == 0
200
- [
201
- '<div><table><tr><td width="20"></td><td><pre>',
202
- self[:input],
203
- '</pre></td></tr></table></div>'
204
- ].join
205
- else
206
- [
207
- '<div><table><tr><td width="20"></td><td><pre>',
208
- self[:input],
209
- '</pre><table><tr><td width="20"></td><td><table>',
210
- map { |k, v| ["<tr><td><strong>#{k}</strong></td>", v.respond_to?(:to_html) ? v.to_html : "<td><span><pre>#{v}</pre></span></td></tr>"] },
211
- '</table>',
212
- '</td></tr></table></td></tr></table></div>'
213
- ].join
214
- end
215
- end
216
- end
217
- class Add < Array
218
- def update
219
- if(File.exists?('.git') && File.exists?('.gitignore'))
220
- add 'git add --all'
221
- else
222
- if(defined?(SOURCE))
223
- if(File.exists?('.svn'))
224
- SOURCE.each{|f|
225
-
226
- add "svn add #{f} --parents" if Command.output("svn status #{f}").include?('?')
227
- add "svn add #{f} --parents" if Command.exit_code("svn status #{f}") != 0
228
- }
229
- end
230
- if(File.exists?('.git'))
231
- SOURCE.each{|f|
232
- add "git add #{f} -v" if `git status #{f}`.include?('untracked')
233
- }
234
- end
235
- end
236
- end
237
- end
238
- end
239
- class Analyze < Array
240
- def update
241
- if(`gem list countloc`.include?('countloc ('))
242
- FileUtils.mkdir('doc') if(!File.exists?('doc'))
243
- add 'countloc -r * --html doc/countloc.html'
244
- end
245
- end
246
- end
247
- class Array
248
- def execute value=nil
249
- i=0
250
- while i < self.length
251
- self[i]=Command.new(self[i]) if(self[i].is_a?(String))
252
- self[i]=Command.new(self[i]) if(self[i].is_a?(Hash) && !self[i].is_a?(Command))
253
-
254
- if(!value.nil? && value.is_a?(Hash))
255
- value.each{|k,v|self[i][k]=v}
256
- end
257
-
258
- self[i].execute if(self[i].is_a?(Command))
259
- i=i+1
260
- end
261
- end
262
-
263
- def add command
264
- self << command if(!include?(command))
265
- end
266
-
267
- def to_html
268
- html=Array.new
269
- html << '<div>'
270
- self.each{|e|
271
- html << e.to_html if e.respond_to?(:to_html)
272
- }
273
- html << '</div>'
274
- html.join
275
- end
276
- end
277
- require 'rake'
278
-
279
- SLN_FILES=FileList.new('*.sln','*/*.sln','*/*/*.sln')
280
-
281
- class Build < Array
282
- def update
283
-
284
- changed = true
285
- #changed = Git.has_changes? if(File.exists?('.git') && defined?(Git))
286
- #changed = Svn.has_changes? if(File.exists?('.svn') && defined?(Svn))
287
- if(changed)
288
- Dir.glob('*.gemspec'){|gemspec|
289
- add "gem build #{gemspec}" if !File.exist?(Gemspec.gemfile gemspec)
290
- }
291
-
292
- SLN_FILES.each{|sln_file|
293
- vs_version=MSBuild.get_vs_version(sln_file)
294
- if(MSBuild.has_version?(vs_version))
295
- MSBuild.get_configurations(sln_file).each{ |configuration|
296
- MSBuild.get_platforms(sln_file).each{|platform|
297
- #Console.debug "configuration='#{configuration}', platform='#{platform}'"
298
- self.add "\"#{MSBuild.get_version(vs_version)}\" \"#{sln_file}\" /nologo /p:Configuration=#{configuration} /p:Platform=\"#{platform}\""
299
- }
300
- }
301
- else
302
- "puts version #{vs_version} not found for MsBuild"
303
- end
304
- }
305
- end
306
- end
307
- end
308
- class Clean < Array
309
- def update
310
- ['.yardoc','log','tmp','obj'].each{|dir|
311
- CLEAN.include(dir) if File.exists?(dir)
312
- }
313
-
314
- CLEAN.include('*.{suo,sdf}')
315
-
316
- #add '<%Rake::Task[:clean].reenable%>'
317
- add '<%Rake::Task[:clean].invoke%>'
318
- end
319
- end
320
- class Clobber < Array
321
- def update
322
- ['bin'].each{|dir|
323
- CLOBBER.include(dir) if File.exists?(dir)
324
- }
325
-
326
- clean=Clean.new
327
- clean.update
328
-
329
- CLOBBER.include('*.gem')
330
-
331
- #add '<%Rake::Task[:clobber].reenable%>'
332
- add '<%Rake::Task[:clobber].invoke%>'
333
- end
334
- end
335
- require 'open3'
336
- #require_relative('./array.rb')
337
- #require_relative('./hash.rb')
338
- #require_relative('./timer.rb')
339
-
340
- BUFFER_SIZE=1024 if(!defined?(BUFFER_SIZE))
341
-
342
- # = Command
343
- #
344
- # execution of system commands
345
- #
346
- # = Keys
347
- #
348
- # - :input The input of the commands.
349
- # - :timeout The timeout in seconds.
350
- # a value of zero is to infinite timeout.
351
- # defaults to zero
352
- # - :directory The working directory for the command.
353
- # defaults to the current directory
354
- # - :exit_code The exit code of the command
355
- # - :output The output contains the stdout output of the command
356
- # - :error The error contains stderr output of the command
357
- # - :machine The name of the machine the command executed on
358
- # - :user The user name
359
- # - :start_time
360
- # - :end_time
361
- #
362
- class Command < Hash
363
- def initialize command
364
-
365
- self[:input] = ''
366
- self[:timeout] = 0
367
- self[:directory] = ''
368
- self[:exit_code] = 0
369
- self[:output] = ''
370
- self[:error] = ''
371
- self[:machine] = ''
372
- self[:user] = ''
373
- self[:start_time] = nil
374
- self[:end_time] = nil
375
-
376
- if(command.kind_of?(String))
377
- self[:input] = command
378
- end
379
-
380
- if(command.kind_of?(Hash))
381
- command.each{|k,v|
382
- self[k.to_sym]=v
383
- }
384
- end
385
- end
386
-
387
- def quiet?
388
- (self.has_key?(:quiet) && self[:quiet])
389
- end
390
-
391
- def execute value=nil
392
-
393
- if(!value.nil? && value.is_a?(Hash))
394
- value.each{|k,v|self[k]=v}
395
- end
396
-
397
- pwd=Dir.pwd
398
- self[:directory] = pwd if(!self.has_key?(:directory) || self[:directory].length==0)
399
-
400
- if(self[:timeout] > 0)
401
- puts "#{self[:input]} (#{self[:directory]}) timeout #{self[:timeout].to_s}" if(!quiet?)
402
- else
403
- puts "#{self[:input]} (#{self[:directory]})" if(!quiet?)
404
- end
405
-
406
- self[:machine] = Command.machine
407
- self[:user] = Command.user
408
-
409
- self[:start_time]=Time.now
410
- timer=Timer.new
411
-
412
- Dir.chdir(self[:directory]) do
413
- if self[:input].include?('<%') && self[:input].include?('%>')
414
- ruby = self[:input].gsub("<%","").gsub("%>","")
415
-
416
- begin
417
- self[:output]=eval(ruby)
418
- rescue
419
- self[:exit_code]=1
420
- self[:error]="unable to eval(#{ruby})"
421
- end
422
-
423
- self[:elapsed] = timer.elapsed_str
424
- self[:end_time] = Time.now
425
- else
426
- begin
427
- if(self[:timeout] <= 0)
428
- self[:output],self[:error],status= Open3.capture3(self[:input])
429
- self[:exit_code]=status.to_i
430
- self[:elapsed] = timer.elapsed_str
431
- self[:end_time] = Time.now
432
- else
433
- require_relative 'timeout.rb'
434
- #puts run_with_timeout(self[:input], self[:timeout], 1).to_s
435
- #self[:output] = run_with_timeout(self[:input], self[:timeout], 1)
436
- result=run_with_timeout2(self[:directory],self[:input], self[:timeout], 2)
437
- self[:output]=result[0]
438
- self[:error]=result[1]
439
- self[:exit_code]=result[2]
440
-
441
- self[:elapsed] = timer.elapsed_str
442
- self[:end_time] = Time.now
443
-
444
- if(timer.elapsed >= self[:timeout])
445
- self[:exit_code]=1
446
- self[:error] = self[:error] + "timed out"
447
- end
448
- end
449
- rescue Exception => e
450
- self[:elapsed] = timer.elapsed_str
451
- self[:end_time] = Time.now
452
- self[:error] = "Exception: " + e.to_s
453
- self[:exit_code]=1
454
- end
455
- end
456
- end
457
-
458
-
459
- if(self[:exit_code] != 0)
460
- if(!quiet?)
461
- puts "exit_code=#{self[:exit_code]}"
462
- puts self[:output]
463
- puts self[:error]
464
- end
465
- if(!self.has_key?(:ignore_failure) || !self[:ignore_failure])
466
- raise "#{self[:input]} failed"
467
- end #unless (self.has_key?(:ignore_failure) && self[:ignore_failure]==true)
468
- end
469
-
470
- end
471
-
472
- def self.machine
473
- if !ENV['COMPUTERNAME'].nil?
474
- return ENV['COMPUTERNAME']
475
- end
476
-
477
- machine = `hostname`
478
- machine = machine.split('.')[0] if machine.include?('.')
479
- return machine.strip
480
- end
481
-
482
- def self.user
483
- ENV['USER'].nil? ? ENV['USERNAME'] : ENV['USER']
484
- end
485
-
486
- def self.home
487
- ["USERPROFILE","HOME"].each {|v|
488
- return ENV[v].gsub('\\','/') unless ENV[v].nil?
489
- }
490
- dir="~"
491
- dir=ENV["HOME"] unless ENV["HOME"].nil?
492
- dir=ENV["USERPROFILE"].gsub('\\','/') unless ENV["USERPROFILE"].nil?
493
- return dir
494
- end
495
-
496
- def self.dev_root
497
- ["DEV_HOME","DEV_ROOT"].each {|v|
498
- return ENV[v].gsub('\\','/') unless ENV[v].nil?
499
- }
500
- dir=home
501
- #dir=ENV["DEV_ROOT"].gsub('\\','/') unless ENV["DEV_ROOT"].nil?
502
- return dir
503
- end
504
-
505
- def self.exit_code command
506
- cmd = Command.new(command)
507
- cmd[:ignore_failure]=true
508
- cmd[:quiet]=true
509
- cmd.execute
510
- cmd[:exit_code]
511
- end
512
-
513
- def self.output command
514
- cmd = Command.new(command)
515
- cmd[:ignore_failure]=true
516
- cmd[:quiet]=true
517
- cmd.execute
518
- cmd[:output]
519
- end
520
-
521
- def getFormattedTimeSpan timespan
522
- seconds = timespan
523
- seconds.to_s + " sec"
524
- end
525
-
526
- def self.execute command
527
- cmd = Command.new(command)
528
- cmd.execute
529
- cmd[:exit_code]
530
- end
531
-
532
- def summary
533
- duration=""
534
- duration=getFormattedTimeSpan(self[:end_time]-self[:start_time]) + " - " if(!self[:end_time].nil?)
535
- duration + "#{self[:exit_code].to_s} #{self[:input]} (#{self[:directory]})"
536
- end
537
-
538
- def to_html
539
- if self[:exit_code] == 0
540
- [
541
- '<div><table><tr><td width="20"></td><td><pre>',
542
- self[:input],
543
- '</pre></td></tr></table></div>'
544
- ].join
545
- else
546
- [
547
- '<div><table><tr><td width="20"></td><td><pre>',
548
- self[:input],
549
- '</pre><table><tr><td width="20"></td><td><table>',
550
- map { |k, v| ["<tr><td><strong>#{k}</strong></td>", v.respond_to?(:to_html) ? v.to_html : "<td><span><pre>#{v}</pre></span></td></tr>"] },
551
- '</table>',
552
- '</td></tr></table></td></tr></table></div>'
553
- ].join
554
- end
555
- end
556
- end
557
- #require_relative('hash.rb')
558
- #require_relative('pull.rb')
559
- #require_relative('update.rb')
560
- #require_relative('setup.rb')
561
- #require_relative('build.rb')
562
- #require_relative('test.rb')
563
- #require_relative('analyze.rb')
564
- #require_relative('publish.rb')
565
- #require_relative('doc.rb')
566
- #require_relative('clean.rb')
567
- #require_relative('clobber.rb')
568
- #require_relative('add.rb')
569
- #require_relative('commit.rb')
570
- #require_relative('push.rb')
571
-
572
- class Commands < Hash
573
-
574
- def initialize directory=Dir.pwd
575
- Dir.chdir(directory) do
576
- self[:pull]=Pull.new
577
- self[:update]=Update.new
578
- self[:setup]=Setup.new
579
- self[:build]=Build.new
580
- self[:test]=Test.new
581
- self[:analyze]=Analyze.new
582
- self[:doc]=Doc.new
583
- self[:clean]=Clean.new
584
- self[:publish]=Publish.new
585
- self[:clobber]=Clobber.new
586
- self[:add]=Add.new
587
- self[:commit]=Commit.new
588
- self[:push]=Push.new
589
- end
590
- end
591
-
592
- end
593
- #require_relative('internet.rb')
594
-
595
- class Commit < Array
596
- def update
597
- if(File.exists?('.git') && `git config --list`.include?('user.name='))
598
- if(!`git status`.include?('nothing to commit') &&
599
- !`git status`.include?('untracked files present'))
600
- if(File.exists?('commit.message') && File.read('commit.message').gsub(/\s+/,"").length >0)
601
- add "git commit -a -v -m \"#{File.read('commit.message')}\""
602
- else
603
- add "git commit -m'all'"
604
- end
605
- add "<%FileUtils.rm('commit.message')%>" if File.exists?('commit.message')
606
- end
607
- end
608
- if(File.exists?('.svn') && Internet.available?)
609
- add 'svn commit -m"commit all"'
610
- end
611
- end
612
- end
613
- class Doc < Array
614
- def update
615
- #cmd=Command.new ({ :input => 'yard --version', :ignore_failure => true})
616
- #cmd.execute
617
- if(Command.exit_code('yard --version'))
618
- add 'yard doc - LICENSE' if File.exists?('README.md') && File.exists?('LICENSE')
619
- end
620
- end
621
- end
622
- class Gemspec
623
- def self.update gemspec_file
624
- Text.replace_in_file gemspec_file,
625
- /('\d{4}-\d{2}-\d{2}')/,
626
- "'#{Time.now.strftime('%Y-%m-%d')}'"
627
- end
628
-
629
- def self.gemfile gemspec_file
630
- spec=Gem::Specification.load(gemspec_file)
631
- return "#{spec.name}-#{spec.version}.gem" if !spec.nil?
632
- return ""
633
- end
634
-
635
- def self.version gemspec_file
636
- spec=Gem::Specification.load(gemspec_file)
637
- return spec.version.to_s
638
- end
639
-
640
- def self.published_version gemspec_file
641
- published_version=''
642
- spec=Gem::Specification.load(gemspec_file)
643
- begin
644
- published_version = `gem list -r #{spec.name}`.scan(/\((\d+.\d+.\d+)\)/)[0][0]
645
- rescue
646
- published_version=''
647
- end
648
- published_version
649
- end
650
- def self.published? gemspec_file
651
- published_version(gemspec_file)==version(gemspec_file) ? true : false
652
- end
653
-
654
- def self.normalize gemspec_file
655
- spec=Gem::Specification.load(gemspec_file)
656
- File.open(gemspec_file,'w'){|f|f.write(spec.to_ruby)}
657
- end
658
-
659
- def self.upgrade gemspec_file
660
- end
661
- end
662
- class Git
663
- def self.branch
664
- begin
665
- `git branch`.scan(/\* ([.\w-]+)/)[0][0]
666
- rescue
667
- ''
668
- end
669
- end
670
-
671
- def self.remote_origin directory=''
672
- url=''
673
- directory=Dir.pwd if directory.length == 0
674
- Dir.chdir(directory) do
675
- begin
676
- url=`git remote show origin`.scan(/Fetch URL: ([\.\-:\/\w\d]+)/)[0]
677
- rescue
678
- url=''
679
- end
680
- end
681
- url
682
- end
683
- end
684
- class Hash
685
- def execute value=nil
686
- self.each{|k,v|
687
- v.update if v.respond_to?(:update)
688
- if(v.is_a?(Array) && v.length==0)
689
- self.delete k
690
- else
691
- #puts "executing #{k}"
692
-
693
- v.execute(value) if v.respond_to?(:execute)
694
- end
695
- }
696
- end
697
- def to_html
698
- [
699
- '<div>',
700
- map { |k, v| ["<br/><div><strong>#{k}</strong>", v.respond_to?(:to_html) ? v.to_html : "<span>#{v}</span></div><br/>"] },
701
- '</div>'
702
- ].join
703
- end
704
- end
705
- #require_relative 'array.rb'
706
- INFO=Array.new
707
-
708
- require 'open-uri'
709
- #require 'net/http'
710
- require 'timeout'
711
- class Internet
712
-
713
- @@available=true
714
-
715
- def self.available?
716
- return @@available if !@@available.nil?
717
-
718
- begin
719
- index=open('http://www.google.com').read
720
- if index.include?('<Title>Google')
721
- @@available = true
722
- else
723
- puts "open('http://www.google.com') returned false"
724
- end
725
- rescue Exception => e
726
- puts "open('http://www.google.com') raised an exception: #{e.to_s}"
727
- @@available = false
728
- end
729
- @@available
730
- end
731
- end
732
- # Visual Studio 2008 version 9.0, solution format version 10.00
733
- # Visual Studio 2010 version 10.0, solution format version 11.00
734
- # Visual Studio 2012 version 11.0, solution format version 12.00
735
- # Visual Studio 2013 version 12.0, solution format version 12.00
736
- class MSBuild < Hash
737
-
738
- def initialize
739
- self[:vs9]="C:\\Windows\\Microsoft.NET\\Framework\\v3.5\\msbuild.exe" if(File.exists?("C:\\Windows\\Microsoft.NET\\Framework\\v3.5\\msbuild.exe"))
740
- self[:vs12]="C:\\Program Files (x86)\\MSBuild\\12.0\\bin\\msbuild.exe" if(File.exists?("C:\\Program Files (x86)\\MSBuild\\12.0\\bin\\msbuild.exe"))
741
- end
742
-
743
- def self.has_version? version
744
- if(defined?(MSBUILD))
745
- MSBUILD.has_key?(version)
746
- else
747
- msb=MSBuild.new
748
- return msb.has_key? version
749
- end
750
- end
751
-
752
- def self.get_version version
753
- if(defined?(MSBUILD))
754
- MSBUILD[version]
755
- else
756
- msb=MSBuild.new
757
- return msb[version]
758
- end
759
- end
760
-
761
- def self.get_vs_version(sln_filename)
762
- sln_text=File.read(sln_filename,:encoding=>'UTF-8')
763
- return :vs9 if sln_text.include?('Format Version 10.00')
764
- return :vs12
765
- end
766
-
767
- def self.get_configurations(sln_filename)
768
- configs=Array.new
769
- sln_text=File.read(sln_filename,:encoding=>'UTF-8')
770
- sln_text.scan( /= ([\w]+)\|/ ).each{|m|
771
- c=m.first.to_s
772
- configs << c if !configs.include?(c)
773
- }
774
- return configs
775
- end
776
-
777
- def self.get_platforms(sln_filename)
778
- platforms=Array.new
779
- sln_text=File.read(sln_filename,:encoding=>"UTF-8")
780
- sln_text.scan( /= [\w]+\|([\w ]+)/ ).each{|m|
781
- p=m.first.to_s
782
- platforms << p if !platforms.include?(p)
783
- }
784
- return platforms
785
- end
786
- end
787
-
788
- #require_relative('internet.rb')
789
- class Publish < Array
790
- def update
791
- if(Internet.available?)
792
- if(File.exists?('.git'))
793
- if(`git branch`.include?('* master'))
794
- Dir.glob('*.gemspec').each{|gemspec_file|
795
- add "gem push #{Gemspec.gemfile(gemspec_file)}" if !Gemspec.published? gemspec_file
796
- }
797
- end
798
- end
799
- if(File.exists?('.svn'))
800
- if(`svn info`.include?('/trunk'))
801
- Dir.glob('*.gemspec').each{|gemspec_file|
802
- add "gem push #{Gemspec.gemfile(gemspec_file)}" if !Gemspec.published? gemspec_file
803
- }
804
- end
805
- end
806
- end
807
- end
808
- end
809
- #require_relative('git.rb')
810
- #require_relative('internet.rb')
811
-
812
- class Pull < Array
813
- def update
814
- if(Internet.available?)
815
- if(File.exists?('.git') && `git config --list`.include?('user.name='))
816
- self << 'git pull' if Git.branch != 'develop'
817
- end
818
- end
819
- end
820
- end
821
- class Push < Array
822
- def update
823
- if(File.exists?('.git') && `git config --list`.include?('user.name='))
824
- self << 'git push'
825
- self << 'git push --tags'# if Git.branch != 'develop' && Internet.available?
826
- end
827
- end
828
- end
829
- #
830
- # use the SVN_EXPORTS hash to define svn exports destined for DEV_ROOT/dep
831
- #
832
- # SVN_EXPORT={ 'System.Data.SQLite/1.0.93.0' => 'https://third-party.googlecode.com/svn/trunk/System.Data.SQLite/1.0.93.0' }
833
- #
834
- class Setup < Array
835
- def update
836
- add 'bundle install' if(File.exists?('Gemfile'))
837
-
838
- Dir.glob('*.gemspec').each{|gemspec_file|
839
- add "<%Gemspec.update('#{gemspec_file}')%>"
840
- }
841
-
842
- if(defined?(SVN_EXPORTS))
843
- SVN_EXPORTS.each{|k,v|
844
- if(!File.exists?("#{Command.dev_root}/dep/#{k}"))
845
- FileUtils.mkdir_p(File.dirname("#{Command.dev_root}/dep/#{k}")) if !File.exists?("#{Command.dev_root}/dep/#{k}")
846
- dest="#{Command.dev_root}/dep/#{k}"
847
- add "svn export #{v} #{Command.dev_root}/dep/#{k}" if !dest.include?("@")
848
- add "svn export #{v} #{Command.dev_root}/dep/#{k}@" if dest.include?("@")
849
- end
850
- }
851
- end
852
-
853
- if(defined?(GIT_EXPORTS))
854
- GIT_EXPORTS.each{|k,v|
855
- directory = "#{Command.dev_root}/dep/#{k}"
856
- if(!File.exists?(directory))
857
- if(v.include?('@'))
858
- puts `git clone #{v.split('@')[0]} #{directory}`
859
- Dir.chdir(directory) do
860
- puts `git reset --hard #{v.split('@')[1]}`
861
- end
862
- else
863
- add "git clone #{v} #{directory}"
864
- end
865
- end
866
- }
867
- end
868
- end
869
- end
870
- class Tag < Array
871
-
872
- end
873
- #
874
- # nunit dlls may be specified with
875
- # NUNIT=FileList.new('**/*.Test.dll')
876
- #
877
- # for nunit dlls that must be run in x86 mode,
878
- # NUNIT_x86=FileList.new('**/*.x86.Test.dll')
879
- #
880
-
881
-
882
- class Test < Array
883
- def update
884
- add 'rspec' if File.exists?('spec')
885
-
886
- if(defined?(NUNIT))
887
- NUNIT.each{|nunit_dll|
888
- add "\"#{Test.nunit_console}\" \"#{Rake.application.original_dir}\\#{nunit_dll}\" /xml:\"#{nunit_dll}.TestResults.xml\""
889
- }
890
- end
891
-
892
- if(defined?(NUNIT_X86))
893
- NUNIT_X86.each{|nunit_dll|
894
- add "\"#{Test.nunit_console_x86}\" \"#{Rake.application.original_dir}\\#{nunit_dll}\" /xml:\"#{nunit_dll}.TestResults.xml\""
895
- }
896
- end
897
-
898
- if(defined?(TESTS))
899
- TEST.each{|t| add t}
900
- end
901
- end
902
-
903
- @@nunit_console=''
904
- def self.nunit_console
905
- if(!File.exists?(@@nunit_console))
906
- if(defined?(NUNIT_CONSOLE))
907
- @@nunit_console = NUNIT_CONSOLE
908
- end
909
- @@nunit_console = "C:\\Program Files (x86)\\NUnit 2.6.4\\bin\\nunit-console.exe" if(!File.exists?(@@nunit_console))
910
- @@nunit_console = "C:\\Program Files (x86)\\NUnit 2.6.3\\bin\\nunit-console.exe" if(!File.exists?(@@nunit_console))
911
- end
912
- if(!File.exists?(@@nunit_console))
913
- raise "unable to locate nunit-console.exe, assign NUNIT_CONSOLE to the correct location."
914
- end
915
- @@nunit_console
916
- end
917
-
918
- @@nunit_console_x86=''
919
- def self.nunit_console_x86
920
- if(!File.exists?(@@nunit_console_x86))
921
- if(defined?(NUNIT_CONSOLE_X86))
922
- @@nunit_console_x86 = NUNIT_CONSOLE_X86
923
- end
924
- @@nunit_console_x86 = "C:\\Program Files (x86)\\NUnit 2.6.4\\bin\\nunit-console-x86.exe" if(!File.exists?(@@nunit_console_x86))
925
- @@nunit_console_x86 = "C:\\Program Files (x86)\\NUnit 2.6.3\\bin\\nunit-console-x86.exe" if(!File.exists?(@@nunit_console_x86))
926
- end
927
- if(!File.exists?(@@nunit_console_x86))
928
- raise "unable to locate nunit-console-x86.exe, assign NUNIT_CONSOLE_X86 to the correct location."
929
- end
930
- @@nunit_console_x86
931
- end
932
- end
933
-
934
- NUNIT=FileList.new('bin/**/*.Test.dll')
935
- class Text
936
- def self.replace_in_glob(glob,search,replace)
937
- Dir.glob(glob).each{ |f| replace_in_file(f,search,replace) }
938
- end
939
-
940
- def self.replace_in_file(filename,search,replace)
941
- text1 = IO.read(filename)
942
- text2 = text1.gsub(search) { |str| str=replace }
943
- unless text1==text2
944
- File.open(filename,"w") { |f| f.puts text2 }
945
- return true
946
- end
947
- false
948
- end
949
-
950
- end
951
- ############################################################################
952
- # The following code is based on code originally copied from
953
- # https://gist.github.com/lpar/1032297
954
- # Gist title: lpar/timeout.rb
955
- ############################################################################
956
- # Runs a specified shell command in a separate thread.
957
- # If it exceeds the given timeout in seconds, kills it.
958
- # Returns any output produced by the command (stdout or stderr) as a String.
959
- # Uses Kernel.select to wait up to the tick length (in seconds) between
960
- # checks on the command's status
961
- #
962
- # If you've got a cleaner way of doing this, I'd be interested to see it.
963
- # If you think you can do it with Ruby's Timeout module, think again.
964
- def run_with_timeout(directory,command, timeout, tick)
965
- output = ''
966
- exit_code=1
967
- begin
968
- # Start task in another thread, which spawns a process
969
- stdin, stderrout, thread = Open3.popen2e(command, :chdir=>directory)
970
- # Get the pid of the spawned process
971
- pid = thread[:pid]
972
- start = Time.now
973
-
974
- while (Time.now - start) < timeout and thread.alive?
975
- # Wait up to `tick` seconds for output/error data
976
- Kernel.select([stderrout], nil, nil, tick)
977
- # Try to read the data
978
- begin
979
- output << stderrout.read_nonblock(BUFFER_SIZE)
980
- rescue IO::WaitReadable
981
- # A read would block, so loop around for another select
982
- rescue EOFError
983
- # Command has completed, not really an error...
984
- break
985
- end
986
- end
987
-
988
- # Give Ruby time to clean up the other thread
989
- sleep 1
990
-
991
- if thread.alive?
992
- # We need to kill the process, because killing the thread leaves
993
- # the process alive but detached, annoyingly enough.
994
- Process.kill("TERM", pid)
995
- else
996
- exit_code=thread.value
997
- sleep 1
998
- end
999
-
1000
- ensure
1001
- stdin.close if stdin
1002
- stderrout.close if stderrout
1003
- end
1004
- return [output,exit_code]
1005
- end
1006
-
1007
- require 'timeout'
1008
- def run_with_timeout2(directory,command,timeout)
1009
- # stdout, stderr pipes
1010
- rout, wout = IO.pipe
1011
- rerr, werr = IO.pipe
1012
- output=''
1013
- error=''
1014
- exit_code=1
1015
- pid = Process.spawn(command, :chdir => directory, :out => wout, :err => werr)
1016
- begin
1017
- Timeout.timeout(timeout) do
1018
- exit_code = Process.wait2(pid)
1019
- output = rout.readlines.join("\n")
1020
- error = rerr.readlines.join("\n")
1021
- end
1022
- rescue
1023
- Proces.kill('TERM',pid)
1024
- output = output + 'timeout occurred.'
1025
- ensure
1026
- rout.close
1027
- rerr.close
1028
- end
1029
- [output,exit_code]
1030
- end
1031
-
1032
- class Timer
1033
- attr_accessor :start_time
1034
-
1035
- def initialize
1036
- @start_time=Time.now
1037
- end
1038
-
1039
- def elapsed # in seconds
1040
- return Time.now-@start_time
1041
- end
1042
-
1043
- def elapsed_str
1044
- elapsed_str="[" + "%.0f" %(elapsed) + "s]"
1045
- end
1046
-
1047
- def self.elapsed_exceeds?(name,duration_seconds)
1048
- if(Timer.get_elapsed(name).nil? || Timer.get_elapsed(name) > duration_seconds)
1049
- return true
1050
- end
1051
- return false
1052
- end
1053
-
1054
- def self.get_elapsed(name)
1055
- timestamp=get_timestamp(name)
1056
- return Time.now-timestamp if(!timestamp.nil?)
1057
- nil
1058
- end
1059
-
1060
- def self.get_timestamp(name)
1061
- dir=Rake.application.original_dir
1062
- if(File.exists?("#{DEV[:dev_root]}/log/#{name}.timestamp"))
1063
- return Time.parse(File.read("#{DEV[:dev_root]}/log/#{name}.timestamp").strip)
1064
- end
1065
- nil
1066
- end
1067
-
1068
- def self.set_timestamp(name)
1069
- Dir.mkdir("#{DEV_TASKS[:dev_root]}/log") if(!Dir.exists?("#{DEV_TASKS[:dev_root]}/log"))
1070
- File.open("#{DEV_TASKS[:dev_root]}/log/#{name}.timestamp",'w'){|f|f.puts(Time.now.to_s)}
1071
- end
1072
- end
1073
-
1074
- TIMER=Timer.new
1075
- class Update < Array
1076
- def update
1077
- self .add 'svn update' if File.exists?('.svn') && Internet.available?
1078
- end
1079
- end
1080
- class Upgrade < Array
1081
- def update
1082
- if(File.exists?('Gemfile'))
1083
- end
1084
- end
1085
- end
1086
- require 'json'
1087
- require 'rake/clean'
1088
-
1089
- CLOBBER.include('*.gem')
1090
-
1091
- SOURCE=FileList.new('LICENSE','README','README.md',"Gemfile")
1092
- SOURCE.include('*.{gitignore,yml,gemspec}')
1093
- SOURCE.include('**/*.{rb}')
1094
- SOURCE.include('**/*.{cs}')
1095
- SOURCE.include('**/*.{c,h}')
1096
- SOURCE.include('**/*.{cpp,hpp}')
1097
-
1098
- Dir.glob("#{File.dirname(__FILE__)}/commands/*.rb").each{|rb|
1099
- require(rb)
1100
- }
1101
-
1102
-
1103
- COMMANDS=Commands.new
1104
- MSBUILD=MSBuild.new