Class: EPC::Command::PushCommand

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

Constant Summary collapse

ZIP_DIR_EXCLUDES =
%w(target)
ZIP_FILE_EXCLUDES =
%w(pom.xml)
ZIP_EXT_EXCLUDES =
['.class', '.jar']

Constants inherited from BaseCommand

BaseCommand::GIVEUP_TICKS, BaseCommand::SLEEP_TIME, 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



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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/epc/command/push_command.rb', line 14

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

  @klass_name = "push"
  params = resolve_context(args,
                            :accept_no_object => true,
                            :skip_object_resolution => Proc.new{|type, id| true},
                            :skip_target_resolution => Proc.new{|type, id| true})


  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
  parse_timeout_value

  if has_object? && has_target?
    raise InputError, "When manually specifying solution and project context you must provide the path to the file with --direct-deploy" if @options[:direct_deploy].blank?
    solution_name = object_id
    project_name = target_id
    paths = [@options[:direct_deploy]]
  end


  if solution_name.blank? && project_name.blank?
    solution_id, solution_name = infer_solution_context(nil, path)
    raise FatalError, "Solution could not be inferred" if solution_id.nil?

    if EPC::Config.is_solution_dir?(path)
      if project_name.nil?
        proceed = ask_yn("You are pushing the [#{solution_name}] solution. Correct: [Yn]? ") 
        paths = Dir.glob(path +"/*/").select{|dir| EPC::Config.is_project_dir?(dir)}
      else
        project_id, p_name = infer_project_context(project_name, path, solution_id, {:get_project_name => true})
        raise FatalError, "Project not found. Please run this command with the correct project name." if !project_name.nil? && (p_name.nil? || p_name.empty?)
        proceed = ask_yn("You are pushing the [#{p_name}] project belonging to the [#{solution_name}] solution. Correct: [Yn]? ") 
        paths = [path + "/#{project_name}"]
      end
    elsif EPC::Config.is_project_dir?(path)
      project_id, project_name = infer_project_context(p_name, path, solution_id, false)
      raise FatalError if project_id.nil?
      proceed = ask_yn("You are pushing the [#{project_name}] project belonging to the [#{solution_name}] solution. Correct: [Yn]? ") 
      paths = [path]
    else
      say("This command must be run from a solution/project directory")
      return 1
    end

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

    raise FatalError, "Nothing to push" if paths.empty?
  end

  @versions = []
  paths.each do |path|
    project_id, project_name = infer_project_context(nil, path, solution_id, {:get_project_name => true}) unless project_name.present? && has_target?
    say("\nPushing #{project_name}...")
    begin
      zip_path = @options[:direct_deploy].present? ? @options[:direct_deploy] : zip_source(path)
      raise FatalError, "File missing: #{zip_path}" unless zip_path && File.exists?(zip_path)
      sha1 = sha1(zip_path)
      zip_file_name = @options[:direct_deploy].present? ? File.basename(zip_path) : nil
      status, url, signature, id = create_push(project_name, solution_name, sha1, @options[:note], zip_file_name)
      if status.successful?
        pushed = push_zip(zip_path, url, signature, @options[:direct_deploy])
        resp = confirm_push(id)
        if resp[:build_id].present? && !@options[:skip_build]
          poll_for_build_status(resp[:build_id]) unless @options[:no_poll].present?
        end
        @versions << {project_name => resp[:project_version]} if pushed
      else
        return 1
      end
    rescue Exception => ex
      say("Push failed [#{ex}].")
      return 1
    end
  end
  return 0
end

#execute_internalObject



99
100
101
102
# File 'lib/epc/command/push_command.rb', line 99

def execute_internal
  code = execute
  return code, @versions
end