changeset 8191:e3a2fde31af1

RT-38956: UserJvmOptionsService.setUserJVMOptions Needs to save preferences to disk Summary: commit file on set, not on JVM shutdown. Contributed-by: cbensen Reviewed-by: shemnon
author shemnon
date Fri, 10 Oct 2014 16:15:00 -0600
parents b35aa0611a35
children 888f8d323f55 3a7f004c4995 e9aacd03cefd 99f401a0dd53
files modules/fxpackager/src/main/java/jdk/packager/services/userjvmoptions/LauncherUserJvmOptions.java modules/fxpackager/src/main/native/library/common/FilePath.cpp modules/fxpackager/src/main/native/library/common/Package.cpp modules/fxpackager/src/main/native/library/common/Package.h modules/fxpackager/src/main/native/library/common/PropertyFile.cpp modules/fxpackager/src/main/native/library/common/main.cpp modules/fxpackager/src/test/java/hello/TestPackager.java
diffstat 7 files changed, 43 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/modules/fxpackager/src/main/java/jdk/packager/services/userjvmoptions/LauncherUserJvmOptions.java	Fri Oct 10 13:54:07 2014 -0600
+++ b/modules/fxpackager/src/main/java/jdk/packager/services/userjvmoptions/LauncherUserJvmOptions.java	Fri Oct 10 16:15:00 2014 -0600
@@ -133,7 +133,7 @@
     }
 
     @Override
-    public synchronized void setUserJVMOptions(Map<String, String> options) {
+    public void setUserJVMOptions(Map<String, String> options) {
         checkAllPermissions();
         synchronized (semaphore) {
             List<String> keys = new LinkedList<>();
@@ -150,7 +150,7 @@
     }
 
     @Override
-    public synchronized Map<String, String> getUserJVMOptionDefaults() {
+    public Map<String, String> getUserJVMOptionDefaults() {
         checkAllPermissions();
         synchronized (semaphore) {
             Map<String, String> results = new TreeMap<>();
--- a/modules/fxpackager/src/main/native/library/common/FilePath.cpp	Fri Oct 10 13:54:07 2014 -0600
+++ b/modules/fxpackager/src/main/native/library/common/FilePath.cpp	Fri Oct 10 16:15:00 2014 -0600
@@ -208,7 +208,7 @@
     std::list<TString> paths;
     TString lpath = Path;
 
-    while (lpath.empty() == false && FileExists(lpath) == false) {
+    while (lpath.empty() == false && DirectoryExists(lpath) == false) {
         paths.push_front(lpath);
         lpath = ExtractFilePath(lpath);
     }
--- a/modules/fxpackager/src/main/native/library/common/Package.cpp	Fri Oct 10 13:54:07 2014 -0600
+++ b/modules/fxpackager/src/main/native/library/common/Package.cpp	Fri Oct 10 16:15:00 2014 -0600
@@ -188,7 +188,9 @@
                 Platform& platform = Platform::GetInstance();
 
                 if (platform.IsMainThread() == true) {
-                    printf("%s\n", arg.c_str()); //TODO remove
+#ifdef DEBUG
+                    printf("%s\n", arg.c_str());
+#endif //DEBUG
                     continue;
                 }
             }
@@ -215,14 +217,6 @@
 }
 
 Package::~Package(void) {
-}
-
-void Package::Shutdown() {
-    if (FJVMUserConfig->IsModified()) {
-        Platform& platform = Platform::GetInstance();
-        FJVMUserConfig->SaveToFile(platform.GetJVMUserArgsConfigFileName());
-    }
-
     delete FJVMUserConfig;
 }
 
@@ -266,6 +260,10 @@
     }
 
     MergeJVMDefaultsWithOverrides();
+    if (FJVMUserConfig->IsModified()) {
+        Platform& platform = Platform::GetInstance();
+        FJVMUserConfig->SaveToFile(platform.GetJVMUserArgsConfigFileName());
+    }
 }
 
 std::map<TString, TValueIndex> Package::GetJVMUserArgs() {
--- a/modules/fxpackager/src/main/native/library/common/Package.h	Fri Oct 10 13:54:07 2014 -0600
+++ b/modules/fxpackager/src/main/native/library/common/Package.h	Fri Oct 10 16:15:00 2014 -0600
@@ -78,10 +78,9 @@
     
     bool FDebugging;
 
-    PropertyFile* FJVMUserConfig;
-
-    std::map<TString, TValueIndex> FDefaultJVMUserArgs;
-    std::map<TString, TValueIndex> FJVMUserArgs;
+    PropertyFile* FJVMUserConfig; // Contains JVM user overrides
+    std::map<TString, TValueIndex> FDefaultJVMUserArgs; // Contains JVM user defaults
+    std::map<TString, TValueIndex> FJVMUserArgs; // Contains a merge of JVM defaults and user overrides
 
 
     Package(void);
@@ -93,8 +92,7 @@
 public:
     static Package& GetInstance();
     ~Package(void);
-    
-    void Shutdown();
+
     void FreeBootFields();
 
     void SetCommandLineArguments(int argc, TCHAR* argv[]);
--- a/modules/fxpackager/src/main/native/library/common/PropertyFile.cpp	Fri Oct 10 13:54:07 2014 -0600
+++ b/modules/fxpackager/src/main/native/library/common/PropertyFile.cpp	Fri Oct 10 16:15:00 2014 -0600
@@ -76,6 +76,7 @@
 void PropertyFile::Assign(std::map<TString, TString> Value) {
     FData.clear();
     FData.insert(Value.begin(), Value.end());
+    SetModified(true);
 }
 
 bool PropertyFile::LoadFromFile(const TString FileName) {
--- a/modules/fxpackager/src/main/native/library/common/main.cpp	Fri Oct 10 13:54:07 2014 -0600
+++ b/modules/fxpackager/src/main/native/library/common/main.cpp	Fri Oct 10 16:15:00 2014 -0600
@@ -117,7 +117,5 @@
     }
     
     void stop_launcher() {
-        Package& package = Package::GetInstance();
-        package.Shutdown();
     }
 }
--- a/modules/fxpackager/src/test/java/hello/TestPackager.java	Fri Oct 10 13:54:07 2014 -0600
+++ b/modules/fxpackager/src/test/java/hello/TestPackager.java	Fri Oct 10 16:15:00 2014 -0600
@@ -36,6 +36,9 @@
 import java.util.Map;
 import javax.swing.*;
 import javax.swing.table.DefaultTableModel;
+import javax.swing.event.TableModelEvent;
+import javax.swing.event.TableModelListener;
+import javax.swing.JOptionPane;
 
 public class TestPackager {
 
@@ -49,10 +52,10 @@
         for (Map.Entry <String, String> entry : userOptions.entrySet()) {
             System.out.println("key:" + entry.getKey() + " value:" + entry.getValue());
         }
-        if (!userOptions.containsKey("-DfirstRunMs")) {
-            userOptions.put("-DfirstRunMs", Long.toString(System.currentTimeMillis()));
+        if (!userOptions.containsKey("-DfirstRunMs=")) {
+            userOptions.put("-DfirstRunMs=", Long.toString(System.currentTimeMillis()));
         }
-        userOptions.put("-DlastRunMs", Long.toString(System.currentTimeMillis()));
+        userOptions.put("-DlastRunMs=", Long.toString(System.currentTimeMillis()));
         ujo.setUserJVMOptions(userOptions);
 
         JFrame frame = new JFrame("Display Parameters");
@@ -83,6 +86,28 @@
         model.addColumn("Key");
         model.addColumn("Effective");
         model.addColumn("Default");
+        model.addTableModelListener(new TableModelListener() {
+          public void tableChanged(TableModelEvent e) {
+             System.out.println(e);
+
+             switch (e.getType()) {
+               case TableModelEvent.UPDATE:
+                 int column = e.getColumn();
+                 int row = e.getFirstRow();
+
+                 if (column == 1) {
+                   String key = model.getValueAt(row, 0).toString();
+                   String value = model.getValueAt(row, column).toString();
+                   JOptionPane.showMessageDialog(null, key + "=" + value + " column=" + String.valueOf(column) + " row=" + String.valueOf(row), "Changed", JOptionPane.INFORMATION_MESSAGE);
+                   UserJvmOptionsService ujo = UserJvmOptionsService.getUserJVMDefaults();
+                   Map<String, String> userOptions = ujo.getUserJVMOptions();
+                   userOptions.put(key, value);
+                   ujo.setUserJVMOptions(userOptions);
+                 }
+                 break;
+             }
+          }
+        });
 
         Map<String, String> defaults = ujo.getUserJVMOptionDefaults();
         for (Map.Entry <String, String> entry : userOptions.entrySet()) {