ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r1178820 - in /ant/core/trunk: WHATSNEW src/main/org/apache/tools/ant/taskdefs/Javac.java src/tests/antunit/taskdefs/javac-test.xml
Date Tue, 04 Oct 2011 14:54:11 GMT
Author: bodewig
Date: Tue Oct  4 14:54:11 2011
New Revision: 1178820

URL: http://svn.apache.org/viewvc?rev=1178820&view=rev
Log:
Empty package-info.class is created in wrong directory if no destdir is specified.  PR 51947

Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Javac.java
    ant/core/trunk/src/tests/antunit/taskdefs/javac-test.xml

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=1178820&r1=1178819&r2=1178820&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Tue Oct  4 14:54:11 2011
@@ -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:
 --------------
 

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Javac.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Javac.java?rev=1178820&r1=1178819&r2=1178820&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Javac.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Javac.java Tue Oct  4 14:54:11 2011
@@ -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())
{

Modified: ant/core/trunk/src/tests/antunit/taskdefs/javac-test.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/taskdefs/javac-test.xml?rev=1178820&r1=1178819&r2=1178820&view=diff
==============================================================================
--- ant/core/trunk/src/tests/antunit/taskdefs/javac-test.xml (original)
+++ ant/core/trunk/src/tests/antunit/taskdefs/javac-test.xml Tue Oct  4 14:54:11 2011
@@ -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" />



Mime
View raw message