rjack-tarpit 1.4.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/History.rdoc +13 -9
  2. data/Manifest.txt +39 -0
  3. data/NOTICE.txt +1 -1
  4. data/README.rdoc +85 -30
  5. data/Rakefile +11 -30
  6. data/lib/rjack-tarpit.rb +15 -456
  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/{pkg/rjack-zookeeper-3.4.1.0-java/test → test}/test_zookeeper.rb +0 -0
  46. metadata +132 -66
  47. data/.gemtest +0 -0
@@ -0,0 +1,134 @@
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 LineMatchTaskDefiner
20
+
21
+ # Regexp to use for first line of History file with version, date
22
+ attr_accessor :history_regexp
23
+
24
+ # Regexp to use for a valid/releasable date on History
25
+ attr_accessor :history_date_regexp
26
+
27
+ # Proc returning regexp given gem version as parameter, to use to
28
+ # validate the version of the latest history entry.
29
+ attr_accessor :history_version_regexp
30
+
31
+ # Array of "init" files to check for gem version references in
32
+ # (default: [ init/<spec.name> ], if exists)
33
+ attr_accessor :init_files
34
+
35
+ # Proc given spec and returning regexp matching gem line to find in
36
+ # init_files. (default: /^gem.+<spec.name>/)
37
+ attr_accessor :init_line_regexp
38
+
39
+ # Proc returning regexp given gem version as parameter, to use to
40
+ # validate the gem version of gem line in init_files.
41
+ # (default: /= <spec.version>/)
42
+ attr_accessor :init_version_regexp
43
+
44
+ def initialize
45
+ super
46
+
47
+ @history_regexp = /^==/
48
+ @history_date_regexp = /\([0-9\-]+\)$/
49
+ @history_version_regexp = Proc.new { |v| / #{v} / }
50
+
51
+ @init_files = :default
52
+ @init_line_regexp = Proc.new { |s| /^gem.+#{s.name}/ }
53
+ @init_version_regexp = Proc.new { |v| /= #{v}/ }
54
+
55
+ add_define_hook( :define_line_match_tasks )
56
+ end
57
+
58
+ def define_line_match_tasks
59
+
60
+ if spec.history_file && history_regexp
61
+ desc "Check that #{spec.history_file} has latest version"
62
+ task :check_history_version do
63
+ test_line_match( spec.history_file,
64
+ history_regexp,
65
+ history_version_regexp.call( spec.version ) )
66
+ end
67
+ [ :gem, :tag, :push ].each { |t| task t => :check_history_version }
68
+ end
69
+
70
+ if spec.history_file && history_date_regexp
71
+ desc "Check that #{spec.history_file} has a date for release"
72
+ task :check_history_date do
73
+ test_line_match( spec.history_file,
74
+ history_regexp,
75
+ history_date_regexp )
76
+ end
77
+ [ :tag, :push ].each { |t| task t => :check_history_date }
78
+ end
79
+
80
+ if init_files == :default
81
+ init_files = [ File.join( 'init', spec.name ) ].
82
+ select { |f| File.exist?( f ) }
83
+ end
84
+
85
+ init_files.each do |inf|
86
+ desc "Check that #{init_files.join(", ")} has latest version"
87
+ task :check_init_version do
88
+ test_line_match( inf,
89
+ init_line_regexp.call( spec ),
90
+ init_version_regexp.call( spec.version ) )
91
+ end
92
+ end
93
+
94
+ unless init_files.empty?
95
+ [ :gem, :tag ].each { |t| task t => :check_init_version }
96
+ end
97
+
98
+ end
99
+
100
+ # Test that all specified files have at least one line matching
101
+ # line_regex, and that first line additionally matches (optional)
102
+ # pass_line_regex.
103
+ # ==== Parameters
104
+ # files<Array(~)>:: List of files to test
105
+ # line_regex<Regexp>:: Test first matching line
106
+ # pass_line_regex:: Further test on match line (default: match all)
107
+ # ==== Raises
108
+ # RuntimeError:: on test failure.
109
+ def test_line_match( files, line_regex, pass_line_regex = // )
110
+ Array( files ).each do |mfile|
111
+ found = false
112
+ open( mfile ) do |mf|
113
+ num = 0
114
+ mf.each do |line|
115
+ num += 1
116
+ if line =~ line_regex
117
+ found = true
118
+ unless line =~ pass_line_regex
119
+ raise( "%s:%d: %s !~ %s" %
120
+ [ mfile, num, line.strip, pass_line_regex.inspect ] )
121
+ end
122
+ break
123
+ end
124
+ end
125
+ end
126
+ unless found
127
+ raise "#{mfile}: #{line_regex.inspect} not found"
128
+ end
129
+ end
130
+ end
131
+
132
+ end
133
+
134
+ end
@@ -0,0 +1,74 @@
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
+
19
+ module RJack::TarPit
20
+
21
+ # Helper mixin for deriving default spec properties from the README
22
+ # (rdoc,txt) file
23
+ module ReadmeParser
24
+
25
+ # Parse the given README file, setting properties homepage,
26
+ # summary, and description on self if possible.
27
+ def parse_readme( file )
28
+
29
+ in_desc = false
30
+ desc = ""
31
+
32
+ readme_file_open( file ) do |fin|
33
+ fin.each do |line|
34
+ if homepage.nil? && line =~ /^\s*\*\s*(http\S+)\s*$/
35
+ self.homepage = $1
36
+ elsif line =~ /^=/ # section header
37
+ in_desc = ( line =~ /^=+\s*Description\s*$/i )
38
+ # Stop at new section if we already have a description
39
+ break unless desc.empty?
40
+ elsif in_desc
41
+ # Stop if empty line after description, or bullet (*) list
42
+ break if ( !desc.empty? && line =~ /^\s*$/ ) || line =~ /^\s*\*/
43
+ desc << line
44
+ end
45
+ end
46
+ end
47
+
48
+ desc = desc.
49
+ gsub( /\s+/, ' ' ). #Simplify whitespace
50
+ gsub( /\{([^\}]+)\}\[[^\]]*\]/, '\1' ). # Replace rdoc link \w anchor
51
+ gsub( /(\S)\[\s*http:[^\]]*\]/, '\1' ). # Replace bare rdoc links
52
+ strip.
53
+ sub( /:$/, '.' ) # Replace a final ':', like when term. at list
54
+
55
+ # Summary is first sentence if we find one, or entire desc otherwise
56
+ if desc =~ /^(.+[!?:.])\s/
57
+ self.summary = $1.strip
58
+ self.description = desc # Use remainder for description
59
+ else
60
+ self.summary = desc
61
+ end
62
+
63
+ end
64
+
65
+ private
66
+
67
+ # Open, and test hook
68
+ def readme_file_open( file, &block )
69
+ File.open( file, 'r', &block )
70
+ end
71
+
72
+ end
73
+
74
+ end
@@ -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