lib/kpm/base_artifact.rb in kpm-0.1.3 vs lib/kpm/base_artifact.rb in kpm-0.1.4

- old
+ new

@@ -34,12 +34,12 @@ KAUI_PACKAGING = 'war' 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) - coordinates = build_coordinates(group_id, artifact_id, packaging, classifier, version) - pull_and_put_in_place(logger, coordinates, destination_path, is_ruby_plugin_and_should_skip_top_dir(group_id, artifact_id), sha1_file, force_download, verify_sha1, overrides, ssl_verify) + 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) 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,23 +55,45 @@ } end protected - def pull_and_put_in_place(logger, coordinates, 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, 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(coordinates, overrides, ssl_verify) - + artifact_info = artifact_info(coordinate_map, overrides, ssl_verify) 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) + # Return early if there's nothing to do if !force_download && skip_if_exists(artifact_info, coordinates, sha1_file) 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] + 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) + 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 + end + else + artifact_info[:bundle_dir] = artifact_info[:dir_name] + end + artifact_info[:skipped] = true return artifact_info end + + # Create the destination directory FileUtils.mkdir_p(artifact_info[:dir_name]) # Download the artifact in a temporary directory in case of failures Dir.mktmpdir do |tmp_destination_dir| @@ -136,15 +158,16 @@ # 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(coordinates, overrides={}, ssl_verify=true) + def artifact_info(coordinate_map, overrides={}, ssl_verify=true) info = { :skipped => false } + coordinates = build_coordinates(coordinate_map) nexus_info = nexus_remote(overrides, ssl_verify).get_artifact_info(coordinates) xml = REXML::Document.new(nexus_info) info[:sha1] = xml.elements['//sha1'].text unless xml.elements['//sha1'].nil? info[:version] = xml.elements['//version'].text unless xml.elements['//version'].nil? @@ -214,10 +237,17 @@ logger.warn("Sha1 verification failed for #{coordinates} : local_sha1 = #{local_sha1}, remote_sha1 = #{remote_sha1}") end res end - def build_coordinates(group_id, artifact_id, packaging, classifier, version=nil) + def build_coordinates(coordinate_map) + + group_id = coordinate_map[:group_id] + artifact_id = coordinate_map[:artifact_id] + packaging = coordinate_map[:packaging] + classifier = coordinate_map[:classifier] + version = coordinate_map[:version] + if classifier.nil? if version.nil? "#{group_id}:#{artifact_id}:#{packaging}" else "#{group_id}:#{artifact_id}:#{packaging}:#{version}"