/hg/icedtea-web: PolicyEditor indicates active file IO and unit ...

aazores at icedtea.classpath.org aazores at icedtea.classpath.org
Tue Jun 3 21:21:21 UTC 2014


changeset d9ff050f08bb in /hg/icedtea-web
details: http://icedtea.classpath.org/hg/icedtea-web?cmd=changeset;node=d9ff050f08bb
author: Andrew Azores <aazores at redhat.com>
date: Tue Jun 03 17:21:11 2014 -0400

	PolicyEditor indicates active file IO and unit tests wait for this to complete

	2014-06-03  Andrew Azores  <aazores at redhat.com>

	    Added indicator method for if PolicyEditor is currently performing file
	    IO. Unit tests wait for IO to complete before testing editor contents.
	    * netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java
	    (performingIO, isPerformingIO): new field and getter to indicate if file
	    IO is currently being performed.
	    (changesMade): made volatile
	    * tests/netx/unit/net/sourceforge/jnlp/security/policyeditor/PolicyEditorTest.java
	    (setNewTempFile): call Thread.sleep while editor.isPerformingIO


diffstat:

 ChangeLog                                                                        |  11 ++
 netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java                |  46 ++++++---
 tests/netx/unit/net/sourceforge/jnlp/security/policyeditor/PolicyEditorTest.java |   4 +
 3 files changed, 46 insertions(+), 15 deletions(-)

diffs (124 lines):

diff -r f02ad0ae6d86 -r d9ff050f08bb ChangeLog
--- a/ChangeLog	Tue Jun 03 17:02:56 2014 -0400
+++ b/ChangeLog	Tue Jun 03 17:21:11 2014 -0400
@@ -1,3 +1,14 @@
+2014-06-03  Andrew Azores  <aazores at redhat.com>
+
+	Added indicator method for if PolicyEditor is currently performing file
+	IO. Unit tests wait for IO to complete before testing editor contents.
+	* netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java
+	(performingIO, isPerformingIO): new field and getter to indicate if file
+	IO is currently being performed.
+	(changesMade): made volatile
+	* tests/netx/unit/net/sourceforge/jnlp/security/policyeditor/PolicyEditorTest.java
+	(setNewTempFile): call Thread.sleep while editor.isPerformingIO
+
 2014-06-03  Andrew Azores  <aazores at redhat.com>
 
 	PolicyEditor persists empty non-default codebase entries
diff -r f02ad0ae6d86 -r d9ff050f08bb netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java
--- a/netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java	Tue Jun 03 17:02:56 2014 -0400
+++ b/netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java	Tue Jun 03 17:21:11 2014 -0400
@@ -157,8 +157,9 @@
             + "  " + CODEBASE_FLAG + "\t\t" + R("PECodebaseFlag") + "\n";
 
     private final PolicyFileModel policyFile = new PolicyFileModel();
-    private boolean changesMade = false;
+    private volatile boolean changesMade = false;
     private boolean closed = false;
+    private volatile boolean performingIO = false;
     private final Map<PolicyEditorPermissions, JCheckBox> checkboxMap = new TreeMap<>();
     private final List<JCheckBoxWithGroup> groupBoxList = new ArrayList<>(Group.values().length);
     private final JScrollPane scrollPane = new JScrollPane();
@@ -1093,6 +1094,13 @@
         policyFile.clearCustomPermissions();
     }
 
+    /**
+     * @return whether this PolicyEditor is currently opening or saving a policy file to disk
+     */
+    public boolean isPerformingIO() {
+        return performingIO;
+    }
+
     private void openAndParsePolicyFile() {
         resetCodebases();
         try {
@@ -1115,13 +1123,16 @@
             @Override
             protected Void doInBackground() throws Exception {
                 try {
-                    SwingUtilities.invokeLater(new Runnable() {
-                        @Override
-                        public void run() {
-                            progressIndicator.setLocationRelativeTo(parentWindow);
-                            progressIndicator.setVisible(true);
-                        }
-                    });
+                    if (parentWindow != null) {
+                        SwingUtilities.invokeLater(new Runnable() {
+                            @Override
+                            public void run() {
+                                progressIndicator.setLocationRelativeTo(parentWindow);
+                                progressIndicator.setVisible(true);
+                            }
+                        });
+                    }
+                    performingIO = true;
                     policyFile.openAndParsePolicyFile();
                 } catch (final FileNotFoundException fnfe) {
                     OutputController.getLogger().log(fnfe);
@@ -1137,6 +1148,7 @@
             @Override
             public void done() {
                 changesMade = false;
+                performingIO = false;
                 for (final String codebase : policyFile.getCodebases()) {
                     final String model;
                     if (codebase.isEmpty()) {
@@ -1177,13 +1189,16 @@
             @Override
             public Void doInBackground() throws Exception {
                 try {
-                    SwingUtilities.invokeLater(new Runnable() {
-                        @Override
-                        public void run() {
-                            progressIndicator.setLocationRelativeTo(parentWindow);
-                            progressIndicator.setVisible(true);
-                        }
-                    });
+                    if (parentWindow != null) {
+                        SwingUtilities.invokeLater(new Runnable() {
+                            @Override
+                            public void run() {
+                                progressIndicator.setLocationRelativeTo(parentWindow);
+                                progressIndicator.setVisible(true);
+                            }
+                        });
+                    }
+                    performingIO = true;
                     policyFile.savePolicyFile();
                 } catch (final IOException e) {
                     OutputController.getLogger().log(e);
@@ -1195,6 +1210,7 @@
             @Override
             public void done() {
                 changesMade = false;
+                performingIO = false;
                 showChangesSavedDialog();
                 progressIndicator.setVisible(false);
                 progressIndicator.dispose();
diff -r f02ad0ae6d86 -r d9ff050f08bb tests/netx/unit/net/sourceforge/jnlp/security/policyeditor/PolicyEditorTest.java
--- a/tests/netx/unit/net/sourceforge/jnlp/security/policyeditor/PolicyEditorTest.java	Tue Jun 03 17:02:56 2014 -0400
+++ b/tests/netx/unit/net/sourceforge/jnlp/security/policyeditor/PolicyEditorTest.java	Tue Jun 03 17:21:11 2014 -0400
@@ -59,6 +59,10 @@
     public void setNewTempfile() throws Exception {
         tempFilePath = File.createTempFile("policyeditor", null).getCanonicalPath();
         editor = new PolicyEditor(tempFilePath);
+        // policy file is loaded async; give it some time before we test its contents
+        while (editor.isPerformingIO()) {
+            Thread.sleep(50);
+        }
     }
 
     @Test


More information about the distro-pkg-dev mailing list