lib/kpm/base_artifact.rb in kpm-0.5.3 vs lib/kpm/base_artifact.rb in kpm-0.6.0
- old
+ new
@@ -1,7 +1,6 @@
require 'digest/sha1'
-require 'nexus_cli'
require 'rexml/document'
module KPM
class ArtifactCorruptedException < IOError
@@ -42,12 +41,12 @@
def pull_from_fs(logger, file_path, destination_path=nil)
pull_from_fs_and_put_in_place(logger, file_path, destination_path)
end
- def nexus_remote(overrides={}, ssl_verify=true)
- nexus_remote ||= NexusCli::RemoteFactory.create(nexus_defaults.merge(overrides || {}), ssl_verify)
+ def nexus_remote(overrides={}, ssl_verify=true, logger=nil)
+ nexus_remote ||= KPM::NexusFacade::RemoteFactory.create(nexus_defaults.merge(overrides || {}), ssl_verify, logger)
end
def nexus_defaults
{
url: 'https://oss.sonatype.org',
@@ -100,10 +99,11 @@
# Download the artifact in a temporary directory in case of failures
Dir.mktmpdir do |tmp_destination_dir|
logger.info " Starting download of #{coordinates} to #{tmp_destination_dir}"
downloaded_artifact_info = pull_and_verify(logger, artifact_info[:sha1], coordinates, tmp_destination_dir, sha1_file, verify_sha1, overrides, ssl_verify)
+ remove_old_default_bundles(coordinate_map,artifact_info,downloaded_artifact_info)
if artifact_info[:is_tgz]
artifact_info[:bundle_dir] = Utils.unpack_tgz(downloaded_artifact_info[:file_path], artifact_info[:dir_name], skip_top_dir)
FileUtils.rm downloaded_artifact_info[:file_path]
else
FileUtils.mv downloaded_artifact_info[:file_path], artifact_info[:file_path]
@@ -170,14 +170,14 @@
:skipped => false
}
coordinates = KPM::Coordinates.build_coordinates(coordinate_map)
begin
- nexus_info = nexus_remote(overrides, ssl_verify).get_artifact_info(coordinates)
- rescue NexusCli::ArtifactMalformedException => e
- raise NexusCli::NexusCliError.new("Invalid coordinates #{coordinate_map}")
- rescue NexusCli::NexusCliError => e
+ nexus_info = nexus_remote(overrides, ssl_verify, logger).get_artifact_info(coordinates)
+ rescue KPM::NexusFacade::ArtifactMalformedException => e
+ raise StandardError.new("Invalid coordinates #{coordinate_map}")
+ rescue StandardError => e
logger.warn("Unable to retrieve coordinates #{coordinate_map}")
raise e
end
xml = REXML::Document.new(nexus_info)
@@ -217,11 +217,11 @@
destination_path
end
def pull_and_verify(logger, remote_sha1, coordinates, destination_dir, sha1_file, verify_sha1, overrides={}, ssl_verify=true)
- info = nexus_remote(overrides, ssl_verify).pull_artifact(coordinates, destination_dir)
+ info = nexus_remote(overrides, ssl_verify, logger).pull_artifact(coordinates, destination_dir)
# Always verify sha1 and if incorrect either throw or log when we are asked to bypass sha1 verification
verified = verify(logger, coordinates, info[:file_path], remote_sha1)
if !verified
raise ArtifactCorruptedException if verify_sha1
@@ -271,9 +271,25 @@
return false if last_part == classic_filename
end
# Probably a directory
true
+ end
+
+ def remove_old_default_bundles(coordinate_map, artifact_info, downloaded_artifact_info)
+ return unless coordinate_map[:artifact_id] == 'killbill-platform-osgi-bundles-defaultbundles'
+
+ downloaded_default_bundles = Utils.peek_tgz_file_names(downloaded_artifact_info[:file_path])
+ existing_default_bundles = Dir.glob("#{artifact_info[:dir_name]}/*")
+
+ existing_default_bundles.each do |bundle|
+ bundle_name = Utils.get_plugin_name_from_file_path(bundle)
+ is_downloaded = downloaded_default_bundles.index {|file_name| file_name.include? bundle_name}
+ unless is_downloaded.nil?
+ FileUtils.remove(bundle)
+ end
+ end
+
end
end
end
end