Class: RSCM::ClearCase

Inherits:
Base
  • Object
show all
Defined in:
lib/rscm/scm/clearcase.rb

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 inherited from Base

Base::DEFAULT_QUIET_PERIOD, Base::THIRTY_TWO_WEEKS_AGO, Base::TWO_WEEKS_AGO

Instance Attribute Summary collapse

Attributes inherited from Base

#default_options, #logger

Instance Method Summary collapse

Methods inherited from Base

#==, #add, #can_create_central?, #central_exists?, #checkout, #checkout_commandline, #checkout_dir, #checkout_dir=, #commit, #create_central, #destroy_central, #diff, #edit, #file, #install_trigger, #move, #open, #poll_new_revisions, #rootdir, #supports_trigger?, #to_identifier, #to_yaml_properties, #transactional?, #trigger_installed?, #trigger_mechanism, #uninstall_trigger, #update_commandline, #uptodate?

Constructor Details

#initialize(stream = nil, stgloc = nil, tag = nil, config_spec = DEFAULT_CONFIG_SPEC) ⇒ ClearCase

Returns a new instance of ClearCase.



21
22
23
# File 'lib/rscm/scm/clearcase.rb', line 21

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_specObject

Returns the value of attribute config_spec.



19
20
21
# File 'lib/rscm/scm/clearcase.rb', line 19

def config_spec
  @config_spec
end

#stglocObject

Returns the value of attribute stgloc.



19
20
21
# File 'lib/rscm/scm/clearcase.rb', line 19

def stgloc
  @stgloc
end

#streamObject

Returns the value of attribute stream.



19
20
21
# File 'lib/rscm/scm/clearcase.rb', line 19

def stream
  @stream
end

#tagObject

Returns the value of attribute tag.



19
20
21
# File 'lib/rscm/scm/clearcase.rb', line 19

def tag
  @tag
end

Instance Method Details

#catcs(options = {}) ⇒ Object



113
114
115
116
117
118
119
120
# File 'lib/rscm/scm/clearcase.rb', line 113

def catcs(options={})
  Dir.chdir(checkout_dir) do
    catcs_cmd = "cleartool catcs"
    execute(catcs_cmd, options) do |io|
      yield io
    end
  end
end

#checked_out?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/rscm/scm/clearcase.rb', line 72

def checked_out?
  !Dir["#{checkout_dir}/*"].empty?
end

#destroy_working_copy(options = {}) ⇒ Object



76
77
78
79
80
# File 'lib/rscm/scm/clearcase.rb', line 76

def destroy_working_copy(options={})
  execute("cleartool rmview #{checkout_dir}", options) do |io|
    io.read
  end
end

#import_central(options = {}) ⇒ Object



82
83
84
85
86
# File 'lib/rscm/scm/clearcase.rb', line 82

def import_central(options={})
  execute("clearfsimport -recurse -nsetevent #{options[:dir]} #{checkout_dir}", options) do |io|
    io.read
  end
end

#load_rulesObject

What’s loaded into view



131
132
133
134
135
136
137
138
139
140
141
# File 'lib/rscm/scm/clearcase.rb', line 131

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



90
91
92
93
94
95
96
# File 'lib/rscm/scm/clearcase.rb', line 90

def mkview!(options={})
   # Create view (working copy)
   mkview_cmd = "cleartool mkview -snapshot -stream #{@stream} -stgloc #{@stgloc} -tag #{@tag} #{@checkout_dir}"
   execute(mkview_cmd, options) do |io|
     puts io.read
   end
end

#revisions(from_identifier, options = {}) ⇒ Object



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
# File 'lib/rscm/scm/clearcase.rb', line 25

def revisions(from_identifier, options={})
  options = {
    :from_identifier => from_identifier,
    :to_identifier => Time.infinity, 
    :relative_path => nil
  }.merge(options)

  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, options) 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.message.strip!
          result.add(file)
        end
      end
    end
  end
  result
end

#update_load_rules!(options = {}) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/rscm/scm/clearcase.rb', line 98

def update_load_rules!(options={})
  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



122
123
124
125
126
127
128
# File 'lib/rscm/scm/clearcase.rb', line 122

def vob(load_rule)
  if(load_rule =~ /[\\\/]*([\w]*)/)
    $1
  else
    nil
  end
end