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/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.licence.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.licence.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/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 (-4 / +28 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 () {
63
        return agreement;
75
        if(agreement!=null) {
76
            return agreement;
77
        } else if (url!=null) {
78
            return AutoupdateCatalogCache.getDefault().getLicense(name,url);
79
        } else {
80
            return null;
81
        }
64
    }
82
    }
65
    
83
    public void setUrl(URL url) {
84
        this.url = url;
85
    }
66
    public void setAgreement (String content) {
86
    public void setAgreement (String content) {
67
        this.agreement = content;
87
        if(content!=null) {
88
            AutoupdateCatalogCache.getDefault().storeLicense(name,content);
89
        } else {
90
            agreement = null;
91
        }
68
    }
92
    }
69
    
93
    
70
}
94
}
(-)a/autoupdate.services/src/org/netbeans/modules/autoupdate/updateprovider/AutoupdateCatalogCache.java (-121 / +92 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 60-66    Link Here 
60
 */
58
 */
61
public class AutoupdateCatalogCache {
59
public class AutoupdateCatalogCache {
62
    private File cacheDir;
60
    private File cacheDir;
63
    private Exception storedException;
61
    
64
    
62
    
65
    private static AutoupdateCatalogCache INSTANCE;
63
    private static AutoupdateCatalogCache INSTANCE;
66
    
64
    
 Lines 89-94    Link Here 
89
            cacheDir = new File(dir, "catalogcache"); // NOI18N
87
            cacheDir = new File(dir, "catalogcache"); // NOI18N
90
        }
88
        }
91
        cacheDir.mkdirs();
89
        cacheDir.mkdirs();
90
        getLicenseDir().mkdirs();
92
        err.log (Level.FINE, "getCacheDirectory: " + cacheDir.getPath ());
91
        err.log (Level.FINE, "getCacheDirectory: " + cacheDir.getPath ());
93
        return;
92
        return;
94
    }
93
    }
 Lines 100-106    Link Here 
100
            assert dir != null && dir.exists () : "Cache directory must exist.";
99
            assert dir != null && dir.exists () : "Cache directory must exist.";
101
            File cache = new File (dir, codeName);
100
            File cache = new File (dir, codeName);
102
101
103
            copy (original, cache);
102
            copy(original, cache, false);
104
103
105
            try {
104
            try {
106
                url = cache.toURI ().toURL ();
105
                url = cache.toURI ().toURL ();
 Lines 137-144    Link Here 
137
            return null;
136
            return null;
138
        }
137
        }
139
    }
138
    }
139
    private File getLicenseDir() {
140
        return new File(getCatalogCache(), "licenses");
141
    }
142
143
    private File getLicenseFile(String name) {
144
        return new File(getLicenseDir(), name);
145
    }
146
147
    public String getLicense(String name) {
148
        return getLicense(name, null);
149
    }
150
151
    public String getLicense(String name, URL url) {
152
        synchronized (name.intern()) {
153
            File file = getLicenseFile(name);
154
            if (!file.exists()) {
155
                if (url == null) {
156
                    return null;
157
                }
158
                try {
159
                    copy(url, file, true);
160
                } catch (IOException e) {
161
                    // if can`t get the license, treat it as empty but delete it on exit
162
                    err.log(Level.INFO, "Can`t store license from " + url + " to " + file, e);
163
                    try {
164
                        if (file.exists()) {
165
                            file.delete();
166
                        }
167
                        file.createNewFile();
168
                        file.deleteOnExit(); //
169
170
                    } catch (IOException ex) {
171
                        err.log(Level.INFO, "Can`t create empty license file", ex);
172
                    }
173
                }
174
            }
175
            return readFile(file);
176
        }
177
    }
178
179
    public void storeLicense(String name, String content) {
180
        synchronized (name.intern()) {
181
            File file = getLicenseFile(name);
182
            if (file.exists() || content == null) {
183
                return;
184
            }
185
            writeToFile(content, file);
186
        }
187
    }
140
    
188
    
141
    private void copy (final URL sourceUrl, final File cache) throws IOException {
189
    private String readFile(File file) {
190
        try {
191
                FileInputStream fr = new FileInputStream(file);
192
                byte[] buffer = new byte[8192];
193
                int n = 0;
194
                StringBuilder sb = new StringBuilder();
195
                while ((n = fr.read(buffer)) != -1) {
196
                    sb.append(new String(buffer, 0, n, "utf-8"));//NOI18N
197
                }
198
                return sb.toString();
199
            } catch (IOException e) {
200
                err.log(Level.INFO, "Can`t read license from file " + file, e);
201
                return null;
202
            }
203
    }
204
    private void writeToFile(String content, File file) {
205
        FileOutputStream fw = null;
206
        try {
207
            fw = new FileOutputStream(file);
208
            fw.write(content.getBytes("utf-8")); //NOI18N
209
        } catch (IOException e) {
210
            err.log(Level.INFO, "Can`t write to " + file, e);
211
        } finally {
212
            if (fw != null) {
213
                try {
214
                    fw.flush();
215
                    fw.close();
216
                } catch (IOException e) {
217
                    err.log(Level.INFO, "Can`t output stream for " + file, e);
218
                }
219
            }
220
        }
221
    }
222
    
223
    private void copy (final URL sourceUrl, final File cache, final boolean allowZeroSize) throws IOException {
142
        // -- create NetworkListener
224
        // -- create NetworkListener
143
        // -- request stream
225
        // -- request stream
144
        // -- report success or IOException
226
        // -- report success or IOException
 Lines 151-274    Link Here 
151
            prefix += cache.getName();
233
            prefix += cache.getName();
152
        }
234
        }
153
        final File temp = File.createTempFile (prefix, null, cache.getParentFile ()); //NOI18N
235
        final File temp = File.createTempFile (prefix, null, cache.getParentFile ()); //NOI18N
154
        temp.deleteOnExit();
236
        temp.deleteOnExit();        
155
        storeException (null);
156
237
157
        NetworkAccess.NetworkListener nwl = new NetworkAccess.NetworkListener () {
238
        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
        
239
        
187
        NetworkAccess.Task task = NetworkAccess.createNetworkAcessTask (sourceUrl, AutoupdateSettings.getOpenConnectionTimeout (), nwl);
240
        NetworkAccess.Task task = NetworkAccess.createNetworkAcessTask (sourceUrl, AutoupdateSettings.getOpenConnectionTimeout (), nwl);
188
        task.waitFinished ();
241
        task.waitFinished ();
189
        notifyException ();
242
        nwl.notifyException ();
190
    }
243
    }
191
    
244
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
}
245
}
(-)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 (+190 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 DownloadListener implements NetworkAccess.NetworkListener {
56
57
    private Exception storedException;
58
    private File cache;
59
    private File temp;
60
    private URL sourceUrl;
61
    private boolean allowZeroLength;
62
63
    public DownloadListener(URL sourceUrl, File cache, File temp, boolean allowZeroLength) {
64
        this.sourceUrl = sourceUrl;
65
        this.cache = cache;
66
        this.temp = temp;
67
        this.allowZeroLength = allowZeroLength;
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
104
    private boolean isExceptionStored() {
105
        return storedException != null;
106
    }
107
108
    private void storeException(Exception x) {
109
        storedException = x;
110
    }
111
112
    private Exception getStoredException() {
113
        return storedException;
114
    }
115
116
    private void doCopy(URL sourceUrl, InputStream is, File cache, File temp, int contentLength) throws IOException {
117
118
        OutputStream os = null;
119
        int read = 0;
120
        int totalRead = 0;
121
122
        try {
123
            os = new BufferedOutputStream(new FileOutputStream(temp));
124
            byte[] bytes = new byte[1024];
125
            while ((read = is.read(bytes)) != -1) {
126
                os.write(bytes, 0, read);
127
                totalRead += read;
128
129
            }
130
131
            is.close();
132
            os.flush();
133
            os.close();
134
            os = null;
135
            if (contentLength != -1 && contentLength != totalRead) {
136
                err.log(Level.INFO, "Content length was reported as " + contentLength + " bytes, but read " + totalRead + " bytes from " + sourceUrl);
137
                throw new IOException("unexpected closed connection to " + sourceUrl);
138
            }
139
140
            if (totalRead == 0 && !allowZeroLength) {
141
                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");
142
                throw new IOException("zero sized file reported at " + sourceUrl);
143
            }
144
145
            synchronized (this) {
146
                if (cache.exists() && !cache.delete()) {
147
                    err.log(Level.INFO, "Cannot delete cache " + cache);
148
                    try {
149
                        Thread.sleep(200);
150
                    } catch (InterruptedException ie) {
151
                        assert false : ie;
152
                    }
153
154
                    cache.delete();
155
                }
156
157
            }
158
            err.log(Level.INFO, "Read " + totalRead + " bytes from file at " + sourceUrl);
159
160
            if (temp.length() == 0) {
161
                err.log(Level.INFO, "Temp cache size is zero bytes");
162
            }
163
164
            if (!temp.renameTo(cache)) {
165
                err.log(Level.INFO, "Cannot rename temp " + temp + " to cache " + cache);
166
            }
167
168
            if (cache.exists() && cache.length() == 0) {
169
                err.log(Level.INFO, "Final cache size is zero bytes");
170
            }
171
172
        } catch (IOException ioe) {
173
            err.log(Level.INFO, "Writing content of URL " + sourceUrl + " failed.", ioe);
174
            throw ioe;
175
        } finally {
176
            try {
177
                if (is != null) {
178
                    is.close();
179
                }
180
                if (os != null) {
181
                    os.flush();
182
                    os.close();
183
                }
184
185
            } catch (IOException ioe) {
186
                err.log(Level.INFO, "Closing streams failed.", ioe);
187
            }
188
        }
189
    }
190
}
(-)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/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 (-10 / +44 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 317-323    Link Here 
317
                pw.println ();
325
                pw.println ();
318
		Map<String,Element> licenses = new HashMap<String,Element>();
326
		Map<String,Element> licenses = new HashMap<String,Element>();
319
                Set<String> licenseNames = new HashSet<String>();
327
                Set<String> licenseNames = new HashSet<String>();
320
                
328
329
                String prefix = null;
330
                if (dist_base != null) {
331
                    // fix/enforce distribution URL base
332
                    if (dist_base.equals(".")) {
333
                        prefix = "";
334
                    } else {
335
                        prefix = dist_base + "/";
336
                    }
337
                }
338
                final File licensesDir = new File(desc.getParentFile(), "licenses");
339
                if (useLicenseUrl) {
340
                     if (licensesDir.exists()) {
341
                         for (File f : licensesDir.listFiles()) {
342
                            f.delete();
343
                        }
344
                        } else {
345
                        licensesDir.mkdir();
346
                     }
347
                }
348
321
                for (Map.Entry<String,Collection<Module>> entry : modulesByGroup.entrySet()) {
349
                for (Map.Entry<String,Collection<Module>> entry : modulesByGroup.entrySet()) {
322
                    String groupName = entry.getKey();
350
                    String groupName = entry.getKey();
323
                    // Don't indent; embedded descriptions would get indented otherwise.
351
                    // Don't indent; embedded descriptions would get indented otherwise.
 Lines 335-354    Link Here 
335
                        String name = manifest.getAttribute("OpenIDE-Module-Name");
363
                        String name = manifest.getAttribute("OpenIDE-Module-Name");
336
                        if (name.length() > 0) {
364
                        if (name.length() > 0) {
337
                            log(" Adding module " + name + " (" + m.nbm.getAbsolutePath() + ")");
365
                            log(" Adding module " + name + " (" + m.nbm.getAbsolutePath() + ")");
338
                        }
366
                        }                        
339
                        if (dist_base != null) {
367
                        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);
368
                            module.setAttribute("distribution", prefix + m.relativePath);
348
                        }
369
                        }
349
                        NodeList licenseList = module.getElementsByTagName("license");
370
                        NodeList licenseList = module.getElementsByTagName("license");
350
                        if (licenseList.getLength() > 0) {
371
                        if (licenseList.getLength() > 0) {
351
                            Element license = (Element) licenseList.item(0);
372
                            Element license = (Element) licenseList.item(0);
373
                            if (useLicenseUrl) {
374
                                String relativePath = "licenses/" + license.getAttribute("name") + ".license";
375
                                String path = relativePath;
376
                                if (prefix != null) {
377
                                    path = prefix + relativePath;
378
                                }
379
                                license.setAttribute("url", path);
380
                                String licenseText = license.getTextContent();
381
                                license.setTextContent("");
382
                                FileWriter fw = new FileWriter(new File(desc.getParentFile(), relativePath));
383
                                fw.write(licenseText);
384
                                fw.close();
385
                            }
352
                            // XXX ideally would compare the license texts to make sure they actually match up
386
                            // XXX ideally would compare the license texts to make sure they actually match up
353
                            licenses.put(license.getAttribute("name"), license);
387
                            licenses.put(license.getAttribute("name"), license);
354
                            module.removeChild(license);
388
                            module.removeChild(license);
(-)a/nbbuild/build.xml (-2 / +4 lines)
 Lines 924-930    Link Here 
924
      </antcall>
924
      </antcall>
925
      <taskdef name="makeupdatedesc" classname="org.netbeans.nbbuild.MakeUpdateDesc"
925
      <taskdef name="makeupdatedesc" classname="org.netbeans.nbbuild.MakeUpdateDesc"
926
               classpath="${nb_all}/nbbuild/nbantext.jar"/>
926
               classpath="${nb_all}/nbbuild/nbantext.jar"/>
927
      <makeupdatedesc desc="nbms/catalog.xml" distbase=".">
927
      <property name="catalog.use.license.url" value="true"/>
928
      <makeupdatedesc desc="nbms/catalog.xml" distbase="." uselicenseurl="${catalog.use.license.url}">
928
          <fileset dir="nbms">
929
          <fileset dir="nbms">
929
              <include name="*.nbm"/>
930
              <include name="*.nbm"/>
930
          </fileset>
931
          </fileset>
 Lines 2034-2041    Link Here 
2034
      <property name="nbms.location" location="nbms"/>
2035
      <property name="nbms.location" location="nbms"/>
2035
      <property name="catalog.file" location="catalog.xml"/>
2036
      <property name="catalog.file" location="catalog.xml"/>
2036
      <property name="catalog.base.url" value="http://bits.netbeans.org/"/>
2037
      <property name="catalog.base.url" value="http://bits.netbeans.org/"/>
2038
      <property name="catalog.use.license.url" value="true"/>
2037
<!--      <genau config="ausrc/modules.setup" nbmLocation="${nbms.location}" catalog="${catalog.file}" catalogDeploymentLocation="${catalog.base.url}"/>-->
2039
<!--      <genau config="ausrc/modules.setup" nbmLocation="${nbms.location}" catalog="${catalog.file}" catalogDeploymentLocation="${catalog.base.url}"/>-->
2038
      <makeupdatedesc desc="${catalog.file}" distbase="${catalog.base.url}" automaticgrouping="true">
2040
      <makeupdatedesc desc="${catalog.file}" distbase="${catalog.base.url}" automaticgrouping="true" uselicenseurl="${catalog.use.license.url}">
2039
          <fileset dir="${nbms.location}">
2041
          <fileset dir="${nbms.location}">
2040
              <include name="**/*.nbm"/>
2042
              <include name="**/*.nbm"/>
2041
          </fileset>
2043
          </fileset>

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