This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 231223
Collapse All | Expand All

(-)a/core.netigso/apichanges.xml (+13 lines)
Lines 52-57 Link Here
52
    <apidef name="general">OSGi Related Behavior</apidef>
52
    <apidef name="general">OSGi Related Behavior</apidef>
53
</apidefs>
53
</apidefs>
54
<changes>
54
<changes>
55
    <change id="findpkgs.exported.if.present">
56
      <api name="general"/>
57
      <summary>FIND_COVERED_PKGS new value: exportedIfPresent</summary>
58
      <version major="1" minor="23"/>
59
      <date day="20" month="6" year="2013"/>
60
      <author login="jtulach"/>
61
      <compatibility addition="yes" binary="compatible" source="compatible" semantic="compatible"/>
62
      <description>
63
          <a href="@TOP@architecture-summary.html#branding-org.netbeans.core.netigso.FIND_COVERED_PKGS">
64
              FIND_COVERED_PKGS</a> supports new value: <b>exportedIfPresent</b>.
65
     </description>
66
     <issue number="218022"/>
67
    </change>
55
    <change id="inject.system.properties">
68
    <change id="inject.system.properties">
56
      <api name="spi"/>
69
      <api name="spi"/>
57
      <summary>Use -J-D to influence configuration of Felix</summary>
70
      <summary>Use -J-D to influence configuration of Felix</summary>
(-)a/core.netigso/arch.xml (-1 / +5 lines)
Lines 672-681 Link Here
672
   <api category="devel" group="branding" name="org.netbeans.core.netigso.FIND_COVERED_PKGS"
672
   <api category="devel" group="branding" name="org.netbeans.core.netigso.FIND_COVERED_PKGS"
673
   type="export">
673
   type="export">
674
   The <b>FIND_COVERED_PKGS</b> branding key defines method to find list of covered packages
674
   The <b>FIND_COVERED_PKGS</b> branding key defines method to find list of covered packages
675
   for an OSGi bundle. Currently it can be empty or <code>findEntries</code>, which
675
   for an OSGi bundle. Currently it can be empty or <b>findEntries</b>, which
676
   means Netigso will use <code>bundle.findEntries("", null, true)</code>. As that method
676
   means Netigso will use <code>bundle.findEntries("", null, true)</code>. As that method
677
   resolves the bundle, it may not always be appropriate. In such case brand
677
   resolves the bundle, it may not always be appropriate. In such case brand
678
   this token to empty string and only "Export-Package" values will be used.
678
   this token to empty string and only "Export-Package" values will be used.
679
   Since version 1.23 there is also a chance to set the token to <b>exportedIfPresent</b>
680
   which will use the value of "Export-Package" tag when it is present, but
681
   when there is none, <code>bundle.findEntries("", null, true)</code> will be 
682
   used.
679
   </api>
683
   </api>
680
   <api category="devel" group="systemproperty" name="felix_org.osgi.framework" type="export">
684
   <api category="devel" group="systemproperty" name="felix_org.osgi.framework" type="export">
681
       <code>System.getProperties()</code> that start with prefix <code>felix.</code>
685
       <code>System.getProperties()</code> that start with prefix <code>felix.</code>
(-)a/core.netigso/manifest.mf (-1 / +1 lines)
Lines 2-8 Link Here
2
OpenIDE-Module: org.netbeans.core.netigso
2
OpenIDE-Module: org.netbeans.core.netigso
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/core/netigso/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/core/netigso/Bundle.properties
4
OpenIDE-Module-Provides: org.netbeans.NetigsoFramework
4
OpenIDE-Module-Provides: org.netbeans.NetigsoFramework
5
OpenIDE-Module-Specification-Version: 1.22
5
OpenIDE-Module-Specification-Version: 1.23
6
OpenIDE-Module-Needs: org.osgi.framework.launch.FrameworkFactory
6
OpenIDE-Module-Needs: org.osgi.framework.launch.FrameworkFactory
7
AutoUpdate-Essential-Module: true
7
AutoUpdate-Essential-Module: true
8
8
(-)a/core.netigso/src/org/netbeans/core/netigso/Netigso.java (-4 / +8 lines)
Lines 277-286 Link Here
277
            ClassLoader l = new NetigsoLoader(b, m, jar);
277
            ClassLoader l = new NetigsoLoader(b, m, jar);
278
            Set<String> pkgs = new HashSet<String>();
278
            Set<String> pkgs = new HashSet<String>();
279
            String[] knownPkgs = registered.get(m.getCodeNameBase());
279
            String[] knownPkgs = registered.get(m.getCodeNameBase());
280
            Object exported = b.getHeaders("").get("Export-Package");
280
            if (knownPkgs == EMPTY) {
281
            if (knownPkgs == EMPTY) {
281
                try {
282
                try {
282
                    SELF_QUERY.set(true);
283
                    SELF_QUERY.set(true);
283
                    if (findCoveredPkgs()) {
284
                    if (findCoveredPkgs(exported)) {
284
                        Enumeration en = b.findEntries("", null, true);
285
                        Enumeration en = b.findEntries("", null, true);
285
                        if (en == null) {
286
                        if (en == null) {
286
                            LOG.log(Level.INFO, "Bundle {0}: {1} is empty", new Object[] { b.getBundleId(), b.getSymbolicName() });
287
                            LOG.log(Level.INFO, "Bundle {0}: {1} is empty", new Object[] { b.getBundleId(), b.getSymbolicName() });
Lines 295-301 Link Here
295
                            }
296
                            }
296
                        }
297
                        }
297
                    }
298
                    }
298
                    Object exported = b.getHeaders("").get("Export-Package");
299
                    if (exported instanceof String) {
299
                    if (exported instanceof String) {
300
                        for (String p : exported.toString().split(",")) { // NOI18N
300
                        for (String p : exported.toString().split(",")) { // NOI18N
301
                            int semic = p.indexOf(';');
301
                            int semic = p.indexOf(';');
Lines 325-331 Link Here
325
                LOG.log(Level.FINE, "Starting bundle {0}: {1}", new Object[] { m.getCodeNameBase(), start });
325
                LOG.log(Level.FINE, "Starting bundle {0}: {1}", new Object[] { m.getCodeNameBase(), start });
326
                if (start) {
326
                if (start) {
327
                    b.start();
327
                    b.start();
328
                    if (findCoveredPkgs() && !isResolved(b) && isRealBundle(b)) {
328
                    if (findCoveredPkgs(exported) && !isResolved(b) && isRealBundle(b)) {
329
                        throw new IOException("Cannot start " + m.getCodeName() + " state remains INSTALLED after start()"); // NOI18N
329
                        throw new IOException("Cannot start " + m.getCodeName() + " state remains INSTALLED after start()"); // NOI18N
330
                    }
330
                    }
331
                }
331
                }
Lines 704-713 Link Here
704
    }
704
    }
705
705
706
    @Messages({"#NOI18N", "FIND_COVERED_PKGS=findEntries"})
706
    @Messages({"#NOI18N", "FIND_COVERED_PKGS=findEntries"})
707
    private boolean findCoveredPkgs() {
707
    private boolean findCoveredPkgs(Object exportedPackages) {
708
        if (defaultCoveredPkgs == null) {
708
        if (defaultCoveredPkgs == null) {
709
            defaultCoveredPkgs = FIND_COVERED_PKGS();
709
            defaultCoveredPkgs = FIND_COVERED_PKGS();
710
        }
710
        }
711
        if ("exportedIfPresent".equals(defaultCoveredPkgs)) { // NOI18N
712
            return exportedPackages == null;
713
        }
714
        
711
        return "findEntries".equals(defaultCoveredPkgs); // NOI18N
715
        return "findEntries".equals(defaultCoveredPkgs); // NOI18N
712
    }
716
    }
713
717
(-)84950ad0c9bb (+42 lines)
Added Link Here
1
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
#
3
# Copyright 2011 Oracle and/or its affiliates. All rights reserved.
4
#
5
# Oracle and Java are registered trademarks of Oracle and/or its affiliates.
6
# Other names may be trademarks of their respective owners.
7
#
8
# The contents of this file are subject to the terms of either the GNU
9
# General Public License Version 2 only ("GPL") or the Common
10
# Development and Distribution License("CDDL") (collectively, the
11
# "License"). You may not use this file except in compliance with the
12
# License. You can obtain a copy of the License at
13
# http://www.netbeans.org/cddl-gplv2.html
14
# or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
15
# specific language governing permissions and limitations under the
16
# License.  When distributing the software, include this License Header
17
# Notice in each file and include the License file at
18
# nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
19
# particular file as subject to the "Classpath" exception as provided
20
# by Oracle in the GPL Version 2 section of the License file that
21
# accompanied this code. If applicable, add the following below the
22
# License Header, with the fields enclosed by brackets [] replaced by
23
# your own identifying information:
24
# "Portions Copyrighted [year] [name of copyright owner]"
25
#
26
# If you wish your version of this file to be governed by only the CDDL
27
# or only the GPL Version 2, indicate your decision by adding
28
# "[Contributor] elects to include this software in this distribution
29
# under the [CDDL or GPL Version 2] license." If you do not indicate a
30
# single choice of license, a recipient has the option to distribute
31
# your version of this file under either the CDDL, the GPL Version 2 or
32
# to extend the choice of license to its licensees as provided above.
33
# However, if you add GPL Version 2 code and therefore, elected the GPL
34
# Version 2 license, then the option applies only if the new code is
35
# made subject to such option by the copyright holder.
36
#
37
# Contributor(s):
38
#
39
# Portions Copyrighted 2011 Sun Microsystems, Inc.
40
41
# NOI18N
42
FIND_COVERED_PKGS=exportedIfPresent
(-)84950ad0c9bb (+166 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * Contributor(s):
28
 *
29
 * The Original Software is NetBeans. The Initial Developer of the Original
30
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2008 Sun
31
 * Microsystems, Inc. All Rights Reserved.
32
 *
33
 * If you wish your version of this file to be governed by only the CDDL
34
 * or only the GPL Version 2, indicate your decision by adding
35
 * "[Contributor] elects to include this software in this distribution
36
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
37
 * single choice of license, a recipient has the option to distribute
38
 * your version of this file under either the CDDL, the GPL Version 2 or
39
 * to extend the choice of license to its licensees as provided above.
40
 * However, if you add GPL Version 2 code and therefore, elected the GPL
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
43
 */
44
45
package org.netbeans.core.netigso;
46
47
import org.netbeans.core.startup.*;
48
import java.io.File;
49
import java.io.IOException;
50
import java.util.Collections;
51
import java.util.Locale;
52
import org.netbeans.Module;
53
import org.netbeans.ModuleManager;
54
import org.netbeans.SetupHid;
55
import org.openide.filesystems.FileObject;
56
import org.openide.filesystems.FileUtil;
57
import org.osgi.framework.Bundle;
58
59
/**
60
 * How does OSGi integration deals with layer registration? Can we read
61
 * it without resolving the bundle?
62
 *
63
 * @author Jaroslav Tulach
64
 */
65
public class ExportedIfPresentTest extends SetupHid {
66
    private static Module m1;
67
    private static ModuleManager mgr;
68
69
    public ExportedIfPresentTest(String name) {
70
        super(name);
71
    }
72
73
    protected @Override void setUp() throws Exception {
74
        // changes minimal start level to 10
75
        Locale.setDefault(new Locale("def", "EX"));
76
        clearWorkDir();
77
78
        
79
        data = new File(getDataDir(), "jars");
80
        jars = new File(getWorkDir(), "jars");
81
        jars.mkdirs();
82
        File simpleModule = createTestJAR("simple-module", null);
83
        File dependsOnSimpleModule = createTestJAR("depends-on-simple-module", null, simpleModule);
84
85
        if (System.getProperty("netbeans.user") == null) {
86
            File ud = new File(getWorkDir(), "ud");
87
            ud.mkdirs();
88
89
            System.setProperty("netbeans.user", ud.getPath());
90
91
92
            ModuleSystem ms = Main.getModuleSystem();
93
            mgr = ms.getManager();
94
            mgr.mutexPrivileged().enterWriteAccess();
95
            try {
96
                m1 = mgr.create(simpleModule, null, false, false, false);
97
                mgr.enable(Collections.<Module>singleton(m1));
98
            } finally {
99
                mgr.mutexPrivileged().exitWriteAccess();
100
            }
101
        }
102
103
    }
104
    private File createTestJAR(String name, String srcdir, File... classpath) throws IOException {
105
        return createTestJAR(data, jars, name, srcdir, classpath);
106
    }
107
    public void testCanLoadClassFromContextClassLoaderAsNoExportPackageAvailable() throws Exception {
108
        FileObject fo;
109
        Module m2;
110
        try {
111
            mgr.mutexPrivileged().enterWriteAccess();
112
            String mfBar = "Bundle-SymbolicName: org.bar\n" +
113
                "Bundle-Version: 1.1.0\n" +
114
                "Bundle-ManifestVersion: 2\n" +
115
                "Import-Package: org.foo\n" +
116
                "OpenIDE-Module-Layer: org/bar/layer.xml\n" +
117
                "\n\n";
118
119
            File j2 = changeManifest(new File(jars, "depends-on-simple-module.jar"), mfBar);
120
            m2 = mgr.create(j2, null, false, false, false);
121
            mgr.enable(m2);
122
        } finally {
123
            mgr.mutexPrivileged().exitWriteAccess();
124
        }
125
        try {
126
            mgr.mutexPrivileged().enterWriteAccess();
127
            Class<?> c = mgr.getClassLoader().loadClass("org.bar.SomethingElse");
128
            assertNotNull("Can load the class successfully", c);
129
        } finally {
130
            mgr.disable(m2);
131
            mgr.mutexPrivileged().exitWriteAccess();
132
        }
133
    }
134
    public void testCannotLoadClassFromContextClassLoaderWhenSomeExportPackageIsAvailable() throws Exception {
135
        FileObject fo;
136
        Module m2;
137
        try {
138
            mgr.mutexPrivileged().enterWriteAccess();
139
            String mfBar = "Bundle-SymbolicName: org.bar2\n" +
140
                "Bundle-Version: 1.1.0\n" +
141
                "Bundle-ManifestVersion: 2\n" +
142
                "Import-Package: org.foo\n" +
143
                "Export-Package: org.foo\n" +
144
                "\n\n";
145
146
            File j2 = changeManifest(new File(jars, "depends-on-simple-module.jar"), mfBar);
147
            m2 = mgr.create(j2, null, false, false, false);
148
            mgr.enable(m2);
149
        } finally {
150
            mgr.mutexPrivileged().exitWriteAccess();
151
        }
152
        try {
153
            mgr.mutexPrivileged().enterWriteAccess();
154
            try {
155
                Class<?> c = mgr.getClassLoader().loadClass("org.bar.SomethingElse");
156
                fail("The class should not have been found: " + c);
157
            } catch (ClassNotFoundException ex) {
158
                assertTrue(ex.getMessage(), ex.getMessage().contains("SomethingElse"));
159
            }
160
        } finally {
161
            mgr.disable(m2);
162
            mgr.mutexPrivileged().exitWriteAccess();
163
        }
164
    }
165
166
}

Return to bug 231223