Class: ReleaseModel

Inherits:
Object
  • Object
show all
Includes:
Utilities
Defined in:
lib/release/release_model.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utilities

#ask, #echo_with_color, #help_info, #next_snapshot, #read_file, #right_padding, #terminate, #verify_pattern, #verify_pattern_terminate, #wait_or_do, #write_file

Constructor Details

#initializeReleaseModel

Returns a new instance of ReleaseModel.



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
# File 'lib/release/release_model.rb', line 12

def initialize

  @dry_run = (ask 'Dry run?','n') == 'y'

  @release_version = ask 'What should the release version be?', read_release_version
  verify_pattern_terminate @release_version, $version

  @next_version = ask 'What should the next SNAPSHOT version be?', (next_snapshot @release_version)
  verify_pattern_terminate @next_version, $snapshot_version

  @release_branch = "release/#{@release_version}"
  @snapshots = File.open('pom.xml').read.scan($snapshot_dependency)

  read_snapshot_versions
  prepare_new_iteration_deps

  echo_with_color "\n\n====================Release information========================================================",'green'
  puts "\nDry run: #{@dry_run}"
  if @dry_run
    help_info "---> IMPORTANT: Dry run will still change the snapshot dependencies versions (if any), don't forget to revert those changes\n"
  end

  help_info "\n1. Release version: "; puts release_version
  help_info "\n2. Next snapshot version: ";puts next_version
  help_info "\n3. Snapshot dependencies found:\n"

  unless @snapshots.size==0

    help_info "#{column 'Dependency'} : #{column 'Current version'} -> #{column 'Release version'} -> #{column 'New iteration version'}\n"
    @snapshots.each do |snapshot|
      puts "#{column snapshot[0]} : #{column snapshot[1]} -> #{column snapshot[2]} -> #{column snapshot[3]}"
    end
  end
  echo_with_color "\n=================================================================================================",'green'
end

Instance Attribute Details

#dry_runObject (readonly)

Returns the value of attribute dry_run.



52
53
54
# File 'lib/release/release_model.rb', line 52

def dry_run
  @dry_run
end

#next_versionObject (readonly)

Returns the value of attribute next_version.



52
53
54
# File 'lib/release/release_model.rb', line 52

def next_version
  @next_version
end

#release_branchObject (readonly)

Returns the value of attribute release_branch.



52
53
54
# File 'lib/release/release_model.rb', line 52

def release_branch
  @release_branch
end

#release_versionObject (readonly)

Returns the value of attribute release_version.



52
53
54
# File 'lib/release/release_model.rb', line 52

def release_version
  @release_version
end

#snapshotsObject (readonly)

Returns the value of attribute snapshots.



52
53
54
# File 'lib/release/release_model.rb', line 52

def snapshots
  @snapshots
end

Instance Method Details

#column(value) ⇒ Object



48
49
50
# File 'lib/release/release_model.rb', line 48

def column(value)
  right_padding value,30;
end

#prepare_new_iteration_depsObject



73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/release/release_model.rb', line 73

def prepare_new_iteration_deps
  unless @snapshots
    return
  end

  help_info "\n\nSet SNAPSHOT versions for dependencies for the next iteration"
  @snapshots.each do |snapshot|
    default_version = next_snapshot snapshot[2]
    snap_version=self.ask "For the next iteration, what snapshot version to use for ==> #{snapshot[0]}?", default_version
    snapshot << (snap_version == 'y' ? default_version : snap_version)
  end
end

#read_release_versionObject



54
55
56
57
58
# File 'lib/release/release_model.rb', line 54

def read_release_version
  artifact_version = REXML::Document.new(File.new('pom.xml')).elements['/project/version'].text
  verify_pattern_terminate artifact_version, $snapshot_version
  $snapshot_version.match(artifact_version).captures[0]
end

#read_snapshot_versionsObject



60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/release/release_model.rb', line 60

def read_snapshot_versions
  unless @snapshots
    return
  end

  help_info "\n\nFound dependencies with SNAPSHOT versions:"
  @snapshots.each do |snapshot|
    default_version=$snapshot_version.match(snapshot[1]).captures[0]
    release_version=self.ask "What release version to use for ==> #{snapshot[0]}?", default_version
    snapshot << (release_version == 'y' ? default_version : release_version)
  end
end