hayato1980-tomcatmanager 0.1.0
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/.document +5 -0
- data/.gitignore +5 -0
- data/LICENSE +20 -0
- data/README.rdoc +18 -0
- data/Rakefile +48 -0
- data/VERSION +1 -0
- data/bin/tomcatmanager +36 -0
- data/lib/tomcatmanager.rb +86 -0
- data/spec/spec_helper.rb +9 -0
- data/spec/tomcatmanager_spec.rb +83 -0
- data/tomcatmanager.gemspec +57 -0
- metadata +75 -0
data/.document
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Hayato
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
= tomcatmanager
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but
|
13
|
+
bump version in a commit by itself I can ignore when I pull)
|
14
|
+
* Send me a pull request. Bonus points for topic branches.
|
15
|
+
|
16
|
+
== Copyright
|
17
|
+
|
18
|
+
Copyright (c) 2009 Hayato. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "tomcatmanager"
|
8
|
+
gem.summary = %Q{TODO: one-line summary of your gem}
|
9
|
+
gem.description = %Q{TODO: longer description of your gem}
|
10
|
+
gem.email = "haya10.ito+github@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/hayato1980/tomcatmanager"
|
12
|
+
gem.authors = ["Hayato"]
|
13
|
+
gem.add_development_dependency "rspec"
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
rescue LoadError
|
17
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'spec/rake/spectask'
|
21
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
22
|
+
spec.libs << 'lib' << 'spec'
|
23
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
24
|
+
end
|
25
|
+
|
26
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
27
|
+
spec.libs << 'lib' << 'spec'
|
28
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
29
|
+
spec.rcov = true
|
30
|
+
end
|
31
|
+
|
32
|
+
task :spec => :check_dependencies
|
33
|
+
|
34
|
+
task :default => :spec
|
35
|
+
|
36
|
+
require 'rake/rdoctask'
|
37
|
+
Rake::RDocTask.new do |rdoc|
|
38
|
+
if File.exist?('VERSION')
|
39
|
+
version = File.read('VERSION')
|
40
|
+
else
|
41
|
+
version = ""
|
42
|
+
end
|
43
|
+
|
44
|
+
rdoc.rdoc_dir = 'rdoc'
|
45
|
+
rdoc.title = "tomcatmanager #{version}"
|
46
|
+
rdoc.rdoc_files.include('README*')
|
47
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
48
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/bin/tomcatmanager
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require 'lib/tomcatmanager'
|
5
|
+
option = { }
|
6
|
+
|
7
|
+
opt = OptionParser.new do |opt|
|
8
|
+
opt.on('-l', '--list') {|v| option[:command] = :list }
|
9
|
+
opt.on('-d VAL', '--deploy=VAL') do |v|
|
10
|
+
option[:command] = :deploy
|
11
|
+
option[:deploy] = v
|
12
|
+
end
|
13
|
+
opt.on('-e VAL', '--undeploy=VAL') do |v|
|
14
|
+
option[:command] = :undeploy
|
15
|
+
option[:undeploy] = v
|
16
|
+
end
|
17
|
+
opt.on('--user VAL') {|v| option[:user] = v }
|
18
|
+
opt.on('--password VAL') {|v| option[:password] = v }
|
19
|
+
end
|
20
|
+
|
21
|
+
opt.parse!(ARGV)
|
22
|
+
|
23
|
+
tm = TomcatManager.new do|tm|
|
24
|
+
tm.manager= option[:user]
|
25
|
+
tm.password = option[:password]
|
26
|
+
end
|
27
|
+
|
28
|
+
case option[:command]
|
29
|
+
when :list
|
30
|
+
tm.list.each {|app| puts app[:path] }
|
31
|
+
when :deploy
|
32
|
+
tm.deploy option[:deploy]
|
33
|
+
when :undeploy
|
34
|
+
tm.undeploy option[:undeploy]
|
35
|
+
end
|
36
|
+
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'net/http'
|
3
|
+
Net::HTTP.version_1_2
|
4
|
+
|
5
|
+
|
6
|
+
class TomcatManager
|
7
|
+
|
8
|
+
class TomcatManager::Unauthorized < Exception; end
|
9
|
+
class TomcatManager::WarNotFound < Exception
|
10
|
+
def initlalized(filename)
|
11
|
+
super("war file not found : #{filename}")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
attr_accessor :manager
|
16
|
+
attr_accessor :password
|
17
|
+
attr_accessor :host
|
18
|
+
attr_accessor :port
|
19
|
+
|
20
|
+
def initialize
|
21
|
+
@host = "127.0.0.1"
|
22
|
+
@port = "8080"
|
23
|
+
yield self if block_given?
|
24
|
+
end
|
25
|
+
|
26
|
+
def list
|
27
|
+
result = []
|
28
|
+
request('/manager/list').body.each_line do |line|
|
29
|
+
next if line =~ /^OK/
|
30
|
+
e = line.split(/:/)
|
31
|
+
result << {
|
32
|
+
:path => e[0],
|
33
|
+
:status => e[1],
|
34
|
+
:session => e[2],
|
35
|
+
:name => e[3],
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
result
|
40
|
+
end
|
41
|
+
|
42
|
+
def undeploy path
|
43
|
+
response = request("/manager/undeploy?path=/#{path}")
|
44
|
+
puts response.body
|
45
|
+
end
|
46
|
+
|
47
|
+
def deploy filename, path=nil
|
48
|
+
raise WarNotFound.new(filename) unless File.exists?(filename)
|
49
|
+
|
50
|
+
def default_pathname filename
|
51
|
+
result =File.basename(filename).gsub( /\.war/i , "")
|
52
|
+
puts result
|
53
|
+
result
|
54
|
+
end
|
55
|
+
path = default_pathname(filename) if path.nil?
|
56
|
+
|
57
|
+
response = request("/manager/deploy?path=/#{path}",:put) do |req|
|
58
|
+
File.open(filename){ |f| req.body = f.read }
|
59
|
+
end
|
60
|
+
|
61
|
+
puts response.body
|
62
|
+
end
|
63
|
+
|
64
|
+
def request(path,method=:get)
|
65
|
+
Net::HTTP.start(@host,@port) do |http|
|
66
|
+
case method
|
67
|
+
when :get
|
68
|
+
req = Net::HTTP::Get.new(path)
|
69
|
+
when :put
|
70
|
+
req = Net::HTTP::Put.new(path)
|
71
|
+
else
|
72
|
+
raise ArgumentError.new("invalid method #{method}")
|
73
|
+
end
|
74
|
+
|
75
|
+
req.basic_auth @manager, @password
|
76
|
+
|
77
|
+
yield req if block_given?
|
78
|
+
|
79
|
+
response = http.request(req)
|
80
|
+
raise TomcatManager::Unauthorized if response.code == "401"
|
81
|
+
|
82
|
+
return response
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
3
|
+
require 'fakeweb'
|
4
|
+
|
5
|
+
describe "Tomcatmanager" do
|
6
|
+
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
@account = "manager"
|
10
|
+
@incorrect_account = "incorrect"
|
11
|
+
@password = "password"
|
12
|
+
@host = "127.0.0.1"
|
13
|
+
@port = "8080"
|
14
|
+
|
15
|
+
FakeWeb.register_uri(:get, "http://#{@incorrect_account}:#{@password}@#{@host}:#{@port}/manager/list", :body => "Unauthorized", :status => ["401", "Unauthorized"])
|
16
|
+
|
17
|
+
FakeWeb.register_uri(:get, "http://#{@account}:#{@password}@#{@host}:#{@port}/manager/list",
|
18
|
+
:body => <<END_OF_RESPONSE
|
19
|
+
OK - バーチャルホスト localhost のアプリケーション一覧です
|
20
|
+
/:running:0:ROOT
|
21
|
+
/manager:running:3:manager
|
22
|
+
/hudson:running:0:hudson
|
23
|
+
/apache-solr-nightly:running:0:apache-solr-nightly
|
24
|
+
/docs:running:0:docs
|
25
|
+
/examples:running:0:examples
|
26
|
+
/host-manager:running:0:host-manager
|
27
|
+
/solr-search-example:running:0:solr-search-example
|
28
|
+
END_OF_RESPONSE
|
29
|
+
)
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
after(:each) do
|
34
|
+
FakeWeb.clean_registry
|
35
|
+
end
|
36
|
+
|
37
|
+
it "has account info" do
|
38
|
+
tm = TomcatManager.new do |tm|
|
39
|
+
tm.manager="manager"
|
40
|
+
tm.password="password"
|
41
|
+
end
|
42
|
+
tm.manager.should == "manager"
|
43
|
+
tm.password.should == "password"
|
44
|
+
end
|
45
|
+
|
46
|
+
it "has list info after called list method accessed by correct password" do
|
47
|
+
|
48
|
+
tomcat = TomcatManager.new do |tm|
|
49
|
+
tm.manager=@account
|
50
|
+
tm.password=@password
|
51
|
+
end
|
52
|
+
|
53
|
+
list = tomcat.list
|
54
|
+
|
55
|
+
list.first[:path].should == "/"
|
56
|
+
list.size.should == 8
|
57
|
+
end
|
58
|
+
|
59
|
+
it "throw unauthorized exception accessed by incorrect password" do
|
60
|
+
|
61
|
+
tomcat = TomcatManager.new do |tm|
|
62
|
+
tm.manager=@incorrect_account
|
63
|
+
tm.password=@password
|
64
|
+
end
|
65
|
+
|
66
|
+
lambda{tomcat.list}.should raise_error(TomcatManager::Unauthorized)
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
it "throw FileNotFound at deploy method with not exist war" do
|
71
|
+
tomcat = TomcatManager.new do |tm|
|
72
|
+
tm.manager=@account
|
73
|
+
tm.password=@password
|
74
|
+
end
|
75
|
+
|
76
|
+
lambda{ tomcat.deploy "/tmp/aaaaaaaa.war","testpath" }.should raise_error(TomcatManager::WarNotFound)
|
77
|
+
end
|
78
|
+
|
79
|
+
it "throw ArgumentError by request method without :get or :put" do
|
80
|
+
lambda{ TomcatManager.new.request("/test",:invalid_method) }.should raise_error(ArgumentError)
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{tomcatmanager}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Hayato"]
|
12
|
+
s.date = %q{2009-09-23}
|
13
|
+
s.default_executable = %q{tomcatmanager}
|
14
|
+
s.description = %q{TODO: longer description of your gem}
|
15
|
+
s.email = %q{haya10.ito+github@gmail.com}
|
16
|
+
s.executables = ["tomcatmanager"]
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE",
|
19
|
+
"README.rdoc"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
".document",
|
23
|
+
".gitignore",
|
24
|
+
"LICENSE",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"bin/tomcatmanager",
|
29
|
+
"lib/tomcatmanager.rb",
|
30
|
+
"spec/spec_helper.rb",
|
31
|
+
"spec/tomcatmanager_spec.rb",
|
32
|
+
"tomcatmanager.gemspec"
|
33
|
+
]
|
34
|
+
s.has_rdoc = true
|
35
|
+
s.homepage = %q{http://github.com/hayato1980/tomcatmanager}
|
36
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
37
|
+
s.require_paths = ["lib"]
|
38
|
+
s.rubygems_version = %q{1.3.1}
|
39
|
+
s.summary = %q{TODO: one-line summary of your gem}
|
40
|
+
s.test_files = [
|
41
|
+
"spec/spec_helper.rb",
|
42
|
+
"spec/tomcatmanager_spec.rb"
|
43
|
+
]
|
44
|
+
|
45
|
+
if s.respond_to? :specification_version then
|
46
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
47
|
+
s.specification_version = 2
|
48
|
+
|
49
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
50
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
51
|
+
else
|
52
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
53
|
+
end
|
54
|
+
else
|
55
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
56
|
+
end
|
57
|
+
end
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hayato1980-tomcatmanager
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Hayato
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-09-23 00:00:00 -07:00
|
13
|
+
default_executable: tomcatmanager
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rspec
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
description: "TODO: longer description of your gem"
|
26
|
+
email: haya10.ito+github@gmail.com
|
27
|
+
executables:
|
28
|
+
- tomcatmanager
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- LICENSE
|
33
|
+
- README.rdoc
|
34
|
+
files:
|
35
|
+
- .document
|
36
|
+
- .gitignore
|
37
|
+
- LICENSE
|
38
|
+
- README.rdoc
|
39
|
+
- Rakefile
|
40
|
+
- VERSION
|
41
|
+
- bin/tomcatmanager
|
42
|
+
- lib/tomcatmanager.rb
|
43
|
+
- spec/spec_helper.rb
|
44
|
+
- spec/tomcatmanager_spec.rb
|
45
|
+
- tomcatmanager.gemspec
|
46
|
+
has_rdoc: true
|
47
|
+
homepage: http://github.com/hayato1980/tomcatmanager
|
48
|
+
licenses:
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options:
|
51
|
+
- --charset=UTF-8
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: "0"
|
59
|
+
version:
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: "0"
|
65
|
+
version:
|
66
|
+
requirements: []
|
67
|
+
|
68
|
+
rubyforge_project:
|
69
|
+
rubygems_version: 1.3.5
|
70
|
+
signing_key:
|
71
|
+
specification_version: 2
|
72
|
+
summary: "TODO: one-line summary of your gem"
|
73
|
+
test_files:
|
74
|
+
- spec/spec_helper.rb
|
75
|
+
- spec/tomcatmanager_spec.rb
|