Initialize
[sdk/tools/sdk-build.git] / src / common / dependency.rb
1 =begin
2  
3   dependency.rb
4
5 Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6
7 Contact:
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>
12
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
16
17 http://www.apache.org/licenses/LICENSE-2.0
18
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.
24
25 Contributors:
26 - S-Core Co., Ltd
27 =end
28
29 $LOAD_PATH.unshift File.dirname(__FILE__)
30 require "Version" 
31
32 class Dependency
33     attr_accessor :package_name, :comp, :base_version, :target_os_list
34     def initialize (package_name, comp, base_version, target_os_list)
35         @package_name = package_name
36         @comp = comp
37         @base_version = base_version
38         @target_os_list = target_os_list
39     end 
40
41     def to_s
42         string = @package_name 
43         if not @comp.nil? and not @base_version.nil? then 
44             string = string + " ( #{@comp} #{@base_version} )" 
45         end
46  
47         if not @target_os_list.empty? then 
48             string = string + " [ #{@target_os_list.join("|")} ]"
49         end 
50         return string
51     end 
52
53         def match? ver
54                 if @base_version.nil? 
55                         return true
56                 end
57
58                 # compare to base version
59                 if @comp == ">>"
60                         return Version.new(ver) > Version.new(@base_version)
61                 elsif @comp == ">="
62                         return Version.new(ver) >= Version.new(@base_version)
63                 elsif @comp == "=="
64                         return Version.new(ver) == Version.new(@base_version)
65                 elsif @comp == "<="
66                         return Version.new(ver) <= Version.new(@base_version)
67                 elsif @comp == "<<"
68                         return Version.new(ver) < Version.new(@base_version)
69                 else
70                         return true
71                 end     
72         end
73 end 
74