rakejava 1.2.0 → 1.3.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.
Files changed (3) hide show
  1. data/README.markdown +28 -0
  2. data/lib/rakejava.rb +105 -5
  3. metadata +3 -3
data/README.markdown CHANGED
@@ -74,3 +74,31 @@ Here's an example of using sign_info with the jar task:
74
74
  :alias => 'you-know-yours'
75
75
  }
76
76
  end
77
+
78
+ -------------------------
79
+ # copy_to #
80
+
81
+ This is a function that lets you copy files to a destination directory. What makes this interesting is that by default it won't copy files unless they're newer. Here's an example:
82
+
83
+ task :copy_stuff do
84
+ copy_to "/my/dest/dir" do |c|
85
+ c.files << CopyFiles['build/java', '**/*.class'].exclude(/Test.class/)
86
+ c.files << CopyFiles['lib', '**/*.{jar,zip}'].flatten!.dest('lib')
87
+ c.files << Dir['ext/**/*.jar']
88
+ c.force # Normally, only newer files get copied
89
+ end
90
+ end
91
+
92
+ ### CopyFiles ###
93
+
94
+ A `Rake::FileList` where the first argument is the parent directory of the files you want to specify for copying. The files will end up in the destination with the same relative path to their original parent.
95
+
96
+ c.files << CopyFiles['lib', '**/*.{jar,zip}']
97
+
98
+ You can use `CopyFiles` to collect files and then dump them all into the target directory by using `flatten!()`.
99
+
100
+ c.files << CopyFiles['lib', '**/*.{jar,zip}'].flatten!
101
+
102
+ You can send all of the files specified in `CopyFiles` to a subdir of the target dir by using `dest()`.
103
+
104
+ c.files << CopyFiles['lib', '**/*.{jar,zip}'].flatten!.dest('my_lib')
data/lib/rakejava.rb CHANGED
@@ -1,10 +1,10 @@
1
1
  # RakeJava is a set of custom rake tasks for building Java projects
2
2
  #
3
3
  # Author: Tom Santos
4
- # http://github.com/tsantos/rakejava/tree/master
4
+ # http://github.com/tsantos/rakejava
5
5
 
6
6
  =begin
7
- Copyright 2009 Tom Santos
7
+ Copyright 2009, 2010 Tom Santos
8
8
 
9
9
  Licensed under the Apache License, Version 2.0 (the "License");
10
10
  you may not use this file except in compliance with the License.
@@ -91,7 +91,7 @@ class JarFiles < Rake::FileList
91
91
  @resolved = true
92
92
  pushd @root
93
93
  super
94
- puts "Resolving JarFiles list"
94
+ puts "Resolving #{self.class.name} list"
95
95
  @items.map! { |i| "#{@root}#{File::SEPARATOR}#{i}" }
96
96
  popd
97
97
  end
@@ -99,6 +99,32 @@ class JarFiles < Rake::FileList
99
99
  end
100
100
  end
101
101
 
102
+ class CopyFiles < JarFiles
103
+ def initialize *args
104
+ super
105
+ @flattened = false
106
+ @dest = nil
107
+ end
108
+
109
+ def flatten!
110
+ @flattened = true
111
+ self
112
+ end
113
+
114
+ def flattened?
115
+ @flattened
116
+ end
117
+
118
+ def dest_path
119
+ @dest
120
+ end
121
+
122
+ def dest subdir
123
+ @dest = subdir.sub(%r[/+$], '') # remove trailing slashes
124
+ self
125
+ end
126
+ end
127
+
102
128
  module RakeJava
103
129
  class JavacTask < Rake::Task
104
130
  include RakeJavaUtil
@@ -199,7 +225,6 @@ module RakeJava
199
225
 
200
226
  def initialize name, app
201
227
  super
202
- @root = "."
203
228
  @files = []
204
229
 
205
230
  # Deal with namespaces. I have no idea if this
@@ -312,6 +337,76 @@ module RakeJava
312
337
  file.path
313
338
  end
314
339
  end
340
+
341
+ # A simple class for copying files from various places to
342
+ # a single target directory. You can tell it to just copy
343
+ # files if they're newer than the target version.
344
+ #
345
+ class Copier
346
+ attr_accessor :files
347
+
348
+ def initialize dest_dir, &block
349
+ @files = []
350
+ @dest_dir = dest_dir.sub(%r[/+$], '') # remove trailing slashes
351
+ @check_date = true
352
+ block.call(self)
353
+ end
354
+
355
+ def force
356
+ @check_date = false
357
+ end
358
+
359
+ def copy
360
+ dirs = Set.new
361
+
362
+ @files.each do |copy_files|
363
+ src_files = copy_files.to_a
364
+
365
+ if copy_files.kind_of?(CopyFiles)
366
+ partials = src_files.map { |f| f.sub(%r[^#{copy_files.root}/], '') }
367
+ else
368
+ partials = src_files
369
+ end
370
+
371
+ partials.each do |part|
372
+ if copy_files.kind_of?(CopyFiles)
373
+ src_path = "#{copy_files.root}/#{part}"
374
+ dest_dir = @dest_dir + (copy_files.dest_path ? "/#{copy_files.dest_path}" : '')
375
+ if copy_files.flattened?
376
+ dest_path = "#{dest_dir}/#{File.basename(src_path)}"
377
+ else
378
+ dest_path = "#{dest_dir}/#{part}"
379
+ end
380
+ else
381
+ src_path = part
382
+ dest_path = "#{@dest_dir}/#{part}"
383
+ end
384
+
385
+ if File.directory?(src_path)
386
+ next
387
+ end
388
+
389
+ if @check_date && File.exist?(dest_path)
390
+ src_time = File.mtime(src_path)
391
+ dest_time = File.mtime(dest_path)
392
+ if src_time <= dest_time
393
+ next
394
+ end
395
+ end
396
+
397
+ # Ensure the path
398
+ parent = File.dirname(dest_path)
399
+ unless dirs.include?(parent)
400
+ dirs << parent
401
+ mkdir_p parent
402
+ end
403
+
404
+ # Copy the file
405
+ cp src_path, dest_path
406
+ end
407
+ end
408
+ end
409
+ end
315
410
  end
316
411
 
317
412
  def javac *args, &block
@@ -322,4 +417,9 @@ def jar *args, &block
322
417
  RakeJava::JarTask.define_task(*args, &block)
323
418
  end
324
419
 
325
- # vi:tabstop=3:expandtab:filetype=ruby
420
+ def copy_to dest_dir, &block
421
+ copier = RakeJava::Copier.new(dest_dir, &block)
422
+ copier.copy()
423
+ end
424
+
425
+ # vim: filetype=ruby tabstop=3 expandtab
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 1
7
- - 2
7
+ - 3
8
8
  - 0
9
- version: 1.2.0
9
+ version: 1.3.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Tom Santos
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-06-28 00:00:00 -07:00
17
+ date: 2010-06-29 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency