private void initialize(final BundleContext context) { if (Debug.DEBUG_GENERAL) Debug.println("> AspectJHook.initialize() context=" + context); this.bundleContext = context; final ISupplementerRegistry supplementerRegistry = getSupplementerRegistry(); adaptorFactory.initialize(context, supplementerRegistry); final ServiceReference serviceReference = context.getServiceReference(PackageAdmin.class.getName()); final PackageAdmin packageAdmin = (PackageAdmin) context.getService(serviceReference); supplementerRegistry.setBundleContext(context); supplementerRegistry.setPackageAdmin(packageAdmin); context.addBundleListener(new SupplementBundleListener(supplementerRegistry)); // final re-build supplementer final registry state for final installed bundles final Bundle[] installedBundles = context.getBundles(); for (int i = 0; i < installedBundles.length; i++) { supplementerRegistry.addSupplementer(installedBundles[i], false); } for (int i = 0; i < installedBundles.length; i++) { supplementerRegistry.addSupplementedBundle(installedBundles[i]); } if (Debug.DEBUG_GENERAL) Debug.println("< AspectJHook.initialize() adaptorFactory=" + adaptorFactory); }
/** @see junit.framework.TestCase#setUp() */ @Override protected void setUp() throws Exception { super.setUp(); adaptorProvider = EasyMock.createNiceMock(IAdaptorProvider.class); context = EasyMock.createNiceMock(BundleContext.class); bundle = EasyMock.createMock(Bundle.class); otherBundle = EasyMock.createMock(Bundle.class); supplementerBundle1 = EasyMock.createMock(Bundle.class); supplementerBundle2 = EasyMock.createMock(Bundle.class); supplementerBundle3 = EasyMock.createMock(Bundle.class); supplementedBundle1 = EasyMock.createMock(Bundle.class); supplementedBundle2 = EasyMock.createMock(Bundle.class); supplementedBundle3 = EasyMock.createMock(Bundle.class); packageAdmin = EasyMock.createMock(PackageAdmin.class); EasyMock.expect(packageAdmin.getHosts(bundle)).andStubReturn(null); EasyMock.expect(packageAdmin.getHosts(supplementedBundle1)).andStubReturn(null); EasyMock.expect(packageAdmin.getHosts(supplementedBundle2)).andStubReturn(null); EasyMock.expect(packageAdmin.getHosts(supplementedBundle3)).andStubReturn(null); EasyMock.expect(packageAdmin.getHosts(supplementerBundle1)).andStubReturn(null); EasyMock.expect(packageAdmin.getHosts(supplementerBundle2)).andStubReturn(null); EasyMock.expect(packageAdmin.getHosts(supplementerBundle3)).andStubReturn(null); registry = new SupplementerRegistry(adaptorProvider); registry.setBundleContext(context); registry.setPackageAdmin(packageAdmin); EasyMock.expect(bundle.getBundleId()).andStubReturn(1l); EasyMock.expect(otherBundle.getBundleId()).andStubReturn(2l); EasyMock.expect(supplementerBundle1.getBundleId()).andStubReturn(3l); EasyMock.expect(supplementerBundle2.getBundleId()).andStubReturn(4l); EasyMock.expect(supplementerBundle3.getBundleId()).andStubReturn(5l); EasyMock.expect(supplementedBundle1.getBundleId()).andStubReturn(6l); EasyMock.expect(supplementedBundle2.getBundleId()).andStubReturn(7l); EasyMock.expect(supplementedBundle3.getBundleId()).andStubReturn(8l); EasyMock.expect(bundle.getSymbolicName()).andStubReturn("symbolic-name-bundle"); EasyMock.expect(otherBundle.getSymbolicName()).andStubReturn("symbolic-name-otherBundle"); EasyMock.expect(supplementerBundle1.getSymbolicName()) .andStubReturn("symbolic-name-supplementerBundle1"); EasyMock.expect(supplementerBundle2.getSymbolicName()) .andStubReturn("symbolic-name-supplementerBundle2"); EasyMock.expect(supplementerBundle3.getSymbolicName()) .andStubReturn("symbolic-name-supplementerBundle3"); EasyMock.expect(supplementedBundle1.getSymbolicName()) .andStubReturn("symbolic-name-supplementedBundle1"); EasyMock.expect(supplementedBundle2.getSymbolicName()) .andStubReturn("symbolic-name-supplementedBundle2"); EasyMock.expect(supplementedBundle3.getSymbolicName()).andStubReturn("different-symbolic-name"); mocks = new Object[] { adaptorProvider, packageAdmin, context, bundle, otherBundle, supplementedBundle1, supplementedBundle2, supplementedBundle3, supplementerBundle1, supplementerBundle2, supplementerBundle3 }; }