diff options
author | Jiri Vanek <[email protected]> | 2012-02-01 18:23:10 +0100 |
---|---|---|
committer | Jiri Vanek <[email protected]> | 2012-02-01 18:23:10 +0100 |
commit | 8dfc3c1bd0fcaa60a0defd85cd044b954de4ccfb (patch) | |
tree | 98c5c0c86bef90c9a5ed16c761c763d6db5c0573 /netx/net/sourceforge/jnlp | |
parent | 83a814966b14deb946e6c9fa9b55a75b9e22472d (diff) |
fixed LRU cache behaviour in case of failure. Tests added.
Diffstat (limited to 'netx/net/sourceforge/jnlp')
5 files changed, 229 insertions, 134 deletions
diff --git a/netx/net/sourceforge/jnlp/cache/CacheLRUWrapper.java b/netx/net/sourceforge/jnlp/cache/CacheLRUWrapper.java index 59ab00d..e148bd3 100644 --- a/netx/net/sourceforge/jnlp/cache/CacheLRUWrapper.java +++ b/netx/net/sourceforge/jnlp/cache/CacheLRUWrapper.java @@ -36,6 +36,8 @@ exception statement from your version. */ package net.sourceforge.jnlp.cache; +import static net.sourceforge.jnlp.runtime.Translator.R; + import java.io.File; import java.io.IOException; import java.nio.channels.FileLock; @@ -178,10 +180,8 @@ enum CacheLRUWrapper { int c = t1.compareTo(t2); return c < 0 ? 1 : (c > 0 ? -1 : 0); - } catch (NumberFormatException e) { - // Perhaps an error is too harsh. Maybe just somehow turn - // caching off if this is the case. - throw new InternalError("Corrupt LRU file entries"); + } catch (Exception e) { + throw new LruCacheException(R("Corrupt LRU file entries")); } } }); @@ -249,4 +249,8 @@ enum CacheLRUWrapper { public String generateKey(String path) { return System.currentTimeMillis() + "," + getIdForCacheFolder(path); } + + void clearLRUSortedEntries() { + cacheOrder.clear(); + } } diff --git a/netx/net/sourceforge/jnlp/cache/CacheUtil.java b/netx/net/sourceforge/jnlp/cache/CacheUtil.java index b88c6e9..320b0f2 100644 --- a/netx/net/sourceforge/jnlp/cache/CacheUtil.java +++ b/netx/net/sourceforge/jnlp/cache/CacheUtil.java @@ -144,16 +144,16 @@ public class CacheUtil { * process is using them can be quite disasterous. Hence why Launcher creates lock files * and we check for those by calling {@link #okToClearCache()} */ - public static void clearCache() { + public static boolean clearCache() { if (!okToClearCache()) { System.err.println(R("CCannotClearCache")); - return; + return false; } File cacheDir = new File(CacheUtil.cacheDir); if (!(cacheDir.isDirectory())) { - return; + return false; } if (JNLPRuntime.isDebug()) { @@ -165,6 +165,7 @@ public class CacheUtil { } catch (IOException e) { throw new RuntimeException(e); } + return true; } /** @@ -322,7 +323,37 @@ public class CacheUtil { private static File getCacheFileIfExist(File urlPath) { synchronized (lruHandler) { File cacheFile = null; - List<Entry<String, String>> entries = lruHandler.getLRUSortedEntries(); + int tries = 0; + List<Entry<String, String>> entries = null; + do { + try { + tries++; + entries = lruHandler.getLRUSortedEntries(); + } catch (LruCacheException ex) { + if (tries == 1) { + ex.printStackTrace(); + System.out.println(R("CFakeCache")); + lruHandler.clearLRUSortedEntries(); + lruHandler.store(); + System.out.println(R("CFakedCache")); + } else if (tries == 2) { + ex.printStackTrace(); + System.out.println(R("CStillCorupted")); + boolean clearingresult = CacheUtil.clearCache(); + if (!clearingresult) { + throw new InternalError(R("CCleaningUnsuccessful")); + } + System.out.println(R("CClearedReloading")); + lruHandler.clearLRUSortedEntries(); + lruHandler.store(); + System.out.println(R("CReloadRestarting")); + + } else { + throw new InternalError(R("CStillBroken")); + } + + } + } while (entries == null); // Start searching from the most recent to least recent. for (Entry<String, String> e : entries) { final String key = e.getKey(); diff --git a/netx/net/sourceforge/jnlp/cache/LruCacheException.java b/netx/net/sourceforge/jnlp/cache/LruCacheException.java new file mode 100644 index 0000000..9589b06 --- /dev/null +++ b/netx/net/sourceforge/jnlp/cache/LruCacheException.java @@ -0,0 +1,52 @@ +/* LruCacheException.java -- Thrown when cache is corrupted. +Copyright (C) 2012 Red Hat, Inc. + +This file is part of IcedTea. + +IcedTea is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License as published by +the Free Software Foundation, version 2. + +IcedTea is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with IcedTea; see the file COPYING. If not, write to +the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. + */ +package net.sourceforge.jnlp.cache; + +class LruCacheException extends RuntimeException { + + public LruCacheException() { + super(); + } + + public LruCacheException(String string) { + super(string); + } + + public LruCacheException(Throwable cause) { + super(cause); + } +} diff --git a/netx/net/sourceforge/jnlp/resources/Messages.properties b/netx/net/sourceforge/jnlp/resources/Messages.properties index a08331d..f1187e5 100644 --- a/netx/net/sourceforge/jnlp/resources/Messages.properties +++ b/netx/net/sourceforge/jnlp/resources/Messages.properties @@ -190,6 +190,13 @@ CChooseCache=Choose a cache directory... CChooseCacheInfo=Netx needs a location for storing cache files.
CChooseCacheDir=Cache directory
CCannotClearCache=Can not clear cache at this time
+CFakeCache=Cache is corrupt. Disabling.
+CFakedCache=Cache is corrupt and has been disabled. It is strongly recommended that you run 'javaws -Xclearcache' and rerun your application as soon as possible.
+CStillCorupted=Cache is still corrupt, clearing it.
+CCleaningUnsuccessful=Unable to clear cache due to running javaws instance. Please try to shut down all instances of javaws, run 'javaws -Xclearcache', and rerun your jnlp file
+CClearedReloading=Cache cleared, re-loading.
+CReloadRestarting=Cache re-loaded and application re-starting. It is strongly recommended that you run 'javaws -Xclearcache' and re-run your application as soon as possible.
+CStillBroken=Unable to fix corrupt cache. Please shutdown all javaws instances, run 'javaws -Xclearcache', and re-start your application.
# Security
SFileReadAccess=The application has requested read access to {0}. Do you want to allow this action?
@@ -205,7 +212,7 @@ SClipboardWriteAccess=The application has requested write-only access to the sys SPrinterAccess=The application has requested printer access. Do you want to allow this action?
SNetworkAccess=The application has requested permission to establish connections to {0}. Do you want to allow this action?
SNoAssociatedCertificate=<no associated certificate>
-SUnverified=(unverified) +SUnverified=(unverified)
SAlwaysTrustPublisher=Always trust content from this publisher
SHttpsUnverified=The website's certificate cannot be verified.
SNotAllSignedSummary=Only parts of this application code are signed.
@@ -266,7 +273,7 @@ KSClientCerts=Client Authentication Certificates # Deployment Configuration messages
DCIncorrectValue=Property "{0}" has incorrect value "{1}". Possible values {2}.
DCInternal=Internal error: {0}
-DCSourceInternal=<internal> +DCSourceInternal=<internal>
DCUnknownSettingWithName=Property "{0}" is unknown.
# Value Validator messages. Messages should follow "Possible values ..."
@@ -279,124 +286,124 @@ VVPossibleUrlValues=include any valid url (eg http://icedtea.classpath.org/hg/) # Control Panel - Main
CPMainDescriptionShort=Configure IcedTea-Web
CPMainDescriptionLong=Configure how the browser plugin (IcedTeaNPPlugin) and javaws (NetX) work
- -# Control Panel - Tab Descriptions -CPAboutDescription=View version information about Icedtea Control Panel. -CPNetworkSettingsDescription=Configure network settings, including how IcedTea-Web connects to the internet and whether to use any proxies. -CPTempInternetFilesDescription=Java stores application data for faster execution the next time you run it. -CPJRESettingsDescription=View and manage Java Runtime Environment versions and settings for Java applications and applets. -CPCertificatesDescription=Use certificates to positively identify yourself, certifications, authorities, and plublishers. -CPSecurityDescription=Use this to configure security settings. -CPDebuggingDescription=Enable options here to help with debugging -CPDesktopIntegrationDescription=Set whether or not to allow creation of desktop shortcut. - -# Control Panel - Buttons -CPButAbout=About... -CPButNetworkSettings=Network Settings... -CPButSettings=Settings... -CPButView=View... -CPButCertificates=Certificates... - -# Control Panel - Headers -CPHead=IcedTea Web Control Panel -CPHeadAbout=About -CPHeadNetworkSettings=Network Proxy Settings -CPHeadTempInternetFiles=Temporary Internet Files -CPHeadJRESettings=Java Runtime Environment Settings -CPHeadCertificates=Certificates -CPHeadDebugging=Debugging Settings -CPHeadDesktopIntegration=Desktop Integrations -CPHeadSecurity=Security Settings - -# Control Panel - Tabs -CPTabAbout=About IcedTea-Web -CPTabCache=Cache -CPTabCertificate=Certificates -CPTabClassLoader=Class Loaders -CPTabDebugging=Debugging -CPTabDesktopIntegration=Desktop Integration -CPTabNetwork=Network -CPTabRuntimes=Runtimes -CPTabSecurity=Security - -# Control Panel - AboutPanel -CPAboutInfo=This is the control panel for setting deployments.properties.<br/>Not all options will take effect until implemented.<br/>The use of multiple JREs is currently unsupported.<br/> - -# Control Panel - AdvancedProxySettings -APSDialogTitle=Network Settings -APSServersPanel=Servers -APSProxyTypeLabel=Type -APSProxyAddressLabel=Proxy Address -APSProxyPortLabel=Proxy Port -APSLabelHTTP=HTTP -APSLabelSecure=Secure -APSLabelFTP=FTP -APSLabelSocks=Socks -APSSameProxyForAllProtocols=Use the same proxy server for all protocols. -APSExceptionsLabel=Exceptions -APSExceptionsDescription=Do not use proxy server for addresses beginning with -APSExceptionInstruction=Separate each entry with a semicolon. - -# Control Panel - DebugginPanel -DPEnableTracing=Enable tracing -DPEnableLogging=Enable logging -DPDisable=Disable -DPHide=Hide on startup -DPShow=Show on startup -DPJavaConsole=Java Console - -# Control Panel - DesktopShortcutPanel -DSPNeverCreate=Never create -DSPAlwaysAllow=Always allow -DSPAskUser=Ask user -DSPAskIfHinted=Ask if hinted -DSPAlwaysIfHinted=Always if hinted - -# Control Panel - NetworkSettingsPanel -NSDescription-1=Unknown Setting. -NSDescription0=Use direct connection. -NSDescription1=Override browser proxy settings. -NSDescription2=Use automatic proxy configuration script at the specified location. -NSDescription3=Use proxy settings from your default browser to connect to the internet. -NSAddress=Address -NSPort=Port -NSAdvanced=Advanced -NSBypassLocal=Bypass proxy server for local addresses -NSDirectConnection=Direct connection -NSManualProxy=Manual proxy server -NSAutoProxy=Automatic proxy configuration script -NSBrowserProxy=Use browser settings -NSScriptLocation=Script location - -# Control Panel - SecurityGeneralPanel -SGPAllowUserGrantSigned=Allow users to grant permissions to signed content -SGPAllowUserGrantUntrust=Allow users to grant permissions to content from an untrusted authority -SGPUseBrowserKeystore=Use certificates and keys in browser keystore (Unsupported) -SGPUsePersonalCertOneMatch=Use personal certificate automatically if only one matches server request (Unsupported) -SGPWarnCertHostMismatch=Warn if site certificate does not match hostname -SGPShowValid=Show site certificate even if it is valid (Unsupported) -SGPShowSandboxWarning=Show sandbox warning banner -SGPAllowUserAcceptJNLPSecurityRequests=Allow user to accept JNLP security requests -SGPCheckCertRevocationList=Check certificates for revocation using Certificate Revocation Lists (CRLs) (Unsupported) -SGPEnableOnlineCertValidate=Enable online certificate validation (Unsupported) -SGPEnableTrustedPublisherList=Enable list of trusted publishers (Unsupported) -SGPEnableBlacklistRevocation=Enable blacklist revocation check (Unsupported) -SGPEnableCachingPassword=Enable caching password for authentication (Unsupported) -SGPUseSSL2=Use SSL 2.0 compatible ClientHello format (Unsupported) -SGPUseSSL3=Use SSL 3.0 (Unsupported) -SGPUseTLS1=Use TLS 1.0 (Unsupported) - -# Control Panel - TemporaryInternetFilesPanel -TIFPEnableCache=Keep temporary files on my computer -TIFPLocation=Location -TIFPLocationLabel=Select the location where temporary files are kept -TIFPChange=Change -TIFPDiskSpace=Disk space -TIFPCompressionLevel=Select the compression level for JAR files -TIFPNone=None -TIFPMax=Max -TIFPCacheSize=Set the amount of disk space for storing temporary files -TIFPDeleteFiles=Delete files +
+# Control Panel - Tab Descriptions
+CPAboutDescription=View version information about Icedtea Control Panel.
+CPNetworkSettingsDescription=Configure network settings, including how IcedTea-Web connects to the internet and whether to use any proxies.
+CPTempInternetFilesDescription=Java stores application data for faster execution the next time you run it.
+CPJRESettingsDescription=View and manage Java Runtime Environment versions and settings for Java applications and applets.
+CPCertificatesDescription=Use certificates to positively identify yourself, certifications, authorities, and plublishers.
+CPSecurityDescription=Use this to configure security settings.
+CPDebuggingDescription=Enable options here to help with debugging
+CPDesktopIntegrationDescription=Set whether or not to allow creation of desktop shortcut.
+
+# Control Panel - Buttons
+CPButAbout=About...
+CPButNetworkSettings=Network Settings...
+CPButSettings=Settings...
+CPButView=View...
+CPButCertificates=Certificates...
+
+# Control Panel - Headers
+CPHead=IcedTea Web Control Panel
+CPHeadAbout=About
+CPHeadNetworkSettings=Network Proxy Settings
+CPHeadTempInternetFiles=Temporary Internet Files
+CPHeadJRESettings=Java Runtime Environment Settings
+CPHeadCertificates=Certificates
+CPHeadDebugging=Debugging Settings
+CPHeadDesktopIntegration=Desktop Integrations
+CPHeadSecurity=Security Settings
+
+# Control Panel - Tabs
+CPTabAbout=About IcedTea-Web
+CPTabCache=Cache
+CPTabCertificate=Certificates
+CPTabClassLoader=Class Loaders
+CPTabDebugging=Debugging
+CPTabDesktopIntegration=Desktop Integration
+CPTabNetwork=Network
+CPTabRuntimes=Runtimes
+CPTabSecurity=Security
+
+# Control Panel - AboutPanel
+CPAboutInfo=This is the control panel for setting deployments.properties.<br/>Not all options will take effect until implemented.<br/>The use of multiple JREs is currently unsupported.<br/>
+
+# Control Panel - AdvancedProxySettings
+APSDialogTitle=Network Settings
+APSServersPanel=Servers
+APSProxyTypeLabel=Type
+APSProxyAddressLabel=Proxy Address
+APSProxyPortLabel=Proxy Port
+APSLabelHTTP=HTTP
+APSLabelSecure=Secure
+APSLabelFTP=FTP
+APSLabelSocks=Socks
+APSSameProxyForAllProtocols=Use the same proxy server for all protocols.
+APSExceptionsLabel=Exceptions
+APSExceptionsDescription=Do not use proxy server for addresses beginning with
+APSExceptionInstruction=Separate each entry with a semicolon.
+
+# Control Panel - DebugginPanel
+DPEnableTracing=Enable tracing
+DPEnableLogging=Enable logging
+DPDisable=Disable
+DPHide=Hide on startup
+DPShow=Show on startup
+DPJavaConsole=Java Console
+
+# Control Panel - DesktopShortcutPanel
+DSPNeverCreate=Never create
+DSPAlwaysAllow=Always allow
+DSPAskUser=Ask user
+DSPAskIfHinted=Ask if hinted
+DSPAlwaysIfHinted=Always if hinted
+
+# Control Panel - NetworkSettingsPanel
+NSDescription-1=Unknown Setting.
+NSDescription0=Use direct connection.
+NSDescription1=Override browser proxy settings.
+NSDescription2=Use automatic proxy configuration script at the specified location.
+NSDescription3=Use proxy settings from your default browser to connect to the internet.
+NSAddress=Address
+NSPort=Port
+NSAdvanced=Advanced
+NSBypassLocal=Bypass proxy server for local addresses
+NSDirectConnection=Direct connection
+NSManualProxy=Manual proxy server
+NSAutoProxy=Automatic proxy configuration script
+NSBrowserProxy=Use browser settings
+NSScriptLocation=Script location
+
+# Control Panel - SecurityGeneralPanel
+SGPAllowUserGrantSigned=Allow users to grant permissions to signed content
+SGPAllowUserGrantUntrust=Allow users to grant permissions to content from an untrusted authority
+SGPUseBrowserKeystore=Use certificates and keys in browser keystore (Unsupported)
+SGPUsePersonalCertOneMatch=Use personal certificate automatically if only one matches server request (Unsupported)
+SGPWarnCertHostMismatch=Warn if site certificate does not match hostname
+SGPShowValid=Show site certificate even if it is valid (Unsupported)
+SGPShowSandboxWarning=Show sandbox warning banner
+SGPAllowUserAcceptJNLPSecurityRequests=Allow user to accept JNLP security requests
+SGPCheckCertRevocationList=Check certificates for revocation using Certificate Revocation Lists (CRLs) (Unsupported)
+SGPEnableOnlineCertValidate=Enable online certificate validation (Unsupported)
+SGPEnableTrustedPublisherList=Enable list of trusted publishers (Unsupported)
+SGPEnableBlacklistRevocation=Enable blacklist revocation check (Unsupported)
+SGPEnableCachingPassword=Enable caching password for authentication (Unsupported)
+SGPUseSSL2=Use SSL 2.0 compatible ClientHello format (Unsupported)
+SGPUseSSL3=Use SSL 3.0 (Unsupported)
+SGPUseTLS1=Use TLS 1.0 (Unsupported)
+
+# Control Panel - TemporaryInternetFilesPanel
+TIFPEnableCache=Keep temporary files on my computer
+TIFPLocation=Location
+TIFPLocationLabel=Select the location where temporary files are kept
+TIFPChange=Change
+TIFPDiskSpace=Disk space
+TIFPCompressionLevel=Select the compression level for JAR files
+TIFPNone=None
+TIFPMax=Max
+TIFPCacheSize=Set the amount of disk space for storing temporary files
+TIFPDeleteFiles=Delete files
TIFPViewFiles=View files...
# Control Panel - Cache Viewer
@@ -409,12 +416,12 @@ CVCPColDomain=Domain CVCPColType=Type
CVCPColPath=Path
CVCPColName=Name
- -# Control Panel - Misc. -CPJRESupport=IcedTea-Web currently does not support the use of multiple JREs. -CPInvalidPort=Invalid port number given.\n[Valid port numbers are 1-65535] -CPInvalidPortTitle=Error on input. - +
+# Control Panel - Misc.
+CPJRESupport=IcedTea-Web currently does not support the use of multiple JREs.
+CPInvalidPort=Invalid port number given.\n[Valid port numbers are 1-65535]
+CPInvalidPortTitle=Error on input.
+
# command line control panel
CLNoInfo=No information avaiable (is this a valid option?).
CLValue=Value: {0}
diff --git a/netx/net/sourceforge/jnlp/util/PropertiesFile.java b/netx/net/sourceforge/jnlp/util/PropertiesFile.java index a3188e0..69dbf53 100644 --- a/netx/net/sourceforge/jnlp/util/PropertiesFile.java +++ b/netx/net/sourceforge/jnlp/util/PropertiesFile.java @@ -134,6 +134,7 @@ public class PropertiesFile extends Properties { OutputStream s = null; try { try { + file.getParentFile().mkdirs(); s = new FileOutputStream(file); store(s, header); } finally { |