diff -r d49cb1e754b2 core.netigso/test/unit/src/org/netbeans/core/netigso/EnabledAutoloadTest.java --- a/core.netigso/test/unit/src/org/netbeans/core/netigso/EnabledAutoloadTest.java Thu Jun 30 09:12:56 2011 +0200 +++ b/core.netigso/test/unit/src/org/netbeans/core/netigso/EnabledAutoloadTest.java Thu Jun 30 11:04:00 2011 +0200 @@ -54,6 +54,7 @@ import org.netbeans.junit.Log; import org.netbeans.junit.NbModuleSuite; import org.netbeans.junit.NbTestCase; +import org.openide.util.Mutex.ExceptionAction; /** * @@ -86,33 +87,34 @@ } public void testDependOnAutoload() throws Exception { - ModuleManager mgr = Main.getModuleSystem().getManager(); - mgr.mutexPrivileged().enterWriteAccess(); - try { - Module m1; - String mf = "Bundle-SymbolicName: org.require.autoload\n" + - "Bundle-Version: 33.0.3\n" + - "Bundle-ManifestVersion: 2\n" + - "Require-Bundle: org.openide.compat\n\n"; - /* - mf = "OpenIDE-Module: org.require.autoload\n" + - "OpenIDE-Module-Module-Dependencies: org.openide.compat\n\n"; - /**/ - File jj1 = NetigsoHid.changeManifest(getWorkDir(), j1, mf); - m1 = mgr.create(jj1, null, false, false, false); + final ModuleManager mgr = Main.getModuleSystem().getManager(); + mgr.mutex().writeAccess(new ExceptionAction() { + @Override + public Void run() throws Exception { + Module m1; + String mf = "Bundle-SymbolicName: org.require.autoload\n" + + "Bundle-Version: 33.0.3\n" + + "Bundle-ManifestVersion: 2\n" + + "Require-Bundle: org.openide.compat\n\n"; + /* + mf = "OpenIDE-Module: org.require.autoload\n" + + "OpenIDE-Module-Module-Dependencies: org.openide.compat\n\n"; + /**/ + File jj1 = NetigsoHid.changeManifest(getWorkDir(), j1, mf); + m1 = mgr.create(jj1, null, false, false, false); - CharSequence log = Log.enable("org.netbeans.core.modules", Level.WARNING); - mgr.enable(m1); + CharSequence log = Log.enable("org.netbeans.core.modules", Level.WARNING); + mgr.enable(m1); - assertTrue("OSGi module is now enabled", m1.isEnabled()); + assertTrue("OSGi module is now enabled", m1.isEnabled()); - Class wl = m1.getClassLoader().loadClass("org.openide.util.WeakListener"); - assertNotNull("Weak listener found", wl); + Class wl = m1.getClassLoader().loadClass("org.openide.util.WeakListener"); + assertNotNull("Weak listener found", wl); - Module compat = mgr.get("org.openide.compat"); - assertTrue("Compat module is turned on too", compat.isEnabled()); - } finally { - mgr.mutexPrivileged().exitWriteAccess(); - } + Module compat = mgr.get("org.openide.compat"); + assertTrue("Compat module is turned on too", compat.isEnabled()); + return null; + } + }); } } diff -r d49cb1e754b2 core.netigso/test/unit/src/org/netbeans/core/netigso/IntegrationTest.java --- a/core.netigso/test/unit/src/org/netbeans/core/netigso/IntegrationTest.java Thu Jun 30 09:12:56 2011 +0200 +++ b/core.netigso/test/unit/src/org/netbeans/core/netigso/IntegrationTest.java Thu Jun 30 11:04:00 2011 +0200 @@ -58,6 +58,7 @@ import org.netbeans.junit.NbModuleSuite; import org.netbeans.junit.NbTestCase; import org.openide.util.Lookup; +import org.openide.util.Mutex.ExceptionAction; import org.osgi.framework.launch.Framework; /** @@ -100,22 +101,26 @@ public void testCheckWhichContainerIsRunning() throws Exception { - ModuleManager mgr = Main.getModuleSystem().getManager(); - mgr.mutexPrivileged().enterWriteAccess(); - Module m1; - String mf = "Bundle-SymbolicName: org.foo\n" + - "Bundle-Version: 1.1.0\n" + - "Bundle-ManifestVersion: 2\n" + - "Export-Package: org.foo"; + final ModuleManager mgr = Main.getModuleSystem().getManager(); + mgr.mutex().writeAccess(new ExceptionAction() { + @Override + public Void run() throws Exception { + Module m1; + String mf = "Bundle-SymbolicName: org.foo\n" + + "Bundle-Version: 1.1.0\n" + + "Bundle-ManifestVersion: 2\n" + + "Export-Package: org.foo"; - LOG.info("about to enable module org.foo"); - File jj1 = NetigsoHid.changeManifest(getWorkDir(), j1, mf); - m1 = mgr.create(jj1, null, false, false, false); - mgr.enable(m1); - LOG.info("Enabling is over"); + LOG.info("about to enable module org.foo"); + File jj1 = NetigsoHid.changeManifest(getWorkDir(), j1, mf); + m1 = mgr.create(jj1, null, false, false, false); + mgr.enable(m1); + LOG.info("Enabling is over"); - assertTrue("OSGi module is now enabled", m1.isEnabled()); - mgr.mutexPrivileged().exitWriteAccess(); + assertTrue("OSGi module is now enabled", m1.isEnabled()); + return null; + } + }); Object obj = Lookup.getDefault().lookup(NetigsoFramework.class); LOG.log(Level.INFO, "NetigsoFramework: {0}", obj); diff -r d49cb1e754b2 core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoActivationCanAccessLayersTest.java --- a/core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoActivationCanAccessLayersTest.java Thu Jun 30 09:12:56 2011 +0200 +++ b/core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoActivationCanAccessLayersTest.java Thu Jun 30 11:04:00 2011 +0200 @@ -51,6 +51,7 @@ import org.netbeans.Module; import org.netbeans.ModuleManager; import org.netbeans.SetupHid; +import org.openide.util.Mutex.ExceptionAction; /** * Can the BundleActivators access layer entries defined by other (NetBeans) modules? @@ -81,21 +82,22 @@ public void testActivation() throws Exception { ModuleSystem ms = Main.getModuleSystem(); mgr = ms.getManager(); - mgr.mutexPrivileged().enterWriteAccess(); - try { - File simpleModule = new File(jars, "activate.jar"); - m1 = mgr.create(simpleModule, null, false, false, false); - System.setProperty("activate.layer.test", "can-this-file-be-found.txt"); - mgr.enable(m1); + mgr.mutex().writeAccess(new ExceptionAction() { + @Override + public Void run() throws Exception { + File simpleModule = new File(jars, "activate.jar"); + m1 = mgr.create(simpleModule, null, false, false, false); + System.setProperty("activate.layer.test", "can-this-file-be-found.txt"); + mgr.enable(m1); - Class main = m1.getClassLoader().loadClass("org.activate.Main"); - Object s = main.getField("start").get(null); - assertNotNull("Bundle started, its context provided", s); + Class main = m1.getClassLoader().loadClass("org.activate.Main"); + Object s = main.getField("start").get(null); + assertNotNull("Bundle started, its context provided", s); - mgr.disable(m1); - } finally { - mgr.mutexPrivileged().exitWriteAccess(); - } + mgr.disable(m1); + return null; + } + }); } private File createTestJAR(String name, String srcdir, File... classpath) throws IOException { return createTestJAR(data, jars, name, srcdir, classpath); diff -r d49cb1e754b2 core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoActivationOnExitTest.java --- a/core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoActivationOnExitTest.java Thu Jun 30 09:12:56 2011 +0200 +++ b/core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoActivationOnExitTest.java Thu Jun 30 11:04:00 2011 +0200 @@ -51,6 +51,7 @@ import org.netbeans.Module; import org.netbeans.ModuleManager; import org.netbeans.SetupHid; +import org.openide.util.Mutex.ExceptionAction; /** * Do we correctly call the BundleActivators? @@ -82,23 +83,24 @@ public void testDeactivationOnExit() throws Exception { ModuleSystem ms = Main.getModuleSystem(); mgr = ms.getManager(); - mgr.mutexPrivileged().enterWriteAccess(); - try { - File simpleModule = new File(jars, "activate.jar"); - m1 = mgr.create(simpleModule, null, false, false, false); - mgr.enable(m1); + mgr.mutex().writeAccess(new ExceptionAction() { + @Override + public Void run() throws Exception { + File simpleModule = new File(jars, "activate.jar"); + m1 = mgr.create(simpleModule, null, false, false, false); + mgr.enable(m1); - Class main = m1.getClassLoader().loadClass("org.activate.Main"); - Object s = main.getField("start").get(null); - assertNotNull("Bundle started, its context provided", s); + Class main = m1.getClassLoader().loadClass("org.activate.Main"); + Object s = main.getField("start").get(null); + assertNotNull("Bundle started, its context provided", s); - assertTrue("Shutdown OK", mgr.shutDown()); + assertTrue("Shutdown OK", mgr.shutDown()); - Object e = main.getField("stop").get(null); - assertNotNull("Bundle stopped, its context provided", e); - } finally { - mgr.mutexPrivileged().exitWriteAccess(); - } + Object e = main.getField("stop").get(null); + assertNotNull("Bundle stopped, its context provided", e); + return null; + } + }); } private File createTestJAR(String name, String srcdir, File... classpath) throws IOException { return createTestJAR(data, jars, name, srcdir, classpath); diff -r d49cb1e754b2 core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoActivationTest.java --- a/core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoActivationTest.java Thu Jun 30 09:12:56 2011 +0200 +++ b/core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoActivationTest.java Thu Jun 30 11:04:00 2011 +0200 @@ -51,6 +51,7 @@ import org.netbeans.Module; import org.netbeans.ModuleManager; import org.netbeans.SetupHid; +import org.openide.util.Mutex.ExceptionAction; /** * Do we correctly call the BundleActivators? @@ -82,23 +83,24 @@ public void testActivation() throws Exception { ModuleSystem ms = Main.getModuleSystem(); mgr = ms.getManager(); - mgr.mutexPrivileged().enterWriteAccess(); - try { - File simpleModule = new File(jars, "activate.jar"); - m1 = mgr.create(simpleModule, null, false, false, false); - mgr.enable(m1); + mgr.mutex().writeAccess(new ExceptionAction() { + @Override + public Void run() throws Exception { + File simpleModule = new File(jars, "activate.jar"); + m1 = mgr.create(simpleModule, null, false, false, false); + mgr.enable(m1); - Class main = m1.getClassLoader().loadClass("org.activate.Main"); - Object s = main.getField("start").get(null); - assertNotNull("Bundle started, its context provided", s); + Class main = m1.getClassLoader().loadClass("org.activate.Main"); + Object s = main.getField("start").get(null); + assertNotNull("Bundle started, its context provided", s); - mgr.disable(m1); + mgr.disable(m1); - Object e = main.getField("stop").get(null); - assertNotNull("Bundle stopped, its context provided", e); - } finally { - mgr.mutexPrivileged().exitWriteAccess(); - } + Object e = main.getField("stop").get(null); + assertNotNull("Bundle stopped, its context provided", e); + return null; + } + }); } private File createTestJAR(String name, String srcdir, File... classpath) throws IOException { return createTestJAR(data, jars, name, srcdir, classpath); diff -r d49cb1e754b2 core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoLayerTest.java --- a/core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoLayerTest.java Thu Jun 30 09:12:56 2011 +0200 +++ b/core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoLayerTest.java Thu Jun 30 11:04:00 2011 +0200 @@ -63,6 +63,7 @@ import org.netbeans.SetupHid; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; +import org.openide.util.Mutex.ExceptionAction; /** * How does OSGi integration deals with layer registration? @@ -97,14 +98,15 @@ ModuleSystem ms = Main.getModuleSystem(); mgr = ms.getManager(); - mgr.mutexPrivileged().enterWriteAccess(); - try { - File j1 = new File(jars, "simple-module.jar"); - m1 = mgr.create(j1, null, false, false, false); - mgr.enable(Collections.singleton(m1)); - } finally { - mgr.mutexPrivileged().exitWriteAccess(); - } + mgr.mutex().writeAccess(new ExceptionAction() { + @Override + public Void run() throws Exception { + File j1 = new File(jars, "simple-module.jar"); + m1 = mgr.create(j1, null, false, false, false); + mgr.enable(Collections.singleton(m1)); + return null; + } + }); } } @@ -112,23 +114,23 @@ return createTestJAR(data, jars, name, srcdir, classpath); } public void testOSGiCanProvideLayer() throws Exception { - mgr.mutexPrivileged().enterWriteAccess(); - FileObject fo; - try { - String mfBar = "Bundle-SymbolicName: org.bar\n" + - "Bundle-Version: 1.1.0\n" + - "Bundle-ManifestVersion: 2\n" + - "Import-Package: org.foo\n" + - "OpenIDE-Module-Layer: org/bar/layer.xml\n" + - "\n\n"; + mgr.mutex().writeAccess(new ExceptionAction() { + @Override + public Void run() throws Exception { + String mfBar = "Bundle-SymbolicName: org.bar\n" + + "Bundle-Version: 1.1.0\n" + + "Bundle-ManifestVersion: 2\n" + + "Import-Package: org.foo\n" + + "OpenIDE-Module-Layer: org/bar/layer.xml\n" + + "\n\n"; - File j2 = changeManifest(new File(jars, "depends-on-simple-module.jar"), mfBar); - Module m2 = mgr.create(j2, null, false, false, false); - mgr.enable(m2); - } finally { - mgr.mutexPrivileged().exitWriteAccess(); - } - fo = FileUtil.getConfigFile("TestFolder"); + File j2 = changeManifest(new File(jars, "depends-on-simple-module.jar"), mfBar); + Module m2 = mgr.create(j2, null, false, false, false); + mgr.enable(m2); + return null; + } + }); + FileObject fo = FileUtil.getConfigFile("TestFolder"); assertNotNull("Folder found", fo); URL u = mgr.getClassLoader().getResource("org/bar/layer.xml"); diff -r d49cb1e754b2 core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoMetaInfServicesTest.java --- a/core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoMetaInfServicesTest.java Thu Jun 30 09:12:56 2011 +0200 +++ b/core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoMetaInfServicesTest.java Thu Jun 30 11:04:00 2011 +0200 @@ -53,6 +53,7 @@ import org.netbeans.ModuleManager; import org.netbeans.SetupHid; import org.openide.util.Lookup; +import org.openide.util.Mutex.ExceptionAction; /** * Do we correctly handle META-INF/services in bundles? @@ -84,28 +85,29 @@ public void testActivation() throws Exception { ModuleSystem ms = Main.getModuleSystem(); mgr = ms.getManager(); - mgr.mutexPrivileged().enterWriteAccess(); - try { - Callable fr = Lookup.getDefault().lookup(Callable.class); - assertNull("No registration found yet", fr); + mgr.mutex().writeAccess(new ExceptionAction() { + @Override + public Void run() throws Exception { + Callable fr = Lookup.getDefault().lookup(Callable.class); + assertNull("No registration found yet", fr); - - File simpleModule = new File(jars, "activate.jar"); - m1 = mgr.create(simpleModule, null, false, false, false); - mgr.enable(m1); - Callable registration = Lookup.getDefault().lookup(Callable.class); - assertNotNull("Registration of Callable found", registration); - Object s = registration.call(); - assertNotNull("Bundle started, its context provided", s); + File simpleModule = new File(jars, "activate.jar"); + m1 = mgr.create(simpleModule, null, false, false, false); + mgr.enable(m1); - mgr.disable(m1); - - Callable nr = Lookup.getDefault().lookup(Callable.class); - assertNull("No registration found anymore", nr); - } finally { - mgr.mutexPrivileged().exitWriteAccess(); - } + Callable registration = Lookup.getDefault().lookup(Callable.class); + assertNotNull("Registration of Callable found", registration); + Object s = registration.call(); + assertNotNull("Bundle started, its context provided", s); + + mgr.disable(m1); + + Callable nr = Lookup.getDefault().lookup(Callable.class); + assertNull("No registration found anymore", nr); + return null; + } + }); } private File createTestJAR(String name, String srcdir, File... classpath) throws IOException { return createTestJAR(data, jars, name, srcdir, classpath); diff -r d49cb1e754b2 core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoOSGiActivationVisibleTest.java --- a/core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoOSGiActivationVisibleTest.java Thu Jun 30 09:12:56 2011 +0200 +++ b/core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoOSGiActivationVisibleTest.java Thu Jun 30 11:04:00 2011 +0200 @@ -56,6 +56,7 @@ import org.netbeans.ModuleManager; import org.netbeans.SetupHid; import org.netbeans.Util; +import org.openide.util.Mutex.ExceptionAction; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; @@ -72,9 +73,10 @@ private static File simpleBundle; private static File activate; private static Bundle toEnable; - private static Class directBundle; - private static Class someModule; + private static Class directBundle; + private static Class someModule; private static Method loadClass; + BundleContext bc; public NetigsoOSGiActivationVisibleTest(String name) { super(name); @@ -107,21 +109,21 @@ ModuleSystem ms = Main.getModuleSystem(); mgr = ms.getManager(); - mgr.mutexPrivileged().enterWriteAccess(); - BundleContext bc; - try { - m1 = mgr.create(activate, null, false, false, false); - m2 = mgr.create(simpleBundle, null, false, autoload(), false); - - mgr.enable(m1); + mgr.mutex().writeAccess(new ExceptionAction() { + @Override + public Void run() throws Exception { + m1 = mgr.create(activate, null, false, false, false); + m2 = mgr.create(simpleBundle, null, false, autoload(), false); - Class main = m1.getClassLoader().loadClass("org.activate.Main"); - Object s = main.getField("start").get(null); - assertNotNull("Bundle started, its context provided", s); - bc = (BundleContext) s; - } finally { - mgr.mutexPrivileged().exitWriteAccess(); - } + mgr.enable(m1); + + Class main = m1.getClassLoader().loadClass("org.activate.Main"); + Object s = main.getField("start").get(null); + assertNotNull("Bundle started, its context provided", s); + bc = (BundleContext) s; + return null; + } + }); toEnable = null; for (Bundle b : bc.getBundles()) { if (b.getSymbolicName().equals("org.snd.module")) { diff -r d49cb1e754b2 core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoOSGiCanDependTest.java --- a/core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoOSGiCanDependTest.java Thu Jun 30 09:12:56 2011 +0200 +++ b/core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoOSGiCanDependTest.java Thu Jun 30 11:04:00 2011 +0200 @@ -49,6 +49,7 @@ import org.netbeans.MockModuleInstaller; import org.netbeans.Module; import org.netbeans.ModuleManager; +import org.openide.util.Mutex.ExceptionAction; /** * @@ -62,35 +63,39 @@ public void testOSGiCanDependOnNetBeans() throws Exception { MockModuleInstaller installer = new MockModuleInstaller(); MockEvents ev = new MockEvents(); - ModuleManager mgr = new ModuleManager(installer, ev); - mgr.mutexPrivileged().enterWriteAccess(); - HashSet both = null; - try { - String mfBar = "Bundle-SymbolicName: org.bar\n" + - "Bundle-Version: 1.1.0\n" + - "Bundle-ManifestVersion: 2\n" + - "Export-Package: org.bar\n" + - "Import-Package: org.foo\n" + - "\n\n"; + final ModuleManager mgr = new ModuleManager(installer, ev); + mgr.mutex().writeAccess(new ExceptionAction() { + @Override + public Void run() throws Exception { + HashSet both = null; + try { + String mfBar = "Bundle-SymbolicName: org.bar\n" + + "Bundle-Version: 1.1.0\n" + + "Bundle-ManifestVersion: 2\n" + + "Export-Package: org.bar\n" + + "Import-Package: org.foo\n" + + "\n\n"; - File j1 = new File(jars, "simple-module.jar"); - File j2 = changeManifest(new File(jars, "depends-on-simple-module.jar"), mfBar); - Module m1 = mgr.create(j1, null, false, false, false); - Module m2 = mgr.create(j2, null, false, false, false); - HashSet b = new HashSet(Arrays.asList(m1, m2)); - mgr.enable(b); - both = b; + File j1 = new File(jars, "simple-module.jar"); + File j2 = changeManifest(new File(jars, "depends-on-simple-module.jar"), mfBar); + Module m1 = mgr.create(j1, null, false, false, false); + Module m2 = mgr.create(j2, null, false, false, false); + HashSet b = new HashSet(Arrays.asList(m1, m2)); + mgr.enable(b); + both = b; - Class clazz = m2.getClassLoader().loadClass("org.bar.SomethingElse"); - Class sprclass = m2.getClassLoader().loadClass("org.foo.Something"); + Class clazz = m2.getClassLoader().loadClass("org.bar.SomethingElse"); + Class sprclass = m2.getClassLoader().loadClass("org.foo.Something"); - assertEquals("Correct parent is used", sprclass, clazz.getSuperclass()); - } finally { - if (both != null) { - mgr.disable(both); + assertEquals("Correct parent is used", sprclass, clazz.getSuperclass()); + } finally { + if (both != null) { + mgr.disable(both); + } + } + return null; } - mgr.mutexPrivileged().exitWriteAccess(); - } + }); } } diff -r d49cb1e754b2 core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoOSGiCanRequestNoMajorTest.java --- a/core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoOSGiCanRequestNoMajorTest.java Thu Jun 30 09:12:56 2011 +0200 +++ b/core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoOSGiCanRequestNoMajorTest.java Thu Jun 30 11:04:00 2011 +0200 @@ -62,40 +62,44 @@ public void testOSGiCanRequireBundleOnNetBeans() throws Exception { MockModuleInstaller installer = new MockModuleInstaller(); MockEvents ev = new MockEvents(); - ModuleManager mgr = new ModuleManager(installer, ev); - mgr.mutexPrivileged().enterWriteAccess(); - HashSet both = null; - try { - String mfModule = "Manifest-Version: 1.0\n" + - "OpenIDE-Module: org.foo\n" + - "OpenIDE-Module-Name: Foo test module\n" + - "OpenIDE-Module-Specification-Version: 1.2\n\n\n"; + final ModuleManager mgr = new ModuleManager(installer, ev); + mgr.mutex().writeAccess(new org.openide.util.Mutex.ExceptionAction() { + @Override + public Void run() throws Exception { + HashSet both = null; + try { + String mfModule = "Manifest-Version: 1.0\n" + + "OpenIDE-Module: org.foo\n" + + "OpenIDE-Module-Name: Foo test module\n" + + "OpenIDE-Module-Specification-Version: 1.2\n\n\n"; - String mfBar = "Bundle-SymbolicName: org.bar\n" + - "Bundle-Version: 1.1.0\n" + - "Bundle-ManifestVersion: 2\n" + - "Export-Package: org.bar\n" + - "Require-Bundle: org.foo;bundle-version=\"[1.0,2.0)\"\n" + - "\n\n"; + String mfBar = "Bundle-SymbolicName: org.bar\n" + + "Bundle-Version: 1.1.0\n" + + "Bundle-ManifestVersion: 2\n" + + "Export-Package: org.bar\n" + + "Require-Bundle: org.foo;bundle-version=\"[1.0,2.0)\"\n" + + "\n\n"; - File j1 = changeManifest(new File(jars, "simple-module.jar"), mfModule); - File j2 = changeManifest(new File(jars, "depends-on-simple-module.jar"), mfBar); - Module m1 = mgr.create(j1, null, false, false, false); - Module m2 = mgr.create(j2, null, false, false, false); - HashSet b = new HashSet(Arrays.asList(m1, m2)); - mgr.enable(b); - both = b; + File j1 = changeManifest(new File(jars, "simple-module.jar"), mfModule); + File j2 = changeManifest(new File(jars, "depends-on-simple-module.jar"), mfBar); + Module m1 = mgr.create(j1, null, false, false, false); + Module m2 = mgr.create(j2, null, false, false, false); + HashSet b = new HashSet(Arrays.asList(m1, m2)); + mgr.enable(b); + both = b; - Class sprclass = m1.getClassLoader().loadClass("org.foo.Something"); - Class clazz = m2.getClassLoader().loadClass("org.bar.SomethingElse"); + Class sprclass = m1.getClassLoader().loadClass("org.foo.Something"); + Class clazz = m2.getClassLoader().loadClass("org.bar.SomethingElse"); - assertEquals("Correct parent is used", sprclass, clazz.getSuperclass()); - } finally { - if (both != null) { - mgr.disable(both); + assertEquals("Correct parent is used", sprclass, clazz.getSuperclass()); + } finally { + if (both != null) { + mgr.disable(both); + } + } + return null; } - mgr.mutexPrivileged().exitWriteAccess(); - } + }); } } diff -r d49cb1e754b2 core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoOSGiCanRequestTest.java --- a/core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoOSGiCanRequestTest.java Thu Jun 30 09:12:56 2011 +0200 +++ b/core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoOSGiCanRequestTest.java Thu Jun 30 11:04:00 2011 +0200 @@ -63,35 +63,40 @@ public void testOSGiCanRequireBundleOnNetBeans() throws Exception { MockModuleInstaller installer = new MockModuleInstaller(); MockEvents ev = new MockEvents(); - ModuleManager mgr = new ModuleManager(installer, ev); - mgr.mutexPrivileged().enterWriteAccess(); - HashSet both = null; - try { - String mfBar = "Bundle-SymbolicName: org.bar\n" + - "Bundle-Version: 1.1.0\n" + - "Bundle-ManifestVersion: 2\n" + - "Export-Package: org.bar\n" + - "Require-Bundle: org.foo;bundle-version=\"[100.0,102.0)\"\n" + - "\n\n"; + final ModuleManager mgr = new ModuleManager(installer, ev); + mgr.mutex().writeAccess(new org.openide.util.Mutex.ExceptionAction() { - File j1 = new File(jars, "simple-module.jar"); - File j2 = changeManifest(new File(jars, "depends-on-simple-module.jar"), mfBar); - Module m1 = mgr.create(j1, null, false, false, false); - Module m2 = mgr.create(j2, null, false, false, false); - HashSet b = new HashSet(Arrays.asList(m1, m2)); - mgr.enable(b); - both = b; + @Override + public Void run() throws Exception { + HashSet both = null; + try { + String mfBar = "Bundle-SymbolicName: org.bar\n" + + "Bundle-Version: 1.1.0\n" + + "Bundle-ManifestVersion: 2\n" + + "Export-Package: org.bar\n" + + "Require-Bundle: org.foo;bundle-version=\"[100.0,102.0)\"\n" + + "\n\n"; - Class sprclass = m1.getClassLoader().loadClass("org.foo.Something"); - Class clazz = m2.getClassLoader().loadClass("org.bar.SomethingElse"); + File j1 = new File(jars, "simple-module.jar"); + File j2 = changeManifest(new File(jars, "depends-on-simple-module.jar"), mfBar); + Module m1 = mgr.create(j1, null, false, false, false); + Module m2 = mgr.create(j2, null, false, false, false); + HashSet b = new HashSet(Arrays.asList(m1, m2)); + mgr.enable(b); + both = b; - assertEquals("Correct parent is used", sprclass, clazz.getSuperclass()); - } finally { - if (both != null) { - mgr.disable(both); + Class sprclass = m1.getClassLoader().loadClass("org.foo.Something"); + Class clazz = m2.getClassLoader().loadClass("org.bar.SomethingElse"); + + assertEquals("Correct parent is used", sprclass, clazz.getSuperclass()); + } finally { + if (both != null) { + mgr.disable(both); + } + } + return null; } - mgr.mutexPrivileged().exitWriteAccess(); - } + }); } } diff -r d49cb1e754b2 core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoOSGiFragmentTest.java --- a/core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoOSGiFragmentTest.java Thu Jun 30 09:12:56 2011 +0200 +++ b/core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoOSGiFragmentTest.java Thu Jun 30 11:04:00 2011 +0200 @@ -63,47 +63,52 @@ public void testOSGiFragmentDependency() throws Exception { MockModuleInstaller installer = new MockModuleInstaller(); MockEvents ev = new MockEvents(); - ModuleManager mgr = new ModuleManager(installer, ev); - mgr.mutexPrivileged().enterWriteAccess(); - HashSet toCleanUp = null; - try { - String mfFoo = "" - + "Bundle-SymbolicName: org.foo\n" + - "Bundle-Version: 1.1.0\n" + - "Bundle-ManifestVersion: 2\n" + - "Export-Package: org.foo,org.bar\n" + - "\n\n"; - - String mfBar = "Fragment-Host: org.foo\n" - + "Bundle-SymbolicName: org.bar\n" + - "Bundle-Version: 1.1.0\n" + - "Bundle-ManifestVersion: 2\n" + - "\n\n"; + final ModuleManager mgr = new ModuleManager(installer, ev); + mgr.mutex().writeAccess(new org.openide.util.Mutex.ExceptionAction() { - String mfDependency = "OpenIDE-Module: org.test\n" - + "OpenIDE-Module-Module-Dependencies: org.bar, org.foo\n" + - "\n\n"; + @Override + public Void run() throws Exception { + HashSet toCleanUp = null; + try { + String mfFoo = "" + + "Bundle-SymbolicName: org.foo\n" + + "Bundle-Version: 1.1.0\n" + + "Bundle-ManifestVersion: 2\n" + + "Export-Package: org.foo,org.bar\n" + + "\n\n"; - File j1 = changeManifest(new File(jars, "simple-module.jar"), mfFoo); - File j2 = changeManifest(new File(jars, "depends-on-simple-module.jar"), mfBar); - File j3 = changeManifest(new File(jars, "depends-on-simple-module.jar"), mfDependency); - Module m1 = mgr.create(j1, null, false, true, false); - Module m2 = mgr.create(j2, null, false, true, false); - Module m3 = mgr.create(j3, null, false, false, false); - HashSet b = new HashSet(Arrays.asList(m3)); - mgr.enable(m3); - toCleanUp = b; + String mfBar = "Fragment-Host: org.foo\n" + + "Bundle-SymbolicName: org.bar\n" + + "Bundle-Version: 1.1.0\n" + + "Bundle-ManifestVersion: 2\n" + + "\n\n"; - Class sprclass = m3.getClassLoader().loadClass("org.foo.Something"); - Class clazz = m3.getClassLoader().loadClass("org.bar.SomethingElse"); + String mfDependency = "OpenIDE-Module: org.test\n" + + "OpenIDE-Module-Module-Dependencies: org.bar, org.foo\n" + + "\n\n"; - assertEquals("Correct parent is used", sprclass, clazz.getSuperclass()); - } finally { - if (toCleanUp != null) { - mgr.disable(toCleanUp); + File j1 = changeManifest(new File(jars, "simple-module.jar"), mfFoo); + File j2 = changeManifest(new File(jars, "depends-on-simple-module.jar"), mfBar); + File j3 = changeManifest(new File(jars, "depends-on-simple-module.jar"), mfDependency); + Module m1 = mgr.create(j1, null, false, true, false); + Module m2 = mgr.create(j2, null, false, true, false); + Module m3 = mgr.create(j3, null, false, false, false); + HashSet b = new HashSet(Arrays.asList(m3)); + mgr.enable(m3); + toCleanUp = b; + + Class sprclass = m3.getClassLoader().loadClass("org.foo.Something"); + Class clazz = m3.getClassLoader().loadClass("org.bar.SomethingElse"); + + assertEquals("Correct parent is used", sprclass, clazz.getSuperclass()); + } finally { + if (toCleanUp != null) { + mgr.disable(toCleanUp); + } + } + return null; } - mgr.mutexPrivileged().exitWriteAccess(); - } + }); } } diff -r d49cb1e754b2 core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoReloadTest.java --- a/core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoReloadTest.java Thu Jun 30 09:12:56 2011 +0200 +++ b/core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoReloadTest.java Thu Jun 30 11:04:00 2011 +0200 @@ -81,31 +81,33 @@ public void testCanReloadAModule() throws Exception { ModuleSystem ms = Main.getModuleSystem(); mgr = ms.getManager(); - mgr.mutexPrivileged().enterWriteAccess(); - try { - m1 = mgr.create(withoutA, null, false, false, false); - mgr.enable(m1); + mgr.mutex().writeAccess(new org.openide.util.Mutex.ExceptionAction() { - } finally { - mgr.mutexPrivileged().exitWriteAccess(); - } + @Override + public Void run() throws Exception { + m1 = mgr.create(withoutA, null, false, false, false); + mgr.enable(m1); + return null; + } + }); assertTrue("Delete is OK", withoutA.delete()); assertTrue("Rename is OK", withActivator.renameTo(withoutA)); TestModuleDeployer.deployTestModule(withoutA); - Class main = m1.getClassLoader().loadClass("org.activate.Main"); + final Class main = m1.getClassLoader().loadClass("org.activate.Main"); Object s = main.getField("start").get(null); assertNotNull("Bundle started, its context provided", s); - mgr.mutexPrivileged().enterWriteAccess(); - try { - mgr.disable(m1); - Object e = main.getField("stop").get(null); - assertNotNull("Bundle stopped, its context provided", e); - } finally { - mgr.mutexPrivileged().exitWriteAccess(); - } + mgr.mutex().writeAccess(new org.openide.util.Mutex.ExceptionAction() { + @Override + public Void run() throws Exception { + mgr.disable(m1); + Object e = main.getField("stop").get(null); + assertNotNull("Bundle stopped, its context provided", e); + return null; + } + }); } private File createTestJAR(String name, String srcdir, File... classpath) throws IOException { return createTestJAR(data, jars, name, srcdir, classpath); diff -r d49cb1e754b2 core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoServicesTest.java --- a/core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoServicesTest.java Thu Jun 30 09:12:56 2011 +0200 +++ b/core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoServicesTest.java Thu Jun 30 11:04:00 2011 +0200 @@ -105,14 +105,16 @@ ModuleSystem ms = Main.getModuleSystem(); mgr = ms.getManager(); - mgr.mutexPrivileged().enterWriteAccess(); - try { - File j1 = new File(jars, "simple-module.jar"); - m1 = mgr.create(j1, null, false, false, false); - mgr.enable(Collections.singleton(m1)); - } finally { - mgr.mutexPrivileged().exitWriteAccess(); - } + mgr.mutex().writeAccess(new org.openide.util.Mutex.ExceptionAction() { + + @Override + public Void run() throws Exception { + File j1 = new File(jars, "simple-module.jar"); + m1 = mgr.create(j1, null, false, false, false); + mgr.enable(Collections.singleton(m1)); + return null; + } + }); } } @@ -120,21 +122,21 @@ return createTestJAR(data, jars, name, srcdir, classpath); } public void testOSGiServicesVisibleInLookup() throws Exception { - mgr.mutexPrivileged().enterWriteAccess(); - FileObject fo; - try { - String mfBar = "Bundle-SymbolicName: org.bar\n" + - "Bundle-Version: 1.1.0\n" + - "Bundle-ManifestVersion: 2\n" + - "Import-Package: org.foo\n" + - "\n\n"; + mgr.mutex().writeAccess(new org.openide.util.Mutex.ExceptionAction() { + @Override + public Void run() throws Exception { + String mfBar = "Bundle-SymbolicName: org.bar\n" + + "Bundle-Version: 1.1.0\n" + + "Bundle-ManifestVersion: 2\n" + + "Import-Package: org.foo\n" + + "\n\n"; - File j2 = changeManifest(new File(jars, "depends-on-simple-module.jar"), mfBar); - Module m2 = mgr.create(j2, null, false, false, false); - mgr.enable(m2); - } finally { - mgr.mutexPrivileged().exitWriteAccess(); - } + File j2 = changeManifest(new File(jars, "depends-on-simple-module.jar"), mfBar); + Module m2 = mgr.create(j2, null, false, false, false); + mgr.enable(m2); + return null; + } + }); Bundle b = findBundle("org.bar"); assertNotNull("Bundle really found", b); diff -r d49cb1e754b2 core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoTest.java --- a/core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoTest.java Thu Jun 30 09:12:56 2011 +0200 +++ b/core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoTest.java Thu Jun 30 11:04:00 2011 +0200 @@ -67,173 +67,194 @@ public void testFactoryCreatesOurModules() throws Exception { MockModuleInstaller installer = new MockModuleInstaller(); MockEvents ev = new MockEvents(); - ModuleManager mgr = new ModuleManager(installer, ev); - mgr.mutexPrivileged().enterWriteAccess(); - Module m2; - Module m1; - HashSet both = null; - try { - String mf = "Bundle-SymbolicName: org.foo;singleton:=true\n" + - "Bundle-Version: 1.1.0\n" + - "Bundle-ManifestVersion: 2\n" + - "Export-Package: org.foo"; - String mfBar = - "OpenIDE-Module: org.bar/1\n" + - "OpenIDE-Module-Name: Depends on bar test module\n" + - "OpenIDE-Module-Module-Dependencies: org.foo\n" + - "some"; + final ModuleManager mgr = new ModuleManager(installer, ev); + mgr.mutex().writeAccess(new org.openide.util.Mutex.ExceptionAction() { + @Override + public Void run() throws Exception { + Module m2; + Module m1; + HashSet both = null; + try { + String mf = "Bundle-SymbolicName: org.foo;singleton:=true\n" + + "Bundle-Version: 1.1.0\n" + + "Bundle-ManifestVersion: 2\n" + + "Export-Package: org.foo"; + String mfBar = + "OpenIDE-Module: org.bar/1\n" + + "OpenIDE-Module-Name: Depends on bar test module\n" + + "OpenIDE-Module-Module-Dependencies: org.foo\n" + + "some"; - File j1 = changeManifest(new File(jars, "simple-module.jar"), mf); - File j2 = changeManifest(new File(jars, "depends-on-simple-module.jar"), mfBar); - m1 = mgr.create(j1, null, false, false, false); - m2 = mgr.create(j2, null, false, false, false); - HashSet b = new HashSet(Arrays.asList(m1, m2)); - mgr.enable(b); - both = b; + File j1 = changeManifest(new File(jars, "simple-module.jar"), mf); + File j2 = changeManifest(new File(jars, "depends-on-simple-module.jar"), mfBar); + m1 = mgr.create(j1, null, false, false, false); + m2 = mgr.create(j2, null, false, false, false); + HashSet b = new HashSet(Arrays.asList(m1, m2)); + mgr.enable(b); + both = b; - - Class clazz = m2.getClassLoader().loadClass("org.bar.SomethingElse"); - Class sprclass = m2.getClassLoader().loadClass("org.foo.Something"); - assertEquals("Correct parent is used", sprclass, clazz.getSuperclass()); + Class clazz = m2.getClassLoader().loadClass("org.bar.SomethingElse"); + Class sprclass = m2.getClassLoader().loadClass("org.foo.Something"); - } finally { - if (both != null) { - mgr.disable(both); + assertEquals("Correct parent is used", sprclass, clazz.getSuperclass()); + + } finally { + if (both != null) { + mgr.disable(both); + } + } + return null; } - mgr.mutexPrivileged().exitWriteAccess(); - } + }); } public void testDashnames() throws Exception { MockModuleInstaller installer = new MockModuleInstaller(); MockEvents ev = new MockEvents(); - ModuleManager mgr = new ModuleManager(installer, ev); - mgr.mutexPrivileged().enterWriteAccess(); - Module m2; - Module m1; - HashSet both = null; - try { - String mf = "Bundle-SymbolicName: org.foo-bar\n" + - "Bundle-Version: 1.1.0\n" + - "Bundle-ManifestVersion: 2\n" + - "Export-Package: org.foo"; - String mfBar = - "OpenIDE-Module: org.bar/1\n" + - "OpenIDE-Module-Name: Depends on bar test module\n" + - "OpenIDE-Module-Module-Dependencies: org.foo_bar\n" + - "some"; + final ModuleManager mgr = new ModuleManager(installer, ev); + mgr.mutex().writeAccess(new org.openide.util.Mutex.ExceptionAction() { + @Override + public Void run() throws Exception { + Module m2; + Module m1; + HashSet both = null; + try { + String mf = "Bundle-SymbolicName: org.foo-bar\n" + + "Bundle-Version: 1.1.0\n" + + "Bundle-ManifestVersion: 2\n" + + "Export-Package: org.foo"; + String mfBar = + "OpenIDE-Module: org.bar/1\n" + + "OpenIDE-Module-Name: Depends on bar test module\n" + + "OpenIDE-Module-Module-Dependencies: org.foo_bar\n" + + "some"; - File j1 = changeManifest(new File(jars, "simple-module.jar"), mf); - File j2 = changeManifest(new File(jars, "depends-on-simple-module.jar"), mfBar); - m1 = mgr.create(j1, null, false, false, false); - m2 = mgr.create(j2, null, false, false, false); - HashSet b = new HashSet(Arrays.asList(m1, m2)); - mgr.enable(b); - both = b; + File j1 = changeManifest(new File(jars, "simple-module.jar"), mf); + File j2 = changeManifest(new File(jars, "depends-on-simple-module.jar"), mfBar); + m1 = mgr.create(j1, null, false, false, false); + m2 = mgr.create(j2, null, false, false, false); + HashSet b = new HashSet(Arrays.asList(m1, m2)); + mgr.enable(b); + both = b; - Class clazz = m2.getClassLoader().loadClass("org.bar.SomethingElse"); - Class sprclass = m2.getClassLoader().loadClass("org.foo.Something"); + Class clazz = m2.getClassLoader().loadClass("org.bar.SomethingElse"); + Class sprclass = m2.getClassLoader().loadClass("org.foo.Something"); - assertEquals("Correct parent is used", sprclass, clazz.getSuperclass()); + assertEquals("Correct parent is used", sprclass, clazz.getSuperclass()); - } finally { - if (both != null) { - mgr.disable(both); + } finally { + if (both != null) { + mgr.disable(both); + } + } + return null; } - mgr.mutexPrivileged().exitWriteAccess(); - } + }); } public void testFactoryCreatesOurModulesWithDeps() throws Exception { MockModuleInstaller installer = new MockModuleInstaller(); MockEvents ev = new MockEvents(); - ModuleManager mgr = new ModuleManager(installer, ev); - mgr.mutexPrivileged().enterWriteAccess(); - HashSet both = null; - try { - String mf = "Bundle-SymbolicName: org.foo\n" + - "Bundle-Version: 1.1.0\n" + - "Bundle-ManifestVersion: 2\n" + - "Export-Package: org.foo"; - String mfBar = - "OpenIDE-Module: org.bar/1\n" + - "OpenIDE-Module-Name: Depends on bar test module\n" + - "OpenIDE-Module-Module-Dependencies: org.foo > 1.0\n" + - "some"; + final ModuleManager mgr = new ModuleManager(installer, ev); + mgr.mutex().writeAccess(new org.openide.util.Mutex.ExceptionAction() { + @Override + public Void run() throws Exception { + HashSet both = null; + try { + String mf = "Bundle-SymbolicName: org.foo\n" + + "Bundle-Version: 1.1.0\n" + + "Bundle-ManifestVersion: 2\n" + + "Export-Package: org.foo"; + String mfBar = + "OpenIDE-Module: org.bar/1\n" + + "OpenIDE-Module-Name: Depends on bar test module\n" + + "OpenIDE-Module-Module-Dependencies: org.foo > 1.0\n" + + "some"; - File j1 = changeManifest(new File(jars, "simple-module.jar"), mf); - File j2 = changeManifest(new File(jars, "depends-on-simple-module.jar"), mfBar); - Module m1 = mgr.create(j1, null, false, false, false); - Module m2 = mgr.create(j2, null, false, false, false); - HashSet b = new HashSet(Arrays.asList(m1, m2)); - mgr.enable(b); - both = b; + File j1 = changeManifest(new File(jars, "simple-module.jar"), mf); + File j2 = changeManifest(new File(jars, "depends-on-simple-module.jar"), mfBar); + Module m1 = mgr.create(j1, null, false, false, false); + Module m2 = mgr.create(j2, null, false, false, false); + HashSet b = new HashSet(Arrays.asList(m1, m2)); + mgr.enable(b); + both = b; - Class clazz = m2.getClassLoader().loadClass("org.bar.SomethingElse"); - Class sprclass = m2.getClassLoader().loadClass("org.foo.Something"); + Class clazz = m2.getClassLoader().loadClass("org.bar.SomethingElse"); + Class sprclass = m2.getClassLoader().loadClass("org.foo.Something"); - assertEquals("Correct parent is used", sprclass, clazz.getSuperclass()); - } finally { - if (both != null) { - mgr.disable(both); + assertEquals("Correct parent is used", sprclass, clazz.getSuperclass()); + } finally { + if (both != null) { + mgr.disable(both); + } + } + return null; } - mgr.mutexPrivileged().exitWriteAccess(); - } + }); } public void testLongDepsAreShortened() throws Exception { MockModuleInstaller installer = new MockModuleInstaller(); MockEvents ev = new MockEvents(); - ModuleManager mgr = new ModuleManager(installer, ev); - mgr.mutexPrivileged().enterWriteAccess(); - Module m2 = null; - try { - String mfBar = - "OpenIDE-Module: org.bar/1\n" + - "OpenIDE-Module-Specification-Version: 2.3.0.42.2\n" + - "OpenIDE-Module-Name: Too many dots in version\n" + - "OpenIDE-Module-Public-Packages: org.bar.*\n" + - "some"; + final ModuleManager mgr = new ModuleManager(installer, ev); + mgr.mutex().writeAccess(new org.openide.util.Mutex.ExceptionAction() { - File j2 = changeManifest(new File(jars, "depends-on-simple-module.jar"), mfBar); - m2 = mgr.create(j2, null, false, false, false); - mgr.enable(m2); - } finally { - if (m2 != null) { - mgr.disable(m2); + @Override + public Void run() throws Exception { + Module m2 = null; + try { + String mfBar = + "OpenIDE-Module: org.bar/1\n" + + "OpenIDE-Module-Specification-Version: 2.3.0.42.2\n" + + "OpenIDE-Module-Name: Too many dots in version\n" + + "OpenIDE-Module-Public-Packages: org.bar.*\n" + + "some"; + + File j2 = changeManifest(new File(jars, "depends-on-simple-module.jar"), mfBar); + m2 = mgr.create(j2, null, false, false, false); + mgr.enable(m2); + } finally { + if (m2 != null) { + mgr.disable(m2); + } + } + return null; } - mgr.mutexPrivileged().exitWriteAccess(); - } + }); } public void testNonNumericVersionNumberIsOK() throws Exception { MockModuleInstaller installer = new MockModuleInstaller(); MockEvents ev = new MockEvents(); - ModuleManager mgr = new ModuleManager(installer, ev); - mgr.mutexPrivileged().enterWriteAccess(); - Module m2 = null; - try { - String mfBar = - "Bundle-SymbolicName: org.bar\n" + - "Bundle-Version: 2.3.0.Prelude-rel24\n" + - "Export-Packages: org.bar.*\n" + - "some"; + final ModuleManager mgr = new ModuleManager(installer, ev); + mgr.mutex().writeAccess(new org.openide.util.Mutex.ExceptionAction() { + @Override + public Void run() throws Exception { + Module m2 = null; + try { + String mfBar = + "Bundle-SymbolicName: org.bar\n" + + "Bundle-Version: 2.3.0.Prelude-rel24\n" + + "Export-Packages: org.bar.*\n" + + "some"; - File j2 = changeManifest(new File(jars, "depends-on-simple-module.jar"), mfBar); - m2 = mgr.create(j2, null, false, false, false); - mgr.enable(m2); - assertEquals("2.3.0", m2.getSpecificationVersion().toString()); - assertEquals("2.3.0.Prelude-rel24", m2.getImplementationVersion()); - } finally { - if (m2 != null) { - mgr.disable(m2); + File j2 = changeManifest(new File(jars, "depends-on-simple-module.jar"), mfBar); + m2 = mgr.create(j2, null, false, false, false); + mgr.enable(m2); + assertEquals("2.3.0", m2.getSpecificationVersion().toString()); + assertEquals("2.3.0.Prelude-rel24", m2.getImplementationVersion()); + } finally { + if (m2 != null) { + mgr.disable(m2); + } + } + return null; } - mgr.mutexPrivileged().exitWriteAccess(); - } + }); } } diff -r d49cb1e754b2 core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoUsesSwingTest.java --- a/core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoUsesSwingTest.java Thu Jun 30 09:12:56 2011 +0200 +++ b/core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoUsesSwingTest.java Thu Jun 30 11:04:00 2011 +0200 @@ -88,16 +88,17 @@ ModuleSystem ms = Main.getModuleSystem(); mgr = ms.getManager(); - mgr.mutexPrivileged().enterWriteAccess(); - try { - m1 = mgr.create(simpleModule, null, false, false, false); - mgr.enable(Collections.singleton(m1)); - Class c = m1.getClassLoader().loadClass("org.barwing.Main"); - Runnable r = (Runnable)c.newInstance(); - r.run(); - } finally { - mgr.mutexPrivileged().exitWriteAccess(); - } + mgr.mutex().writeAccess(new org.openide.util.Mutex.ExceptionAction() { + @Override + public Void run() throws Exception { + m1 = mgr.create(simpleModule, null, false, false, false); + mgr.enable(Collections.singleton(m1)); + Class c = m1.getClassLoader().loadClass("org.barwing.Main"); + Runnable r = (Runnable)c.newInstance(); + r.run(); + return null; + } + }); } } diff -r d49cb1e754b2 core.startup/nbproject/project.xml --- a/core.startup/nbproject/project.xml Thu Jun 30 09:12:56 2011 +0200 +++ b/core.startup/nbproject/project.xml Thu Jun 30 11:04:00 2011 +0200 @@ -55,7 +55,7 @@ 1 - 2.39 + 2.42 diff -r d49cb1e754b2 core.startup/src/org/netbeans/core/startup/ConsistencyVerifier.java --- a/core.startup/src/org/netbeans/core/startup/ConsistencyVerifier.java Thu Jun 30 09:12:56 2011 +0200 +++ b/core.startup/src/org/netbeans/core/startup/ConsistencyVerifier.java Thu Jun 30 11:04:00 2011 +0200 @@ -59,6 +59,7 @@ import org.netbeans.Module; import org.netbeans.ModuleInstaller; import org.netbeans.ModuleManager; +import org.openide.util.Mutex.Action; /** * Utility class permitting you to verify that a set of modules could be enabled together. @@ -98,9 +99,21 @@ return findInconsistencies(modules, permittedDisabledAutoloads, true); } /* accessible to test */ static SortedMap> findInconsistencies( - Set modules, Set permittedDisabledAutoloads, boolean formatted) throws IllegalArgumentException { - ModuleManager mgr = new ModuleManager(new DummyInstaller(), new DummyEvents()); - mgr.mutexPrivileged().enterWriteAccess(); + final Set modules, final Set permittedDisabledAutoloads, final boolean formatted) throws IllegalArgumentException { + final ModuleManager mgr = new ModuleManager(new DummyInstaller(), new DummyEvents()); + return mgr.mutex().writeAccess(new Action>>() { + @Override + public SortedMap> run() { + return doFindInconsistencies(mgr, modules, permittedDisabledAutoloads, formatted); + } + }); + } + + + private static SortedMap> doFindInconsistencies( + ModuleManager mgr, Set modules, + Set permittedDisabledAutoloads, boolean formatted + ) throws IllegalArgumentException { Manifest dummy = new Manifest(); dummy.getMainAttributes().putValue("OpenIDE-Module", "__dummy__"); // NOI18N dummy.getMainAttributes().putValue("OpenIDE-Module-Provides", diff -r d49cb1e754b2 core.startup/src/org/netbeans/core/startup/ModuleList.java --- a/core.startup/src/org/netbeans/core/startup/ModuleList.java Thu Jun 30 09:12:56 2011 +0200 +++ b/core.startup/src/org/netbeans/core/startup/ModuleList.java Thu Jun 30 11:04:00 2011 +0200 @@ -91,6 +91,8 @@ import org.openide.modules.Dependency; import org.openide.modules.InstalledFileLocator; import org.openide.modules.SpecificationVersion; +import org.openide.util.Mutex.ExceptionAction; +import org.openide.util.MutexException; import org.openide.util.Parameters; import org.openide.util.RequestProcessor; import org.openide.util.Utilities; @@ -1179,10 +1181,10 @@ pendingRun = false; } LOG.fine("ModuleList: will process outstanding external XML changes"); - mgr.mutexPrivileged().enterWriteAccess(); try { - folder.getFileSystem().runAtomicAction(new FileSystem.AtomicAction() { - public void run() throws IOException { + mgr.mutex().writeAccess(new ExceptionAction() { + @Override + public Void run() throws Exception { // 1. For any dirty XML for which status exists but reloadable differs from XML: change. // 2. For any XML for which we have no status: create & create status, as disabled. // 3. For all dirty XML which says enabled but status says disabled: batch-enable as possible. @@ -1215,13 +1217,12 @@ stepUpdateProps(dirtyprops); stepMarkClean(); } + return null; } }); LOG.fine("ModuleList: finished processing outstanding external XML changes"); - } catch (IOException ioe) { - LOG.log(Level.WARNING, null, ioe); - } finally { - mgr.mutexPrivileged().exitWriteAccess(); + } catch (MutexException ioe) { + LOG.log(Level.WARNING, null, ioe.getException()); } } // All the steps called from the run() method to handle disk changes: diff -r d49cb1e754b2 core.startup/src/org/netbeans/core/startup/ModuleSystem.java --- a/core.startup/src/org/netbeans/core/startup/ModuleSystem.java Thu Jun 30 09:12:56 2011 +0200 +++ b/core.startup/src/org/netbeans/core/startup/ModuleSystem.java Thu Jun 30 11:04:00 2011 +0200 @@ -71,6 +71,9 @@ import org.openide.filesystems.FileSystem; import org.openide.filesystems.FileUtil; import org.openide.util.Exceptions; +import org.openide.util.Mutex.Action; +import org.openide.util.Mutex.ExceptionAction; +import org.openide.util.MutexException; /** Controller of the IDE's whole module system. * Contains higher-level convenience methods to @@ -153,16 +156,16 @@ * @return list of module-related JARs/ZIPs */ public List getModuleJars () { - mgr.mutexPrivileged().enterReadAccess(); - try { - List l = new ArrayList(); - for (Module m: mgr.getEnabledModules()) { - l.addAll(m.getAllJars()); + return mgr.mutex().readAccess(new Action>() { + @Override + public List run() { + List l = new ArrayList(); + for (Module m: mgr.getEnabledModules()) { + l.addAll(m.getAllJars()); + } + return l; } - return l; - } finally { - mgr.mutexPrivileged().exitReadAccess(); - } + }); } /** We just make the modules now, restore them later @@ -178,7 +181,7 @@ // Keep a list of manifest URL bases which we know we do not need to // parse. Some of these manifests might be signed, and if so, we do not // want to touch them, as it slows down startup quite a bit. - Set ignoredJars = new HashSet(); + final Set ignoredJars = new HashSet(); String javaHome = System.getProperty("java.home"); // NOI18N if (javaHome != null) { File lib = new File(new File(javaHome).getParentFile(), "lib"); // NOI18N @@ -189,155 +192,16 @@ ignoredJars.add(new File(entry)); } LOG.log(Level.FINE, "Ignored JARs: {0}", ignoredJars); - - mgr.mutexPrivileged().enterWriteAccess(); - ev.log(Events.START_LOAD_BOOT_MODULES); - try { - bootModules = new HashSet(10); - ClassLoader loader = ModuleSystem.class.getClassLoader(); - Enumeration e = loader.getResources("META-INF/MANIFEST.MF"); // NOI18N - ev.log(Events.PERF_TICK, "got all manifests"); // NOI18N - - // There will be duplicates: cf. #32576. - Set checkedManifests = new HashSet(); - MANIFESTS: - while (e.hasMoreElements()) { - URL manifestUrl = e.nextElement(); - if (!checkedManifests.add(manifestUrl)) { - // Already seen, ignore. - continue; - } - URL jarURL = FileUtil.getArchiveFile(manifestUrl); - if (jarURL != null && jarURL.getProtocol().equals("file") && - /* #121777 */ jarURL.getPath().startsWith("/")) { - LOG.log(Level.FINE, "Considering JAR: {0}", jarURL); - try { - if (ignoredJars.contains(new File(jarURL.toURI()))) { - LOG.log(Level.FINE, "ignoring JDK/JRE manifest: {0}", manifestUrl); - continue MANIFESTS; - } - } catch (URISyntaxException x) { - Exceptions.printStackTrace(x); - } - } - LOG.log(Level.FINE, "Checking boot manifest: {0}", manifestUrl); - - InputStream is; - try { - is = manifestUrl.openStream(); - } catch (IOException ioe) { - // Debugging for e.g. #32493 - which JAR was guilty? - Exceptions.attachMessage(ioe, "URL: " + manifestUrl); // NOI18N - throw ioe; - } - try { - Manifest mani = new Manifest(is); - Attributes attr = mani.getMainAttributes(); - if (attr.getValue("OpenIDE-Module") == null) { // NOI18N - // Not a module. - continue; - } - bootModules.add(mgr.createFixed(mani, manifestUrl, loader)); - } finally { - is.close(); - } + mgr.mutex().writeAccess(new Action() { + @Override + public Void run() { + doLoadBootModules(ignoredJars); + return null; } - if (list == null) { - // Plain calling us, we have to install now. - // Do it the simple way. - mgr.enable(bootModules); - } - ev.log(Events.PERF_TICK, "added all classpath modules"); // NOI18N - - } catch (IOException ioe) { - // Note: includes also InvalidException's for malformed this and that. - // Probably if a bootstrap module is corrupt we are in pretty bad shape - // anyway, so don't bother trying to be fancy and install just some of - // them etc. - LOG.log(Level.WARNING, null, ioe); - } catch (DuplicateException de) { - LOG.log(Level.WARNING, null, de); - } finally { - // Not 100% accurate in this case: - ev.log(Events.FINISH_LOAD_BOOT_MODULES); - mgr.mutexPrivileged().exitWriteAccess(); - } + }); } - - /** Refreshes the list of modules. Used from autoupdate.services. - * @since 1.28 - */ - public final void refresh() { - list.moduleListChanged(); - } - - /** Read disk settings and determine what the known modules are. - */ - public void readList() { - ev.log(Events.PERF_START, "ModuleSystem.readList"); // NOI18N - mgr.mutexPrivileged().enterWriteAccess(); - try { - list.readInitial(); - } finally { - mgr.mutexPrivileged().exitWriteAccess(); - } - ev.log(Events.PERF_END, "ModuleSystem.readList"); // NOI18N - } - - /** Install read modules. - */ - public void restore() { - ev.log(Events.PERF_START, "ModuleSystem.restore"); // NOI18N - mgr.mutexPrivileged().enterWriteAccess(); - try { - Set toTrigger = new HashSet(bootModules/*Collections.EMPTY_SET*/); - list.trigger(toTrigger); - mgr.releaseModuleManifests(); - } finally { - mgr.mutexPrivileged().exitWriteAccess(); - } - ev.log(Events.PERF_END, "ModuleSystem.restore"); // NOI18N - } - - /** Shut down the system: ask modules to shut down. - * Some of them may refuse. - */ - public boolean shutDown(final Runnable midHook) { - mgr.mutexPrivileged().enterWriteAccess(); - boolean res; - Runnable both = new Runnable() { - @Override - public void run() { - midHook.run(); - Stamps.getModulesJARs().shutdown(); - } - }; - try { - res = mgr.shutDown(both); - } finally { - mgr.mutexPrivileged().exitWriteAccess(); - } - return res; - } - - /** Load a module in test (reloadable) mode. - * If there is an existing module with a different JAR, get - * rid of it and load this one instead. - * If it is already installed, disable it and reenable it - * to reload its contents. - * If other modules depend on it, disable them first and - * then (try to) enable them again later. - */ - final void deployTestModule(File jar) throws IOException { - if (! jar.isAbsolute()) throw new IOException("Absolute paths only please"); // NOI18N - // Check to see if Javeleon is enabled. If so, - // let Javeleon handle the module reloading. - if (JaveleonModule.isJaveleonPresent && JaveleonModuleReloader.getDefault().reloadJaveleonModule(jar, mgr, installer, ev)) { - return; - } - - mgr.mutexPrivileged().enterWriteAccess(); + private void doDeployTestModule(File jar) throws IOException, IllegalArgumentException { ev.log(Events.START_DEPLOY_TEST_MODULE, jar); // For now, just print to stderr directly; could also go thru Events. // No need for I18N, module developers are expected to know English @@ -412,7 +276,170 @@ System.err.println("Done."); // NOI18N } finally { ev.log(Events.FINISH_DEPLOY_TEST_MODULE, jar); - mgr.mutexPrivileged().exitWriteAccess(); + } + } + + private void doLoadBootModules(Set ignoredJars) throws IllegalArgumentException { + ev.log(Events.START_LOAD_BOOT_MODULES); + try { + bootModules = new HashSet(10); + ClassLoader loader = ModuleSystem.class.getClassLoader(); + Enumeration e = loader.getResources("META-INF/MANIFEST.MF"); // NOI18N + ev.log(Events.PERF_TICK, "got all manifests"); // NOI18N + + // There will be duplicates: cf. #32576. + Set checkedManifests = new HashSet(); + MANIFESTS: + while (e.hasMoreElements()) { + URL manifestUrl = e.nextElement(); + if (!checkedManifests.add(manifestUrl)) { + // Already seen, ignore. + continue; + } + URL jarURL = FileUtil.getArchiveFile(manifestUrl); + if (jarURL != null && jarURL.getProtocol().equals("file") && + /* #121777 */ jarURL.getPath().startsWith("/")) { + LOG.log(Level.FINE, "Considering JAR: {0}", jarURL); + try { + if (ignoredJars.contains(new File(jarURL.toURI()))) { + LOG.log(Level.FINE, "ignoring JDK/JRE manifest: {0}", manifestUrl); + continue MANIFESTS; + } + } catch (URISyntaxException x) { + Exceptions.printStackTrace(x); + } + } + LOG.log(Level.FINE, "Checking boot manifest: {0}", manifestUrl); + + InputStream is; + try { + is = manifestUrl.openStream(); + } catch (IOException ioe) { + // Debugging for e.g. #32493 - which JAR was guilty? + Exceptions.attachMessage(ioe, "URL: " + manifestUrl); // NOI18N + throw ioe; + } + try { + Manifest mani = new Manifest(is); + Attributes attr = mani.getMainAttributes(); + if (attr.getValue("OpenIDE-Module") == null) { // NOI18N + // Not a module. + continue; + } + bootModules.add(mgr.createFixed(mani, manifestUrl, loader)); + } finally { + is.close(); + } + } + if (list == null) { + // Plain calling us, we have to install now. + // Do it the simple way. + mgr.enable(bootModules); + } + ev.log(Events.PERF_TICK, "added all classpath modules"); // NOI18N + + } catch (IOException ioe) { + // Note: includes also InvalidException's for malformed this and that. + // Probably if a bootstrap module is corrupt we are in pretty bad shape + // anyway, so don't bother trying to be fancy and install just some of + // them etc. + LOG.log(Level.WARNING, null, ioe); + } catch (DuplicateException de) { + LOG.log(Level.WARNING, null, de); + } finally { + // Not 100% accurate in this case: + ev.log(Events.FINISH_LOAD_BOOT_MODULES); + } + } + + /** Refreshes the list of modules. Used from autoupdate.services. + * @since 1.28 + */ + public final void refresh() { + list.moduleListChanged(); + } + + /** Read disk settings and determine what the known modules are. + */ + public void readList() { + ev.log(Events.PERF_START, "ModuleSystem.readList"); // NOI18N + mgr.mutex().writeAccess(new Runnable() { + @Override + public void run() { + list.readInitial(); + } + }); + ev.log(Events.PERF_END, "ModuleSystem.readList"); // NOI18N + } + + /** Install read modules. + */ + public void restore() { + ev.log(Events.PERF_START, "ModuleSystem.restore"); // NOI18N + mgr.mutex().writeAccess(new Runnable() { + @Override + public void run() { + Set toTrigger = new HashSet(bootModules/*Collections.EMPTY_SET*/); + list.trigger(toTrigger); + mgr.releaseModuleManifests(); + } + }); + ev.log(Events.PERF_END, "ModuleSystem.restore"); // NOI18N + } + + /** Shut down the system: ask modules to shut down. + * Some of them may refuse. + */ + public boolean shutDown(final Runnable midHook) { + class ActionImpl implements Runnable { + boolean second; + boolean res; + + public ActionImpl() { + } + + @Override + public void run() { + if (second) { + midHook.run(); + Stamps.getModulesJARs().shutdown(); + } else { + second = true; + res = mgr.shutDown(this); + } + } + } + ActionImpl impl = new ActionImpl(); + return impl.res; + } + + /** Load a module in test (reloadable) mode. + * If there is an existing module with a different JAR, get + * rid of it and load this one instead. + * If it is already installed, disable it and reenable it + * to reload its contents. + * If other modules depend on it, disable them first and + * then (try to) enable them again later. + */ + final void deployTestModule(final File jar) throws IOException { + try { + if (! jar.isAbsolute()) throw new IOException("Absolute paths only please"); // NOI18N + + // Check to see if Javeleon is enabled. If so, + // let Javeleon handle the module reloading. + if (JaveleonModule.isJaveleonPresent && JaveleonModuleReloader.getDefault().reloadJaveleonModule(jar, mgr, installer, ev)) { + return; + } + + mgr.mutex().writeAccess(new ExceptionAction() { + @Override + public Void run() throws IOException { + doDeployTestModule(jar); + return null; + } + }); + } catch (MutexException ex) { + throw (IOException)ex.getException(); } } /** Make sure some module is disabled. diff -r d49cb1e754b2 core.startup/src/org/netbeans/core/startup/NbInstaller.java --- a/core.startup/src/org/netbeans/core/startup/NbInstaller.java Thu Jun 30 09:12:56 2011 +0200 +++ b/core.startup/src/org/netbeans/core/startup/NbInstaller.java Thu Jun 30 11:04:00 2011 +0200 @@ -67,6 +67,7 @@ import java.util.StringTokenizer; import java.util.TreeMap; import java.util.TreeSet; +import java.util.concurrent.Executor; import java.util.jar.Attributes; import java.util.jar.JarEntry; import java.util.jar.JarFile; @@ -92,7 +93,6 @@ import org.openide.util.NbCollections; import org.openide.util.SharedClassObject; import org.openide.util.NbBundle; -import org.openide.util.Utilities; import org.openide.util.lookup.InstanceContent; import org.xml.sax.SAXException; @@ -103,7 +103,7 @@ * messages and the like. * @author Jesse Glick, Jan Pokorsky, Jaroslav Tulach, et al. */ -final class NbInstaller extends ModuleInstaller { +final class NbInstaller extends ModuleInstaller implements Executor { private static final Logger LOG = Logger.getLogger(NbInstaller.class.getName()); @@ -484,6 +484,17 @@ } private final InstanceContent.Convertor convertor = new Convertor(); + + @Override + public void execute(Runnable command) { + FileUtil.runAtomicAction(command); + } + + @Override + protected Executor executor() { + return this; + } + private final class Convertor implements InstanceContent.Convertor { // or ? Convertor() {} public Object convert(ManifestSection s) { diff -r d49cb1e754b2 core.startup/test/unit/src/org/netbeans/core/startup/ModuleFormatSatisfiedTest.java --- a/core.startup/test/unit/src/org/netbeans/core/startup/ModuleFormatSatisfiedTest.java Thu Jun 30 09:12:56 2011 +0200 +++ b/core.startup/test/unit/src/org/netbeans/core/startup/ModuleFormatSatisfiedTest.java Thu Jun 30 11:04:00 2011 +0200 @@ -54,6 +54,7 @@ import java.util.jar.Manifest; import org.netbeans.Module; import org.netbeans.ModuleManager; +import org.openide.util.Mutex.ExceptionAction; /** Checks whether a modules are provided with ModuleFormat1 token. * @@ -89,19 +90,20 @@ final MockEvents ev = new MockEvents(); NbInstaller installer = new NbInstaller(ev); - ModuleManager mgr = new ModuleManager(installer, ev); + final ModuleManager mgr = new ModuleManager(installer, ev); installer.registerManager(mgr); - mgr.mutexPrivileged().enterWriteAccess(); - try { - addOpenideModules(mgr); - Module m1 = mgr.create(moduleJarFile, null, false, false, false); - assertEquals(Collections.EMPTY_SET, m1.getProblems()); - mgr.enable(m1); - mgr.disable(m1); - mgr.delete(m1); - } finally { - mgr.mutexPrivileged().exitWriteAccess(); - } + mgr.mutex().writeAccess(new ExceptionAction() { + @Override + public Void run() throws Exception { + addOpenideModules(mgr); + Module m1 = mgr.create(moduleJarFile, null, false, false, false); + assertEquals(Collections.EMPTY_SET, m1.getProblems()); + mgr.enable(m1); + mgr.disable(m1); + mgr.delete(m1); + return null; + } + }); } static void addOpenideModules (ModuleManager mgr) throws Exception { diff -r d49cb1e754b2 core.startup/test/unit/src/org/netbeans/core/startup/ModuleListDontDeleteDisabledModulesTest.java --- a/core.startup/test/unit/src/org/netbeans/core/startup/ModuleListDontDeleteDisabledModulesTest.java Thu Jun 30 09:12:56 2011 +0200 +++ b/core.startup/test/unit/src/org/netbeans/core/startup/ModuleListDontDeleteDisabledModulesTest.java Thu Jun 30 11:04:00 2011 +0200 @@ -53,6 +53,7 @@ import org.netbeans.MockModuleInstaller; import org.netbeans.SetupHid; import org.openide.filesystems.*; +import org.openide.util.Mutex.ExceptionAction; import org.openide.util.test.MockLookup; /** @@ -127,15 +128,16 @@ FileObject configFo = FileUtil.getConfigFile("Modules/org-foo.xml"); assertNotNull("Config file exists", configFo); - mgr.mutexPrivileged().enterWriteAccess(); - try { - assertEquals(Collections.emptySet(), list.readInitial()); - assertEquals(Collections.emptySet(), mgr.getModules()); - list.trigger(Collections.emptySet()); - assertEquals(Collections.emptySet(), mgr.getModules()); - } finally { - mgr.mutexPrivileged().exitWriteAccess(); - } + mgr.mutex().writeAccess(new ExceptionAction() { + @Override + public Void run() throws Exception { + assertEquals(Collections.emptySet(), list.readInitial()); + assertEquals(Collections.emptySet(), mgr.getModules()); + list.trigger(Collections.emptySet()); + assertEquals(Collections.emptySet(), mgr.getModules()); + return null; + } + }); assertTrue("Old config file is still OK", configFo.isValid()); FileObject configFo2 = FileUtil.getConfigFile("Modules/org-foo.xml"); diff -r d49cb1e754b2 core.startup/test/unit/src/org/netbeans/core/startup/ModuleListTest.java --- a/core.startup/test/unit/src/org/netbeans/core/startup/ModuleListTest.java Thu Jun 30 09:12:56 2011 +0200 +++ b/core.startup/test/unit/src/org/netbeans/core/startup/ModuleListTest.java Thu Jun 30 11:04:00 2011 +0200 @@ -71,6 +71,7 @@ import org.openide.filesystems.FileUtil; import org.openide.filesystems.LocalFileSystem; import org.openide.modules.InstalledFileLocator; +import org.openide.util.Mutex.ExceptionAction; import org.openide.util.test.MockLookup; /** Test the functions of the module list, i.e. finding modules on @@ -138,18 +139,19 @@ * Make sure a class from one can depend on a class from another. */ public void testScanAndTwiddle() throws Exception { - mgr.mutexPrivileged().enterWriteAccess(); - try { - // XXX try to read an actual initial list too... - assertEquals(Collections.emptySet(), list.readInitial()); - Set modules = new HashSet(); - modules.add(makeModule("simple-module.jar")); - modules.add(makeModule("depends-on-simple-module.jar")); - list.trigger(modules); - assertEquals(modules, mgr.getEnabledModules()); - } finally { - mgr.mutexPrivileged().exitWriteAccess(); - } + mgr.mutex().writeAccess(new ExceptionAction() { + @Override + public Void run() throws Exception { + // XXX try to read an actual initial list too... + assertEquals(Collections.emptySet(), list.readInitial()); + Set modules = new HashSet(); + modules.add(makeModule("simple-module.jar")); + modules.add(makeModule("depends-on-simple-module.jar")); + list.trigger(modules); + assertEquals(modules, mgr.getEnabledModules()); + return null; + } + }); FileObject[] xml = modulesfolder.getChildren(); assertEquals(2, xml.length); FileObject foo, bar; @@ -168,16 +170,17 @@ // Checking that changes in memory will rewrite XML: LoggedFileListener listener = new LoggedFileListener(); modulesfolder.addFileChangeListener(listener); - mgr.mutexPrivileged().enterWriteAccess(); - try { - Module m1 = mgr.get("org.foo"); - assertNotNull(m1); - Module m2 = mgr.get("org.bar"); - assertNotNull(m2); - mgr.disable(new HashSet(Arrays.asList(m1, m2))); - } finally { - mgr.mutexPrivileged().exitWriteAccess(); - } + mgr.mutex().writeAccess(new ExceptionAction() { + @Override + public Void run() throws Exception { + Module m1 = mgr.get("org.foo"); + assertNotNull(m1); + Module m2 = mgr.get("org.bar"); + assertNotNull(m2); + mgr.disable(new HashSet(Arrays.asList(m1, m2))); + return null; + } + }); // We expect it to have marked both as disabled now: listener.waitForChange("Modules/org-foo.xml"); listener.waitForChange("Modules/org-bar.xml"); @@ -216,14 +219,15 @@ MockEvents ev = new MockEvents(); ModuleManager mgr2 = new ModuleManager(installer, ev); assertNotNull(mf); - ModuleList list2 = new ModuleList(mgr2, mf, ev); - mgr2.mutexPrivileged().enterWriteAccess(); + final ModuleList list2 = new ModuleList(mgr2, mf, ev); CharSequence log = Log.enable("org.netbeans.core.startup.ModuleList", Level.FINEST); - try { - list2.readInitial(); - } finally { - mgr2.mutexPrivileged().exitWriteAccess(); - } + mgr2.mutex().writeAccess(new ExceptionAction() { + @Override + public Void run() throws Exception { + list2.readInitial(); + return null; + } + }); if (log.toString().indexOf("no cache") >= 0) { fail("Everything shall be read from cache:\n" + log); } @@ -250,15 +254,16 @@ * Written to help test #27106. */ public void testAddNewModuleViaXML() throws Exception { - mgr.mutexPrivileged().enterWriteAccess(); - try { - assertEquals(Collections.emptySet(), list.readInitial()); - assertEquals(Collections.emptySet(), mgr.getModules()); - list.trigger(Collections.emptySet()); - assertEquals(Collections.emptySet(), mgr.getModules()); - } finally { - mgr.mutexPrivileged().exitWriteAccess(); - } + mgr.mutex().writeAccess(new ExceptionAction() { + @Override + public Void run() throws Exception { + assertEquals(Collections.emptySet(), list.readInitial()); + assertEquals(Collections.emptySet(), mgr.getModules()); + list.trigger(Collections.emptySet()); + assertEquals(Collections.emptySet(), mgr.getModules()); + return null; + } + }); LoggedPCListener listener = new LoggedPCListener(); mgr.addPropertyChangeListener(listener); modulesfolder.getFileSystem().runAtomicAction(new FileSystem.AtomicAction() { @@ -269,16 +274,17 @@ } }); assertTrue("PROP_MODULES fired", listener.waitForChange(mgr, ModuleManager.PROP_MODULES)); - mgr.mutexPrivileged().enterReadAccess(); - try { - Set modules = mgr.getEnabledModules(); - assertEquals(1, modules.size()); - Module m = (Module)modules.iterator().next(); - assertEquals("org.foo", m.getCodeNameBase()); - assertTrue(m.isEnabled()); - } finally { - mgr.mutexPrivileged().exitReadAccess(); - } + mgr.mutex().writeAccess(new ExceptionAction() { + @Override + public Void run() throws Exception { + Set modules = mgr.getEnabledModules(); + assertEquals(1, modules.size()); + Module m = (Module)modules.iterator().next(); + assertEquals("org.foo", m.getCodeNameBase()); + assertTrue(m.isEnabled()); + return null; + } + }); } // XXX try to read a nonempty initial list diff -r d49cb1e754b2 core.startup/test/unit/src/org/netbeans/core/startup/NbBootDelegationTest.java --- a/core.startup/test/unit/src/org/netbeans/core/startup/NbBootDelegationTest.java Thu Jun 30 09:12:56 2011 +0200 +++ b/core.startup/test/unit/src/org/netbeans/core/startup/NbBootDelegationTest.java Thu Jun 30 11:04:00 2011 +0200 @@ -46,6 +46,7 @@ import java.util.Collections; import org.netbeans.Module; import org.netbeans.ModuleManager; +import org.openide.util.Mutex.ExceptionAction; /** * @@ -58,31 +59,35 @@ } public void testNetBeansBootDelegation() throws Exception { - ModuleManager mgr = Main.getModuleSystem().getManager(); - mgr.mutexPrivileged().enterWriteAccess(); - System.setProperty("netbeans.bootdelegation", "javax.swing, javax.naming.*"); - try { - Module m1 = mgr.create(new File(jars, "simple-module.jar"), null, false, false, false); - mgr.enable(Collections.singleton(m1)); - final ClassLoader ldr = m1.getClassLoader(); - Class jtree = Class.forName("javax.swing.JTree", true, ldr); - assertNotNull("JTree found", jtree); - String tableModel = "javax.swing.table.TableModel"; - try { - Class model = Class.forName(tableModel, true, ldr); - fail("Model shall not be accessible: " + model); - } catch (ClassNotFoundException ex) { - // OK - assertNotNull("The class exists on boot path", ClassLoader.getSystemClassLoader().loadClass(tableModel)); + final ModuleManager mgr = Main.getModuleSystem().getManager(); + mgr.mutex().writeAccess(new ExceptionAction() { + @Override + public Void run() throws Exception { + System.setProperty("netbeans.bootdelegation", "javax.swing, javax.naming.*"); + try { + Module m1 = mgr.create(new File(jars, "simple-module.jar"), null, false, false, false); + mgr.enable(Collections.singleton(m1)); + final ClassLoader ldr = m1.getClassLoader(); + Class jtree = Class.forName("javax.swing.JTree", true, ldr); + assertNotNull("JTree found", jtree); + String tableModel = "javax.swing.table.TableModel"; + try { + Class model = Class.forName(tableModel, true, ldr); + fail("Model shall not be accessible: " + model); + } catch (ClassNotFoundException ex) { + // OK + assertNotNull("The class exists on boot path", ClassLoader.getSystemClassLoader().loadClass(tableModel)); + } + Class list = Class.forName("java.util.ArrayList", true, ldr); + assertNotNull("java packages are always accessible", list); + Class naming = Class.forName("javax.naming.event.EventContext", true, ldr); + assertNotNull("naming is recursively visible", naming); + } finally { + System.getProperties().remove("netbeans.bootdelegation"); + } + return null; } - Class list = Class.forName("java.util.ArrayList", true, ldr); - assertNotNull("java packages are always accessible", list); - Class naming = Class.forName("javax.naming.event.EventContext", true, ldr); - assertNotNull("naming is recursively visible", naming); - } finally { - System.getProperties().remove("netbeans.bootdelegation"); - mgr.mutexPrivileged().exitWriteAccess(); - } + }); } diff -r d49cb1e754b2 core.startup/test/unit/src/org/netbeans/core/startup/NbInstallerHideClasspathPackagesTest.java --- a/core.startup/test/unit/src/org/netbeans/core/startup/NbInstallerHideClasspathPackagesTest.java Thu Jun 30 09:12:56 2011 +0200 +++ b/core.startup/test/unit/src/org/netbeans/core/startup/NbInstallerHideClasspathPackagesTest.java Thu Jun 30 11:04:00 2011 +0200 @@ -55,6 +55,7 @@ import org.netbeans.Events; import org.netbeans.Module; import org.netbeans.ModuleManager; +import org.openide.util.Mutex.ExceptionAction; /** * Checks that OpenIDE-Module-Hide-Classpath-Packages works. @@ -66,7 +67,7 @@ } public void testHideClasspathPackages() throws Exception { - File m1j = new File(getWorkDir(), "m1.jar"); + final File m1j = new File(getWorkDir(), "m1.jar"); Map contents = new HashMap(); contents.put("javax/net/SocketFactory.class", "ignored"); contents.put("javax/swing/JPanel.class", "overrides"); @@ -77,7 +78,7 @@ mani.put("OpenIDE-Module", "m1"); mani.put("OpenIDE-Module-Hide-Classpath-Packages", "javax.swing.**, javax.naming.*"); createJar(m1j, contents, mani); - File m2j = new File(getWorkDir(), "m2.jar"); + final File m2j = new File(getWorkDir(), "m2.jar"); mani = new HashMap(); mani.put("OpenIDE-Module", "m2"); mani.put("OpenIDE-Module-Module-Dependencies", "m1"); @@ -85,50 +86,51 @@ mani.put("OpenIDE-Module-Layer", "m2/layer.xml"); mani.put("OpenIDE-Module-Package-Dependencies", "javax.management[Descriptor]"); createJar(m2j, Collections.singletonMap("m2/layer.xml", ""), mani); - File m3j = new File(getWorkDir(), "m3.jar"); + final File m3j = new File(getWorkDir(), "m3.jar"); createJar(m3j, Collections.emptyMap(), Collections.singletonMap("OpenIDE-Module", "m3")); Events ev = new MockEvents(); NbInstaller inst = new NbInstaller(ev); - ModuleManager mgr = new ModuleManager(inst, ev); + final ModuleManager mgr = new ModuleManager(inst, ev); inst.registerManager(mgr); - mgr.mutexPrivileged().enterWriteAccess(); - try { - Module m1 = mgr.create(m1j, null, false, false, false); - Module m2 = mgr.create(m2j, null, false, false, false); - Module m3 = mgr.create(m3j, null, false, false, false); - mgr.enable(new HashSet(Arrays.asList(m1, m2, m3))); - ModuleManagerTest.assertDoesNotOverride(m1, "javax.net.SocketFactory"); - ModuleManagerTest.assertOverrides(m1, "javax.swing.JPanel"); - ModuleManagerTest.assertOverrides(m1, "javax.swing.text.Document"); - ModuleManagerTest.assertOverrides(m1, "javax.naming.Context"); - ModuleManagerTest.assertDoesNotOverride(m1, "javax.naming.spi.Resolver"); - ModuleManagerTest.assertDoesNotOverride(m2, "javax.net.SocketFactory"); - ModuleManagerTest.assertOverrides(m2, "javax.swing.JPanel"); - ModuleManagerTest.assertOverrides(m2, "javax.swing.text.Document"); - ModuleManagerTest.assertOverrides(m2, "javax.naming.Context"); - ModuleManagerTest.assertDoesNotOverride(m2, "javax.naming.spi.Resolver"); - ModuleManagerTest.assertDoesNotOverride(m3, "javax.net.SocketFactory"); - ModuleManagerTest.assertDoesNotOverride(m3, "javax.swing.JPanel"); - ModuleManagerTest.assertDoesNotOverride(m3, "javax.swing.text.Document"); - ModuleManagerTest.assertDoesNotOverride(m3, "javax.naming.Context"); - ModuleManagerTest.assertDoesNotOverride(m3, "javax.naming.spi.Resolver"); - // #159586: masked JRE classes should not be accessible from SCL either. - ClassLoader scl = mgr.getClassLoader(); - ModuleManagerTest.assertDoesNotOverride(scl, "javax.net.SocketFactory"); - ModuleManagerTest.assertOverrides(scl, "system class loader", "javax.swing.JPanel"); - ModuleManagerTest.assertOverrides(scl, "system class loader", "javax.swing.text.Document"); - ModuleManagerTest.assertOverrides(scl, "system class loader", "javax.naming.Context"); - ModuleManagerTest.assertDoesNotOverride(scl, "javax.naming.spi.Resolver"); - mgr.disable(new HashSet(Arrays.asList(m1, m2, m3))); - scl = mgr.getClassLoader(); - ModuleManagerTest.assertDoesNotOverride(scl, "javax.net.SocketFactory"); - ModuleManagerTest.assertDoesNotOverride(scl, "javax.swing.JPanel"); - ModuleManagerTest.assertDoesNotOverride(scl, "javax.swing.text.Document"); - ModuleManagerTest.assertDoesNotOverride(scl, "javax.naming.Context"); - ModuleManagerTest.assertDoesNotOverride(scl, "javax.naming.spi.Resolver"); - } finally { - mgr.mutexPrivileged().exitWriteAccess(); - } + mgr.mutex().writeAccess(new ExceptionAction() { + @Override + public Void run() throws Exception { + Module m1 = mgr.create(m1j, null, false, false, false); + Module m2 = mgr.create(m2j, null, false, false, false); + Module m3 = mgr.create(m3j, null, false, false, false); + mgr.enable(new HashSet(Arrays.asList(m1, m2, m3))); + ModuleManagerTest.assertDoesNotOverride(m1, "javax.net.SocketFactory"); + ModuleManagerTest.assertOverrides(m1, "javax.swing.JPanel"); + ModuleManagerTest.assertOverrides(m1, "javax.swing.text.Document"); + ModuleManagerTest.assertOverrides(m1, "javax.naming.Context"); + ModuleManagerTest.assertDoesNotOverride(m1, "javax.naming.spi.Resolver"); + ModuleManagerTest.assertDoesNotOverride(m2, "javax.net.SocketFactory"); + ModuleManagerTest.assertOverrides(m2, "javax.swing.JPanel"); + ModuleManagerTest.assertOverrides(m2, "javax.swing.text.Document"); + ModuleManagerTest.assertOverrides(m2, "javax.naming.Context"); + ModuleManagerTest.assertDoesNotOverride(m2, "javax.naming.spi.Resolver"); + ModuleManagerTest.assertDoesNotOverride(m3, "javax.net.SocketFactory"); + ModuleManagerTest.assertDoesNotOverride(m3, "javax.swing.JPanel"); + ModuleManagerTest.assertDoesNotOverride(m3, "javax.swing.text.Document"); + ModuleManagerTest.assertDoesNotOverride(m3, "javax.naming.Context"); + ModuleManagerTest.assertDoesNotOverride(m3, "javax.naming.spi.Resolver"); + // #159586: masked JRE classes should not be accessible from SCL either. + ClassLoader scl = mgr.getClassLoader(); + ModuleManagerTest.assertDoesNotOverride(scl, "javax.net.SocketFactory"); + ModuleManagerTest.assertOverrides(scl, "system class loader", "javax.swing.JPanel"); + ModuleManagerTest.assertOverrides(scl, "system class loader", "javax.swing.text.Document"); + ModuleManagerTest.assertOverrides(scl, "system class loader", "javax.naming.Context"); + ModuleManagerTest.assertDoesNotOverride(scl, "javax.naming.spi.Resolver"); + mgr.disable(new HashSet(Arrays.asList(m1, m2, m3))); + scl = mgr.getClassLoader(); + ModuleManagerTest.assertDoesNotOverride(scl, "javax.net.SocketFactory"); + ModuleManagerTest.assertDoesNotOverride(scl, "javax.swing.JPanel"); + ModuleManagerTest.assertDoesNotOverride(scl, "javax.swing.text.Document"); + ModuleManagerTest.assertDoesNotOverride(scl, "javax.naming.Context"); + ModuleManagerTest.assertDoesNotOverride(scl, "javax.naming.spi.Resolver"); + return null; + } + }); } @Override diff -r d49cb1e754b2 core.startup/test/unit/src/org/netbeans/core/startup/NbInstallerTest2.java --- a/core.startup/test/unit/src/org/netbeans/core/startup/NbInstallerTest2.java Thu Jun 30 09:12:56 2011 +0200 +++ b/core.startup/test/unit/src/org/netbeans/core/startup/NbInstallerTest2.java Thu Jun 30 11:04:00 2011 +0200 @@ -51,6 +51,7 @@ import org.netbeans.Module; import org.netbeans.ModuleManager; import org.openide.filesystems.FileUtil; +import org.openide.util.Mutex.ExceptionAction; /** Test the NetBeans module installer implementation. * Broken into pieces to ensure each runs in its own VM. @@ -72,28 +73,29 @@ Main.getModuleSystem (); // init module system final MockEvents ev = new MockEvents(); NbInstaller installer = new NbInstaller(ev); - ModuleManager mgr = new ModuleManager(installer, ev); + final ModuleManager mgr = new ModuleManager(installer, ev); installer.registerManager(mgr); - mgr.mutexPrivileged().enterWriteAccess(); - try { - Locale orig = Locale.getDefault(); - Locale.setDefault(new Locale("cs", "CZ")); - try { - Module m1 = mgr.create(new File(jars, "base-layer-mod.jar"), null, false, false, false); - assertEquals(Collections.EMPTY_SET, m1.getProblems()); - assertEquals(null, slurp("foo/file1.txt")); - mgr.enable(m1); - assertEquals("prekladany obsah", slurp("foo/file1.txt")); - assertEquals("base contents", slurp("foo/file2.txt")); - assertEquals("someval", FileUtil.getConfigFile("foo/file5.txt").getAttribute("myattr")); - mgr.disable(m1); - mgr.delete(m1); - } finally { - Locale.setDefault(orig); + mgr.mutex().writeAccess(new ExceptionAction() { + @Override + public Void run() throws Exception { + Locale orig = Locale.getDefault(); + Locale.setDefault(new Locale("cs", "CZ")); + try { + Module m1 = mgr.create(new File(jars, "base-layer-mod.jar"), null, false, false, false); + assertEquals(Collections.EMPTY_SET, m1.getProblems()); + assertEquals(null, slurp("foo/file1.txt")); + mgr.enable(m1); + assertEquals("prekladany obsah", slurp("foo/file1.txt")); + assertEquals("base contents", slurp("foo/file2.txt")); + assertEquals("someval", FileUtil.getConfigFile("foo/file5.txt").getAttribute("myattr")); + mgr.disable(m1); + mgr.delete(m1); + } finally { + Locale.setDefault(orig); + } + return null; } - } finally { - mgr.mutexPrivileged().exitWriteAccess(); - } + }); } } diff -r d49cb1e754b2 core.startup/test/unit/src/org/netbeans/core/startup/NbInstallerTest3.java --- a/core.startup/test/unit/src/org/netbeans/core/startup/NbInstallerTest3.java Thu Jun 30 09:12:56 2011 +0200 +++ b/core.startup/test/unit/src/org/netbeans/core/startup/NbInstallerTest3.java Thu Jun 30 11:04:00 2011 +0200 @@ -49,6 +49,7 @@ import java.util.Collections; import org.netbeans.Module; import org.netbeans.ModuleManager; +import org.openide.util.Mutex.ExceptionAction; import org.openide.util.NbBundle; /** Test the NetBeans module installer implementation. @@ -66,26 +67,27 @@ Main.getModuleSystem (); final MockEvents ev = new MockEvents(); NbInstaller installer = new NbInstaller(ev); - ModuleManager mgr = new ModuleManager(installer, ev); + final ModuleManager mgr = new ModuleManager(installer, ev); installer.registerManager(mgr); - mgr.mutexPrivileged().enterWriteAccess(); - try { - String orig = NbBundle.getBranding(); - NbBundle.setBranding("foo"); - try { - Module m1 = mgr.create(new File(jars, "base-layer-mod.jar"), null, false, false, false); - assertEquals(Collections.EMPTY_SET, m1.getProblems()); - mgr.enable(m1); - assertEquals("special contents", slurp("foo/file1.txt")); - assertEquals(null, slurp("foo/file2.txt")); - mgr.disable(m1); - mgr.delete(m1); - } finally { - NbBundle.setBranding(orig); + mgr.mutex().writeAccess(new ExceptionAction() { + @Override + public Void run() throws Exception { + String orig = NbBundle.getBranding(); + NbBundle.setBranding("foo"); + try { + Module m1 = mgr.create(new File(jars, "base-layer-mod.jar"), null, false, false, false); + assertEquals(Collections.EMPTY_SET, m1.getProblems()); + mgr.enable(m1); + assertEquals("special contents", slurp("foo/file1.txt")); + assertEquals(null, slurp("foo/file2.txt")); + mgr.disable(m1); + mgr.delete(m1); + } finally { + NbBundle.setBranding(orig); + } + return null; } - } finally { - mgr.mutexPrivileged().exitWriteAccess(); - } + }); } } diff -r d49cb1e754b2 core.startup/test/unit/src/org/netbeans/core/startup/NbInstallerTest4.java --- a/core.startup/test/unit/src/org/netbeans/core/startup/NbInstallerTest4.java Thu Jun 30 09:12:56 2011 +0200 +++ b/core.startup/test/unit/src/org/netbeans/core/startup/NbInstallerTest4.java Thu Jun 30 11:04:00 2011 +0200 @@ -54,6 +54,7 @@ import org.netbeans.ModuleManager; import org.netbeans.Stamps; import org.openide.filesystems.FileUtil; +import org.openide.util.Mutex.ExceptionAction; /** Test the NetBeans module installer implementation. * Broken into pieces to ensure each runs in its own VM. @@ -72,33 +73,34 @@ Main.getModuleSystem (); // init module system final MockEvents ev = new MockEvents(); NbInstaller installer = new NbInstaller(ev); - ModuleManager mgr = new ModuleManager(installer, ev); + final ModuleManager mgr = new ModuleManager(installer, ev); installer.registerManager(mgr); - mgr.mutexPrivileged().enterWriteAccess(); - try { - Module m1 = mgr.create(new File(jars, "base-layer-mod.jar"), null, false, false, false); - Module m2 = mgr.create(new File(jars, "override-layer-mod.jar"), null, false, false, false); - assertEquals(Collections.EMPTY_SET, m2.getProblems()); - assertEquals(null, slurp("foo/file1.txt")); - assertEquals(null, slurp("foo/file3.txt")); - assertEquals(null, slurp("foo/file4.txt")); - Set m1m2 = new HashSet(Arrays.asList(m1, m2)); - mgr.enable(m1m2); - - Stamps.getModulesJARs().flush(0); - Stamps.getModulesJARs().shutdown(); - - assertEquals("base contents", slurp("foo/file1.txt")); - assertEquals("customized contents", slurp("foo/file3.txt")); - assertEquals(null, slurp("foo/file4.txt")); - assertEquals("someotherval", FileUtil.getConfigFile("foo/file5.txt").getAttribute("myattr")); - mgr.disable(m1m2); - assertEquals(null, slurp("foo/file1.txt")); - mgr.delete(m2); - mgr.delete(m1); - } finally { - mgr.mutexPrivileged().exitWriteAccess(); - } + mgr.mutex().writeAccess(new ExceptionAction() { + @Override + public Void run() throws Exception { + Module m1 = mgr.create(new File(jars, "base-layer-mod.jar"), null, false, false, false); + Module m2 = mgr.create(new File(jars, "override-layer-mod.jar"), null, false, false, false); + assertEquals(Collections.EMPTY_SET, m2.getProblems()); + assertEquals(null, slurp("foo/file1.txt")); + assertEquals(null, slurp("foo/file3.txt")); + assertEquals(null, slurp("foo/file4.txt")); + Set m1m2 = new HashSet(Arrays.asList(m1, m2)); + mgr.enable(m1m2); + + Stamps.getModulesJARs().flush(0); + Stamps.getModulesJARs().shutdown(); + + assertEquals("base contents", slurp("foo/file1.txt")); + assertEquals("customized contents", slurp("foo/file3.txt")); + assertEquals(null, slurp("foo/file4.txt")); + assertEquals("someotherval", FileUtil.getConfigFile("foo/file5.txt").getAttribute("myattr")); + mgr.disable(m1m2); + assertEquals(null, slurp("foo/file1.txt")); + mgr.delete(m2); + mgr.delete(m1); + return null; + } + }); } } diff -r d49cb1e754b2 core.startup/test/unit/src/org/netbeans/core/startup/NbInstallerTest5.java --- a/core.startup/test/unit/src/org/netbeans/core/startup/NbInstallerTest5.java Thu Jun 30 09:12:56 2011 +0200 +++ b/core.startup/test/unit/src/org/netbeans/core/startup/NbInstallerTest5.java Thu Jun 30 11:04:00 2011 +0200 @@ -50,6 +50,7 @@ import org.netbeans.Module; import org.netbeans.ModuleManager; import org.openide.filesystems.FileUtil; +import org.openide.util.Mutex.ExceptionAction; /** Test the NetBeans module installer implementation. * Broken into pieces to ensure each runs in its own VM. @@ -71,36 +72,37 @@ .lookup(org.openide.modules.ModuleInfo.class)); // TEMP final MockEvents ev = new MockEvents(); NbInstaller installer = new NbInstaller(ev); - ModuleManager mgr = new ModuleManager(installer, ev); + final ModuleManager mgr = new ModuleManager(installer, ev); installer.registerManager(mgr); - mgr.mutexPrivileged().enterWriteAccess(); - try { - Module m1 = mgr.create(new File(jars, "base-layer-mod.jar"), null, false, false, false); - Module m2 = mgr.create(new File(jars, "override-layer-mod.jar"), null, false, false, false); - - assertEquals(Collections.EMPTY_SET, m2.getProblems()); - assertEquals(null, slurp("foo/file1.txt")); - assertEquals(null, slurp("foo/file3.txt")); - assertEquals(null, slurp("foo/file4.txt")); - mgr.enable(m1); - assertEquals("base contents", slurp("foo/file1.txt")); - assertEquals("base contents", slurp("foo/file3.txt")); - assertEquals("base contents", slurp("foo/file4.txt")); - assertEquals("someval", FileUtil.getConfigFile("foo/file5.txt").getAttribute("myattr")); - mgr.enable(m2); - assertEquals("base contents", slurp("foo/file1.txt")); - assertEquals(null, slurp("foo/file4.txt")); - assertEquals("customized contents", slurp("foo/file3.txt")); - assertEquals("someotherval", FileUtil.getConfigFile("foo/file5.txt").getAttribute("myattr")); - mgr.disable(m2); - assertEquals("base contents", slurp("foo/file3.txt")); - mgr.disable(m1); - assertEquals(null, slurp("foo/file3.txt")); - mgr.delete(m2); - mgr.delete(m1); - } finally { - mgr.mutexPrivileged().exitWriteAccess(); - } + mgr.mutex().writeAccess(new ExceptionAction() { + @Override + public Void run() throws Exception { + Module m1 = mgr.create(new File(jars, "base-layer-mod.jar"), null, false, false, false); + Module m2 = mgr.create(new File(jars, "override-layer-mod.jar"), null, false, false, false); + + assertEquals(Collections.EMPTY_SET, m2.getProblems()); + assertEquals(null, slurp("foo/file1.txt")); + assertEquals(null, slurp("foo/file3.txt")); + assertEquals(null, slurp("foo/file4.txt")); + mgr.enable(m1); + assertEquals("base contents", slurp("foo/file1.txt")); + assertEquals("base contents", slurp("foo/file3.txt")); + assertEquals("base contents", slurp("foo/file4.txt")); + assertEquals("someval", FileUtil.getConfigFile("foo/file5.txt").getAttribute("myattr")); + mgr.enable(m2); + assertEquals("base contents", slurp("foo/file1.txt")); + assertEquals(null, slurp("foo/file4.txt")); + assertEquals("customized contents", slurp("foo/file3.txt")); + assertEquals("someotherval", FileUtil.getConfigFile("foo/file5.txt").getAttribute("myattr")); + mgr.disable(m2); + assertEquals("base contents", slurp("foo/file3.txt")); + mgr.disable(m1); + assertEquals(null, slurp("foo/file3.txt")); + mgr.delete(m2); + mgr.delete(m1); + return null; + } + }); } } diff -r d49cb1e754b2 core.startup/test/unit/src/org/netbeans/core/startup/NbInstallerTest8.java --- a/core.startup/test/unit/src/org/netbeans/core/startup/NbInstallerTest8.java Thu Jun 30 09:12:56 2011 +0200 +++ b/core.startup/test/unit/src/org/netbeans/core/startup/NbInstallerTest8.java Thu Jun 30 11:04:00 2011 +0200 @@ -53,6 +53,7 @@ import org.netbeans.ModuleManager; import junit.textui.TestRunner; import org.netbeans.junit.NbTestSuite; +import org.openide.util.Mutex.ExceptionAction; /** Test the NetBeans module installer implementation. * Broken into pieces to ensure each runs in its own VM. @@ -89,22 +90,23 @@ */ public void testEarlyModuleInfoLookup() throws Exception { // Ought to load these modules: - ModuleManager mgr = Main.getModuleSystem().getManager(); - mgr.mutexPrivileged().enterWriteAccess(); - try { - Module m = mgr.get("lookformyself"); - assertNull(m); - m = mgr.create(moduleJar, new ModuleHistory(moduleJar.getAbsolutePath()), false, false, false); - assertEquals("look-for-myself.jar can be enabled", Collections.EMPTY_SET, m.getProblems()); - mgr.enable(m); - Class c = m.getClassLoader().loadClass("lookformyself.Loder"); - Method meth = c.getMethod("foundNow"); - assertTrue("ModuleInfo is found after startup", (Boolean) meth.invoke(null)); - Field f = c.getField("foundEarly"); - assertTrue("ModuleInfo is found during dataloader section initialization", (Boolean) f.get(null)); - } finally { - mgr.mutexPrivileged().exitWriteAccess(); - } + final ModuleManager mgr = Main.getModuleSystem().getManager(); + mgr.mutex().writeAccess(new ExceptionAction() { + @Override + public Void run() throws Exception { + Module m = mgr.get("lookformyself"); + assertNull(m); + m = mgr.create(moduleJar, new ModuleHistory(moduleJar.getAbsolutePath()), false, false, false); + assertEquals("look-for-myself.jar can be enabled", Collections.EMPTY_SET, m.getProblems()); + mgr.enable(m); + Class c = m.getClassLoader().loadClass("lookformyself.Loder"); + Method meth = c.getMethod("foundNow"); + assertTrue("ModuleInfo is found after startup", (Boolean) meth.invoke(null)); + Field f = c.getField("foundEarly"); + assertTrue("ModuleInfo is found during dataloader section initialization", (Boolean) f.get(null)); + return null; + } + }); } } diff -r d49cb1e754b2 core.startup/test/unit/src/org/netbeans/core/startup/PlatformDependencySatisfiedTest.java --- a/core.startup/test/unit/src/org/netbeans/core/startup/PlatformDependencySatisfiedTest.java Thu Jun 30 09:12:56 2011 +0200 +++ b/core.startup/test/unit/src/org/netbeans/core/startup/PlatformDependencySatisfiedTest.java Thu Jun 30 11:04:00 2011 +0200 @@ -55,6 +55,7 @@ import java.util.jar.Manifest; import org.netbeans.Module; import org.netbeans.ModuleManager; +import org.openide.util.Mutex.ExceptionAction; import org.openide.util.Utilities; /** Checks whether a module with generated @@ -175,7 +176,7 @@ assertEnableModule("org.openide.modules.os.OS2", true); } - private void assertEnableModule(String req, boolean enable) throws Exception { + private void assertEnableModule(String req, final boolean enable) throws Exception { Manifest man = new Manifest (); man.getMainAttributes ().putValue ("Manifest-Version", "1.0"); man.getMainAttributes ().putValue ("OpenIDE-Module", "org.test.PlatformDependency/1"); @@ -189,23 +190,24 @@ final MockEvents ev = new MockEvents(); NbInstaller installer = new NbInstaller(ev); - ModuleManager mgr = new ModuleManager(installer, ev); + final ModuleManager mgr = new ModuleManager(installer, ev); ModuleFormatSatisfiedTest.addOpenideModules(mgr); installer.registerManager(mgr); - mgr.mutexPrivileged().enterWriteAccess(); - try { - Module m1 = mgr.create(moduleJarFile, null, false, false, false); - if (enable) { - assertEquals(Collections.EMPTY_SET, m1.getProblems()); - mgr.enable(m1); - mgr.disable(m1); - } else { - assertFalse("We should not be able to enable the module", m1.getProblems().isEmpty()); + mgr.mutex().writeAccess(new ExceptionAction() { + @Override + public Void run() throws Exception { + Module m1 = mgr.create(moduleJarFile, null, false, false, false); + if (enable) { + assertEquals(Collections.EMPTY_SET, m1.getProblems()); + mgr.enable(m1); + mgr.disable(m1); + } else { + assertFalse("We should not be able to enable the module", m1.getProblems().isEmpty()); + } + mgr.delete(m1); + return null; } - mgr.delete(m1); - } finally { - mgr.mutexPrivileged().exitWriteAccess(); - } + }); } } diff -r d49cb1e754b2 core.startup/test/unit/src/org/netbeans/core/startup/layers/SystemFileSystemTest.java --- a/core.startup/test/unit/src/org/netbeans/core/startup/layers/SystemFileSystemTest.java Thu Jun 30 09:12:56 2011 +0200 +++ b/core.startup/test/unit/src/org/netbeans/core/startup/layers/SystemFileSystemTest.java Thu Jun 30 11:04:00 2011 +0200 @@ -60,6 +60,7 @@ import org.netbeans.core.startup.MainLookup; import org.netbeans.SetupHid; import org.openide.filesystems.FileAttributeEvent; +import org.openide.filesystems.FileChangeAdapter; import org.openide.filesystems.FileChangeListener; import org.openide.filesystems.FileEvent; import org.openide.filesystems.FileObject; @@ -68,6 +69,7 @@ import org.openide.filesystems.FileUtil; import org.openide.modules.ModuleInfo; import org.openide.util.Lookup; +import org.openide.util.Mutex.ExceptionAction; import org.openide.util.lookup.InstanceContent; /** Test layering of filesystems installed via lookup. @@ -194,68 +196,96 @@ } public void testPreferenceOfLayersNowDynamicSystemsCanHideWhatComesFromLayers() throws Exception { - ModuleManager mgr = Main.getModuleSystem ().getManager(); - mgr.mutexPrivileged().enterWriteAccess(); - Module m1 = mgr.create(new File(jars, "base-layer-mod.jar"), null, false, false, false); - FileObject global; - try { - assertEquals(Collections.EMPTY_SET, m1.getProblems()); - mgr.enable(m1); - global = FileUtil.getConfigFile("foo/file2.txt"); - assertNotNull("File Object installed: " + global, global); - assertEquals("base contents", read(global)); - - FileObject fo1 = FileUtil.createData(fs1.getRoot(), global.getPath()); - fo1.setAttribute("one", 1); - write(fo1, "fileone"); + final ModuleManager mgr = Main.getModuleSystem ().getManager(); + final FileObject[] glob = { null }; + mgr.mutex().writeAccess(new ExceptionAction() { + @Override + public Void run() throws Exception { + Module m1 = mgr.create(new File(jars, "base-layer-mod.jar"), null, false, false, false); + FileObject global; + try { + assertEquals(Collections.EMPTY_SET, m1.getProblems()); + mgr.enable(m1); + global = FileUtil.getConfigFile("foo/file2.txt"); + glob[0] = global; + assertNotNull("File Object installed: " + global, global); + assertEquals("base contents", read(global)); - FileObject fo2 = FileUtil.createData(fs2.getRoot(), global.getPath()); - fo2.setAttribute("two", 2); - write(fo2, "two"); + FileObject fo1 = FileUtil.createData(fs1.getRoot(), global.getPath()); + fo1.setAttribute("one", 1); + write(fo1, "fileone"); - events.clear(); + FileObject fo2 = FileUtil.createData(fs2.getRoot(), global.getPath()); + fo2.setAttribute("two", 2); + write(fo2, "two"); - MainLookup.register(fs1, this); - MainLookup.register(fs2, this); - - Iterator it = Lookup.getDefault().lookupAll(FileSystem.class).iterator(); - assertTrue("At least One", it.hasNext()); - assertEquals("first is fs1", fs1, it.next()); - assertTrue("At least two ", it.hasNext()); - assertEquals("first is fs2", fs2, it.next()); - - assertEquals("fileone", read(global)); - } finally { - mgr.disable(m1); - mgr.delete(m1); - mgr.mutexPrivileged().exitWriteAccess(); - } - assertTrue("Still valid", global.isValid()); - assertEquals("fileone", read(global)); + events.clear(); + + MainLookup.register(fs1, SystemFileSystemTest.this); + MainLookup.register(fs2, SystemFileSystemTest.this); + + Iterator it = Lookup.getDefault().lookupAll(FileSystem.class).iterator(); + assertTrue("At least One", it.hasNext()); + assertEquals("first is fs1", fs1, it.next()); + assertTrue("At least two ", it.hasNext()); + assertEquals("first is fs2", fs2, it.next()); + + assertEquals("fileone", read(global)); + } finally { + mgr.disable(m1); + mgr.delete(m1); + } + return null; + } + }); + assertTrue("Still valid", glob[0].isValid()); + assertEquals("fileone", read(glob[0])); } public void testCanHideFilesFromModules() throws Exception { - ModuleManager mgr = Main.getModuleSystem ().getManager(); - mgr.mutexPrivileged().enterWriteAccess(); - Module m1 = mgr.create(new File(jars, "base-layer-mod.jar"), null, false, false, false); - try { - assertEquals(Collections.EMPTY_SET, m1.getProblems()); - mgr.enable(m1); - FileObject global = FileUtil.getConfigFile("foo/file2.txt"); - assertNotNull("File Object installed: " + global, global); - assertEquals("base contents", read(global)); - - FileObject fo1 = FileUtil.createData(fs1.getRoot(), global.getPath() + "_hidden"); + final ModuleManager mgr = Main.getModuleSystem ().getManager(); - events.clear(); - MainLookup.register(fs1, this); - assertNull("No longer findable", global.getFileSystem().findResource(global.getPath())); - assertFalse("Is not valid anymore", global.isValid()); - } finally { - mgr.disable(m1); - mgr.delete(m1); - mgr.mutexPrivileged().exitWriteAccess(); + class L extends FileChangeAdapter { + int cnt; + + @Override + public void fileDeleted(FileEvent fe) { + assertFalse("Don't hold mutex", mgr.mutex().isReadAccess()); + assertFalse("Don't hold write mutex", mgr.mutex().isWriteAccess()); + cnt++; + } + } + final L listener = new L(); + + mgr.mutex().writeAccess(new ExceptionAction() { + @Override + public Exception run() throws Exception { + Module m1 = mgr.create(new File(jars, "base-layer-mod.jar"), null, false, false, false); + try { + assertEquals(Collections.EMPTY_SET, m1.getProblems()); + mgr.enable(m1); + FileObject global = FileUtil.getConfigFile("foo/file2.txt"); + assertNotNull("File Object installed: " + global, global); + assertEquals("base contents", read(global)); + global.getParent().addFileChangeListener(listener); + + FileObject fo1 = FileUtil.createData(fs1.getRoot(), global.getPath() + "_hidden"); + + events.clear(); + MainLookup.register(fs1, SystemFileSystemTest.this); + + assertNull("No longer findable", global.getFileSystem().findResource(global.getPath())); + assertFalse("Is not valid anymore", global.isValid()); + } finally { + mgr.disable(m1); + mgr.delete(m1); + } + return null; + } + }); + if (listener.cnt == 0) { + fail("File change should have been notified: " + listener.cnt); } } diff -r d49cb1e754b2 o.n.bootstrap/manifest.mf --- a/o.n.bootstrap/manifest.mf Thu Jun 30 09:12:56 2011 +0200 +++ b/o.n.bootstrap/manifest.mf Thu Jun 30 11:04:00 2011 +0200 @@ -1,6 +1,6 @@ Manifest-Version: 1.0 OpenIDE-Module: org.netbeans.bootstrap/1 -OpenIDE-Module-Specification-Version: 2.41 +OpenIDE-Module-Specification-Version: 2.42 OpenIDE-Module-Localizing-Bundle: org/netbeans/Bundle.properties OpenIDE-Module-Recommends: org.netbeans.NetigsoFramework diff -r d49cb1e754b2 o.n.bootstrap/src/org/netbeans/ModuleInstaller.java --- a/o.n.bootstrap/src/org/netbeans/ModuleInstaller.java Thu Jun 30 09:12:56 2011 +0200 +++ b/o.n.bootstrap/src/org/netbeans/ModuleInstaller.java Thu Jun 30 11:04:00 2011 +0200 @@ -48,6 +48,7 @@ import java.io.IOException; import java.util.List; import java.util.Set; +import java.util.concurrent.Executor; import java.util.jar.JarFile; import java.util.jar.Manifest; import org.openide.modules.Dependency; @@ -224,4 +225,14 @@ return null; } + /** Executor to wrap operations in {@link ModuleManager#mutex()} to. + * Created to delay events about changes in filesystem until all other + * attributes of enabled/disabled modules are ready. + * + * @return by default null + * @since 2.42 + */ + protected Executor executor() { + return null; + } } diff -r d49cb1e754b2 o.n.bootstrap/src/org/netbeans/ModuleManager.java --- a/o.n.bootstrap/src/org/netbeans/ModuleManager.java Thu Jun 30 09:12:56 2011 +0200 +++ b/o.n.bootstrap/src/org/netbeans/ModuleManager.java Thu Jun 30 11:04:00 2011 +0200 @@ -69,6 +69,7 @@ import java.util.Set; import java.util.StringTokenizer; import java.util.TreeSet; +import java.util.concurrent.Executor; import java.util.jar.Manifest; import java.util.logging.Level; import org.openide.LifecycleManager; @@ -128,6 +129,10 @@ */ public ModuleManager(ModuleInstaller installer, Events ev) { this.installer = installer; + final Executor executor = installer.executor(); + this.MUTEX = executor != null ? + new Mutex(MUTEX_PRIVILEGED, executor) : + new Mutex(MUTEX_PRIVILEGED); this.ev = ev; String patches = System.getProperty("netbeans.systemclassloader.patches"); if (patches != null) { @@ -171,7 +176,8 @@ } private final Mutex.Privileged MUTEX_PRIVILEGED = new Mutex.Privileged(); - private final Mutex MUTEX = new Mutex(MUTEX_PRIVILEGED); + private final Mutex MUTEX; + /** Get a locking mutex for this module installer. * All calls other than adding or removing property change * listeners, or getting the module lookup, called on this @@ -196,9 +202,8 @@ return MUTEX; } /** Classes in this package can, if careful, use the privileged form. - * @since JST-PENDING this had to be made public as the package is now split in two */ - public final Mutex.Privileged mutexPrivileged() { + final Mutex.Privileged mutexPrivileged() { return MUTEX_PRIVILEGED; } // [PENDING] with improved API for Mutex, could throw