@SuppressWarnings({ "unchecked", "rawtypes" })
public int copyResource(Map flags2, String resource, String target) {
Map flags = Maps.newLinkedHashMap();
if (!flags2.containsKey(IGNORE_ENTITY_SSH_FLAGS))
flags.putAll(getSshFlags());
flags.putAll(flags2);
String dest = target;
if (!new File(target).isAbsolute()) {
dest = getRunDir() + "/" + target;
}
int result = -1;
if (resource.toLowerCase().matches("^https?://.*")) {
result = getMachine().execCommands(flags, "download-resource",
ImmutableList.of(
BashCommands.INSTALL_CURL,
String.format("curl -f --silent --insecure %s -o %s", resource, dest)));
}
if (result != 0) {
result = getMachine().copyTo(flags, getResource(resource), dest);
}
if (log.isDebugEnabled())
log.debug("Copied file for {}: {} to {} - result {}", new Object[] { entity, resource, dest, result });
return result;
}