Class: EPC::Command::BuildCommand

Inherits:
BaseCommand show all
Defined in:
lib/epc/command/build_command.rb

Constant Summary

Constants inherited from BaseCommand

EPC::Command::BaseCommand::GIVEUP_TICKS, EPC::Command::BaseCommand::SLEEP_TIME, EPC::Command::BaseCommand::TICKER_TICKS

Instance Attribute Summary

Attributes inherited from BaseCommand

#client, #klass_name, #object_id, #object_type, #options, #target_id, #target_type

Instance Method Summary collapse

Methods inherited from BaseCommand

#check_options, #context_params, #context_params=, #go, include_module, inherited, #initialize, required_options, #say_err

Methods included from PersistentAttributes

#auth_token, #caller_id, #target_url

Constructor Details

This class inherits a constructor from EPC::Command::BaseCommand

Instance Method Details

#execute(*args) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/epc/command/build_command.rb', line 6

def execute(*args)
  path = "."  
  path = File.expand_path(path)

  projects_data = {}

  if @options[:no_poll].present? && @options[:timeout].present?
    raise InputError, "You cannot specify both --nopoll and --timeout options at the same time"
  end

  @timeout = GIVEUP_TICKS

  solution_id, solution_name = infer_solution_context(nil, path)

  if EPC::Config.is_solution_dir?(path)
    if args.empty?
      proceed = ask_yn("You are building the [#{solution_name}] solution. Correct: [Yn]? ") 
      Dir.glob(path +"/*/").select{|dir| EPC::Config.is_project_dir?(dir)}.map{|pth| projects_data[EPC::Config.get_project_value(pth, "id")] = nil}
    else
      names = []
      args.map{|e| e.split("=")}.each do |project_name, version|
        if numeric?(project_name)
          project_id = project_name.to_i
        else
          project_id, p_name = infer_project_context(project_name, path, solution_id)
        end
        raise FatalError, "Project not found.Please run this command with the correct project name." if project_id.nil? || project_id == 0

        names << project_name
        projects_data[project_id] = version
      end

      proceed = ask_yn("You are building the [#{names.join(",")}] projects belonging to the [#{solution_name}] solution. Correct: [Yn]? ") 
    end

  elsif EPC::Config.is_project_dir?(path)
    project_id, project_name = infer_project_context(project_name, path, false) 
    raise FatalError, "Project could not be inferred" if project_id.nil?

    proceed = ask_yn("You are building the [#{project_name}] project belonging to the [#{solution_name}] solution. Correct: [Yn]? ") 
    projects_data[project_id] = (args.first rescue nil)
  end

  return 1 if (proceed.upcase == "N" rescue true )


  parse_timeout_value

  if projects_data.keys
    created, id = create_build(projects_data, @options[:note])
    if created && @options[:no_poll].nil?
      say("Building - ")
      return poll_for_build_status(id)
    end
  else
    say_err("Failed to find the project ID in the EPC configuration. Aborting")
  end
  return 1
end