5 Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
8 Taejun Ha <taejun.ha@samsung.com>
9 Jiil Hyoun <jiil.hyoun@samsung.com>
10 Donghyuk Yang <donghyuk.yang@samsung.com>
11 DongHee Yang <donghee.yang@samsung.com>
13 Licensed under the Apache License, Version 2.0 (the "License");
14 you may not use this file except in compliance with the License.
15 You may obtain a copy of the License at
17 http://www.apache.org/licenses/LICENSE-2.0
19 Unless required by applicable law or agreed to in writing, software
20 distributed under the License is distributed on an "AS IS" BASIS,
21 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 See the License for the specific language governing permissions and
23 limitations under the License.
30 $LOAD_PATH.unshift File.dirname(__FILE__)
31 require "GitBuildProject.rb"
32 require "BinaryUploadProject.rb"
33 require "MultiBuildJob.rb"
34 require "PackageManifest.rb"
38 attr_accessor :projects
41 def initialize( server )
44 @project_root = "#{@server.path}/projects"
48 # load existing project from server configuration
51 if not File.exist? @project_root then
52 FileUtils.mkdir_p @project_root
56 Dir.new(@project_root).entries.each do |name|
58 if name.eql? "." or name.eql? ".." then next end
61 @server.log.info "Loading project : #{name}"
62 prj = load_project( name )
71 # get_project of the name
72 def get_project ( name )
73 @projects.each do |prj|
74 if prj.name.eql? name then return prj end
81 def add_git_project(name , repos, branch, passwd, os_list)
82 prj = get_project( name)
83 if not prj.nil? then return false end
85 new_prj = GitBuildProject.new(name, repos, branch, @server, os_list)
86 if not passwd.nil? and not passwd.empty? then
87 new_prj.passwd = passwd
89 @projects.push new_prj
91 # check project directory
92 if not File.exist? "#{@project_root}/#{name}" then
93 FileUtils.mkdir_p "#{@project_root}/#{name}"
97 write_configuration(name, repos, branch, passwd, os_list)
103 def add_binary_project(name, pkg_name, passwd, os_list)
104 prj = get_project( name)
105 if not prj.nil? then return false end
107 new_prj = BinaryUploadProject.new(name, pkg_name, @server, os_list)
108 if not passwd.nil? and not passwd.empty? then
109 new_prj.passwd = passwd
111 @projects.push new_prj
113 # check project directory
114 if not File.exist? "#{@project_root}/#{name}" then
115 FileUtils.mkdir_p "#{@project_root}/#{name}"
118 # write configuration
119 write_configuration_for_binary_project(name, pkg_name, passwd, os_list)
125 def add_remote_project( name, server_id)
129 # create new job for project
130 # if cannot create, return nil
131 def create_new_job( name, os )
132 prj = get_project( name )
133 if prj.nil? then return nil end
135 return prj.create_new_job( os )
139 # create new multi build job
140 def create_new_multi_build_job( sub_job_list )
141 result = MultiBuildJob.new( @server )
143 sub_job_list.each do |job|
144 result.add_sub_job( job )
151 # create new full job
152 def create_new_full_build_job( )
154 result = MultiBuildJob.new( @server )
157 @projects.each do |prj|
158 if prj.type != "GIT" then next end
160 prj.os_list.each do |os|
161 if not @server.supported_os_list.include? os then next end
163 new_job = create_new_job( prj.name, os )
164 if new_job.nil? then next end
166 # This make project to build
167 # even though there is a package of same version on pkg-server
168 new_job.set_force_rebuild(true)
171 result.add_sub_job( new_job )
179 # get project that includes specified pkg name and os
180 # will return [project,os,ver] list
181 def get_projects_from_pkgs(pkgs)
183 @projects.each do |prj|
185 name = pkg.package_name
189 # check project provide target package
190 if prj.include_package?(name, ver, os) then
191 result.push [prj, os, ver]
201 def get_project_from_package_name(pkg_name)
202 @projects.each do |prj|
203 # check project provide target package
204 if prj.include_package?(pkg_name) then
213 # get project from git repository
214 def get_git_project( repos )
215 @projects.each { |prj|
216 if prj.type == "GIT" and prj.repository == repos then
225 def create_unnamed_git_project(repos)
226 name = "UNNAMED_PRJ_#{@projects.count}"
229 os_list = Utils.get_all_OSs()
231 add_git_project(name , repos, branch, passwd, os_list)
233 return get_project(name)
238 # load and create project
239 def load_project(name)
242 config_file = "#{@project_root}/#{name}/build"
243 if not File.exist? config_file then return nil end
250 os_list = @server.supported_os_list
253 File.open( config_file, "r" ) do |f|
255 idx = l.index("=") + 1
256 length = l.length - idx
258 if l.start_with?("TYPE=")
259 type = l[idx,length].strip
260 elsif l.start_with?("PASSWD=")
261 passwd = l[idx,length].strip
262 elsif l.start_with?("GIT_REPOSITORY=")
263 repos = l[idx,length].strip
264 elsif l.start_with?("GIT_BRANCH=")
265 branch = l[idx,length].strip
266 elsif l.start_with?("OS_LIST=")
267 os_list = l[idx,length].strip.split(",")
268 elsif l.start_with?("REMOTE_SERVER_ID=")
269 rserver_id = l[idx,length].strip
270 elsif l.start_with?("PACKAGE_NAME=")
271 pkg_name = l[idx,length].strip
278 # write back & create project
279 if type == "GIT" then
280 write_configuration(name, repos, branch, passwd, os_list)
281 new_project = GitBuildProject.new(name, repos, branch, @server, os_list)
284 sources_file = "#{@project_root}/#{name}/sources"
285 if File.exist? sources_file then
286 File.open(sources_file, "r") do |f|
288 version = l.split(",")[0].strip
289 info = l.split(",")[1].strip
291 new_project.add_source_info( version, info )
297 pkginfo_dir = "#{@project_root}/#{name}/pkginfos"
298 if not File.exist? pkginfo_dir then FileUtils.mkdir_p pkginfo_dir end
299 Dir.new(pkginfo_dir).entries.each do |file|
300 if file.eql? "." or file.eql? ".." then next end
302 vlen = file.length - ".manifest".length
303 version = file[0,vlen]
304 new_project.add_package_info( version, "#{pkginfo_dir}/#{file}" )
307 elsif type == "BINARY" then
308 write_configuration_for_binary_project(name, pkg_name, passwd, os_list)
309 new_project = BinaryUploadProject.new(name, pkg_name, @server, os_list)
313 # set passwd if exist
314 if not passwd.empty? then
315 new_project.passwd = passwd
323 # write configuration
324 def write_configuration(name, repos, branch, passwd, os_list )
325 config_file = "#{@project_root}/#{name}/build"
326 File.open( config_file, "w" ) do |f|
328 if not passwd.nil? and not passwd.empty? then
329 f.puts "PASSWD=#{passwd}"
331 f.puts "GIT_REPOSITORY=#{repos}"
332 f.puts "GIT_BRANCH=#{branch}"
333 f.puts "OS_LIST=#{os_list.join(",")}"
338 # write configuration
339 def write_configuration_for_binary_project(name, pkg_name, passwd, os_list )
340 config_file = "#{@project_root}/#{name}/build"
341 File.open( config_file, "w" ) do |f|
343 if not passwd.nil? and not passwd.empty? then
344 f.puts "PASSWD=#{passwd}"
346 f.puts "PACKAGE_NAME=#{pkg_name}"
347 f.puts "OS_LIST=#{os_list.join(",")}"