# Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with this # work for additional information regarding copyright ownership. The ASF # licenses this file to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations under # the License. module BuildrDeb class DebTask < Buildr::ArchiveTask attr_accessor :control, :prerm, :postinst, :postrm, :preinst, :version # The ArchiveTask class delegates this method # so we can create the archive. # the file_map is the result of the computations of the include and exclude filters. # # With deb we recreate the structure asked by the user # then we will call dpkg --build over it. def create_from(file_map) root = File.join("target", "_#{File.basename(name)}") mkpath File.join(root, "DEBIAN") #echo "THe version " + @version for file in ["control", "prerm", "postinst", "postrm", "preinst"] thefile = eval("self."+file) targetFile = File.join(root, "DEBIAN", file) if !thefile.nil? and File.exists? thefile actualFile = File.open(thefile, "r") myfile = File.open( targetFile, "w") actualFile.each { |line| if file == "control" then if line.match /^Version: / and !@version.nil? then myfile.puts("Version: " + @version +"\n") else myfile.puts eval('"'+ line + '"') end else myfile.puts line end } myfile.close actualFile.close File.chmod 0755, targetFile #cp send(file.to_sym), File.join(root, "DEBIAN", file) #File.chmod 0755, File.join(root, "DEBIAN", file) end end file_map.each do |path, content| _path = File.join(root, path) if content.respond_to?(:call) raise "Not implemented" content.call path elsif content.nil? || File.directory?(content.to_s) mkpath _path else mkpath File.dirname(_path) cp content.to_s, _path end end out = %x[ dpkg --build \"#{root}\" \"#{name}\" 2>&1 ] raise "dpkg failed with this error:\n#{out}" if $? != 0 end end module ActAsDebPackager include Extension def package_as_deb(file_name) deb = DebTask.define_task(file_name) deb.tap do package ||= project.id version ||= project.version end deb.enhance do |task| raise "no control file was defined when packaging #{project.id} as a deb file" if task.control.nil? end return deb end end end module Buildr class Project include BuildrDeb::ActAsDebPackager end end