diff -r 84950ad0c9bb core.netigso/apichanges.xml --- a/core.netigso/apichanges.xml Thu Jun 13 12:55:30 2013 +0200 +++ b/core.netigso/apichanges.xml Thu Jun 13 16:29:38 2013 +0200 @@ -52,6 +52,19 @@ OSGi Related Behavior + + + FIND_COVERED_PKGS new value: exportedIfPresent + + + + + + + FIND_COVERED_PKGS supports new value: exportedIfPresent. + + + Use -J-D to influence configuration of Felix diff -r 84950ad0c9bb core.netigso/arch.xml --- a/core.netigso/arch.xml Thu Jun 13 12:55:30 2013 +0200 +++ b/core.netigso/arch.xml Thu Jun 13 16:29:38 2013 +0200 @@ -672,10 +672,14 @@ The FIND_COVERED_PKGS branding key defines method to find list of covered packages - for an OSGi bundle. Currently it can be empty or findEntries, which + for an OSGi bundle. Currently it can be empty or findEntries, which means Netigso will use bundle.findEntries("", null, true). As that method resolves the bundle, it may not always be appropriate. In such case brand this token to empty string and only "Export-Package" values will be used. + Since version 1.23 there is also a chance to set the token to exportedIfPresent + which will use the value of "Export-Package" tag when it is present, but + when there is none, bundle.findEntries("", null, true) will be + used. System.getProperties() that start with prefix felix. diff -r 84950ad0c9bb core.netigso/manifest.mf --- a/core.netigso/manifest.mf Thu Jun 13 12:55:30 2013 +0200 +++ b/core.netigso/manifest.mf Thu Jun 13 16:29:38 2013 +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.22 +OpenIDE-Module-Specification-Version: 1.23 OpenIDE-Module-Needs: org.osgi.framework.launch.FrameworkFactory AutoUpdate-Essential-Module: true diff -r 84950ad0c9bb core.netigso/src/org/netbeans/core/netigso/Netigso.java --- a/core.netigso/src/org/netbeans/core/netigso/Netigso.java Thu Jun 13 12:55:30 2013 +0200 +++ b/core.netigso/src/org/netbeans/core/netigso/Netigso.java Thu Jun 13 16:29:38 2013 +0200 @@ -277,10 +277,11 @@ ClassLoader l = new NetigsoLoader(b, m, jar); Set pkgs = new HashSet(); String[] knownPkgs = registered.get(m.getCodeNameBase()); + Object exported = b.getHeaders("").get("Export-Package"); if (knownPkgs == EMPTY) { try { SELF_QUERY.set(true); - if (findCoveredPkgs()) { + if (findCoveredPkgs(exported)) { Enumeration en = b.findEntries("", null, true); if (en == null) { LOG.log(Level.INFO, "Bundle {0}: {1} is empty", new Object[] { b.getBundleId(), b.getSymbolicName() }); @@ -295,7 +296,6 @@ } } } - Object exported = b.getHeaders("").get("Export-Package"); if (exported instanceof String) { for (String p : exported.toString().split(",")) { // NOI18N int semic = p.indexOf(';'); @@ -325,7 +325,7 @@ LOG.log(Level.FINE, "Starting bundle {0}: {1}", new Object[] { m.getCodeNameBase(), start }); if (start) { b.start(); - if (findCoveredPkgs() && !isResolved(b) && isRealBundle(b)) { + if (findCoveredPkgs(exported) && !isResolved(b) && isRealBundle(b)) { throw new IOException("Cannot start " + m.getCodeName() + " state remains INSTALLED after start()"); // NOI18N } } @@ -704,10 +704,14 @@ } @Messages({"#NOI18N", "FIND_COVERED_PKGS=findEntries"}) - private boolean findCoveredPkgs() { + private boolean findCoveredPkgs(Object exportedPackages) { if (defaultCoveredPkgs == null) { defaultCoveredPkgs = FIND_COVERED_PKGS(); } + if ("exportedIfPresent".equals(defaultCoveredPkgs)) { // NOI18N + return exportedPackages == null; + } + return "findEntries".equals(defaultCoveredPkgs); // NOI18N } diff -r 84950ad0c9bb core.netigso/test/unit/src/org/netbeans/core/netigso/Bundle_def_EX.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core.netigso/test/unit/src/org/netbeans/core/netigso/Bundle_def_EX.properties Thu Jun 13 16:29:38 2013 +0200 @@ -0,0 +1,42 @@ +# 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. + +# NOI18N +FIND_COVERED_PKGS=exportedIfPresent diff -r 84950ad0c9bb core.netigso/test/unit/src/org/netbeans/core/netigso/ExportedIfPresentTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core.netigso/test/unit/src/org/netbeans/core/netigso/ExportedIfPresentTest.java Thu Jun 13 16:29:38 2013 +0200 @@ -0,0 +1,166 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-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]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2008 Sun + * Microsystems, Inc. All Rights Reserved. + * + * 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. + */ + +package org.netbeans.core.netigso; + +import org.netbeans.core.startup.*; +import java.io.File; +import java.io.IOException; +import java.util.Collections; +import java.util.Locale; +import org.netbeans.Module; +import org.netbeans.ModuleManager; +import org.netbeans.SetupHid; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; +import org.osgi.framework.Bundle; + +/** + * How does OSGi integration deals with layer registration? Can we read + * it without resolving the bundle? + * + * @author Jaroslav Tulach + */ +public class ExportedIfPresentTest extends SetupHid { + private static Module m1; + private static ModuleManager mgr; + + public ExportedIfPresentTest(String name) { + super(name); + } + + protected @Override void setUp() throws Exception { + // changes minimal start level to 10 + Locale.setDefault(new Locale("def", "EX")); + clearWorkDir(); + + + data = new File(getDataDir(), "jars"); + jars = new File(getWorkDir(), "jars"); + jars.mkdirs(); + File simpleModule = createTestJAR("simple-module", null); + File dependsOnSimpleModule = createTestJAR("depends-on-simple-module", null, simpleModule); + + if (System.getProperty("netbeans.user") == null) { + File ud = new File(getWorkDir(), "ud"); + ud.mkdirs(); + + System.setProperty("netbeans.user", ud.getPath()); + + + ModuleSystem ms = Main.getModuleSystem(); + mgr = ms.getManager(); + mgr.mutexPrivileged().enterWriteAccess(); + try { + m1 = mgr.create(simpleModule, null, false, false, false); + mgr.enable(Collections.singleton(m1)); + } finally { + mgr.mutexPrivileged().exitWriteAccess(); + } + } + + } + private File createTestJAR(String name, String srcdir, File... classpath) throws IOException { + return createTestJAR(data, jars, name, srcdir, classpath); + } + public void testCanLoadClassFromContextClassLoaderAsNoExportPackageAvailable() throws Exception { + FileObject fo; + Module m2; + try { + mgr.mutexPrivileged().enterWriteAccess(); + 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); + m2 = mgr.create(j2, null, false, false, false); + mgr.enable(m2); + } finally { + mgr.mutexPrivileged().exitWriteAccess(); + } + try { + mgr.mutexPrivileged().enterWriteAccess(); + Class c = mgr.getClassLoader().loadClass("org.bar.SomethingElse"); + assertNotNull("Can load the class successfully", c); + } finally { + mgr.disable(m2); + mgr.mutexPrivileged().exitWriteAccess(); + } + } + public void testCannotLoadClassFromContextClassLoaderWhenSomeExportPackageIsAvailable() throws Exception { + FileObject fo; + Module m2; + try { + mgr.mutexPrivileged().enterWriteAccess(); + String mfBar = "Bundle-SymbolicName: org.bar2\n" + + "Bundle-Version: 1.1.0\n" + + "Bundle-ManifestVersion: 2\n" + + "Import-Package: org.foo\n" + + "Export-Package: org.foo\n" + + "\n\n"; + + File j2 = changeManifest(new File(jars, "depends-on-simple-module.jar"), mfBar); + m2 = mgr.create(j2, null, false, false, false); + mgr.enable(m2); + } finally { + mgr.mutexPrivileged().exitWriteAccess(); + } + try { + mgr.mutexPrivileged().enterWriteAccess(); + try { + Class c = mgr.getClassLoader().loadClass("org.bar.SomethingElse"); + fail("The class should not have been found: " + c); + } catch (ClassNotFoundException ex) { + assertTrue(ex.getMessage(), ex.getMessage().contains("SomethingElse")); + } + } finally { + mgr.disable(m2); + mgr.mutexPrivileged().exitWriteAccess(); + } + } + +}