From 28c651a95ac66940b0ea3830b955c012ea41ad66 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Tue, 4 Oct 2011 14:54:11 +0000 Subject: [PATCH] Empty package-info.class is created in wrong directory if no destdir is specified. PR 51947 git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1178820 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 7 +++++ .../org/apache/tools/ant/taskdefs/Javac.java | 9 ++++-- src/tests/antunit/taskdefs/javac-test.xml | 30 ++++++++++++++++++- 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/WHATSNEW b/WHATSNEW index 3e759b7bd..218cbd2d7 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -91,6 +91,13 @@ Fixed bugs: given file is not a ZIP archive and it is smaller than the size of a ZIP "end of central directory record". + * would create the empty package-info.class file in the wrong + directory if no destdir was specified. Note it may still pick the + wrong directory if you specify more than one source directory but + no destDir. It is highly recommended that you always explicitly + specify the destDir attribute. + Bugzilla Report 51947. + Other changes: -------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/Javac.java b/src/main/org/apache/tools/ant/taskdefs/Javac.java index 0c2d76c37..dd80b727f 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Javac.java +++ b/src/main/org/apache/tools/ant/taskdefs/Javac.java @@ -1134,7 +1134,10 @@ public class Javac extends MatchingTask { if (adapter.execute()) { // Success try { - generateMissingPackageInfoClasses(); + generateMissingPackageInfoClasses(destDir != null + ? destDir + : getProject() + .resolveFile(src.list()[0])); } catch (IOException x) { // Should this be made a nonfatal warning? throw new BuildException(x, getLocation()); @@ -1194,12 +1197,12 @@ public class Javac extends MatchingTask { * Otherwise this task's up-to-date tracking mechanisms do not work. * @see Bug #43114 */ - private void generateMissingPackageInfoClasses() throws IOException { + private void generateMissingPackageInfoClasses(File dest) throws IOException { for (Iterator i = packageInfos.entrySet().iterator(); i.hasNext(); ) { Map.Entry entry = (Map.Entry) i.next(); String pkg = (String) entry.getKey(); Long sourceLastMod = (Long) entry.getValue(); - File pkgBinDir = new File(destDir, pkg.replace('/', File.separatorChar)); + File pkgBinDir = new File(dest, pkg.replace('/', File.separatorChar)); pkgBinDir.mkdirs(); File pkgInfoClass = new File(pkgBinDir, "package-info.class"); if (pkgInfoClass.isFile() && pkgInfoClass.lastModified() >= sourceLastMod.longValue()) { diff --git a/src/tests/antunit/taskdefs/javac-test.xml b/src/tests/antunit/taskdefs/javac-test.xml index 90e6c4a05..7201d2da1 100644 --- a/src/tests/antunit/taskdefs/javac-test.xml +++ b/src/tests/antunit/taskdefs/javac-test.xml @@ -80,7 +80,7 @@ - + @@ -92,7 +92,11 @@ + + @@ -111,6 +115,30 @@ + + + + + + + + + + + + + + + + + + + + +