[Jpackage-commits] dist/ant/JPP-6 ant.spec, 1.27, 1.28 apache-ant-bug43114.patch, NONE, 1.1

David Walluck david at ryu.zarb.org
Tue Jul 28 19:06:34 CEST 2009


Update of /home/projects/jpackage/cvs/dist/ant/JPP-6
In directory ryu.zarb.org:/tmp/cvs-serv32631

Modified Files:
	ant.spec 
Added Files:
	apache-ant-bug43114.patch 
Log Message:
- add patch for #43114

Index: ant.spec
===================================================================
RCS file: /home/projects/jpackage/cvs/dist/ant/JPP-6/ant.spec,v
retrieving revision 1.27
retrieving revision 1.28
diff -C 2 -d -r1.27 -r1.28
*** ant.spec	16 Feb 2009 20:42:24 -0000	1.27
--- ant.spec	28 Jul 2009 17:06:32 -0000	1.28
***************
*** 59,63 ****
  Name:           ant
  Version:        1.7.1
! Release:        9%{?dist}
  Epoch:          0
  Summary:        Ant build tool for java
--- 59,63 ----
  Name:           ant
  Version:        1.7.1
! Release:        10%{?dist}
  Epoch:          0
  Summary:        Ant build tool for java
***************
*** 101,106 ****
  Patch2:         apache-ant-gnu-classpath.patch
  Patch3:         apache-ant-no-test-jar.patch
  
! BuildRequires:  jpackage-utils >= 0:1.7.5
  BuildRequires:  java-devel >= 0:1.5.0
  BuildRequires:  jaxp_transform_impl
--- 101,110 ----
  Patch2:         apache-ant-gnu-classpath.patch
  Patch3:         apache-ant-no-test-jar.patch
+ #  Patch for #43114: ensuring that package-info.class is created/touched when
+ #  package-info.java is compiled.
+ Patch4:         apache-ant-bug43114.patch
  
! 
! BuildRequires:  jpackage-utils >= 0:1.7.3
  BuildRequires:  java-devel >= 0:1.5.0
  BuildRequires:  jaxp_transform_impl
***************
*** 112,116 ****
  %endif
  
! Requires:       jpackage-utils >= 0:1.7.5
  Requires:       java-devel >= 0:1.5.0
  %if %without bootstrap
--- 116,120 ----
  %endif
  
! Requires:       jpackage-utils >= 0:1.7.3
  Requires:       java-devel >= 0:1.5.0
  %if %without bootstrap
***************
*** 143,148 ****
  %endif
  
! Requires(post): jpackage-utils >= 0:1.7.5
! Requires(postun): jpackage-utils >= 0:1.7.5
  
  %description
--- 147,152 ----
  %endif
  
! Requires(post): jpackage-utils >= 0:1.7.3
! Requires(postun): jpackage-utils >= 0:1.7.3
  
  %description
***************
*** 507,510 ****
--- 511,518 ----
  %patch3 -p1
  
+ #  Patch for #43114: ensuring that package-info.class is created/touched when
+ #  package-info.java is compiled.
+ %patch4 -p1
+ 
  # clean jar files
  find . -name "*.jar" | %{_bindir}/xargs -t rm
***************
*** 739,744 ****
--- 747,754 ----
  %{__cp} -p %{buildroot}%{_javadir}/%{name}-%{version}.jar %{buildroot}%{repodirlib}/ant.jar
  %{__cp} -p %{buildroot}%{_javadir}/%{name}-launcher-%{version}.jar %{buildroot}%{repodirlib}/ant-launcher.jar
+ %if %without bootstrap
  %{__cp} -p %{buildroot}%{_javadir}/%{name}/%{name}-junit-%{version}.jar %{buildroot}%{repodirlib}/ant-junit.jar
  %endif
+ %endif
  
  # -----------------------------------------------------------------------------
***************
*** 1320,1323 ****
--- 1330,1336 ----
  
  %changelog
+ * Tue Jul 28 2009 David Walluck <dwalluck at redhat.com> 0:1.7.1-10
+ - add patch for #43114
+ 
  * Mon Feb 16 2009 David Walluck <dwalluck at redhat.com> 0:1.7.1-9
  - fix mixed-use-of-spaces-and-tabs

--- NEW FILE: apache-ant-bug43114.patch ---
--- apache-ant-1.7.1/src/main/org/apache/tools/ant/taskdefs/Javac.java.orig	2009-06-29 11:18:55.019197000 -0400
+++ apache-ant-1.7.1/src/main/org/apache/tools/ant/taskdefs/Javac.java	2009-06-29 11:18:59.493594000 -0400
@@ -19,10 +19,12 @@
 package org.apache.tools.ant.taskdefs;
 
 import java.io.File;
-
-import java.util.ArrayList;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.HashMap;
 import java.util.Iterator;
-import java.util.List;
+import java.util.Map;
 
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.DirectoryScanner;
@@ -86,9 +88,6 @@
     private static final String CLASSIC = "classic";
     private static final String EXTJAVAC = "extJavac";
 
-    private static final String PACKAGE_INFO_JAVA = "package-info.java";
-    private static final String PACKAGE_INFO_CLASS = "package-info.class";
-
     private Path src;
     private File destDir;
     private Path compileClasspath;
@@ -115,6 +114,7 @@
     protected boolean failOnError = true;
     protected boolean listFiles = false;
     protected File[] compileList = new File[0];
+    private Map/*<String,Long>*/ packageInfos = new HashMap();
     // CheckStyle:VisibilityModifier ON
 
     private String source;
@@ -124,7 +124,6 @@
     private String errorProperty;
     private boolean taskSuccess = true; // assume the best
     private boolean includeDestClasses = true;
-    private List    updateDirList = new ArrayList();
 
     /**
      * Javac task for compilation of Java files.
@@ -892,6 +891,7 @@
      */
     protected void resetFileLists() {
         compileList = new File[0];
+        packageInfos = new HashMap();
     }
 
     /**
@@ -909,8 +909,8 @@
         SourceFileScanner sfs = new SourceFileScanner(this);
         File[] newFiles = sfs.restrictAsFiles(files, srcDir, destDir, m);
 
-        newFiles = removePackageInfoFiles(newFiles, srcDir, destDir);
         if (newFiles.length > 0) {
+            lookForPackageInfos(srcDir, newFiles);
             File[] newCompileList
                 = new File[compileList.length + newFiles.length];
             System.arraycopy(compileList, 0, newCompileList, 0,
@@ -1063,10 +1063,12 @@
 
             // finally, lets execute the compiler!!
             if (adapter.execute()) {
-                // Success - check
-                for (Iterator i = updateDirList.iterator(); i.hasNext();) {
-                    File file = (File) i.next();
-                    file.setLastModified(System.currentTimeMillis());
+                // Success
+                try {
+                    generateMissingPackageInfoClasses();
+                } catch (IOException x) {
+                    // Should this be made a nonfatal warning?
+                    throw new BuildException(x, getLocation());
                 }
             } else {
                 // Fail path
@@ -1100,72 +1102,69 @@
         }
     }
 
-    // ----------------------------------------------------------------
-    //  Code to remove package-info.java files from compilation
-    //  Since Ant 1.7.1.
-    //
-    //    package-info.java are files that contain package level
-    //    annotations. They may or may not have corresponding .class
-    //    files.
-    //
-    //    The following code uses the algorithm:
-    //     * on entry we have the files that need to be compiled
-    //     * if the filename is not package-info.java compile it
-    //     * if a corresponding .class file exists compile it
-    //     * if the corresponding class directory does not exist compile it
-    //     * if the corresponding directory lastmodifed time is
-    //       older than the java file, compile the java file and
-    //       touch the corresponding class directory (on successful
-    //       compilation).
-    //
-    // ----------------------------------------------------------------
-    private File[] removePackageInfoFiles(
-        File[] newFiles, File srcDir, File destDir) {
-        if (!hasPackageInfo(newFiles)) {
-            return newFiles;
-        }
-        List ret = new ArrayList();
-        for (int i = 0; i < newFiles.length; ++i) {
-            if (needsCompilePackageFile(newFiles[i], srcDir, destDir)) {
-                ret.add(newFiles[i]);
+    private void lookForPackageInfos(File srcDir, File[] newFiles) {
+        for (int i = 0; i < newFiles.length; i++) {
+            File f = newFiles[i];
+            if (!f.getName().equals("package-info.java")) {
+                continue;
             }
-        }
-        return (File[]) ret.toArray(new File[0]);
-    }
-
-    private boolean hasPackageInfo(File[] newFiles) {
-        for (int i = 0; i < newFiles.length; ++i) {
-            if (newFiles[i].getName().equals(PACKAGE_INFO_JAVA)) {
-                return true;
+            String path = relativePath(srcDir, f).
+                    replace(File.separatorChar, '/');
+            String suffix = "/package-info.java";
+            if (!path.endsWith(suffix)) {
+                log("anomalous package-info.java path: " + path, Project.MSG_WARN);
+                continue;
             }
+            String pkg = path.substring(0, path.length() - suffix.length());
+            packageInfos.put(pkg, Long.valueOf(f.lastModified()));
         }
-        return false;
     }
 
-    private boolean needsCompilePackageFile(
-        File file, File srcDir, File destDir) {
-        if (!file.getName().equals(PACKAGE_INFO_JAVA)) {
-            return true;
-        }
-        // return true if destDir contains the file
-        String rel = relativePath(srcDir, file);
-        File destFile = new File(destDir, rel);
-        File parent = destFile.getParentFile();
-        destFile = new File(parent, PACKAGE_INFO_CLASS);
-        File sourceFile = new File(srcDir, rel);
-        if (destFile.exists()) {
-            return true;
-        }
-        // Dest file does not exist
-        // Compile Source file if sourceFile is newer that destDir
-        // TODO - use fs
-        if (sourceFile.lastModified()
-            > destFile.getParentFile().lastModified()) {
-            updateDirList.add(destFile.getParentFile());
-            return true;
+    /**
+     * Ensure that every {@code package-info.java} produced a {@code package-info.class}.
+     * 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 {
+        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));
+            pkgBinDir.mkdirs();
+            File pkgInfoClass = new File(pkgBinDir, "package-info.class");
+            if (pkgInfoClass.isFile() && pkgInfoClass.lastModified() >= sourceLastMod.longValue()) {
+                continue;
+            }
+            log("Creating empty " + pkgInfoClass);
+            OutputStream os = new FileOutputStream(pkgInfoClass);
+            try {
+                os.write(PACKAGE_INFO_CLASS_HEADER);
+                byte[] name = pkg.getBytes("UTF-8");
+                int length = name.length + /* "/package-info" */ 13;
+                os.write((byte) length / 256);
+                os.write((byte) length % 256);
+                os.write(name);
+                os.write(PACKAGE_INFO_CLASS_FOOTER);
+            } finally {
+                os.close();
+            }
         }
-        return false;
     }
+    private static final byte[] PACKAGE_INFO_CLASS_HEADER = {
+        (byte) 0xca, (byte) 0xfe, (byte) 0xba, (byte) 0xbe, 0x00, 0x00, 0x00,
+        0x31, 0x00, 0x07, 0x07, 0x00, 0x05, 0x07, 0x00, 0x06, 0x01, 0x00, 0x0a,
+        0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x46, 0x69, 0x6c, 0x65, 0x01, 0x00,
+        0x11, 0x70, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x2d, 0x69, 0x6e, 0x66,
+        0x6f, 0x2e, 0x6a, 0x61, 0x76, 0x61, 0x01
+    };
+    private static final byte[] PACKAGE_INFO_CLASS_FOOTER = {
+        0x2f, 0x70, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x2d, 0x69, 0x6e, 0x66,
+        0x6f, 0x01, 0x00, 0x10, 0x6a, 0x61, 0x76, 0x61, 0x2f, 0x6c, 0x61, 0x6e,
+        0x67, 0x2f, 0x4f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x02, 0x00, 0x00, 0x01,
+        0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x03,
+        0x00, 0x00, 0x00, 0x02, 0x00, 0x04
+    };
 
     private String relativePath(File src, File file) {
         return file.getAbsolutePath().substring(




More information about the JPackage-commits mailing list