lib/kpm/base_artifact.rb in kpm-0.1.7 vs lib/kpm/base_artifact.rb in kpm-0.2.0

- old
+ new

@@ -35,11 +35,11 @@ KAUI_CLASSIFIER = nil class << self def pull(logger, group_id, artifact_id, packaging='jar', classifier=nil, version='LATEST', destination_path=nil, sha1_file=nil, force_download=false, verify_sha1=true, overrides={}, ssl_verify=true) coordinate_map = {:group_id => group_id, :artifact_id => artifact_id, :packaging => packaging, :classifier => classifier, :version => version} - pull_and_put_in_place(logger, coordinate_map, destination_path, is_ruby_plugin_and_should_skip_top_dir(group_id, artifact_id), sha1_file, force_download, verify_sha1, overrides, ssl_verify) + pull_and_put_in_place(logger, coordinate_map, nil, destination_path, false, sha1_file, force_download, verify_sha1, overrides, ssl_verify) end def pull_from_fs(logger, file_path, destination_path=nil) pull_from_fs_and_put_in_place(logger, file_path, destination_path) end @@ -55,13 +55,14 @@ } end protected - def pull_and_put_in_place(logger, coordinate_map, destination_path=nil, skip_top_dir=true, sha1_file=nil, force_download=false, verify_sha1=true, overrides={}, ssl_verify=true) + def pull_and_put_in_place(logger, coordinate_map, plugin_name, destination_path=nil, skip_top_dir=true, sha1_file=nil, force_download=false, verify_sha1=true, overrides={}, ssl_verify=true) # Build artifact info artifact_info = artifact_info(logger, coordinate_map, overrides, ssl_verify) + artifact_info[:plugin_name] = plugin_name populate_fs_info(artifact_info, destination_path) # Update with resolved version in case 'LATEST' was passed coordinate_map[:version] = artifact_info[:version] coordinates = build_coordinates(coordinate_map) @@ -71,13 +72,16 @@ logger.info " Skipping installation of #{coordinates} to #{artifact_info[:file_path]}, file already exists" # We need to do a bit of magic to make sure that artifact_info[:bundle_dir] is correctly populated when we bail early if artifact_info[:is_tgz] && coordinate_map[:artifact_id] != 'killbill-platform-osgi-bundles-defaultbundles' plugin_dir = File.split(artifact_info[:dir_name])[0] - plugins_manager = PluginsManager.new(plugin_dir, logger) - artifact_id = coordinates.split(':')[1] - plugin_name = plugins_manager.guess_plugin_name(artifact_id) + plugin_name = artifact_info[:plugin_name] + unless plugin_name + plugins_manager = PluginsManager.new(plugin_dir, logger) + artifact_id = coordinates.split(':')[1] + plugin_name = plugins_manager.guess_plugin_name(artifact_id) + end if plugin_name.nil? logger.warn("Failed to guess plugin_name for #{coordinates}: artifact_info[:bundle_dir] will not be populated correctly") else version = artifact_info[:version] artifact_info[:bundle_dir] = Pathname.new(artifact_info[:dir_name]).join(plugin_name).join(version).to_s @@ -137,26 +141,38 @@ def skip_if_exists(artifact_info, coordinates, sha1_file) # Unclear if this is even possible return false if artifact_info[:sha1].nil? + # If tgz artifact, check if expected exploded folder exists + if artifact_info[:is_tgz] + artifact_path = Pathname.new(artifact_info[:file_path]) + if artifact_info[:plugin_name] + artifact_path = artifact_path.join(artifact_info[:plugin_name]).join(artifact_info[:version]) + end + return false if !artifact_path.exist? + # Else, exit early if file_path does not exist or is a directory + elsif !File.exists?(artifact_info[:file_path]) || + File.directory?(artifact_info[:file_path]) + return false + end + # Check entry in sha1_file if exists if sha1_file && File.exists?(sha1_file) sha1_checker = Sha1Checker.from_file(sha1_file) local_sha1 = sha1_checker.sha1(coordinates) return true if local_sha1 == artifact_info[:sha1] end - # If not using sha1_file mechanism, exit early if file_path does not exist or is a directory - if !File.exists?(artifact_info[:file_path]) || - File.directory?(artifact_info[:file_path]) - return false + if artifact_info[:is_tgz] + # tgz artifact seems to be installed, but is not in the sha1 file, so do not skip it + false + else + # Finally check if remote_sha1 matches what we have locally + local_sha1 = Digest::SHA1.file(artifact_info[:file_path]).hexdigest + local_sha1 == artifact_info[:sha1] end - - # Finally check if remote_sha1 matches what we have locally - local_sha1 = Digest::SHA1.file(artifact_info[:file_path]).hexdigest - local_sha1 == artifact_info[:sha1] end def artifact_info(logger, coordinate_map, overrides={}, ssl_verify=true) info = { :skipped => false @@ -261,14 +277,9 @@ end end end # Magic methods... - - def is_ruby_plugin_and_should_skip_top_dir(group_id, artifact_id) - # The second check is for custom ruby plugins - group_id == KILLBILL_RUBY_PLUGIN_GROUP_ID || artifact_id.include?('plugin') - end def path_looks_like_a_directory(path) # It already is! return true if File.directory?(path) # It already isn't!