This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 84852
Collapse All | Expand All

(-)a/apisupport.harness/manifest.mf (-1 / +1 lines)
Lines 1-5 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.modules.apisupport.harness
2
OpenIDE-Module: org.netbeans.modules.apisupport.harness
3
OpenIDE-Module-Specification-Version: 1.20
3
OpenIDE-Module-Specification-Version: 1.21
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/apisupport/harness/Bundle.properties
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/apisupport/harness/Bundle.properties
5
5
(-)a/apisupport.harness/release/README (+4 lines)
Lines 796-801 Link Here
796
also define just ${nbjdk.home} directly, without using ${nbjdk.active}, if you do
796
also define just ${nbjdk.home} directly, without using ${nbjdk.active}, if you do
797
not need to use the Java Platform Manager to set up the JDK definition.
797
not need to use the Java Platform Manager to set up the JDK definition.
798
798
799
pack200.excludes [since 6.9] - comma- or space- separated list of patterns of 
800
files relative to cluster directory for which pack200 compression should not be used 
801
while creating NBMs.
802
799
project.license [since 6.0] - license to use for newly created files in the project
803
project.license [since 6.0] - license to use for newly created files in the project
800
(applies also to suites); default is 'cddl' for modules inside netbeans.org.
804
(applies also to suites); default is 'cddl' for modules inside netbeans.org.
801
805
(-)a/autoupdate.services/libsrc/org/netbeans/updater/ModuleUpdater.java (-7 / +42 lines)
Lines 291-296 Link Here
291
    }
291
    }
292
292
293
293
294
294
    /** Unpack the distribution files into update directory */
295
    /** Unpack the distribution files into update directory */
295
296
296
    private void unpack ()  {
297
    private void unpack ()  {
Lines 356-366 Link Here
356
357
357
                try {
358
                try {
358
                    jarFile = new JarFile (nbm);
359
                    jarFile = new JarFile (nbm);
359
                    Enumeration entries = jarFile.entries();
360
                    Enumeration<JarEntry> entries = jarFile.entries();
360
                    List <String> executableFiles = readExecutableFilesList(jarFile);
361
                    List <String> executableFiles = readExecutableFilesList(jarFile);
361
                    List <File> filesToChmod = new ArrayList <File> ();
362
                    List <File> filesToChmod = new ArrayList <File> ();
362
                    while( entries.hasMoreElements() ) {
363
                    while( entries.hasMoreElements() ) {
363
                        JarEntry entry = (JarEntry) entries.nextElement();
364
                        JarEntry entry = entries.nextElement();
364
                        checkStop();
365
                        checkStop();
365
                        if ( entry.getName().startsWith( UPDATE_NETBEANS_DIR ) ) {
366
                        if ( entry.getName().startsWith( UPDATE_NETBEANS_DIR ) ) {
366
                            if (! entry.isDirectory ()) {
367
                            if (! entry.isDirectory ()) {
Lines 370-380 Link Here
370
                                }
371
                                }
371
                                String pathTo = entry.getName ().substring (UPDATE_NETBEANS_DIR.length () + 1);
372
                                String pathTo = entry.getName ().substring (UPDATE_NETBEANS_DIR.length () + 1);
372
                                // path without netbeans prefix
373
                                // path without netbeans prefix
373
                                if ( mu.isL10n() )
374
                                    version.addL10NFileWithCrc( pathTo, Long.toString( entry.getCrc() ), mu.getSpecification_version());
375
                                else
376
                                    version.addFileWithCrc( pathTo, Long.toString( entry.getCrc() ) );
377
378
                                File destFile = new File (cluster, entry.getName ().substring (UPDATE_NETBEANS_DIR.length()));
374
                                File destFile = new File (cluster, entry.getName ().substring (UPDATE_NETBEANS_DIR.length()));
379
                                if ( destFile.exists() ) {
375
                                if ( destFile.exists() ) {
380
                                    File bckFile = new File( getBackupDirectory (cluster), entry.getName() );
376
                                    File bckFile = new File( getBackupDirectory (cluster), entry.getName() );
Lines 387-396 Link Here
387
                                } else {
383
                                } else {
388
                                    destFile.getParentFile ().mkdirs ();
384
                                    destFile.getParentFile ().mkdirs ();
389
                                }
385
                                }
386
                                
390
                                bytesRead = copyStreams( jarFile.getInputStream( entry ), new FileOutputStream( destFile ), bytesRead );
387
                                bytesRead = copyStreams( jarFile.getInputStream( entry ), new FileOutputStream( destFile ), bytesRead );
391
                                if(executableFiles.contains(pathTo)) {
388
                                if(executableFiles.contains(pathTo)) {
392
                                    filesToChmod.add(destFile);
389
                                    filesToChmod.add(destFile);
393
                                }
390
                                }
391
                                long crc = entry.getCrc();
392
                                if(pathTo.endsWith(".jar.pack.gz") &&
393
                                        jarFile.getEntry(entry.getName().substring(0, entry.getName().lastIndexOf(".pack.gz")))==null) {
394
                                     //check if file.jar.pack.gz does not exit for file.jar - then unpack current .pack.gz file
395
                                    File unpacked = new File(destFile.getParentFile(), destFile.getName().substring(0, destFile.getName().lastIndexOf(".pack.gz")));
396
                                    unpack200(destFile, unpacked);
397
                                    destFile.delete();
398
                                    pathTo = pathTo.substring(0, pathTo.length() - ".pack.gz".length());
399
                                    crc = UpdateTracking.getFileCRC(unpacked);
400
                                }
401
                                if ( mu.isL10n() ) {
402
                                    version.addL10NFileWithCrc( pathTo, Long.toString(crc), mu.getSpecification_version());
403
                                } else {
404
                                    version.addFileWithCrc( pathTo, Long.toString(crc));
405
                                }
406
                                
394
                                UpdaterFrame.setProgressValue( bytesRead );
407
                                UpdaterFrame.setProgressValue( bytesRead );
395
                            }
408
                            }
396
                        } else if ( entry.getName().startsWith( UPDATE_MAIN_DIR )&&
409
                        } else if ( entry.getName().startsWith( UPDATE_MAIN_DIR )&&
Lines 467-472 Link Here
467
            t.deleteUnusedFiles ();            
480
            t.deleteUnusedFiles ();            
468
        }
481
        }
469
    }
482
    }
483
    
484
    private boolean unpack200(File src, File dest) {
485
        String unpack200Executable = new File(System.getProperty("java.home"),
486
                "bin/unpack200" + (isWindows() ? ".exe" : "")).getAbsolutePath();
487
        ProcessBuilder pb = new ProcessBuilder(unpack200Executable, src.getAbsolutePath(), dest.getAbsolutePath());
488
        pb.directory(src.getParentFile());
489
        int result = 1;
490
        try {
491
            //maybe reuse start() method here?
492
            Process process = pb.start();
493
            //TODO: Need to think of unpack200/lvprcsrv.exe issues
494
            //https://netbeans.org/bugzilla/show_bug.cgi?id=117334
495
            //https://netbeans.org/bugzilla/show_bug.cgi?id=119861
496
            result = process.waitFor();
497
            process.destroy();
498
        } catch (IOException e) {
499
            e.printStackTrace();
500
        } catch (InterruptedException e) {
501
            e.printStackTrace();
502
        }
503
        return result == 0;
504
    }
470
505
471
    private List<String> readExecutableFilesList(JarFile jarFile) {
506
    private List<String> readExecutableFilesList(JarFile jarFile) {
472
        List<String> list = new ArrayList<String>();
507
        List<String> list = new ArrayList<String>();
(-)a/autoupdate.services/libsrc/org/netbeans/updater/UpdateTracking.java (-2 / +2 lines)
Lines 508-515 Link Here
508
            bsrc = new BufferedInputStream( new FileInputStream( file ) );
508
            bsrc = new BufferedInputStream( new FileInputStream( file ) );
509
            byte[] bytes = new byte[1024];
509
            byte[] bytes = new byte[1024];
510
            int i;
510
            int i;
511
            while( (i = bsrc.read()) != -1 ) {
511
            while( (i = bsrc.read(bytes)) != -1 ) {
512
                crc.update( (byte)i );
512
                crc.update(bytes, 0, i );
513
            }
513
            }
514
        }
514
        }
515
        finally {
515
        finally {
(-)a/autoupdate.services/manifest.mf (-1 / +1 lines)
Lines 1-7 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.modules.autoupdate.services
2
OpenIDE-Module: org.netbeans.modules.autoupdate.services
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/autoupdate/services/resources/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/autoupdate/services/resources/Bundle.properties
4
OpenIDE-Module-Specification-Version: 1.17
4
OpenIDE-Module-Specification-Version: 1.18
5
OpenIDE-Module-Layer: org/netbeans/modules/autoupdate/services/resources/layer.xml
5
OpenIDE-Module-Layer: org/netbeans/modules/autoupdate/services/resources/layer.xml
6
AutoUpdate-Show-In-Client: false
6
AutoUpdate-Show-In-Client: false
7
AutoUpdate-Essential-Module: true
7
AutoUpdate-Essential-Module: true
(-)a/autoupdate.services/nbproject/project.properties (+1 lines)
Lines 5-7 Link Here
5
javadoc.arch=${basedir}/arch.xml
5
javadoc.arch=${basedir}/arch.xml
6
javadoc.apichanges=${basedir}/apichanges.xml
6
javadoc.apichanges=${basedir}/apichanges.xml
7
test.unit.cp.extra=${basedir}/modules/ext/updater.jar
7
test.unit.cp.extra=${basedir}/modules/ext/updater.jar
8
pack200.excludes=modules/ext/updater.jar
(-)21298aae226f (+341 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 *
35
 * Contributor(s):
36
 *
37
 * Portions Copyrighted 2010 Sun Microsystems, Inc.
38
 */
39
package org.netbeans.modules.autoupdate.services;
40
41
import java.io.File;
42
import java.io.FileInputStream;
43
import java.io.FileOutputStream;
44
import java.io.IOException;
45
import java.io.OutputStream;
46
import java.io.OutputStreamWriter;
47
import java.io.PrintWriter;
48
import java.net.URL;
49
import java.util.ArrayList;
50
import java.util.List;
51
import java.util.jar.Attributes;
52
import java.util.jar.JarFile;
53
import java.util.jar.JarOutputStream;
54
import java.util.jar.Manifest;
55
import java.util.jar.Pack200;
56
import java.util.zip.GZIPOutputStream;
57
import java.util.zip.ZipEntry;
58
import org.netbeans.api.autoupdate.InstallSupport;
59
import org.netbeans.api.autoupdate.OperationContainer;
60
import org.netbeans.api.autoupdate.OperationContainer.OperationInfo;
61
import org.netbeans.api.autoupdate.OperationException;
62
import org.netbeans.api.autoupdate.OperationSupport.Restarter;
63
import org.netbeans.api.autoupdate.TestUtils;
64
import org.netbeans.api.autoupdate.UpdateElement;
65
import org.netbeans.api.autoupdate.UpdateUnit;
66
import org.netbeans.api.autoupdate.UpdateUnitProvider;
67
import org.netbeans.api.autoupdate.UpdateUnitProviderFactory;
68
import org.netbeans.core.startup.MainLookup;
69
import org.netbeans.junit.NbTestCase;
70
import org.netbeans.modules.autoupdate.updateprovider.AutoupdateCatalogProvider;
71
import org.openide.filesystems.FileUtil;
72
import org.openide.util.Lookup;
73
74
/**
75
 *
76
 * @author Dmitry Lipin
77
 */
78
public class NbmPack200Test extends NbTestCase {
79
80
    protected List<UpdateUnit> keepItNotToGC;
81
    private static File catalogFile;
82
    private static URL catalogURL;
83
    private File tmpDirectory;
84
    private List<File> nbms = new ArrayList<File>();
85
    private List<String> moduleElements = new ArrayList<String>();
86
87
    public NbmPack200Test(String testName) {
88
        super(testName);
89
    }
90
91
    public static class MyProvider extends AutoupdateCatalogProvider {
92
93
        public MyProvider() {
94
            super("test-updates-provider", "test-updates-provider", catalogURL, UpdateUnitProvider.CATEGORY.STANDARD);
95
        }
96
    }
97
98
    private String getModuleElement(boolean visible, String codeName, String releaseVersion, String implVersion, String moduleName, String distr, String specVersion, String dependency) {
99
        String releaseVersionAppendix = ((releaseVersion != null /*&& Integer.parseInt(releaseVersion)!=0*/) ? ("/" + releaseVersion) : "");
100
        return "\n<module "
101
                + "\n     codenamebase='" + codeName + "' "
102
                + "\n     distribution='" + distr + "' "
103
                + "\n     downloadsize='0' "
104
                + "\n     homepage='' "
105
                + "\n     license='AD9FBBC9' "
106
                + "\n     moduleauthor='' "
107
                + "\n     needsrestart='false' "
108
                + "\n     releasedate='2007/01/30'>"
109
                + "\n    <manifest "
110
                + "\n       AutoUpdate-Show-In-Client='" + visible + "' "
111
                + "\n       OpenIDE-Module='" + codeName + releaseVersionAppendix + "'"
112
                + "\n       OpenIDE-Module-Implementation-Version='" + (implVersion == null ? "070130" : implVersion) + "' "
113
                + "\n       OpenIDE-Module-Java-Dependencies='Java &gt; 1.4' "
114
                + "\n       OpenIDE-Module-Name='" + moduleName + "' "
115
                + (dependency != null ? " OpenIDE-Module-Module-Dependencies=\"" + dependency.replace(">", "&gt;") + "\" " : "")
116
                + "\n       OpenIDE-Module-Requires='org.openide.modules.ModuleFormat1' "
117
                + "\n       OpenIDE-Module-Specification-Version='" + specVersion + "'/>"
118
                + "\n    <license name='AD9FBBC9'>[NO LICENSE SPECIFIED]"
119
                + "\n</license>"
120
                + "\n</module>\n";
121
    }
122
123
    private String createInfoXML(boolean visible, String codeName, String releaseVersion, String implVersion, String moduleName, String distr, String specVersion, String dependency) {
124
        String moduleElement = getModuleElement(visible, codeName, releaseVersion, implVersion, moduleName, distr, specVersion, dependency);
125
126
        moduleElements.add(moduleElement);
127
        return "<?xml version='1.0' encoding='UTF-8'?>"
128
                + "<!DOCTYPE module PUBLIC '-//NetBeans//DTD Autoupdate Module Info 2.5//EN' 'http://www.netbeans.org/dtds/autoupdate-info-2_5.dtd'>"
129
                + moduleElement;
130
    }
131
132
    private void writeCatalog() throws IOException {
133
        String res = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
134
                + "<!DOCTYPE module_updates PUBLIC \"-//NetBeans//DTD Autoupdate Catalog 2.5//EN\" \"http://www.netbeans.org/dtds/autoupdate-catalog-2_5.dtd\">"
135
                + "<module_updates timestamp=\"00/00/19/08/03/2006\">\n";
136
        for (String element : moduleElements) {
137
            res += element;
138
        }
139
        res += "</module_updates>\n";
140
        if (catalogFile == null) {
141
            catalogFile = File.createTempFile("catalog-", ".xml", tmpDirectory);
142
            catalogURL = catalogFile.toURI().toURL();
143
        }
144
        PrintWriter pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream(catalogFile), "UTF-8"));
145
        pw.write(res);
146
        pw.close();
147
    }
148
149
    private String getConfigXML(String codeName, String moduleFile, String specVersion) {
150
        return "<?xml version='1.0' encoding='UTF-8'?>"
151
                + " <!DOCTYPE module PUBLIC '-//NetBeans//DTD Module Status 1.0//EN'"
152
                + " 'http://www.netbeans.org/dtds/module-status-1_0.dtd'>"
153
                + " <module name='" + codeName + "'>"
154
                + " <param name='autoload'>false</param>"
155
                + " <param name='eager'>false</param>"
156
                + " <param name='enabled'>true</param>"
157
                + " <param name='jar'>modules/" + moduleFile + ".jar</param>"
158
                + " <param name='reloadable'>false</param>"
159
                + " <param name='specversion'>" + specVersion + "</param>"
160
                + " </module>";
161
    }
162
163
    private String getManifest(String codeName, String releaseVersion, String implVersion, String moduleDir, String specVersion, boolean visible, String dependency) {
164
        String releaseVersionAppendix = ((releaseVersion != null /*&& Integer.parseInt(releaseVersion)!=0*/) ? ("/" + releaseVersion) : "");
165
        return "Manifest-Version: 1.0\n"
166
                + "Ant-Version: Apache Ant 1.7.0\n"
167
                + "Created-By: 1.6.0-b105 (Sun Microsystems Inc.)\n"
168
                + "OpenIDE-Module-Public-Packages: -\n"
169
                + "OpenIDE-Module-Java-Dependencies: Java > 1.4\n"
170
                + "OpenIDE-Module-Implementation-Version: " + (implVersion == null ? "070130" : implVersion)
171
                + "\n"
172
                + (dependency != null ? ("OpenIDE-Module-Module-Dependencies: " + dependency + "\n") : "")
173
                + "OpenIDE-Module: " + codeName + releaseVersionAppendix
174
                + "\n"
175
                + "OpenIDE-Module-Localizing-Bundle: " + moduleDir + "Bundle.properties\n"
176
                + "OpenIDE-Module-Specification-Version: " + specVersion + "\n"
177
                + "OpenIDE-Module-Requires: org.openide.modules.ModuleFormat1\n"
178
                + "AutoUpdate-Show-In-Client: " + visible + "\n"
179
                + "\n";
180
    }
181
182
    private File prepareNBM(String codeName, String releaseVersion, String implVersion, String specVersion, boolean visible, String dependency) throws Exception {
183
        String moduleName = codeName.substring(codeName.lastIndexOf(".") + 1);
184
        String moduleFile = codeName.replace(".", "-");
185
        String moduleDir = codeName.replace(".", "/") + "/";
186
        File nbm = File.createTempFile(moduleFile + "-", ".nbm", tmpDirectory);
187
188
        final String MODULE_NAME_PROP = "OpenIDE-Module-Name";
189
190
        File jar = new File(tmpDirectory, "netbeans/modules/" + moduleFile + ".jar");
191
        jar.getParentFile().mkdirs();
192
        JarOutputStream jos = new JarOutputStream(new FileOutputStream(jar));
193
        int idx = moduleDir.indexOf("/");
194
        while (idx != -1) {
195
            jos.putNextEntry(new ZipEntry(moduleDir.substring(0, idx + 1)));
196
            idx = moduleDir.indexOf("/", idx + 1);
197
        }
198
199
        jos.putNextEntry(new ZipEntry(moduleDir + "Bundle.properties"));
200
        jos.write(new String(MODULE_NAME_PROP + "=" + moduleName).getBytes("UTF-8"));
201
        jos.putNextEntry(new ZipEntry("META-INF/"));
202
        jos.putNextEntry(new ZipEntry("META-INF/manifest.mf"));
203
        jos.write(getManifest(codeName, releaseVersion, implVersion, moduleDir, specVersion, visible, dependency).getBytes("UTF-8"));
204
        jos.close();
205
        File jarPackGz = new File(jar.getParentFile(), jar.getName() + ".pack.gz");
206
        assertEquals("Cannot compress jar using pack200", pack200(jar, jarPackGz), true);
207
        jar.delete();
208
209
210
        Manifest mf = new Manifest();
211
        mf.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
212
213
214
        jos = new JarOutputStream(new FileOutputStream(nbm), mf);
215
        jos.putNextEntry(new ZipEntry("Info/"));
216
        jos.putNextEntry(new ZipEntry("Info/info.xml"));
217
        jos.write(createInfoXML(visible, codeName, releaseVersion, implVersion, moduleName, nbm.toURI().toURL().toString(), specVersion, dependency).getBytes("UTF-8"));
218
219
        jos.putNextEntry(new ZipEntry("netbeans/"));
220
        jos.putNextEntry(new ZipEntry("netbeans/modules/"));
221
        jos.putNextEntry(new ZipEntry("netbeans/config/"));
222
        jos.putNextEntry(new ZipEntry("netbeans/config/Modules/"));
223
        jos.putNextEntry(new ZipEntry("netbeans/config/Modules/" + moduleFile + ".xml"));
224
225
        jos.write(getConfigXML(codeName, moduleFile, specVersion).getBytes("UTF-8"));
226
227
228
        jos.putNextEntry(new ZipEntry("netbeans/modules/" + moduleFile + ".jar.pack.gz"));
229
230
        FileInputStream fis = new FileInputStream(jarPackGz);
231
        FileUtil.copy(fis, jos);
232
        fis.close();
233
        jarPackGz.delete();
234
        jos.close();
235
        nbms.add(nbm);
236
237
        return nbm;
238
    }
239
240
    private boolean pack200(final File sourceFile, final File targetFile) throws IOException {
241
        OutputStream outputStream = null;
242
        JarFile jarFile = null;
243
        boolean result = false;
244
        try {
245
            jarFile = new JarFile(sourceFile);
246
            outputStream = new GZIPOutputStream(new FileOutputStream(targetFile));
247
            Pack200.newPacker().pack(jarFile, outputStream);
248
            result = true;
249
        } finally {
250
            if (jarFile != null) {
251
                try {
252
                    jarFile.close();
253
                } catch (IOException e) {
254
                }
255
            }
256
            if (outputStream != null) {
257
                try {
258
                    outputStream.close();
259
                } catch (IOException e) {
260
                }
261
            }
262
        }
263
        return result;
264
    }
265
266
    protected void setUp() throws Exception {
267
        super.setUp();
268
        this.clearWorkDir();
269
        tmpDirectory = new File(getWorkDirPath(), "tmp");
270
        tmpDirectory.mkdirs();
271
272
        writeCatalog();
273
274
        TestUtils.setUserDir(getWorkDirPath());
275
        TestUtils.testInit();
276
277
        MainLookup.register(new MyProvider());
278
        assert Lookup.getDefault().lookup(MyProvider.class) != null;
279
        UpdateUnitProviderFactory.getDefault().refreshProviders(null, true);
280
    }
281
282
    private void doInstall(OperationContainer<InstallSupport> installContainer) throws OperationException {
283
        InstallSupport support = installContainer.getSupport();
284
        assertNotNull(support);
285
286
        InstallSupport.Validator v = support.doDownload(null, false);
287
        assertNotNull(v);
288
        InstallSupport.Installer i = support.doValidate(v, null);
289
        assertNotNull(i);
290
        Restarter r = null;
291
        try {
292
            r = support.doInstall(i, null);
293
        } catch (OperationException ex) {
294
            if (OperationException.ERROR_TYPE.INSTALL == ex.getErrorType()) {
295
                // can ingore
296
                // module system cannot load the module either
297
            } else {
298
                fail(ex.toString());
299
            }
300
        }
301
        assertNull("Installing new element require restarting though it should not", r);
302
    }
303
304
    
305
    public void testNbmWithPack200Compression() throws Exception {
306
        String moduleCNB = "org.netbeans.modules.mymodule";
307
        String moduleReleaseVersion = "1";
308
        String moduleImplVersion = "2";
309
        String moduleSpecVersion = "1.0";
310
311
        prepareNBM(moduleCNB, moduleReleaseVersion, moduleImplVersion, moduleSpecVersion, false, null);
312
313
        writeCatalog();
314
        UpdateUnitProviderFactory.getDefault().refreshProviders(null, true);
315
        OperationContainer<InstallSupport> installContainer = OperationContainer.createForInstall();
316
        UpdateUnit moduleUnit = getUpdateUnit(moduleCNB);
317
        assertNull("cannot be installed", moduleUnit.getInstalled());
318
        UpdateElement moduleElement = getAvailableUpdate(moduleUnit, 0);
319
        assertEquals(moduleElement.getSpecificationVersion(), moduleSpecVersion);
320
        OperationInfo<InstallSupport> independentInfo = installContainer.add(moduleElement);
321
        assertNotNull(independentInfo);
322
        doInstall(installContainer);
323
        assertTrue("module was not installed from NBM with pack200 compression", moduleUnit.getInstalled() != null);
324
        assertTrue("module was not enabled after installation from NBM with pack200 compression", moduleUnit.getInstalled().isEnabled());
325
    }
326
327
    
328
329
    public UpdateUnit getUpdateUnit(String codeNameBase) {
330
        UpdateUnit uu = UpdateManagerImpl.getInstance().getUpdateUnit(codeNameBase);
331
        assertNotNull(uu);
332
        return uu;
333
    }
334
335
    public UpdateElement getAvailableUpdate(UpdateUnit updateUnit, int idx) {
336
        List<UpdateElement> available = updateUnit.getAvailableUpdates();
337
        assertTrue(available.size() > idx);
338
        return available.get(idx);
339
340
    }
341
}
(-)a/nbbuild/antsrc/org/netbeans/nbbuild/AutoUpdate.java (-3 / +66 lines)
Lines 39-47 Link Here
39
39
40
package org.netbeans.nbbuild;
40
package org.netbeans.nbbuild;
41
41
42
import java.io.BufferedInputStream;
42
import java.io.BufferedOutputStream;
43
import java.io.BufferedOutputStream;
43
import java.io.ByteArrayInputStream;
44
import java.io.ByteArrayInputStream;
44
import java.io.File;
45
import java.io.File;
46
import java.io.FileInputStream;
45
import java.io.FileOutputStream;
47
import java.io.FileOutputStream;
46
import java.io.IOException;
48
import java.io.IOException;
47
import java.io.InputStream;
49
import java.io.InputStream;
Lines 239-263 Link Here
239
                    if (zipEntry.getName().endsWith("/")) {
241
                    if (zipEntry.getName().endsWith("/")) {
240
                        continue;
242
                        continue;
241
                    }
243
                    }
242
                    final String relName = zipEntry.getName().substring(9);
244
                    String relName = zipEntry.getName().substring(9);
243
                    File trgt = new File(whereTo, relName.replace('/', File.separatorChar));
245
                    File trgt = new File(whereTo, relName.replace('/', File.separatorChar));
244
                    trgt.getParentFile().mkdirs();
246
                    trgt.getParentFile().mkdirs();
245
                    log("Writing " + trgt, Project.MSG_VERBOSE);
247
                    log("Writing " + trgt, Project.MSG_VERBOSE);
246
248
247
                    InputStream is = zf.getInputStream(zipEntry);
249
                    InputStream is = zf.getInputStream(zipEntry);
248
                    OutputStream os = new FileOutputStream(trgt);
250
                    OutputStream os = new FileOutputStream(trgt);
251
                    boolean doUnpack200 = false;
252
                    if(relName.endsWith(".jar.pack.gz") && zf.getEntry(zipEntry.getName().substring(0, zipEntry.getName().length() + 8))==null) {
253
                        doUnpack200 = true;
254
                    }
249
                    CRC32 crc = new CRC32();
255
                    CRC32 crc = new CRC32();
250
                    for (;;) {
256
                    for (;;) {
251
                        int len = is.read(bytes);
257
                        int len = is.read(bytes);
252
                        if (len == -1) {
258
                        if (len == -1) {
253
                            break;
259
                            break;
254
                        }
260
                        }
255
                        crc.update(bytes, 0, len);
261
                        if(!doUnpack200) {
262
                            crc.update(bytes, 0, len);
263
                        }
256
                        os.write(bytes, 0, len);
264
                        os.write(bytes, 0, len);
257
                    }
265
                    }
258
                    is.close();
266
                    is.close();
259
                    os.close();
267
                    os.close();
260
                    config.write(("    <file crc='" + crc.getValue() + "' name='" + relName + "'/>\n").getBytes("UTF-8"));
268
                    long crcValue = crc.getValue();
269
                    if(doUnpack200) {
270
                        File dest = new File(trgt.getParentFile(), trgt.getName().substring(0, trgt.getName().length() - 8));
271
                        unpack200(trgt, dest);
272
                        trgt.delete();
273
                        crcValue = getFileCRC(dest);
274
                        relName = relName.substring(0, relName.length() - 8);
275
                    }
276
                    config.write(("    <file crc='" + crcValue + "' name='" + relName + "'/>\n").getBytes("UTF-8"));
261
                }
277
                }
262
                config.write("  </module_version>\n</module>\n".getBytes("UTF-8"));
278
                config.write("  </module_version>\n</module>\n".getBytes("UTF-8"));
263
                config.close();
279
                config.close();
Lines 274-279 Link Here
274
        }
290
        }
275
    }
291
    }
276
292
293
    private boolean unpack200(File src, File dest) {
294
        // Copy of ModuleUpdater.unpack200
295
296
        log("Unpacking " + src + " to " + dest, Project.MSG_VERBOSE);
297
        String unpack200Executable = new File(System.getProperty("java.home"),
298
                "bin/unpack200" + (isWindows() ? ".exe" : "")).getAbsolutePath();
299
        ProcessBuilder pb = new ProcessBuilder(unpack200Executable, src.getAbsolutePath(), dest.getAbsolutePath());
300
        pb.directory(src.getParentFile());
301
        int result = 1;
302
        try {
303
            //maybe reuse start() method here?
304
            Process process = pb.start();
305
            //TODO: Need to think of unpack200/lvprcsrv.exe issues
306
            //https://netbeans.org/bugzilla/show_bug.cgi?id=117334
307
            //https://netbeans.org/bugzilla/show_bug.cgi?id=119861
308
            result = process.waitFor();
309
            process.destroy();
310
        } catch (IOException e) {
311
            e.printStackTrace();
312
        } catch (InterruptedException e) {
313
            e.printStackTrace();
314
        }
315
        return result == 0;
316
    }
317
    private static boolean isWindows() {
318
        String os = System.getProperty("os.name"); // NOI18N
319
        return (os != null && os.toLowerCase().startsWith("windows"));//NOI18N
320
    }
321
322
    private static long getFileCRC(File file) throws IOException {
323
        BufferedInputStream bsrc = null;
324
        CRC32 crc = new CRC32();
325
        try {
326
            bsrc = new BufferedInputStream( new FileInputStream( file ) );
327
            byte[] bytes = new byte[1024];
328
            int i;
329
            while( (i = bsrc.read(bytes)) != -1 ) {
330
                crc.update(bytes, 0, i );
331
            }
332
        }
333
        finally {
334
            if ( bsrc != null )
335
                bsrc.close();
336
        }
337
        return crc.getValue();
338
    }
339
277
    private boolean matches(String cnb, String targetCluster) {
340
    private boolean matches(String cnb, String targetCluster) {
278
        for (Modules ps : modules) {
341
        for (Modules ps : modules) {
279
            if (ps.clusters != null) {
342
            if (ps.clusters != null) {
(-)a/nbbuild/antsrc/org/netbeans/nbbuild/MakeNBM.java (-2 / +136 lines)
Lines 58-63 Link Here
58
import java.util.ArrayList;
58
import java.util.ArrayList;
59
import java.util.Collections;
59
import java.util.Collections;
60
import java.util.Date;
60
import java.util.Date;
61
import java.util.Enumeration;
61
import java.util.Iterator;
62
import java.util.Iterator;
62
import java.util.List;
63
import java.util.List;
63
import java.util.Locale;
64
import java.util.Locale;
Lines 66-73 Link Here
66
import java.util.StringTokenizer;
67
import java.util.StringTokenizer;
67
import java.util.jar.Attributes;
68
import java.util.jar.Attributes;
68
import java.util.jar.Attributes.Name;
69
import java.util.jar.Attributes.Name;
70
import java.util.jar.JarEntry;
69
import java.util.jar.JarFile;
71
import java.util.jar.JarFile;
72
import java.util.jar.Pack200;
73
import java.util.jar.Pack200.Packer;
70
import java.util.zip.CRC32;
74
import java.util.zip.CRC32;
75
import java.util.zip.GZIPOutputStream;
71
import java.util.zip.ZipEntry;
76
import java.util.zip.ZipEntry;
72
import javax.xml.parsers.DocumentBuilderFactory;
77
import javax.xml.parsers.DocumentBuilderFactory;
73
import javax.xml.parsers.ParserConfigurationException;
78
import javax.xml.parsers.ParserConfigurationException;
Lines 323-328 Link Here
323
    private Attributes englishAttr = null;
328
    private Attributes englishAttr = null;
324
    private Path updaterJar;
329
    private Path updaterJar;
325
    private FileSet executablesSet;
330
    private FileSet executablesSet;
331
    private boolean usePack200;
332
    private String pack200excludes;
333
    private final static Packer packer = Pack200.newPacker();
326
334
327
    /** Try to find and create localized info.xml files */
335
    /** Try to find and create localized info.xml files */
328
    public void setLocales(String s) {
336
    public void setLocales(String s) {
Lines 346-351 Link Here
346
        this.file = file;
354
        this.file = file;
347
    }
355
    }
348
356
357
    public void setUsePack200(boolean usePack200) {
358
        this.usePack200 = usePack200;
359
    }
360
361
    public void setPack200Excludes(String pack200excludes) {
362
        this.pack200excludes = pack200excludes;
363
    }
364
349
    /** List of executable files in NBM concatinated by ${line.separator}. */
365
    /** List of executable files in NBM concatinated by ${line.separator}. */
350
    public FileSet createExecutables() {
366
    public FileSet createExecutables() {
351
        return (executablesSet = new FileSet());
367
        return (executablesSet = new FileSet());
Lines 648-655 Link Here
648
 	ZipFileSet fs = new ZipFileSet();
664
 	ZipFileSet fs = new ZipFileSet();
649
        List <String> moduleFiles = new ArrayList <String>();
665
        List <String> moduleFiles = new ArrayList <String>();
650
 	fs.setDir( productDir );
666
 	fs.setDir( productDir );
651
 	for (int i=0; i < files.length; i++) {
667
        String [] filesForPackaging = null;
652
 	    fs.createInclude().setName( files[i] );
668
        if(usePack200 && pack200excludes!=null && !pack200excludes.equals("")) {
669
            FileSet pack200Files = new FileSet();
670
            pack200Files.setDir(productDir);
671
            pack200Files.setExcludes(pack200excludes);
672
            pack200Files.setProject(getProject());
673
            for (int i=0; i < files.length; i++) {
674
                  pack200Files.createInclude().setName( files[i] );
675
            }
676
            DirectoryScanner ds = pack200Files.getDirectoryScanner();
677
            ds.scan();
678
            filesForPackaging = ds.getIncludedFiles();            
679
        }
680
681
        List<File> packedFiles = new ArrayList<File>();
682
        for (int i = 0; i < files.length; i++) {
683
            if (usePack200) {
684
                File sourceFile = new File(productDir, files[i]);
685
                if (sourceFile.isFile() && sourceFile.getName().endsWith(".jar")) {
686
687
                    boolean doPackage = true;
688
                    if (filesForPackaging != null) {
689
                        doPackage = false;
690
                        for (String f : filesForPackaging) {
691
                            if (new File(productDir, f).equals(sourceFile)) {
692
                                doPackage = true;
693
                                break;
694
                            }
695
                        }
696
                    }
697
                    if(doPackage) {
698
                        //if both <filename>.jar and <filename>.jad exist - skip it
699
                        //if both <filename>.jar and <filename>.jar.pack.gz exist - skip it                        
700
                        for (String f : files) {
701
                            if(f.equals(files[i].substring(0, files[i].lastIndexOf(".jar")) + ".jad") ||
702
                                    f.equals(files[i] + ".pack.gz")) {
703
                                doPackage = false;
704
                                break;
705
                            }
706
                        }
707
708
                    }
709
                    if (doPackage) {
710
                        File targetFile = new File(productDir, files[i] + ".pack.gz");
711
                        try {
712
                            if (pack200(sourceFile, targetFile)) {
713
                                packedFiles.add(targetFile);
714
                                files[i] = files[i] + ".pack.gz";
715
                            }
716
                        } catch (IOException e) {
717
                            if(targetFile.exists()) {
718
                                targetFile.delete();
719
                            }
720
                            log("Can`t pack file " + sourceFile, e, Project.MSG_WARN);
721
                        }
722
                    }
723
                }
724
            }
725
726
            fs.createInclude().setName(files[i]);
653
            moduleFiles.add(files[i]);
727
            moduleFiles.add(files[i]);
654
        }
728
        }
655
 	fs.setPrefix("netbeans/");
729
 	fs.setPrefix("netbeans/");
Lines 715-720 Link Here
715
	jar.setLocation(getLocation());
789
	jar.setLocation(getLocation());
716
	jar.init ();
790
	jar.init ();
717
	jar.execute ();
791
	jar.execute ();
792
        for(File f : packedFiles) {
793
            f.delete();
794
        }
718
795
719
	// Print messages if we overrode anything. //
796
	// Print messages if we overrode anything. //
720
        if (nbm.lastModified() != jarModified) {
797
        if (nbm.lastModified() != jarModified) {
Lines 766-771 Link Here
766
	}
843
	}
767
    }
844
    }
768
845
846
    private boolean isSigned(final JarFile jar) throws IOException {
847
        Enumeration<JarEntry> entries = jar.entries();
848
        boolean signatureInfoPresent = false;
849
        boolean signatureFilePresent = false;
850
        while (entries.hasMoreElements()) {
851
            String entryName = entries.nextElement().getName();
852
            if (entryName.startsWith("META-INF/")) {
853
                if (entryName.endsWith(".RSA") || entryName.endsWith(".DSA")) {
854
                    signatureFilePresent = true;
855
                    if (signatureInfoPresent) {
856
                        break;
857
                    }
858
                } else if (entryName.endsWith(".SF")) {
859
                    signatureInfoPresent = true;
860
                    if (signatureFilePresent) {
861
                        break;
862
                    }
863
                }
864
            }
865
        }
866
        return signatureFilePresent && signatureInfoPresent;
867
    }
868
869
   private boolean pack200(final File sourceFile, final File targetFile) throws IOException {
870
       OutputStream outputStream = null;
871
       JarFile jarFile = null;
872
       boolean result = false;
873
        try {
874
            jarFile = new JarFile(sourceFile);
875
            if(!isSigned(jarFile)) {
876
                outputStream = new GZIPOutputStream(new FileOutputStream(targetFile));
877
                packer.pack(jarFile, outputStream);
878
                result = true;
879
            }
880
        } finally {
881
            if(jarFile!=null) {
882
                try {
883
                    jarFile.close();
884
                } catch (IOException e) {
885
                    log("Cannot close output stream jar for file " + sourceFile, e, Project.MSG_WARN);
886
                }
887
            }
888
            if(outputStream!=null) {                
889
                try {
890
                    outputStream.close();
891
                } catch (IOException e) {
892
                    log("Cannot close output stream for file " + targetFile, e, Project.MSG_WARN);
893
                }
894
                if(result) {
895
                    targetFile.setLastModified(sourceFile.lastModified());
896
                }
897
            }
898
        }
899
        return result;
900
    }
901
902
769
    private Document createInfoXml(final Attributes attr) throws BuildException {
903
    private Document createInfoXml(final Attributes attr) throws BuildException {
770
        DOMImplementation domimpl;
904
        DOMImplementation domimpl;
771
        try {
905
        try {
(-)a/nbbuild/templates/common.xml (+4 lines)
Lines 407-412 Link Here
407
        <mkdir dir="build"/>
407
        <mkdir dir="build"/>
408
        <property name="nbm.target.cluster" value=""/> <!-- fallback -->
408
        <property name="nbm.target.cluster" value=""/> <!-- fallback -->
409
        <property name="license.file.override" value="${license.file}"/>
409
        <property name="license.file.override" value="${license.file}"/>
410
        <property name="usepack200" value="true"/>
411
        <property name="pack200.excludes" value=""/>
410
        <makenbm file="build/${nbm}"
412
        <makenbm file="build/${nbm}"
411
                 productdir="${cluster}"
413
                 productdir="${cluster}"
412
                 module="${module.jar}"
414
                 module="${module.jar}"
Lines 414-419 Link Here
414
                 distribution="${nbm.distribution}"
416
                 distribution="${nbm.distribution}"
415
                 needsrestart="${nbm.needs.restart}"
417
                 needsrestart="${nbm.needs.restart}"
416
                 global="${nbm.is.global}"
418
                 global="${nbm.is.global}"
419
                 usepack200="${usepack200}"
420
                 pack200excludes="${pack200.excludes}"
417
                 targetcluster="${nbm.target.cluster}"
421
                 targetcluster="${nbm.target.cluster}"
418
                 releasedate="${nbm.release.date}"
422
                 releasedate="${nbm.release.date}"
419
                 moduleauthor="${nbm.module.author}">
423
                 moduleauthor="${nbm.module.author}">

Return to bug 84852