lib/gjp/project.rb in gjp-0.38.0 vs lib/gjp/project.rb in gjp-0.39.0

- old
+ new

@@ -1,9 +1,7 @@ # encoding: UTF-8 -require "find" - module Gjp # encapsulates a Gjp project directory class Project include Logging @@ -24,21 +22,21 @@ end # finds the project directory up in the tree, like git does def self.find_project_dir(starting_dir) result = starting_dir - while is_project(result) == false && result != "/" + while project?(result) == false && result != "/" result = File.expand_path("..", result) end - raise NoProjectDirectoryError.new(starting_dir) if result == "/" + fail NoProjectDirectoryError, starting_dir if result == "/" result end # returns true if the specified directory is a valid gjp project - def self.is_project(dir) + def self.project?(dir) File.directory?(File.join(dir, "src")) && File.directory?(File.join(dir, "kit")) && File.directory?(File.join(dir, ".git")) end @@ -46,18 +44,18 @@ # raises NoPackageDirectoryError if dir is not a (sub)directory of a package def get_package_name(dir) dir_path = Pathname.new(File.expand_path(dir)).relative_path_from(Pathname.new(@full_path)) components = dir_path.to_s.split(File::SEPARATOR) if components.count >= 2 && - components.first == "src" && - Dir.exist?(File.join(@full_path, components[0], components[1])) + components.first == "src" && + Dir.exist?(File.join(@full_path, components[0], components[1])) components[1] - else - raise NoPackageDirectoryError - end + else + fail NoPackageDirectoryError + end rescue ArgumentError, NoProjectDirectoryError - raise NoPackageDirectoryError.new(dir) + raise NoPackageDirectoryError, dir end # inits a new project directory structure def self.init(dir) Dir.chdir(dir) do @@ -81,30 +79,28 @@ # starts a dry running phase: files added to kit/ will be added # to the kit package, src/ will be reset at the current state # when finished def dry_run - if is_dry_running - return false - end + return false if dry_running? current_directory = Pathname.new(Dir.pwd).relative_path_from Pathname.new(@full_path) take_snapshot("Dry-run started", :dry_run_started, current_directory) true end # returns true iff we are currently dry-running - def is_dry_running + def dry_running? latest_tag_count(:dry_run_started) > latest_tag_count(:dry_run_finished) end # ends a dry-run. # if abort is true, reverts the whole directory # if abort is false, reverts sources and updates output file lists def finish(abort) - if is_dry_running + if dry_running? if abort @git.revert_whole_directory(".", latest_tag(:dry_run_started)) @git.delete_tag(latest_tag(:dry_run_started)) else take_snapshot "Changes during dry-run", :dry_run_changed @@ -209,34 +205,37 @@ # moves any .jar from src/ to kit/ and links it back def purge_jars from_directory do result = [] Find.find("src") do |file| - if file =~ /.jar$/ && !File.symlink?(file) - new_location = File.join("kit", "jars", Pathname.new(file).split[1]) - FileUtils.mv(file, new_location) + next unless file =~ /.jar$/ && !File.symlink?(file) - link_target = Pathname.new(new_location) - .relative_path_from(Pathname.new(file).split.first) - .to_s + new_location = File.join("kit", "jars", Pathname.new(file).split[1]) + FileUtils.mv(file, new_location) - File.symlink(link_target, file) - result << [file, new_location] - end + link_target = Pathname.new(new_location) + .relative_path_from(Pathname.new(file).split.first) + .to_s + + File.symlink(link_target, file) + result << [file, new_location] end result end end end + # current directory is not a gjp project class NoProjectDirectoryError < StandardError attr_reader :directory def initialize(directory) @directory = directory end end + + # current directory is not a gjp package directory class NoPackageDirectoryError < StandardError attr_reader :directory def initialize(directory) @directory = directory