--- /dev/null 2014-08-27 09:20:29.000000000 -0600 +++ new/modules/fxpackager/src/main/java/com/oracle/tools/packager/utils/PreferencesUserJvmOptions.java 2014-08-27 09:20:29.000000000 -0600 @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code 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 + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package com.oracle.tools.packager.utils; + +import java.util.Map; +import java.util.TreeMap; +import java.util.prefs.BackingStoreException; +import java.util.prefs.Preferences; + +/** + * Access to old preferences based UserJvmOptions + */ +class PreferencesUserJvmOptions implements UserJvmOptions { + + /** + * Get the preferences node according to the system property. + */ + Preferences node = Preferences.userRoot().node(System.getProperty("app.preferences.id")); + + /** + * Get a map of all User JVM Options currently stored in the backing store + * + * @return a mutable map of the options. This map is not "live" but is a snapshot. + */ + @Override + public Map getUserJVMOptions() { + Map result = new TreeMap<>(); + try { + for (String s : node.childrenNames()) { + String o = node.get(s, null); + if (o != null) { + result.put(s, o); + } + } + } catch (BackingStoreException ignore) { + } + + return result; + } + + /** + * Write a map of all User JVM Options to the backing store. + * The options will reflect the map, and if an option is not set + * in the map but set in the backing store it will be removed. + * + * @param options the options to write, all of which will be written. + */ + @Override + public void setUserJVMOptions(Map options) { + try { + node.clear(); + for (Map.Entry entry : options.entrySet()) { + node.put(entry.getKey(), entry.getValue()); + } + node.flush(); + } catch (BackingStoreException ignore) { + } + + } + + /** + * Defaults cannot be divined when using Preferences + * @return nothing + * @throws java.lang.UnsupportedOperationException all the time. + */ + @Override + public Map getUserJVMOptionDefaults() { + throw new UnsupportedOperationException("Preferences backed UserJvmOptions do not enumerate their defaults"); + } +} --- /dev/null 2014-08-27 09:20:30.000000000 -0600 +++ new/modules/fxpackager/src/main/java/com/oracle/tools/packager/utils/UserJvmOptions.java 2014-08-27 09:20:30.000000000 -0600 @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code 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 + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package com.oracle.tools.packager.utils; + +import java.util.Iterator; +import java.util.Map; +import java.util.ServiceLoader; + +/** + * Runtime access to the UserJVMOptions. + * + */ +public interface UserJvmOptions { + + static UserJvmOptions getUserJVMDefaults() { + ServiceLoader loader = ServiceLoader.load(UserJvmOptions.class); + Iterator iter = loader.iterator(); + if (iter.hasNext()) { + return iter.next(); + } else { +// return new LauncherUserJvmOptions(); + return new PreferencesUserJvmOptions(); + } + } + + /** + * The "current" set of UserJVMOptions. + * + * This will take effect on the next application start, and this may not + * reflect the current set of UserJVMOptions used to start this application. + * + * @return A map of the keys and values. Alterations to this map will not + * change the stored UserJVMOptions + */ + Map getUserJVMOptions(); + + /** + * Sets the passed in options as the UserJVMOptions. + * + * If the application has specified default values and those keys are not + * in this map, they will be replaced by the default values. + * + * No validation or error checking is performed on these values. It is + * entirely possible that you may provide a set of UserJVMOptions that + * may prevent the normal startup of your application and may require + * manual intervention to resolve. + * + * @param options The UserJVMOptions to set. + */ + void setUserJVMOptions(Map options); + + /** + * The "default" set of UserJVMOptions. + * + * This returns the default set of keys and values that the application has + * been configured to use. + * + * @return the keys and values of the default UserJVMOptions. + * @throws UnsupportedOperationException if the defaults cannot be calculated. + */ + Map getUserJVMOptionDefaults(); + +}