From f2d99c202b5aaa3f387784d14d9882ea6e4d3d41 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Wed, 26 Aug 2009 11:03:10 +0000 Subject: [PATCH] create parent directory of archive in and if needed. PR 45377. Based on patch by Remie Bolte git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@807960 13f79535-47bb-0310-9956-ffa450edef68 --- CONTRIBUTORS | 1 + WHATSNEW | 4 ++++ contributors.xml | 4 ++++ src/main/org/apache/tools/ant/taskdefs/Tar.java | 6 ++++++ src/main/org/apache/tools/ant/taskdefs/Zip.java | 7 +++++++ 5 files changed, 22 insertions(+) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 09573efd7..af4f861d0 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -252,6 +252,7 @@ Rami Ojares Randy Watler Raphael Pierquin Ray Waldin +Remie Bolte Richard Evans Rick Beton Robert Anderson diff --git a/WHATSNEW b/WHATSNEW index 28db72a99..efaec479d 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -919,6 +919,10 @@ Other changes: HTTP connections at the HttpUrlConnection level. Bugzilla Report 41891. + * and (and tasks derived from ) will now create the + parent directory of the destination archive if it doesn't exist. + Bugzilla Report 45377. + Changes from Ant 1.7.0 TO Ant 1.7.1 ============================================= diff --git a/contributors.xml b/contributors.xml index 30e33ab67..8787c9109 100644 --- a/contributors.xml +++ b/contributors.xml @@ -1030,6 +1030,10 @@ Ray Waldin + + Remie + Bolte + Richard Evans diff --git a/src/main/org/apache/tools/ant/taskdefs/Tar.java b/src/main/org/apache/tools/ant/taskdefs/Tar.java index 31bea1329..2e89c4d19 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Tar.java +++ b/src/main/org/apache/tools/ant/taskdefs/Tar.java @@ -279,6 +279,12 @@ public class Tar extends MatchingTask { return; } + File parent = tarFile.getParentFile(); + if (parent != null && !parent.isDirectory() && !parent.mkdirs()) { + throw new BuildException("Failed to create missing parent" + + " directory for " + tarFile); + } + log("Building tar: " + tarFile.getAbsolutePath(), Project.MSG_INFO); TarOutputStream tOut = null; diff --git a/src/main/org/apache/tools/ant/taskdefs/Zip.java b/src/main/org/apache/tools/ant/taskdefs/Zip.java index c82319dbe..b49ffe28f 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Zip.java +++ b/src/main/org/apache/tools/ant/taskdefs/Zip.java @@ -618,6 +618,13 @@ public class Zip extends MatchingTask { if (!state.isOutOfDate()) { return; } + + File parent = zipFile.getParentFile(); + if (parent != null && !parent.isDirectory() && !parent.mkdirs()) { + throw new BuildException("Failed to create missing parent" + + " directory for " + zipFile); + } + updatedFile = true; if (!zipFile.exists() && state.isWithoutAnyResources()) { createEmptyZip(zipFile);