public static void downloadFile()

in taverna-maven-plugin/src/main/java/org/apache/taverna/mavenplugin/Utils.java [76:103]


	public static void downloadFile(String resourceName, File file, Wagon wagon, Log log)
			throws MojoExecutionException, ResourceDoesNotExistException {
		String resourceUrl = getResourceUrl(wagon, resourceName);
		File digestFile = new File(file.getPath() + ".md5");
		try {
			log.info(String.format("Downloading %1$s to %2$s", resourceUrl, file));
			wagon.get(resourceName, file);
			wagon.get(resourceName + ".md5", digestFile);
		} catch (TransferFailedException e) {
			throw new MojoExecutionException(String.format("Error transferring %1$s to %2$s",
					resourceUrl, file), e);
		} catch (AuthorizationException e) {
			throw new MojoExecutionException(String.format(
					"Authentication error transferring %1$s to %2$s", resourceUrl, file), e);
		}
		try {
			String digestString1 = DigestUtils.md5Hex(new FileInputStream(file));
			String digestString2 = FileUtils.readFileToString(digestFile);
			if (!digestString1.equals(digestString2)) {
				throw new MojoExecutionException(String.format(
						"Error downloading file: digsests not equal. (%1$s != %2$s)",
						digestString1, digestString2));
			}
		} catch (IOException e) {
			throw new MojoExecutionException(String.format("Error checking digest for %1$s", file),
					e);
		}
	}