diff -r 0ce49db65c29 core.netigso/apichanges.xml --- a/core.netigso/apichanges.xml Wed Sep 14 17:25:58 2011 +0200 +++ b/core.netigso/apichanges.xml Wed Sep 14 22:32:38 2011 +0200 @@ -49,8 +49,28 @@ 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. + One can specify direct value for + Netigso-Export-Package + to export also non-public APIs. + + Netigso grants access to archives diff -r 0ce49db65c29 core.netigso/arch.xml --- a/core.netigso/arch.xml Wed Sep 14 17:25:58 2011 +0200 +++ b/core.netigso/arch.xml Wed Sep 14 22:32:38 2011 +0200 @@ -620,7 +620,11 @@ -->

- XXX no answer for exec-property + + If a NetBeans module's manifest contains tag Netigso-Export-Package, + then it is used as a value of Export-Package OSGi tag, when + re-exporting the module as OSGi bundle. +

diff -r 0ce49db65c29 core.netigso/manifest.mf --- a/core.netigso/manifest.mf Wed Sep 14 17:25:58 2011 +0200 +++ b/core.netigso/manifest.mf Wed Sep 14 22:32:38 2011 +0200 @@ -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 -r 0ce49db65c29 core.netigso/nbproject/project.xml --- a/core.netigso/nbproject/project.xml Wed Sep 14 17:25:58 2011 +0200 +++ b/core.netigso/nbproject/project.xml Wed Sep 14 22:32:38 2011 +0200 @@ -55,7 +55,7 @@ 1 - 2.37 + 2.41 diff -r 0ce49db65c29 core.netigso/src/org/netbeans/core/netigso/Netigso.java --- a/core.netigso/src/org/netbeans/core/netigso/Netigso.java Wed Sep 14 17:25:58 2011 +0200 +++ b/core.netigso/src/org/netbeans/core/netigso/Netigso.java Wed Sep 14 22:32:38 2011 +0200 @@ -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; @@ -423,9 +426,12 @@ * make sense to represent this module as bundle */ private static InputStream fakeBundle(ModuleInfo m) throws IOException { + String netigsoExp = (String) m.getAttribute("Netigso-Export-Package"); // NOI18N String exp = (String) m.getAttribute("OpenIDE-Module-Public-Packages"); // NOI18N - if ("-".equals(exp)) { // NOI18N - return null; + if (netigsoExp == null) { + if ("-".equals(exp) || m.getAttribute("OpenIDE-Module-Friends") != null) { // NOI18N + return null; + } } ByteArrayOutputStream os = new ByteArrayOutputStream(); Manifest man = new Manifest(); @@ -437,7 +443,9 @@ String spec = threeDotsWithMajor(m.getSpecificationVersion().toString(), m.getCodeName()); man.getMainAttributes().putValue("Bundle-Version", spec.toString()); // NOI18N } - if (exp != null) { + if (netigsoExp != null) { + man.getMainAttributes().putValue("Export-Package", netigsoExp); // NOI18N + } else if (exp != null) { man.getMainAttributes().putValue("Export-Package", exp.replaceAll("\\.\\*", "")); // NOI18N } else { man.getMainAttributes().putValue("Export-Package", m.getCodeNameBase()); // NOI18N diff -r 0ce49db65c29 core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoExportPackageTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoExportPackageTest.java Wed Sep 14 22:32:38 2011 +0200 @@ -0,0 +1,97 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2011 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2011 Sun Microsystems, Inc. + */ +package org.netbeans.core.netigso; + +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; + +public class NetigsoExportPackageTest extends NetigsoHid { + + public NetigsoExportPackageTest(String name) { + super(name); + } + + + public void testNetigsoExportPackage() throws Exception { + MockModuleInstaller installer = new MockModuleInstaller(); + MockEvents ev = new MockEvents(); + ModuleManager mgr = new ModuleManager(installer, ev); + mgr.mutexPrivileged().enterWriteAccess(); + HashSet b = null; + boolean ok = false; + 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"; + + String mfSimple = "OpenIDE-Module: org.foo/1\n" + + "OpenIDE-Module-Specification-Version: 1.2\n" + + "OpenIDE-Module-Public-Packages: org.wrong.foo.*\n" + + "OpenIDE-Module-Friends: few.unknown\n" + + "Netigso-Export-Package: org.foo\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); + b = new HashSet(Arrays.asList(m1, m2)); + mgr.enable(b); + ok = true; + assertTrue("Enabled OK", m2.isEnabled()); + } finally { + if (ok) { + mgr.disable(b); + } + mgr.mutexPrivileged().exitWriteAccess(); + } + } + +} diff -r 0ce49db65c29 core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoOSGiIsNotFriendTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoOSGiIsNotFriendTest.java Wed Sep 14 22:32:38 2011 +0200 @@ -0,0 +1,90 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2010 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2009 Sun Microsystems, Inc. + */ + +package org.netbeans.core.netigso; + +import java.io.File; +import java.util.Arrays; +import java.util.HashSet; +import org.netbeans.*; + +public class NetigsoOSGiIsNotFriendTest extends NetigsoHid { + public NetigsoOSGiIsNotFriendTest(String name) { + super(name); + } + + public void testOSGiBundleAreNotImplicitFriendsOfNetBeansModules() throws Exception { + MockModuleInstaller installer = new MockModuleInstaller(); + MockEvents ev = new MockEvents(); + ModuleManager mgr = new ModuleManager(installer, ev); + mgr.mutexPrivileged().enterWriteAccess(); + try { + String mfBar = "Bundle-SymbolicName: org.bar\n" + + "Bundle-Version: 1.1.0\n" + + "Bundle-ManifestVersion: 2\n" + + "Require-Bundle: org.foo\n" + + "\n\n"; + + 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)); + 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 { + mgr.mutexPrivileged().exitWriteAccess(); + } + } +} diff -r 0ce49db65c29 core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoSelfQueryTest.java --- a/core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoSelfQueryTest.java Wed Sep 14 17:25:58 2011 +0200 +++ b/core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoSelfQueryTest.java Wed Sep 14 22:32:38 2011 +0200 @@ -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 -r 0ce49db65c29 netbinox/test/unit/src/org/netbeans/modules/netbinox/NetigsoOSGiIsNotFriendTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/netbinox/test/unit/src/org/netbeans/modules/netbinox/NetigsoOSGiIsNotFriendTest.java Wed Sep 14 22:32:38 2011 +0200 @@ -0,0 +1,91 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2010 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2009 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.netbinox; + +import java.io.File; +import java.util.Arrays; +import java.util.HashSet; +import org.netbeans.*; + +public class NetigsoOSGiIsNotFriendTest extends NetigsoHid { + public NetigsoOSGiIsNotFriendTest(String name) { + super(name); + } + + public void testOSGiBundleAreNotImplicitFriendsOfNetBeansModules() throws Exception { + MockModuleInstaller installer = new MockModuleInstaller(); + MockEvents ev = new MockEvents(); + ModuleManager mgr = new ModuleManager(installer, ev); + mgr.mutexPrivileged().enterWriteAccess(); + try { + String mfBar = "Bundle-SymbolicName: org.bar\n" + + "Bundle-Version: 1.1.0\n" + + "Bundle-ManifestVersion: 2\n" + + "Require-Bundle: org.foo\n" + + "\n\n"; + + 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)); + 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 { + mgr.mutexPrivileged().exitWriteAccess(); + } + } + +} diff -r 0ce49db65c29 o.n.bootstrap/manifest.mf --- a/o.n.bootstrap/manifest.mf Wed Sep 14 17:25:58 2011 +0200 +++ b/o.n.bootstrap/manifest.mf Wed Sep 14 22:32:38 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 0ce49db65c29 o.n.bootstrap/src/org/netbeans/NetigsoFramework.java --- a/o.n.bootstrap/src/org/netbeans/NetigsoFramework.java Wed Sep 14 17:25:58 2011 +0200 +++ b/o.n.bootstrap/src/org/netbeans/NetigsoFramework.java Wed Sep 14 22:32:38 2011 +0200 @@ -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; }