Class: DevTasks

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDevTasks

Returns a new instance of DevTasks.



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
# File 'lib/dev_tasks.rb', line 23

def initialize
  @timer = Timer.new
	self[:name]=pwd.split('/').last#Rake.application.original_dir.split('/').last
	self[:svn_exports]=SvnExports.new
	self[:scm]=Environment.scm
	self[:scm_origin]=Environment.scm_origin
	self[:branch]=Environment.branch

	
	self[:task_order]=['pull','upgrade','setup','add','build','test','commit','push','verify','publish']
	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
	
	self[:files]=Hash.new
	#self[:files][:source]=Rake::FileList.new("**/{*.{rb,feature,spec,gemspec,cs,c,m,cpp,cxx,h,hpp,i,jam,csproj,vcproj,snk,vcxproj,xcodeproj,plist,xib,sln,filters,xaml,yml,json,resx,settings,config},Jamfile,.semver,Gemfile,README,LICENSE}")
self[:files][:source]=Rake::FileList.new("**/{*.{rb,feature,spec,gemspec}}")
self[:files][:source].include('**/*.{cs,csproj,sln}')
self[:files][:source].include('**/*.{cpp,cxx,h,hpp,i,c,vcproj,vcxproj,filters,resx,settings,config}')
self[:files][:source].include('**/*.{m,xcodeproj,xib}')
self[:files][:source].include('**/*.{xaml,xml,yaml,yml,json,md}')
self[:files][:source].include('**/{Jamfile,.semver,Gemfile,README,LICENSE}')
self[:files][:source].exclude("log/**/*.*")
self[:files][:source].exclude("bin/**/*.*")
self[:files][:source].exclude("obj/**/*.*")
 
	self[:files][:build]=Rake::FileList.new('**/*.{gemspec,sln}')

	self[:files][:artifact]=Rake::FileList.new("**/*.{gem,lib,dll,exe,h,hpp}")

	

	self[:commands]=Commands.new
	update
end

Instance Attribute Details

#timerObject

Returns the value of attribute timer.



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

def timer
  @timer
end

Class Method Details

.description(task_name) ⇒ Object



107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/dev_tasks.rb', line 107

def self.description task_name
	descriptions={
		"add"=>"add untracked files to revision control system",
		"build"=>"executes build commands",
		"test"=>"executes test commands",
		"setup"=>"executes setup commands",
		"commit"=>"commit changes to revision control system"
	}
	if descriptions.has_key?(task_name.to_s)
	  descriptions[task_name.to_s] 
	else 
	  "#{task_name} task"
	end
end

Instance Method Details

#add(hash) ⇒ Object



63
64
65
66
67
# File 'lib/dev_tasks.rb', line 63

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

#define_task(task_name) ⇒ Object



100
101
102
103
104
105
# File 'lib/dev_tasks.rb', line 100

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

#execute(cmd) ⇒ Object



92
93
94
# File 'lib/dev_tasks.rb', line 92

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

#execute_task(task) ⇒ Object



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

def execute_task task
	self[:commands].execute_task task
end

#setup_copy(src, dest) ⇒ Object



142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/dev_tasks.rb', line 142

def setup_copy(src,dest)
  if(File.exists?(src))
 FileUtils.mkdir_p(File.dirname(dest)) if(!File.exists?(File.dirname(dest)))
 if(!File.exists?(dest))
   DEV_TASKS[:commands][:setup] << "<%FileUtils.cp('#{src}','#{dest}')%>"
 end
	else
 if(src.kind_of?(Array))
   src.each{|s|setup_copy(s,dest)}
 end
	end
end

#setup_svn_export(uri, dir) ⇒ Object



138
139
140
# File 'lib/dev_tasks.rb', line 138

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

#svn_export(dep_dir, uri) ⇒ Object



155
156
157
158
159
160
161
# File 'lib/dev_tasks.rb', line 155

def svn_export(dep_dir,uri)
  if(!File.exists?("#{Environment.dev_root}/dep/#{dep_dir}"))
 dest="#{Environment.dev_root}/dep/#{dep_dir}"
 Environment.execute "svn export #{v} #{Environment.dev_root}/dep/#{dep_dir}" if !dest.include?("@")
 Environment.execute "svn export #{v} #{Environment.dev_root}/dep/#{dep_dir}@" if dest.include?("@")
  end
end

#updateObject



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

def update
  self[:dependencies]=Dependencies.new if !has_key?(:dependencies)
	allartifactsexist = true
	self[:files][:artifact].each{|f| allartifactsexist=false if !File.exists?(f)}

	self[:newest_source_file]=self[:files][:source].max_by {|f| File.mtime(f)}
	self[:newest_artifact_file]=self[:files][:artifact].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[:task_order]=['upgrade'] if(File.mtime(self[:newest_artifact]) > File.mtime(self[:newest_src_file]))
   self[:up_to_date]=true
 end
 self[:newest_artifact_file_mtime]=File.mtime(self[:newest_artifact_file]).to_s
 self[:newest_source_file_mtime]=File.mtime(self[:newest_source_file]).to_s
	end
	update_tasks
end

#update_task_dependenciesObject



133
134
135
136
# File 'lib/dev_tasks.rb', line 133

def update_task_dependencies 
  eval('task :build=>[:setup]') if Rake::Task.task_defined?(:setup) && Rake::Task.task_defined?(:build)
  eval('task :test=>[:build]') if Rake::Task.task_defined?(:build) && Rake::Task.task_defined?(:test)
end

#update_tasksObject



122
123
124
125
126
127
128
129
130
131
# File 'lib/dev_tasks.rb', line 122

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
	update_task_dependencies
end