aboutsummaryrefslogtreecommitdiffstats
path: root/netx/net
diff options
context:
space:
mode:
authorJiri Vanek <[email protected]>2013-07-18 08:53:46 +0200
committerJiri Vanek <[email protected]>2013-07-18 08:53:46 +0200
commit3650eabff054cd3c6b3670d248ffeb04e0b76478 (patch)
tree47d498921c29cd34a48026ac5c4a1b17b27aa3cd /netx/net
parent0fe719f17d81f95491b939f23b5d5c3111f7c427 (diff)
IcedTea-Web is now following XDG .config and .cache specification(RH947647)
Diffstat (limited to 'netx/net')
-rw-r--r--netx/net/sourceforge/jnlp/cache/CacheLRUWrapper.java7
-rw-r--r--netx/net/sourceforge/jnlp/config/Defaults.java47
-rw-r--r--netx/net/sourceforge/jnlp/config/DeploymentConfiguration.java150
-rw-r--r--netx/net/sourceforge/jnlp/controlpanel/CachePane.java3
-rw-r--r--netx/net/sourceforge/jnlp/controlpanel/CommandLine.java1
-rw-r--r--netx/net/sourceforge/jnlp/controlpanel/ControlPanel.java1
-rw-r--r--netx/net/sourceforge/jnlp/runtime/Boot.java2
-rw-r--r--netx/net/sourceforge/jnlp/util/FileUtils.java72
8 files changed, 253 insertions, 30 deletions
diff --git a/netx/net/sourceforge/jnlp/cache/CacheLRUWrapper.java b/netx/net/sourceforge/jnlp/cache/CacheLRUWrapper.java
index bf201af..45c8067 100644
--- a/netx/net/sourceforge/jnlp/cache/CacheLRUWrapper.java
+++ b/netx/net/sourceforge/jnlp/cache/CacheLRUWrapper.java
@@ -62,7 +62,7 @@ import net.sourceforge.jnlp.util.PropertiesFile;
* @author Andrew Su ([email protected], [email protected])
*
*/
-enum CacheLRUWrapper {
+public enum CacheLRUWrapper {
INSTANCE;
private int lockCount = 0;
@@ -80,9 +80,10 @@ enum CacheLRUWrapper {
* accessed) followed by folder of item. value = path to file.
*/
private PropertiesFile cacheOrder = new PropertiesFile(
- new File(cacheDir + File.separator + "recently_used"));
+ new File(cacheDir + File.separator + CACHE_INDEX_FILE_NAME));
+ public static final String CACHE_INDEX_FILE_NAME = "recently_used";
- private CacheLRUWrapper(){
+ private CacheLRUWrapper() {
File f = cacheOrder.getStoreFile();
if (!f.exists()) {
try {
diff --git a/netx/net/sourceforge/jnlp/config/Defaults.java b/netx/net/sourceforge/jnlp/config/Defaults.java
index 1191e9e..ee43d0c 100644
--- a/netx/net/sourceforge/jnlp/config/Defaults.java
+++ b/netx/net/sourceforge/jnlp/config/Defaults.java
@@ -51,28 +51,43 @@ import net.sourceforge.jnlp.runtime.JNLPProxySelector;
* This class stores the default configuration
*/
public class Defaults {
+
+ final static String SYSTEM_HOME = System.getProperty("java.home");
+ final static String SYSTEM_SECURITY = SYSTEM_HOME + File.separator + "lib" + File.separator + "security";
+ final static String USER_CONFIG_HOME;
+ final static String USER_CACHE_HOME;
+ final static String USER_SECURITY;
+ final static String LOCKS_DIR = System.getProperty("java.io.tmpdir") + File.separator
+ + System.getProperty("user.name") + File.separator + "netx" + File.separator
+ + "locks";
+ final static File userFile;
+
+ static {
+ String configHome = System.getProperty("user.home") + File.separator + DeploymentConfiguration.DEPLOYMENT_CONFIG_DIR;
+ String cacheHome = System.getProperty("user.home") + File.separator + DeploymentConfiguration.DEPLOYMENT_CACHE_DIR;
+ String XDG_CONFIG_HOME = System.getenv("XDG_CONFIG_HOME");
+ String XDG_CACHE_HOME = System.getenv("XDG_CACHE_HOME");
+ if (XDG_CONFIG_HOME != null) {
+ configHome = XDG_CONFIG_HOME + File.separator + DeploymentConfiguration.DEPLOYMENT_SUBDIR_DIR;
+ }
+ if (XDG_CACHE_HOME != null) {
+ cacheHome = XDG_CACHE_HOME + File.separator + DeploymentConfiguration.DEPLOYMENT_SUBDIR_DIR;
+ }
+ USER_CONFIG_HOME = configHome;
+ USER_CACHE_HOME = cacheHome;
+ USER_SECURITY = USER_CONFIG_HOME + File.separator + "security";
+ userFile = new File(USER_CONFIG_HOME + File.separator + DeploymentConfiguration.DEPLOYMENT_PROPERTIES);
+ }
/**
* Get the default settings for deployment
*/
public static Map<String, Setting<String>> getDefaults() {
- File userFile = new File(System.getProperty("user.home") + File.separator + DeploymentConfiguration.DEPLOYMENT_DIR
- + File.separator + DeploymentConfiguration.DEPLOYMENT_PROPERTIES);
-
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkRead(userFile.toString());
}
- final String SYSTEM_HOME = System.getProperty("java.home");
- final String SYSTEM_SECURITY = SYSTEM_HOME + File.separator + "lib" + File.separator + "security";
-
- final String USER_HOME = System.getProperty("user.home") + File.separator + DeploymentConfiguration.DEPLOYMENT_DIR;
- final String USER_SECURITY = USER_HOME + File.separator + "security";
-
- final String LOCKS_DIR = System.getProperty("java.io.tmpdir") + File.separator
- + System.getProperty("user.name") + File.separator + "netx" + File.separator
- + "locks";
/*
* This is more or less a straight copy from the deployment
@@ -90,12 +105,12 @@ public class Defaults {
{
DeploymentConfiguration.KEY_USER_CACHE_DIR,
BasicValueValidators.getFilePathValidator(),
- USER_HOME + File.separator + "cache"
+ USER_CACHE_HOME + File.separator + "cache"
},
{
DeploymentConfiguration.KEY_USER_PERSISTENCE_CACHE_DIR,
BasicValueValidators.getFilePathValidator(),
- USER_HOME + File.separator + "pcache"
+ USER_CACHE_HOME + File.separator + "pcache"
},
{
DeploymentConfiguration.KEY_SYSTEM_CACHE_DIR,
@@ -105,12 +120,12 @@ public class Defaults {
{
DeploymentConfiguration.KEY_USER_LOG_DIR,
BasicValueValidators.getFilePathValidator(),
- USER_HOME + File.separator + "log"
+ USER_CONFIG_HOME + File.separator + "log"
},
{
DeploymentConfiguration.KEY_USER_TMP_DIR,
BasicValueValidators.getFilePathValidator(),
- USER_HOME + File.separator + "tmp"
+ USER_CACHE_HOME + File.separator + "tmp"
},
{
DeploymentConfiguration.KEY_USER_LOCKS_DIR,
diff --git a/netx/net/sourceforge/jnlp/config/DeploymentConfiguration.java b/netx/net/sourceforge/jnlp/config/DeploymentConfiguration.java
index e4d1040..fd7cf9b 100644
--- a/netx/net/sourceforge/jnlp/config/DeploymentConfiguration.java
+++ b/netx/net/sourceforge/jnlp/config/DeploymentConfiguration.java
@@ -36,6 +36,7 @@ import java.util.Properties;
import java.util.Set;
import javax.naming.ConfigurationException;
+import net.sourceforge.jnlp.cache.CacheLRUWrapper;
import net.sourceforge.jnlp.runtime.JNLPRuntime;
import net.sourceforge.jnlp.util.FileUtils;
@@ -48,8 +49,10 @@ import net.sourceforge.jnlp.util.FileUtils;
*/
public final class DeploymentConfiguration {
- public static final String DEPLOYMENT_DIR = ".icedtea";
- public static final String DEPLOYMENT_CONFIG = "deployment.config";
+ public static final String DEPLOYMENT_SUBDIR_DIR = "icedtea-web";
+ public static final String DEPLOYMENT_CACHE_DIR = ".cache" + File.separator + DEPLOYMENT_SUBDIR_DIR;
+ public static final String DEPLOYMENT_CONFIG_DIR = ".config" + File.separator + DEPLOYMENT_SUBDIR_DIR;
+ public static final String DEPLOYMENT_CONFIG_FILE = "deployment.config";
public static final String DEPLOYMENT_PROPERTIES = "deployment.properties";
public static final String APPLET_TRUST_SETTINGS = ".appletTrustSettings";
@@ -181,8 +184,7 @@ public final class DeploymentConfiguration {
private File userPropertiesFile = null;
/*default user file*/
- public static final File USER_DEPLOYMENT_PROPERTIES_FILE = new File(System.getProperty("user.home") + File.separator + DEPLOYMENT_DIR
- + File.separator + DEPLOYMENT_PROPERTIES);
+ public static final File USER_DEPLOYMENT_PROPERTIES_FILE = new File(Defaults.USER_CONFIG_HOME + File.separator + DEPLOYMENT_PROPERTIES);
/** the current deployment properties */
private Map<String, Setting<String>> currentConfiguration;
@@ -206,8 +208,7 @@ public final class DeploymentConfiguration {
}
public static File getAppletTrustUserSettingsPath() {
- return new File(System.getProperty("user.home") + File.separator + DEPLOYMENT_DIR
- + File.separator + APPLET_TRUST_SETTINGS);
+ return new File(Defaults.USER_CONFIG_HOME + File.separator + APPLET_TRUST_SETTINGS);
}
public static File getAppletTrustGlobalSettingsPath() {
@@ -251,7 +252,7 @@ public final class DeploymentConfiguration {
if (systemConfigFile != null) {
if (loadSystemConfiguration(systemConfigFile)) {
if (JNLPRuntime.isDebug()) {
- System.out.println("System level " + DEPLOYMENT_CONFIG + " is mandatory: " + systemPropertiesMandatory);
+ System.out.println("System level " + DEPLOYMENT_CONFIG_FILE + " is mandatory: " + systemPropertiesMandatory);
}
/* Second, read the System level deployment.properties file */
systemProperties = loadProperties(ConfigType.System, systemPropertiesFile,
@@ -414,7 +415,7 @@ public final class DeploymentConfiguration {
*/
private File findSystemConfigFile() {
File etcFile = new File(File.separator + "etc" + File.separator + ".java" + File.separator
- + "deployment" + File.separator + DEPLOYMENT_CONFIG);
+ + "deployment" + File.separator + DEPLOYMENT_CONFIG_FILE);
if (etcFile.isFile()) {
return etcFile;
}
@@ -435,10 +436,10 @@ public final class DeploymentConfiguration {
File jreFile;
if (jrePath != null) {
jreFile = new File(jrePath + File.separator + "lib"
- + File.separator + DEPLOYMENT_CONFIG);
+ + File.separator + DEPLOYMENT_CONFIG_FILE);
} else {
jreFile = new File(System.getProperty("java.home") + File.separator + "lib"
- + File.separator + DEPLOYMENT_CONFIG);
+ + File.separator + DEPLOYMENT_CONFIG_FILE);
}
if (jreFile.isFile()) {
return jreFile;
@@ -681,4 +682,133 @@ public final class DeploymentConfiguration {
+ (value.isLocked() ? " [LOCKED]" : ""));
}
}
+
+ public static void move14AndOlderFilesTo15StructureCatched() {
+ try {
+ move14AndOlderFilesTo15Structure();
+ } catch (Throwable t) {
+ System.err.println("Critical error during converting old files to new. Continuing");
+ t.printStackTrace();
+ }
+
+ }
+
+ private static void move14AndOlderFilesTo15Structure() {
+ int errors = 0;
+ String PRE_15_DEPLOYMENT_DIR = ".icedtea";
+ String LEGACY_USER_HOME = System.getProperty("user.home") + File.separator + PRE_15_DEPLOYMENT_DIR;
+ File legacyUserDir = new File(LEGACY_USER_HOME);
+ if (legacyUserDir.exists()) {
+ System.out.println("Legacy configuration and cache found. Those will be now transported to new locations");
+ System.out.println(Defaults.USER_CONFIG_HOME + " and " + Defaults.USER_CACHE_HOME);
+ System.out.println("You should not see this message next time you run icedtea-web!");
+ System.out.println("Your custom dirs will not be touched and will work");
+ System.out.println("-----------------------------------------------");
+
+ System.out.println("Preparing new directories:");
+ System.out.println(" " + Defaults.USER_CONFIG_HOME);
+ File f1 = new File(Defaults.USER_CONFIG_HOME);
+ errors += resultToStd(f1.mkdirs());
+ System.out.println(" " + Defaults.USER_CACHE_HOME);
+ File f2 = new File(Defaults.USER_CACHE_HOME);
+ errors += resultToStd(f2.mkdirs());
+
+ String legacySecurity = LEGACY_USER_HOME + File.separator + "security";
+ String currentSecurity = Defaults.USER_SECURITY;
+ errors += moveLegacyToCurrent(legacySecurity, currentSecurity);
+
+ String legacyCache = LEGACY_USER_HOME + File.separator + "cache";
+ String currentCache = Defaults.getDefaults().get(DeploymentConfiguration.KEY_USER_CACHE_DIR).getDefaultValue();
+ errors += moveLegacyToCurrent(legacyCache, currentCache);
+ System.out.println("Adapting " + CacheLRUWrapper.CACHE_INDEX_FILE_NAME + " to new destination");
+ //replace all legacyCache by currentCache in new recently_used
+ try {
+ File f = new File(currentCache, CacheLRUWrapper.CACHE_INDEX_FILE_NAME);
+ String s = FileUtils.loadFileAsString(f);
+ s = s.replace(legacyCache, currentCache);
+ FileUtils.saveFile(s, f);
+ } catch (IOException ex) {
+ ex.printStackTrace();
+ errors++;
+ }
+
+ String legacyPcahceDir = LEGACY_USER_HOME + File.separator + "pcache";
+ String currentPcacheDir = Defaults.getDefaults().get(DeploymentConfiguration.KEY_USER_PERSISTENCE_CACHE_DIR).getDefaultValue();
+ errors += moveLegacyToCurrent(legacyPcahceDir, currentPcacheDir);
+
+ String legacyLogDir = LEGACY_USER_HOME + File.separator + "log";
+ String currentLogDir = Defaults.getDefaults().get(DeploymentConfiguration.KEY_USER_LOG_DIR).getDefaultValue();
+ errors += moveLegacyToCurrent(legacyLogDir, currentLogDir);
+
+ String legacyProperties = LEGACY_USER_HOME + File.separator + DEPLOYMENT_PROPERTIES;
+ String currentProperties = Defaults.USER_CONFIG_HOME + File.separator + DEPLOYMENT_PROPERTIES;
+ errors += moveLegacyToCurrent(legacyProperties, currentProperties);
+
+ String legacyPropertiesOld = LEGACY_USER_HOME + File.separator + DEPLOYMENT_PROPERTIES + ".old";
+ String currentPropertiesOld = Defaults.USER_CONFIG_HOME + File.separator + DEPLOYMENT_PROPERTIES + ".old";
+ errors += moveLegacyToCurrent(legacyPropertiesOld, currentPropertiesOld);
+
+
+ String legacyAppletTrust = LEGACY_USER_HOME + File.separator + APPLET_TRUST_SETTINGS;
+ String currentAppletTrust = getAppletTrustUserSettingsPath().getAbsolutePath();
+ errors += moveLegacyToCurrent(legacyAppletTrust, currentAppletTrust);
+
+ String legacyTmp = LEGACY_USER_HOME + File.separator + "tmp";
+ String currentTmp = Defaults.getDefaults().get(DeploymentConfiguration.KEY_USER_TMP_DIR).getDefaultValue();
+ errors += moveLegacyToCurrent(legacyTmp, currentTmp);
+
+ System.out.println("Removing now empty " + LEGACY_USER_HOME);
+ errors += resultToStd(legacyUserDir.delete());
+
+ if (errors != 0) {
+ System.out.println("There occureed " + errors + " errors");
+ System.out.println("Please double check content of old data in " + LEGACY_USER_HOME + " with ");
+ System.out.println("new " + Defaults.USER_CONFIG_HOME + " and " + Defaults.USER_CACHE_HOME);
+ System.out.println("To disable this check again, please remove " + LEGACY_USER_HOME);
+ }
+
+ } else {
+ if (JNLPRuntime.isDebug()) {
+ System.out.println("System is already following XDG .cache and .config specifications");
+ try {
+ System.out.println("config: " + Defaults.USER_CONFIG_HOME + " file exists: " + new File(Defaults.USER_CONFIG_HOME).exists());
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ try {
+ System.out.println("cache: " + Defaults.USER_CACHE_HOME + " file exists:" + new File(Defaults.USER_CACHE_HOME));
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }
+
+ }
+
+ private static int moveLegacyToCurrent(String legacy, String current) {
+ System.out.println("Moving " + legacy + " to " + current);
+ File cf = new File(current);
+ File old = new File(legacy);
+ if (cf.exists()) {
+ System.out.println("Warning! Destination " + current + " exists!");
+ }
+ if (old.exists()) {
+ boolean moved = old.renameTo(cf);
+ return resultToStd(moved);
+ } else {
+ System.out.println("Source " + legacy + " do not exists, nothing to do");
+ return 0;
+ }
+
+ }
+
+ private static int resultToStd(boolean securityMove) {
+ if (securityMove) {
+ System.out.println("OK");
+ return 0;
+ } else {
+ System.out.println("ERROR");
+ return 1;
+ }
+ }
}
diff --git a/netx/net/sourceforge/jnlp/controlpanel/CachePane.java b/netx/net/sourceforge/jnlp/controlpanel/CachePane.java
index ef65a0b..da3c92e 100644
--- a/netx/net/sourceforge/jnlp/controlpanel/CachePane.java
+++ b/netx/net/sourceforge/jnlp/controlpanel/CachePane.java
@@ -49,6 +49,7 @@ import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableRowSorter;
import net.sourceforge.jnlp.cache.CacheDirectory;
+import net.sourceforge.jnlp.cache.CacheLRUWrapper;
import net.sourceforge.jnlp.cache.DirectoryNode;
import net.sourceforge.jnlp.config.DeploymentConfiguration;
import net.sourceforge.jnlp.runtime.Translator;
@@ -202,7 +203,7 @@ public class CachePane extends JPanel {
}
private void updateRecentlyUsed(File f) {
- File recentlyUsedFile = new File(location + File.separator + "recently_used");
+ File recentlyUsedFile = new File(location + File.separator + CacheLRUWrapper.CACHE_INDEX_FILE_NAME);
PropertiesFile pf = new PropertiesFile(recentlyUsedFile);
pf.load();
Enumeration<Object> en = pf.keys();
diff --git a/netx/net/sourceforge/jnlp/controlpanel/CommandLine.java b/netx/net/sourceforge/jnlp/controlpanel/CommandLine.java
index c7f9c44..01093ee 100644
--- a/netx/net/sourceforge/jnlp/controlpanel/CommandLine.java
+++ b/netx/net/sourceforge/jnlp/controlpanel/CommandLine.java
@@ -453,6 +453,7 @@ public class CommandLine {
* @param args the command line arguments to this program
*/
public static void main(String[] args) throws Exception {
+ DeploymentConfiguration.move14AndOlderFilesTo15StructureCatched();
if (args.length == 0) {
ControlPanel.main(new String[] {});
} else {
diff --git a/netx/net/sourceforge/jnlp/controlpanel/ControlPanel.java b/netx/net/sourceforge/jnlp/controlpanel/ControlPanel.java
index 7def7b5..d118301 100644
--- a/netx/net/sourceforge/jnlp/controlpanel/ControlPanel.java
+++ b/netx/net/sourceforge/jnlp/controlpanel/ControlPanel.java
@@ -399,6 +399,7 @@ public class ControlPanel extends JFrame {
}
public static void main(String[] args) throws Exception {
+ DeploymentConfiguration.move14AndOlderFilesTo15StructureCatched();
final DeploymentConfiguration config = new DeploymentConfiguration();
try {
config.load();
diff --git a/netx/net/sourceforge/jnlp/runtime/Boot.java b/netx/net/sourceforge/jnlp/runtime/Boot.java
index 76b89b4..156b024 100644
--- a/netx/net/sourceforge/jnlp/runtime/Boot.java
+++ b/netx/net/sourceforge/jnlp/runtime/Boot.java
@@ -35,6 +35,7 @@ import net.sourceforge.jnlp.ParserSettings;
import net.sourceforge.jnlp.about.AboutDialog;
import net.sourceforge.jnlp.cache.CacheUtil;
import net.sourceforge.jnlp.cache.UpdatePolicy;
+import net.sourceforge.jnlp.config.DeploymentConfiguration;
import net.sourceforge.jnlp.security.viewer.CertificateViewer;
import net.sourceforge.jnlp.services.ServiceUtil;
import sun.awt.AppContext;
@@ -126,6 +127,7 @@ public final class Boot implements PrivilegedAction<Void> {
if (AppContext.getAppContext() == null) {
SunToolkit.createNewAppContext();
}
+ DeploymentConfiguration.move14AndOlderFilesTo15StructureCatched();
args = argsIn;
if (null != getOption("-viewer")) {
diff --git a/netx/net/sourceforge/jnlp/util/FileUtils.java b/netx/net/sourceforge/jnlp/util/FileUtils.java
index 804983d..d149bc0 100644
--- a/netx/net/sourceforge/jnlp/util/FileUtils.java
+++ b/netx/net/sourceforge/jnlp/util/FileUtils.java
@@ -16,12 +16,20 @@
package net.sourceforge.jnlp.util;
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
import static net.sourceforge.jnlp.runtime.Translator.R;
import java.io.File;
+import java.io.FileInputStream;
import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
import java.io.RandomAccessFile;
+import java.io.Writer;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;
@@ -369,4 +377,68 @@ public final class FileUtils {
}
return lock;
}
+
+ /**
+ * helping dummy method to save String as file
+ *
+ * @param content
+ * @param f
+ * @throws IOException
+ */
+ public static void saveFile(String content, File f) throws IOException {
+ saveFile(content, f, "utf-8");
+ }
+
+ public static void saveFile(String content, File f, String encoding) throws IOException {
+ Writer output = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f), encoding));
+ output.write(content);
+ output.flush();
+ output.close();
+ }
+
+ /**
+ * utility method which can read from any stream as one long String
+ *
+ * @param input stream
+ * @return stream as string
+ * @throws IOException if connection can't be established or resource does not exist
+ */
+ public static String getContentOfStream(InputStream is, String encoding) throws IOException {
+ try {
+ BufferedReader br = new BufferedReader(new InputStreamReader(is, encoding));
+ StringBuilder sb = new StringBuilder();
+ while (true) {
+ String s = br.readLine();
+ if (s == null) {
+ break;
+ }
+ sb.append(s).append("\n");
+
+ }
+ return sb.toString();
+ } finally {
+ is.close();
+ }
+
+ }
+
+ /**
+ * utility method which can read from any stream as one long String
+ *
+ * @param input stream
+ * @return stream as string
+ * @throws IOException if connection can't be established or resource does not exist
+ */
+ public static String getContentOfStream(InputStream is) throws IOException {
+ return getContentOfStream(is, "UTF-8");
+
+ }
+
+ public static String loadFileAsString(File f) throws IOException {
+ return getContentOfStream(new FileInputStream(f));
+ }
+
+ public static String loadFileAsString(File f, String encoding) throws IOException {
+ return getContentOfStream(new FileInputStream(f), encoding);
+ }
}