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

(-)a/apisupport.harness/release/suite.xml (-1 / +10 lines)
Lines 210-216 Link Here
210
            <property name="${nbm.target.cluster.name}" value="${help.target.cluster}" />
210
            <property name="${nbm.target.cluster.name}" value="${help.target.cluster}" />
211
            <property name="cluster.path.evaluated" value="${cluster.path.evaluated}"/> <!-- Just for speed of pre-7.0 projects -->
211
            <property name="cluster.path.evaluated" value="${cluster.path.evaluated}"/> <!-- Just for speed of pre-7.0 projects -->
212
        </subant>
212
        </subant>
213
        <makeupdatedesc desc="${build.updates.dir}/updates.xml" distbase="." automaticgrouping="true">
213
214
        <condition property="use.license.url.in.catalog" value="true" else="false">
215
            <available resource="org/netbeans/updater/resources/autoupdate-catalog-2_6.dtd">
216
                <classpath>
217
                    <resources refid="updater.jar"/>
218
                </classpath>
219
            </available>
220
        </condition>
221
222
        <makeupdatedesc desc="${build.updates.dir}/updates.xml" distbase="." automaticgrouping="true" uselicenseurl="${use.license.url.in.catalog}">
214
            <fileset dir="${build.updates.dir}">
223
            <fileset dir="${build.updates.dir}">
215
                <include name="*.nbm"/>
224
                <include name="*.nbm"/>
216
            </fileset>
225
            </fileset>
(-)a/autoupdate.services/libsrc/org/netbeans/updater/XMLUtil.java (+2 lines)
Lines 167-172 Link Here
167
                    return new InputSource(XMLUtil.class.getResource("resources/autoupdate-catalog-2_5.dtd").toString());
167
                    return new InputSource(XMLUtil.class.getResource("resources/autoupdate-catalog-2_5.dtd").toString());
168
                } else if ("-//NetBeans//DTD Autoupdate Module Info 2.5//EN".equals(publicID)) { // NOI18N
168
                } else if ("-//NetBeans//DTD Autoupdate Module Info 2.5//EN".equals(publicID)) { // NOI18N
169
                    return new InputSource(XMLUtil.class.getResource("resources/autoupdate-info-2_5.dtd").toString());
169
                    return new InputSource(XMLUtil.class.getResource("resources/autoupdate-info-2_5.dtd").toString());
170
                } else if ("-//NetBeans//DTD Autoupdate Catalog 2.6//EN".equals(publicID)) { // NOI18N
171
                    return new InputSource(XMLUtil.class.getResource("resources/autoupdate-catalog-2_6.dtd").toString());
170
                } else {
172
                } else {
171
                    return null;
173
                    return null;
172
                }
174
                }
(-)a/autoupdate.services/libsrc/org/netbeans/updater/resources/autoupdate-catalog-2_6.dtd (+67 lines)
Line 0 Link Here
1
<!-- -//NetBeans//DTD Autoupdate Catalog 2.5//EN -->
2
<!-- XML representation of Autoupdate Modules/Updates Catalog -->
3
4
<!ELEMENT module_updates ((notification?, (module_group|module)*, license*)|error)>
5
<!ATTLIST module_updates timestamp CDATA #REQUIRED>
6
7
<!ELEMENT module_group ((module_group|module)*)>
8
<!ATTLIST module_group name CDATA #REQUIRED>
9
10
<!ELEMENT notification (#PCDATA)>
11
<!ATTLIST notification url CDATA #IMPLIED>
12
13
<!ELEMENT module (description?, module_notification?, external_package*, (manifest | l10n) )>
14
<!ATTLIST module codenamebase CDATA #REQUIRED
15
                 homepage     CDATA #IMPLIED
16
                 distribution CDATA #REQUIRED
17
                 license      CDATA #IMPLIED
18
                 downloadsize CDATA #REQUIRED
19
                 needsrestart (true|false) #IMPLIED
20
                 moduleauthor CDATA #IMPLIED
21
                 releasedate  CDATA #IMPLIED
22
                 global       (true|false) #IMPLIED
23
                 targetcluster CDATA #IMPLIED
24
                 eager (true|false) #IMPLIED
25
                 autoload (true|false) #IMPLIED>
26
27
<!ELEMENT description (#PCDATA)>
28
29
<!ELEMENT module_notification (#PCDATA)>
30
31
<!ELEMENT external_package EMPTY>
32
<!ATTLIST external_package
33
                 name CDATA #REQUIRED
34
                 target_name  CDATA #REQUIRED
35
                 start_url    CDATA #REQUIRED
36
                 description  CDATA #IMPLIED>
37
38
<!ELEMENT manifest EMPTY>
39
<!ATTLIST manifest OpenIDE-Module CDATA #REQUIRED
40
                   OpenIDE-Module-Name CDATA #REQUIRED
41
                   OpenIDE-Module-Specification-Version CDATA #REQUIRED
42
                   OpenIDE-Module-Implementation-Version CDATA #IMPLIED
43
                   OpenIDE-Module-Module-Dependencies CDATA #IMPLIED
44
                   OpenIDE-Module-Package-Dependencies CDATA #IMPLIED
45
                   OpenIDE-Module-Java-Dependencies CDATA #IMPLIED
46
                   OpenIDE-Module-IDE-Dependencies CDATA #IMPLIED
47
                   OpenIDE-Module-Short-Description CDATA #IMPLIED
48
                   OpenIDE-Module-Long-Description CDATA #IMPLIED
49
                   OpenIDE-Module-Display-Category CDATA #IMPLIED
50
                   OpenIDE-Module-Provides CDATA #IMPLIED
51
                   OpenIDE-Module-Requires CDATA #IMPLIED
52
                   OpenIDE-Module-Recommends CDATA #IMPLIED
53
                   OpenIDE-Module-Needs CDATA #IMPLIED
54
                   AutoUpdate-Show-In-Client (true|false) #IMPLIED
55
                   AutoUpdate-Essential-Module (true|false) #IMPLIED>
56
57
<!ELEMENT l10n EMPTY>
58
<!ATTLIST l10n   langcode             CDATA #IMPLIED
59
                 brandingcode         CDATA #IMPLIED
60
                 module_spec_version  CDATA #IMPLIED
61
                 module_major_version CDATA #IMPLIED
62
                 OpenIDE-Module-Name  CDATA #IMPLIED
63
                 OpenIDE-Module-Long-Description CDATA #IMPLIED>
64
65
<!ELEMENT license (#PCDATA)>
66
<!ATTLIST license name CDATA #REQUIRED
67
                  url  CDATA #IMPLIED>
(-)a/autoupdate.services/manifest.mf (-1 / +1 lines)
Lines 1-6 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.6
4
OpenIDE-Module-Specification-Version: 1.7
5
AutoUpdate-Show-In-Client: false
5
AutoUpdate-Show-In-Client: false
6
AutoUpdate-Essential-Module: true
6
AutoUpdate-Essential-Module: true
(-)a/autoupdate.services/src/org/netbeans/modules/autoupdate/services/UpdateLicenseImpl.java (-6 / +25 lines)
Lines 41-70 Link Here
41
41
42
package org.netbeans.modules.autoupdate.services;
42
package org.netbeans.modules.autoupdate.services;
43
43
44
import java.net.URL;
45
import org.netbeans.modules.autoupdate.updateprovider.AutoupdateCatalogCache;
46
44
/**
47
/**
45
 *
48
 *
46
 * @author Jiri Rechtacek
49
 * @author Jiri Rechtacek
50
 * @author Dmitry Lipin
47
 */
51
 */
48
public final class UpdateLicenseImpl {
52
public final class UpdateLicenseImpl {
49
    private String name;
53
    private String name;
50
    private String agreement;
54
    private URL url;
51
    
55
    
52
    /** Creates a new instance of UpdateLicense */
56
    /** Creates a new instance of UpdateLicense */
53
    public UpdateLicenseImpl (String licenseName, String agreement) {
57
    public UpdateLicenseImpl (String licenseName, String agreement) {
54
        this.name = licenseName;
58
        this.name = licenseName;
55
        this.agreement = agreement;
59
        setAgreement(agreement);
60
    }
61
    /** Creates a new instance of UpdateLicense */
62
    public UpdateLicenseImpl (String licenseName, String agreement, URL url) {
63
        this.name = licenseName;
64
        this.url = url;
65
        setAgreement(agreement);
56
    }
66
    }
57
    
67
    
58
    public String getName () {
68
    public String getName () {
59
        return name;
69
        return name;
60
    }
70
    }
61
    
71
    
72
    public URL getURL() {
73
        return url;
74
    }
75
76
    public void setUrl(URL url) {
77
        this.url = url;
78
    }
79
62
    public String getAgreement () {
80
    public String getAgreement () {
63
        return agreement;
81
        return AutoupdateCatalogCache.getDefault().getLicense(name,url);
64
    }
82
    }
65
    
83
    
66
    public void setAgreement (String content) {
84
    public void setAgreement (String content) {
67
        this.agreement = content;
85
        if(content!=null) {
68
    }
86
            AutoupdateCatalogCache.getDefault().storeLicense(name,content);
69
    
87
        }
88
    }    
70
}
89
}
(-)a/autoupdate.services/src/org/netbeans/modules/autoupdate/updateprovider/AutoupdateCatalogCache.java (-121 / +93 lines)
Lines 41-52 Link Here
41
41
42
package org.netbeans.modules.autoupdate.updateprovider;
42
package org.netbeans.modules.autoupdate.updateprovider;
43
43
44
import java.io.BufferedOutputStream;
45
import java.io.File;
44
import java.io.File;
45
import java.io.FileInputStream;
46
import java.io.FileOutputStream;
46
import java.io.FileOutputStream;
47
import java.io.IOException;
47
import java.io.IOException;
48
import java.io.InputStream;
49
import java.io.OutputStream;
50
import java.net.MalformedURLException;
48
import java.net.MalformedURLException;
51
import java.net.URL;
49
import java.net.URL;
52
import java.util.logging.Level;
50
import java.util.logging.Level;
Lines 57-66 Link Here
57
/**
55
/**
58
 *
56
 *
59
 * @author Jiri Rechtacek
57
 * @author Jiri Rechtacek
58
 * @author Dmitry Lipin
60
 */
59
 */
61
public class AutoupdateCatalogCache {
60
public class AutoupdateCatalogCache {
62
    private File cacheDir;
61
    private File cacheDir;
63
    private Exception storedException;
62
    
64
    
63
    
65
    private static AutoupdateCatalogCache INSTANCE;
64
    private static AutoupdateCatalogCache INSTANCE;
66
    
65
    
Lines 89-94 Link Here
89
            cacheDir = new File(dir, "catalogcache"); // NOI18N
88
            cacheDir = new File(dir, "catalogcache"); // NOI18N
90
        }
89
        }
91
        cacheDir.mkdirs();
90
        cacheDir.mkdirs();
91
        getLicenseDir().mkdirs();
92
        err.log (Level.FINE, "getCacheDirectory: " + cacheDir.getPath ());
92
        err.log (Level.FINE, "getCacheDirectory: " + cacheDir.getPath ());
93
        return;
93
        return;
94
    }
94
    }
Lines 100-106 Link Here
100
            assert dir != null && dir.exists () : "Cache directory must exist.";
100
            assert dir != null && dir.exists () : "Cache directory must exist.";
101
            File cache = new File (dir, codeName);
101
            File cache = new File (dir, codeName);
102
102
103
            copy (original, cache);
103
            copy(original, cache, false);
104
104
105
            try {
105
            try {
106
                url = cache.toURI ().toURL ();
106
                url = cache.toURI ().toURL ();
Lines 137-144 Link Here
137
            return null;
137
            return null;
138
        }
138
        }
139
    }
139
    }
140
    private File getLicenseDir() {
141
        return new File(getCatalogCache(), "licenses");
142
    }
143
144
    private File getLicenseFile(String name) {
145
        return new File(getLicenseDir(), name);
146
    }
147
148
    public String getLicense(String name) {
149
        return getLicense(name, null);
150
    }
151
152
    public String getLicense(String name, URL url) {
153
        synchronized (name.intern()) {
154
            File file = getLicenseFile(name);
155
            if (!file.exists()) {
156
                if (url == null) {
157
                    return null;
158
                }
159
                try {
160
                    copy(url, file, true);
161
                } catch (IOException e) {
162
                    // if can`t get the license, treat it as empty but delete it on exit
163
                    err.log(Level.INFO, "Can`t store license from " + url + " to " + file, e);
164
                    try {
165
                        if (file.exists()) {
166
                            file.delete();
167
                        }
168
                        file.createNewFile();
169
                         //in case of error remove the license file and try to download it on the next start
170
                        file.deleteOnExit();
171
172
                    } catch (IOException ex) {
173
                        err.log(Level.INFO, "Can`t create empty license file", ex);
174
                    }
175
                }
176
            }
177
            return readFile(file);
178
        }
179
    }
180
181
    public void storeLicense(String name, String content) {
182
        synchronized (name.intern()) {
183
            File file = getLicenseFile(name);
184
            if (file.exists() || content == null) {
185
                return;
186
            }
187
            writeToFile(content, file);
188
        }
189
    }
140
    
190
    
141
    private void copy (final URL sourceUrl, final File cache) throws IOException {
191
    private String readFile(File file) {
192
        try {
193
                FileInputStream fr = new FileInputStream(file);
194
                byte[] buffer = new byte[8192];
195
                int n = 0;
196
                StringBuilder sb = new StringBuilder();
197
                while ((n = fr.read(buffer)) != -1) {
198
                    sb.append(new String(buffer, 0, n, "utf-8"));//NOI18N
199
                }
200
                return sb.toString();
201
            } catch (IOException e) {
202
                err.log(Level.INFO, "Can`t read license from file " + file, e);
203
                return null;
204
            }
205
    }
206
    private void writeToFile(String content, File file) {
207
        FileOutputStream fw = null;
208
        try {
209
            fw = new FileOutputStream(file);
210
            fw.write(content.getBytes("utf-8")); //NOI18N
211
        } catch (IOException e) {
212
            err.log(Level.INFO, "Can`t write to " + file, e);
213
        } finally {
214
            if (fw != null) {
215
                try {
216
                    fw.flush();
217
                    fw.close();
218
                } catch (IOException e) {
219
                    err.log(Level.INFO, "Can`t output stream for " + file, e);
220
                }
221
            }
222
        }
223
    }
224
    
225
    private void copy (final URL sourceUrl, final File cache, final boolean allowZeroSize) throws IOException {
142
        // -- create NetworkListener
226
        // -- create NetworkListener
143
        // -- request stream
227
        // -- request stream
144
        // -- report success or IOException
228
        // -- report success or IOException
Lines 151-274 Link Here
151
            prefix += cache.getName();
235
            prefix += cache.getName();
152
        }
236
        }
153
        final File temp = File.createTempFile (prefix, null, cache.getParentFile ()); //NOI18N
237
        final File temp = File.createTempFile (prefix, null, cache.getParentFile ()); //NOI18N
154
        temp.deleteOnExit();
238
        temp.deleteOnExit();        
155
        storeException (null);
156
239
157
        NetworkAccess.NetworkListener nwl = new NetworkAccess.NetworkListener () {
240
        DownloadListener nwl = new DownloadListener(sourceUrl, cache, temp,allowZeroSize);
158
159
            public void streamOpened (InputStream stream, int contentLength) {
160
                err.log (Level.FINE, "Successfully started reading URI " + sourceUrl);
161
                try {
162
                    doCopy (sourceUrl, stream, cache, temp, contentLength);
163
                } catch (IOException ex) {
164
                    storeException (ex);
165
                }
166
            }
167
168
            public void accessCanceled () {
169
                err.log (Level.FINE, "Processing " + sourceUrl + " was cancelled.");
170
                storeException (new IOException ("Processing " + sourceUrl + " was cancelled."));
171
            }
172
173
            public void accessTimeOut () {
174
                err.log (Level.FINE, "Timeout when processing " + sourceUrl);
175
                storeException (new IOException ("Timeout when processing " + sourceUrl));
176
            }
177
178
            public void notifyException (Exception x){
179
                err.log (Level.INFO,
180
                            "Reading URL " + sourceUrl + " failed (" + x +
181
                            ")");
182
                storeException (x);
183
            }
184
            
185
        };
186
        
241
        
187
        NetworkAccess.Task task = NetworkAccess.createNetworkAcessTask (sourceUrl, AutoupdateSettings.getOpenConnectionTimeout (), nwl);
242
        NetworkAccess.Task task = NetworkAccess.createNetworkAcessTask (sourceUrl, AutoupdateSettings.getOpenConnectionTimeout (), nwl);
188
        task.waitFinished ();
243
        task.waitFinished ();
189
        notifyException ();
244
        nwl.notifyException ();
190
    }
245
    }
191
    
192
    private void notifyException () throws IOException {
193
        if (isExceptionStored ()) {
194
            throw new IOException (getStoredException ().getLocalizedMessage ());
195
        }
196
    }
197
    
198
    private boolean isExceptionStored () {
199
        return storedException != null;
200
    }
201
    
202
    private void storeException (Exception x) {
203
        storedException = x;
204
    }
205
    
206
    private Exception getStoredException () {
207
        return storedException;
208
    }
209
    
210
    private void doCopy (URL sourceUrl, InputStream is, File cache, File temp, int contentLength) throws IOException {
211
        
212
        OutputStream os = null;
213
        int read = 0;
214
        int totalRead = 0;
215
        
216
        try {
217
            os = new BufferedOutputStream(new FileOutputStream (temp));            
218
            byte [] bytes = new byte [1024];
219
            while ((read = is.read (bytes)) != -1) {
220
                os.write (bytes, 0, read);
221
                totalRead+=read;
222
            }
223
            is.close ();
224
            os.flush ();
225
            os.close ();
226
            os = null;
227
            if(contentLength!=-1 && contentLength!=totalRead) {
228
                err.log(Level.INFO, "Content length was reported as " + contentLength + " bytes, but read " + totalRead + " bytes from " + sourceUrl);
229
                throw new IOException("unexpected closed connection to " + sourceUrl);
230
            }
231
            if(totalRead==0) {
232
                err.log(Level.INFO, "Connection content length was " + contentLength + " bytes (read " + totalRead + "bytes), catalog size can`t be that size - likely server with catalog at " + sourceUrl + " is temporary down");
233
                throw new IOException("zero sized catalog reported at " + sourceUrl);
234
            }
235
            synchronized (this) {
236
                if (cache.exists () && ! cache.delete ()) {
237
                    err.log (Level.INFO, "Cannot delete cache " + cache);
238
                    try {
239
                        Thread.sleep(200);
240
                    } catch (InterruptedException ie) {
241
                        assert false : ie;
242
                    }
243
                    cache.delete();
244
                }
245
            }
246
            err.log (Level.INFO, "Read " + totalRead + " bytes from catalog at " + sourceUrl);
247
            
248
            if(temp.length()==0) {
249
                err.log (Level.INFO, "Temp cache size is zero bytes");
250
            }
251
            if (! temp.renameTo (cache)) {
252
                err.log (Level.INFO, "Cannot rename temp " + temp + " to cache " + cache);
253
            }
254
            if(cache.exists() && cache.length()==0) {
255
                err.log (Level.INFO, "Final cache size is zero bytes");
256
            }
257
        } catch (IOException ioe) {
258
            err.log (Level.INFO, "Writing content of URL " + sourceUrl + " failed.", ioe);
259
            throw ioe;
260
        } finally {
261
            try {
262
                if (is != null) is.close ();
263
                if (os != null)  {
264
                    os.flush ();
265
                    os.close ();
266
                }
267
            } catch (IOException ioe) {
268
                err.log (Level.INFO, "Closing streams failed.", ioe);
269
            }
270
        }
271
        
272
    }
273
    
274
}
246
}
(-)a/autoupdate.services/src/org/netbeans/modules/autoupdate/updateprovider/AutoupdateCatalogParser.java (-18 / +24 lines)
Lines 52-58 Link Here
52
import java.text.ParseException;
52
import java.text.ParseException;
53
import java.text.SimpleDateFormat;
53
import java.text.SimpleDateFormat;
54
import java.util.ArrayList;
54
import java.util.ArrayList;
55
import java.util.Collection;
55
import java.util.HashMap;
56
import java.util.HashMap;
57
import java.util.HashSet;
56
import java.util.List;
58
import java.util.List;
57
import java.util.Map;
59
import java.util.Map;
58
import java.util.Stack;
60
import java.util.Stack;
Lines 118-123 Link Here
118
    private static final String MODULE_ATTR_EAGER = "eager"; // NOI18N
120
    private static final String MODULE_ATTR_EAGER = "eager"; // NOI18N
119
    private static final String MODULE_ATTR_AUTOLOAD = "autoload"; // NOI18N
121
    private static final String MODULE_ATTR_AUTOLOAD = "autoload"; // NOI18N
120
    private static final String MODULE_ATTR_LICENSE = "license"; // NOI18N
122
    private static final String MODULE_ATTR_LICENSE = "license"; // NOI18N
123
    private static final String LICENSE_ATTR_URL = "url"; // NOI18N
121
    
124
    
122
    private static final String MANIFEST_ATTR_SPECIFICATION_VERSION = "OpenIDE-Module-Specification-Version"; // NOI18N
125
    private static final String MANIFEST_ATTR_SPECIFICATION_VERSION = "OpenIDE-Module-Specification-Version"; // NOI18N
123
    
126
    
Lines 187-193 Link Here
187
    private Stack<String> currentGroup = new Stack<String> ();
190
    private Stack<String> currentGroup = new Stack<String> ();
188
    private String catalogDate;
191
    private String catalogDate;
189
    private Stack<ModuleDescriptor> currentModule = new Stack<ModuleDescriptor> ();
192
    private Stack<ModuleDescriptor> currentModule = new Stack<ModuleDescriptor> ();
190
    private Stack<String> currentLicense = new Stack<String> ();
193
    private Stack<Map <String,String>> currentLicense = new Stack<Map <String,String>> ();
191
    private Stack<String> currentNotificationUrl = new Stack<String> ();
194
    private Stack<String> currentNotificationUrl = new Stack<String> ();
192
    private Map<String, UpdateLicenseImpl> name2license = new HashMap<String, UpdateLicenseImpl> ();
195
    private Map<String, UpdateLicenseImpl> name2license = new HashMap<String, UpdateLicenseImpl> ();
193
    private List<String> lines = new ArrayList<String> ();
196
    private List<String> lines = new ArrayList<String> ();
Lines 253-275 Link Here
253
                break;
256
                break;
254
            case license :
257
            case license :
255
                assert ! currentLicense.empty () : "Premature end of license " + qName;
258
                assert ! currentLicense.empty () : "Premature end of license " + qName;
256
                
259
                Map <String, String> curLic = currentLicense.peek ();
257
                if (! lines.isEmpty ()) {
260
                String licenseName = curLic.keySet().iterator().next();
258
261
                Collection<String> values = curLic.values();
259
                    // find and fill UpdateLicenseImpl
262
                String licenseUrl = (values.size() > 0) ? values.iterator().next() : null;
260
                    StringBuffer sb = new StringBuffer (bufferInitSize);
263
                UpdateLicenseImpl updateLicenseImpl = this.name2license.get (licenseName);
261
                    for (String line : lines) {
264
                if (updateLicenseImpl == null) {
262
                        sb.append (line);
265
                    ERR.info("Unpaired license " + licenseName + " without any module.");
266
                } else {
267
                    if (!lines.isEmpty()) {
268
                        // find and fill UpdateLicenseImpl
269
                        StringBuffer sb = new StringBuffer(bufferInitSize);
270
                        for (String line : lines) {
271
                            sb.append(line);
272
                        }
273
                        updateLicenseImpl.setAgreement(sb.toString());
274
                    } else if (licenseUrl != null) {
275
                        updateLicenseImpl.setUrl(getDistribution(licenseUrl, baseUri));
263
                    }
276
                    }
264
                    UpdateLicenseImpl updateLicenseImpl = this.name2license.get (currentLicense.peek ());
265
                    // in invalid catalog might be a un-paired license
266
                    // assert updateLicenseImpl != null : "UpdateLicenseImpl found in map for key " + currentLicense.peek ();
267
                    if (updateLicenseImpl != null) {
268
                        updateLicenseImpl.setAgreement (sb.toString ());
269
                    } else {
270
                        ERR.info ("Unpaired license " + currentLicense.peek () + " without any module.");
271
                    }
272
273
                }
277
                }
274
                
278
                
275
                currentLicense.pop ();
279
                currentLicense.pop ();
Lines 356-362 Link Here
356
                ERR.info ("Not supported yet.");
360
                ERR.info ("Not supported yet.");
357
                break;
361
                break;
358
            case license :
362
            case license :
359
                currentLicense.push (attributes.getValue (LICENSE_ATTR_NAME));
363
                Map <String, String> map = new HashMap<String,String> ();
364
                map.put(attributes.getValue (LICENSE_ATTR_NAME), attributes.getValue (LICENSE_ATTR_URL));
365
                currentLicense.push (map);
360
                break;
366
                break;
361
            default:
367
            default:
362
                ERR.warning ("Unknown element " + qName);
368
                ERR.warning ("Unknown element " + qName);
(-)a/autoupdate.services/src/org/netbeans/modules/autoupdate/updateprovider/DownloadListener.java (+193 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2008 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
 * Contributor(s):
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2009 Sun
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
31
 * or only the GPL Version 2, indicate your decision by adding
32
 * "[Contributor] elects to include this software in this distribution
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
 * single choice of license, a recipient has the option to distribute
35
 * your version of this file under either the CDDL, the GPL Version 2 or
36
 * to extend the choice of license to its licensees as provided above.
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
38
 * Version 2 license, then the option applies only if the new code is
39
 * made subject to such option by the copyright holder.
40
 */
41
42
package org.netbeans.modules.autoupdate.updateprovider;
43
44
import java.io.BufferedOutputStream;
45
import java.io.File;
46
import java.io.FileOutputStream;
47
import java.io.IOException;
48
import java.io.InputStream;
49
import java.io.OutputStream;
50
import java.net.URL;
51
import java.util.logging.Level;
52
import java.util.logging.Logger;
53
54
/**
55
 *
56
 * @author Dmitry Lipin
57
 */
58
public class DownloadListener implements NetworkAccess.NetworkListener {
59
60
    private Exception storedException;
61
    private File cache;
62
    private File temp;
63
    private URL sourceUrl;
64
    private boolean allowZeroLength;
65
66
    public DownloadListener(URL sourceUrl, File cache, File temp, boolean allowZeroLength) {
67
        this.sourceUrl = sourceUrl;
68
        this.cache = cache;
69
        this.temp = temp;
70
        this.allowZeroLength = allowZeroLength;
71
    }
72
    private Logger err = Logger.getLogger(this.getClass().getName());
73
74
    public void streamOpened(InputStream stream, int contentLength) {
75
        err.log(Level.FINE, "Successfully started reading URI " + sourceUrl);
76
        try {
77
            doCopy(sourceUrl, stream, cache, temp, contentLength);
78
        } catch (IOException ex) {
79
            storeException(ex);
80
        }
81
    }
82
83
    public void accessCanceled() {
84
        err.log(Level.FINE, "Processing " + sourceUrl + " was cancelled.");
85
        storeException(new IOException("Processing " + sourceUrl + " was cancelled."));
86
    }
87
88
    public void accessTimeOut() {
89
        err.log(Level.FINE, "Timeout when processing " + sourceUrl);
90
        storeException(new IOException("Timeout when processing " + sourceUrl));
91
    }
92
93
    public void notifyException(Exception x) {
94
        err.log(Level.INFO,
95
                "Reading URL " + sourceUrl + " failed (" + x +
96
                ")");
97
        storeException(x);
98
    }
99
100
    public void notifyException() throws IOException {
101
        if (isExceptionStored()) {
102
            throw new IOException(getStoredException().getLocalizedMessage());
103
        }
104
105
    }
106
107
    private boolean isExceptionStored() {
108
        return storedException != null;
109
    }
110
111
    private void storeException(Exception x) {
112
        storedException = x;
113
    }
114
115
    private Exception getStoredException() {
116
        return storedException;
117
    }
118
119
    private void doCopy(URL sourceUrl, InputStream is, File cache, File temp, int contentLength) throws IOException {
120
121
        OutputStream os = null;
122
        int read = 0;
123
        int totalRead = 0;
124
125
        try {
126
            os = new BufferedOutputStream(new FileOutputStream(temp));
127
            byte[] bytes = new byte[1024];
128
            while ((read = is.read(bytes)) != -1) {
129
                os.write(bytes, 0, read);
130
                totalRead += read;
131
132
            }
133
134
            is.close();
135
            os.flush();
136
            os.close();
137
            os = null;
138
            if (contentLength != -1 && contentLength != totalRead) {
139
                err.log(Level.INFO, "Content length was reported as " + contentLength + " bytes, but read " + totalRead + " bytes from " + sourceUrl);
140
                throw new IOException("unexpected closed connection to " + sourceUrl);
141
            }
142
143
            if (totalRead == 0 && !allowZeroLength) {
144
                err.log(Level.INFO, "Connection content length was " + contentLength + " bytes (read " + totalRead + "bytes), expected file size can`t be that size - likely server with file at " + sourceUrl + " is temporary down");
145
                throw new IOException("zero sized file reported at " + sourceUrl);
146
            }
147
148
            synchronized (this) {
149
                if (cache.exists() && !cache.delete()) {
150
                    err.log(Level.INFO, "Cannot delete cache " + cache);
151
                    try {
152
                        Thread.sleep(200);
153
                    } catch (InterruptedException ie) {
154
                        assert false : ie;
155
                    }
156
157
                    cache.delete();
158
                }
159
160
            }
161
            err.log(Level.INFO, "Read " + totalRead + " bytes from file at " + sourceUrl);
162
163
            if (temp.length() == 0) {
164
                err.log(Level.INFO, "Temp cache size is zero bytes");
165
            }
166
167
            if (!temp.renameTo(cache)) {
168
                err.log(Level.INFO, "Cannot rename temp " + temp + " to cache " + cache);
169
            }
170
171
            if (cache.exists() && cache.length() == 0) {
172
                err.log(Level.INFO, "Final cache size is zero bytes");
173
            }
174
175
        } catch (IOException ioe) {
176
            err.log(Level.INFO, "Writing content of URL " + sourceUrl + " failed.", ioe);
177
            throw ioe;
178
        } finally {
179
            try {
180
                if (is != null) {
181
                    is.close();
182
                }
183
                if (os != null) {
184
                    os.flush();
185
                    os.close();
186
                }
187
188
            } catch (IOException ioe) {
189
                err.log(Level.INFO, "Closing streams failed.", ioe);
190
            }
191
        }
192
    }
193
}
(-)a/autoupdate.services/src/org/netbeans/modules/autoupdate/updateprovider/NetworkAccess.java (-4 / +4 lines)
Lines 75-81 Link Here
75
        }
75
        }
76
        
76
        
77
        private void postTask () {
77
        private void postTask () {
78
            final SizedConnection<InputStream> connectTask = createCallableNetwork (url, timeout);
78
            final SizedConnection connectTask = createCallableNetwork (url, timeout);
79
            rpTask = RequestProcessor.getDefault ().post (new Runnable () {
79
            rpTask = RequestProcessor.getDefault ().post (new Runnable () {
80
                public void run () {
80
                public void run () {
81
                    connect = es.submit (connectTask);
81
                    connect = es.submit (connectTask);
Lines 103-110 Link Here
103
            rpTask.waitFinished ();
103
            rpTask.waitFinished ();
104
        }
104
        }
105
        
105
        
106
        private SizedConnection<InputStream> createCallableNetwork (final URL url, final int timeout) {
106
        private SizedConnection createCallableNetwork (final URL url, final int timeout) {
107
            return new SizedConnection<InputStream> () {
107
            return new SizedConnection () {
108
                private int contentLength = -1;
108
                private int contentLength = -1;
109
109
110
                public int getContentLength() {
110
                public int getContentLength() {
Lines 126-132 Link Here
126
        }
126
        }
127
        
127
        
128
    }
128
    }
129
    private interface SizedConnection<V> extends Callable {
129
    private interface SizedConnection extends Callable<InputStream> {
130
        public int getContentLength();
130
        public int getContentLength();
131
    }
131
    }
132
    public interface NetworkListener {
132
    public interface NetworkListener {
(-)a/autoupdate.services/src/org/netbeans/spi/autoupdate/UpdateLicense.java (-1 / +11 lines)
Lines 41-46 Link Here
41
41
42
package org.netbeans.spi.autoupdate;
42
package org.netbeans.spi.autoupdate;
43
43
44
import java.net.URL;
44
import org.netbeans.modules.autoupdate.services.UpdateLicenseImpl;
45
import org.netbeans.modules.autoupdate.services.UpdateLicenseImpl;
45
46
46
/** Represents License Agreement for usage in Autoupdate infrastructure.
47
/** Represents License Agreement for usage in Autoupdate infrastructure.
Lines 64-68 Link Here
64
    public static final UpdateLicense createUpdateLicense (String licenseName, String agreement) {
65
    public static final UpdateLicense createUpdateLicense (String licenseName, String agreement) {
65
        return new UpdateLicense (new UpdateLicenseImpl (licenseName, agreement));
66
        return new UpdateLicense (new UpdateLicenseImpl (licenseName, agreement));
66
    }
67
    }
67
    
68
69
    /**
70
     *
71
     * @param licenseName name of license
72
     * @param agreementUrl URL to the license agreement
73
     * @return <code>UpdateLicense</code>
74
     */
75
    public static final UpdateLicense createUpdateLicense (String licenseName, String agreement, URL agreementUrl) {
76
        return new UpdateLicense (new UpdateLicenseImpl (licenseName, agreement, agreementUrl));
77
    }
68
}
78
}
(-)a/autoupdate.ui/manifest.mf (-1 / +1 lines)
Lines 3-8 Link Here
3
OpenIDE-Module-Install: org/netbeans/modules/autoupdate/ui/actions/Installer.class
3
OpenIDE-Module-Install: org/netbeans/modules/autoupdate/ui/actions/Installer.class
4
OpenIDE-Module-Layer: org/netbeans/modules/autoupdate/ui/resources/layer.xml
4
OpenIDE-Module-Layer: org/netbeans/modules/autoupdate/ui/resources/layer.xml
5
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/autoupdate/ui/resources/Bundle.properties
5
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/autoupdate/ui/resources/Bundle.properties
6
OpenIDE-Module-Specification-Version: 1.6
6
OpenIDE-Module-Specification-Version: 1.7
7
AutoUpdate-Show-In-Client: false
7
AutoUpdate-Show-In-Client: false
8
AutoUpdate-Essential-Module: true
8
AutoUpdate-Essential-Module: true
(-)a/autoupdate.ui/src/org/netbeans/modules/autoupdate/ui/wizards/InstallUnitWizardIterator.java (-3 / +6 lines)
Lines 44-49 Link Here
44
import java.util.ArrayList;
44
import java.util.ArrayList;
45
import java.util.List;
45
import java.util.List;
46
import java.util.NoSuchElementException;
46
import java.util.NoSuchElementException;
47
import java.util.logging.Logger;
47
import javax.swing.event.ChangeListener;
48
import javax.swing.event.ChangeListener;
48
import org.openide.WizardDescriptor;
49
import org.openide.WizardDescriptor;
49
import org.openide.util.NbBundle;
50
import org.openide.util.NbBundle;
Lines 128-139 Link Here
128
    // If nothing unusual changes in the middle of the wizard, simply:
129
    // If nothing unusual changes in the middle of the wizard, simply:
129
    public void addChangeListener (ChangeListener l) {}
130
    public void addChangeListener (ChangeListener l) {}
130
    public void removeChangeListener (ChangeListener l) {}
131
    public void removeChangeListener (ChangeListener l) {}
131
    
132
132
    private void compactPanels () {
133
    private void compactPanels () {
133
        if (isCompact) {
134
        if (isCompact) {
134
            return ;
135
            return ;
135
        }
136
        }
136
        if (getModel ().allLicensesApproved ()) {
137
138
        boolean allLicensesTouched = getModel().allLicensesTouched();
139
        if (allLicensesTouched && getModel ().allLicensesApproved ()) {            
137
            panels.remove (licenseApprovalStep);
140
            panels.remove (licenseApprovalStep);
138
        }
141
        }
139
        if (! getModel ().hasCustomComponents ()) {
142
        if (! getModel ().hasCustomComponents ()) {
Lines 142-148 Link Here
142
        if (! getModel ().hasStandardComponents ()) {
145
        if (! getModel ().hasStandardComponents ()) {
143
            panels.remove (installStep);
146
            panels.remove (installStep);
144
        }
147
        }
145
        isCompact = true;
148
        isCompact = allLicensesTouched;
146
    }
149
    }
147
    
150
    
148
}
151
}
(-)a/autoupdate.ui/src/org/netbeans/modules/autoupdate/ui/wizards/InstallUnitWizardModel.java (+6 lines)
Lines 67-72 Link Here
67
    private OperationContainer<InstallSupport> updateContainer = null;
67
    private OperationContainer<InstallSupport> updateContainer = null;
68
    private OperationContainer<OperationSupport> customContainer = Containers.forCustomInstall ();
68
    private OperationContainer<OperationSupport> customContainer = Containers.forCustomInstall ();
69
    private PluginManagerUI manager;
69
    private PluginManagerUI manager;
70
    private boolean allLicensesTouched = false;
70
    
71
    
71
    /** Creates a new instance of InstallUnitWizardModel */
72
    /** Creates a new instance of InstallUnitWizardModel */
72
    public InstallUnitWizardModel (OperationType doOperation, OperationContainer<InstallSupport> updateContainer) {
73
    public InstallUnitWizardModel (OperationType doOperation, OperationContainer<InstallSupport> updateContainer) {
Lines 129-139 Link Here
129
                break;
130
                break;
130
            }
131
            }
131
        }
132
        }
133
        allLicensesTouched = true;
132
        return res;
134
        return res;
135
    }
136
    public boolean allLicensesTouched() {
137
        return allLicensesTouched;
133
    }
138
    }
134
    
139
    
135
    public void addApprovedLicenses (Collection<String> licences) {
140
    public void addApprovedLicenses (Collection<String> licences) {
136
        approvedLicences.addAll (licences);
141
        approvedLicences.addAll (licences);
142
        allLicensesTouched = false;
137
    }
143
    }
138
    
144
    
139
    public InstallSupport getInstallSupport () {
145
    public InstallSupport getInstallSupport () {
(-)a/nbbuild/antsrc/org/netbeans/nbbuild/MakeUpdateDesc.java (-13 / +49 lines)
Lines 51-56 Link Here
51
import org.apache.tools.ant.DirectoryScanner;
51
import org.apache.tools.ant.DirectoryScanner;
52
import java.io.File;
52
import java.io.File;
53
import java.io.FileOutputStream;
53
import java.io.FileOutputStream;
54
import java.io.FileWriter;
54
import java.io.IOException;
55
import java.io.IOException;
55
import java.io.InputStream;
56
import java.io.InputStream;
56
import java.io.OutputStream;
57
import java.io.OutputStream;
Lines 163-168 Link Here
163
        dist_base = dbase;
164
        dist_base = dbase;
164
    }
165
    }
165
166
167
    private boolean useLicenseUrl;
168
169
170
    public void setUseLicenseUrl(boolean useLicenseUrl) {
171
        this.useLicenseUrl = useLicenseUrl;
172
    }
173
    
166
    private Path updaterJar;
174
    private Path updaterJar;
167
    /** Fileset for platform/modules/ext/updater.jar, to be used in DTD validation. */
175
    /** Fileset for platform/modules/ext/updater.jar, to be used in DTD validation. */
168
    public Path createUpdaterJar() {
176
    public Path createUpdaterJar() {
Lines 269-275 Link Here
269
                    }
277
                    }
270
                    File desc_ent = new File(ent_name);
278
                    File desc_ent = new File(ent_name);
271
                    desc_ent.delete();
279
                    desc_ent.delete();
272
                    if (use25DTD) {
280
                    if(useLicenseUrl) {
281
                        pw.println("<!DOCTYPE module_updates PUBLIC \"-//NetBeans//DTD Autoupdate Catalog 2.6//EN\" \"http://www.netbeans.org/dtds/autoupdate-catalog-2_6.dtd\" [");
282
                    } else if (use25DTD) {
273
                        pw.println("<!DOCTYPE module_updates PUBLIC \"-//NetBeans//DTD Autoupdate Catalog 2.5//EN\" \"http://www.netbeans.org/dtds/autoupdate-catalog-2_5.dtd\" [");
283
                        pw.println("<!DOCTYPE module_updates PUBLIC \"-//NetBeans//DTD Autoupdate Catalog 2.5//EN\" \"http://www.netbeans.org/dtds/autoupdate-catalog-2_5.dtd\" [");
274
                    } else if (targetClustersDefined) {
284
                    } else if (targetClustersDefined) {
275
                        pw.println("<!DOCTYPE module_updates PUBLIC \"-//NetBeans//DTD Autoupdate Catalog 2.4//EN\" \"http://www.netbeans.org/dtds/autoupdate-catalog-2_4.dtd\" [");
285
                        pw.println("<!DOCTYPE module_updates PUBLIC \"-//NetBeans//DTD Autoupdate Catalog 2.4//EN\" \"http://www.netbeans.org/dtds/autoupdate-catalog-2_4.dtd\" [");
Lines 303-309 Link Here
303
                    pw.println ();
313
                    pw.println ();
304
                    
314
                    
305
                } else {
315
                } else {
306
                    if (use25DTD) {
316
                    if(useLicenseUrl) {
317
                        pw.println("<!DOCTYPE module_updates PUBLIC \"-//NetBeans//DTD Autoupdate Catalog 2.6//EN\" \"http://www.netbeans.org/dtds/autoupdate-catalog-2_6.dtd\">");
318
                    } else if (use25DTD) {
307
                        pw.println("<!DOCTYPE module_updates PUBLIC \"-//NetBeans//DTD Autoupdate Catalog 2.5//EN\" \"http://www.netbeans.org/dtds/autoupdate-catalog-2_5.dtd\">");
319
                        pw.println("<!DOCTYPE module_updates PUBLIC \"-//NetBeans//DTD Autoupdate Catalog 2.5//EN\" \"http://www.netbeans.org/dtds/autoupdate-catalog-2_5.dtd\">");
308
                    } else if (targetClustersDefined) {
320
                    } else if (targetClustersDefined) {
309
                        pw.println("<!DOCTYPE module_updates PUBLIC \"-//NetBeans//DTD Autoupdate Catalog 2.4//EN\" \"http://www.netbeans.org/dtds/autoupdate-catalog-2_4.dtd\">");
321
                        pw.println("<!DOCTYPE module_updates PUBLIC \"-//NetBeans//DTD Autoupdate Catalog 2.4//EN\" \"http://www.netbeans.org/dtds/autoupdate-catalog-2_4.dtd\">");
Lines 316-323 Link Here
316
328
317
                pw.println ();
329
                pw.println ();
318
		Map<String,Element> licenses = new HashMap<String,Element>();
330
		Map<String,Element> licenses = new HashMap<String,Element>();
319
                Set<String> licenseNames = new HashSet<String>();
331
                String prefix = null;
320
                
332
                if (dist_base != null) {
333
                    // fix/enforce distribution URL base
334
                    if (dist_base.equals(".")) {
335
                        prefix = "";
336
                    } else {
337
                        prefix = dist_base + "/";
338
                    }
339
                }
340
                final File licensesDir = new File(desc.getParentFile(), "licenses");
341
                if (useLicenseUrl) {
342
                     if (licensesDir.exists()) {
343
                         for (File f : licensesDir.listFiles()) {
344
                            f.delete();
345
                        }
346
                        } else {
347
                        licensesDir.mkdir();
348
                     }
349
                }
350
321
                for (Map.Entry<String,Collection<Module>> entry : modulesByGroup.entrySet()) {
351
                for (Map.Entry<String,Collection<Module>> entry : modulesByGroup.entrySet()) {
322
                    String groupName = entry.getKey();
352
                    String groupName = entry.getKey();
323
                    // Don't indent; embedded descriptions would get indented otherwise.
353
                    // Don't indent; embedded descriptions would get indented otherwise.
Lines 335-354 Link Here
335
                        String name = manifest.getAttribute("OpenIDE-Module-Name");
365
                        String name = manifest.getAttribute("OpenIDE-Module-Name");
336
                        if (name.length() > 0) {
366
                        if (name.length() > 0) {
337
                            log(" Adding module " + name + " (" + m.nbm.getAbsolutePath() + ")");
367
                            log(" Adding module " + name + " (" + m.nbm.getAbsolutePath() + ")");
338
                        }
368
                        }                        
339
                        if (dist_base != null) {
369
                        if(prefix!=null) {
340
                            // fix/enforce distribution URL base
341
                            String prefix;
342
                            if (dist_base.equals(".")) {
343
                                prefix = "";
344
                            } else {
345
                                prefix = dist_base + "/";
346
                            }
347
                            module.setAttribute("distribution", prefix + m.relativePath);
370
                            module.setAttribute("distribution", prefix + m.relativePath);
348
                        }
371
                        }
349
                        NodeList licenseList = module.getElementsByTagName("license");
372
                        NodeList licenseList = module.getElementsByTagName("license");
350
                        if (licenseList.getLength() > 0) {
373
                        if (licenseList.getLength() > 0) {
351
                            Element license = (Element) licenseList.item(0);
374
                            Element license = (Element) licenseList.item(0);
375
                            if (useLicenseUrl) {
376
                                String relativePath = "licenses/" + license.getAttribute("name") + ".license";
377
                                String path = relativePath;
378
                                if (prefix != null) {
379
                                    path = prefix + relativePath;
380
                                }
381
                                license.setAttribute("url", path);
382
                                String licenseText = license.getTextContent();
383
                                license.setTextContent("");
384
                                FileOutputStream fos = new FileOutputStream(new File(desc.getParentFile(), relativePath));
385
                                fos.write(licenseText.getBytes("UTF-8"));
386
                                fos.close();
387
                            }
352
                            // XXX ideally would compare the license texts to make sure they actually match up
388
                            // XXX ideally would compare the license texts to make sure they actually match up
353
                            licenses.put(license.getAttribute("name"), license);
389
                            licenses.put(license.getAttribute("name"), license);
354
                            module.removeChild(license);
390
                            module.removeChild(license);

Return to bug 149071