rakejava 1.1.4
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/README +25 -0
- data/lib/rakejava.rb +302 -0
- metadata +56 -0
data/README
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
RakeJava is a ruby gem for use with Rake. It lets you compile and jar Java files.
|
2
|
+
|
3
|
+
Simple Example:
|
4
|
+
|
5
|
+
require 'rakejava'
|
6
|
+
require 'rake/clean'
|
7
|
+
|
8
|
+
CLEAN.include 'build'
|
9
|
+
|
10
|
+
task :default => "myproj.jar"
|
11
|
+
|
12
|
+
jar "myproj.jar" => :compile do |t|
|
13
|
+
t.files << JarFiles["build", "**/*.class"]
|
14
|
+
t.manifest = {:version => '1.0.0'}
|
15
|
+
end
|
16
|
+
|
17
|
+
javac :compile => "build" do |t|
|
18
|
+
t.src << Sources["src", "**/*.java"]
|
19
|
+
t.src << Sources["test", "*.java"]
|
20
|
+
t.classpath << Dir["lib/**/*.{zip,jar}"]
|
21
|
+
t.dest = 'build'
|
22
|
+
end
|
23
|
+
|
24
|
+
directory "build"
|
25
|
+
|
data/lib/rakejava.rb
ADDED
@@ -0,0 +1,302 @@
|
|
1
|
+
# RakeJava is a set of custom rake tasks for building Java projects
|
2
|
+
#
|
3
|
+
# Author: Tom Santos
|
4
|
+
# http://github.com/tsantos/rakejava/tree/master
|
5
|
+
|
6
|
+
=begin
|
7
|
+
Copyright 2009 Tom Santos
|
8
|
+
|
9
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
10
|
+
you may not use this file except in compliance with the License.
|
11
|
+
You may obtain a copy of the License at
|
12
|
+
|
13
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
14
|
+
|
15
|
+
Unless required by applicable law or agreed to in writing, software
|
16
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
17
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
18
|
+
See the License for the specific language governing permissions and
|
19
|
+
limitations under the License.
|
20
|
+
=end
|
21
|
+
|
22
|
+
require 'rake'
|
23
|
+
require 'set'
|
24
|
+
require 'tempfile'
|
25
|
+
|
26
|
+
module RakeJavaUtil
|
27
|
+
def pushd dir
|
28
|
+
pushd_stack.unshift(Dir.pwd)
|
29
|
+
cd dir
|
30
|
+
end
|
31
|
+
|
32
|
+
def popd
|
33
|
+
cd pushd_stack.shift
|
34
|
+
end
|
35
|
+
|
36
|
+
def pushd_stack
|
37
|
+
unless defined?(@pushd_stack)
|
38
|
+
@pushd_stack = []
|
39
|
+
end
|
40
|
+
@pushd_stack
|
41
|
+
end
|
42
|
+
|
43
|
+
def path_esc str_ary
|
44
|
+
str_ary.map { |str| str.gsub('$', '\$').gsub(' ', '\ ') }
|
45
|
+
end
|
46
|
+
|
47
|
+
def path_sep str_ary
|
48
|
+
separate(str_ary, File::PATH_SEPARATOR)
|
49
|
+
end
|
50
|
+
|
51
|
+
def space_sep str_ary
|
52
|
+
separate(str_ary, ' ')
|
53
|
+
end
|
54
|
+
|
55
|
+
def separate str_ary, sep
|
56
|
+
result = ""
|
57
|
+
str_ary.each { |str| result << "#{str}#{sep}" }
|
58
|
+
result.chop!
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
class Sources < Rake::FileList
|
63
|
+
attr_accessor :root
|
64
|
+
|
65
|
+
def initialize *args
|
66
|
+
@root = args.shift
|
67
|
+
args = args.map { |arg| "#{@root}/#{arg}" }
|
68
|
+
super
|
69
|
+
end
|
70
|
+
|
71
|
+
class << self
|
72
|
+
def [] *args
|
73
|
+
new(*args)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
class JarFiles < Rake::FileList
|
79
|
+
include RakeJavaUtil
|
80
|
+
|
81
|
+
attr_accessor :root
|
82
|
+
|
83
|
+
def initialize *args
|
84
|
+
@root = args.shift
|
85
|
+
@resolving = false
|
86
|
+
super
|
87
|
+
end
|
88
|
+
|
89
|
+
def resolve
|
90
|
+
unless @resolving
|
91
|
+
@resolving = true
|
92
|
+
pushd @root
|
93
|
+
super
|
94
|
+
puts "Resolving JarFiles list"
|
95
|
+
# Hack time because the jar command is busted. Every arg after the
|
96
|
+
# first file listed after a -C needs to have paths relative to the
|
97
|
+
# command-launch rather than the -C specified dir. The first file arg
|
98
|
+
# after a -C works but subsequent ones fail.
|
99
|
+
hack = @items.shift
|
100
|
+
@items.map! { |i| "#{@root}#{File::SEPARATOR}#{i}" }
|
101
|
+
@items.unshift(hack)
|
102
|
+
popd
|
103
|
+
@resolving = false
|
104
|
+
end
|
105
|
+
self
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
module RakeJava
|
110
|
+
class JavacTask < Rake::Task
|
111
|
+
include RakeJavaUtil
|
112
|
+
|
113
|
+
attr_accessor :bootpath, :classpath, :src, :dest, :args
|
114
|
+
attr_accessor :src_ver, :dest_ver, :debug
|
115
|
+
|
116
|
+
def initialize name, app
|
117
|
+
super
|
118
|
+
@src = []
|
119
|
+
@srcpath = []
|
120
|
+
@bootpath = []
|
121
|
+
@classpath = []
|
122
|
+
end
|
123
|
+
|
124
|
+
def execute args=nil
|
125
|
+
super
|
126
|
+
files = src_files
|
127
|
+
|
128
|
+
unless files.empty?
|
129
|
+
srcpath = @src.map { |src| src.root }
|
130
|
+
|
131
|
+
@bootpath.flatten!
|
132
|
+
@classpath.flatten!
|
133
|
+
|
134
|
+
cmd = "javac"
|
135
|
+
cmd << " -bootclasspath #{path_sep(@bootpath)}" unless @bootpath.empty?
|
136
|
+
cmd << " #{@args}" if @args
|
137
|
+
cmd << " -classpath #{path_sep(@classpath)}" unless @classpath.empty?
|
138
|
+
cmd << " -g" if @debug
|
139
|
+
cmd << " -source #{@src_ver}" if @src_ver
|
140
|
+
cmd << " -target #{@dest_ver}" if @dest_ver
|
141
|
+
cmd << " -sourcepath #{path_sep(srcpath)}" if srcpath
|
142
|
+
cmd << " -d #{@dest}" if @dest
|
143
|
+
cmd << " #{space_sep(files)}"
|
144
|
+
|
145
|
+
max_cmd_len = 500
|
146
|
+
if cmd.length < max_cmd_len
|
147
|
+
puts cmd
|
148
|
+
else
|
149
|
+
puts cmd[0..max_cmd_len] + "..."
|
150
|
+
end
|
151
|
+
puts "Compiling #{files.length} file(s)"
|
152
|
+
system "#{cmd}"
|
153
|
+
puts
|
154
|
+
else
|
155
|
+
puts "No files to compile"
|
156
|
+
end
|
157
|
+
|
158
|
+
end
|
159
|
+
|
160
|
+
def src_files
|
161
|
+
files = []
|
162
|
+
|
163
|
+
@src.each do |source|
|
164
|
+
files << changed_only(source)
|
165
|
+
end
|
166
|
+
|
167
|
+
files.flatten
|
168
|
+
end
|
169
|
+
|
170
|
+
def changed_only sources
|
171
|
+
# Retuns the files that have newer .java files than .class files
|
172
|
+
changed = []
|
173
|
+
sources.each do |src_file|
|
174
|
+
mod_time = File.mtime(src_file)
|
175
|
+
base = File.basename(src_file, ".java")
|
176
|
+
parent = File.dirname(src_file)
|
177
|
+
classfiles = []
|
178
|
+
|
179
|
+
if @dest
|
180
|
+
base_path = parent[sources.root.length+1..-1]
|
181
|
+
classfiles = Dir["#{@dest}/#{base_path}/#{base}*.class"]
|
182
|
+
else
|
183
|
+
# Look next to it
|
184
|
+
classfiles = Dir["#{parent}/#{base}*.class"]
|
185
|
+
end
|
186
|
+
|
187
|
+
unless classfiles.empty?
|
188
|
+
classfiles.each do |classfile|
|
189
|
+
if File.mtime(classfile) < mod_time
|
190
|
+
changed << src_file
|
191
|
+
break
|
192
|
+
end
|
193
|
+
end
|
194
|
+
else
|
195
|
+
changed << src_file
|
196
|
+
end
|
197
|
+
end
|
198
|
+
changed
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
class JarTask < Rake::Task
|
203
|
+
include RakeJavaUtil
|
204
|
+
|
205
|
+
attr_accessor :files, :main_class, :manifest, :sign_info
|
206
|
+
|
207
|
+
def initialize name, app
|
208
|
+
super
|
209
|
+
@root = "."
|
210
|
+
@files = []
|
211
|
+
|
212
|
+
# Deal with namespaces. I have no idea if this
|
213
|
+
# is a total hack.
|
214
|
+
name =~ /.*?\:(.*)/
|
215
|
+
if $1
|
216
|
+
@real_name = $1
|
217
|
+
else
|
218
|
+
@real_name = name
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
def execute args=nil
|
223
|
+
super
|
224
|
+
|
225
|
+
flags = "cf"
|
226
|
+
jar = File.expand_path(@real_name)
|
227
|
+
|
228
|
+
if @main_class
|
229
|
+
unless @manifest
|
230
|
+
@manifest = {}
|
231
|
+
end
|
232
|
+
@manifest["Main-Class"] = @main_class
|
233
|
+
end
|
234
|
+
manifest_path = " "
|
235
|
+
if @manifest
|
236
|
+
flags << "m"
|
237
|
+
if @manifest.kind_of? Hash
|
238
|
+
manifest_path << create_manifest
|
239
|
+
elsif @manifest.kind_of? String
|
240
|
+
manifest_path << File.expand_path(@manifest)
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
cmd = "jar #{flags} #{@real_name}#{manifest_path}"
|
245
|
+
|
246
|
+
@files.each do |file_list|
|
247
|
+
cmd << " -C #{file_list.root} #{space_sep(path_esc(file_list))}"
|
248
|
+
end
|
249
|
+
|
250
|
+
max_cmd_len = 500
|
251
|
+
if cmd.length < max_cmd_len
|
252
|
+
puts cmd
|
253
|
+
else
|
254
|
+
puts cmd[0..max_cmd_len] + "..."
|
255
|
+
end
|
256
|
+
|
257
|
+
system "#{cmd}"
|
258
|
+
puts
|
259
|
+
|
260
|
+
# Now, sign the jar if we're asked to. This only supports the
|
261
|
+
# arguments that I need for my project at the moment.
|
262
|
+
if @sign_info
|
263
|
+
cmd = "jarsigner"
|
264
|
+
cmd << " -storetype #{@sign_info[:store_type]}"
|
265
|
+
cmd << " -keystore #{@sign_info[:key_store]}"
|
266
|
+
cmd << " -storepass #{@sign_info[:store_pass]}"
|
267
|
+
cmd << " #{@real_name}"
|
268
|
+
cmd << " #{@sign_info[:alias]}"
|
269
|
+
puts cmd
|
270
|
+
system "#{cmd}"
|
271
|
+
puts
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
protected
|
276
|
+
def create_manifest
|
277
|
+
manifest = [
|
278
|
+
"Manifest-Version: 1.0",
|
279
|
+
"Created-By: rakejava"
|
280
|
+
]
|
281
|
+
|
282
|
+
@manifest.each do |key, value|
|
283
|
+
manifest << "#{key}: #{value}"
|
284
|
+
end
|
285
|
+
|
286
|
+
file = Tempfile.new("manifest", "/tmp")
|
287
|
+
File.open(file.path, "w") do |f|
|
288
|
+
f.puts(manifest)
|
289
|
+
end
|
290
|
+
|
291
|
+
file.path
|
292
|
+
end
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
296
|
+
def javac *args, &block
|
297
|
+
RakeJava::JavacTask.define_task(*args, &block)
|
298
|
+
end
|
299
|
+
|
300
|
+
def jar *args, &block
|
301
|
+
RakeJava::JarTask.define_task(*args, &block)
|
302
|
+
end
|
metadata
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rakejava
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tom Santos
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-01-19 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Rake tasks for building Java stuff
|
17
|
+
email: santos.tom@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- README
|
26
|
+
- lib/rakejava.rb
|
27
|
+
has_rdoc: true
|
28
|
+
homepage: http://github.com/tsantos/rakejava
|
29
|
+
licenses: []
|
30
|
+
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: "0"
|
41
|
+
version:
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0"
|
47
|
+
version:
|
48
|
+
requirements: []
|
49
|
+
|
50
|
+
rubyforge_project:
|
51
|
+
rubygems_version: 1.3.5
|
52
|
+
signing_key:
|
53
|
+
specification_version: 3
|
54
|
+
summary: Rake tasks for building Java stuff
|
55
|
+
test_files: []
|
56
|
+
|