String attkey = IdentityNamespace.CAPABILITY_MAVEN_IDENTITY_ATTRIBUTE;
String attval = (String) icap.getAttributes().get(attkey);
if (attval != null && !attval.equals(mavenid.toExternalForm()))
throw new IllegalArgumentException("Resource already contains a " + attkey + " attribute: " + attval);
ResourceBuilder builder = new DefaultResourceBuilder();
for (Capability aux : res.getCapabilities(null)) {
Capability cap = builder.addCapability(aux.getNamespace(), aux.getAttributes(), aux.getDirectives());
if (IdentityNamespace.IDENTITY_NAMESPACE.equals(cap.getNamespace())) {
cap.getAttributes().put(attkey, mavenid.toExternalForm());
}
}
for (Requirement aux : res.getRequirements(null)) {
builder.addRequirement(aux.getNamespace(), aux.getAttributes(), aux.getDirectives());
}
Resource rescopy = builder.getResource();
return getRequiredRepositoryStorage().addResource(rescopy);
}