def use(*specs)
named = specs.flatten.inject({}) do |seen, spec|
if Hash === spec && (spec.keys & ActsAsArtifact::ARTIFACT_ATTRIBUTES).empty?
spec.each_pair do |name, spec|
if ArtifactNamespace === spec
raise ArgumentError.new("Circular reference") if self == spec
registry[name.to_sym] = spec
elsif Numeric === spec || (String === spec && VersionRequirement.version?(spec))
artifact = ArtifactRequirement.allocate
artifact.name = name
artifact.version = spec.to_s
seen[artifact.name] ||= artifact
elsif Symbol === spec
self.alias name, spec
elsif Array === spec
seen[name] ||= spec.map { |s| ArtifactRequirement.new(s) }
else
artifact = ArtifactRequirement.new(spec)
artifact.name = name
seen[artifact.name] ||= artifact
end
end
else
if Symbol === spec
artifact = get(spec).dclone
else
artifact = ArtifactRequirement.new(spec)
end
seen[artifact.name] ||= artifact
end
seen
end
named.each_pair do |name, artifact|
is_group = Array === artifact
artifact = [artifact].flatten.map do |artifact|
unvers = artifact.unversioned_spec
previous = get(unvers, false) || get(name, false)
if previous
if previous.requirement
unless unvers
satisfied = previous.requirement.satisfied_by?(artifact.version)
else
satisfied = previous.satisfied_by?(artifact)
end
raise "Unsatisfied dependency #{previous} " +
"not satisfied by #{artifact}" unless satisfied
previous.version = artifact.version
artifact = previous
else
unless artifact.id == previous.id && name != previous.name
previous.copy_attrs(artifact)
artifact = previous
end
end
else
if unvers.nil? &&
(previous = get(unvers, true, false, false))
version = artifact.version
artifact.copy_attrs(previous)
artifact.version = version
end
artifact.requirement = nil
end
artifact.selected!
end
artifact = artifact.first unless is_group
if is_group
names = artifact.map do |art|
unv = art.unversioned_spec
registry[unv] = art
unv
end
group(name, *(names + [{:namespace => self}]))
elsif artifact.id
unvers = artifact.unversioned_spec
registry[name] = artifact
registry.alias unvers, name
else
registry[name] = artifact
end
end
self
end