Please use the Apache issue tracking system for new NetBeans issues (https://issues.apache.org/jira/projects/NETBEANS0/issues) !!
View | Details | Raw Unified | Return to bug 149071 | Differences between
and this patch

Collapse All | Expand All

(-)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/src/org/netbeans/modules/autoupdate/services/UpdateLicenseImpl.java (-3 / +24 lines)
 Lines 41-46    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
 Lines 48-70    Link Here 
48
public final class UpdateLicenseImpl {
51
public final class UpdateLicenseImpl {
49
    private String name;
52
    private String name;
50
    private String agreement;
53
    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
        this.agreement = agreement;
56
    }
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);
66
    }
57
    
67
    
58
    public String getName () {
68
    public String getName () {
59
        return name;
69
        return name;
60
    }
70
    }
61
    
71
    public URL getURL() {
72
        return url;
73
    }
62
    public String getAgreement () {
74
    public String getAgreement () {
75
        if(agreement!=null) {
76
            return agreement;
77
        } else if (url!=null) {
78
            agreement = AutoupdateCatalogCache.getDefault().getLicense(name,url);
79
        }
63
        return agreement;
80
        return agreement;
64
    }
81
    }
65
    
82
    public void setUrl(URL url) {
83
        this.url = url;
84
    }
66
    public void setAgreement (String content) {
85
    public void setAgreement (String content) {
67
        this.agreement = content;
86
        if(content!=null) {
87
            AutoupdateCatalogCache.getDefault().storeLicense(name,content);
88
        }
68
    }
89
    }
69
    
90
    
70
}
91
}
(-)a/autoupdate.services/src/org/netbeans/modules/autoupdate/updateprovider/AutoupdateCatalogCache.java (-115 / +96 lines)
 Lines 43-48    Link Here 
43
43
44
import java.io.BufferedOutputStream;
44
import java.io.BufferedOutputStream;
45
import java.io.File;
45
import java.io.File;
46
import java.io.FileInputStream;
46
import java.io.FileOutputStream;
47
import java.io.FileOutputStream;
47
import java.io.IOException;
48
import java.io.IOException;
48
import java.io.InputStream;
49
import java.io.InputStream;
 Lines 60-66    Link Here 
60
 */
61
 */
61
public class AutoupdateCatalogCache {
62
public class AutoupdateCatalogCache {
62
    private File cacheDir;
63
    private File cacheDir;
63
    private Exception storedException;
64
    
64
    
65
    
65
    private static AutoupdateCatalogCache INSTANCE;
66
    private static AutoupdateCatalogCache INSTANCE;
66
    
67
    
 Lines 100-106    Link Here 
100
            assert dir != null && dir.exists () : "Cache directory must exist.";
101
            assert dir != null && dir.exists () : "Cache directory must exist.";
101
            File cache = new File (dir, codeName);
102
            File cache = new File (dir, codeName);
102
103
103
            copy (original, cache);
104
            copyCatalog(original, cache);
104
105
105
            try {
106
            try {
106
                url = cache.toURI ().toURL ();
107
                url = cache.toURI ().toURL ();
 Lines 137-144    Link Here 
137
            return null;
138
            return null;
138
        }
139
        }
139
    }
140
    }
141
    private File getLicenseDir() {
142
        return new File(getCatalogCache(), "licenses");
143
    }
144
145
    private File getLicenseFile(String name) {
146
        return new File(getLicenseDir(), name);
147
    }
148
149
    public String getLicense(String name) {
150
        return getLicense(name, null);
151
    }
152
153
    public String getLicense(String name, URL url) {
154
        synchronized (name.intern()) {
155
            File file = getLicenseFile(name);
156
            if (!file.exists()) {
157
                if(url==null) {
158
                    return null;
159
                }
160
                try {
161
                    return copyLicense(url, file);
162
                } catch (IOException e) {
163
                    err.log(Level.INFO, "Can`t load license from " + url, e);
164
                    return null;
165
                }
166
            }
167
            try {
168
                FileInputStream fr = new FileInputStream(file);
169
                byte[] buffer = new byte[8192];
170
                int n = 0;
171
                StringBuilder sb = new StringBuilder();
172
                while ((n = fr.read(buffer)) != -1) {
173
                    sb.append(new String(buffer, 0, n, "utf-8"));//NOI18N
174
                }
175
                return sb.toString();
176
            } catch (IOException e) {
177
                err.log(Level.INFO, "Can`t read license from file " + file, e);
178
                return null;
179
            }
180
        }
181
    }
182
183
    public void storeLicense(String name, String content) {
184
        synchronized (name.intern()) {
185
            File file = getLicenseFile(name);
186
            if (file.exists() || content==null) {
187
                return;
188
            }
189
190
            FileOutputStream fw = null;
191
            try {
192
                fw = new FileOutputStream(file);
193
                fw.write(content.getBytes("utf-8")); //NOI18N
194
            } catch (IOException e) {
195
                err.log(Level.INFO, "Can`t write license " + name + " to " + file, e);
196
            } finally {
197
                if (fw != null) {
198
                    try {
199
                        fw.flush();
200
                        fw.close();
201
                    } catch (IOException e) {
202
                        err.log(Level.INFO, "Can`t output stream for " + file, e);
203
                    }
204
                }
205
            }
206
        }
207
    }
140
    
208
    
141
    private void copy (final URL sourceUrl, final File cache) throws IOException {
209
    private void copyCatalog (final URL sourceUrl, final File cache) throws IOException {
142
        // -- create NetworkListener
210
        // -- create NetworkListener
143
        // -- request stream
211
        // -- request stream
144
        // -- report success or IOException
212
        // -- report success or IOException
 Lines 151-274    Link Here 
151
            prefix += cache.getName();
219
            prefix += cache.getName();
152
        }
220
        }
153
        final File temp = File.createTempFile (prefix, null, cache.getParentFile ()); //NOI18N
221
        final File temp = File.createTempFile (prefix, null, cache.getParentFile ()); //NOI18N
154
        temp.deleteOnExit();
222
        temp.deleteOnExit();        
155
        storeException (null);
156
223
157
        NetworkAccess.NetworkListener nwl = new NetworkAccess.NetworkListener () {
224
        DownloadCatalogListener nwl = new DownloadCatalogListener(sourceUrl, cache, temp);
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
        
225
        
187
        NetworkAccess.Task task = NetworkAccess.createNetworkAcessTask (sourceUrl, AutoupdateSettings.getOpenConnectionTimeout (), nwl);
226
        NetworkAccess.Task task = NetworkAccess.createNetworkAcessTask (sourceUrl, AutoupdateSettings.getOpenConnectionTimeout (), nwl);
188
        task.waitFinished ();
227
        task.waitFinished ();
189
        notifyException ();
228
        nwl.notifyException ();
190
    }
229
    }
191
    
230
192
    private void notifyException () throws IOException {
231
    private String copyLicense (final URL sourceUrl, final File cache) throws IOException {
193
        if (isExceptionStored ()) {
232
        // -- create NetworkListener
194
            throw new IOException (getStoredException ().getLocalizedMessage ());
233
        // -- request stream
234
        // -- report success or IOException
235
        // -- if success then do copy
236
237
        err.log(Level.INFO, "Processing URL: " + sourceUrl); // NOI18N
238
239
        String prefix = "";
240
        while (prefix.length () < 3) {
241
            prefix += cache.getName();
195
        }
242
        }
243
        final File temp = File.createTempFile (prefix, null, cache.getParentFile ()); //NOI18N
244
        temp.deleteOnExit();
245
246
        DownloadLicenseListener nwl = new DownloadLicenseListener(sourceUrl, cache, temp);
247
248
        NetworkAccess.Task task = NetworkAccess.createNetworkAcessTask (sourceUrl, AutoupdateSettings.getOpenConnectionTimeout (), nwl);
249
        task.waitFinished ();
250
        nwl.notifyException ();
251
        return nwl.getLicense();
196
    }
252
    }
197
    
253
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
    
254
    
274
}
255
}
(-)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/DownloadCatalogListener.java (+188 lines)
Line 0    Link Here 
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2009 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 2009 Sun Microsystems, Inc.
38
 */
39
package org.netbeans.modules.autoupdate.updateprovider;
40
41
import java.io.BufferedOutputStream;
42
import java.io.File;
43
import java.io.FileOutputStream;
44
import java.io.IOException;
45
import java.io.InputStream;
46
import java.io.OutputStream;
47
import java.net.URL;
48
import java.util.logging.Level;
49
import java.util.logging.Logger;
50
51
/**
52
 *
53
 * @author dlm198383
54
 */
55
public class DownloadCatalogListener implements NetworkAccess.NetworkListener {
56
57
    private Exception storedException;
58
    private File cache;
59
    private File temp;
60
    private URL sourceUrl;
61
62
    public DownloadCatalogListener(URL sourceUrl, File cache, File temp) {
63
        this.sourceUrl = sourceUrl;
64
        this.cache = cache;
65
        this.temp = temp;
66
    }
67
    private Logger err = Logger.getLogger(this.getClass().getName());
68
69
    public void streamOpened(InputStream stream, int contentLength) {
70
        err.log(Level.FINE, "Successfully started reading URI " + sourceUrl);
71
        try {
72
            doCopy(sourceUrl, stream, cache, temp, contentLength);
73
        } catch (IOException ex) {
74
            storeException(ex);
75
        }
76
    }
77
78
    public void accessCanceled() {
79
        err.log(Level.FINE, "Processing " + sourceUrl + " was cancelled.");
80
        storeException(new IOException("Processing " + sourceUrl + " was cancelled."));
81
    }
82
83
    public void accessTimeOut() {
84
        err.log(Level.FINE, "Timeout when processing " + sourceUrl);
85
        storeException(new IOException("Timeout when processing " + sourceUrl));
86
    }
87
88
    public void notifyException(Exception x) {
89
        err.log(Level.INFO,
90
                "Reading URL " + sourceUrl + " failed (" + x +
91
                ")");
92
        storeException(x);
93
    }
94
95
    public void notifyException() throws IOException {
96
        if (isExceptionStored()) {
97
            throw new IOException(getStoredException().getLocalizedMessage());
98
        }
99
100
    }
101
102
    private boolean isExceptionStored() {
103
        return storedException != null;
104
    }
105
106
    private void storeException(Exception x) {
107
        storedException = x;
108
    }
109
110
    private Exception getStoredException() {
111
        return storedException;
112
    }
113
114
    private void doCopy(URL sourceUrl, InputStream is, File cache, File temp, int contentLength) throws IOException {
115
116
        OutputStream os = null;
117
        int read = 0;
118
        int totalRead = 0;
119
120
        try {
121
            os = new BufferedOutputStream(new FileOutputStream(temp));
122
            byte[] bytes = new byte[1024];
123
            while ((read = is.read(bytes)) != -1) {
124
                os.write(bytes, 0, read);
125
                totalRead += read;
126
127
            }
128
129
            is.close();
130
            os.flush();
131
            os.close();
132
            os = null;
133
            if (contentLength != -1 && contentLength != totalRead) {
134
                err.log(Level.INFO, "Content length was reported as " + contentLength + " bytes, but read " + totalRead + " bytes from " + sourceUrl);
135
                throw new IOException("unexpected closed connection to " + sourceUrl);
136
            }
137
138
            if (totalRead == 0) {
139
                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");
140
                throw new IOException("zero sized catalog reported at " + sourceUrl);
141
            }
142
143
            synchronized (this) {
144
                if (cache.exists() && !cache.delete()) {
145
                    err.log(Level.INFO, "Cannot delete cache " + cache);
146
                    try {
147
                        Thread.sleep(200);
148
                    } catch (InterruptedException ie) {
149
                        assert false : ie;
150
                    }
151
152
                    cache.delete();
153
                }
154
155
            }
156
            err.log(Level.INFO, "Read " + totalRead + " bytes from catalog at " + sourceUrl);
157
158
            if (temp.length() == 0) {
159
                err.log(Level.INFO, "Temp cache size is zero bytes");
160
            }
161
162
            if (!temp.renameTo(cache)) {
163
                err.log(Level.INFO, "Cannot rename temp " + temp + " to cache " + cache);
164
            }
165
166
            if (cache.exists() && cache.length() == 0) {
167
                err.log(Level.INFO, "Final cache size is zero bytes");
168
            }
169
170
        } catch (IOException ioe) {
171
            err.log(Level.INFO, "Writing content of URL " + sourceUrl + " failed.", ioe);
172
            throw ioe;
173
        } finally {
174
            try {
175
                if (is != null) {
176
                    is.close();
177
                }
178
                if (os != null) {
179
                    os.flush();
180
                    os.close();
181
                }
182
183
            } catch (IOException ioe) {
184
                err.log(Level.INFO, "Closing streams failed.", ioe);
185
            }
186
        }
187
    }
188
}
(-)a/autoupdate.services/src/org/netbeans/modules/autoupdate/updateprovider/DownloadLicenseListener.java (+195 lines)
Line 0    Link Here 
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2009 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 2009 Sun Microsystems, Inc.
38
 */
39
package org.netbeans.modules.autoupdate.updateprovider;
40
41
import java.io.BufferedOutputStream;
42
import java.io.File;
43
import java.io.FileOutputStream;
44
import java.io.IOException;
45
import java.io.InputStream;
46
import java.io.OutputStream;
47
import java.net.URL;
48
import java.util.logging.Level;
49
import java.util.logging.Logger;
50
51
/**
52
 *
53
 * @author Dmitry Lipin
54
 */
55
public class DownloadLicenseListener implements NetworkAccess.NetworkListener {
56
57
    private Exception storedException;
58
    private File cache;
59
    private File temp;
60
    private URL sourceUrl;
61
    private StringBuilder license;
62
63
    public DownloadLicenseListener(URL sourceUrl, File cache, File temp) {
64
        this.sourceUrl = sourceUrl;
65
        this.cache = cache;
66
        this.temp = temp;
67
        license = new StringBuilder();
68
    }
69
    private Logger err = Logger.getLogger(this.getClass().getName());
70
71
    public void streamOpened(InputStream stream, int contentLength) {
72
        err.log(Level.FINE, "Successfully started reading URI " + sourceUrl);
73
        try {
74
            doCopy(sourceUrl, stream, cache, temp, contentLength);
75
        } catch (IOException ex) {
76
            storeException(ex);
77
        }
78
    }
79
80
    public void accessCanceled() {
81
        err.log(Level.FINE, "Processing " + sourceUrl + " was cancelled.");
82
        storeException(new IOException("Processing " + sourceUrl + " was cancelled."));
83
    }
84
85
    public void accessTimeOut() {
86
        err.log(Level.FINE, "Timeout when processing " + sourceUrl);
87
        storeException(new IOException("Timeout when processing " + sourceUrl));
88
    }
89
90
    public void notifyException(Exception x) {
91
        err.log(Level.INFO,
92
                "Reading URL " + sourceUrl + " failed (" + x +
93
                ")");
94
        storeException(x);
95
    }
96
97
    public void notifyException() throws IOException {
98
        if (isExceptionStored()) {
99
            throw new IOException(getStoredException().getLocalizedMessage());
100
        }
101
102
    }
103
    public String getLicense() {
104
        return license.toString();
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
                license.append(new String(bytes,0,read,"utf-8"));
132
            }
133
134
135
            is.close();
136
            os.flush();
137
            os.close();
138
            os = null;
139
            if (contentLength != -1 && contentLength != totalRead) {
140
                err.log(Level.INFO, "Content length was reported as " + contentLength + " bytes, but read " + totalRead + " bytes from " + sourceUrl);
141
                throw new IOException("unexpected closed connection to " + sourceUrl);
142
            }
143
            /*
144
            if (totalRead == 0) {
145
                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");
146
                throw new IOException("zero sized catalog reported at " + sourceUrl);
147
            }
148
            */
149
            synchronized (this) {
150
                if (cache.exists() && !cache.delete()) {
151
                    err.log(Level.INFO, "Cannot delete cache " + cache);
152
                    try {
153
                        Thread.sleep(200);
154
                    } catch (InterruptedException ie) {
155
                        assert false : ie;
156
                    }
157
158
                    cache.delete();
159
                }
160
161
            }
162
            err.log(Level.INFO, "Read " + totalRead + " bytes from catalog at " + sourceUrl);
163
164
            if (temp.length() == 0) {
165
                err.log(Level.INFO, "Temp cache size is zero bytes");
166
            }
167
168
            if (!temp.renameTo(cache)) {
169
                err.log(Level.INFO, "Cannot rename temp " + temp + " to cache " + cache);
170
            }
171
172
            if (cache.exists() && cache.length() == 0) {
173
                err.log(Level.INFO, "Final cache size is zero bytes");
174
            }
175
176
        } catch (IOException ioe) {
177
            err.log(Level.INFO, "Writing content of URL " + sourceUrl + " failed.", ioe);
178
            throw ioe;
179
        } finally {
180
            try {
181
                if (is != null) {
182
                    is.close();
183
                }
184
                if (os != null) {
185
                    os.flush();
186
                    os.close();
187
                }
188
189
            } catch (IOException ioe) {
190
                err.log(Level.INFO, "Closing streams failed.", ioe);
191
            }
192
        }
193
194
    }
195
}
(-)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/src/org/netbeans/modules/autoupdate/ui/wizards/InstallUnitWizardIterator.java (-1 / +2 lines)
 Lines 133-141    Link Here 
133
        if (isCompact) {
133
        if (isCompact) {
134
            return ;
134
            return ;
135
        }
135
        }
136
        /*
136
        if (getModel ().allLicensesApproved ()) {
137
        if (getModel ().allLicensesApproved ()) {
137
            panels.remove (licenseApprovalStep);
138
            panels.remove (licenseApprovalStep);
138
        }
139
        }*/
139
        if (! getModel ().hasCustomComponents ()) {
140
        if (! getModel ().hasCustomComponents ()) {
140
            panels.remove (customHandleStep);
141
            panels.remove (customHandleStep);
141
        }
142
        }

Return to bug 149071
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo