Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 935ebdc

Browse files
committed
add java_local_file to allow distribution methods not supported by
remote_file (ftp, authenticated http, maven, etc)
1 parent 094d0bd commit 935ebdc

File tree

3 files changed

+125
-2
lines changed

3 files changed

+125
-2
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#
2+
# Cookbook Name:: application_java
3+
# Library:: provider_java_local_file
4+
#
5+
# Copyright 2012, ZephirWorks
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
19+
20+
require 'chef/provider/file'
21+
22+
class Chef
23+
class Provider
24+
class File
25+
class JavaLocalFile < Chef::Provider::File
26+
27+
def load_current_resource
28+
@new_resource.path @new_resource.release_path
29+
super
30+
end
31+
32+
def action_deploy
33+
action_create
34+
end
35+
36+
def action_force_deploy
37+
action_create
38+
end
39+
40+
def set_content
41+
unless compare_content
42+
backup @new_resource.path if ::File.exists?(@new_resource.path)
43+
::FileUtils.cp_r(@new_resource.content, @new_resource.path)
44+
Chef::Log.info("#{@new_resource.content} copied to #{@new_resource.path}")
45+
@new_resource.updated_by_last_action(true)
46+
end
47+
end
48+
49+
def compare_content
50+
checksum(@current_resource.path) == checksum(@new_resource.content)
51+
end
52+
end
53+
end
54+
end
55+
end
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#
2+
# Cookbook Name:: application_java
3+
# Library:: resource_java_local_file
4+
#
5+
# Copyright 2012, ZephirWorks
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
19+
20+
require 'chef/resource/file'
21+
22+
class Chef
23+
class Resource
24+
class JavaLocalFile < Chef::Resource::File
25+
26+
alias :user :owner
27+
alias :repository :content
28+
29+
def initialize(name, run_context=nil)
30+
super
31+
@resource_name = :java_local_file
32+
@provider = Chef::Provider::File::JavaLocalFile
33+
@deploy_to = nil
34+
@allowed_actions.push(:deploy,:force_deploy)
35+
end
36+
37+
def provider
38+
Chef::Provider::File::JavaLocalFile
39+
end
40+
41+
def deploy_to(args=nil)
42+
set_or_return(
43+
:deploy_to,
44+
args,
45+
:kind_of => String
46+
)
47+
end
48+
49+
def revision(arg=nil)
50+
set_or_return(
51+
:checksum,
52+
arg,
53+
:kind_of => String
54+
)
55+
end
56+
57+
def release_path
58+
@release_path ||= @deploy_to + "/releases/#{revision}.war"
59+
end
60+
61+
def method_missing(name, *args, &block)
62+
Chef::Log.info "java_local_file missing(#{name}, #{args.inspect}), ignoring it"
63+
end
64+
65+
end
66+
end
67+
end

providers/java_webapp.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
action :before_compile do
2323

2424
# include_recipe 'java'
25-
26-
new_resource.strategy :java_remote_file
25+
unless new_resource.defined?( strategy )
26+
new_resource.strategy :java_remote_file
27+
end
2728
end
2829

2930
action :before_deploy do

0 commit comments

Comments
 (0)