fusegen 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc CHANGED
@@ -2,24 +2,65 @@
2
2
 
3
3
  This project creates dynamic quickstarts for JBoss Fuse and JBoss A-MQ.
4
4
 
5
- Try it out
6
- ----------
5
+ Pre-Requisites:
6
+ ---------------
7
7
 
8
- If you have rails installed you should be able to try it out using:
8
+ Ruby and RubyGems installed on your local machine.
9
9
 
10
- >git clone https://github.com/dstanley/fusegen.git
11
- >rake package
12
- >gem install ./pkg/fusegen-0.0.1.gem
13
10
 
11
+ Try it out
12
+ ----------
13
+
14
+ >gem install fusegen
14
15
 
15
16
  Then for a list of options
16
17
 
17
18
  >fusegen help
18
19
 
20
+
21
+ *CONFIGURE & QUERY*
22
+
23
+ Add a repo to your configuration
24
+
25
+ >fusegen repo add https://raw.github.com/dstanley/fusegen-templates/master/
26
+
27
+ Query the available quickstarts
28
+
29
+ >fusegen qs list
30
+
31
+
32
+
33
+ *EXAMPLES*
34
+
35
+ Generate a camel project using defaults
36
+
37
+ >fusegen new camel-basic
38
+
19
39
  Generate a camel project using 2.10.0.redhat-60060
20
40
 
21
- >fusegen -f 60060 fuse camel-basic
41
+ >fusegen new -f 60060 -g com.mycompany.camel camel-basic
42
+
43
+ Generate a spring based cxf wsdl-first project
44
+
45
+ >fusegen new -g com.mycompany.camel cxf-wsdl-first
46
+
47
+ Generate a basic jms consumer
48
+
49
+ >fusegen new amq-consumer
50
+
51
+ Generate a multi-threaded jms producer
52
+
53
+ >fusegen new amq-producer
54
+
55
+
56
+
57
+ *LATEST*
58
+
59
+ To install from the latest source
60
+
61
+ >git clone https://github.com/dstanley/fusegen.git
62
+ >rake package
63
+ >gem install ./pkg/fusegen-0.0.1.gem
64
+
22
65
 
23
- Generate a camel project using 2.10.0.redhat-60024
24
66
 
25
- >fusegen -f 60024 fuse camel-basic
data/Rakefile CHANGED
@@ -7,7 +7,7 @@ require 'cucumber/rake/task'
7
7
  Rake::RDocTask.new do |rd|
8
8
  rd.main = "README.rdoc"
9
9
  rd.rdoc_files.include("README.rdoc","lib/**/*.rb","bin/**/*")
10
- rd.title = 'Your application title'
10
+ rd.title = 'fusegen'
11
11
  end
12
12
 
13
13
  spec = eval(File.read('fusegen.gemspec'))
data/bin/fusegen CHANGED
@@ -19,15 +19,8 @@ version Fusegen::VERSION
19
19
 
20
20
 
21
21
 
22
- desc 'Project category (e.g. fuse|amq|fabric|patch)'
23
- default_value 'none'
24
- arg_name '<category>'
25
- flag [:c,:category]
26
-
27
-
28
- desc 'Git base uri'
29
- arg_name '[gitbase]'
30
- flag [:g,:gitbase]
22
+ desc 'Debug output'
23
+ switch [:debug], { :negatable => false }
31
24
 
32
25
  desc 'Creates a new project'
33
26
  arg_name '[project]'
@@ -79,7 +72,7 @@ command :new do |c|
79
72
  options[:name] = args[0] unless args.nil?
80
73
 
81
74
  g = Generator.new
82
- g.generate(global_options,options,args)
75
+ g.new_project(global_options,options,args)
83
76
 
84
77
  end
85
78
  end
@@ -94,91 +87,104 @@ command [:qs,:quickstarts] do |c|
94
87
  c.command :list do |list|
95
88
  list.action do |global_options,options,args|
96
89
 
97
- # load top level meta data from each repo
98
- # Display by repo by default
99
- # If -c then display category list
100
- # If -t then display by tag
101
-
102
- puts "camel-base"
90
+ g = Generator.new
91
+ g.qs_list(global_options,options,args)
103
92
  end
104
93
  end
105
94
 
106
- c.desc "List available categories"
107
- c.command [:c,:categories] do |categories|
108
- categories.action do |global_options,options,args|
109
- puts "Available Categories:"
110
- puts " fuse - JBoss Fuse projects"
111
- puts " amq - JBoss A-MQ projects"
112
- puts " fabric - Fuse Fabric projects"
113
- puts " patch - JBoss Fuse patch projects"
114
-
115
- end
116
- end
117
-
118
- c.desc "Add a github repo to repository db"
119
- c.command [:ar,:addrepo] do |repo|
120
- repo.action do |global_options,options,args|
121
- # Validate input
122
- # Save the repo to local config
123
- if args.nil? || args.length == 0
124
- puts "No repo provided.."
125
- help_now!
126
- else
127
- # ... logic here
128
- puts "[TODO] Add repo to config '" + args[0] + "'"
129
- end
130
- end
131
- end
132
-
133
- c.desc "Show quickstart info for a project"
95
+
96
+ c.desc "Show quickstart info for a project template"
134
97
  c.arg_name '<name>'
135
98
  c.command :info do |info|
136
99
  info.action do |global_options,options,args|
137
-
138
-
139
100
  # Validate input
140
101
  if args.nil? || args.length == 0
141
102
  puts "No quickstart name provided.."
142
103
  help_now!
143
104
  else
144
- # ... logic here
145
- puts "[TODO] show quickstart info for '" + args[0] + "'"
105
+ g = Generator.new
106
+ g.qs_info(global_options,options,args)
146
107
  end
147
-
148
108
  end
149
109
  end
150
110
  end
151
111
 
112
+ desc 'Manage quickstart repositories'
113
+ command :repo do |c|
114
+
115
+ c.desc "Add a local or git quickstart repo"
116
+ c.arg_name '<path>'
117
+ c.command [:add] do |addrepo|
118
+ addrepo.action do |global_options,options,args|
119
+ if args.nil? || args.length == 0 then
120
+ puts "No path to repository provided."
121
+ help_now!
122
+ else
123
+ g = Generator.new
124
+ g.repo_add(global_options,options,args)
125
+ end
126
+ end
127
+ end
128
+
129
+ c.desc "Remove a local or git quickstart repo"
130
+ c.command [:rm] do |rm|
131
+ rm.action do |global_options,options,args|
132
+ # Validate input
133
+ # Save the repo to local config
134
+ if args.nil? || args.length == 0
135
+ puts "No repository identifier provided."
136
+ help_now!
137
+ else
138
+ g = Generator.new
139
+ g.repo_rm(global_options,options,args)
140
+ end
141
+ end
142
+ end
143
+
144
+ c.desc "List available quickstart repos"
145
+ c.command [:list] do |list|
146
+ list.action do |global_options,options,args|
147
+ g = Generator.new
148
+ g.repo_list(global_options,options,args)
149
+
150
+ end
151
+ end
152
+
153
+
154
+
155
+ end
156
+
157
+
152
158
 
153
159
  desc 'Append to an existing project'
154
- command :util do |c|
155
-
156
- c.desc "Add a features file to a project"
157
- c.command [:af,:addfeature] do |feature|
160
+ command :add do |c|
161
+
162
+ g = Generator.new
163
+
164
+ c.desc "Add a karaf features file to a project"
165
+ c.command [:feature] do |feature|
158
166
  feature.action do |global_options,options,args|
159
- puts "[TODO] Add a features file to a project"
167
+ g.add_feature
160
168
  end
161
169
  end
162
170
 
163
- # TODO: Command to add maven dependencies for fuse features?
164
-
165
- c.desc "Add a maven profile to a maven pom"
166
- c.arg_name '<name> <className>'
167
- c.command [:p,:profile] do |profile|
168
- profile.action do |global_options,options,args|
169
-
170
-
171
- # Validate input
172
- if args.nil? || args.length == 0
173
- puts "No quickstart name provided.."
174
- help_now!
175
- else
176
- # ... logic here
177
- puts "[TODO] show quickstart info for '" + args[0] + "'"
178
- end
179
-
180
- end
171
+ c.desc "Add an index.yml to a fusegen template repository"
172
+ c.command [:index] do |index|
173
+ index.action do |global_options,options,args|
174
+ g.add_index
175
+ end
176
+ end
177
+
178
+ c.desc "Add an Readme.md to a project"
179
+ c.command [:readme] do |readme|
180
+ readme.action do |global_options,options,args|
181
+ g.add_readme
182
+ end
181
183
  end
184
+
185
+ # Other possible add
186
+ # Add a fabric deploy script
187
+ # Add a profile to a maven pom?
182
188
  end
183
189
 
184
190
 
@@ -0,0 +1,69 @@
1
+ require 'rubygems'
2
+ require 'thor'
3
+
4
+
5
+
6
+ class Generator < Thor
7
+
8
+ module Add
9
+
10
+ def add_index
11
+ add_template_index
12
+ end
13
+
14
+ def add_feature
15
+ puts "[TODO] Add a feature file"
16
+ end
17
+
18
+ def add_readme
19
+ puts "[TODO] Add a readme file"
20
+ end
21
+
22
+
23
+ private
24
+
25
+ # Creates an index for a template repository
26
+ def add_template_index
27
+ index = {}
28
+ quickstarts = {}
29
+
30
+ puts ""
31
+ username = ask "What is your github username?"
32
+ baseuri = "https://raw.github.com/#{username}/fusegen-templates/master"
33
+
34
+ meta = {
35
+ "version" => "0.0.1",
36
+ "author" => username,
37
+ "baseuri" => baseuri
38
+ }
39
+
40
+ Dir.glob("**/*.yml").each do |file|
41
+ path = file.split('/')
42
+
43
+ if path.length > 2
44
+ begin
45
+ config = YAML.load_file(file)
46
+ rescue Exception => e
47
+ puts "Error reading " + file
48
+ end
49
+
50
+ # First element is the category, group all categories together
51
+ if quickstarts[path[0]].nil?
52
+ quickstarts[path[0]] = [];
53
+ end
54
+ data = { "name" => path[1], "manifest" => path[2], "short_description" => config["short_description"],
55
+ "version" => config["version"] }
56
+ quickstarts[path[0]] << data
57
+ end
58
+ end
59
+
60
+ index["quickstarts"] = quickstarts
61
+ index["meta"] = meta
62
+ File.open("index.yml", 'w') { |file| YAML::dump(index, file)}
63
+
64
+ puts "Created index.yml. Please verify the baseuri is correct."
65
+ end
66
+
67
+
68
+ end
69
+ end
@@ -1,152 +1,30 @@
1
+ require 'rubygems'
1
2
  require 'thor'
3
+ require 'fusegen/repo'
4
+ require 'fusegen/new'
5
+ require 'fusegen/add'
6
+ require 'fusegen/quickstart'
7
+ require 'fusegen/util'
2
8
 
3
9
  class Generator < Thor
4
10
  include Thor::Actions
5
-
11
+ include Thor::Shell
12
+ include Generator::New
13
+ include Generator::Repo
14
+ include Generator::Add
15
+ include Generator::Quickstart
16
+ include Generator::Util
17
+
6
18
  attr_accessor :versions
7
19
 
8
- desc "generate", "generate new project"
9
- def generate(global_options,options,args)
10
-
11
- begin
12
- say_task "Creating " + options[:name]
13
- create_project options
14
- rescue Exception => e
15
- pp global_options
16
- pp options
17
- pp args
18
- puts e.message
19
- puts e.backtrace
20
- end
21
- end
22
-
23
20
  def self.source_root
24
- File.dirname(__FILE__)
21
+ File.dirname(__FILE__)
25
22
  end
26
23
 
27
24
  private
28
25
 
29
- def initialize
30
- super
31
-
32
- @versions = { "60"=> { "camel"=>"2.10.0.redhat-", "activemq"=>"5.8.0.redhat-",
33
- "cxf"=>"2.6.0.redhat-", "spring"=>"3.1.3.RELEASE",
34
- "karaf"=>"2.3.0.redhat-" },
35
- "61"=> { "camel"=>"2.12.0.redhat-", "activemq"=>"5.9.0.redhat-",
36
- "cxf"=>"2.7.0.redhat-", "spring"=>"3.2.3.RELEASE",
37
- "karaf"=>"2.3.0.redhat-" }
38
- }
39
-
40
- end
41
-
42
- def create_project(options)
43
-
44
- #begin
45
- base_path = options[:groupid].gsub('.', '/')
46
-
47
- # Download manifest
48
- copy_from_github 'manifest.yml', 'manifest.yml', options
49
-
50
- project = load_file 'manifest.yml', options
51
-
52
- if project.size > 0
53
-
54
- project["copies"].each do |source, destination|
55
- destination.gsub! '@base_path',base_path
56
- copy_from_github source, destination, options
57
- end
58
-
59
- project["subs"].each do |subs|
60
- subs[1].each do |sub|
61
- file = options[:name] + '/' + subs[0].dup
62
- file.gsub! '@base_path',base_path
63
- subvalue = get_substitution_value(sub, options)
64
- regex = Regexp.new /#{sub}/
65
- gsub_file file, regex, subvalue
66
- end
67
- end
68
-
69
- remove_file options[:name] + '/manifest.yml'
70
- else
71
- say_error "Quickstart '" + options[:name] + "' is not valid"
72
- end
73
-
74
- end
75
-
76
-
77
- def say_task(name); say "\033[1m\033[32m" + "task".rjust(10) + "\033[0m" + " #{name} .." end
78
- def say_warn(name); say "\033[1m\033[36m" + "warn".rjust(10) + "\033[0m" + " #{name}" end
79
- def say_error(name); say "\033[1m\033[31m" + "error".rjust(10) + "\033[0m" + " #{name}" end
80
-
81
-
82
26
  def source_paths
83
- [File.join(Dir.pwd, "templates")] + super
27
+ [Dir.pwd] + super
84
28
  end
85
-
86
- def copy_from_github(source, destination, options = {})
87
- base = 'https://raw.github.com/dstanley/fusegen-templates/master/archetypes/'
88
- base = options[:gitbase] unless options[:gitbase].nil?
89
- base = base + options[:category] + '/' + options[:name] + '/'
90
-
91
- begin
92
- #remove_file destination
93
- get base + source, options[:name] + '/' + destination
94
- rescue OpenURI::HTTPError
95
- say_error "Unable to download " + base + source
96
- end
97
- end
98
-
99
- def load_file(file, options={})
100
- begin
101
- cfg = {}
102
- path = options[:name] + '/' + file
103
- cfg = YAML.load_file(path)
104
- rescue Exception => e
105
- end
106
- cfg
107
- end
108
-
109
-
110
- def get_substitution_value(keyword, options={})
111
- case keyword
112
- when "@project_version"
113
- options[:projectversion]
114
- when "@package"
115
- options[:groupid]
116
- when "@package_reverse"
117
- options[:groupid].split(".").reverse.join(".")
118
- when "@group_id"
119
- options[:groupid]
120
- when "@artifact_id"
121
- options[:artifactid]
122
- when "@packaging"
123
- options[:packaging]
124
- when "@project_version"
125
- options[:projectversion]
126
- when "@name"
127
- options[:name]
128
- when "@camel_version"
129
- get_version(options[:fuseversion],"camel")
130
- when "@activemq_version"
131
- get_version(options[:fuseversion],"activemq")
132
- when "@cxf_version"
133
- get_version(options[:fuseversion],"cxf")
134
- when "@smx_version"
135
- get_version(options[:fuseversion],"smx")
136
- when "@karaf_version"
137
- get_version(options[:fuseversion],"karaf")
138
- when "@spring_version"
139
- get_version(options[:fuseversion],"spring")
140
- when "@fabric_host"
141
- "@" + options[:fabrichost]
142
- else
143
- keyword
144
- end
145
- end
146
-
147
- def get_version(project_version, component)
148
- @versions[project_version[0..1]][component] + project_version
149
- end
150
-
151
-
29
+
152
30
  end
@@ -0,0 +1,121 @@
1
+ require 'rubygems'
2
+ require 'thor'
3
+
4
+ class Generator < Thor
5
+
6
+ module New
7
+
8
+ def new_project(global_options,options,args)
9
+ do_new_project options
10
+ end
11
+
12
+ private
13
+
14
+ def do_new_project(options)
15
+
16
+ begin
17
+ base_path = options[:groupid].gsub('.', '/')
18
+
19
+ quickstart = find_quickstart(options)
20
+
21
+ if not quickstart.nil?
22
+ options[:gitbase] = quickstart["baseuri"]
23
+ options[:category] = quickstart["category"]
24
+
25
+ if options[:debug]
26
+ say_info ":gitbase " + options[:gitbase]
27
+ say_info ":gitbase " + options[:category]
28
+ end
29
+
30
+ if not options[:gitbase].end_with?('/')
31
+ options[:gitbase] = options[:gitbase] + "/"
32
+ end
33
+
34
+ say_task "Creating " + options[:name]
35
+
36
+ # Download manifest
37
+ copy_from_repo 'manifest.yml', 'manifest.yml', options
38
+
39
+ project = load_file 'manifest.yml', options
40
+
41
+ if project.size > 0
42
+
43
+ project["copies"].each do |source, destination|
44
+ destination.gsub! '@base_path',base_path
45
+ copy_from_repo source, destination, options
46
+ end
47
+
48
+ project["subs"].each do |subs|
49
+ subs[1].each do |sub|
50
+ file = options[:name] + '/' + subs[0].dup
51
+ file.gsub! '@base_path',base_path
52
+ subvalue = get_substitution_value(sub, options)
53
+ regex = Regexp.new /#{sub}/
54
+ gsub_file file, regex, subvalue
55
+ end
56
+ end
57
+
58
+ remove_file options[:name] + '/manifest.yml'
59
+ else
60
+ say_error "We found the project but cannot read its manifest :-( '" + options[:name] + "'"
61
+ end
62
+ else
63
+ say_error "Could not find '" + options[:name] + "'"
64
+ end
65
+
66
+ rescue Exception => e
67
+ if options[:debug]
68
+ puts e.message
69
+ puts e.backtrace
70
+ end
71
+ end
72
+ end
73
+
74
+
75
+ def find_quickstart(options)
76
+ # load all know quickstarts from cache
77
+ quickstarts = get_quickstarts
78
+ candidates = {}
79
+ quickstarts.each do |category, meta|
80
+ meta.each do |template|
81
+ # find a match by quickstart name
82
+ if template["name"] == options[:name]
83
+ candidates[template["repo"]] = template
84
+ end
85
+ end
86
+ end
87
+
88
+ if candidates.length > 0
89
+ # if we have > matches on the name, give user a choice
90
+ if candidates.length > 1
91
+ index = 1
92
+ choices = []
93
+
94
+ printf "%-3s [%-12s] %-10s %-20s %-60s\n", "Index", "Repository", "Category", "Name", "Description"
95
+ candidates.each do |category, template|
96
+ printf "%-5s [%-12s] %-10s %-20s %-60s\n", index.to_s, template["repo"], template["category"], template["name"], template["short_description"]
97
+ choices << index.to_s
98
+ index += 1
99
+ end
100
+
101
+ say_info "Multiple matches for #{options[:name]}. "
102
+ selection = ask("Choose quickstart: [" + choices.join(",") + "]").to_i - 1
103
+ if not candidates.to_a[selection].nil? then
104
+ template = candidates.to_a[selection]
105
+ return template[1]
106
+ else
107
+ say_error "Choice was not valid."
108
+ end
109
+ else
110
+ # We only found one match for that quickstart name
111
+ candidates.each do |category, template|
112
+ return template
113
+ end
114
+ end
115
+ end
116
+ nil
117
+ end
118
+
119
+ end
120
+
121
+ end
@@ -0,0 +1,46 @@
1
+ require 'rubygems'
2
+ require 'thor'
3
+
4
+
5
+
6
+ class Generator < Thor
7
+
8
+ module Quickstart
9
+
10
+ def qs_list(global_options,options,args)
11
+ do_qs_list
12
+ end
13
+
14
+ def qs_info(global_options,options,args)
15
+ do_qs_info args[0], options
16
+ end
17
+
18
+
19
+ private
20
+
21
+ def do_qs_info(template, options={})
22
+ puts "[TODO] show readme for quickstart .."
23
+ end
24
+
25
+ def do_qs_list(options={})
26
+ begin
27
+ quickstarts = get_quickstarts
28
+
29
+ if quickstarts.size > 0
30
+ printf "%-10s %-12s %-10s %-20s %-60s\n", "Version", "Repository", "Category", "Name", "Description"
31
+ end
32
+
33
+ quickstarts.each do |category, meta|
34
+ meta.each do |template|
35
+ printf "[%-8s] %-12s %-10s %-20s %-60s\n", template["version"], template["repo"], category, template["name"], template["short_description"]
36
+ end
37
+ end
38
+ rescue Exception => e
39
+ puts e.message
40
+ puts e.backtrace
41
+ end
42
+ end
43
+
44
+
45
+ end
46
+ end
@@ -0,0 +1,127 @@
1
+ require 'rubygems'
2
+ require 'thor'
3
+
4
+
5
+
6
+ class Generator < Thor
7
+
8
+ module Repo
9
+
10
+
11
+ def repo_list(global_options,options,args)
12
+ do_repo_list
13
+ end
14
+
15
+ def repo_add(global_options,options,args)
16
+ check_config_dir
17
+ do_repo_add args[0], options
18
+ end
19
+
20
+ def repo_rm(global_options,options,args)
21
+ do_repo_rm args[0], options
22
+ end
23
+
24
+ def repo_find_template(name)
25
+ do_repo_find_template name
26
+ end
27
+
28
+ private
29
+
30
+ def check_config_dir
31
+ if not File.directory?("~/.fusegen")
32
+ empty_directory "~/.fusegen", { :verbose => false }
33
+ end
34
+ end
35
+
36
+ def do_repo_add(path, options={})
37
+ begin
38
+
39
+ options[:verbose] = false
40
+ if path =~ /http/
41
+ if not path.end_with?('/')
42
+ path = path + "/"
43
+ end
44
+ # convert to a raw github uri if we need to
45
+ path = path.gsub(/\/github.com/, "\/raw.github.com")
46
+ options[:gitbase] = path
47
+ copy_from_repo 'index.yml', '.index', options
48
+ else
49
+ copy_file path + "/index.yml", ".index", options
50
+ end
51
+
52
+ config = YAML.load_file(".index")
53
+
54
+ meta = config["meta"]
55
+ if meta && meta["baseuri"] && meta["author"]
56
+ meta["expires"] = Time.now + (3*24*60*60) # cache for 3 days
57
+ File.open(".index", 'w') { |file| YAML::dump(config, file)}
58
+ copy_file ".index", "~/.fusegen/#{meta["author"].gsub(/\s+/, "").downcase}/index", options
59
+ repos = load_file "~/.fusegen/repos"
60
+ repos[meta["author"]] = { "meta" => meta["author"].gsub(/\s+/, "").downcase }
61
+ File.open(File.expand_path('~') + "/.fusegen/repos", 'w') { |file| YAML::dump(repos, file) }
62
+ puts "Added repository '#{meta["author"]}'"
63
+ else
64
+ puts "Unable to add '#{path}'. Repository is invalid or missing an index."
65
+ end
66
+
67
+ remove_file ".index", options
68
+
69
+ rescue Exception => e
70
+ puts e.message
71
+ puts e.backtrace
72
+ end
73
+ end
74
+
75
+
76
+ def do_repo_rm(key, options={})
77
+ begin
78
+ options[:verbose] = false
79
+ repos = load_file "~/.fusegen/repos"
80
+ repos.tap { |hash| hash.delete(key) }
81
+ File.open(File.expand_path('~') + "/.fusegen/repos", 'w') { |file| YAML::dump(repos, file) }
82
+ remove_dir File.expand_path('~') + "/.fusegen/#{key}", options
83
+
84
+ rescue Exception => e
85
+ if options[:debug]
86
+ puts e.message
87
+ puts e.backtrace
88
+ end
89
+ end
90
+ end
91
+
92
+
93
+ def do_repo_list(options={})
94
+ begin
95
+ repos = load_file "~/.fusegen/repos"
96
+
97
+ # if the repo is empty, write a default repo
98
+
99
+ if repos.size > 0
100
+ printf "%-12s %-20s\n", "Repository", "Location"
101
+ else
102
+ puts "No repositories have been configured yet. Try and add a repository e.g."
103
+ puts ""
104
+ puts ">fusegen repo add <repository>"
105
+ puts ""
106
+ puts "EXAMPLE:"
107
+ puts ">fusegen repo add https://raw.github.com/dstanley/fusegen-templates/master/"
108
+ end
109
+
110
+ repos.each do |key, value|
111
+ index = load_file "~/.fusegen/#{key}/index"
112
+ printf "[%-10s] %-20s \n", key, index["meta"]["baseuri"]
113
+ end
114
+
115
+ rescue Exception => e
116
+ puts e.message
117
+ puts e.backtrace
118
+ end
119
+ end
120
+
121
+
122
+ def do_repo_find_template(name)
123
+
124
+ end
125
+
126
+ end
127
+ end
@@ -0,0 +1,164 @@
1
+ require 'rubygems'
2
+ require 'thor'
3
+
4
+
5
+
6
+ class Generator < Thor
7
+
8
+ module Util
9
+
10
+ def initialize
11
+ super
12
+ @versions = {
13
+ "60"=> { "camel"=>"2.10.0.redhat-", "activemq"=>"5.8.0.redhat-",
14
+ "cxf"=>"2.6.0.redhat-", "spring"=>"3.1.3.RELEASE",
15
+ "karaf"=>"2.3.0.redhat-" },
16
+
17
+ "61"=> { "camel"=>"2.12.0.redhat-", "activemq"=>"5.9.0.redhat-",
18
+ "cxf"=>"2.7.0.redhat-", "spring"=>"3.2.3.RELEASE",
19
+ "karaf"=>"2.3.0.redhat-" }
20
+ }
21
+ end
22
+
23
+
24
+ def copy_from_repo(source, destination, options = {})
25
+
26
+ base = options[:gitbase] unless options[:gitbase].nil?
27
+ prefix = ""
28
+
29
+ # true when creating a new project
30
+ if options[:category] != "none" && options[:name]
31
+ base = base + options[:category] + '/' + options[:name] + '/'
32
+ prefix = options[:name] + '/'
33
+ end
34
+
35
+ begin
36
+ #remove_file destination
37
+ if base =~ /http/
38
+ get base + source, prefix + destination, options
39
+ else
40
+ copy_file base + source, prefix + destination, options
41
+ end
42
+ rescue Exception => e
43
+ say_error "Unable to load " + base + source
44
+ if options[:debug]
45
+ puts e.message
46
+ puts e.backtrace
47
+ end
48
+ end
49
+ end
50
+
51
+ def load_file(file, options={})
52
+ begin
53
+ cfg = {}
54
+ if file =~ /~/
55
+ file[0] = ''
56
+ file = File.expand_path('~') + file
57
+ end
58
+
59
+ if options[:name]
60
+ file = options[:name] + '/' + file
61
+ end
62
+ cfg = YAML.load_file(file)
63
+ rescue Exception => e
64
+ end
65
+ cfg
66
+ end
67
+
68
+ def get_substitution_value(keyword, options={})
69
+ case keyword
70
+ when "@project_version"
71
+ options[:projectversion]
72
+ when "@package"
73
+ options[:groupid]
74
+ when "@package_reverse"
75
+ options[:groupid].split(".").reverse.join(".")
76
+ when "@group_id"
77
+ options[:groupid]
78
+ when "@artifact_id"
79
+ options[:artifactid]
80
+ when "@packaging"
81
+ options[:packaging]
82
+ when "@project_version"
83
+ options[:projectversion]
84
+ when "@name"
85
+ options[:name]
86
+ when "@camel_version"
87
+ get_version(options[:fuseversion],"camel")
88
+ when "@activemq_version"
89
+ get_version(options[:fuseversion],"activemq")
90
+ when "@cxf_version"
91
+ get_version(options[:fuseversion],"cxf")
92
+ when "@smx_version"
93
+ get_version(options[:fuseversion],"smx")
94
+ when "@karaf_version"
95
+ get_version(options[:fuseversion],"karaf")
96
+ when "@spring_version"
97
+ get_version(options[:fuseversion],"spring",false)
98
+ when "@fabric_host"
99
+ "@" + options[:fabrichost]
100
+ else
101
+ keyword
102
+ end
103
+ end
104
+
105
+ def get_quickstarts
106
+ repos = load_file "~/.fusegen/repos"
107
+
108
+ quickstarts = {}
109
+ repos.each do |key, value|
110
+
111
+ # load the index
112
+ index = load_file "~/.fusegen/#{value["meta"]}/index"
113
+
114
+ meta = index["meta"]
115
+
116
+ # refresh index if its expired
117
+ if meta && meta["expires"] < Time.now
118
+ options[:gitbase] = meta["baseuri"]
119
+ do_repo_add options, meta["baseuri"]
120
+ index = load_file "~/.fusegen/#{path}/index"
121
+ end
122
+
123
+ index["quickstarts"].each do |category, meta|
124
+ meta.each do |template|
125
+ template["repo"] = value["meta"]
126
+ template["baseuri"] = index["meta"]["baseuri"]
127
+ template["category"] = category
128
+
129
+ if quickstarts[category].nil? then quickstarts[category] = []; end
130
+ quickstarts[category] << template
131
+ end
132
+ end
133
+ end
134
+ quickstarts
135
+ end
136
+
137
+ def get_version(project_version, component, composite=true)
138
+ if composite
139
+ @versions[project_version[0..1]][component] + project_version
140
+ else
141
+ @versions[project_version[0..1]][component]
142
+ end
143
+ end
144
+
145
+ def say_task(name)
146
+ say "\033[1m\033[32m" + "task".rjust(10) + "\033[0m" + " #{name} .."
147
+ end
148
+
149
+ def say_info(name)
150
+ say "\033[1m\033[36m" + "info".rjust(10) + "\033[0m" + " #{name}"
151
+ end
152
+
153
+ def say_warn(name)
154
+ say "\033[1m\033[36m" + "warn".rjust(10) + "\033[0m" + " #{name}"
155
+ end
156
+
157
+ def say_error(name)
158
+ say "\033[1m\033[31m" + "error".rjust(10) + "\033[0m" + " #{name}"
159
+ end
160
+
161
+
162
+
163
+ end
164
+ end
@@ -1,3 +1,3 @@
1
1
  module Fusegen
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fusegen
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Dave Stanley
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2014-02-16 00:00:00 Z
18
+ date: 2014-02-24 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rake
@@ -111,7 +111,12 @@ files:
111
111
  - fusegen.gemspec
112
112
  - fusegen.rdoc
113
113
  - lib/fusegen.rb
114
+ - lib/fusegen/add.rb
114
115
  - lib/fusegen/generator.rb
116
+ - lib/fusegen/new.rb
117
+ - lib/fusegen/quickstart.rb
118
+ - lib/fusegen/repo.rb
119
+ - lib/fusegen/util.rb
115
120
  - lib/fusegen/version.rb
116
121
  - test/default_test.rb
117
122
  - test/test_helper.rb