diff --git a/core.netigso/apichanges.xml b/core.netigso/apichanges.xml --- a/core.netigso/apichanges.xml +++ b/core.netigso/apichanges.xml @@ -49,8 +49,25 @@ Netigso Integration SPI + OSGi Related Behavior + + + Friend API is no longer accessible + + + + + In previous version OSGi bundles could access NetBeans APIs which + enumerated list of "friends" without any restrictions. This has been + restricted. If you need a friend access, consider writing real + NetBeans module. + + + Only NetBeans modules with public API can be accessed from OSGi bundles. + + Netigso grants access to archives diff --git a/core.netigso/manifest.mf b/core.netigso/manifest.mf --- a/core.netigso/manifest.mf +++ b/core.netigso/manifest.mf @@ -2,7 +2,7 @@ OpenIDE-Module: org.netbeans.core.netigso OpenIDE-Module-Localizing-Bundle: org/netbeans/core/netigso/Bundle.properties OpenIDE-Module-Provides: org.netbeans.NetigsoFramework -OpenIDE-Module-Specification-Version: 1.10 +OpenIDE-Module-Specification-Version: 1.11 OpenIDE-Module-Needs: org.osgi.framework.launch.FrameworkFactory AutoUpdate-Essential-Module: true diff --git a/core.netigso/nbproject/project.xml b/core.netigso/nbproject/project.xml --- a/core.netigso/nbproject/project.xml +++ b/core.netigso/nbproject/project.xml @@ -55,7 +55,7 @@ 1 - 2.37 + 2.41 diff --git a/core.netigso/src/org/netbeans/core/netigso/Netigso.java b/core.netigso/src/org/netbeans/core/netigso/Netigso.java --- a/core.netigso/src/org/netbeans/core/netigso/Netigso.java +++ b/core.netigso/src/org/netbeans/core/netigso/Netigso.java @@ -268,6 +268,9 @@ try { LOG.log(Level.FINE, "Starting bundle {0}", m.getCodeNameBase()); b.start(); + if (b.getState() == Bundle.INSTALLED && isRealBundle(b)) { + throw new IOException("Cannot start " + m.getCodeName() + " state remains INSTALLED after start()"); // NOI18N + } } catch (BundleException possible) { if (isRealBundle(b)) { throw possible; @@ -424,7 +427,7 @@ */ private static InputStream fakeBundle(ModuleInfo m) throws IOException { String exp = (String) m.getAttribute("OpenIDE-Module-Public-Packages"); // NOI18N - if ("-".equals(exp)) { // NOI18N + if ("-".equals(exp) || m.getAttribute("OpenIDE-Module-Friends") != null) { // NOI18N return null; } ByteArrayOutputStream os = new ByteArrayOutputStream(); diff --git a/core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoOSGiCanDependTest.java b/core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoOSGiIsNotFriendTest.java copy from core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoOSGiCanDependTest.java copy to core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoOSGiIsNotFriendTest.java --- a/core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoOSGiCanDependTest.java +++ b/core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoOSGiIsNotFriendTest.java @@ -45,50 +45,45 @@ import java.io.File; import java.util.Arrays; import java.util.HashSet; -import org.netbeans.MockEvents; -import org.netbeans.MockModuleInstaller; -import org.netbeans.Module; -import org.netbeans.ModuleManager; +import org.netbeans.*; -/** - * - * @author Jaroslav Tulach - */ -public class NetigsoOSGiCanDependTest extends NetigsoHid { - public NetigsoOSGiCanDependTest(String name) { +public class NetigsoOSGiIsNotFriendTest extends NetigsoHid { + public NetigsoOSGiIsNotFriendTest(String name) { super(name); } - public void testOSGiCanDependOnNetBeans() throws Exception { + public void testOSGiBundleAreNotImplicitFriendsOfNetBeansModules() 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" + + "Require-Bundle: org.foo\n" + "\n\n"; - File j1 = new File(jars, "simple-module.jar"); + String mfSimple = "OpenIDE-Module: org.foo/1\n" + + "OpenIDE-Module-Specification-Version: 1.2\n" + + "OpenIDE-Module-Public-Packages: org.foo.*\n" + + "OpenIDE-Module-Friends: few.unknown\n" + + "\n\n"; + + + File j1 = changeManifest(new File(jars, "simple-module.jar"), mfSimple); 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"); - - assertEquals("Correct parent is used", sprclass, clazz.getSuperclass()); + try { + mgr.enable(b); + fail("InvalidException should be raised!"); + } catch (InvalidException ex) { + // OK + } + assertFalse("We should not be able to enable org.bar bundle!", m2.isEnabled()); } finally { - if (both != null) { - mgr.disable(both); - } mgr.mutexPrivileged().exitWriteAccess(); } } diff --git a/core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoSelfQueryTest.java b/core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoSelfQueryTest.java --- a/core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoSelfQueryTest.java +++ b/core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoSelfQueryTest.java @@ -453,6 +453,7 @@ private final String url; private final MockFramework f; private final NetigsoArchive archive; + private transient int state = Bundle.INSTALLED; public MockBundle(String url, MockFramework f) { this.url = url; @@ -464,7 +465,7 @@ @Override public int getState() { - throw new UnsupportedOperationException("Not supported yet."); + return state; } @Override @@ -474,6 +475,7 @@ @Override public void start() throws BundleException { + state = Bundle.ACTIVE; } @Override diff --git a/core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoOSGiCanDependTest.java b/netbinox/test/unit/src/org/netbeans/modules/netbinox/NetigsoOSGiIsNotFriendTest.java copy from core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoOSGiCanDependTest.java copy to netbinox/test/unit/src/org/netbeans/modules/netbinox/NetigsoOSGiIsNotFriendTest.java --- a/core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoOSGiCanDependTest.java +++ b/netbinox/test/unit/src/org/netbeans/modules/netbinox/NetigsoOSGiIsNotFriendTest.java @@ -40,55 +40,50 @@ * Portions Copyrighted 2009 Sun Microsystems, Inc. */ -package org.netbeans.core.netigso; +package org.netbeans.modules.netbinox; import java.io.File; import java.util.Arrays; import java.util.HashSet; -import org.netbeans.MockEvents; -import org.netbeans.MockModuleInstaller; -import org.netbeans.Module; -import org.netbeans.ModuleManager; +import org.netbeans.*; -/** - * - * @author Jaroslav Tulach - */ -public class NetigsoOSGiCanDependTest extends NetigsoHid { - public NetigsoOSGiCanDependTest(String name) { +public class NetigsoOSGiIsNotFriendTest extends NetigsoHid { + public NetigsoOSGiIsNotFriendTest(String name) { super(name); } - public void testOSGiCanDependOnNetBeans() throws Exception { + public void testOSGiBundleAreNotImplicitFriendsOfNetBeansModules() 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" + + "Require-Bundle: org.foo\n" + "\n\n"; - File j1 = new File(jars, "simple-module.jar"); + String mfSimple = "OpenIDE-Module: org.foo/1\n" + + "OpenIDE-Module-Specification-Version: 1.2\n" + + "OpenIDE-Module-Public-Packages: org.foo.*\n" + + "OpenIDE-Module-Friends: few.unknown\n" + + "\n\n"; + + + File j1 = changeManifest(new File(jars, "simple-module.jar"), mfSimple); 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"); - - assertEquals("Correct parent is used", sprclass, clazz.getSuperclass()); + try { + mgr.enable(b); + fail("InvalidException should be raised!"); + } catch (InvalidException ex) { + // OK + } + assertFalse("We should not be able to enable org.bar bundle!", m2.isEnabled()); } finally { - if (both != null) { - mgr.disable(both); - } mgr.mutexPrivileged().exitWriteAccess(); } } diff --git a/o.n.bootstrap/manifest.mf b/o.n.bootstrap/manifest.mf --- a/o.n.bootstrap/manifest.mf +++ b/o.n.bootstrap/manifest.mf @@ -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 --git a/o.n.bootstrap/src/org/netbeans/NetigsoFramework.java b/o.n.bootstrap/src/org/netbeans/NetigsoFramework.java --- a/o.n.bootstrap/src/org/netbeans/NetigsoFramework.java +++ b/o.n.bootstrap/src/org/netbeans/NetigsoFramework.java @@ -51,7 +51,6 @@ import java.util.List; import java.util.Set; import org.openide.modules.ModuleInfo; -import org.openide.util.Exceptions; import org.openide.util.Lookup; import org.openide.util.lookup.Lookups; @@ -151,7 +150,7 @@ toEnable.addAll(newlyEnabling); } - static Set turnOn(ClassLoader findNetigsoFrameworkIn, Collection allModules) { + static Set turnOn(ClassLoader findNetigsoFrameworkIn, Collection allModules) throws InvalidException { boolean found = false; if (framework == null) { for (Module m : toEnable) { @@ -189,7 +188,7 @@ return additional; } - private static boolean delayedInit() { + private static boolean delayedInit() throws InvalidException { List init; synchronized (NetigsoFramework.class) { init = toInit; @@ -198,13 +197,24 @@ return true; } } + InvalidException thrw = null; for (NetigsoModule nm : init) { try { nm.start(); } catch (IOException ex) { - Exceptions.printStackTrace(ex); + nm.setEnabled(false); + InvalidException invalid = new InvalidException(nm, ex.getMessage()); + if (thrw == null) { + invalid.initCause(ex); + } else { + invalid.initCause(thrw); + } + thrw = invalid; } } + if (thrw != null) { + throw thrw; + } return false; }