rjack-tarpit 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.rdoc ADDED
@@ -0,0 +1,2 @@
1
+ === 1.0.0 (2009-10-10)
2
+ * Initial release.
data/Manifest.txt ADDED
@@ -0,0 +1,5 @@
1
+ Manifest.txt
2
+ History.rdoc
3
+ README.rdoc
4
+ Rakefile
5
+ lib/rjack-tarpit.rb
data/README.rdoc ADDED
@@ -0,0 +1,68 @@
1
+ = rjack-tarpit
2
+
3
+ * http://rjack.rubyforge.org
4
+ * http://rubyforge.org/projects/rjack
5
+
6
+ == Description
7
+
8
+ TarPit provides the glue for an unholy union of build tools. Namely:
9
+
10
+ * Rake[http://github.com/jimweirich/rake] with
11
+ Hoe[http://seattlerb.rubyforge.org/hoe/] for gem publishing
12
+ * Maven[http://maven.apache.org/] for Java builds with dependencies.
13
+
14
+ In particular, it runs "mvn package" when needed, links jars to the
15
+ gem lib directory, and provides (semi-)automatic Manifest.txt
16
+ generation with these jar files without offending Hoe.
17
+
18
+ * The Maven pom.xml (and assembly.xml if needed) must be managed
19
+ independently.
20
+ * A Manifest.static file holds the static elements of the manifest.
21
+
22
+ == Synopsis
23
+
24
+ Rakefile example for a gem including a single jar, built from java
25
+ source with maven:
26
+
27
+ # -*- ruby -*-
28
+ $LOAD_PATH << './lib'
29
+ require 'mygem/version'
30
+
31
+ require 'rubygems'
32
+ gem 'rjack-tarpit', '~> 1.0.0'
33
+ require 'rjack-tarpit'
34
+
35
+ t = RJack::TarPit.new( 'mygem', MyGem::VERSION, :no_assembly )
36
+
37
+ t.specify do |h|
38
+ h.developer( "David Kellum", "dek-oss@gravitext.com" )
39
+ h.extra_deps += [ [ 'rjack-slf4j', '~> 1.5.8' ],
40
+ [ 'rjack-logback, '~> 1.9.16' ] ]
41
+ end
42
+
43
+ file 'Manifest.txt' => [ 'lib/mygem/version.rb' ]
44
+
45
+ t.define_tasks
46
+
47
+ == Dependencies
48
+
49
+ Besides the explicit gem dependencies, TarPit requires:
50
+
51
+ * rake 0.8.7+ (currently bundled with JRuby 1.3)
52
+ * Apache Maven 2.x ('mvn' command on path)
53
+
54
+ == License
55
+
56
+ Copyright (c) 2009 David Kellum
57
+
58
+ Licensed under the Apache License, Version 2.0 (the "License"); you
59
+ may not use this file except in compliance with the License. You
60
+ may obtain a copy of the License at:
61
+
62
+ http://www.apache.org/licenses/LICENSE-2.0
63
+
64
+ Unless required by applicable law or agreed to in writing, software
65
+ distributed under the License is distributed on an "AS IS" BASIS,
66
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
67
+ implied. See the License for the specific language governing
68
+ permissions and limitations under the License.
data/Rakefile ADDED
@@ -0,0 +1,39 @@
1
+ # -*- ruby -*-
2
+ #--
3
+ # Copyright (C) 2009 David Kellum
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License"); you
6
+ # may not use this file except in compliance with the License. You
7
+ # may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14
+ # implied. See the License for the specific language governing
15
+ # permissions and limitations under the License.
16
+ #++
17
+
18
+ $LOAD_PATH << './lib'
19
+ require 'rubygems'
20
+
21
+ # Use same hoe version for building gem plus this gem's dependency
22
+ hoe_version = '~> 2.3.3'
23
+ gem 'hoe', hoe_version
24
+ require 'rjack-tarpit'
25
+
26
+ include RJack
27
+
28
+ t = TarPit.new( 'rjack-tarpit', TarPit::VERSION )
29
+
30
+ t.specify do |h|
31
+ h.developer( 'David Kellum', 'dek-oss@gravitext.com' )
32
+ h.extra_deps += [ [ 'hoe', hoe_version ],
33
+ [ 'rdoc', '~> 2.4' ],
34
+ [ 'rubyforge', '~> 1.0.3' ] ]
35
+ h.rubyforge_name = 'rjack'
36
+ h.remote_rdoc_dir = 'tarpit'
37
+ end
38
+
39
+ t.define_tasks
@@ -0,0 +1,338 @@
1
+ #--
2
+ # Copyright (C) 2009 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
+ require 'hoe'
18
+
19
+ # Silly Hoe sets up DOT with rdoc unless this is set.
20
+ ENV['NODOT'] = "no thanks"
21
+
22
+ module RJack
23
+
24
+ # Provides glue for Rake, Hoe, and Maven by generating tasks.
25
+ module TarPit
26
+ # Module version
27
+ VERSION = '1.0.0'
28
+
29
+ # Construct new task generator by gem name, version, and flags. A descendant
30
+ # of BaseStrategy is returned.
31
+ # ==== flags
32
+ # :jars_from_assembly:: jars will be found in assembly rather then
33
+ # set in Rakefile.
34
+ # :no_assembly:: One jar created from source, jars=[default_jar],
35
+ # no assembly setup in maven.
36
+ def self.new( name, version, *flags )
37
+ if flags.include?( :jars_from_assembly )
38
+ JarsFromAssembly.new( name, version, flags )
39
+ else
40
+ BaseStrategy.new( name, version, flags )
41
+ end
42
+ end
43
+
44
+ # Base strategy implementation where jars are known by the
45
+ # Rakefile (not :jars_from_assembly)
46
+ class BaseStrategy
47
+
48
+ # Name of gem as constructed.
49
+ attr_reader :name
50
+ # Version of gem as constructed.
51
+ attr_reader :version
52
+
53
+ # The set of jar file names (without path) to include. May be
54
+ # lazily computed by other strategies.
55
+ attr_accessor :jars
56
+
57
+ # Destination path for any jars [Default: lib/name]
58
+ attr_accessor :jar_dest
59
+
60
+ # Any additional generated files to be included [Default: nil]
61
+ attr_accessor :generated_files
62
+
63
+ # The name of the assembly [Default: name]
64
+ attr_writer :assembly_name
65
+
66
+ # The version of the assembly, which might be static
67
+ # (i.e. "1.0") if the pom is not shared (dependency jars only)
68
+ # [Default: version]
69
+ attr_writer :assembly_version
70
+
71
+ # See TarPit.new
72
+ def initialize( name, version, flags )
73
+ @name = name
74
+ @version = version
75
+ @flags = flags
76
+ @jars = [ default_jar ] if @flags.include?( :no_assembly )
77
+ @jar_dest = File.join( 'lib', @name )
78
+ @hoe_specifier = :unset
79
+ end
80
+
81
+ # Return a default jar name built from name and version
82
+ def default_jar
83
+ "#{name}-#{version}.jar"
84
+ end
85
+
86
+ # Specify gem project details, yielding Hoe instance to block
87
+ # after setting various defaults. Thus all Hoe.spec setters are
88
+ # valid in this block. The actual Hoe construction and execution
89
+ # of block is deferred to define_tasks.
90
+ def specify( &block )
91
+ @hoe_specifier = block
92
+ end
93
+
94
+ # Define all tasks based on provided details. In this strategy,
95
+ # the Manifest.txt task will be invoked prior to calling
96
+ # Hoe.spec, thus any additional Manifest.txt dependencies
97
+ # should be specified prior to this call.
98
+ def define_tasks
99
+ define_maven_package_task if jars
100
+
101
+ if jars || generated_files
102
+ mtask = define_manifest_task
103
+
104
+ # The manifest needs to run before hoe_specify
105
+ mtask.invoke
106
+ end
107
+
108
+ define_post_maven_tasks if jars
109
+
110
+ hoe_specify
111
+
112
+ define_git_tag
113
+ end
114
+
115
+ # Define task for dynamically generating Manifest.txt, by
116
+ # appending array returned by the given block to specified files, or
117
+ # contents of Manifest.static.
118
+ def define_manifest_task
119
+
120
+ if File.exist?( 'Manifest.static' )
121
+ file 'Manifest.txt' => [ 'Manifest.static' ]
122
+ end
123
+
124
+ gf = clean_list( generated_files ).sort
125
+ [ :gem, :test ].each { |t| task t => gf }
126
+
127
+ unless gf.empty?
128
+ task :gen_clean do
129
+ rm_f gf
130
+ end
131
+ task :clean => :gen_clean
132
+ end
133
+
134
+ desc "Force update of Manifest.txt"
135
+ task :manifest do
136
+ generate_manifest
137
+ end
138
+
139
+ mtask = file 'Manifest.txt' do
140
+ generate_manifest
141
+ end
142
+
143
+ mtask
144
+ end
145
+
146
+ # File touched to record the time of last successful 'mvn
147
+ # package' run.
148
+ MVN_STATE_FILE = 'target/.tarpit'
149
+
150
+ # Define a file task tracking calls to "mvn package"
151
+ def define_maven_package_task
152
+ file MVN_STATE_FILE => maven_dependencies do
153
+ sh( 'mvn package' ) do |ok,res|
154
+ if ok
155
+ touch( MVN_STATE_FILE )
156
+ else
157
+ raise "TARPIT: 'mvn package' failed."
158
+ end
159
+ end
160
+ end
161
+ end
162
+
163
+ # Define file tasks for all jar symlinks and other misc. maven
164
+ # associated tasks like :mvn_clean.
165
+ def define_post_maven_tasks
166
+ jfrom = jar_from
167
+ jars.each do |jar|
168
+ from = File.join( jfrom, jar )
169
+ dest = File.join( jar_dest, jar )
170
+ file from => [ MVN_STATE_FILE ]
171
+ file dest => [ from ] do
172
+ ln_sf( File.join( '..', '..', from ), dest )
173
+ end
174
+ [ :gem, :test ].each { |t| task t => [ dest ] }
175
+ end
176
+
177
+ task :mvn_clean do
178
+ remove_dest_jars
179
+ sh 'mvn clean'
180
+ end
181
+ task :clean => :mvn_clean
182
+ end
183
+
184
+ # Dependencies on "mvn package" including pom.xml, any assembly.xml,
185
+ # all files under the "src" directory.
186
+ def maven_dependencies
187
+ deps = [ 'pom.xml' ]
188
+ deps << 'assembly.xml' if File.exist?( 'assembly.xml' )
189
+ deps += FileList[ "src/**/*" ].exclude { |f| ! File.file?( f ) }
190
+ deps
191
+ end
192
+
193
+ # Define git based :tag task
194
+ def define_git_tag
195
+ task :tag do
196
+ tag = [ name, version ].join( '-' )
197
+ dname = File.dirname( __FILE__ )
198
+ dname = '.' if Dir.getwd == dname
199
+ sh( "git status --only #{dname}" ) do |ok,res|
200
+ if ok #changes present
201
+ raise "Commit these changes before tagging."
202
+ end
203
+ end
204
+ sh %{git tag -s -f -m "tag [#{tag}]" "#{tag}"}
205
+ end
206
+ end
207
+
208
+ # Setup Hoe via Hoe.spec
209
+ def hoe_specify
210
+ unless @hoe_specifier == :unset
211
+ tp = self
212
+ outer = @hoe_specifier
213
+ Hoe.spec( @name ) do |h|
214
+ h.version = tp.version
215
+
216
+ h.readme_file = 'README.rdoc' if File.exist?( 'README.rdoc' )
217
+ h.history_file = 'History.rdoc' if File.exist?( 'History.rdoc' )
218
+ h.extra_rdoc_files = FileList[ '*.rdoc' ]
219
+
220
+ outer.call( h )
221
+ end
222
+ end
223
+ end
224
+
225
+ # Generate Manifest.txt
226
+ def generate_manifest
227
+ remove_dest_jars
228
+
229
+ m = []
230
+ if File.exist?( 'Manifest.static' )
231
+ m += read_file_list( 'Manifest.static' )
232
+ end
233
+ m += clean_list( generated_files ).sort
234
+ m += dest_jars
235
+
236
+ puts "TARPIT: Updating Manifest.txt"
237
+ open( 'Manifest.txt', 'w' ) { |out| out.puts m }
238
+ end
239
+
240
+ # Remove jars in jar_dest by wildcard expression
241
+ def remove_dest_jars
242
+ jars = FileList[ File.join( jar_dest, "*.jar" ) ].sort
243
+ rm_f jars unless jars.empty?
244
+ end
245
+
246
+ # The list of jars in jar_dest path, used during manifest generation
247
+ def dest_jars
248
+ clean_list( jars ).sort.map { |j| File.join( jar_dest, j ) }
249
+ end
250
+
251
+ # The target/assembly path from which jars are linked
252
+ def jar_from
253
+ dirs = [ 'target' ]
254
+
255
+ unless @flags.include?( :no_assembly )
256
+ dirs << [ @assembly_name || name,
257
+ @assembly_version || version,
258
+ 'bin.dir' ].join('-')
259
+ end
260
+
261
+ File.join( dirs )
262
+ end
263
+
264
+ # Read a list of files and return a cleaned list.
265
+ def read_file_list( sfile )
266
+ clean_list( open( sfile ) { |f| f.readlines } )
267
+ end
268
+
269
+ # Cleanup a list of files
270
+ def clean_list( l )
271
+ l = l.to_a.compact
272
+ l.map! { |f| f.strip }
273
+ l.map! { |f| f.empty? ? nil : f }
274
+ l.compact!
275
+ l
276
+ end
277
+
278
+ end
279
+
280
+ # Strategy in which the jars are inferred only by inspecting the
281
+ # the completed maven assembly. The :manifest task is thus
282
+ # dependent on 'mvn package'. Manifest changes need to be manually
283
+ # incorporated by explicitly running "jrake manifest"
284
+ class JarsFromAssembly < BaseStrategy
285
+
286
+ # Define all tasks based on provided details. Don't invoke
287
+ # Manifest.txt before Hoe, just use whats already in place.
288
+ def define_tasks
289
+ define_maven_package_task
290
+
291
+ mtask = define_manifest_task
292
+
293
+ task :manifest => [ MVN_STATE_FILE ]
294
+
295
+ define_post_maven_tasks
296
+
297
+ hoe_specify
298
+
299
+ define_git_tag
300
+ end
301
+
302
+ # For manifest, map destination jars from available jars in
303
+ # (jar_from) target/assembly. These are available since mvn
304
+ # package will be run first for the :manifest target.
305
+ def dest_jars
306
+ jars = FileList[ File.join( jar_from, "*.jar" ) ]
307
+ jars = jars.map { |j| File.basename( j ) }.sort
308
+ jars.map { |j| File.join( jar_dest, j ) }
309
+ end
310
+
311
+ # Extract jar files from saved Manifest state, since
312
+ # neither from or dest jars may be available at call time.
313
+ def jars
314
+ unless @jars
315
+ files = read_file_list( 'Manifest.txt' ).select { |f| f =~ /\.jar$/ }
316
+ @jars = files.map { |f| File.basename( f ) }
317
+ end
318
+ @jars
319
+ end
320
+
321
+ end
322
+
323
+ end
324
+
325
+ end
326
+
327
+ # Replace special Hoe development dependency with rjack-tarpit (which
328
+ # itself depends on constrained version of Hoe.)
329
+ class Hoe
330
+ def add_dependencies
331
+ self.extra_deps = normalize_deps extra_deps
332
+ self.extra_dev_deps = normalize_deps extra_dev_deps
333
+
334
+ unless name == 'rjack-tarpit'
335
+ extra_dev_deps << [ 'rjack-tarpit', "~> #{ RJack::TarPit::VERSION }" ]
336
+ end
337
+ end
338
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ required_ruby_version: !ruby/object:Gem::Requirement
3
+ requirements:
4
+ - - '>='
5
+ - !ruby/object:Gem::Version
6
+ version: "0"
7
+ version:
8
+ email:
9
+ - dek-oss@gravitext.com
10
+ cert_chain: []
11
+
12
+ summary: TarPit provides the glue for an unholy union of build tools
13
+ post_install_message:
14
+ extra_rdoc_files:
15
+ - Manifest.txt
16
+ - README.rdoc
17
+ - History.rdoc
18
+ homepage: http://rjack.rubyforge.org
19
+ signing_key:
20
+ name: rjack-tarpit
21
+ rdoc_options:
22
+ - --main
23
+ - README.rdoc
24
+ rubyforge_project: rjack
25
+ autorequire:
26
+ licenses: []
27
+
28
+ executables: []
29
+
30
+ description: "TarPit provides the glue for an unholy union of build tools. Namely:\n\
31
+ \n* Rake[http://github.com/jimweirich/rake] with\n Hoe[http://seattlerb.rubyforge.org/hoe/] \
32
+ for gem publishing\n* Maven[http://maven.apache.org/] for Java builds with dependencies.\n\
33
+ \nIn particular, it runs \"mvn package\" when needed, links jars to the\ngem lib \
34
+ directory, and provides (semi-)automatic Manifest.txt\ngeneration with these jar \
35
+ files without offending Hoe.\n\n* The Maven pom.xml (and assembly.xml if needed) \
36
+ must be managed\n independently.\n* A Manifest.static file holds the static elements \
37
+ of the manifest."
38
+ specification_version: 3
39
+ default_executable:
40
+ files:
41
+ - Manifest.txt
42
+ - History.rdoc
43
+ - README.rdoc
44
+ - Rakefile
45
+ - lib/rjack-tarpit.rb
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - '>='
49
+ - !ruby/object:Gem::Version
50
+ version: "0"
51
+ version:
52
+ extensions: []
53
+
54
+ rubygems_version: 1.3.3
55
+ requirements: []
56
+
57
+ authors:
58
+ - David Kellum
59
+ date: 2009-10-10 07:00:00 +00:00
60
+ platform: ruby
61
+ test_files: []
62
+
63
+ version: !ruby/object:Gem::Version
64
+ version: 1.0.0
65
+ require_paths:
66
+ - lib
67
+ dependencies:
68
+ - !ruby/object:Gem::Dependency
69
+ version_requirements: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ~>
72
+ - !ruby/object:Gem::Version
73
+ version: 2.3.3
74
+ version:
75
+ type: :runtime
76
+ version_requirement:
77
+ name: hoe
78
+ - !ruby/object:Gem::Dependency
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ~>
82
+ - !ruby/object:Gem::Version
83
+ version: "2.4"
84
+ version:
85
+ type: :runtime
86
+ version_requirement:
87
+ name: rdoc
88
+ - !ruby/object:Gem::Dependency
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 1.0.3
94
+ version:
95
+ type: :runtime
96
+ version_requirement:
97
+ name: rubyforge
98
+ bindir: bin
99
+ has_rdoc: true