--- a/apisupport.harness/release/suite.xml
+++ a/apisupport.harness/release/suite.xml
@@ -210,7 +210,16 @@
-
+
+
+
+
+
+
+
+
+
+
--- a/autoupdate.services/libsrc/org/netbeans/updater/resources/autoupdate-catalog-2_6.dtd
+++ a/autoupdate.services/libsrc/org/netbeans/updater/resources/autoupdate-catalog-2_6.dtd
@@ -0,0 +1,67 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
--- a/autoupdate.services/src/org/netbeans/modules/autoupdate/services/UpdateLicenseImpl.java
+++ a/autoupdate.services/src/org/netbeans/modules/autoupdate/services/UpdateLicenseImpl.java
@@ -41,6 +41,9 @@
package org.netbeans.modules.autoupdate.services;
+import java.net.URL;
+import org.netbeans.modules.autoupdate.updateprovider.AutoupdateCatalogCache;
+
/**
*
* @author Jiri Rechtacek
@@ -48,23 +51,44 @@
public final class UpdateLicenseImpl {
private String name;
private String agreement;
+ private URL url;
/** Creates a new instance of UpdateLicense */
public UpdateLicenseImpl (String licenseName, String agreement) {
this.name = licenseName;
this.agreement = agreement;
}
+ /** Creates a new instance of UpdateLicense */
+ public UpdateLicenseImpl (String licenseName, String agreement, URL url) {
+ this.name = licenseName;
+ this.url = url;
+ setAgreement(agreement);
+ }
public String getName () {
return name;
}
-
+ public URL getURL() {
+ return url;
+ }
public String getAgreement () {
- return agreement;
+ if(agreement!=null) {
+ return agreement;
+ } else if (url!=null) {
+ return AutoupdateCatalogCache.getDefault().getLicense(name,url);
+ } else {
+ return null;
+ }
}
-
+ public void setUrl(URL url) {
+ this.url = url;
+ }
public void setAgreement (String content) {
- this.agreement = content;
+ if(content!=null) {
+ AutoupdateCatalogCache.getDefault().storeLicense(name,content);
+ } else {
+ agreement = null;
+ }
}
}
--- a/autoupdate.services/src/org/netbeans/modules/autoupdate/updateprovider/AutoupdateCatalogCache.java
+++ a/autoupdate.services/src/org/netbeans/modules/autoupdate/updateprovider/AutoupdateCatalogCache.java
@@ -41,12 +41,10 @@
package org.netbeans.modules.autoupdate.updateprovider;
-import java.io.BufferedOutputStream;
import java.io.File;
+import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Level;
@@ -60,7 +58,7 @@
*/
public class AutoupdateCatalogCache {
private File cacheDir;
- private Exception storedException;
+
private static AutoupdateCatalogCache INSTANCE;
@@ -89,6 +87,7 @@
cacheDir = new File(dir, "catalogcache"); // NOI18N
}
cacheDir.mkdirs();
+ getLicenseDir().mkdirs();
err.log (Level.FINE, "getCacheDirectory: " + cacheDir.getPath ());
return;
}
@@ -100,7 +99,7 @@
assert dir != null && dir.exists () : "Cache directory must exist.";
File cache = new File (dir, codeName);
- copy (original, cache);
+ copy(original, cache, false);
try {
url = cache.toURI ().toURL ();
@@ -137,8 +136,91 @@
return null;
}
}
+ private File getLicenseDir() {
+ return new File(getCatalogCache(), "licenses");
+ }
+
+ private File getLicenseFile(String name) {
+ return new File(getLicenseDir(), name);
+ }
+
+ public String getLicense(String name) {
+ return getLicense(name, null);
+ }
+
+ public String getLicense(String name, URL url) {
+ synchronized (name.intern()) {
+ File file = getLicenseFile(name);
+ if (!file.exists()) {
+ if (url == null) {
+ return null;
+ }
+ try {
+ copy(url, file, true);
+ } catch (IOException e) {
+ // if can`t get the license, treat it as empty but delete it on exit
+ err.log(Level.INFO, "Can`t store license from " + url + " to " + file, e);
+ try {
+ if (file.exists()) {
+ file.delete();
+ }
+ file.createNewFile();
+ file.deleteOnExit(); //
+
+ } catch (IOException ex) {
+ err.log(Level.INFO, "Can`t create empty license file", ex);
+ }
+ }
+ }
+ return readFile(file);
+ }
+ }
+
+ public void storeLicense(String name, String content) {
+ synchronized (name.intern()) {
+ File file = getLicenseFile(name);
+ if (file.exists() || content == null) {
+ return;
+ }
+ writeToFile(content, file);
+ }
+ }
- private void copy (final URL sourceUrl, final File cache) throws IOException {
+ private String readFile(File file) {
+ try {
+ FileInputStream fr = new FileInputStream(file);
+ byte[] buffer = new byte[8192];
+ int n = 0;
+ StringBuilder sb = new StringBuilder();
+ while ((n = fr.read(buffer)) != -1) {
+ sb.append(new String(buffer, 0, n, "utf-8"));//NOI18N
+ }
+ return sb.toString();
+ } catch (IOException e) {
+ err.log(Level.INFO, "Can`t read license from file " + file, e);
+ return null;
+ }
+ }
+ private void writeToFile(String content, File file) {
+ FileOutputStream fw = null;
+ try {
+ fw = new FileOutputStream(file);
+ fw.write(content.getBytes("utf-8")); //NOI18N
+ } catch (IOException e) {
+ err.log(Level.INFO, "Can`t write to " + file, e);
+ } finally {
+ if (fw != null) {
+ try {
+ fw.flush();
+ fw.close();
+ } catch (IOException e) {
+ err.log(Level.INFO, "Can`t output stream for " + file, e);
+ }
+ }
+ }
+ }
+
+ private void copy (final URL sourceUrl, final File cache, final boolean allowZeroSize) throws IOException {
// -- create NetworkListener
// -- request stream
// -- report success or IOException
@@ -151,124 +233,13 @@
prefix += cache.getName();
}
final File temp = File.createTempFile (prefix, null, cache.getParentFile ()); //NOI18N
- temp.deleteOnExit();
- storeException (null);
+ temp.deleteOnExit();
- NetworkAccess.NetworkListener nwl = new NetworkAccess.NetworkListener () {
-
- public void streamOpened (InputStream stream, int contentLength) {
- err.log (Level.FINE, "Successfully started reading URI " + sourceUrl);
- try {
- doCopy (sourceUrl, stream, cache, temp, contentLength);
- } catch (IOException ex) {
- storeException (ex);
- }
- }
-
- public void accessCanceled () {
- err.log (Level.FINE, "Processing " + sourceUrl + " was cancelled.");
- storeException (new IOException ("Processing " + sourceUrl + " was cancelled."));
- }
-
- public void accessTimeOut () {
- err.log (Level.FINE, "Timeout when processing " + sourceUrl);
- storeException (new IOException ("Timeout when processing " + sourceUrl));
- }
-
- public void notifyException (Exception x){
- err.log (Level.INFO,
- "Reading URL " + sourceUrl + " failed (" + x +
- ")");
- storeException (x);
- }
-
- };
+ DownloadListener nwl = new DownloadListener(sourceUrl, cache, temp,allowZeroSize);
NetworkAccess.Task task = NetworkAccess.createNetworkAcessTask (sourceUrl, AutoupdateSettings.getOpenConnectionTimeout (), nwl);
task.waitFinished ();
- notifyException ();
+ nwl.notifyException ();
}
-
- private void notifyException () throws IOException {
- if (isExceptionStored ()) {
- throw new IOException (getStoredException ().getLocalizedMessage ());
- }
- }
-
- private boolean isExceptionStored () {
- return storedException != null;
- }
-
- private void storeException (Exception x) {
- storedException = x;
- }
-
- private Exception getStoredException () {
- return storedException;
- }
-
- private void doCopy (URL sourceUrl, InputStream is, File cache, File temp, int contentLength) throws IOException {
-
- OutputStream os = null;
- int read = 0;
- int totalRead = 0;
-
- try {
- os = new BufferedOutputStream(new FileOutputStream (temp));
- byte [] bytes = new byte [1024];
- while ((read = is.read (bytes)) != -1) {
- os.write (bytes, 0, read);
- totalRead+=read;
- }
- is.close ();
- os.flush ();
- os.close ();
- os = null;
- if(contentLength!=-1 && contentLength!=totalRead) {
- err.log(Level.INFO, "Content length was reported as " + contentLength + " bytes, but read " + totalRead + " bytes from " + sourceUrl);
- throw new IOException("unexpected closed connection to " + sourceUrl);
- }
- if(totalRead==0) {
- 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");
- throw new IOException("zero sized catalog reported at " + sourceUrl);
- }
- synchronized (this) {
- if (cache.exists () && ! cache.delete ()) {
- err.log (Level.INFO, "Cannot delete cache " + cache);
- try {
- Thread.sleep(200);
- } catch (InterruptedException ie) {
- assert false : ie;
- }
- cache.delete();
- }
- }
- err.log (Level.INFO, "Read " + totalRead + " bytes from catalog at " + sourceUrl);
-
- if(temp.length()==0) {
- err.log (Level.INFO, "Temp cache size is zero bytes");
- }
- if (! temp.renameTo (cache)) {
- err.log (Level.INFO, "Cannot rename temp " + temp + " to cache " + cache);
- }
- if(cache.exists() && cache.length()==0) {
- err.log (Level.INFO, "Final cache size is zero bytes");
- }
- } catch (IOException ioe) {
- err.log (Level.INFO, "Writing content of URL " + sourceUrl + " failed.", ioe);
- throw ioe;
- } finally {
- try {
- if (is != null) is.close ();
- if (os != null) {
- os.flush ();
- os.close ();
- }
- } catch (IOException ioe) {
- err.log (Level.INFO, "Closing streams failed.", ioe);
- }
- }
-
- }
-
+
}
--- a/autoupdate.services/src/org/netbeans/modules/autoupdate/updateprovider/AutoupdateCatalogParser.java
+++ a/autoupdate.services/src/org/netbeans/modules/autoupdate/updateprovider/AutoupdateCatalogParser.java
@@ -52,7 +52,9 @@
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Stack;
@@ -118,6 +120,7 @@
private static final String MODULE_ATTR_EAGER = "eager"; // NOI18N
private static final String MODULE_ATTR_AUTOLOAD = "autoload"; // NOI18N
private static final String MODULE_ATTR_LICENSE = "license"; // NOI18N
+ private static final String LICENSE_ATTR_URL = "url"; // NOI18N
private static final String MANIFEST_ATTR_SPECIFICATION_VERSION = "OpenIDE-Module-Specification-Version"; // NOI18N
@@ -187,7 +190,7 @@
private Stack currentGroup = new Stack ();
private String catalogDate;
private Stack currentModule = new Stack ();
- private Stack currentLicense = new Stack ();
+ private Stack