@@ -220,7 +220,7 @@ private List<IClasspathEntry> computePluginEntriesByModel() throws CoreException
220220 return List .of ();
221221 }
222222
223- Map <BundleDescription , List <Rule >> map = retrieveVisiblePackagesFromState (desc );
223+ Map <BundleDescription , Set <Rule >> map = retrieveVisiblePackagesFromState (desc );
224224
225225 // Add any library entries contributed via classpath contributor
226226 // extension (Bug 363733)
@@ -333,8 +333,8 @@ private static synchronized Stream<IClasspathContributor> getClasspathContributo
333333 return Stream .concat (fClasspathContributors .stream (), PDECore .getDefault ().getClasspathContributors ());
334334 }
335335
336- private Map <BundleDescription , List <Rule >> retrieveVisiblePackagesFromState (BundleDescription desc ) {
337- Map <BundleDescription , List <Rule >> visiblePackages = new HashMap <>();
336+ private Map <BundleDescription , Set <Rule >> retrieveVisiblePackagesFromState (BundleDescription desc ) {
337+ Map <BundleDescription , Set <Rule >> visiblePackages = new HashMap <>();
338338 StateHelper helper = BundleHelper .getPlatformAdmin ().getStateHelper ();
339339 addVisiblePackagesFromState (helper , desc , visiblePackages );
340340 if (desc .getHost () != null ) {
@@ -344,7 +344,7 @@ private Map<BundleDescription, List<Rule>> retrieveVisiblePackagesFromState(Bund
344344 }
345345
346346 private void addVisiblePackagesFromState (StateHelper helper , BundleDescription desc ,
347- Map <BundleDescription , List <Rule >> visiblePackages ) {
347+ Map <BundleDescription , Set <Rule >> visiblePackages ) {
348348 if (desc == null ) {
349349 return ;
350350 }
@@ -354,11 +354,9 @@ private void addVisiblePackagesFromState(StateHelper helper, BundleDescription d
354354 if (exporter == null ) {
355355 continue ;
356356 }
357- List <Rule > list = visiblePackages .computeIfAbsent (exporter , e -> new ArrayList <>());
357+ Set <Rule > list = visiblePackages .computeIfAbsent (exporter , e -> new LinkedHashSet <>());
358358 Rule rule = getRule (helper , desc , export );
359- if (!list .contains (rule )) {
360- list .add (rule );
361- }
359+ list .add (rule );
362360 }
363361 }
364362
@@ -370,7 +368,7 @@ private Rule getRule(StateHelper helper, BundleDescription desc, ExportPackageDe
370368 }
371369
372370 protected void addDependencyViaImportPackage (BundleDescription desc , Set <BundleDescription > added ,
373- Map <BundleDescription , List <Rule >> map , List <IClasspathEntry > entries ) throws CoreException {
371+ Map <BundleDescription , Set <Rule >> map , List <IClasspathEntry > entries ) throws CoreException {
374372 if (desc == null || !added .add (desc )) {
375373 return ;
376374 }
@@ -388,12 +386,12 @@ protected void addDependencyViaImportPackage(BundleDescription desc, Set<BundleD
388386 }
389387
390388 private void addDependency (BundleDescription desc , Set <BundleDescription > added ,
391- Map <BundleDescription , List <Rule >> map , List <IClasspathEntry > entries ) throws CoreException {
389+ Map <BundleDescription , Set <Rule >> map , List <IClasspathEntry > entries ) throws CoreException {
392390 addDependency (desc , added , map , entries , true );
393391 }
394392
395393 private void addDependency (BundleDescription desc , Set <BundleDescription > added ,
396- Map <BundleDescription , List <Rule >> map , List <IClasspathEntry > entries , boolean useInclusion )
394+ Map <BundleDescription , Set <Rule >> map , List <IClasspathEntry > entries , boolean useInclusion )
397395 throws CoreException {
398396 if (desc == null || !added .add (desc )) {
399397 return ;
@@ -436,7 +434,7 @@ private void addDependency(BundleDescription desc, Set<BundleDescription> added,
436434 }
437435 }
438436
439- private boolean addPlugin (BundleDescription desc , boolean useInclusions , Map <BundleDescription , List <Rule >> map ,
437+ private boolean addPlugin (BundleDescription desc , boolean useInclusions , Map <BundleDescription , Set <Rule >> map ,
440438 List <IClasspathEntry > entries ) throws CoreException {
441439 IPluginModelBase model = PluginRegistry .findModel ((Resource ) desc );
442440 if (model == null || !model .isEnabled ()) {
@@ -464,7 +462,7 @@ private boolean addPlugin(BundleDescription desc, boolean useInclusions, Map<Bun
464462 return true ;
465463 }
466464
467- private List <Rule > getInclusions (Map <BundleDescription , List <Rule >> map , IPluginModelBase model ) {
465+ private List <Rule > getInclusions (Map <BundleDescription , Set <Rule >> map , IPluginModelBase model ) {
468466 BundleDescription desc = model .getBundleDescription ();
469467 if (desc == null || "false" .equals (System .getProperty ("pde.restriction" )) //$NON-NLS-1$ //$NON-NLS-2$
470468 || !(fModel instanceof IBundlePluginModelBase ) || TargetPlatformHelper .getTargetVersion () < 3.1 ) {
@@ -474,12 +472,12 @@ private List<Rule> getInclusions(Map<BundleDescription, List<Rule>> map, IPlugin
474472 if (desc .getHost () != null ) {
475473 desc = (BundleDescription ) desc .getHost ().getSupplier ();
476474 }
477- List <Rule > rules = map .getOrDefault (desc , List .of ());
478- return (rules .isEmpty () && !ClasspathUtilCore .hasBundleStructure (model )) ? null : rules ;
475+ Set <Rule > rules = map .getOrDefault (desc , Set .of ());
476+ return (rules .isEmpty () && !ClasspathUtilCore .hasBundleStructure (model )) ? null : new ArrayList <>( rules ) ;
479477 }
480478
481479 private void addHostPlugin (HostSpecification hostSpec , Set <BundleDescription > added ,
482- Map <BundleDescription , List <Rule >> map , List <IClasspathEntry > entries ) throws CoreException {
480+ Map <BundleDescription , Set <Rule >> map , List <IClasspathEntry > entries ) throws CoreException {
483481 BaseDescription desc = hostSpec .getSupplier ();
484482
485483 if (desc instanceof BundleDescription host ) {
@@ -623,7 +621,7 @@ private void addJunit5RuntimeDependencies(Set<BundleDescription> added, List<ICl
623621 }
624622
625623 // add dependency with exclude all rule
626- Map <BundleDescription , List <Rule >> rules = Map .of (desc , List .of ());
624+ Map <BundleDescription , Set <Rule >> rules = Map .of (desc , Set .of ());
627625 addPlugin (desc , true , rules , entries );
628626 }
629627 }
@@ -687,7 +685,7 @@ private void addTransitiveDependenciesWithForbiddenAccess(Set<BundleDescription>
687685 while (transitiveDeps .hasNext ()) {
688686 BundleDescription desc = transitiveDeps .next ();
689687 if (added .add (desc )) {
690- Map <BundleDescription , List <Rule >> rules = Map .of (desc , List .of ());
688+ Map <BundleDescription , Set <Rule >> rules = Map .of (desc , Set .of ());
691689 addPlugin (desc , true , rules , entries );
692690 }
693691 }
@@ -701,21 +699,24 @@ private void addExtraModel(BundleDescription desc, Set<BundleDescription> added,
701699 if (added .contains (bundleDesc )) {
702700 return ;
703701 }
704- Map <BundleDescription , List <Rule >> rules = new HashMap <>();
702+ Map <BundleDescription , Set <Rule >> rules = new HashMap <>();
705703 findExportedPackages (bundleDesc , desc , rules );
706704 addDependency (bundleDesc , added , rules , entries , true );
707705 }
708706 }
709707
710708 protected final void findExportedPackages (BundleDescription desc , BundleDescription projectDesc ,
711- Map <BundleDescription , List <Rule >> map ) {
709+ Map <BundleDescription , Set <Rule >> map ) {
712710 if (desc != null ) {
713711 Queue <BundleDescription > queue = new ArrayDeque <>();
714712 queue .add (desc );
715713 while (!queue .isEmpty ()) {
716714 BundleDescription bdesc = queue .remove ();
715+ if (map .containsKey (bdesc )) {
716+ continue ;
717+ }
717718 ExportPackageDescription [] expkgs = bdesc .getExportPackages ();
718- List <Rule > rules = new ArrayList <>();
719+ Set <Rule > rules = new LinkedHashSet <>();
719720 for (ExportPackageDescription expkg : expkgs ) {
720721 boolean discouraged = restrictPackage (projectDesc , expkg );
721722 IPath path = IPath .fromOSString (expkg .getName ().replace ('.' , '/' ) + "/*" ); //$NON-NLS-1$
0 commit comments