def to_hash(spec)
if spec.respond_to?(:to_spec)
to_hash spec.to_spec
elsif Hash === spec
rake_check_options spec, :id, :group, :type, :classifier, :version
spec = ARTIFACT_ATTRIBUTES.inject({}) { |h, k| h[k] = spec[k].to_s if spec[k] ; h }
fail "Missing group identifier for #{spec.inspect}" unless spec[:group]
fail "Missing artifact identifier for #{spec.inspect}" unless spec[:id]
fail "Missing version for #{spec.inspect}" unless spec[:version]
spec[:type] = (spec[:type] || DEFAULT_TYPE).to_sym
spec
elsif String === spec
group, id, type, version, *rest = spec.split(':').map { |part| part.empty? ? nil : part }
unless rest.empty?
classifier, version = version, rest.shift
fail "Expecting <group:id:type:version> or <group:id:type:classifier:version>, found <#{spec}>" unless rest.empty?
end
to_hash :group=>group, :id=>id, :type=>type, :version=>version, :classifier=>classifier
else
fail 'Expecting a String, Hash or object that responds to to_spec'
end
end