public
Created

Buildr uberjar example concatenting spring meta data

  • Download Gist
gistfile1.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
assembly_dir = 'target/assembly'
main_class = 'com.something.something.Blah'
 
artifacts.each do |artifact|
Unzip.new( _(assembly_dir) => artifact ).extract
# Create a concatenation of all the spring.schemas for each spring jars
if File.exist?( "#{_(assembly_dir)}/META-INF/spring.schemas" )
new_schema = IO.read("#{_(assembly_dir)}/META-INF/spring.schemas")
File.open( "#{_(assembly_dir)}/META-INF/master_spring.schemas", 'a') do |f|
f.write( new_schema )
f.write("\n")
end
# remove jar's spring.schema
FileUtils.rm( "#{_(assembly_dir)}/META-INF/spring.schemas" )
end
# Create a concatenation of all the spring.handlers for each spring jars
if File.exist?( "#{_(assembly_dir)}/META-INF/spring.handlers" )
new_handler = IO.read("#{_(assembly_dir)}/META-INF/spring.handlers")
master_handler = File.open( "#{_(assembly_dir)}/META-INF/master_spring.handlers", 'a') do |f|
f.write( new_handler )
f.write("\n")
end
# remove jar's spring.handlers
FileUtils.rm( "#{_(assembly_dir)}/META-INF/spring.handlers" )
end
# Create a concatenation of all the spring.tooling for each spring jars
if File.exist?( "#{_(assembly_dir)}/META-INF/spring.tooling" )
new_handler = IO.read("#{_(assembly_dir)}/META-INF/spring.tooling")
master_handler = File.open( "#{_(assembly_dir)}/META-INF/master_spring.tooling", 'a') do |f|
f.write( new_handler )
f.write("\n")
end
# remove jar's spring.handlers
FileUtils.rm( "#{_(assembly_dir)}/META-INF/spring.tooling" )
end
end
 
FileUtils.mv( "#{_(assembly_dir)}/META-INF/master_spring.schemas", "#{_(assembly_dir)}/META-INF/spring.schemas" )
FileUtils.mv( "#{_(assembly_dir)}/META-INF/master_spring.handlers", "#{_(assembly_dir)}/META-INF/spring.handlers" )
FileUtils.mv( "#{_(assembly_dir)}/META-INF/master_spring.tooling", "#{_(assembly_dir)}/META-INF/spring.tooling" )
# remove dirs from assembly that should not be in uberjar
FileUtils.rm_rf( "#{_(assembly_dir)}/example/package" )
FileUtils.rm_rf( "#{_(assembly_dir)}/example/dir" )
 
# create manifest file
File.open( _("#{assembly_dir}/META-INF/MANIFEST.MF"), 'w') do |f|
f.write("Implementation-Title: Uberjar Exampleh\n")
f.write("Implementation-Version: #{project_version}\n")
f.write("Main-Class: #{main_class}\n")
f.write("Created-By: Buildr\n")
end
 
present_dir = Dir.pwd
Dir.chdir _(assembly_dir)
puts "Creating #{_("target/#{project.name}-#{project.version}.jar")}"
`jar -cfm #{_("target/#{project.name}-#{project.version}.jar")} #{_(assembly_dir)}/META-INF/MANIFEST.MF .`
Dir.chdir present_dir

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.