Module: Generator::Util

Included in:
Generator
Defined in:
lib/fusegen/util.rb

Instance Method Summary collapse

Instance Method Details

#copy_from_repo(source, destination, options = {}) ⇒ Object



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
# File 'lib/fusegen/util.rb', line 24

def copy_from_repo(source, destination, options = {})
  
  base = options[:gitbase] unless options[:gitbase].nil?    
  prefix = ""

  # true when creating a new project
  if options[:category] != "none" && options[:name]
    base = base  + options[:category] + '/' + options[:name] + '/'
    prefix = options[:name] + '/'
  end

  begin
     #remove_file destination  
     if base =~ /http/
       get base + source, prefix + destination, options
     else
       copy_file base + source, prefix + destination, options
     end
  rescue Exception => e 
     say_error "Unable to load " + base + source
     if options[:debug] 
         puts e.message  
         puts e.backtrace
     end         
  end    
end

#get_quickstarts(options = {}) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/fusegen/util.rb', line 105

def get_quickstarts(options={}) 
  repos = load_file "~/.fusegen/repos"

  quickstarts = {}
  repos.each do |key, value|

    # load the index
    index = load_file "~/.fusegen/#{value["meta"]}/index"

    meta = index["meta"]
    
    # refresh index if its expired
    if meta && meta["expires"] < Time.now
      options[:gitbase] = meta["baseuri"]
      do_repo_add meta["baseuri"], options
      index = load_file "~/.fusegen/#{value["meta"]}/index"
    end
    
    index["quickstarts"].each do |category, meta|
       meta.each do |template|
          template["repo"] = value["meta"]
          template["baseuri"] = index["meta"]["baseuri"]       
          template["category"] = category      
               
          if quickstarts[category].nil? then quickstarts[category] = []; end
          quickstarts[category] << template
       end
    end
  end
  quickstarts
end

#get_substitution_value(keyword, options = {}) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/fusegen/util.rb', line 68

def get_substitution_value(keyword, options={})
  case keyword
    when "@project_version" 
      options[:projectversion]
    when "@package" 
      options[:groupid]
    when "@package_reverse" 
      options[:groupid].split(".").reverse.join(".")
    when "@group_id"
      options[:groupid]
    when "@artifact_id"
      options[:artifactid]      
    when "@packaging"
      options[:packaging]
    when "@project_version"
      options[:projectversion]      
    when "@name"
      options[:name]  
    when "@camel_version"
      get_version(options[:fuseversion],"camel")
    when "@activemq_version"
      get_version(options[:fuseversion],"activemq")
    when "@cxf_version"
      get_version(options[:fuseversion],"cxf")
    when "@smx_version"
      get_version(options[:fuseversion],"smx")
    when "@karaf_version"
      get_version(options[:fuseversion],"karaf")
    when "@spring_version"
      get_version(options[:fuseversion],"spring",false)
    when "@fabric_host" 
      "@" + options[:fabrichost]
    else
      keyword 
    end
end

#get_version(project_version, component, composite = true) ⇒ Object



137
138
139
140
141
142
143
# File 'lib/fusegen/util.rb', line 137

def get_version(project_version, component, composite=true) 
  if composite
    @versions[project_version[0..1]][component] + project_version
  else
    @versions[project_version[0..1]][component]
  end
end

#initializeObject



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/fusegen/util.rb', line 10

def initialize
  super
  @versions = { 
    "60"=> { "camel"=>"2.10.0.redhat-", "activemq"=>"5.8.0.redhat-", 
             "cxf"=>"2.6.0.redhat-", "spring"=>"3.1.3.RELEASE",
             "karaf"=>"2.3.0.redhat-" }, 
             
    "61"=> { "camel"=>"2.12.0.redhat-", "activemq"=>"5.9.0.redhat-", 
             "cxf"=>"2.7.0.redhat-", "spring"=>"3.2.3.RELEASE",
             "karaf"=>"2.3.0.redhat-" } 
  }            
end

#load_file(file, options = {}) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/fusegen/util.rb', line 51

def load_file(file, options={})
  begin
    cfg = {}
    if file =~ /~/
      file[0] = ''
      file = File.expand_path('~') + file
    end

    if options[:name]
      file = options[:name] + '/' + file
    end
    cfg = YAML.load_file(file)
  rescue Exception => e        
  end
  cfg
end

#say_error(name) ⇒ Object



157
158
159
# File 'lib/fusegen/util.rb', line 157

def say_error(name)
   say "\033[1m\033[31m" + "error".rjust(10) + "\033[0m" + "  #{name}" 
end

#say_info(name) ⇒ Object



149
150
151
# File 'lib/fusegen/util.rb', line 149

def say_info(name)
   say "\033[1m\033[36m" + "info".rjust(10) + "\033[0m" + "  #{name}" 
end

#say_task(name) ⇒ Object



145
146
147
# File 'lib/fusegen/util.rb', line 145

def say_task(name)
   say "\033[1m\033[32m" + "task".rjust(10) + "\033[0m" + "  #{name} .." 
end

#say_warn(name) ⇒ Object



153
154
155
# File 'lib/fusegen/util.rb', line 153

def say_warn(name)
   say "\033[1m\033[36m" + "warn".rjust(10) + "\033[0m" + "  #{name}" 
end