Sha256: 958c1c0ac405af6f328494bf7bcc4622efa3c665ffba5c8aeaa91f3f07370897

Contents?: true

Size: 1.93 KB

Versions: 2

Compression:

Stored size: 1.93 KB

Contents

# encoding: UTF-8

require 'find'
require 'pathname'

module Gjp
  # runs programs from a gjp kit with gjp-specific options
  class KitRunner
    include Logger

    def initialize(project)      
      @project = project
    end

    # finds an executable in a bin/ subdirectory of kit
    def find_executable(name)
      @project.from_directory do
        Find.find("kit") do |path|
          if path =~ /bin\/#{name}$/
            log.debug("found #{name} executable: #{path}")
            return path
          end
        end
      end

      log.debug("#{name} executable not found")
      nil
    end

    # runs an external executable
    def run_executable(full_commandline)
      log.debug "running #{full_commandline}"
      Process.wait(Process.spawn(full_commandline))
    end

    # runs mvn in a subprocess
    def mvn(options)
      run_executable "#{get_maven_commandline(@project.full_path)} #{options.join(' ')}"
    end

    # returns a command line for running Maven from the specified
    # prefix
    def get_maven_commandline(prefix)
      executable = find_executable("mvn")

      if executable != nil
        mvn_path = File.join(prefix, executable)
        repo_path = File.join(prefix, "kit", "m2")
        config_path = File.join(prefix, "kit", "m2", "settings.xml")

        "#{mvn_path} -Dmaven.repo.local=#{repo_path} -s#{config_path}"
      else
        raise ExecutableNotFoundException
      end
    end

    # runs mvn in a subprocess
    def ant(options)
      run_executable "#{get_ant_commandline(@project.full_path)} #{options.join(' ')}"
    end

    # returns a command line for running Ant from the specified
    # prefix
    def get_ant_commandline(prefix)
      executable = find_executable("ant")

      if executable != nil
        ant_path = File.join(prefix, executable)

        "#{ant_path}"
      else
        raise ExecutableNotFoundException
      end
    end
  end

  class ExecutableNotFoundException < Exception
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
gjp-0.23.0 lib/gjp/kit_runner.rb
gjp-0.22.0 lib/gjp/kit_runner.rb