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 195041
Collapse All | Expand All

(-)a/autoupdate.services/libsrc/org/netbeans/updater/ModuleUpdater.java (+49 lines)
Lines 45-50 Link Here
45
package org.netbeans.updater;
45
package org.netbeans.updater;
46
46
47
import java.io.*;
47
import java.io.*;
48
import java.net.URL;
49
import java.net.URLConnection;
48
import java.util.*;
50
import java.util.*;
49
import java.util.jar.*;
51
import java.util.jar.*;
50
52
Lines 424-429 Link Here
424
                                    filesToChmod.add(destFile);
426
                                    filesToChmod.add(destFile);
425
                                }
427
                                }
426
                                long crc = entry.getCrc();
428
                                long crc = entry.getCrc();
429
                                if (pathTo.endsWith(".jar.external")) {
430
                                    File downloaded = new File(destFile.getParentFile(), destFile.getName().substring(0, destFile.getName().lastIndexOf(".external")));
431
                                    final InputStream spec = jarFile.getInputStream(entry);
432
                                    InputStream is = externalDownload(spec);
433
                                    spec.close();
434
                                    FileOutputStream os = new FileOutputStream(downloaded);
435
                                    copyStreams(is, os, -1);
436
                                    is.close();
437
                                    os.close();
438
                                    crc = UpdateTracking.getFileCRC(downloaded);
439
                                }
427
                                if(pathTo.endsWith(".jar.pack.gz") &&
440
                                if(pathTo.endsWith(".jar.pack.gz") &&
428
                                        jarFile.getEntry(entry.getName().substring(0, entry.getName().lastIndexOf(".pack.gz")))==null) {
441
                                        jarFile.getEntry(entry.getName().substring(0, entry.getName().lastIndexOf(".pack.gz")))==null) {
429
                                     //check if file.jar.pack.gz does not exit for file.jar - then unpack current .pack.gz file
442
                                     //check if file.jar.pack.gz does not exit for file.jar - then unpack current .pack.gz file
Lines 516-521 Link Here
516
            t.deleteUnusedFiles ();            
529
            t.deleteUnusedFiles ();            
517
        }
530
        }
518
    }
531
    }
532
    private InputStream externalDownload(InputStream is) throws IOException {
533
        BufferedReader br = new BufferedReader(new InputStreamReader(is));
534
        URLConnection conn;
535
        for (;;) {
536
            String line = br.readLine();
537
            if (line == null) {
538
                break;
539
            }
540
            if (line.startsWith("URL:")) {
541
                String url = line.substring(4).trim();
542
                for (;;) {
543
                    int index = url.indexOf("${");
544
                    if (index == -1) {
545
                        break;
546
                    }
547
                    int end = url.indexOf("}", index);
548
                    String propName = url.substring(index + 2, end);
549
                    final String propVal = System.getProperty(propName);
550
                    if (propVal == null) {
551
                        throw new IOException("Can't find property " + propName);
552
                    }
553
                    url = url.substring(0, index) + propVal + url.substring(end + 1);
554
                }
555
                XMLUtil.LOG.log(Level.INFO, "Trying external URL: {0}", url);
556
                try {
557
                    conn = new URL(url).openConnection();
558
                    conn.connect();
559
                    return conn.getInputStream();
560
                } catch (IOException ex) {
561
                    XMLUtil.LOG.log(Level.WARNING, "Cannot connect to {0}", url);
562
                    XMLUtil.LOG.log(Level.INFO, "Details", ex);
563
                }
564
            }
565
        }
566
        throw new IOException("Cannot resolve external references");
567
    }
519
    
568
    
520
    private boolean unpack200(File src, File dest) {
569
    private boolean unpack200(File src, File dest) {
521
        String unpack200Executable = new File(System.getProperty("java.home"),
570
        String unpack200Executable = new File(System.getProperty("java.home"),
(-)3364ee25de93 (+322 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2010 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2010 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.autoupdate.services;
43
44
import java.io.File;
45
import java.io.FileInputStream;
46
import java.io.FileOutputStream;
47
import java.io.IOException;
48
import java.io.OutputStream;
49
import java.io.OutputStreamWriter;
50
import java.io.PrintWriter;
51
import java.net.URL;
52
import java.util.ArrayList;
53
import java.util.List;
54
import java.util.jar.Attributes;
55
import java.util.jar.JarFile;
56
import java.util.jar.JarOutputStream;
57
import java.util.jar.Manifest;
58
import java.util.jar.Pack200;
59
import java.util.logging.Level;
60
import java.util.zip.GZIPOutputStream;
61
import java.util.zip.ZipEntry;
62
import org.netbeans.api.autoupdate.InstallSupport;
63
import org.netbeans.api.autoupdate.OperationContainer;
64
import org.netbeans.api.autoupdate.OperationContainer.OperationInfo;
65
import org.netbeans.api.autoupdate.OperationException;
66
import org.netbeans.api.autoupdate.OperationSupport.Restarter;
67
import org.netbeans.api.autoupdate.TestUtils;
68
import org.netbeans.api.autoupdate.UpdateElement;
69
import org.netbeans.api.autoupdate.UpdateUnit;
70
import org.netbeans.api.autoupdate.UpdateUnitProvider;
71
import org.netbeans.api.autoupdate.UpdateUnitProviderFactory;
72
import org.netbeans.core.startup.MainLookup;
73
import org.netbeans.junit.NbTestCase;
74
import org.netbeans.modules.autoupdate.updateprovider.AutoupdateCatalogProvider;
75
import org.openide.filesystems.FileUtil;
76
import org.openide.util.Lookup;
77
78
public class NbmExternalTest 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 NbmExternalTest(String testName) {
88
        super(testName);
89
    }
90
91
    @Override
92
    protected Level logLevel() {
93
        return Level.FINE;
94
    }
95
96
    
97
    public static class MyProvider extends AutoupdateCatalogProvider {
98
99
        public MyProvider() {
100
            super("test-updates-provider", "test-updates-provider", catalogURL, UpdateUnitProvider.CATEGORY.STANDARD);
101
        }
102
    }
103
104
    private String getModuleElement(boolean visible, String codeName, String releaseVersion, String implVersion, String moduleName, String distr, String specVersion, String dependency) {
105
        String releaseVersionAppendix = ((releaseVersion != null /*&& Integer.parseInt(releaseVersion)!=0*/) ? ("/" + releaseVersion) : "");
106
        return "\n<module "
107
                + "\n     codenamebase='" + codeName + "' "
108
                + "\n     distribution='" + distr + "' "
109
                + "\n     downloadsize='0' "
110
                + "\n     homepage='' "
111
                + "\n     license='AD9FBBC9' "
112
                + "\n     moduleauthor='' "
113
                + "\n     needsrestart='false' "
114
                + "\n     releasedate='2007/01/30'>"
115
                + "\n    <manifest "
116
                + "\n       AutoUpdate-Show-In-Client='" + visible + "' "
117
                + "\n       OpenIDE-Module='" + codeName + releaseVersionAppendix + "'"
118
                + "\n       OpenIDE-Module-Implementation-Version='" + (implVersion == null ? "070130" : implVersion) + "' "
119
                + "\n       OpenIDE-Module-Java-Dependencies='Java &gt; 1.4' "
120
                + "\n       OpenIDE-Module-Name='" + moduleName + "' "
121
                + (dependency != null ? " OpenIDE-Module-Module-Dependencies=\"" + dependency.replace(">", "&gt;") + "\" " : "")
122
                + "\n       OpenIDE-Module-Requires='org.openide.modules.ModuleFormat1' "
123
                + "\n       OpenIDE-Module-Specification-Version='" + specVersion + "'/>"
124
                + "\n</module>";
125
    }
126
127
    private String createInfoXML(boolean visible, String codeName, String releaseVersion, String implVersion, String moduleName, String distr, String specVersion, String dependency) {
128
        String moduleElement = getModuleElement(visible, codeName, releaseVersion, implVersion, moduleName, distr, specVersion, dependency);
129
130
        moduleElements.add(moduleElement);
131
        moduleElements.add("\n    <license name='AD9FBBC9'>[NO LICENSE SPECIFIED]"
132
                         + "\n</license>\n");
133
        return "<?xml version='1.0' encoding='UTF-8'?>"
134
                + "<!DOCTYPE module PUBLIC '-//NetBeans//DTD Autoupdate Module Info 2.5//EN' 'http://www.netbeans.org/dtds/autoupdate-info-2_5.dtd'>"
135
                + moduleElement;
136
    }
137
138
    private void writeCatalog() throws IOException {
139
        String res = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
140
                + "<!DOCTYPE module_updates PUBLIC \"-//NetBeans//DTD Autoupdate Catalog 2.5//EN\" \"http://www.netbeans.org/dtds/autoupdate-catalog-2_5.dtd\">"
141
                + "<module_updates timestamp=\"00/00/19/08/03/2006\">\n";
142
        for (String element : moduleElements) {
143
            res += element;
144
        }
145
        res += "</module_updates>\n";
146
        if (catalogFile == null) {
147
            catalogFile = File.createTempFile("catalog-", ".xml", tmpDirectory);
148
            catalogURL = catalogFile.toURI().toURL();
149
        }
150
        PrintWriter pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream(catalogFile), "UTF-8"));
151
        pw.write(res);
152
        pw.close();
153
    }
154
155
    private String getConfigXML(String codeName, String moduleFile, String specVersion) {
156
        return "<?xml version='1.0' encoding='UTF-8'?>"
157
                + " <!DOCTYPE module PUBLIC '-//NetBeans//DTD Module Status 1.0//EN'"
158
                + " 'http://www.netbeans.org/dtds/module-status-1_0.dtd'>"
159
                + " <module name='" + codeName + "'>"
160
                + " <param name='autoload'>false</param>"
161
                + " <param name='eager'>false</param>"
162
                + " <param name='enabled'>true</param>"
163
                + " <param name='jar'>modules/" + moduleFile + ".jar</param>"
164
                + " <param name='reloadable'>false</param>"
165
                + " <param name='specversion'>" + specVersion + "</param>"
166
                + " </module>";
167
    }
168
169
    private String getManifest(String codeName, String releaseVersion, String implVersion, String moduleDir, String specVersion, boolean visible, String dependency) {
170
        String releaseVersionAppendix = ((releaseVersion != null /*&& Integer.parseInt(releaseVersion)!=0*/) ? ("/" + releaseVersion) : "");
171
        return "Manifest-Version: 1.0\n"
172
                + "Ant-Version: Apache Ant 1.7.0\n"
173
                + "Created-By: 1.6.0-b105 (Sun Microsystems Inc.)\n"
174
                + "OpenIDE-Module-Public-Packages: -\n"
175
                + "OpenIDE-Module-Java-Dependencies: Java > 1.4\n"
176
                + "OpenIDE-Module-Implementation-Version: " + (implVersion == null ? "070130" : implVersion)
177
                + "\n"
178
                + (dependency != null ? ("OpenIDE-Module-Module-Dependencies: " + dependency + "\n") : "")
179
                + "OpenIDE-Module: " + codeName + releaseVersionAppendix
180
                + "\n"
181
                + "OpenIDE-Module-Localizing-Bundle: " + moduleDir + "Bundle.properties\n"
182
                + "OpenIDE-Module-Specification-Version: " + specVersion + "\n"
183
                + "OpenIDE-Module-Requires: org.openide.modules.ModuleFormat1\n"
184
                + "AutoUpdate-Show-In-Client: " + visible + "\n"
185
                + "\n";
186
    }
187
188
    private File prepareNBM(String codeName, String releaseVersion, String implVersion, String specVersion, boolean visible, String dependency) throws Exception {
189
        String moduleName = codeName.substring(codeName.lastIndexOf(".") + 1);
190
        String moduleFile = codeName.replace(".", "-");
191
        String moduleDir = codeName.replace(".", "/") + "/";
192
        File nbm = File.createTempFile(moduleFile + "-", ".nbm", tmpDirectory);
193
194
        final String MODULE_NAME_PROP = "OpenIDE-Module-Name";
195
196
        File jar = new File(tmpDirectory, "x.jar");
197
        jar.getParentFile().mkdirs();
198
        JarOutputStream jos = new JarOutputStream(new FileOutputStream(jar));
199
        int idx = moduleDir.indexOf("/");
200
        while (idx != -1) {
201
            jos.putNextEntry(new ZipEntry(moduleDir.substring(0, idx + 1)));
202
            idx = moduleDir.indexOf("/", idx + 1);
203
        }
204
205
        jos.putNextEntry(new ZipEntry(moduleDir + "Bundle.properties"));
206
        jos.write(new String(MODULE_NAME_PROP + "=" + moduleName).getBytes("UTF-8"));
207
        jos.putNextEntry(new ZipEntry("META-INF/"));
208
        jos.putNextEntry(new ZipEntry("META-INF/manifest.mf"));
209
        jos.write(getManifest(codeName, releaseVersion, implVersion, moduleDir, specVersion, visible, dependency).getBytes("UTF-8"));
210
        jos.close();
211
        File ext = new File(jar.getParentFile(), jar.getName() + ".external");
212
        FileOutputStream os = new FileOutputStream(ext);
213
        os.write(("URL: " + jar.toURI().toString() + "\n").getBytes());
214
        os.close();
215
216
        Manifest mf = new Manifest();
217
        mf.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
218
219
220
        jos = new JarOutputStream(new FileOutputStream(nbm), mf);
221
        jos.putNextEntry(new ZipEntry("Info/"));
222
        jos.putNextEntry(new ZipEntry("Info/info.xml"));
223
        jos.write(createInfoXML(visible, codeName, releaseVersion, implVersion, moduleName, nbm.toURI().toURL().toString(), specVersion, dependency).getBytes("UTF-8"));
224
225
        jos.putNextEntry(new ZipEntry("netbeans/"));
226
        jos.putNextEntry(new ZipEntry("netbeans/modules/"));
227
        jos.putNextEntry(new ZipEntry("netbeans/config/"));
228
        jos.putNextEntry(new ZipEntry("netbeans/config/Modules/"));
229
        jos.putNextEntry(new ZipEntry("netbeans/config/Modules/" + moduleFile + ".xml"));
230
231
        jos.write(getConfigXML(codeName, moduleFile, specVersion).getBytes("UTF-8"));
232
233
234
        jos.putNextEntry(new ZipEntry("netbeans/modules/" + moduleFile + ".jar.external"));
235
236
        FileInputStream fis = new FileInputStream(ext);
237
        FileUtil.copy(fis, jos);
238
        fis.close();
239
        ext.delete();
240
        jos.close();
241
        nbms.add(nbm);
242
243
        return nbm;
244
    }
245
246
    protected void setUp() throws Exception {
247
        super.setUp();
248
        this.clearWorkDir();
249
        tmpDirectory = new File(getWorkDirPath(), "tmp");
250
        tmpDirectory.mkdirs();
251
252
        writeCatalog();
253
254
        TestUtils.setUserDir(getWorkDirPath());
255
        TestUtils.testInit();
256
257
        MainLookup.register(new MyProvider());
258
        assert Lookup.getDefault().lookup(MyProvider.class) != null;
259
        UpdateUnitProviderFactory.getDefault().refreshProviders(null, true);
260
    }
261
262
    private void doInstall(OperationContainer<InstallSupport> installContainer) throws OperationException {
263
        InstallSupport support = installContainer.getSupport();
264
        assertNotNull(support);
265
266
        InstallSupport.Validator v = support.doDownload(null, false);
267
        assertNotNull(v);
268
        InstallSupport.Installer i = support.doValidate(v, null);
269
        assertNotNull(i);
270
        Restarter r = null;
271
        try {
272
            r = support.doInstall(i, null);
273
        } catch (OperationException ex) {
274
            if (OperationException.ERROR_TYPE.INSTALL == ex.getErrorType()) {
275
                // can ingore
276
                // module system cannot load the module either
277
            } else {
278
                fail(ex.toString());
279
            }
280
        }
281
        assertNull("Installing new element require restarting though it should not", r);
282
    }
283
284
    public void testNbmWithExternal() throws Exception {
285
        String moduleCNB = "org.netbeans.modules.mymodule";
286
        String moduleReleaseVersion = "1";
287
        String moduleImplVersion = "2";
288
        String moduleSpecVersion = "1.0";
289
290
        prepareNBM(moduleCNB, moduleReleaseVersion, moduleImplVersion, moduleSpecVersion, false, null);
291
292
        writeCatalog();
293
        UpdateUnitProviderFactory.getDefault().refreshProviders(null, true);
294
        OperationContainer<InstallSupport> installContainer = OperationContainer.createForInstall();
295
        UpdateUnit moduleUnit = getUpdateUnit(moduleCNB);
296
        assertNull("cannot be installed", moduleUnit.getInstalled());
297
        UpdateElement moduleElement = getAvailableUpdate(moduleUnit, 0);
298
        assertEquals(moduleElement.getSpecificationVersion(), moduleSpecVersion);
299
        OperationInfo<InstallSupport> independentInfo = installContainer.add(moduleElement);
300
        assertNotNull(independentInfo);
301
        doInstall(installContainer);
302
        
303
        File module = new File(new File(getWorkDir(), "modules"), "org-netbeans-modules-mymodule.jar");
304
        assertTrue("module file exists", module.exists());
305
        assertTrue("module was not installed from NBM external", moduleUnit.getInstalled() != null);
306
    }
307
308
    
309
310
    public UpdateUnit getUpdateUnit(String codeNameBase) {
311
        UpdateUnit uu = UpdateManagerImpl.getInstance().getUpdateUnit(codeNameBase);
312
        assertNotNull(uu);
313
        return uu;
314
    }
315
316
    public UpdateElement getAvailableUpdate(UpdateUnit updateUnit, int idx) {
317
        List<UpdateElement> available = updateUnit.getAvailableUpdates();
318
        assertTrue(available.size() > idx);
319
        return available.get(idx);
320
321
    }
322
}
(-)a/nbbuild/antsrc/org/netbeans/nbbuild/AutoUpdate.java (-1 / +49 lines)
Lines 43-62 Link Here
43
package org.netbeans.nbbuild;
43
package org.netbeans.nbbuild;
44
44
45
import java.io.BufferedInputStream;
45
import java.io.BufferedInputStream;
46
import java.io.BufferedReader;
46
import java.io.ByteArrayInputStream;
47
import java.io.ByteArrayInputStream;
47
import java.io.File;
48
import java.io.File;
48
import java.io.FileInputStream;
49
import java.io.FileInputStream;
49
import java.io.FileOutputStream;
50
import java.io.FileOutputStream;
50
import java.io.IOException;
51
import java.io.IOException;
51
import java.io.InputStream;
52
import java.io.InputStream;
53
import java.io.InputStreamReader;
52
import java.io.OutputStream;
54
import java.io.OutputStream;
53
import java.net.URISyntaxException;
55
import java.net.URISyntaxException;
54
import java.net.URL;
56
import java.net.URL;
57
import java.net.URLConnection;
55
import java.util.ArrayList;
58
import java.util.ArrayList;
56
import java.util.Enumeration;
59
import java.util.Enumeration;
57
import java.util.HashMap;
60
import java.util.HashMap;
58
import java.util.List;
61
import java.util.List;
59
import java.util.Map;
62
import java.util.Map;
63
import java.util.concurrent.atomic.AtomicLong;
60
import java.util.regex.Pattern;
64
import java.util.regex.Pattern;
61
import java.util.zip.CRC32;
65
import java.util.zip.CRC32;
62
import java.util.zip.ZipEntry;
66
import java.util.zip.ZipEntry;
Lines 251-261 Link Here
251
                    log("Writing " + trgt, Project.MSG_VERBOSE);
255
                    log("Writing " + trgt, Project.MSG_VERBOSE);
252
256
253
                    InputStream is = zf.getInputStream(zipEntry);
257
                    InputStream is = zf.getInputStream(zipEntry);
254
                    OutputStream os = new FileOutputStream(trgt);
255
                    boolean doUnpack200 = false;
258
                    boolean doUnpack200 = false;
256
                    if(relName.endsWith(".jar.pack.gz") && zf.getEntry(zipEntry.getName().substring(0, zipEntry.getName().length() - 8))==null) {
259
                    if(relName.endsWith(".jar.pack.gz") && zf.getEntry(zipEntry.getName().substring(0, zipEntry.getName().length() - 8))==null) {
257
                        doUnpack200 = true;
260
                        doUnpack200 = true;
258
                    }
261
                    }
262
                    OutputStream os;
263
                    if (relName.endsWith(".external")) {
264
                        is = externalDownload(is);
265
                        File dest = new File(trgt.getParentFile(), trgt.getName().substring(0, trgt.getName().length() - 9));
266
                        os = new FileOutputStream(dest);
267
                    } else {
268
                        os = new FileOutputStream(trgt);
269
                    }
259
                    CRC32 crc = new CRC32();
270
                    CRC32 crc = new CRC32();
260
                    for (;;) {
271
                    for (;;) {
261
                        int len = is.read(bytes);
272
                        int len = is.read(bytes);
Lines 303-308 Link Here
303
            }
314
            }
304
        }
315
        }
305
    }
316
    }
317
    
318
    private InputStream externalDownload(InputStream is) throws IOException {
319
        BufferedReader br = new BufferedReader(new InputStreamReader(is));
320
        URLConnection conn;
321
        for (;;) {
322
            String line = br.readLine();
323
            if (line == null) {
324
                break;
325
            }
326
            if (line.startsWith("URL:")) {
327
                String url = line.substring(4).trim();
328
                for (;;) {
329
                    int index = url.indexOf("${");
330
                    if (index == -1) {
331
                        break;
332
                    }
333
                    int end = url.indexOf("}", index);
334
                    String propName = url.substring(index + 2, end);
335
                    final String propVal = System.getProperty(propName);
336
                    if (propVal == null) {
337
                        throw new IOException("Can't find property " + propName);
338
                    }
339
                    url = url.substring(0, index) + propVal + url.substring(end + 1);
340
                }
341
                log("Trying external URL: " + url, Project.MSG_INFO);
342
                try {
343
                    conn = new URL(url).openConnection();
344
                    conn.connect();
345
                    return conn.getInputStream();
346
                } catch (IOException ex) {
347
                    log("Cannot connect to " + url, Project.MSG_WARN);
348
                    log("Details", ex, Project.MSG_VERBOSE);
349
                }
350
            }
351
        }
352
        throw new IOException("Cannot resolve external references");
353
    }
306
354
307
    
355
    
308
    public static boolean unpack200(File src, File dest) {
356
    public static boolean unpack200(File src, File dest) {
(-)a/nbbuild/test/unit/src/org/netbeans/nbbuild/AutoUpdateTest.java (-3 / +162 lines)
Lines 45-50 Link Here
45
import java.io.File;
45
import java.io.File;
46
import java.io.FileOutputStream;
46
import java.io.FileOutputStream;
47
import java.io.IOException;
47
import java.io.IOException;
48
import java.util.ArrayList;
49
import java.util.List;
48
import java.util.zip.ZipEntry;
50
import java.util.zip.ZipEntry;
49
import java.util.zip.ZipOutputStream;
51
import java.util.zip.ZipOutputStream;
50
import org.w3c.dom.Document;
52
import org.w3c.dom.Document;
Lines 131-137 Link Here
131
        File lastM = new File(new File(target, "platform"), ".lastModified");
133
        File lastM = new File(new File(target, "platform"), ".lastModified");
132
        assertTrue("Last modified file created", lastM.exists());
134
        assertTrue("Last modified file created", lastM.exists());
133
    }
135
    }
136
    
137
    
138
    public void testDownloadAndExtractExternal() throws Exception {
139
        File f = new File(getWorkDir(), "org-netbeans-api-annotations-common.xml");
140
        extractResource(f, "org-netbeans-api-annotations-common.xml");
141
        
142
        File ext = extractString("external content");
143
        
144
        String extRef =
145
            "URL: " + ext.toURI().toString() + "\n";
134
146
147
        File nbm = generateNBMContent("org-netbeans-api-annotations-common.nbm",
148
            "netbeans/config/Modules/org-netbeans-api-annotations-common.xml", "empty",
149
            "netbeans/modules/org-netbeans-api-annotations-common.jar.external", extRef,
150
            "netbeans/docs/My Manager's So-Called \"README\"", "empty");
151
152
        File target = new File(getWorkDir(), "target");
153
        target.mkdirs();
154
155
        execute(
156
            "autoupdate.xml", "-verbose", "-Durl=" + f.toURI().toURL(),
157
            "-Dincludes=org.netbeans.api.annotations.common",
158
            "-Dtarget=" + target
159
        );
160
161
        File xml = new File(
162
            new File(new File(target, "platform"), "update_tracking"),
163
            "org-netbeans-api-annotations-common.xml"
164
        );
165
        assertTrue("xml file created", xml.exists());
166
        Document doc = XMLUtil.parse(new InputSource(xml.toURI().toString()), false, false, null, null);
167
        NodeList nl = doc.getElementsByTagName("file");
168
        assertEquals(3, nl.getLength());
169
        assertEquals("docs/My Manager's So-Called \"README\"", ((Element) nl.item(2)).getAttribute("name"));
170
171
        File jar = new File(
172
            new File(new File(target, "platform"), "modules"),
173
            "org-netbeans-api-annotations-common.jar"
174
        );
175
        File jarExt = new File(
176
            new File(new File(target, "platform"), "modules"),
177
            "org-netbeans-api-annotations-common.jar.external"
178
        );
179
        assertFalse("no external file created", jarExt.exists());
180
        assertTrue("jar file created", jar.exists());
181
        assertEquals("Contains expected", "external content", readFile(jar));
182
183
        File lastM = new File(new File(target, "platform"), ".lastModified");
184
        assertTrue("Last modified file created", lastM.exists());
185
    }
186
187
    public void testDownloadAndExtractExternalWithFirstURLBroken() throws Exception {
188
        File f = new File(getWorkDir(), "org-netbeans-api-annotations-common.xml");
189
        extractResource(f, "org-netbeans-api-annotations-common.xml");
190
        
191
        File ext = extractString("external content");
192
        
193
        String extRef =
194
            "URL: file:/I/dont/exist/At/All\n" +
195
            "URL: " + ext.toURI().toString() + "\n";
196
197
        File nbm = generateNBMContent("org-netbeans-api-annotations-common.nbm",
198
            "netbeans/config/Modules/org-netbeans-api-annotations-common.xml", "empty",
199
            "netbeans/modules/org-netbeans-api-annotations-common.jar.external", extRef,
200
            "netbeans/docs/My Manager's So-Called \"README\"", "empty");
201
202
        File target = new File(getWorkDir(), "target");
203
        target.mkdirs();
204
205
        execute(
206
            "autoupdate.xml", "-verbose", "-Durl=" + f.toURI().toURL(),
207
            "-Dincludes=org.netbeans.api.annotations.common",
208
            "-Dtarget=" + target
209
        );
210
211
        File xml = new File(
212
            new File(new File(target, "platform"), "update_tracking"),
213
            "org-netbeans-api-annotations-common.xml"
214
        );
215
        assertTrue("xml file created", xml.exists());
216
        Document doc = XMLUtil.parse(new InputSource(xml.toURI().toString()), false, false, null, null);
217
        NodeList nl = doc.getElementsByTagName("file");
218
        assertEquals(3, nl.getLength());
219
        assertEquals("docs/My Manager's So-Called \"README\"", ((Element) nl.item(2)).getAttribute("name"));
220
221
        File jar = new File(
222
            new File(new File(target, "platform"), "modules"),
223
            "org-netbeans-api-annotations-common.jar"
224
        );
225
        File jarExt = new File(
226
            new File(new File(target, "platform"), "modules"),
227
            "org-netbeans-api-annotations-common.jar.external"
228
        );
229
        assertFalse("no external file created", jarExt.exists());
230
        assertTrue("jar file created", jar.exists());
231
        assertEquals("Contains expected", "external content", readFile(jar));
232
233
        File lastM = new File(new File(target, "platform"), ".lastModified");
234
        assertTrue("Last modified file created", lastM.exists());
235
    }
236
    
237
    public void testDownloadAndExtractExternalWithProperty() throws Exception {
238
        File f = new File(getWorkDir(), "org-netbeans-api-annotations-common.xml");
239
        extractResource(f, "org-netbeans-api-annotations-common.xml");
240
        
241
        File ext = extractString("external content");
242
        System.setProperty("my.ref", ext.getParent());
243
        
244
        String extRef =
245
            "URL: file:${my.ref}/" + ext.getName() + "\n";
246
247
        File nbm = generateNBMContent("org-netbeans-api-annotations-common.nbm",
248
            "netbeans/config/Modules/org-netbeans-api-annotations-common.xml", "empty",
249
            "netbeans/modules/org-netbeans-api-annotations-common.jar.external", extRef,
250
            "netbeans/docs/My Manager's So-Called \"README\"", "empty");
251
252
        File target = new File(getWorkDir(), "target");
253
        target.mkdirs();
254
255
        execute(
256
            "autoupdate.xml", "-verbose", "-Durl=" + f.toURI().toURL(),
257
            "-Dincludes=org.netbeans.api.annotations.common",
258
            "-Dtarget=" + target
259
        );
260
261
        File xml = new File(
262
            new File(new File(target, "platform"), "update_tracking"),
263
            "org-netbeans-api-annotations-common.xml"
264
        );
265
        assertTrue("xml file created", xml.exists());
266
        Document doc = XMLUtil.parse(new InputSource(xml.toURI().toString()), false, false, null, null);
267
        NodeList nl = doc.getElementsByTagName("file");
268
        assertEquals(3, nl.getLength());
269
        assertEquals("docs/My Manager's So-Called \"README\"", ((Element) nl.item(2)).getAttribute("name"));
270
271
        File jar = new File(
272
            new File(new File(target, "platform"), "modules"),
273
            "org-netbeans-api-annotations-common.jar"
274
        );
275
        File jarExt = new File(
276
            new File(new File(target, "platform"), "modules"),
277
            "org-netbeans-api-annotations-common.jar.external"
278
        );
279
        assertFalse("no external file created", jarExt.exists());
280
        assertTrue("jar file created", jar.exists());
281
        assertEquals("Contains expected", "external content", readFile(jar));
282
283
        File lastM = new File(new File(target, "platform"), ".lastModified");
284
        assertTrue("Last modified file created", lastM.exists());
285
    }
135
286
136
    public void testUpdateAlreadyInstalled() throws Exception {
287
    public void testUpdateAlreadyInstalled() throws Exception {
137
        File f = new File(getWorkDir(), "org-netbeans-api-annotations-common.xml");
288
        File f = new File(getWorkDir(), "org-netbeans-api-annotations-common.xml");
Lines 438-449 Link Here
438
    }
589
    }
439
590
440
    public File generateNBM (String name, String... files) throws IOException {
591
    public File generateNBM (String name, String... files) throws IOException {
592
        List<String> filesAndContent = new ArrayList<String>();
593
        for (String s : files) {
594
            filesAndContent.add(s);
595
            filesAndContent.add("empty");
596
        }
597
        return generateNBMContent(name, filesAndContent.toArray(new String[0]));
598
    }
599
    public File generateNBMContent (String name, String... filesAndContent) throws IOException {
441
        File f = new File (getWorkDir (), name);
600
        File f = new File (getWorkDir (), name);
442
601
443
        ZipOutputStream os = new ZipOutputStream (new FileOutputStream (f));
602
        ZipOutputStream os = new ZipOutputStream (new FileOutputStream (f));
444
        for (String n : files) {
603
        for (int i = 0; i < filesAndContent.length; i += 2) {
445
            os.putNextEntry(new ZipEntry(n));
604
            os.putNextEntry(new ZipEntry(filesAndContent[i]));
446
            os.write("empty".getBytes());
605
            os.write(filesAndContent[i + 1].getBytes());
447
            os.closeEntry();
606
            os.closeEntry();
448
        }
607
        }
449
        os.putNextEntry(new ZipEntry("Info/info.xml"));
608
        os.putNextEntry(new ZipEntry("Info/info.xml"));

Return to bug 195041