Class: RSCM::ClearCase
Constant Summary collapse
- LOG_FORMAT =
"- !ruby/object:RSCM::RevisionFile\\n developer: %u\\n time: \\\"%Nd\\\"\\n native_revision_identifier: %Vn\\n previous_native_revision_identifier: %PVn\\n path: %En\\n status: %o\\n message: \\\"%Nc\\\"\\n\\n"
- TIME_FORMAT =
"%d-%b-%Y.%H:%M:%S"
- MAGIC_TOKEN =
"9q8w7e6r5t4y"
- STATUSES =
{ "checkin" => RevisionFile::MODIFIED, "mkelem" => RevisionFile::ADDED, "rmelem" => RevisionFile::DELETED, }
- DEFAULT_CONFIG_SPEC =
"element * CHECKEDOUT\nelement * /main/LATEST"
Constants included from RevisionPoller
RevisionPoller::BASE_INCREMENT, RevisionPoller::CRITICAL_REVISION_SIZE, RevisionPoller::TWENTY_FOUR_HOURS
Instance Attribute Summary collapse
-
#config_spec ⇒ Object
Returns the value of attribute config_spec.
-
#stgloc ⇒ Object
Returns the value of attribute stgloc.
-
#stream ⇒ Object
Returns the value of attribute stream.
-
#tag ⇒ Object
Returns the value of attribute tag.
Attributes inherited from Base
#default_options, #store_revisions_command
Attributes included from RevisionPoller
Instance Method Summary collapse
- #catcs(options = {}) ⇒ Object
- #checked_out? ⇒ Boolean
- #destroy_working_copy(options = {}) ⇒ Object
- #import_central(options = {}) ⇒ Object
-
#initialize(stream = nil, stgloc = nil, tag = nil, config_spec = DEFAULT_CONFIG_SPEC) ⇒ ClearCase
constructor
A new instance of ClearCase.
-
#load_rules ⇒ Object
What’s loaded into view.
-
#mkview!(options = {}) ⇒ Object
Non-RSCM API methods.
- #revisions(from_identifier, options = {}) ⇒ Object
- #update_load_rules!(options = {}) ⇒ Object
- #vob(load_rule) ⇒ Object
Methods inherited from Base
#==, #add, #available?, #can_create_central?, #central_exists?, #checked_out_files, #checkout, #checkout_commandline, #checkout_dir, #checkout_dir=, #commit, #create_central, #destroy_central, #diff, #edit, #install_trigger, #move, #open, #store_revisions_command?, #supports_trigger?, #to_identifier, #to_yaml_properties, #transactional?, #trigger_installed?, #trigger_mechanism, #uninstall_trigger, #update_commandline, #uptodate?
Methods included from RevisionPoller
Constructor Details
#initialize(stream = nil, stgloc = nil, tag = nil, config_spec = DEFAULT_CONFIG_SPEC) ⇒ ClearCase
Returns a new instance of ClearCase.
23 24 25 |
# File 'lib/rscm/scm/clearcase.rb', line 23 def initialize(stream=nil, stgloc=nil, tag=nil, config_spec=DEFAULT_CONFIG_SPEC) @stream, @stgloc, @tag, @config_spec = stream, stgloc, tag, config_spec end |
Instance Attribute Details
#config_spec ⇒ Object
Returns the value of attribute config_spec.
21 22 23 |
# File 'lib/rscm/scm/clearcase.rb', line 21 def config_spec @config_spec end |
#stgloc ⇒ Object
Returns the value of attribute stgloc.
21 22 23 |
# File 'lib/rscm/scm/clearcase.rb', line 21 def stgloc @stgloc end |
#stream ⇒ Object
Returns the value of attribute stream.
21 22 23 |
# File 'lib/rscm/scm/clearcase.rb', line 21 def stream @stream end |
#tag ⇒ Object
Returns the value of attribute tag.
21 22 23 |
# File 'lib/rscm/scm/clearcase.rb', line 21 def tag @tag end |
Instance Method Details
#catcs(options = {}) ⇒ Object
115 116 117 118 119 120 121 122 |
# File 'lib/rscm/scm/clearcase.rb', line 115 def catcs(={}) Dir.chdir(checkout_dir) do catcs_cmd = "cleartool catcs" execute(catcs_cmd, ) do |io| yield io end end end |
#checked_out? ⇒ Boolean
74 75 76 |
# File 'lib/rscm/scm/clearcase.rb', line 74 def checked_out? !Dir["#{checkout_dir}/*"].empty? end |
#destroy_working_copy(options = {}) ⇒ Object
78 79 80 81 82 |
# File 'lib/rscm/scm/clearcase.rb', line 78 def destroy_working_copy(={}) execute("cleartool rmview #{checkout_dir}", ) do |io| io.read end end |
#import_central(options = {}) ⇒ Object
84 85 86 87 88 |
# File 'lib/rscm/scm/clearcase.rb', line 84 def import_central(={}) execute("clearfsimport -recurse -nsetevent #{[:dir]} #{checkout_dir}", ) do |io| io.read end end |
#load_rules ⇒ Object
What’s loaded into view
133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/rscm/scm/clearcase.rb', line 133 def load_rules result = [] catcs do |io| io.each_line do |line| if(line =~ /^load[\s]*(.*)$/) return result << $1 end end end result end |
#mkview!(options = {}) ⇒ Object
Non-RSCM API methods
92 93 94 95 96 97 98 |
# File 'lib/rscm/scm/clearcase.rb', line 92 def mkview!(={}) # Create view (working copy) mkview_cmd = "cleartool mkview -snapshot -stream #{@stream} -stgloc #{@stgloc} -tag #{@tag} #{@checkout_dir}" execute(mkview_cmd, ) do |io| puts io.read end end |
#revisions(from_identifier, options = {}) ⇒ Object
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 |
# File 'lib/rscm/scm/clearcase.rb', line 27 def revisions(from_identifier, ={}) = { :from_identifier => from_identifier, :to_identifier => Time.infinity, :relative_path => nil }.merge() checkout unless checked_out? rules = load_rules vob = vob(rules[0]) result = Revisions.new unless vob STDERR.puts "No vob found. Please set load rules in the view: #{checkout_dir}" return result end with_working_dir(checkout_dir) do since = (from_identifier + 1).strftime(TIME_FORMAT) cmd = "cleartool lshistory -recurse -nco -since #{since} -fmt \"#{LOG_FORMAT}\" -pname #{vob}" execute(cmd, ) do |io| # escape all quotes, except the one at the beginning and end. this is a bit ugly... raw_yaml = io.read fixed_yaml = raw_yaml.gsub(/^ message: \"/, " message: #{MAGIC_TOKEN}") fixed_yaml = fixed_yaml.gsub(/\"\n\n/, "#{MAGIC_TOKEN}\n\n") fixed_yaml = fixed_yaml.gsub(/\"/, "\\\"") fixed_yaml = fixed_yaml.gsub(MAGIC_TOKEN, "\"") files = YAML.load(fixed_yaml) files.each do |file| file.path.gsub!(/\\/, "/") file.status = STATUSES[file.status] rev = revision(file.native_revision_identifier) if(rev && matches_load_rules?(rules, file.path)) file.native_revision_identifier = rev file.previous_native_revision_identifier = revision(file.previous_native_revision_identifier) t = file.time # the time now has escaped quotes.. file.time = Time.utc(t[2..5],t[6..7],t[8..9],t[11..12],t[13..14],t[15..16]) file..strip! result.add(file) end end end end result end |
#update_load_rules!(options = {}) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/rscm/scm/clearcase.rb', line 100 def update_load_rules!(={}) Dir.chdir(checkout_dir) do # tempfile is broken on windows (!!) cfg_spec_file = "__rscm.cfgspec" config_spec_file = File.open(cfg_spec_file, "w") do |io| io.write(@config_spec) end setcs_cmd = "cleartool setcs #{cfg_spec_file}" Better.popen(setcs_cmd, "w") do |io| io.write "yes\n" end end end |
#vob(load_rule) ⇒ Object
124 125 126 127 128 129 130 |
# File 'lib/rscm/scm/clearcase.rb', line 124 def vob(load_rule) if(load_rule =~ /[\\\/]*([\w]*)/) $1 else nil end end |