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, #options

Instance Method Summary collapse

Methods inherited from BaseCommand

#go, inherited, #initialize, required_options

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(project_name = nil) ⇒ Object

Raises:



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
# File 'lib/epc/command/push_command.rb', line 14

def execute(project_name = nil)
  path = "."  
  path = File.expand_path(path)


  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

  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?

  @versions = []
  paths.each do |path|
    project_id, project_name = infer_project_context(nil, path, solution_id, {:get_project_name => true})
    say("\nPushing #{project_name}...")
    begin
      zip_path = zip_source(path)
      return 1 unless zip_path
      sha1 = sha1(zip_path)
      status, url, signature, id = create_push(project_name, solution_name, sha1, @options[:note])
      if status.successful?
        pushed = push_zip(zip_path, url, signature)
        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



83
84
85
86
# File 'lib/epc/command/push_command.rb', line 83

def execute_internal
  code = execute
  return code, @versions
end