Class: Rake::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/rake/config.rb,
lib/rake/extensions.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.gl_run(*args, &aBlock) ⇒ Object

Execute command (as is) on local_host using greenletters to enable expect like behaviour (useful for dealling with passwords).



621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
# File 'lib/rake/config.rb', line 621

def self.gl_run(*args, &aBlock)
  $TRACE = Rake.application.options.trace;

  options = Hash.new;
  if args.last.is_a?(Construct) then 
    raise ConfigurationError, "gl_run should not be passed a Construct";
  elsif args.last.is_a?(Hash)
    options = args.pop;
  end
  Conf.timeout = Hash.new() unless Conf.has_key?(:timeout);
  Conf.timeout.maxTimeout = 10 unless Conf.timeout.has_key?(:maxTimeout);
  if options.has_key?(:timeout) then
    options[:timeout] = Conf.timeout.maxTimeout if Conf.timeout.maxTimeout.to_i < options[:timeout].to_i ;
  else
    options[:timeout] = 10;
  end

  Rake::Application.mesg args.join(' ') if $TRACE
  Rake::Application.mesg "#{options}" if $TRACE && !options.empty?() && options.has_key?(:verbose);

  asyncTriggersBlocks = Array.new;
  if options.has_key? :asyncTriggersBlocks then
    asyncTriggersBlocks = options[:asyncTriggersBlocks];
  end

  exitStatus = 0;
  if options.has_key? :exitStatus then
    exitStatus = options[:exitStatus];
  end

  options[:env] = ENV unless options.has_key?(:env);
  options[:transcript] = Rake::Application.logger unless options.has_key?(:transcript);

  cmdProcess = Greenletters::Process.new(*args, options);
  cmdProcess.start!;

  asyncTriggersBlocks.each do | asyncTriggersBlock |
    if asyncTriggersBlock.kind_of? Proc then
      asyncTriggersBlock.call(cmdProcess);
    end
  end

  aBlock.call(cmdProcess) unless aBlock.nil?;

  cmdProcess.wait_for(:exit, exitStatus);

  cmdProcess
end

.local_sh(*args, &aBlock) ⇒ Object

Execute command using sh on local_host using greenletters.



606
607
608
609
610
611
612
613
614
615
616
# File 'lib/rake/config.rb', line 606

def self.local_sh(*args, &aBlock)
  options = if args.last.is_a?(Hash) then args.pop else {} end
  options = Conf.sh.data.merge(options);
  cmd     = [options[:command], 
             options[:cmdOptions],
             "-c", 
             args.flatten.join(' ')
            ].flatten

  gl_run(*cmd, options, &aBlock);
end

.remote_ssh(*args, &aBlock) ⇒ Object

Execute command using ssh to remote_host using greenletters.



584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
# File 'lib/rake/config.rb', line 584

def self.remote_ssh(*args, &aBlock)
  options = if args.last.is_a?(Hash) then args.pop else {} end
  options = Conf.ssh.data.merge(options);
  options[:timeout] = 10 unless options.has_key?(:timeout);
  sshPort = Array.new();
  sshPort = [ '-p', options[:remotePort]] if options.has_key?(:remotePort);
  cmd     = [options[:command], 
             options[:cmdOptions], 
             '-l',
             options[:userId],
             sshPort,
             options[:remoteHost]
            ].flatten

  gl_run(*cmd, options) do | p |
    p.wait_for(:output, Regexp.new(options[:commandPromptRegExp]));
    Rake::Application.mesg args.flatten.join(' ') if Rake.application.options.trace;
    p.puts args.flatten.join(' ') + '; exit';
  end
end

.rsync_from_remote(remotePath, localPath, options = {}, &aBlock) ⇒ Object

Execute the rsync command on the arguments provided using greenletters.



571
572
573
574
575
576
577
578
579
580
581
# File 'lib/rake/config.rb', line 571

def self.rsync_from_remote(remotePath, localPath, options = {}, &aBlock)
  options = Conf.rsync.data.merge(options);
  options[:timeout] = 10 unless options.has_key?(:timeout);
  cmd     = [options[:command], 
             options[:cmdOptions], 
             "#{options[:userId]}@#{options[:remoteHost]}:#{remotePath}",
             localPath,
            ].flatten

  gl_run(*cmd, options, &aBlock);
end

.rsync_to_remote(localPath, remotePath, options = {}, &aBlock) ⇒ Object

Execute the rsync command on the arguments provided using greenletters.



555
556
557
558
559
560
561
562
563
564
565
566
567
568
# File 'lib/rake/config.rb', line 555

def self.rsync_to_remote(localPath, remotePath, options = {}, &aBlock)
  if localPath =~ /\*/ then
    localPath = Dir.glob(localPath);
  end
  options = Conf.rsync.data.merge(options);
  options[:timeout] = 10 unless options.has_key?(:timeout);
  cmd     = [options[:command], 
             options[:cmdOptions], 
             localPath,
             "#{options[:userId]}@#{options[:remoteHost]}:#{remotePath}",
            ].flatten

  gl_run(*cmd, options, &aBlock);
end

.scp_from_remote(remotePath, localPath, options = {}, &aBlock) ⇒ Object

Execute the rsync command on the arguments provided using greenletters.



542
543
544
545
546
547
548
549
550
551
552
# File 'lib/rake/config.rb', line 542

def self.scp_from_remote(remotePath, localPath, options = {}, &aBlock)
  options = Conf.scp.data.merge(options);
  options[:timeout] = 10 unless options.has_key?(:timeout);
  cmd     = [options[:command], 
             options[:cmdOptions], 
             "#{options[:userId]}@#{options[:remoteHost]}:#{remotePath}",
             localPath,
            ].flatten

  gl_run(*cmd, options, &aBlock);
end

.scp_to_remote_scp(localPath, remotePath, options = {}, &aBlock) ⇒ Object

Execute the rsync command on the arguments provided using greenletters.



529
530
531
532
533
534
535
536
537
538
539
# File 'lib/rake/config.rb', line 529

def self.scp_to_remote_scp(localPath, remotePath, options = {}, &aBlock)
  options = Conf.scp.data.merge(options);
  options[:timeout] = 10 unless options.has_key?(:timeout);
  cmd     = [options[:command], 
             options[:cmdOptions], 
             localPath,
             "#{options[:userId]}@#{options[:remoteHost]}:#{remotePath}",
            ].flatten

  gl_run(*cmd, options, &aBlock);
end

Instance Method Details

#execute(args = nil) ⇒ Object

Execute the actions associated with this task.



173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/rake/extensions.rb', line 173

def execute(args=nil)
  args ||= EMPTY_TASK_ARGS
  if application.options.dryrun
    Rake::Application.mesg "** Execute (dry run) #{name}"
    return
  end
  if application.options.trace
    Rake::Application.mesg "** Execute #{name}"
  end
  application.enhance_with_matching_rule(name) if @actions.empty?
  @actions.each do |act|
    case act.arity
    when 1
      act.call(self)
    else
      act.call(self, args)
    end
  end
end

#invoke_with_call_chain(task_args, invocation_chain) ⇒ Object

Same as invoke, but explicitly pass a call chain to detect circular dependencies.



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/rake/extensions.rb', line 156

def invoke_with_call_chain(task_args, invocation_chain) # :nodoc:
  new_chain = InvocationChain.append(self, invocation_chain)
  @lock.synchronize do
    if application.options.trace
      Rake::Application.mesg "** Invoke #{name} #{format_trace_flags}"
    end
    return if @already_invoked
    @already_invoked = true
    invoke_prerequisites(task_args, new_chain)
    execute(task_args) if needed?
  end
rescue Exception => ex
  add_chain_to(ex, new_chain)
  raise ex
end