Issue #185192 ML NBM build is broken
authorDmitry Lipin <dlipin@netbeans.org>
Wed, 05 May 2010 20:59:17 +0400
changeset 9490d3e98ad6002
parent 948 62dcdd01fca8
child 950 87cc8a2c946b
Issue #185192 ML NBM build is broken
antsrc/org/netbeans/l10n/Package.java
     1.1 --- a/antsrc/org/netbeans/l10n/Package.java	Fri Apr 30 08:53:10 2010 +0900
     1.2 +++ b/antsrc/org/netbeans/l10n/Package.java	Wed May 05 20:59:17 2010 +0400
     1.3 @@ -42,6 +42,7 @@
     1.4  
     1.5  import java.io.BufferedOutputStream;
     1.6  import java.io.File;
     1.7 +import java.io.FileInputStream;
     1.8  import java.io.FileOutputStream;
     1.9  import java.io.IOException;
    1.10  import java.io.InputStream;
    1.11 @@ -53,6 +54,7 @@
    1.12  import java.util.jar.JarFile;
    1.13  import java.util.zip.ZipEntry;
    1.14  import org.netbeans.nbbuild.XMLUtil;
    1.15 +import org.netbeans.nbbuild.AutoUpdate;
    1.16  import org.apache.tools.ant.BuildException;
    1.17  import org.apache.tools.ant.DirectoryScanner;
    1.18  import org.apache.tools.ant.Project;
    1.19 @@ -196,8 +198,37 @@
    1.20                      if (bundleentry == null) {
    1.21                          //Read it from the NBM and module's jar manifest
    1.22                          JarFile nbmFile = new JarFile(destNbmFile);
    1.23 -                        ZipEntry ze = nbmFile.getEntry("netbeans" + File.separator + "modules" + File.separator + nbmName + ".jar");
    1.24 -                        InputStream is = nbmFile.getInputStream(ze);
    1.25 +                        String jarEntryName = "netbeans/modules/" + nbmName + ".jar";
    1.26 +                        ZipEntry ze = nbmFile.getEntry(jarEntryName);
    1.27 +                        InputStream is;
    1.28 +                        if(ze == null) {
    1.29 +                            //NBM is packed with pack200
    1.30 +                            ze = nbmFile.getEntry(jarEntryName + ".pack.gz");
    1.31 +                            if(ze!=null) {
    1.32 +                                File packedJar = File.createTempFile(nbmName, ".jar.pack.gz", tmpDir);
    1.33 +                                File unpackedJar = File.createTempFile(nbmName, ".jar", tmpDir);
    1.34 +                                unpackedJar.deleteOnExit();
    1.35 +                                packedJar.deleteOnExit();
    1.36 +                                InputStream fis = nbmFile.getInputStream(ze);
    1.37 +                                BufferedOutputStream bof = new BufferedOutputStream(new FileOutputStream(packedJar));
    1.38 +                                byte [] buffer = new byte [4096];
    1.39 +                                int read = 0;
    1.40 +                                while ((read = fis.read(buffer)) != -1) {
    1.41 +                                    bof.write(buffer, 0, read);
    1.42 +                                }
    1.43 +                                bof.close();
    1.44 +                                fis.close();
    1.45 +                                AutoUpdate.unpack200(packedJar, unpackedJar);
    1.46 +                                is = new FileInputStream(unpackedJar);
    1.47 +                            } else {
    1.48 +                                throw new BuildException("Cannot find neither " +
    1.49 +                                        jarEntryName + ".pack.gz nor " +
    1.50 +                                        jarEntryName + " entry in " + nbmFile.getName());
    1.51 +                            }
    1.52 +                        } else {
    1.53 +                            is = nbmFile.getInputStream(ze);
    1.54 +                        }
    1.55 +                        
    1.56                          File tmpJar = File.createTempFile("module", ".jar", tmpDir);
    1.57                          BufferedOutputStream bof = new BufferedOutputStream(new FileOutputStream(tmpJar));
    1.58                          int ch = 0;
    1.59 @@ -223,7 +254,7 @@
    1.60                          }
    1.61                          // Open the original info XML
    1.62                          JarFile nbmFile = new JarFile(destNbmFile);
    1.63 -                        Document doc = XMLUtil.parse(new InputSource(nbmFile.getInputStream(nbmFile.getEntry("Info" + File.separator + "info.xml"))), false, false, new ErrorCatcher(), null);
    1.64 +                        Document doc = XMLUtil.parse(new InputSource(nbmFile.getInputStream(nbmFile.getEntry("Info/info.xml"))), false, false, new ErrorCatcher(), null);
    1.65                          Element manifest = (Element) doc.getElementsByTagName("manifest").item(0);
    1.66  
    1.67                          // Now pick up attributes from the bundle and put them to the info.xml