class Maestro::Plugin::RakeTasks::PackageTask

Attributes

dest_dir[RW]

The destination directory default:

.
directories[RW]

List the directories to package default:

[ 'src', 'vendor', 'images' ]
files[RW]

List the files to package default:

[ 'manifest.json', 'README.md', 'LICENSE' ]
manifest_template_path[RW]

The path to the manifest template default:

'./manifest.template.json'
name[RW]

Name of task.

default:

:package
plugin_name[RW]

The plugin name default read from pom.xml (artifactId)

pom_path[RW]

The path to the pom.xml default:

'./pom.xml'
use_pom[RW]

Tells the task to read version and plugin name from a pom.xml file default:

true
verbose[RW]

Use verbose output. If this is set to true, the task will print the progress output to stdout.

default:

true
version[RW]

The plugin version default read from pom.xml (version)

Public Class Methods

new(*args, &task_block) click to toggle source
# File lib/maestro/plugin/rake_tasks/package_task.rb, line 67
def initialize(*args, &task_block)
  setup_ivars(args)

  desc "Package a Maestro Ruby plugin into a Zip file" unless ::Rake.application.last_comment

  task name, *args do |_, task_args|
    RakeFileUtils.send(:verbose, verbose) do
      task_block.call(*[self, task_args].slice(0, task_block.arity)) if task_block
      run_task verbose
    end
  end
end

Public Instance Methods

run_task(verbose) click to toggle source
# File lib/maestro/plugin/rake_tasks/package_task.rb, line 91
def run_task(verbose)
  parse_pom if @use_pom

  # Make sure we have a valid name and version
  abort "ERROR: Plugin name is missing" unless @plugin_name
  abort "ERROR: Plugin version is missing" unless @version

  # If we use a template, use it to create the manifest
  update_manifest(git_version)

  # Create the zip file
  create_zip_file("#{@plugin_name}-#{@version}.zip")

end
setup_ivars(args) click to toggle source
# File lib/maestro/plugin/rake_tasks/package_task.rb, line 80
def setup_ivars(args)
  @name = args.shift || :package
  @verbose, @use_pom = true, true
  @directories = [ 'src', 'vendor', 'images' ]
  @files = [ 'manifest.json', 'README.md', 'LICENSE' ]
  @version, @plugin_name = nil, nil
  @dest_dir = '.'
  @pom_path = './pom.xml'
  @manifest_template_path = './manifest.template.json'
end

Private Instance Methods

add_dir( zipfile, d ) click to toggle source

add a directory to the zip file

# File lib/maestro/plugin/rake_tasks/package_task.rb, line 160
def add_dir( zipfile, d )
  FileList.new("#{d}/**/*").each { |f| add_file(zipfile, f) if File.file?(f) }
end
add_file( zipfile, f ) click to toggle source

add a file to the zip file

# File lib/maestro/plugin/rake_tasks/package_task.rb, line 150
def add_file( zipfile, f )
  if File.exists?(f)
    puts "Writing #{f} at #{@dest_dir}" if verbose
    zipfile.add(f, "#{@dest_dir}/#{f}")
  else
    puts "Ignoring missing file #{f} at #{@dest_dir}"
  end
end
create_zip_file(zip_file) click to toggle source
# File lib/maestro/plugin/rake_tasks/package_task.rb, line 142
def create_zip_file(zip_file)
  Zip::File.open(zip_file, Zip::File::CREATE) do |z|
    @directories.each { |dir| add_dir z, dir }
    @files.each { |file| add_file z, file }
  end
end
git_version() click to toggle source
# File lib/maestro/plugin/rake_tasks/package_task.rb, line 114
def git_version
  return @version unless Dir.exists?(".git")
  git = Git.open('.')
  # check if there are modified files
  if git.status.select { |s| s.type == 'M' }.empty?
    commit = git.log.first.sha[0..5]
    "#{@version}-#{commit}"
  else
    warn "WARNING: There are modified files, not using commit hash in version"
    @version
  end
end
parse_pom() click to toggle source
# File lib/maestro/plugin/rake_tasks/package_task.rb, line 108
def parse_pom
  pom = Pom.new(@pom_path)
  @plugin_name ||= pom.artifact_id
  @version ||= pom.version
end
update_manifest(manifest_version) click to toggle source

update the version number in the manifest file.

# File lib/maestro/plugin/rake_tasks/package_task.rb, line 128
def update_manifest(manifest_version)
  manifest = JSON.parse(IO.read(@manifest_template_path))
  if manifest.instance_of? Array
    manifest.each { |m| m['version'] = manifest_version }
  else
    manifest['version'] = manifest_version
    if !manifest['tasks'].nil? and manifest['tasks'].instance_of? Array
      manifest['tasks'].each { |m| m['version'] = manifest_version }
    end
  end

  File.open('manifest.json','w'){ |f| f.write(JSON.pretty_generate(manifest)) }
end