diff --git a/WHATSNEW b/WHATSNEW index c416a9e20..30df9545f 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -362,6 +362,9 @@ Fixed bugs: * FTP task, getTimeDiff method was returning wrong value. Bugzilla 30595. +* make sure that Zip and its derivates call the createEmptyZip method when + there are no resources to zip/jar/... + * Zip task was not zipping when only empty directories were found. Bugzilla 30365. diff --git a/src/main/org/apache/tools/ant/taskdefs/Zip.java b/src/main/org/apache/tools/ant/taskdefs/Zip.java index 4698b9a98..d333152b3 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Zip.java +++ b/src/main/org/apache/tools/ant/taskdefs/Zip.java @@ -474,6 +474,10 @@ public class Zip extends MatchingTask { return; } + if (!zipFile.exists() && state.isWithoutAnyResources()) { + createEmptyZip(zipFile); + return; + } Resource[][] addThem = state.getResourcesToAdd(); if (doUpdate) { @@ -1384,5 +1388,22 @@ public class Zip extends MatchingTask { public Resource[][] getResourcesToAdd() { return resourcesToAdd; } + /** + * find out if there are absolutely no resources to add + * @return true if there are no resources to add + */ + public boolean isWithoutAnyResources() { + if (resourcesToAdd == null) { + return true; + } + for (int counter = 0; counter < resourcesToAdd.length; counter++) { + if (resourcesToAdd[counter] != null) { + if (resourcesToAdd[counter].length > 0) { + return false; + } + } + } + return true; + } } } diff --git a/src/testcases/org/apache/tools/ant/taskdefs/JarTest.java b/src/testcases/org/apache/tools/ant/taskdefs/JarTest.java index 99c19f291..1a89321a7 100644 --- a/src/testcases/org/apache/tools/ant/taskdefs/JarTest.java +++ b/src/testcases/org/apache/tools/ant/taskdefs/JarTest.java @@ -258,7 +258,7 @@ public class JarTest extends BuildFileTest { } } public void testManifestOnlyJar() { - executeTarget("testManifestOnlyJar"); + expectLogContaining("testManifestOnlyJar", "Building MANIFEST-only jar: "); File manifestFile = getProject().resolveFile(tempDir + "META-INF" + File.separator + "MANIFEST.MF"); assertTrue(manifestFile.exists()); } diff --git a/src/testcases/org/apache/tools/ant/taskdefs/ZipTest.java b/src/testcases/org/apache/tools/ant/taskdefs/ZipTest.java index 9db2078dc..cf1923d5a 100644 --- a/src/testcases/org/apache/tools/ant/taskdefs/ZipTest.java +++ b/src/testcases/org/apache/tools/ant/taskdefs/ZipTest.java @@ -141,7 +141,7 @@ public class ZipTest extends BuildFileTest { getProject().resolveFile("test3.zip").exists()); } public void testZipEmptyCreate() { - executeTarget("zipEmptyCreate"); + expectLogContaining("zipEmptyCreate", "Note: creating empty"); assertTrue("archive should be created", getProject().resolveFile("test3.zip").exists()); }