Browse Source

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
master
Stefan Bodewig 13 years ago
parent
commit
28c651a95a
3 changed files with 42 additions and 4 deletions
  1. +7
    -0
      WHATSNEW
  2. +6
    -3
      src/main/org/apache/tools/ant/taskdefs/Javac.java
  3. +29
    -1
      src/tests/antunit/taskdefs/javac-test.xml

+ 7
- 0
WHATSNEW View File

@@ -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".

* <javac> 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:
--------------



+ 6
- 3
src/main/org/apache/tools/ant/taskdefs/Javac.java View File

@@ -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 <a href="https://issues.apache.org/bugzilla/show_bug.cgi?id=43114">Bug #43114</a>
*/
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()) {


+ 29
- 1
src/tests/antunit/taskdefs/javac-test.xml View File

@@ -80,7 +80,7 @@
</au:assertTrue>
</target>

<target name="testPackageInfoJava" description="https://issues.apache.org/bugzilla/show_bug.cgi?id=43114">
<target name="setUpForPackageInfoJava">
<mkdir dir="${javac-dir}/src/a" />
<mkdir dir="${build-dir}" />
<echo file="${javac-dir}/src/a/package-info.java">
@@ -92,7 +92,11 @@
</echo>
<javac srcdir="${javac-dir}/src" destdir="${build-dir}" updatedProperty="first-pass" />
<au:assertPropertyEquals name="first-pass" value="true" />
</target>

<target name="testPackageInfoJava"
depends="setUpForPackageInfoJava"
description="https://issues.apache.org/bugzilla/show_bug.cgi?id=43114">
<!-- no changes, shouldn't recompile, the initial bug -->
<javac srcdir="${javac-dir}/src" destdir="${build-dir}" updatedProperty="second-pass" />
<au:assertFalse>
@@ -111,6 +115,30 @@
<au:assertPropertyEquals name="third-pass" value="true" />
</target>

<target name="testPackageInfoJavaNoDest"
depends="setUpForPackageInfoJava"
description="https://issues.apache.org/bugzilla/show_bug.cgi?id=51947">
<javac srcdir="${javac-dir}/src" updatedProperty="first-pass" />
<au:assertPropertyEquals name="first-pass" value="true" />

<!-- no changes, shouldn't recompile, the initial bug -->
<javac srcdir="${javac-dir}/src" updatedProperty="second-pass" />
<au:assertFalse>
<isset property="second-pass" />
</au:assertFalse>
<sleep seconds="2" />

<!-- change package-info.java but make containing target dir even
more recent - the regression in Ant 1.7.1 -->
<touch file="${javac-dir}/src/a/package-info.java" />
<sleep seconds="2" />
<touch>
<file file="${javac-dir}/src/a" />
</touch>
<javac srcdir="${javac-dir}/src" updatedProperty="third-pass" />
<au:assertPropertyEquals name="third-pass" value="true" />
</target>

<target name="-create-javac-adapter">
<property name="adapter.dir" location="${output}/adapter" />
<mkdir dir="${input}/org/example" />


Loading…
Cancel
Save