From ebb88231f802918096159da453bed2c4839e6042 Mon Sep 17 00:00:00 2001 From: Robert Kanter Date: Fri, 28 Oct 2016 17:35:28 -0700 Subject: [PATCH] HADOOP-10075. addendum to fix compilation on Windows --- .../plugin/resourcegz/ResourceGzMojo.java | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/hadoop-maven-plugins/src/main/java/org/apache/hadoop/maven/plugin/resourcegz/ResourceGzMojo.java b/hadoop-maven-plugins/src/main/java/org/apache/hadoop/maven/plugin/resourcegz/ResourceGzMojo.java index 5c9e26e6ba..e7ab663e42 100644 --- a/hadoop-maven-plugins/src/main/java/org/apache/hadoop/maven/plugin/resourcegz/ResourceGzMojo.java +++ b/hadoop-maven-plugins/src/main/java/org/apache/hadoop/maven/plugin/resourcegz/ResourceGzMojo.java @@ -24,10 +24,12 @@ import java.io.BufferedReader; import java.io.File; import java.io.FileOutputStream; +import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.util.List; import java.util.function.Consumer; +import java.util.regex.Matcher; import java.util.zip.GZIPOutputStream; /** @@ -101,17 +103,21 @@ public void accept(Path path) { } try { File outFile = new File(outputDir, path.toFile().getCanonicalPath() - .replaceFirst(inputDir.getCanonicalPath(), "") + ".gz"); - outFile.getParentFile().mkdirs(); - try ( - GZIPOutputStream os = new GZIPOutputStream( - new FileOutputStream(outFile)); - BufferedReader is = Files.newBufferedReader(path) - ) { - getLog().info("Compressing " + path + " to " + outFile); - IOUtils.copy(is, os); - } catch (Throwable t) { - this.throwable = t; + .replaceFirst(Matcher.quoteReplacement( + inputDir.getCanonicalPath()), "") + ".gz"); + if (outFile.getParentFile().isDirectory() || + outFile.getParentFile().mkdirs()) { + try ( + GZIPOutputStream os = new GZIPOutputStream( + new FileOutputStream(outFile)); + BufferedReader is = Files.newBufferedReader(path) + ) { + getLog().info("Compressing " + path + " to " + outFile); + IOUtils.copy(is, os); + } + } else { + throw new IOException("Directory " + outFile.getParent() + + " does not exist or was unable to be created"); } } catch (Throwable t) { this.throwable = t;