Class: DevTasks

Inherits:
Hash
  • Object
show all
Defined in:
lib/dev_tasks.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDevTasks

Returns a new instance of DevTasks.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/dev_tasks.rb', line 22

def initialize
  @timer = Timer.new
  #hash = JSON.parse File.read("#{File.dirname(__FILE__)}/spec.json")
	#self[:dev_tasks_gem]=JSON.parse File.read("#{File.dirname(__FILE__)}/spec.json")
	self[:name]=pwd.split('/').last#Rake.application.original_dir.split('/').last
	self[:scm]=Environment.scm
	self[:branch]=Environment.branch
	self[:src_glob]="**/{*.{rb,feature,spec,cs,c,m,cpp,cxx,h,hpp,i,jam,csproj,vcproj,snk,vcxproj,xcodeproj,plist,xib,sln,filters,xaml,resx,settings,config},Jamfile,.semver,Gemfile,README,LICENSE}"
	self[:newest_src_file]=Dir.glob(self[:src_glob]).max_by {|f| File.mtime(f)}
	self[:command_order]=['pull','upgrade','setup','add','build','test','commit','publish','push']
	self[:relative_directory]=Environment.relative_directory
	self[:working_directory]=Environment.working_directory
	self[:context]=Environment.context
	self[:machine]=Environment.machine
	self[:platform]=RUBY_PLATFORM
	self[:dev_root]=Environment.dev_root
	self[:settings]=Settings.new
	update
end

Instance Attribute Details

#timerObject

Returns the value of attribute timer.



20
21
22
# File 'lib/dev_tasks.rb', line 20

def timer
  @timer
end

Instance Method Details

#add(hash) ⇒ Object



42
43
44
45
46
# File 'lib/dev_tasks.rb', line 42

def add hash
  hash.each do |key,value|
 self[key]=value if !has_key?(key)
	end
end

#define_task(task_name) ⇒ Object



93
94
95
96
97
98
# File 'lib/dev_tasks.rb', line 93

def define_task task_name
  if(!Rake::Task.task_defined?(task_name))
    ruby="desc '#{task_name} task';task :#{task_name} do;DEV_TASKS.execute_task '#{task_name}';end"
 eval(ruby)
	end
end

#execute(cmd) ⇒ Object



70
71
72
# File 'lib/dev_tasks.rb', line 70

def execute cmd
  self[:commands].execute_command cmd
end

#execute_task(task) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/dev_tasks.rb', line 74

def execute_task task
  sym_task = task.to_sym
  timer=Timer.new
  #start_time=Time.now
  Console.announce_task_start task
  if(!self[:commands].has_key?(sym_task))
    puts "no commands discovered for task " + task
  else
    self[:commands][sym_task].each {|c| self[:commands].execute_command(c) }
  end
	elapsed = timer.elapsed
  #end_time=Time.now
  #elapsed=end_time-start_time
	if elapsed > 30 
    elapsed_str="[" + "%.0f" %(elapsed) + "s]"
    Console.announce_task_end task, elapsed_str
	end
end

#setup(uri, dir) ⇒ Object



121
122
123
# File 'lib/dev_tasks.rb', line 121

def setup(uri,dir)
	DEV_TASKS[:commands][:setup] << "svn export #{uri} #{dir}" if(!File.exists?(dir))
end

#updateObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/dev_tasks.rb', line 48

def update
  self[:dependencies]=Dependencies.new if !has_key?(:dependencies)
	self[:artifacts]=Artifacts.new if !has_key?(:artifacts)
	allartifactsexist = true
	self[:artifacts].each{|f| allartifactsexist=false if !File.exists?(f)}
	self[:newest_artifact]=self[:artifacts].max_by  { |f| File.mtime(f) } if allartifactsexist

	self[:commands]=Commands.new if !has_key?(:commands)
	self[:commands].update

	self[:up_to_date] = false
	if(allartifactsexist && !self[:newest_artifact].nil? && !self[:newest_src_file].nil? && File.exists?(self[:newest_artifact]) && File.exists?(self[:newest_src_file]))
 if(File.mtime(self[:newest_artifact]) > File.mtime(self[:newest_src_file]))
   self[:command_order]=['upgrade'] if(File.mtime(self[:newest_artifact]) > File.mtime(self[:newest_src_file]))
   self[:up_to_date]=true
 end
 self[:newest_artifact_mtime]=File.mtime(self[:newest_artifact]).to_s
 self[:newest_src_file_mtime]=File.mtime(self[:newest_src_file]).to_s
	end
	update_tasks
end

#update_tasksObject



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/dev_tasks.rb', line 100

def update_tasks
  dev_task_defaults=Array.new
	self[:commands].each do |key,array|
 if(array.length > 0)
   define_task key
   dev_task_defaults << key
 end
	end

	#if(!Rake::Task.task_defined?('dev_tasks_default'))
	#  tasklist=""
	#  dev_task_defaults.each{|t|
	#    tasklist = tasklist + "," if tasklist.length > 0
	#    tasklist = tasklist + ":" + t.to_s
	#  }
	#  ruby="desc 'dev_tasks_default task [#{tasklist}]';task :dev_tasks_default => [#{tasklist}] do;puts '[:dev_task_default] completed in ' + DEV_TASKS.timer.elapsed_str;end"
	#  eval(ruby)
	#end
end