rjack-tarpit 2.0.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/History.rdoc +71 -0
  2. data/Manifest.txt +45 -0
  3. data/NOTICE.txt +2 -0
  4. data/README.rdoc +124 -0
  5. data/Rakefile +21 -0
  6. data/lib/rjack-tarpit.rb +40 -0
  7. data/lib/rjack-tarpit/base.rb +22 -0
  8. data/lib/rjack-tarpit/base_strategy.rb +175 -0
  9. data/lib/rjack-tarpit/clean.rb +43 -0
  10. data/lib/rjack-tarpit/doc.rb +67 -0
  11. data/lib/rjack-tarpit/gem.rb +119 -0
  12. data/lib/rjack-tarpit/git.rb +45 -0
  13. data/lib/rjack-tarpit/line_match.rb +134 -0
  14. data/lib/rjack-tarpit/readme_parser.rb +74 -0
  15. data/lib/rjack-tarpit/spec.rb +314 -0
  16. data/lib/rjack-tarpit/test.rb +110 -0
  17. data/lib/rjack-tarpit/util.rb +37 -0
  18. data/test/jproject/History.rdoc +2 -0
  19. data/test/jproject/Manifest.static +10 -0
  20. data/test/jproject/Manifest.txt +11 -0
  21. data/test/jproject/NOTICE.txt +2 -0
  22. data/test/jproject/README.rdoc +24 -0
  23. data/test/jproject/Rakefile +7 -0
  24. data/test/jproject/jproject.gemspec +15 -0
  25. data/test/jproject/lib/jproject.rb +11 -0
  26. data/test/jproject/lib/jproject/base.rb +3 -0
  27. data/test/jproject/pom.xml +75 -0
  28. data/test/jproject/test/setup.rb +7 -0
  29. data/test/jproject/test/test_jproject.rb +14 -0
  30. data/test/setup.rb +7 -0
  31. data/test/test_projects.rb +71 -0
  32. data/test/test_readme_parser.rb +97 -0
  33. data/test/test_tarpit.rb +33 -0
  34. data/test/zookeeper/History.rdoc +2 -0
  35. data/test/zookeeper/Manifest.static +10 -0
  36. data/test/zookeeper/Manifest.txt +13 -0
  37. data/test/zookeeper/README.rdoc +23 -0
  38. data/test/zookeeper/Rakefile +7 -0
  39. data/test/zookeeper/assembly.xml +15 -0
  40. data/test/zookeeper/lib/rjack-zookeeper.rb +29 -0
  41. data/test/zookeeper/lib/rjack-zookeeper/base.rb +23 -0
  42. data/test/zookeeper/pom.xml +73 -0
  43. data/test/zookeeper/rjack-zookeeper.gemspec +18 -0
  44. data/test/zookeeper/test/setup.rb +17 -0
  45. data/test/zookeeper/test/test_zookeeper.rb +14 -0
  46. metadata +186 -0
@@ -0,0 +1,314 @@
1
+ #--
2
+ # Copyright (c) 2009-2012 David Kellum
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); you
5
+ # may not use this file except in compliance with the License. You may
6
+ # obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13
+ # implied. See the License for the specific language governing
14
+ # permissions and limitations under the License.
15
+ #++
16
+
17
+ require 'rjack-tarpit/base'
18
+ require 'rjack-tarpit/util'
19
+ require 'rjack-tarpit/readme_parser'
20
+
21
+ require 'fileutils'
22
+
23
+ module RJack::TarPit
24
+
25
+ class << self
26
+
27
+ # The result of the last call to specify.
28
+ attr_reader :last_spec
29
+
30
+ # Produce a Gem::Specification embellished with SpecHelper,
31
+ # ReadmeParser, and yield to block.
32
+ # The specification name defaults to <name>.gemspec calling this.
33
+ # Within block, $LOAD_PATH will have the projects lib included.
34
+ def specify( &block )
35
+
36
+ # Embellish a Specification instance with SpecHelper.
37
+ #
38
+ # This way spec.to_yaml continues to be a Gem::Specification
39
+ # object. Deriving our own Specification subclass would cause
40
+ # problems with to_yaml.
41
+ spec = Gem::Specification.new
42
+ class << spec
43
+ include SpecHelper
44
+ include ReadmeParser
45
+ end
46
+
47
+ specfile = caller[0] =~ /^(.*\.gemspec)/ && $1
48
+
49
+ # Default name to the (name).gemspec that should be calling us
50
+ spec.name = File.basename( specfile, ".gemspec" )
51
+
52
+ # Add project's lib/ to LOAD_PATH for block...
53
+ $LOAD_PATH.unshift( File.join( File.dirname( specfile ), 'lib' ) )
54
+
55
+ spec.tarpit_specify &block
56
+
57
+ $LOAD_PATH.shift # ...then remove it to avoid pollution
58
+
59
+ @last_spec = spec
60
+ end
61
+ end
62
+
63
+ # Helper mixin for Gem::Specification, adding Manifest awareness,
64
+ # maven strategy, jars and other generated_files declarations, as
65
+ # well as several convenience methods and defaults. Many of these were
66
+ # Hoe inspired or remain compatible with Hoe.spec
67
+ module SpecHelper
68
+
69
+ # The filename for the project README
70
+ # (default: README.rdoc or README.txt if present)
71
+ attr_accessor :readme_file
72
+
73
+ # The filename for the project History
74
+ # (default: History.rdoc or History.txt if present)
75
+ attr_accessor :history_file
76
+
77
+ # The set of jar file names (without path) to include. May be
78
+ # auto-computed for :no_assembly (default_jar) or
79
+ # :jars_from_assembly (from Manifest.txt) maven_strategy.
80
+ attr_writer :jars
81
+
82
+ # Destination path for any jar links
83
+ # (default: lib/<name>)
84
+ attr_accessor :jar_dest
85
+
86
+ # Any additional generated files to be included.
87
+ # (default: nil)
88
+ attr_accessor :generated_files
89
+
90
+ # Strategy for interacting with maven
91
+ # (default: nil, none )
92
+ # :jars_from_assembly:: jars will be found in assembly rather then
93
+ # set in Rakefile.
94
+ # :no_assembly:: One jar created from source, jars=[default_jar],
95
+ # no assembly setup in maven.
96
+ attr_accessor :maven_strategy
97
+
98
+ # The name of the assembly (default: name)
99
+ attr_accessor :assembly_name
100
+
101
+ # The version of the assembly, which might be static, i.e. "1.0",
102
+ # if the pom is not shared (dependency jars only)
103
+ # (default: version)
104
+ attr_accessor :assembly_version
105
+
106
+ # The canonical file containing the version number, where changes
107
+ # should trigger Manifest.txt (re-)generation.
108
+ # (default: lib/<name>/base.rb or lib/<name>/version.rb if present)
109
+ attr_accessor :version_file
110
+
111
+ # Set defaults, yields self to block, and finalizes
112
+ def tarpit_specify
113
+
114
+ # Better defaults
115
+ if File.exist?( 'Manifest.txt' )
116
+ self.files = Util::read_file_list( 'Manifest.txt' )
117
+ end
118
+
119
+ self.executables =
120
+ self.files.grep( /^bin\/.+/ ) { |f| File.basename( f ) }
121
+
122
+ @readme_file = existing( %w[ README.rdoc README.txt ] )
123
+ @history_file = existing( %w[ History.rdoc History.txt ] )
124
+
125
+ self.extra_rdoc_files += [ Dir[ '*.rdoc' ],
126
+ @readme_file,
127
+ @history_file ].flatten.compact.sort.uniq
128
+
129
+ self.rdoc_options += [ '--main', @readme_file ] if @readme_file
130
+
131
+ @jars = nil
132
+ @jar_dest = nil
133
+ @generated_files = nil
134
+ @maven_strategy = nil
135
+
136
+ parse_readme( @readme_file ) if @readme_file
137
+
138
+ yield self if block_given?
139
+
140
+ @assembly_name ||= name
141
+ @assembly_version ||= version
142
+
143
+ version_candidates = %w[ base version ].map do |f|
144
+ File.join( 'lib', name, "#{f}.rb" )
145
+ end
146
+ @version_file ||= existing( version_candidates )
147
+
148
+ @jar_dest ||= File.join( 'lib', name )
149
+
150
+ @jars = Array( @jars ).compact
151
+ @jars = nil if @jars.empty?
152
+
153
+ if ( @jars.nil? &&
154
+ ( ( @maven_strategy == :no_assembly ) ||
155
+ ( @maven_strategy.nil? && File.exist?( 'pom.xml' ) ) ) )
156
+ @jars = [ default_jar ]
157
+ end
158
+
159
+ # The platform must be java if jars are specified.
160
+ self.platform = :java if !jars.empty?
161
+
162
+ # Add tarpit as dev dependency unless already present
163
+ unless ( name == 'rjack-tarpit' ||
164
+ dependencies.find { |d| d.name == 'rjack-tarpit' } )
165
+ depend( 'rjack-tarpit', "~> #{ RJack::TarPit::MINOR_VERSION }", :dev )
166
+ end
167
+
168
+ check_generate_manifest
169
+
170
+ end
171
+
172
+ # Add developer with optional email.
173
+ def add_developer( author, email = nil )
174
+ ( self.authors ||= [] ) << author
175
+ ( self.email ||= [] ) << email if email
176
+ end
177
+
178
+ # Add a dependencies by name, version requirements, and a final
179
+ # optional :dev or :development symbol indicating its for
180
+ # development.
181
+ def depend( name, *args )
182
+ if args.last == :dev || args.last == :development
183
+ args.pop
184
+ add_development_dependency( name, *args )
185
+ else
186
+ add_dependency( name, *args )
187
+ end
188
+ end
189
+
190
+ # Set summary. This override cleans up whitespace.
191
+ def summary=( val )
192
+ super( val.gsub( /\s+/, ' ' ).strip )
193
+ end
194
+
195
+ # Set summary. This override cleans up whitespace.
196
+ def description=( val )
197
+ super( val.gsub( /\s+/, ' ' ).strip )
198
+ end
199
+
200
+ # Override Gem::Specification to support simple platform
201
+ # symbol/string, i.e. :java
202
+ def platform=( val )
203
+ if val.is_a?( Symbol ) || val.is_a?( String )
204
+ val = Gem::Platform.new( val.to_s )
205
+ end
206
+ super( val )
207
+ end
208
+
209
+ # Return set or defaulted jar file names (without path)
210
+ def jars
211
+ if @jars.nil? && ( maven_strategy == :jars_from_assembly )
212
+
213
+ # Extract jar files from saved Manifest state, since neither
214
+ # from or dest jars may be available at call time.
215
+ @jars =
216
+ Util::read_file_list( 'Manifest.txt' ).
217
+ select { |f| f =~ /\.jar$/ }.
218
+ map { |f| File.basename( f ) }
219
+
220
+ #FIXME: Test Manifest.txt exists yet?
221
+ end
222
+ @jars ||= Array( @jars )
223
+ end
224
+
225
+ def check_generate_manifest
226
+ # FIXME: How about diffent aproach: Always build new manifest
227
+ # list, compare, and report and write if change from read in
228
+ # list?
229
+
230
+ unless @generated_manifest
231
+ if File.exist?( 'Manifest.static' )
232
+ mtime = [ 'Manifest.static', version_file ].
233
+ compact.
234
+ map { |f| File.stat( f ).mtime }.
235
+ max
236
+
237
+ if ( !File.exist?( 'Manifest.txt' ) ||
238
+ mtime > File.stat( 'Manifest.txt' ).mtime )
239
+ generate_manifest
240
+ self.files = Util::read_file_list( 'Manifest.txt' )
241
+ end
242
+ end
243
+ end
244
+ end
245
+
246
+ # Generate Manifest.txt
247
+ def generate_manifest
248
+ unless @generated_manifest #only once
249
+ remove_dest_jars
250
+
251
+ m = []
252
+ if File.exist?( 'Manifest.static' )
253
+ m += Util::read_file_list( 'Manifest.static' )
254
+ end
255
+ m += Util::clean_list( generated_files ).sort
256
+ m += dest_jars
257
+
258
+ puts "TARPIT: Regenerating #{ File.expand_path( 'Manifest.txt' ) }"
259
+ open( 'Manifest.txt', 'w' ) { |out| out.puts m }
260
+ @generated_manifest = true
261
+ else
262
+ puts "already generated"
263
+ end
264
+ end
265
+
266
+ # Remove jars in jar_dest by wildcard expression
267
+ def remove_dest_jars
268
+ jars = Dir[ File.join( jar_dest, "*.jar" ) ].sort
269
+ FileUtils::rm_f jars unless jars.empty?
270
+ end
271
+
272
+ # The target/assembly path from which jars are linked
273
+ def jar_from
274
+ dirs = [ 'target' ]
275
+
276
+ unless maven_strategy == :no_assembly
277
+ dirs << [ assembly_name,
278
+ assembly_version,
279
+ 'bin.dir' ].join( '-' )
280
+ end
281
+
282
+ File.join( dirs )
283
+ end
284
+
285
+ private
286
+
287
+ # The list of jars in jar_dest path, used during manifest generation
288
+ def dest_jars
289
+ if maven_strategy == :jars_from_assembly
290
+
291
+ # For manifest, map destination jars from available jars in
292
+ # (jar_from) target/assembly. These are available since mvn
293
+ # package will be run first for the :manifest target.
294
+ Dir[ File.join( jar_from, "*.jar" ) ].
295
+ map { |j| File.basename( j ) }.
296
+ sort.
297
+ map { |j| File.join( jar_dest, j ) }
298
+ else
299
+ Util::clean_list( jars ).
300
+ sort.
301
+ map { |j| File.join( jar_dest, j ) }
302
+ end
303
+ end
304
+
305
+ def existing( files )
306
+ files.find { |f| File.exist?( f ) }
307
+ end
308
+
309
+ # Return a default jar name built from name and version
310
+ def default_jar
311
+ "#{name}-#{version}.jar"
312
+ end
313
+ end
314
+ end
@@ -0,0 +1,110 @@
1
+ #--
2
+ # Copyright (c) 2009-2012 David Kellum
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); you
5
+ # may not use this file except in compliance with the License. You may
6
+ # obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13
+ # implied. See the License for the specific language governing
14
+ # permissions and limitations under the License.
15
+ #++
16
+
17
+ module RJack::TarPit
18
+
19
+ module TestTaskDefiner
20
+
21
+ # Proc for setting Rake TestTask options
22
+ # (default: nil, no-op)
23
+ attr_accessor :test_task_config
24
+
25
+ # Support same options as Rake::TestTask, plus tarpit's own
26
+ # :mini_in_proc (default) option, which loads minitest tests and
27
+ # runs in (rake) process.
28
+ attr_accessor :test_loader
29
+
30
+ # Proc for setting RSpec::Core::RakeTask options
31
+ # (default: nil, no-op)
32
+ attr_accessor :rspec_task_config
33
+
34
+ def initialize
35
+ super
36
+
37
+ @test_loader = :mini_in_proc
38
+ @test_task_config = nil
39
+ @rspec_task_config = nil
40
+
41
+ add_define_hook( :define_test_tasks )
42
+ add_define_hook( :define_spec_tasks )
43
+ end
44
+
45
+ def define_spec_tasks
46
+
47
+ if File.directory?( "spec" ) || rspec_task_config
48
+ require 'rspec/core/rake_task'
49
+
50
+ desc "Run RSpec on specifications"
51
+ RSpec::Core::RakeTask.new( :spec ) do |t|
52
+ t.rspec_opts ||= []
53
+ t.rspec_opts += %w[ -Ispec:lib ]
54
+ rspec_task_config.call( t ) if rspec_task_config
55
+ end
56
+
57
+ desc "Run RSpec on specifications"
58
+ task :test => [ :spec ]
59
+
60
+ task :default => [ :test ]
61
+ end
62
+
63
+ end
64
+
65
+ def define_test_tasks
66
+
67
+ if test_loader == :mini_in_proc
68
+
69
+ tfiles = FileList[ "test/test*.rb" ]
70
+ if !tfiles.empty?
71
+
72
+ desc "Run minitest tests (in rake process)"
73
+ task :test do |t,args|
74
+ require 'minitest/unit'
75
+
76
+ MiniTest::Unit.class_eval do
77
+ def self.autorun # :nodoc:
78
+ # disable autorun, as we are running ourselves
79
+ end
80
+ end
81
+
82
+ tfiles.each { |f| load f }
83
+
84
+ code = MiniTest::Unit.new.run( ( ENV['TESTOPTS'] || '' ).split )
85
+ fail "test failed (#{code})" if code && code > 0
86
+ puts
87
+ end
88
+
89
+ else
90
+ desc "No-op"
91
+ task :test
92
+ end
93
+
94
+ else
95
+
96
+ require 'rake/testtask'
97
+
98
+ Rake::TestTask.new do |t|
99
+ t.loader = test_loader
100
+ test_task_config.call( t ) if test_task_config
101
+ end
102
+
103
+ end
104
+
105
+ task :default => [ :test ]
106
+ end
107
+
108
+ end
109
+
110
+ end
@@ -0,0 +1,37 @@
1
+ #--
2
+ # Copyright (c) 2009-2012 David Kellum
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); you
5
+ # may not use this file except in compliance with the License. You
6
+ # may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13
+ # implied. See the License for the specific language governing
14
+ # permissions and limitations under the License.
15
+ #++
16
+
17
+ module RJack::TarPit
18
+ module Util
19
+
20
+ module_function
21
+
22
+ # Read a list of files and return a cleaned list.
23
+ def read_file_list( sfile )
24
+ clean_list( open( sfile ) { |f| f.readlines } )
25
+ end
26
+
27
+ # Cleanup a list of files
28
+ def clean_list( l )
29
+ Array( l ).
30
+ compact.
31
+ map { |f| f.strip }.
32
+ reject { |f| f.empty? }
33
+ end
34
+
35
+ end
36
+
37
+ end