Skip to content

Commit

Permalink
Add Play Framework
Browse files Browse the repository at this point in the history
Change-Id: I5ef7a845d4a7fdbc7bd7137a4c69a7bfe36b0dd1
  • Loading branch information
Jennifer Hickey committed May 9, 2012
1 parent 0a459dc commit 6eacb0e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
25 changes: 23 additions & 2 deletions lib/cli/frameworks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ class Framework
'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'}]
'Rack' => ['rack', { :mem => '128M', :description => 'Rack Application'}],
'Play' => ['play', { :mem => '128M', :description => 'Play Framework Application'}]
}

class << self
Expand Down Expand Up @@ -54,6 +55,8 @@ 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
Expand Down Expand Up @@ -109,6 +112,7 @@ def detect(path, available_frameworks)
# Python
elsif !Dir.glob('wsgi.py').empty?
return Framework.lookup('WSGI')

# .Net
elsif !Dir.glob('web.config').empty?
return Framework.lookup('dotNet')
Expand All @@ -118,14 +122,18 @@ def detect(path, available_frameworks)
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

private
def detect_framework_from_war(war_file=nil)
if war_file
contents = ZipUtil.entry_lines(war_file)
Expand All @@ -149,6 +157,19 @@ def detect_framework_from_war(war_file=nil)
return Framework.lookup('JavaWeb')
end
end

def detect_framework_from_zip(zip_file, available_frameworks)
contents = ZipUtil.entry_lines(zip_file)
detect_framework_from_zip_contents(contents, available_frameworks)
end

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
end

attr_reader :name, :description, :console
Expand Down
28 changes: 28 additions & 0 deletions spec/unit/frameworks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@
framework(app).to_s.should=~ /Node.js/
end

it 'should be able to detect a Play app' do
VMC::Cli::Framework.detect_framework_from_zip_contents("lib/play.play_2.9.1-2.1-SNAPSHOT.jar",
[["play"],["standalone"]])
end

it 'should return correct list of available frameworks' do
VMC::Cli::Framework.known_frameworks([["standalone"],["rails3"]]).should == ["Rails","Standalone"]
end
Expand All @@ -108,11 +113,34 @@
framework(app).should == nil
end

it 'should detect Standalone app from single zip file' do
app = spec_asset("tests/standalone/java_app/target/zip/" +
"standalone-java-app-1.0.0.BUILD-SNAPSHOT-jar.zip")
framework(app,false,[["standalone"],["play"]]).to_s.should=~ /Standalone/
end

it 'should detect Standalone app from dir containing a single zip file' do
app = spec_asset("tests/standalone/java_app/target/zip/")
framework(app,false,[["standalone"],["play"]]).to_s.should=~ /Standalone/
end

it 'should fall back to nil if Standalone framework not supported for zip file' do
app = spec_asset("tests/standalone/java_app/target/zip/" +
"standalone-java-app-1.0.0.BUILD-SNAPSHOT-jar.zip")
framework(app).should == nil
end

it 'should fall back to Standalone app if dir does not match other frameworks' do
app = spec_asset('tests/standalone/python_app')
framework(app,false,[["standalone"]]).to_s.should=~ /Standalone/
end

it 'should detect default Java runtime with a zip of jars' do
app = spec_asset("tests/standalone/java_app/target/zip/" +
"standalone-java-app-1.0.0.BUILD-SNAPSHOT-jar.zip")
framework(app,false,[["standalone"]]).default_runtime(app).should == "java"
end

it 'should fall back to nil if Standalone framework not supported for dir' do
app = spec_asset('tests/standalone/python_app')
framework(app).should == nil
Expand Down

0 comments on commit 6eacb0e

Please sign in to comment.