Module: JrubyWarck::Manipulations
Constant Summary
Constants included
from Constants
Constants::ADDITIONAL_CLASSPATH, Constants::BOOTSTRAP_ERB, Constants::BUILD_DIR, Constants::CLASSPATH, Constants::CONTEXT_LISTENERS, Constants::HOME, Constants::INIT, Constants::MANIFEST_MF, Constants::META_INF, Constants::RACKUP_FILE, Constants::REJECT_FILES, Constants::RUNNING_FROM, Constants::SELECT_FILES, Constants::WEB_INF, Constants::WEB_XML
Instance Method Summary
collapse
Instance Method Details
#add_additional_files ⇒ Object
94
95
96
97
98
99
100
|
# File 'lib/jruby-warck/manipulations.rb', line 94
def add_additional_files
puts "++ Copying additional files to #{WEB_INF}"
FileList[SELECT_FILES].each do |file|
mkdir_p file.pathmap("#{WEB_INF}/%d") unless File.exists?(file.pathmap("#{WEB_INF}/%d"))
cp file, file.pathmap("#{WEB_INF}/%d/%f")
end
end
|
#add_bootstrap_script(archive_name) ⇒ Object
102
103
104
105
106
107
108
|
# File 'lib/jruby-warck/manipulations.rb', line 102
def add_bootstrap_script(archive_name)
puts "++ Creating bootstrapping script"
bootstrap = File.new("#{BUILD_DIR}/jar-bootstrap.rb", "w")
bootstrap.puts(ERB.new(BOOTSTRAP_ERB).result(binding))
bootstrap.close
end
|
#add_class_files ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/jruby-warck/manipulations.rb', line 64
def add_class_files
puts "++ Moving .class files to #{WEB_INF}"
puts "++ Generating .rb stubs in #{WEB_INF}"
@class_files.each do |file|
mkdir_p file.pathmap(WEB_INF + "/%d") unless File.exists? file.pathmap(WEB_INF + "/%d")
mv file, (WEB_INF + "/" + file)
stub = File.open((WEB_INF + "/" + file).sub(/\.class$/, ".rb"), "w")
stub.puts("load __FILE__.sub(/\.rb$/, '.class')")
stub.close
end
end
|
#add_deployment_descriptor(framework = :rack) ⇒ Object
31
32
33
34
35
36
37
38
39
|
# File 'lib/jruby-warck/manipulations.rb', line 31
def add_deployment_descriptor(framework = :rack)
web_xml_path = "web.xml"
generate_deployment_descriptor(web_xml_path, framework) if !File.exist?(web_xml_path)
puts "++ Adding web.xml to #{WEB_INF}"
cp web_xml_path, "#{WEB_INF}"
end
|
#add_init_file ⇒ Object
41
42
43
44
45
46
47
|
# File 'lib/jruby-warck/manipulations.rb', line 41
def add_init_file
puts "++ Generating init.rb"
init = File.new(META_INF + "/init.rb", "w")
init.puts(INIT)
init.close
end
|
#add_manifest_file ⇒ Object
15
16
17
18
19
20
|
# File 'lib/jruby-warck/manipulations.rb', line 15
def add_manifest_file
puts "++ Adding MANIFEST to #{META_INF}"
manifest = File.new(META_INF + "/MANIFEST.MF", "w")
manifest.puts(MANIFEST_MF)
manifest.close
end
|
#add_public_files ⇒ Object
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/jruby-warck/manipulations.rb', line 78
def add_public_files
puts "++ Copying public files to #{BUILD_DIR}"
(FileList["public/**/*"] - FileList[REJECT_FILES]).each do |file|
if File.directory?(file)
puts " ++ Creating #{file.pathmap("%{public,#{BUILD_DIR}}d/%f")
}"
mkdir_p file.pathmap("%{public,#{BUILD_DIR}}d/%f")
else
puts " ++ Copying #{file.pathmap("%{public,#{BUILD_DIR}}d/%f")
}"
cp file, file.pathmap("%{public,#{BUILD_DIR}}d/%f")
end
end
end
|
#add_rackup_file ⇒ Object
#add_ruby_files ⇒ Object
54
55
56
57
58
59
60
61
62
|
# File 'lib/jruby-warck/manipulations.rb', line 54
def add_ruby_files
@ruby_files = FileList["**/*.rb"]
puts "++ Copying #{@ruby_files.size} Ruby sources to #{WEB_INF}"
@ruby_files.each do |file|
mkdir_p file.pathmap(WEB_INF + "/%d") unless File.exists? file.pathmap(WEB_INF + "/%d")
cp file, (WEB_INF + "/" + file)
end
end
|
#archive_war(archive_name, force = false) ⇒ Object
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
# File 'lib/jruby-warck/manipulations.rb', line 110
def archive_war(archive_name, force = false)
puts "++ Creating war file #{archive_name}.war"
if File.exist?("#{archive_name}.war")
unless force
$stderr.puts "!! #{archive_name}.war already exists, aborting"
exit 1
end
File.delete("#{archive_name}.war")
end
Zip::File.open("#{RUNNING_FROM}/#{archive_name}.war", Zip::File::CREATE) do |zip|
Dir.chdir(BUILD_DIR)
Dir["**/"].each { |d| zip.mkdir(d, 0744) }
FileList["**/*"].exclude { |f| File.directory?(f) }.each { |f| puts " ++ Adding #{f}"; zip.add(f, f) }
zip.close
end
end
|
#compile_ruby_scripts ⇒ Object
131
132
133
134
135
136
137
138
139
140
141
142
143
|
# File 'lib/jruby-warck/manipulations.rb', line 131
def compile_ruby_scripts
@ruby_files = FileList["**/*.rb"]
`jrubyc #{@ruby_files.join(" ")}`
@class_files = FileList["**/*.class"] - FileList["tmp/**/*"]
unless @ruby_files.size.eql?(@class_files.size)
puts "** Warning: it seems that some ruby files were not compiled"
puts ".rb files: #{@ruby_files.size}"
puts ".class files: #{@class_files.size}"
end
end
|
#create_archive_dirs ⇒ Object
8
9
10
11
12
13
|
# File 'lib/jruby-warck/manipulations.rb', line 8
def create_archive_dirs
puts "++ Creating archive directories"
mkdir_p "#{BUILD_DIR}/assets" if Rake::Task.task_defined?("assets:precompile")
mkdir_p WEB_INF
mkdir_p META_INF
end
|
#generate_deployment_descriptor(path, framework = :rack) ⇒ Object
22
23
24
25
26
27
28
29
|
# File 'lib/jruby-warck/manipulations.rb', line 22
def generate_deployment_descriptor(path, framework = :rack)
puts "++ Generating web.xml"
context_listener = CONTEXT_LISTENERS[framework.to_sym]
web_xml = File.new(path, "w")
web_xml.puts(ERB.new(WEB_XML).result(binding))
web_xml.close
end
|