Class: VMC::Cli::Framework
Direct Known Subclasses
Constant Summary collapse
- DEFAULT_FRAMEWORK =
"http://b20nine.com/unknown"
- DEFAULT_MEM =
'256M'
- FRAMEWORKS =
{ 'Rails' => ['rails3', { :mem => '256M', :description => 'Rails Application', :console=>true}], 'Spring' => ['spring', { :mem => '512M', :description => 'Java SpringSource Spring Application'}], 'Grails' => ['grails', { :mem => '512M', :description => 'Java SpringSource Grails Application'}], 'Lift' => ['lift', { :mem => '512M', :description => 'Scala Lift Application'}], 'JavaWeb' => ['java_web',{ :mem => '512M', :description => 'Java Web Application'}], 'Standalone' => ['standalone', { :mem => '64M', :description => 'Standalone Application'}], 'Sinatra' => ['sinatra', { :mem => '128M', :description => 'Sinatra Application'}], 'Node' => ['node', { :mem => '64M', :description => 'Node.js Application'}], 'PHP' => ['php', { :mem => '128M', :description => 'PHP Application'}], 'Erlang/OTP Rebar' => ['otp_rebar', { :mem => '64M', :description => 'Erlang/OTP Rebar Application'}], 'WSGI' => ['wsgi', { :mem => '64M', :description => 'Python WSGI Application'}], 'Django' => ['django', { :mem => '128M', :description => 'Python Django Application'}], 'dotNet' => ['dotNet', { :mem => '128M', :description => '.Net Web Application'}], 'Rack' => ['rack', { :mem => '128M', :description => 'Rack Application'}], 'Play' => ['play', { :mem => '256M', :description => 'Play Framework Application'}], 'JavaWeb_tomcat' => ['java_web', { :mem => '512M', :description => 'Java Web Application on Toncat'}], 'JavaWeb_tongweb' => ['java_web_tongweb', { :mem => '512M', :description => 'Java Web Application on Tongweb'}] }
- JAVAWEB_APPSERVERS =
{ 'JavaWeb_tomcat' => ['java_web',{ :mem => '512M', :description => 'Java Web Application on tomcat'}], 'JavaWeb_tongweb' => ['java_web_tongweb', { :mem => '512M', :description => 'Java Web Application on tongweb'}] }
Instance Attribute Summary collapse
-
#console ⇒ Object
readonly
Returns the value of attribute console.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#exec ⇒ Object
Returns the value of attribute exec.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
- .create(name, opts) ⇒ Object
- .detect(path, available_frameworks) ⇒ Object
- .detect_framework_from_war(war_file = nil) ⇒ Object
- .detect_framework_from_zip(zip_file, available_frameworks) ⇒ Object
- .detect_framework_from_zip_contents(contents, available_frameworks) ⇒ Object
- .javaweb_appservers ⇒ Object
- .known_frameworks(available_frameworks) ⇒ Object
- .lookup(name) ⇒ Object
- .lookup_by_framework(name) ⇒ Object
Instance Method Summary collapse
- #default_runtime(path) ⇒ Object
-
#initialize(framework = nil, opts = {}) ⇒ Framework
constructor
A new instance of Framework.
- #memory(runtime = nil) ⇒ Object (also: #mem)
- #prompt_for_runtime? ⇒ Boolean
- #require_start_command? ⇒ Boolean
- #require_url? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(framework = nil, opts = {}) ⇒ Framework
189 190 191 192 193 194 195 |
# File 'lib/cli/frameworks.rb', line 189 def initialize(framework=nil, opts={}) @name = framework || DEFAULT_FRAMEWORK @memory = opts[:mem] || DEFAULT_MEM @description = opts[:description] || 'Unknown Application Type' @exec = opts[:exec] @console = opts[:console] || false end |
Instance Attribute Details
#console ⇒ Object (readonly)
Returns the value of attribute console.
186 187 188 |
# File 'lib/cli/frameworks.rb', line 186 def console @console end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
186 187 188 |
# File 'lib/cli/frameworks.rb', line 186 def description @description end |
#exec ⇒ Object
Returns the value of attribute exec.
187 188 189 |
# File 'lib/cli/frameworks.rb', line 187 def exec @exec end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
186 187 188 |
# File 'lib/cli/frameworks.rb', line 186 def name @name end |
Class Method Details
.create(name, opts) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/cli/frameworks.rb', line 57 def create(name,opts) if name == "standalone" return StandaloneFramework.new(name, opts) else return Framework.new(name,opts) end end |
.detect(path, available_frameworks) ⇒ Object
65 66 67 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 104 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 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/cli/frameworks.rb', line 65 def detect(path, available_frameworks) if !File.directory? path if path.end_with?('.war') return detect_framework_from_war path elsif path.end_with?('.zip') return detect_framework_from_zip path, available_frameworks elsif available_frameworks.include?(["standalone"]) return Framework.lookup('Standalone') else return nil end end Dir.chdir(path) do # Rails if File.exist?('config/environment.rb') return Framework.lookup('Rails') # Rack elsif File.exist?('config.ru') && available_frameworks.include?(["rack"]) return Framework.lookup('Rack') # Java Web Apps elsif Dir.glob('*.war').first return detect_framework_from_war(Dir.glob('*.war').first) elsif File.exist?('WEB-INF/web.xml') return detect_framework_from_war # Simple Ruby Apps elsif !Dir.glob('*.rb').empty? matched_file = nil Dir.glob('*.rb').each do |fname| next if matched_file File.open(fname, 'r') do |f| str = f.read # This might want to be limited matched_file = fname if (str && str.match(/^\s*require[\s\(]*['"]sinatra['"]/)) end end if matched_file # Sinatra apps f = Framework.lookup('Sinatra') f.exec = "ruby #{matched_file}" return f end # PHP elsif !Dir.glob('*.php').empty? return Framework.lookup('PHP') # Erlang/OTP using Rebar elsif !Dir.glob('releases/*/*.rel').empty? && !Dir.glob('releases/*/*.boot').empty? return Framework.lookup('Erlang/OTP Rebar') # Python Django # XXX: not all django projects keep settings.py in top-level directory elsif File.exist?('manage.py') && File.exist?('settings.py') return Framework.lookup('Django') # Python elsif !Dir.glob('wsgi.py').empty? return Framework.lookup('WSGI') # .Net elsif !Dir.glob('web.config').empty? return Framework.lookup('dotNet') # Node.js elsif !Dir.glob('*.js').empty? if File.exist?('server.js') || File.exist?('app.js') || File.exist?('index.js') || File.exist?('main.js') return Framework.lookup('Node') end # Play or Standalone Apps elsif Dir.glob('*.zip').first zip_file = Dir.glob('*.zip').first return detect_framework_from_zip zip_file, available_frameworks end # Default to Standalone if no other match was made return Framework.lookup('Standalone') if available_frameworks.include?(["standalone"]) end end |
.detect_framework_from_war(war_file = nil) ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/cli/frameworks.rb', line 148 def detect_framework_from_war(war_file=nil) if war_file contents = ZipUtil.entry_lines(war_file) else #assume we are working with current dir contents = Dir['**/*'].join("\n") end # Spring/Lift Variations if contents =~ /WEB-INF\/lib\/grails-web.*\.jar/ return Framework.lookup('Grails') elsif contents =~ /WEB-INF\/lib\/lift-webkit.*\.jar/ return Framework.lookup('Lift') elsif contents =~ /WEB-INF\/classes\/org\/springframework/ return Framework.lookup('Spring') elsif contents =~ /WEB-INF\/lib\/spring-core.*\.jar/ return Framework.lookup('Spring') elsif contents =~ /WEB-INF\/lib\/org\.springframework\.core.*\.jar/ return Framework.lookup('Spring') else return Framework.lookup('JavaWeb') end end |
.detect_framework_from_zip(zip_file, available_frameworks) ⇒ Object
172 173 174 175 |
# File 'lib/cli/frameworks.rb', line 172 def detect_framework_from_zip(zip_file, available_frameworks) contents = ZipUtil.entry_lines(zip_file) detect_framework_from_zip_contents(contents, available_frameworks) end |
.detect_framework_from_zip_contents(contents, available_frameworks) ⇒ Object
177 178 179 180 181 182 183 |
# File 'lib/cli/frameworks.rb', line 177 def detect_framework_from_zip_contents(contents, available_frameworks) if available_frameworks.include?(["play"]) && contents =~ /lib\/play\..*\.jar/ return Framework.lookup('Play') elsif available_frameworks.include?(["standalone"]) return Framework.lookup('Standalone') end end |
.javaweb_appservers ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/cli/frameworks.rb', line 32 def javaweb_appservers frameworks = [] JAVAWEB_APPSERVERS.each do |key,fw| frameworks << key end frameworks end |
.known_frameworks(available_frameworks) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/cli/frameworks.rb', line 39 def known_frameworks(available_frameworks) frameworks = [] FRAMEWORKS.each do |key,fw| frameworks << key if available_frameworks.include? [fw[0]] end frameworks end |
.lookup(name) ⇒ Object
47 48 49 |
# File 'lib/cli/frameworks.rb', line 47 def lookup(name) return create(*FRAMEWORKS[name]) end |
.lookup_by_framework(name) ⇒ Object
51 52 53 54 55 |
# File 'lib/cli/frameworks.rb', line 51 def lookup_by_framework(name) FRAMEWORKS.each do |key,fw| return create(fw[0],fw[1]) if fw[0] == name end end |
Instance Method Details
#default_runtime(path) ⇒ Object
213 214 215 |
# File 'lib/cli/frameworks.rb', line 213 def default_runtime(path) nil end |
#memory(runtime = nil) ⇒ Object Also known as: mem
217 218 219 |
# File 'lib/cli/frameworks.rb', line 217 def memory(runtime=nil) @memory end |
#prompt_for_runtime? ⇒ Boolean
209 210 211 |
# File 'lib/cli/frameworks.rb', line 209 def prompt_for_runtime? false end |
#require_start_command? ⇒ Boolean
205 206 207 |
# File 'lib/cli/frameworks.rb', line 205 def require_start_command? false end |
#require_url? ⇒ Boolean
201 202 203 |
# File 'lib/cli/frameworks.rb', line 201 def require_url? true end |
#to_s ⇒ Object
197 198 199 |
# File 'lib/cli/frameworks.rb', line 197 def to_s description end |