diff -r f18dea419aec ChangeLog --- a/ChangeLog Fri Jul 12 15:47:04 2013 -0400 +++ b/ChangeLog Sat Jul 13 13:19:44 2013 +0200 @@ -1,3 +1,41 @@ +2013-07-13 Jiri Vanek + + IcedTea-Web is now following XDG .config and .cache specification(RH947647) + * tests/reproducers/simple/simpletest1/testcases/XDGspecificationTests.java + new file, test if XDG specification and trasnfer to it are followed correctly, + * NEWS: mentioned new feature + * Makefile.am: (PUBLIC_KEYSTORE) repalced by (PUBLIC_KEYSTORE_STUB) which + is now holding only internal part of path.(exported-test-certs) + (netx-dist-tests-import-cert-to-public) (netx-dist-tests-remove-cert-from-public) + are now resolving XDG variable and setting real path of PUBLIC_KEYSTORE + by resolved value and (PUBLIC_KEYSTORE) + * netx/net/sourceforge/jnlp/cache/CacheLRUWrapper.java: changed to be public + and recently_used strign extracted to (CACHE_INDEX_FILE_NAME) constant + * netx/net/sourceforge/jnlp/config/Defaults.java: is now resovling and + propagating XDG_CONFIG/CACHE_HOME specification. (USER_HOME) repalced by + (USER_CACHE_HOME) and (USER_CONFIG_HOME). + (move14AndOlderFilesTo15Structure) new method responsible for moving + of old data to new locations. (move14AndOlderFilesTo15StructureCatched) + the same but with catch block + * netx/net/sourceforge/jnlp/controlpanel/CachePane.java: + * tests/netx/unit/net/sourceforge/jnlp/cache/CacheLRUWrapperTest.java: + * tests/netx/unit/net/sourceforge/jnlp/util/PropertiesFileTest.java: + are now using (CACHE_INDEX_FILE_NAME) + * netx/net/sourceforge/jnlp/controlpanel/CommandLine.java: (main) + * netx/net/sourceforge/jnlp/controlpanel/ControlPanel.java: (main) + * netx/net/sourceforge/jnlp/runtime/Boot.java: (main) + * plugin/icedteanp/java/sun/applet/PluginMain.java: (main) + are now calling DeploymentConfiguration.move14AndOlderFilesTo15StructureCatched + asap. + * netx/net/sourceforge/jnlp/util/FileUtils.java: various file manipulation + methods moved inside here from test-extensions - (saveFile) (getContentOfStream) + (loadFileAsString) - to avoid duplications + * tests/test-extensions/net/sourceforge/jnlp/ProcessWrapper.java: for puposes of + new test added constructor with string instead of URL + * tests/test-extensions/net/sourceforge/jnlp/ServerAccess.java: see FileUtils.java + + + 2013-07-11 Andrew Azores * NEWS: added entry regarding new About Dialogue diff -r f18dea419aec Makefile.am --- a/Makefile.am Fri Jul 12 15:47:04 2013 -0400 +++ b/Makefile.am Sat Jul 13 13:19:44 2013 +0200 @@ -37,7 +37,7 @@ export EXPORTED_TEST_CERT_PREFIX=icedteatests export EXPORTED_TEST_CERT_SUFFIX=crt export TEST_CERT_ALIAS=icedteaweb -export PUBLIC_KEYSTORE=${HOME}/.icedtea/security/trusted.certs +export PUBLIC_KEYSTORE_STUB=icedtea-web/security/trusted.certs export PUBLIC_KEYSTORE_PASS=changeit export SOFTKILLER=softkiller @@ -727,8 +727,13 @@ #with depending to not stamped target we always have to rerun reproducers targets stamps/exported-test-certs.stamp: stamps/change-dots-to-paths.stamp -types=($(SIGNED_REPRODUCERS)) ; \ + PUBLIC_KEYSTORE=$$XDG_CONFIG_HOME ; \ + if test "x$$PUBLIC_KEYSTORE" = x; then \ + PUBLIC_KEYSTORE=${HOME}/.config ; \ + fi ;\ + PUBLIC_KEYSTORE=$$PUBLIC_KEYSTORE/$(PUBLIC_KEYSTORE_STUB); \ for which in "$${types[@]}" ; do \ - $(BOOT_DIR)/bin/keytool -delete -alias $(TEST_CERT_ALIAS)_$$which -keystore $(PUBLIC_KEYSTORE) -storepass $(PUBLIC_KEYSTORE_PASS) ; \ + $(BOOT_DIR)/bin/keytool -delete -alias $(TEST_CERT_ALIAS)_$$which -keystore $$PUBLIC_KEYSTORE -storepass $(PUBLIC_KEYSTORE_PASS) ; \ done ; types=($(SIGNED_REPRODUCERS)) ; \ for which in "$${types[@]}" ; do \ @@ -739,16 +744,26 @@ stamps/netx-dist-tests-import-cert-to-public: stamps/exported-test-certs.stamp types=($(SIGNED_REPRODUCERS)) ; \ + PUBLIC_KEYSTORE=$$XDG_CONFIG_HOME ; \ + if test "x$$PUBLIC_KEYSTORE" = x; then \ + PUBLIC_KEYSTORE=${HOME}/.config ; \ + fi ;\ + PUBLIC_KEYSTORE=$$PUBLIC_KEYSTORE/$(PUBLIC_KEYSTORE_STUB); \ for which in "$${types[@]}" ; do \ - yes | $(BOOT_DIR)/bin/keytool -import -alias $(TEST_CERT_ALIAS)_$$which -keystore $(PUBLIC_KEYSTORE) -storepass $(PUBLIC_KEYSTORE_PASS) -file $(EXPORTED_TEST_CERT_PREFIX)_$$which.$(EXPORTED_TEST_CERT_SUFFIX) ;\ + yes | $(BOOT_DIR)/bin/keytool -import -alias $(TEST_CERT_ALIAS)_$$which -keystore $$PUBLIC_KEYSTORE -storepass $(PUBLIC_KEYSTORE_PASS) -file $(EXPORTED_TEST_CERT_PREFIX)_$$which.$(EXPORTED_TEST_CERT_SUFFIX) ;\ done ; mkdir -p stamps && \ touch $@ netx-dist-tests-remove-cert-from-public: -types=($(SIGNED_REPRODUCERS)) ; \ + PUBLIC_KEYSTORE=$$XDG_CONFIG_HOME ; \ + if test "x$$PUBLIC_KEYSTORE" = x; then \ + PUBLIC_KEYSTORE=${HOME}/.config ; \ + fi ;\ + PUBLIC_KEYSTORE=$$PUBLIC_KEYSTORE/$(PUBLIC_KEYSTORE_STUB); \ for which in "$${types[@]}" ; do \ - $(BOOT_DIR)/bin/keytool -delete -alias $(TEST_CERT_ALIAS)_$$which -keystore $(PUBLIC_KEYSTORE) -storepass $(PUBLIC_KEYSTORE_PASS) ; \ + $(BOOT_DIR)/bin/keytool -delete -alias $(TEST_CERT_ALIAS)_$$which -keystore $$PUBLIC_KEYSTORE -storepass $(PUBLIC_KEYSTORE_PASS) ; \ done ; -rm -rf stamps/netx-dist-tests-import-cert-to-public diff -r f18dea419aec NEWS --- a/NEWS Fri Jul 12 15:47:04 2013 -0400 +++ b/NEWS Sat Jul 13 13:19:44 2013 +0200 @@ -11,6 +11,7 @@ New in release 1.5 (2013-XX-XX): * IcedTea-Web now using tagsoup as default (tagsoup dependence) sanitizer for input * JDK older then 1.5 no longer supported +* IcedTea-Web is now following XDG .config and .cache specification(RH947647) * NetX - PR1465 - java.io.FileNotFoundException while trying to download a JAR file - Netx can now parse malformed jnlp files using tagsoup diff -r f18dea419aec launcher/launchers.in --- a/launcher/launchers.in Fri Jul 12 15:47:04 2013 -0400 +++ b/launcher/launchers.in Sat Jul 13 13:19:44 2013 +0200 @@ -9,9 +9,18 @@ PROGRAM_NAME=@PROGRAM_NAME@ CP=@JRE@/lib/rt.jar +CONFIG_HOME=$XDG_CONFIG_HOME +if [ "x$CONFIG_HOME" = "x" ] ; then + CONFIG_HOME=~/.config +fi; PROPERTY_NAME=deployment.jre.dir CUSTOM_JRE_REGEX="^$PROPERTY_NAME *= *" -CUSTOM_JRE=`grep "$CUSTOM_JRE_REGEX" ~/.icedtea/deployment.properties 2>/dev/null | sed "s/$CUSTOM_JRE_REGEX//g"` +CUSTOM_JRE=`grep "$CUSTOM_JRE_REGEX" $CONFIG_HOME/icedtea-web/deployment.properties 2>/dev/null | sed "s/$CUSTOM_JRE_REGEX//g"` +#now check in legacy one +if [ "x$CUSTOM_JRE" = "x" ] ; then + CUSTOM_JRE=`grep "$CUSTOM_JRE_REGEX" ~/.icedtea/deployment.properties 2>/dev/null | sed "s/$CUSTOM_JRE_REGEX//g"` +fi; +#now check in global one if [ "x$CUSTOM_JRE" = "x" ] ; then CUSTOM_JRE=`grep "$CUSTOM_JRE_REGEX" /etc/.java/.deploy/deployment.properties 2>/dev/null | sed "s/$CUSTOM_JRE_REGEX//g"` fi; diff -r f18dea419aec netx/net/sourceforge/jnlp/cache/CacheLRUWrapper.java --- a/netx/net/sourceforge/jnlp/cache/CacheLRUWrapper.java Fri Jul 12 15:47:04 2013 -0400 +++ b/netx/net/sourceforge/jnlp/cache/CacheLRUWrapper.java Sat Jul 13 13:19:44 2013 +0200 @@ -62,7 +62,7 @@ * @author Andrew Su (asu@redhat.com, andrew.su@utoronto.ca) * */ -enum CacheLRUWrapper { +public enum CacheLRUWrapper { INSTANCE; private int lockCount = 0; @@ -80,9 +80,10 @@ * 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 -r f18dea419aec netx/net/sourceforge/jnlp/config/Defaults.java --- a/netx/net/sourceforge/jnlp/config/Defaults.java Fri Jul 12 15:47:04 2013 -0400 +++ b/netx/net/sourceforge/jnlp/config/Defaults.java Sat Jul 13 13:19:44 2013 +0200 @@ -51,28 +51,43 @@ * 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> 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 @@ { 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 @@ { 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 -r f18dea419aec netx/net/sourceforge/jnlp/config/DeploymentConfiguration.java --- a/netx/net/sourceforge/jnlp/config/DeploymentConfiguration.java Fri Jul 12 15:47:04 2013 -0400 +++ b/netx/net/sourceforge/jnlp/config/DeploymentConfiguration.java Sat Jul 13 13:19:44 2013 +0200 @@ -36,6 +36,7 @@ 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 @@ */ 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 @@ 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> currentConfiguration; @@ -206,8 +208,7 @@ } 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 @@ 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 @@ */ 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 @@ 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 @@ + (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 -r f18dea419aec netx/net/sourceforge/jnlp/controlpanel/CachePane.java --- a/netx/net/sourceforge/jnlp/controlpanel/CachePane.java Fri Jul 12 15:47:04 2013 -0400 +++ b/netx/net/sourceforge/jnlp/controlpanel/CachePane.java Sat Jul 13 13:19:44 2013 +0200 @@ -49,6 +49,7 @@ 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 @@ } 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 en = pf.keys(); diff -r f18dea419aec netx/net/sourceforge/jnlp/controlpanel/CommandLine.java --- a/netx/net/sourceforge/jnlp/controlpanel/CommandLine.java Fri Jul 12 15:47:04 2013 -0400 +++ b/netx/net/sourceforge/jnlp/controlpanel/CommandLine.java Sat Jul 13 13:19:44 2013 +0200 @@ -453,6 +453,7 @@ * @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 -r f18dea419aec netx/net/sourceforge/jnlp/controlpanel/ControlPanel.java --- a/netx/net/sourceforge/jnlp/controlpanel/ControlPanel.java Fri Jul 12 15:47:04 2013 -0400 +++ b/netx/net/sourceforge/jnlp/controlpanel/ControlPanel.java Sat Jul 13 13:19:44 2013 +0200 @@ -399,6 +399,7 @@ } public static void main(String[] args) throws Exception { + DeploymentConfiguration.move14AndOlderFilesTo15StructureCatched(); final DeploymentConfiguration config = new DeploymentConfiguration(); try { config.load(); diff -r f18dea419aec netx/net/sourceforge/jnlp/runtime/Boot.java --- a/netx/net/sourceforge/jnlp/runtime/Boot.java Fri Jul 12 15:47:04 2013 -0400 +++ b/netx/net/sourceforge/jnlp/runtime/Boot.java Sat Jul 13 13:19:44 2013 +0200 @@ -35,6 +35,7 @@ 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 @@ if (AppContext.getAppContext() == null) { SunToolkit.createNewAppContext(); } + DeploymentConfiguration.move14AndOlderFilesTo15StructureCatched(); args = argsIn; if (null != getOption("-viewer")) { diff -r f18dea419aec netx/net/sourceforge/jnlp/util/FileUtils.java --- a/netx/net/sourceforge/jnlp/util/FileUtils.java Fri Jul 12 15:47:04 2013 -0400 +++ b/netx/net/sourceforge/jnlp/util/FileUtils.java Sat Jul 13 13:19:44 2013 +0200 @@ -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 @@ } 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); + } } diff -r f18dea419aec plugin/icedteanp/java/sun/applet/PluginMain.java --- a/plugin/icedteanp/java/sun/applet/PluginMain.java Fri Jul 12 15:47:04 2013 -0400 +++ b/plugin/icedteanp/java/sun/applet/PluginMain.java Sat Jul 13 13:19:44 2013 +0200 @@ -103,7 +103,7 @@ System.err.println("Invalid pipe names provided. Refusing to proceed."); System.exit(1); } - + DeploymentConfiguration.move14AndOlderFilesTo15StructureCatched(); try { PluginStreamHandler streamHandler = connect(args[0], args[1]); boolean redirectStreams = System.getenv().containsKey("ICEDTEAPLUGIN_DEBUG"); diff -r f18dea419aec tests/netx/unit/net/sourceforge/jnlp/cache/CacheLRUWrapperTest.java --- a/tests/netx/unit/net/sourceforge/jnlp/cache/CacheLRUWrapperTest.java Fri Jul 12 15:47:04 2013 -0400 +++ b/tests/netx/unit/net/sourceforge/jnlp/cache/CacheLRUWrapperTest.java Sat Jul 13 13:19:44 2013 +0200 @@ -55,7 +55,7 @@ .getProperty(DeploymentConfiguration.KEY_USER_CACHE_DIR)).getPath(); // does no DeploymentConfiguration exist for this file name? - private final String cacheIndexFileName = "recently_used"; + private final String cacheIndexFileName = CacheLRUWrapper.CACHE_INDEX_FILE_NAME; private final int noEntriesCacheFile = 1000; diff -r f18dea419aec tests/netx/unit/net/sourceforge/jnlp/util/PropertiesFileTest.java --- a/tests/netx/unit/net/sourceforge/jnlp/util/PropertiesFileTest.java Fri Jul 12 15:47:04 2013 -0400 +++ b/tests/netx/unit/net/sourceforge/jnlp/util/PropertiesFileTest.java Sat Jul 13 13:19:44 2013 +0200 @@ -43,6 +43,7 @@ import java.io.IOException; import java.nio.channels.FileLock; import java.nio.channels.OverlappingFileLockException; +import net.sourceforge.jnlp.cache.CacheLRUWrapper; import net.sourceforge.jnlp.config.DeploymentConfiguration; import net.sourceforge.jnlp.runtime.JNLPRuntime; @@ -61,7 +62,7 @@ .getProperty(DeploymentConfiguration.KEY_USER_CACHE_DIR)).getPath(); // does no DeploymentConfiguration exist for this file name? - private final String cacheIndexFileName = "recently_used"; + private final String cacheIndexFileName = CacheLRUWrapper.CACHE_INDEX_FILE_NAME; private final PropertiesFile cacheIndexFile = new PropertiesFile(new File(cacheDir + File.separatorChar + cacheIndexFileName)); private final int noEntriesCacheFile = 1000; diff -r f18dea419aec tests/reproducers/simple/simpletest1/testcases/XDGspecificationTests.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/reproducers/simple/simpletest1/testcases/XDGspecificationTests.java Sat Jul 13 13:19:44 2013 +0200 @@ -0,0 +1,1104 @@ +/* +Copyright (C) 2011 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. + */ + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import junit.framework.Assert; +import net.sourceforge.jnlp.ContentReaderListener; +import net.sourceforge.jnlp.ProcessResult; +import net.sourceforge.jnlp.ProcessWrapper; +import net.sourceforge.jnlp.ServerAccess; +import net.sourceforge.jnlp.annotations.Bug; +import net.sourceforge.jnlp.annotations.TestInBrowsers; +import net.sourceforge.jnlp.browsertesting.BrowserTest; +import net.sourceforge.jnlp.browsertesting.Browsers; +import net.sourceforge.jnlp.browsertesting.browsers.firefox.FirefoxProfilesOperator; +import net.sourceforge.jnlp.closinglisteners.RulesFolowingClosingListener; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.mozilla.javascript.edu.emory.mathcs.backport.java.util.Arrays; + +@Bug(id = "RH947647") +public class XDGspecificationTests extends BrowserTest { + + public static final String XDG_CONFIG_HOME = "XDG_CONFIG_HOME"; + public static final String XDG_CACHE_HOME = "XDG_CACHE_HOME"; + private static File backupMainDir; + + private static class Backup { + + public final File from; + public final File to; + + public Backup(File from, File to) { + this.from = from; + this.to = to; + } + } + //intentionaly not using constants from itw to check itw + private static final File oldRoot = new File(System.getProperty("user.home"), ".icedtea"); + private static final File realCache; + private static final File realConfig; + private static final File homeCache = new File(System.getProperty("user.home") + File.separator + ".cache" + File.separator + "icedtea-web"); + private static final File homeConfig = new File(System.getProperty("user.home") + File.separator + ".config" + File.separator + "icedtea-web"); + private static List hollyBackup; + + static { + server.LOGS_REPRINT = true; + String configHome = System.getProperty("user.home") + File.separator + ".config"; + String cacheHome = System.getProperty("user.home") + File.separator + ".cache"; + ; + String XDG_CONFIG_HOME_value = System.getenv(XDG_CONFIG_HOME); + String XDG_CACHE_HOME_value = System.getenv(XDG_CACHE_HOME); + if (XDG_CONFIG_HOME_value != null) { + configHome = XDG_CONFIG_HOME_value; + } + if (XDG_CACHE_HOME_value != null) { + cacheHome = XDG_CACHE_HOME_value; + } + realConfig = new File(configHome + File.separator + "icedtea-web"); + realCache = new File(cacheHome + File.separator + "icedtea-web"); + } + + @BeforeClass + public static void backup() throws IOException { + File base = tmpDir(); + backupMainDir = base; + hollyBackup = backupRealSettingsAndClear(base); + } + + @AfterClass + public static void restore() throws IOException { + cleanRealSettings(); + restoreSettings(hollyBackup); + deleteRecursively(backupMainDir); + } + + private static void mv(File oldRoot, File base, List l) { + if (oldRoot.exists()) { + ServerAccess.logOutputReprint("moving of " + oldRoot + " to " + base); + File dest = new File(base, oldRoot.getName()); + boolean a = oldRoot.renameTo(dest); + if (!a) { + ServerAccess.logErrorReprint("moving of " + oldRoot + " to " + base + " failed"); + } else { + ServerAccess.logOutputReprint("sucess"); + } + if (l != null) { + l.add(new Backup(oldRoot, dest)); + } + } else { + ServerAccess.logOutputReprint("Can not move " + oldRoot + " to " + base + " the source (the first) is misisng"); + } + } + + public static File tmpDir() throws IOException { + //creating in home, not in tmp, as we need to be sure the backup is on same device + File f = File.createTempFile("itwConfigCache", "tmpDir", new File(System.getProperty("user.home"))); + f.delete(); + f.mkdir(); + return f; + } + + private static List backupRealSettingsAndClear(File base) throws IOException { + File config = new File(base, "config"); + config.mkdirs(); + File cache = new File(base, "cache"); + cache.mkdirs(); + List l = new ArrayList(); + mv(oldRoot, base, l); + mv(realCache, config, l); + mv(realConfig, cache, l); + return l; + } + + private static void restoreSettings(List col) throws IOException { + for (Backup l : col) { + mv(l.to, l.from.getParentFile(), null); + } + } + + public static void deleteRecursively(File f) { + if (f.exists()) { + ServerAccess.logOutputReprint("removing " + f); + try { + FirefoxProfilesOperator.deleteRecursively(f); + } catch (IOException ex) { + ServerAccess.logException(ex); + } + } else { + ServerAccess.logOutputReprint("removal of " + f + " failed, do not exists"); + } + } + + private static void cleanRealSettings() { + deleteRecursively(oldRoot); + deleteRecursively(realCache); + deleteRecursively(realConfig); + } + + private static void cleanHomeSettings() { + deleteRecursively(oldRoot); + deleteRecursively(homeCache); + deleteRecursively(homeConfig); + } + + private String[] removeXdgVAlues() { + Map p = System.getenv(); + Set> r = p.entrySet(); + List> rr = new ArrayList(r); + Collections.sort(rr, new Comparator>() { + + @Override + public int compare(Entry o1, Entry o2) { + return o1.getKey().compareTo(o2.getKey()); + } + }); + List l = new ArrayList(p.size()); + int i = 0; + int c = 0; + for (Iterator> it = rr.iterator(); it.hasNext(); i++) { + Entry entry = it.next(); + String v = entry.getValue(); + String s = entry.getKey() + "=" + v; + //System.out.println(s); + if (entry.getKey().equals(XDG_CACHE_HOME) || entry.getKey().equals(XDG_CONFIG_HOME)) { + ServerAccess.logOutputReprint("ignoring " + s); + c++; + } else { + l.add(s); + } + + } + if (c == 0) { + ServerAccess.logOutputReprint("no XDG defined, no change in variables "); + } + return l.toArray(new String[l.size()]); + } + + private static String[] setXdgVAlues(File fakeRoot) { + return setXdgVAlues(new File(fakeRoot.getAbsolutePath() + File.separator + "customCache"), new File(fakeRoot.getAbsolutePath() + File.separator + "customConfig")); + } + + private static String[] setXdgVAlues(File cacheF, File configF) { + boolean cache = false; + boolean config = false; + Map p = System.getenv(); + Set> r = p.entrySet(); + List> rr = new ArrayList(r); + Collections.sort(rr, new Comparator>() { + + @Override + public int compare(Entry o1, Entry o2) { + return o1.getKey().compareTo(o2.getKey()); + } + }); + List l = new ArrayList(p.size() + 2); + int i = 0; + for (Iterator> it = rr.iterator(); it.hasNext(); i++) { + Entry entry = it.next(); + String v = entry.getValue(); + String s = entry.getKey() + "=" + v; + //System.out.println(s); + if (entry.getKey().equals(XDG_CACHE_HOME)) { + ServerAccess.logOutputReprint(entry.getKey() + " was " + v); + v = cacheF.getAbsolutePath(); + ServerAccess.logOutputReprint("set " + v); + cache = true; + } else if (entry.getKey().equals(XDG_CONFIG_HOME)) { + ServerAccess.logOutputReprint(entry.getKey() + " was " + v); + v = configF.getAbsolutePath(); + ServerAccess.logOutputReprint("set " + v); + config = true; + } + s = entry.getKey() + "=" + v; + l.add(s); + } + if (!cache) { + ServerAccess.logOutputReprint("was no cache"); + String v = cacheF.getAbsolutePath(); + ServerAccess.logOutputReprint("set " + v); + String s = XDG_CACHE_HOME + "=" + v; + l.add(s); + } + if (!config) { + ServerAccess.logOutputReprint("was no config"); + String v = configF.getAbsolutePath(); + ServerAccess.logOutputReprint("set " + v); + String s = XDG_CONFIG_HOME + "=" + v; + l.add(s); + } + + + return l.toArray(new String[l.size()]); + } + + private static void createFakeOldHomeCache() throws Exception { + File tmp = tmpDir(); + try { + ProcessWrapper pw = new ProcessWrapper( + server.getJavawsLocation(), + Arrays.asList(new String[]{ServerAccess.HEADLES_OPTION}), + server.getUrl("simpletest2.jnlp"), + (ContentReaderListener) null, + null, + setXdgVAlues(tmp, tmp)); + ProcessResult pr = pw.execute(); + Assert.assertTrue(simpletests2Run.toPassingString(), simpletests2Run.evaluate(pr.stderr)); + File currentConfigCache = new File(tmp, "icedtea-web"); + File oldIcedTea = new File(new File(System.getProperty("user.home")) + File.separator + ".icedtea"); + boolean a = currentConfigCache.renameTo(oldIcedTea); + Assert.assertTrue("creation of old cache by renaming " + currentConfigCache + " to " + oldIcedTea + " failed", a); + assertOldMainFilesInHome(false, true, false); + assertNotMainFilesInHome(true, true, true); + } finally { + deleteRecursively(tmp); + } + + } + + private static void createFakeOldHomeConfig() throws Exception { + File tmp = tmpDir(); + long t = ServerAccess.PROCESS_TIMEOUT; + ServerAccess.PROCESS_TIMEOUT = 5000; + try { + ProcessWrapper pw1 = new ProcessWrapper(); + pw1.setArgs(Arrays.asList( + new String[]{ + new File(server.getJavawsFile().getParentFile(), "itweb-settings").getAbsolutePath() + })); + pw1.setVars(setXdgVAlues(tmp, tmp)); + ProcessResult pr1 = pw1.execute(); + + + ProcessWrapper pw2 = new ProcessWrapper(); + pw2.setArgs(Arrays.asList( + new String[]{ + new File(server.getJavawsFile().getParentFile(), "itweb-settings").getAbsolutePath(), + "set", "oldBaf", "oldBaf" + })); + pw2.setVars(setXdgVAlues(tmp, tmp)); + ProcessResult pr2 = pw2.execute(); + Assert.assertTrue(notMoving.toPassingString(), notMoving.evaluate(pr1.stdout)); + Assert.assertTrue(notMoving.toPassingString(), notMoving.evaluate(pr2.stdout)); + Assert.assertTrue(unknownProperty.toPassingString(), unknownProperty.evaluate(pr2.stdout)); + File currentConfigCache = new File(tmp, "icedtea-web"); + File oldIcedTea = new File(new File(System.getProperty("user.home")) + File.separator + ".icedtea"); + boolean a = currentConfigCache.renameTo(oldIcedTea); + Assert.assertTrue("creation of old config by renaming " + currentConfigCache + " to " + oldIcedTea + " failed", a); + assertOldConfigFilesInHome(true, true, true); + assertNotConfigFilesInHome(true, true, true); + ; + } finally { + ServerAccess.PROCESS_TIMEOUT = t; + deleteRecursively(tmp); + } + + } + + @After + @Before + public void cleanHome() { + cleanHomeSettings(); + } + + @After + @Before + public void cleanReal() { + cleanRealSettings(); + } + + private static List getContentOfDirectory(File f) { + List result = new ArrayList(); + if (f == null || !f.exists() || !f.isDirectory()) { + return result; + } + File[] files = f.listFiles(); + for (int i = 0; i < files.length; i++) { + File file = files[i]; + if (file.isDirectory()) { + result.addAll(getContentOfDirectory(file)); + } else { + result.add(file); + } + + } + return result; + } + + private static String listToString(List... l) { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < l.length; i++) { + List list = l[i]; + for (File s : list) { + sb.append(s.getAbsolutePath()).append('\n'); + } + } + + return sb.toString(); + } + + private static void assertConfigFiles(String s, boolean certs, boolean trust, boolean props) { + if (certs) { + Assert.assertTrue(trustedCertsInside.toPassingString(), trustedCertsInside.evaluate(s)); + } + if (trust) { + Assert.assertTrue(appletTrustInside.toPassingString(), appletTrustInside.evaluate(s)); + } + if (props) { + Assert.assertTrue(propsInside.toPassingString(), propsInside.evaluate(s)); + } + Assert.assertTrue(icedteaHostInside.toPassingString(), icedteaHostInside.evaluate(s)); + } + + private static void assertMainFiles(String s, boolean s1, boolean s2, boolean a1) { + if (a1) { + Assert.assertTrue(appletJarInside.toPassingString(), appletJarInside.evaluate(s)); + } + if (s1) { + Assert.assertTrue(jnlpInside1.toPassingString(), jnlpInside1.evaluate(s)); + Assert.assertTrue(jarInside1.toPassingString(), jarInside1.evaluate(s)); + } + if (s2) { + Assert.assertTrue(jnlpInside2.toPassingString(), jnlpInside2.evaluate(s)); + Assert.assertTrue(jarInside2.toPassingString(), jarInside2.evaluate(s)); + } + Assert.assertTrue(localHostInside.toPassingString(), localHostInside.evaluate(s)); + Assert.assertTrue(cacheHostInside.toPassingString(), cacheHostInside.evaluate(s)); + Assert.assertTrue(icedteaHostInside.toPassingString(), icedteaHostInside.evaluate(s)); + Assert.assertTrue(securityHostInside.toPassingString(), securityHostInside.evaluate(s)); + Assert.assertTrue(trustedHostInside.toPassingString(), trustedHostInside.evaluate(s)); + } + + private static void assertNotConfigFiles(String s, boolean certs, boolean trust, boolean props) { + if (certs) { + Assert.assertFalse(trustedCertsInside.toFailingString(), trustedCertsInside.evaluate(s)); + } + if (trust) { + Assert.assertFalse(appletTrustInside.toFailingString(), appletTrustInside.evaluate(s)); + } + if (props) { + Assert.assertFalse(propsInside.toFailingString(), propsInside.evaluate(s)); + } + Assert.assertFalse(icedteaHostInside.toFailingString(), icedteaHostInside.evaluate(s)); + } + + private static void assertNotMainFiles(String s, boolean s1, boolean s2, boolean a1) { + if (a1) { + Assert.assertFalse(appletJarInside.toFailingString(), appletJarInside.evaluate(s)); + } + if (s1) { + Assert.assertFalse(jnlpInside1.toFailingString(), jnlpInside1.evaluate(s)); + Assert.assertFalse(jarInside1.toFailingString(), jarInside1.evaluate(s)); + } + if (s2) { + Assert.assertFalse(jnlpInside2.toFailingString(), jnlpInside2.evaluate(s)); + Assert.assertFalse(jarInside2.toFailingString(), jarInside2.evaluate(s)); + } + Assert.assertFalse(localHostInside.toFailingString(), localHostInside.evaluate(s)); + Assert.assertFalse(cacheHostInside.toFailingString(), cacheHostInside.evaluate(s)); + Assert.assertFalse(icedteaHostInside.toFailingString(), icedteaHostInside.evaluate(s)); + Assert.assertFalse(securityHostInside.toFailingString(), securityHostInside.evaluate(s)); + Assert.assertFalse(trustedHostInside.toFailingString(), trustedHostInside.evaluate(s)); + } + + private static void assertMainFilesInHome(boolean s1, boolean s2, boolean a1) { + String configHome = System.getProperty("user.home") + File.separator + ".config" + File.separator + "icedtea-web"; + String cacheHome = System.getProperty("user.home") + File.separator + ".cache" + File.separator + "icedtea-web"; + assertMainFiles( + listToString(getContentOfDirectory(new File(configHome))) + "\n" + + listToString(getContentOfDirectory(new File(cacheHome))), s1, s2, a1); + } + + private static void assertConfigFilesInHome(boolean certs, boolean trust, boolean props) { + String configHome = System.getProperty("user.home") + File.separator + ".config" + File.separator + "icedtea-web"; + String cacheHome = System.getProperty("user.home") + File.separator + ".cache" + File.separator + "icedtea-web"; + assertConfigFiles( + listToString(getContentOfDirectory(new File(configHome))) + "\n" + + listToString(getContentOfDirectory(new File(cacheHome))), certs, trust, props); + } + + private static void assertNotMainFilesInHome(boolean s1, boolean s2, boolean a1) { + String configHome = System.getProperty("user.home") + File.separator + ".config" + File.separator + "icedtea-web"; + String cacheHome = System.getProperty("user.home") + File.separator + ".cache" + File.separator + "icedtea-web"; + assertNotMainFiles( + listToString(getContentOfDirectory(new File(configHome))) + "\n" + + listToString(getContentOfDirectory(new File(cacheHome))), s1, s2, a1); + } + + private static void assertNotConfigFilesInHome(boolean certs, boolean trust, boolean props) { + String configHome = System.getProperty("user.home") + File.separator + ".config" + File.separator + "icedtea-web"; + String cacheHome = System.getProperty("user.home") + File.separator + ".cache" + File.separator + "icedtea-web"; + assertNotConfigFiles( + listToString(getContentOfDirectory(new File(configHome))) + "\n" + + listToString(getContentOfDirectory(new File(cacheHome))), certs, trust, props); + } + //runs + private static final RulesFolowingClosingListener.ContainsRule simpletests1Run = new RulesFolowingClosingListener.ContainsRule("Good simple javaws exapmle"); + private static final RulesFolowingClosingListener.ContainsRule simpletests2Run = new RulesFolowingClosingListener.ContainsRule("Correct exception"); + private static final RulesFolowingClosingListener.ContainsRule moving = new RulesFolowingClosingListener.ContainsRule("Legacy configuration and cache found. Those will be now transported to new location"); + private static final RulesFolowingClosingListener.NotContainsRule notMoving = new RulesFolowingClosingListener.NotContainsRule("Legacy configuration and cache found. Those will be now transported to new location"); + private static final RulesFolowingClosingListener.ContainsRule unknownProperty = new RulesFolowingClosingListener.ContainsRule("WARNING: Unknown property name"); + private static final RulesFolowingClosingListener.ContainsRule applet1Run = new RulesFolowingClosingListener.ContainsRule("applet was started"); + //javaws/plugin files + private static final RulesFolowingClosingListener.ContainsRule jnlpInside1 = new RulesFolowingClosingListener.ContainsRule("/simpletest1.jnlp"); + private static final RulesFolowingClosingListener.ContainsRule jarInside1 = new RulesFolowingClosingListener.ContainsRule("/simpletest1.jar"); + private static final RulesFolowingClosingListener.ContainsRule jnlpInside2 = new RulesFolowingClosingListener.ContainsRule("/simpletest2.jnlp"); + private static final RulesFolowingClosingListener.ContainsRule jarInside2 = new RulesFolowingClosingListener.ContainsRule("/simpletest2.jar"); + private static final RulesFolowingClosingListener.ContainsRule appletJarInside = new RulesFolowingClosingListener.ContainsRule("AppletTest.jar"); + //private static final RulesFolowingClosingListener.ContainsRule appletHtmlInside = new RulesFolowingClosingListener.ContainsRule("appletAutoTests2.html"); not caching htmls + //common files + private static final RulesFolowingClosingListener.ContainsRule localHostInside = new RulesFolowingClosingListener.ContainsRule("/localhost/"); + private static final RulesFolowingClosingListener.ContainsRule cacheHostInside = new RulesFolowingClosingListener.ContainsRule("/cache/"); + private static final RulesFolowingClosingListener.ContainsRule icedteaHostInside = new RulesFolowingClosingListener.ContainsRule("/icedtea-web/"); + private static final RulesFolowingClosingListener.ContainsRule oldIcedteaHostInside = new RulesFolowingClosingListener.ContainsRule("/.icedtea/"); + private static final RulesFolowingClosingListener.ContainsRule securityHostInside = new RulesFolowingClosingListener.ContainsRule("/security/"); + private static final RulesFolowingClosingListener.ContainsRule trustedHostInside = new RulesFolowingClosingListener.ContainsRule("/trusted"); + //config files + private static final RulesFolowingClosingListener.ContainsRule trustedCertsInside = new RulesFolowingClosingListener.ContainsRule("trusted.cacerts"); + private static final RulesFolowingClosingListener.ContainsRule appletTrustInside = new RulesFolowingClosingListener.ContainsRule(".appletTrustSettings"); + private static final RulesFolowingClosingListener.ContainsRule propsInside = new RulesFolowingClosingListener.ContainsRule("deployment.properties"); + + /* + *JAVAWS - NO OLD CONFIG + */ + @Test + public void runJavawsInCleanSystemWithNoXdg() throws Exception { + assertNotMainFilesInHome(true, true, true); + assertOldNotMainFilesInHome(true, true, true); + ProcessWrapper pw = new ProcessWrapper(server.getJavawsLocation(), null, server.getUrl("simpletest1.jnlp"), (ContentReaderListener) null, null, removeXdgVAlues()); + ProcessResult pr = pw.execute(); + Assert.assertTrue(simpletests1Run.toPassingString(), simpletests1Run.evaluate(pr.stdout)); + Assert.assertTrue(notMoving.toPassingString(), notMoving.evaluate(pr.stdout)); + assertMainFilesInHome(true, false, false); + assertOldNotMainFilesInHome(true, true, true); + } + + @Test + public void runJavawsInCleanSystemWithXdg() throws Exception { + File f = tmpDir(); + try { + assertNotMainFiles(listToString(getContentOfDirectory(f)), true, true, true); + assertOldNotMainFilesInHome(true, true, true); + ProcessWrapper pw = new ProcessWrapper(server.getJavawsLocation(), null, server.getUrl("simpletest1.jnlp"), (ContentReaderListener) null, null, setXdgVAlues(f)); + ProcessResult pr = pw.execute(); + Assert.assertTrue(simpletests1Run.toPassingString(), simpletests1Run.evaluate(pr.stdout)); + Assert.assertTrue(notMoving.toPassingString(), notMoving.evaluate(pr.stdout)); + assertMainFiles(listToString(getContentOfDirectory(f)), true, false, false); + assertOldNotMainFilesInHome(true, true, true); + } finally { + deleteRecursively(f); + } + } + + @Test + public void runJavawsInCleanSystemWithXdgAndNoParent() throws Exception { + File f = tmpDir(); + try { + assertNotMainFiles(listToString(getContentOfDirectory(f)), true, true, true); + assertOldNotMainFilesInHome(true, true, true); + f.delete(); + ProcessWrapper pw = new ProcessWrapper(server.getJavawsLocation(), null, server.getUrl("simpletest1.jnlp"), (ContentReaderListener) null, null, setXdgVAlues(f)); + ProcessResult pr = pw.execute(); + Assert.assertTrue(simpletests1Run.toPassingString(), simpletests1Run.evaluate(pr.stdout)); + Assert.assertTrue(notMoving.toPassingString(), notMoving.evaluate(pr.stdout)); + assertMainFiles(listToString(getContentOfDirectory(f)), true, false, false); + assertOldNotMainFilesInHome(true, true, true); + } finally { + deleteRecursively(f); + } + } + + private static void assertOldMainFiles(String s, boolean s1, boolean s2, boolean a1) { + if (a1) { + Assert.assertTrue(appletJarInside.toPassingString(), appletJarInside.evaluate(s)); + } + if (s1) { + Assert.assertTrue(jnlpInside1.toPassingString(), jnlpInside1.evaluate(s)); + Assert.assertTrue(jarInside1.toPassingString(), jarInside1.evaluate(s)); + } + if (s2) { + Assert.assertTrue(jnlpInside2.toPassingString(), jnlpInside2.evaluate(s)); + Assert.assertTrue(jarInside2.toPassingString(), jarInside2.evaluate(s)); + } + Assert.assertTrue(localHostInside.toPassingString(), localHostInside.evaluate(s)); + Assert.assertTrue(cacheHostInside.toPassingString(), cacheHostInside.evaluate(s)); + Assert.assertTrue(oldIcedteaHostInside.toPassingString(), oldIcedteaHostInside.evaluate(s)); + Assert.assertTrue(securityHostInside.toPassingString(), securityHostInside.evaluate(s)); + Assert.assertTrue(trustedHostInside.toPassingString(), trustedHostInside.evaluate(s)); + } + + private static void assertOldConfigFiles(String s, boolean certs, boolean trust, boolean props) { + if (certs) { + Assert.assertTrue(trustedCertsInside.toPassingString(), trustedCertsInside.evaluate(s)); + } + if (trust) { + Assert.assertTrue(appletTrustInside.toPassingString(), appletTrustInside.evaluate(s)); + } + if (props) { + Assert.assertTrue(propsInside.toPassingString(), propsInside.evaluate(s)); + } + Assert.assertTrue(oldIcedteaHostInside.toPassingString(), oldIcedteaHostInside.evaluate(s)); + } + + private static void assertOldNotMainFiles(String s, boolean s1, boolean s2, boolean a1) { + if (a1) { + Assert.assertFalse(appletJarInside.toFailingString(), appletJarInside.evaluate(s)); + } + if (s1) { + Assert.assertFalse(jnlpInside1.toFailingString(), jnlpInside1.evaluate(s)); + Assert.assertFalse(jarInside1.toFailingString(), jarInside1.evaluate(s)); + } + if (s2) { + Assert.assertFalse(jnlpInside2.toFailingString(), jnlpInside2.evaluate(s)); + Assert.assertFalse(jarInside2.toFailingString(), jarInside2.evaluate(s)); + } + Assert.assertFalse(localHostInside.toFailingString(), localHostInside.evaluate(s)); + Assert.assertFalse(cacheHostInside.toFailingString(), cacheHostInside.evaluate(s)); + Assert.assertFalse(oldIcedteaHostInside.toFailingString(), oldIcedteaHostInside.evaluate(s)); + Assert.assertFalse(securityHostInside.toFailingString(), securityHostInside.evaluate(s)); + Assert.assertFalse(trustedHostInside.toFailingString(), trustedHostInside.evaluate(s)); + } + + private static void assertOldNotConfigFiles(String s, boolean certs, boolean trust, boolean props) { + if (certs) { + Assert.assertFalse(trustedCertsInside.toFailingString(), trustedCertsInside.evaluate(s)); + } + if (trust) { + Assert.assertFalse(appletTrustInside.toFailingString(), appletTrustInside.evaluate(s)); + } + if (props) { + Assert.assertFalse(propsInside.toFailingString(), propsInside.evaluate(s)); + } + Assert.assertFalse(oldIcedteaHostInside.toFailingString(), oldIcedteaHostInside.evaluate(s)); + } + + private static void assertOldMainFilesInHome(boolean s1, boolean s2, boolean a1) { + String oldHome = System.getProperty("user.home") + File.separator + ".icedtea"; + assertOldMainFiles(listToString(getContentOfDirectory(new File(oldHome))), s1, s2, a1); + } + + private static void assertOldNotMainFilesInHome(boolean s1, boolean s2, boolean a1) { + String oldHome = System.getProperty("user.home") + File.separator + ".icedtea"; + assertOldNotMainFiles(listToString(getContentOfDirectory(new File(oldHome))), s1, s2, a1); + } + + private static void assertOldConfigFilesInHome(boolean certs, boolean trust, boolean props) { + String oldHome = System.getProperty("user.home") + File.separator + ".icedtea"; + assertOldConfigFiles(listToString(getContentOfDirectory(new File(oldHome))), certs, trust, props); + } + + private static void assertOldNotConfigFilesInHome(boolean certs, boolean trust, boolean props) { + String oldHome = System.getProperty("user.home") + File.separator + ".icedtea"; + assertOldNotConfigFiles(listToString(getContentOfDirectory(new File(oldHome))), certs, trust, props); + } + + /* + *JAVAWS - OLD CONFIG EXISTS + */ + @Test + public void runJavawsWithNoXdg_oldIcedTeaConfigExisted() throws Exception { + assertNotMainFilesInHome(true, true, true); + assertOldNotMainFilesInHome(true, true, true); + createFakeOldHomeCache(); + ProcessWrapper pw1 = new ProcessWrapper(server.getJavawsLocation(), null, server.getUrl("simpletest1.jnlp"), (ContentReaderListener) null, null, removeXdgVAlues()); + ProcessResult pr1 = pw1.execute(); + Assert.assertTrue(simpletests1Run.toPassingString(), simpletests1Run.evaluate(pr1.stdout)); + Assert.assertTrue(moving.toPassingString(), moving.evaluate(pr1.stdout)); + assertMainFilesInHome(true, true, false); + assertOldNotMainFilesInHome(true, true, true); + + ProcessWrapper pw2 = new ProcessWrapper(server.getJavawsLocation(), null, server.getUrl("simpletest1.jnlp"), (ContentReaderListener) null, null, removeXdgVAlues()); + ProcessResult pr2 = pw2.execute(); + Assert.assertTrue(simpletests1Run.toPassingString(), simpletests1Run.evaluate(pr2.stdout)); + Assert.assertTrue(notMoving.toPassingString(), notMoving.evaluate(pr2.stdout)); + assertMainFilesInHome(true, true, false); + assertOldNotMainFilesInHome(true, true, true); + + } + + @Test + public void runJavawsWithXdg_oldIcedTeaConfigExisted() throws Exception { + File f = tmpDir(); + try { + assertNotMainFiles(listToString(getContentOfDirectory(f)), true, true, true); + assertOldNotMainFilesInHome(true, true, true); + createFakeOldHomeCache(); + ProcessWrapper pw = new ProcessWrapper(server.getJavawsLocation(), null, server.getUrl("simpletest1.jnlp"), (ContentReaderListener) null, null, setXdgVAlues(f)); + ProcessResult pr = pw.execute(); + Assert.assertTrue(simpletests1Run.toPassingString(), simpletests1Run.evaluate(pr.stdout)); + Assert.assertTrue(moving.toPassingString(), moving.evaluate(pr.stdout)); + assertMainFiles(listToString(getContentOfDirectory(f)), true, true, false); + assertOldNotMainFilesInHome(true, true, true); + ProcessWrapper pw2 = new ProcessWrapper(server.getJavawsLocation(), null, server.getUrl("simpletest1.jnlp"), (ContentReaderListener) null, null, removeXdgVAlues()); + ProcessResult pr2 = pw2.execute(); + Assert.assertTrue(simpletests1Run.toPassingString(), simpletests1Run.evaluate(pr2.stdout)); + Assert.assertTrue(notMoving.toPassingString(), notMoving.evaluate(pr2.stdout)); + assertMainFiles(listToString(getContentOfDirectory(f)), true, true, false); + assertOldNotMainFilesInHome(true, true, true); + } finally { + deleteRecursively(f); + } + } + + @Test + public void runJavawsWithXdgAndNoParent_oldIcedTeaConfigExisted() throws Exception { + File f = tmpDir(); + try { + assertNotMainFiles(listToString(getContentOfDirectory(f)), true, true, true); + assertOldNotMainFilesInHome(true, true, true); + createFakeOldHomeCache(); + f.delete(); + ProcessWrapper pw = new ProcessWrapper(server.getJavawsLocation(), null, server.getUrl("simpletest1.jnlp"), (ContentReaderListener) null, null, setXdgVAlues(f)); + ProcessResult pr = pw.execute(); + Assert.assertTrue(simpletests1Run.toPassingString(), simpletests1Run.evaluate(pr.stdout)); + Assert.assertTrue(moving.toPassingString(), moving.evaluate(pr.stdout)); + assertMainFiles(listToString(getContentOfDirectory(f)), true, true, false); + assertOldNotMainFilesInHome(true, true, true); + ProcessWrapper pw2 = new ProcessWrapper(server.getJavawsLocation(), null, server.getUrl("simpletest1.jnlp"), (ContentReaderListener) null, null, removeXdgVAlues()); + ProcessResult pr2 = pw2.execute(); + Assert.assertTrue(simpletests1Run.toPassingString(), simpletests1Run.evaluate(pr2.stdout)); + Assert.assertTrue(notMoving.toPassingString(), notMoving.evaluate(pr2.stdout)); + assertMainFiles(listToString(getContentOfDirectory(f)), true, true, false); + assertOldNotMainFilesInHome(true, true, true); + } finally { + deleteRecursively(f); + } + } + + /* + *ITW-SETTINGS gui - NO OLD CONFIG + */ + @Test + public void runItwGuiInCleanSystemWithNoXdg() throws Exception { + long t = ServerAccess.PROCESS_TIMEOUT; + ServerAccess.PROCESS_TIMEOUT = 5000; + try { + assertNotConfigFilesInHome(true, true, true); + assertOldNotConfigFilesInHome(true, true, true); + ProcessWrapper pw = new ProcessWrapper(); + pw.setArgs(Arrays.asList( + new String[]{ + new File(server.getJavawsFile().getParentFile(), "itweb-settings").getAbsolutePath() + })); + pw.setVars(removeXdgVAlues()); + ProcessResult pr = pw.execute(); + Assert.assertTrue(notMoving.toPassingString(), notMoving.evaluate(pr.stdout)); + assertConfigFilesInHome(true, true, true); + assertOldNotConfigFilesInHome(true, true, true); + } finally { + ServerAccess.PROCESS_TIMEOUT = t; + } + } + + @Test + public void runItwGuiInCleanSystemWithXdg() throws Exception { + File f = tmpDir(); + long t = ServerAccess.PROCESS_TIMEOUT; + ServerAccess.PROCESS_TIMEOUT = 5000; + try { + assertNotConfigFiles(listToString(getContentOfDirectory(f)), true, true, true); + assertOldNotConfigFilesInHome(true, true, true); + ProcessWrapper pw = new ProcessWrapper(); + pw.setArgs(Arrays.asList( + new String[]{ + new File(server.getJavawsFile().getParentFile(), "itweb-settings").getAbsolutePath() + })); + pw.setVars(setXdgVAlues(f)); + ProcessResult pr = pw.execute(); + Assert.assertTrue(notMoving.toPassingString(), notMoving.evaluate(pr.stdout)); + assertConfigFiles(listToString(getContentOfDirectory(f)), true, true, true); + assertOldNotConfigFilesInHome(true, true, true); + } finally { + ServerAccess.PROCESS_TIMEOUT = t; + deleteRecursively(f); + } + } + /* + *ITW-SETTINGS gui- OLD CONFIG EXISTS + */ + + @Test + public void runItwGuiWithNoXdg_oldIcedTeaConfigExisted() throws Exception { + long t = ServerAccess.PROCESS_TIMEOUT; + ServerAccess.PROCESS_TIMEOUT = 5000; + try { + assertNotConfigFilesInHome(true, true, true); + assertOldNotConfigFilesInHome(true, true, true); + createFakeOldHomeConfig(); + ProcessWrapper pw1 = new ProcessWrapper(); + pw1.setArgs(Arrays.asList( + new String[]{ + new File(server.getJavawsFile().getParentFile(), "itweb-settings").getAbsolutePath() + })); + pw1.setVars(removeXdgVAlues()); + ProcessResult pr1 = pw1.execute(); + Assert.assertTrue(moving.toPassingString(), moving.evaluate(pr1.stdout)); + assertConfigFilesInHome(true, true, true); + assertOldNotConfigFilesInHome(true, true, true); + + ProcessWrapper pw2 = new ProcessWrapper(); + pw2.setArgs(Arrays.asList( + new String[]{ + new File(server.getJavawsFile().getParentFile(), "itweb-settings").getAbsolutePath() + })); + pw2.setVars(removeXdgVAlues()); + ProcessResult pr2 = pw2.execute(); + Assert.assertTrue(notMoving.toPassingString(), notMoving.evaluate(pr2.stdout)); + assertConfigFilesInHome(true, true, true); + assertOldNotConfigFilesInHome(true, true, true); + } finally { + ServerAccess.PROCESS_TIMEOUT = t; + } + + } + + @Test + public void runItwGuiWithXdg_oldIcedTeaConfigExisted() throws Exception { + File f = tmpDir(); + long t = ServerAccess.PROCESS_TIMEOUT; + ServerAccess.PROCESS_TIMEOUT = 5000; + try { + assertNotConfigFiles(listToString(getContentOfDirectory(f)), true, true, true); + assertOldNotConfigFilesInHome(true, true, true); + createFakeOldHomeConfig(); + ProcessWrapper pw1 = new ProcessWrapper(); + pw1.setArgs(Arrays.asList( + new String[]{ + new File(server.getJavawsFile().getParentFile(), "itweb-settings").getAbsolutePath() + })); + pw1.setVars(setXdgVAlues(f)); + ProcessResult pr = pw1.execute(); + Assert.assertTrue(moving.toPassingString(), moving.evaluate(pr.stdout)); + assertConfigFiles(listToString(getContentOfDirectory(f)), true, true, true); + assertOldNotConfigFilesInHome(true, true, true); + ProcessWrapper pw2 = new ProcessWrapper(); + pw2.setArgs(Arrays.asList( + new String[]{ + new File(server.getJavawsFile().getParentFile(), "itweb-settings").getAbsolutePath() + })); + pw2.setVars(removeXdgVAlues()); + ProcessResult pr2 = pw2.execute(); + Assert.assertTrue(notMoving.toPassingString(), notMoving.evaluate(pr2.stdout)); + assertConfigFiles(listToString(getContentOfDirectory(f)), true, true, true); + assertOldNotConfigFilesInHome(true, true, true); + } finally { + ServerAccess.PROCESS_TIMEOUT = t; + deleteRecursively(f); + } + } + /* + *ITW-SETTINGS commandline - NO OLD CONFIG + */ + + @Test + public void runItwCmdInCleanSystemWithNoXdg() throws Exception { + long t = ServerAccess.PROCESS_TIMEOUT; + ServerAccess.PROCESS_TIMEOUT = 5000; + try { + assertNotConfigFilesInHome(true, true, true); + assertOldNotConfigFilesInHome(true, true, true); + ProcessWrapper pw = new ProcessWrapper(); + pw.setArgs(Arrays.asList( + new String[]{ + new File(server.getJavawsFile().getParentFile(), "itweb-settings").getAbsolutePath(), + "set", "blah", "blah" + })); + pw.setVars(removeXdgVAlues()); + ProcessResult pr = pw.execute(); + Assert.assertTrue(notMoving.toPassingString(), notMoving.evaluate(pr.stdout)); + Assert.assertTrue(unknownProperty.toPassingString(), unknownProperty.evaluate(pr.stdout)); + assertConfigFilesInHome(false, false, true); + assertOldNotConfigFilesInHome(true, true, true); + } finally { + ServerAccess.PROCESS_TIMEOUT = t; + } + } + + @Test + public void runItwCmdInCleanSystemWithXdg() throws Exception { + File f = tmpDir(); + long t = ServerAccess.PROCESS_TIMEOUT; + ServerAccess.PROCESS_TIMEOUT = 5000; + try { + assertNotConfigFiles(listToString(getContentOfDirectory(f)), true, true, true); + assertOldNotConfigFilesInHome(true, true, true); + ProcessWrapper pw = new ProcessWrapper(); + pw.setArgs(Arrays.asList( + new String[]{ + new File(server.getJavawsFile().getParentFile(), "itweb-settings").getAbsolutePath(), + "set", "blah", "blah" + })); + pw.setVars(setXdgVAlues(f)); + ProcessResult pr = pw.execute(); + Assert.assertTrue(notMoving.toPassingString(), notMoving.evaluate(pr.stdout)); + Assert.assertTrue(unknownProperty.toPassingString(), unknownProperty.evaluate(pr.stdout)); + assertConfigFiles(listToString(getContentOfDirectory(f)), false, false, true); + assertOldNotConfigFilesInHome(true, true, true); + } finally { + ServerAccess.PROCESS_TIMEOUT = t; + deleteRecursively(f); + } + } + /* + *ITW-SETTINGS commandline- OLD CONFIG EXISTS + */ + + @Test + public void runItwCmdWithNoXdg_oldIcedTeaConfigExisted() throws Exception { + long t = ServerAccess.PROCESS_TIMEOUT; + ServerAccess.PROCESS_TIMEOUT = 5000; + try { + assertNotConfigFilesInHome(true, true, true); + assertOldNotConfigFilesInHome(true, true, true); + createFakeOldHomeConfig(); + ProcessWrapper pw1 = new ProcessWrapper(); + pw1.setArgs(Arrays.asList( + new String[]{ + new File(server.getJavawsFile().getParentFile(), "itweb-settings").getAbsolutePath(), + "set", "blah", "blah" + })); + pw1.setVars(removeXdgVAlues()); + ProcessResult pr1 = pw1.execute(); + Assert.assertTrue(moving.toPassingString(), moving.evaluate(pr1.stdout)); + Assert.assertTrue(unknownProperty.toPassingString(), unknownProperty.evaluate(pr1.stdout)); + assertConfigFilesInHome(true, true, true); + assertOldNotConfigFilesInHome(true, true, true); + + ProcessWrapper pw2 = new ProcessWrapper(); + pw2.setArgs(Arrays.asList( + new String[]{ + new File(server.getJavawsFile().getParentFile(), "itweb-settings").getAbsolutePath(), + "set", "baf", "baf" + })); + pw2.setVars(removeXdgVAlues()); + ProcessResult pr2 = pw2.execute(); + Assert.assertTrue(notMoving.toPassingString(), notMoving.evaluate(pr2.stdout)); + Assert.assertTrue(unknownProperty.toPassingString(), unknownProperty.evaluate(pr2.stdout)); + assertConfigFilesInHome(true, true, true); + assertOldNotConfigFilesInHome(true, true, true); + } finally { + ServerAccess.PROCESS_TIMEOUT = t; + } + + } + + @Test + public void runItwCmdWithXdg_oldIcedTeaConfigExisted() throws Exception { + File f = tmpDir(); + long t = ServerAccess.PROCESS_TIMEOUT; + ServerAccess.PROCESS_TIMEOUT = 5000; + try { + assertNotConfigFiles(listToString(getContentOfDirectory(f)), true, true, true); + assertOldNotConfigFilesInHome(true, true, true); + createFakeOldHomeConfig(); + ProcessWrapper pw1 = new ProcessWrapper(); + pw1.setArgs(Arrays.asList( + new String[]{ + new File(server.getJavawsFile().getParentFile(), "itweb-settings").getAbsolutePath(), + "set", "blah", "blah" + })); + pw1.setVars(setXdgVAlues(f)); + ProcessResult pr = pw1.execute(); + Assert.assertTrue(moving.toPassingString(), moving.evaluate(pr.stdout)); + Assert.assertTrue(unknownProperty.toPassingString(), unknownProperty.evaluate(pr.stdout)); + assertConfigFiles(listToString(getContentOfDirectory(f)), true, true, true); + assertOldNotConfigFilesInHome(true, true, true); + ProcessWrapper pw2 = new ProcessWrapper(); + pw2.setArgs(Arrays.asList( + new String[]{ + new File(server.getJavawsFile().getParentFile(), "itweb-settings").getAbsolutePath(), + "set", "baf", "baf" + })); + pw2.setVars(removeXdgVAlues()); + ProcessResult pr2 = pw2.execute(); + Assert.assertTrue(notMoving.toPassingString(), notMoving.evaluate(pr2.stdout)); + Assert.assertTrue(unknownProperty.toPassingString(), unknownProperty.evaluate(pr2.stdout)); + assertConfigFiles(listToString(getContentOfDirectory(f)), true, true, true); + assertOldNotConfigFilesInHome(true, true, true); + } finally { + ServerAccess.PROCESS_TIMEOUT = t; + deleteRecursively(f); + } + } + + private static void fakeExtendedSecurity(File file) throws IOException { + if (!file.exists()) { + boolean a = file.mkdirs(); + Assert.assertTrue("creation of directories for " + file + " failed", a); + } + File f = new File(file, "deployment.properties"); + ServerAccess.saveFile("deployment.security.level = ALLOW_UNSIGNED", f); + } + + /* + *PLUGIN - NO OLD CONFIG + */ + @Test + @TestInBrowsers(testIn = Browsers.one) + public void runAppletInCleanSystemWithNoXdg() throws Exception { + assertNotMainFilesInHome(true, true, true); + assertOldNotMainFilesInHome(true, true, true); + fakeExtendedSecurity(new File(System.getProperty("user.home") + File.separator + ".config" + File.separator + "icedtea-web")); + ProcessWrapper pw = new ProcessWrapper(); + pw.setArgs(Arrays.asList( + new String[]{ + server.getCurrentBrowser().getBin(), + server.getUrl("appletAutoTests2.html").toString() + })); + pw.addStdOutListener(new RulesFolowingClosingListener(applet1Run)); + pw.setVars(removeXdgVAlues()); + ProcessResult pr = pw.execute(); + Assert.assertTrue(applet1Run.toPassingString(), applet1Run.evaluate(pr.stdout)); + Assert.assertTrue(notMoving.toPassingString(), notMoving.evaluate(pr.stdout)); + assertMainFilesInHome(false, false, true); + assertOldNotMainFilesInHome(true, true, true); + } + + @Test + @TestInBrowsers(testIn = Browsers.one) + public void runAppletsInCleanSystemWithXdg() throws Exception { + File f = tmpDir(); + try { + assertNotMainFiles(listToString(getContentOfDirectory(f)), true, true, true); + assertOldNotMainFilesInHome(true, true, true); + fakeExtendedSecurity(new File(f.getAbsolutePath() + File.separator + "customConfig" + File.separator + "icedtea-web")); + ProcessWrapper pw = new ProcessWrapper(); + pw.setArgs(Arrays.asList( + new String[]{ + server.getCurrentBrowser().getBin(), + server.getUrl("appletAutoTests2.html").toString() + })); + pw.addStdOutListener(new RulesFolowingClosingListener(applet1Run)); + pw.setVars(setXdgVAlues(f)); + ProcessResult pr = pw.execute(); + Assert.assertTrue(applet1Run.toPassingString(), applet1Run.evaluate(pr.stdout)); + Assert.assertTrue(notMoving.toPassingString(), notMoving.evaluate(pr.stdout)); + assertMainFiles(listToString(getContentOfDirectory(f)), false, false, true); + assertOldNotMainFilesInHome(true, true, true); + } finally { + deleteRecursively(f); + } + } + /* + *PLUGIN - OLD CONFIG EXISTS + */ + + @Test + @TestInBrowsers(testIn = Browsers.one) + public void runAppletInCleanSystemWithNoXdg_oldIcedTeaConfigExisted() throws Exception { + assertNotMainFilesInHome(true, true, true); + assertOldNotMainFilesInHome(true, true, true); + fakeExtendedSecurity(new File(System.getProperty("user.home") + File.separator + ".icedtea")); + ProcessWrapper pw1 = new ProcessWrapper(); + pw1.setArgs(Arrays.asList( + new String[]{ + server.getCurrentBrowser().getBin(), + server.getUrl("appletAutoTests2.html").toString() + })); + pw1.addStdOutListener(new RulesFolowingClosingListener(applet1Run)); + pw1.setVars(removeXdgVAlues()); + ProcessResult pr1 = pw1.execute(); + Assert.assertTrue(applet1Run.toPassingString(), applet1Run.evaluate(pr1.stdout)); + Assert.assertTrue(moving.toPassingString(), moving.evaluate(pr1.stdout)); + assertMainFilesInHome(false, false, true); + assertOldNotMainFilesInHome(true, true, true); + ProcessWrapper pw = new ProcessWrapper(); + pw.setArgs(Arrays.asList( + new String[]{ + server.getCurrentBrowser().getBin(), + server.getUrl("appletAutoTests2.html").toString() + })); + pw.addStdOutListener(new RulesFolowingClosingListener(applet1Run)); + pw.setVars(removeXdgVAlues()); + ProcessResult pr = pw.execute(); + Assert.assertTrue(applet1Run.toPassingString(), applet1Run.evaluate(pr.stdout)); + Assert.assertTrue(notMoving.toPassingString(), notMoving.evaluate(pr.stdout)); + assertMainFilesInHome(false, false, true); + assertOldNotMainFilesInHome(true, true, true); + } + + @Test + @TestInBrowsers(testIn = Browsers.one) + public void runAppletsInCleanSystemWithXdg_oldIcedTeaConfigExisted() throws Exception { + File f = tmpDir(); + try { + assertNotMainFiles(listToString(getContentOfDirectory(f)), true, true, true); + assertOldNotMainFilesInHome(true, true, true); + fakeExtendedSecurity(new File(System.getProperty("user.home") + File.separator + ".icedtea")); + ProcessWrapper pw1 = new ProcessWrapper(); + pw1.setArgs(Arrays.asList( + new String[]{ + server.getCurrentBrowser().getBin(), + server.getUrl("appletAutoTests2.html").toString() + })); + pw1.addStdOutListener(new RulesFolowingClosingListener(applet1Run)); + pw1.setVars(setXdgVAlues(f)); + ProcessResult pr1 = pw1.execute(); + Assert.assertTrue(applet1Run.toPassingString(), applet1Run.evaluate(pr1.stdout)); + Assert.assertTrue(moving.toPassingString(), moving.evaluate(pr1.stdout)); + assertMainFiles(listToString(getContentOfDirectory(f)), false, false, true); + assertOldNotMainFilesInHome(true, true, true); + ProcessWrapper pw = new ProcessWrapper(); + pw.setArgs(Arrays.asList( + new String[]{ + server.getCurrentBrowser().getBin(), + server.getUrl("appletAutoTests2.html").toString() + })); + pw.addStdOutListener(new RulesFolowingClosingListener(applet1Run)); + pw.setVars(setXdgVAlues(f)); + ProcessResult pr = pw.execute(); + Assert.assertTrue(applet1Run.toPassingString(), applet1Run.evaluate(pr.stdout)); + Assert.assertTrue(notMoving.toPassingString(), notMoving.evaluate(pr.stdout)); + assertMainFiles(listToString(getContentOfDirectory(f)), false, false, true); + assertOldNotMainFilesInHome(true, true, true); + } finally { + deleteRecursively(f); + } + } +} diff -r f18dea419aec tests/test-extensions/net/sourceforge/jnlp/ProcessWrapper.java --- a/tests/test-extensions/net/sourceforge/jnlp/ProcessWrapper.java Fri Jul 12 15:47:04 2013 -0400 +++ b/tests/test-extensions/net/sourceforge/jnlp/ProcessWrapper.java Sat Jul 13 13:19:44 2013 +0200 @@ -64,8 +64,12 @@ public ProcessWrapper() { } - public ProcessWrapper(String toBeExecuted, List otherargs, URL u){ - Assert.assertNotNull(u); + public ProcessWrapper(String toBeExecuted, List otherargs, URL u) { + this(toBeExecuted, otherargs, u.toString()); + } + + public ProcessWrapper(String toBeExecuted, List otherargs, String s) { + Assert.assertNotNull(s); Assert.assertNotNull(toBeExecuted); Assert.assertTrue(toBeExecuted.trim().length() > 1); if (otherargs == null) { @@ -73,7 +77,7 @@ } List urledArgs = new ArrayList(otherargs); urledArgs.add(0, toBeExecuted); - urledArgs.add(u.toString()); + urledArgs.add(s); this.args = urledArgs; this.vars=null; } diff -r f18dea419aec tests/test-extensions/net/sourceforge/jnlp/ServerAccess.java --- a/tests/test-extensions/net/sourceforge/jnlp/ServerAccess.java Fri Jul 12 15:47:04 2013 -0400 +++ b/tests/test-extensions/net/sourceforge/jnlp/ServerAccess.java Sat Jul 13 13:19:44 2013 +0200 @@ -60,6 +60,7 @@ import net.sourceforge.jnlp.browsertesting.Browsers; import net.sourceforge.jnlp.closinglisteners.AutoErrorClosingListener; import net.sourceforge.jnlp.closinglisteners.AutoOkClosingListener; +import net.sourceforge.jnlp.util.FileUtils; import org.junit.Assert; /** @@ -417,23 +418,8 @@ * @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(); - } - + public static String getContentOfStream(InputStream is, String encoding) throws IOException { + return FileUtils.getContentOfStream(is, encoding); } /** @@ -444,8 +430,7 @@ * @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"); - + return FileUtils.getContentOfStream(is); } /** @@ -491,13 +476,10 @@ * @throws IOException */ public static void saveFile(String content, File f) throws IOException { - saveFile(content, f, "utf-8"); + FileUtils.saveFile(content, f); } 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(); + FileUtils.saveFile(content, f, encoding); } /**