Please use the Apache issue tracking system for new NetBeans issues (https://issues.apache.org/jira/projects/NETBEANS0/issues) !!
View | Details | Raw Unified | Return to bug 54123
Collapse All | Expand All

(-)src/org/netbeans/core/modules/Module.java (+27 lines)
 Lines 110-115   public final class Module extends Module Link Here 
110
    private Properties localizedProps;
110
    private Properties localizedProps;
111
    /** public packages, may be null */
111
    /** public packages, may be null */
112
    private PackageExport[] publicPackages;
112
    private PackageExport[] publicPackages;
113
    /** Set<String> of names of friend modules or null */
114
    private Set/*<String>*/ friendNames;
113
    
115
    
114
    /** Map from extension JARs to sets of JAR that load them via Class-Path.
116
    /** Map from extension JARs to sets of JAR that load them via Class-Path.
115
     * Used only for debugging purposes, so that a warning is printed if two
117
     * Used only for debugging purposes, so that a warning is printed if two
 Lines 380-385   public final class Module extends Module Link Here 
380
        return publicPackages;
382
        return publicPackages;
381
    }
383
    }
382
    
384
    
385
    /** Checks whether we use friends attribute and if so, then
386
     * whether the name of module is listed there.
387
     */
388
    public boolean isDeclaredAsFriend (Module module) {
389
        if (friendNames == null) return true;
390
        return friendNames.contains (module.getCodeName());
391
    }
392
    
383
    /** Parse information from the current manifest.
393
    /** Parse information from the current manifest.
384
     * Includes code name, specification version, and dependencies.
394
     * Includes code name, specification version, and dependencies.
385
     * If anything is in an invalid format, throws an exception with
395
     * If anything is in an invalid format, throws an exception with
 Lines 481-486   public final class Module extends Module Link Here 
481
                Util.err.log(ErrorManager.WARNING, "Warning: module " + codeNameBase + " does not declare OpenIDE-Module-Public-Packages in its manifest, so all packages are considered public by default: http://www.netbeans.org/download/dev/javadoc/OpenAPIs/org/openide/doc-files/upgrade.html#3.4-public-packages");
491
                Util.err.log(ErrorManager.WARNING, "Warning: module " + codeNameBase + " does not declare OpenIDE-Module-Public-Packages in its manifest, so all packages are considered public by default: http://www.netbeans.org/download/dev/javadoc/OpenAPIs/org/openide/doc-files/upgrade.html#3.4-public-packages");
482
                publicPackages = null;
492
                publicPackages = null;
483
            }
493
            }
494
            
495
            {
496
                // friends 
497
                String friends = attr.getValue("OpenIDE-Module-Friends"); // NOI18N
498
                if (friends != null) {
499
                    StringTokenizer tok = new StringTokenizer(friends, ", "); // NOI18N
500
                    HashSet set = new HashSet ();
501
                    while (tok.hasMoreTokens()) {
502
                        String piece = tok.nextToken();
503
                        set.add(piece.intern ());
504
                    }
505
                    if (set.isEmpty()) throw new IllegalArgumentException("Illegal OpenIDE-Module-Friends: " + friends); // NOI18N
506
                    this.friendNames = set;
507
                }
508
            }
509
            
510
            
484
            // Dependencies
511
            // Dependencies
485
            Set dependencies = new HashSet(20); // Set<Dependency>
512
            Set dependencies = new HashSet(20); // Set<Dependency>
486
            // First convert IDE/1 -> org.openide/1, so we never have to deal with
513
            // First convert IDE/1 -> org.openide/1, so we never have to deal with
(-)src/org/netbeans/core/modules/ModuleManager.java (+8 lines)
 Lines 555-560   public final class ModuleManager { Link Here 
555
                    return false;
555
                    return false;
556
                }
556
                }
557
                //Util.err.log("friend");
557
                //Util.err.log("friend");
558
            } else {
559
                // We have to verify that the caller is friend of this module
560
                if (!parent.isDeclaredAsFriend (m)) {
561
                    if (Util.err.isLoggable(ErrorManager.INFORMATIONAL)) {
562
                        Util.err.log("Refusing to load public package " + pkg + " for " + m + " from parent module " + parent + " as the caller is not listed as a friend module"); // NOI18N
563
                    }
564
                    return false;
565
                }
558
            }
566
            }
559
            //Util.err.log("exported");
567
            //Util.err.log("exported");
560
        }
568
        }
(-)test/unit/src/org/netbeans/core/modules/ModuleManagerTest.java (+44 lines)
 Lines 1653-1658   public class ModuleManagerTest extends S Link Here 
1653
            mgr.mutexPrivileged().exitWriteAccess();
1653
            mgr.mutexPrivileged().exitWriteAccess();
1654
        }
1654
        }
1655
    }
1655
    }
1656
1657
    public void testPublicPackagesCanBeExportedToSelectedFriendsOnlyIssue54123 () throws Exception {
1658
        ModuleManager mgr = new ModuleManager(new FakeModuleInstaller(), new FakeEvents());
1659
        mgr.mutexPrivileged().enterWriteAccess();
1660
        try {
1661
            addOpenide(mgr);
1662
            Module m1 = mgr.create(new File(jars, "api-mod-export-friend.jar"), null, false, false, false);
1663
            Module m2 = mgr.create(new File(jars, "uses-api-friend.jar"), null, false, false, false);
1664
            Module m3 = mgr.create(new File(jars, "uses-and-exports-api.jar"), null, false, false, false);
1665
            Module m4 = mgr.create(new File(jars, "uses-api-directly.jar"), null, false, false, false);
1666
            assertEquals("api-mod-export-api.jar had no problems", Collections.EMPTY_SET, m1.getProblems());
1667
            assertEquals("uses-api-friend.jar had no problems", Collections.EMPTY_SET, m2.getProblems());
1668
            assertEquals("uses-and-exports-api.jar had no problems", Collections.EMPTY_SET, m3.getProblems());
1669
            assertEquals("uses-api-directly.jar had no problems", Collections.EMPTY_SET, m4.getProblems());
1670
            mgr.enable(new HashSet(Arrays.asList(new Module[] {m1, m2, m3, m4})));
1671
            m2.getClassLoader().loadClass("usesapi.UsesPublicClass").newInstance();
1672
            try {
1673
                m2.getClassLoader().loadClass("usesapi.UsesImplClass").newInstance();
1674
                fail ("Even friends modules cannot access implementation classes");
1675
            } catch (NoClassDefFoundError ex) {
1676
                // ok
1677
            }
1678
            
1679
            try {
1680
                m4.getClassLoader().loadClass("usesapi.UsesPublicClass").newInstance();
1681
                fail ("m4 is not friend and should not be allowed to load the class");
1682
            } catch (NoClassDefFoundError ex) {
1683
                // ok
1684
            }
1685
            try {
1686
                m4.getClassLoader().loadClass("usesapi.UsesImplClass").newInstance();
1687
                fail ("m4 is not friend and should not be allowed to load the implementation either");
1688
            } catch (NoClassDefFoundError ex) {
1689
                // ok
1690
            }
1691
            mgr.disable(new HashSet(Arrays.asList(new Module[] {m1, m2, m3, m4})));
1692
            mgr.delete(m4);
1693
            mgr.delete(m3);
1694
            mgr.delete(m2);
1695
            mgr.delete(m1);
1696
        } finally {
1697
            mgr.mutexPrivileged().exitWriteAccess();
1698
        }
1699
    }
1656
    
1700
    
1657
    public void testModuleInterdependencies() throws Exception {
1701
    public void testModuleInterdependencies() throws Exception {
1658
        FakeModuleInstaller installer = new FakeModuleInstaller();
1702
        FakeModuleInstaller installer = new FakeModuleInstaller();
(-)test/unit/src/org/netbeans/core/modules/build.xml (+8 lines)
 Lines 159-164   Microsystems, Inc. All Rights Reserved. Link Here 
159
            <param name="sourcedir" value="jars/exposes-api"/>
159
            <param name="sourcedir" value="jars/exposes-api"/>
160
        </antcall>
160
        </antcall>
161
        <antcall target="create-jar">
161
        <antcall target="create-jar">
162
            <param name="name" value="api-mod-export-friend"/>
163
            <param name="sourcedir" value="jars/exposes-api"/>
164
        </antcall>
165
        <antcall target="create-jar">
162
            <param name="name" value="uses-api-simple-dep"/>
166
            <param name="name" value="uses-api-simple-dep"/>
163
            <param name="sourcedir" value="jars/uses-api"/>
167
            <param name="sourcedir" value="jars/uses-api"/>
164
            <param name="cp" value="${jars}/api-mod-export-api.jar"/>
168
            <param name="cp" value="${jars}/api-mod-export-api.jar"/>
 Lines 202-207   Microsystems, Inc. All Rights Reserved. Link Here 
202
        </antcall>
206
        </antcall>
203
        <antcall target="create-jar">
207
        <antcall target="create-jar">
204
            <param name="name" value="look-for-myself"/>
208
            <param name="name" value="look-for-myself"/>
209
        </antcall>
210
        <antcall target="create-jar">
211
            <param name="name" value="uses-api-friend"/>
212
            <param name="sourcedir" value="jars/uses-api"/>
205
        </antcall>
213
        </antcall>
206
        <!-- Don't use <jar>! It will add Created-By: Ant 1.nnn, which screws up results. -->
214
        <!-- Don't use <jar>! It will add Created-By: Ant 1.nnn, which screws up results. -->
207
        <zip zipfile="jars/little-manifest.jar" compress="false">
215
        <zip zipfile="jars/little-manifest.jar" compress="false">
(-)test/unit/src/org/netbeans/core/modules/jars/api-mod-export-friend.mf (+8 lines)
Added Link Here 
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.modules.foo
3
OpenIDE-Module-Public-Packages: org.netbeans.api.foo.*
4
OpenIDE-Module-Friends: org.netbeans.core/1, usesapifriend
5
OpenIDE-Module-Specification-Version: 1.0
6
OpenIDE-Module-Implementation-Version: today
7
OpenIDE-Module-IDE-Dependencies: IDE/1 > 2.2
8
(-)test/unit/src/org/netbeans/core/modules/jars/uses-api-friend.mf (+5 lines)
Added Link Here 
1
Manifest-Version: 1.0
2
OpenIDE-Module: usesapifriend
3
OpenIDE-Module-Module-Dependencies: org.netbeans.modules.foo > 1.0
4
OpenIDE-Module-IDE-Dependencies: IDE/1 > 5.0
5

Return to bug 54123
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo