/** * @param bundle * @return */ private static String getHeader(final Bundle bundle, String... keys) { // Look in the bundle... Dictionary headers = bundle.getHeaders(); for (String key : keys) { String value = (String) headers.get(key); if (value != null) { return value; } } // Next, look in the bundle's fragments. Bundle[] bundles = bundle.getBundleContext().getBundles(); for (Bundle fragment : bundles) { // only fragments are in resolved state if (fragment.getState() != bundle.RESOLVED) continue; // A fragment must also have the FRAGMENT_HOST header and the FRAGMENT_HOST header // must be equal to the bundle symbolic name String fragmentHost = (String) fragment.getHeaders().get(Constants.FRAGMENT_HOST); if ((fragmentHost == null) || (!fragmentHost.equals(bundle.getSymbolicName()))) { continue; } headers = fragment.getHeaders(); for (String key : keys) { String value = (String) headers.get(key); if (value != null) { return value; } } } return null; }
public void bundleAdded(Bundle bundle) { String webResourceHeader = (String) bundle.getHeaders().get("X-NgApp"); String[] entries = webResourceHeader.split(","); ArrayList<NgModule> resourceEntries = new ArrayList<>(); m_modules.put(bundle.getSymbolicName(), resourceEntries); for (String entry : entries) { String[] split = entry.split(";"); if (split.length != 3) { return; } String path = split[0]; String moduleFileName = split[1]; String moduleName = split[2]; if (path.startsWith("/")) { path = path.substring(1); } resourceEntries.add( new NgModule( path, moduleFileName, moduleName, (String) bundle.getHeaders().get("X-NgLink"))); } }
/** * test the supplementer registry with a supplemented bundle * * @throws Exception */ public void testSupplementerRegistryWithCombinedSupplementer() throws Exception { Hashtable headers = new Hashtable(); headers.put("Eclipse-SupplementImporter", "test.import1"); headers.put("Eclipse-SupplementExporter", "test.export1"); headers.put("Eclipse-SupplementBundle", "symbolic-name-supplementedBundle1"); EasyMock.expect(bundle.getHeaders()).andStubReturn(headers); EasyMock.expect(bundle.getSymbolicName()).andStubReturn("supplementer"); EasyMock.expect(context.getBundles()).andReturn(new Bundle[] {bundle}); EasyMock.expect(supplementedBundle1.getHeaders()).andStubReturn(new Hashtable()); headers = new Hashtable(); headers.put("Export-Package", "test.export1"); EasyMock.expect(supplementedBundle2.getHeaders()).andStubReturn(headers); headers = new Hashtable(); headers.put("Import-Package", "test.import1"); EasyMock.expect(supplementedBundle3.getHeaders()).andStubReturn(headers); EasyMock.replay(mocks); registry.addBundle(bundle); registry.addBundle(supplementedBundle1); registry.addBundle(supplementedBundle2); registry.addBundle(supplementedBundle3); Supplementer[] supplementers = registry.getSupplementers(supplementedBundle1); assertSame(bundle, supplementers[0].getSupplementerBundle()); supplementers = registry.getSupplementers(supplementedBundle2); assertSame(bundle, supplementers[0].getSupplementerBundle()); supplementers = registry.getSupplementers(supplementedBundle3); assertSame(bundle, supplementers[0].getSupplementerBundle()); EasyMock.verify(mocks); }
/** * Assuming the bundle is started. * * @param bundle * @return classloader object */ public static ClassLoader getBundleClassLoader(Bundle bundle) { String bundleActivator = (String) bundle.getHeaders().get("Bundle-Activator"); if (bundleActivator == null) { bundleActivator = (String) bundle.getHeaders().get("Jetty-ClassInBundle"); } if (bundleActivator != null) { try { return bundle.loadClass(bundleActivator).getClassLoader(); } catch (ClassNotFoundException e) { // should not happen as we are called if the bundle is started // anyways. e.printStackTrace(); } } // resort to introspection if (!identifiedOsgiImpl) { init(bundle); } if (isEquinox) { return internalGetEquinoxBundleClassLoader(bundle); } else if (isFelix) { return internalGetFelixBundleClassLoader(bundle); } return null; }
private void applyChanges(Map<Bundle, String> toUpdate) throws BundleException, IOException { List<Bundle> toStop = new ArrayList<Bundle>(); toStop.addAll(toUpdate.keySet()); while (!toStop.isEmpty()) { List<Bundle> bs = getBundlesToDestroy(toStop); for (Bundle bundle : bs) { String hostHeader = (String) bundle.getHeaders().get(Constants.FRAGMENT_HOST); if (hostHeader == null && (bundle.getState() == Bundle.ACTIVE || bundle.getState() == Bundle.STARTING)) { bundle.stop(); } toStop.remove(bundle); } } Set<Bundle> toRefresh = new HashSet<Bundle>(); Set<Bundle> toStart = new HashSet<Bundle>(); for (Map.Entry<Bundle, String> e : toUpdate.entrySet()) { InputStream is = new URL(e.getValue()).openStream(); try { Bundle bundle = e.getKey(); bundle.update(is); toRefresh.add(bundle); toStart.add(bundle); } finally { is.close(); } } findBundlesWithOptionalPackagesToRefresh(toRefresh); findBundlesWithFramentsToRefresh(toRefresh); if (!toRefresh.isEmpty()) { final CountDownLatch l = new CountDownLatch(1); FrameworkListener listener = new FrameworkListener() { @Override public void frameworkEvent(FrameworkEvent event) { l.countDown(); } }; FrameworkWiring wiring = (FrameworkWiring) bundleContext.getBundle(0).adapt(FrameworkWiring.class); wiring.refreshBundles((Collection<Bundle>) toRefresh, new FrameworkListener[] {listener}); try { l.await(); } catch (InterruptedException e) { throw new PatchException("Bundle refresh interrupted", e); } } for (Bundle bundle : toStart) { String hostHeader = (String) bundle.getHeaders().get(Constants.FRAGMENT_HOST); if (hostHeader == null) { bundle.start(); } } }
@Test public void testPersistTimeoutSystemProperty() throws Exception { System.setProperty(PluginUtils.MAERA_PLUGINS_ENABLE_WAIT, "300"); try { final File propertiesFile = new File(cacheDir, ".properties"); assertFalse(propertiesFile.exists()); final PluginJarBuilder firstBuilder = new PluginJarBuilder("first"); final File jar = firstBuilder .addPluginInformation("first", "Some name", "1.0") .addFormattedJava( "first.MyInterface", "package first;", "public interface MyInterface {}") .addFormattedResource( "META-INF/MANIFEST.MF", "Manifest-Version: 1.0", "Bundle-SymbolicName: first", "Bundle-Version: 1.0", "Export-Package: first", "") .build(); initPluginManager(); pluginManager.installPlugin(new JarPluginArtifact(jar)); Bundle bundle = findBundleByName("first"); Dictionary headers = bundle.getHeaders(); assertEquals("*;timeout:=300", headers.get("Spring-Context")); assertTrue(propertiesFile.exists()); Properties properties = new Properties(); properties.load(new FileInputStream(propertiesFile)); assertEquals("300", properties.getProperty("spring.timeout")); final File testFile = new File(new File(cacheDir, "transformed-plugins"), ".test"); assertTrue(testFile.createNewFile()); assertTrue(testFile.exists()); initPluginManager(); pluginManager.installPlugin(new JarPluginArtifact(jar)); bundle = findBundleByName("first"); headers = bundle.getHeaders(); assertEquals("*;timeout:=300", headers.get("Spring-Context")); assertTrue(propertiesFile.exists()); assertTrue(testFile.exists()); } finally { System.clearProperty(PluginUtils.MAERA_PLUGINS_ENABLE_WAIT); } }
@Override protected Object doExecute() throws Exception { s_logger.info("[Group = {}] , [Name = {}], [Options = {}]", m_group, m_name, m_options); Bundle bundle = getBundle(m_group, m_name); if (bundle == null) { System.err.println( "Apollo bundle is not found. [Group = " + m_group + "] , [Name = " + m_name + "]"); } else { System.out.println("---------------------Base---------------------"); System.out.println("[Location = " + bundle.getLocation() + "]"); System.out.println("[Bundle ID = " + bundle.getBundleId() + "]"); System.out.println("[Symbolic Name = " + bundle.getSymbolicName() + "]"); if (m_options != null) { if (m_options.contains("import")) { System.out.println("\n---------------------Import-Package---------------------"); String ips = (String) bundle.getHeaders().get("Import-Package"); if (ips != null) { for (String ip : ips.split("\",")) { System.out.println(ip); } } } if (m_options.contains("export")) { System.out.println("\n---------------------Export-Package---------------------"); String eps = (String) bundle.getHeaders().get("Export-Package"); if (eps != null) { for (String ep : eps.split("\",")) { System.out.println(ep); } } } if (m_options.contains("provide")) { System.out.println("\n---------------------Provide-Capability---------------------"); String rcs = (String) bundle.getHeaders().get("Provide-Capability"); for (String rc : rcs.split(",")) { System.out.println(rc); } } } } System.out.println(""); return null; }
/** * @param b * @param sb */ public static void getBundleName(Bundle b, StringBuilder sb) { String name = (String) b.getHeaders().get("Bundle-SymbolicName"); if (name == null) { name = (String) b.getHeaders().get("Bundle-Name"); } if (name == null) { name = "Undefined"; } if (name.indexOf(";") > -1) name = name.split(";")[0]; sb.append(name); }
/** * Implements the <tt>ListCellRenderer</tt> method. Returns this panel that has been configured to * display bundle name, version and description. * * @param table the parent table * @param value the value of the rendered cell * @param isSelected indicates if the rendered cell is selected * @param hasFocus indicates if the rendered cell has the focus * @param rowIndex the row index of the rendered cell * @param vColIndex the column index of the rendered cell * @return the rendering component */ public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int rowIndex, int vColIndex) { Bundle bundle = (Bundle) value; Dictionary<?, ?> headers = bundle.getHeaders(); Object bundleName = headers.get(Constants.BUNDLE_NAME); Object bundleVersion = headers.get(Constants.BUNDLE_VERSION); Object bundleDescription = headers.get(Constants.BUNDLE_DESCRIPTION); Icon stateIcon = getStateIcon(bundle.getState()); if (bundleName != null) this.nameLabel.setText(bundleName.toString()); else this.nameLabel.setText("unknown"); if (bundleVersion != null) this.versionLabel.setText(bundleVersion.toString()); else this.versionLabel.setText(""); if (bundleDescription != null) this.descriptionLabel.setText(bundleDescription.toString()); else this.descriptionLabel.setText(""); if (stateIcon != null) this.stateLabel.setIcon(stateIcon); this.nameVersionPanel.remove(systemLabel); if (PluginManagerActivator.isSystemBundle(bundle)) this.nameVersionPanel.add(systemLabel); this.isSelected = isSelected; return this; }
/** * Register namespaces defined in the bundle in the namespace table. * * @param bundle The bundle. */ private void registerNamespaces(Bundle bundle) { final String definition = (String) bundle.getHeaders().get(NAMESPACES_BUNDLE_HEADER); if (definition != null) { log.debug( "registerNamespaces: Bundle {} tries to register: {}", bundle.getSymbolicName(), definition); final StringTokenizer st = new StringTokenizer(definition, ","); final List<NamespaceEntry> entries = new ArrayList<NamespaceEntry>(); while (st.hasMoreTokens()) { final String token = st.nextToken().trim(); int pos = token.indexOf('='); if (pos == -1) { log.warn( "registerNamespaces: Bundle {} has an invalid namespace manifest header entry: {}", bundle.getSymbolicName(), token); } else { final String prefix = token.substring(0, pos).trim(); final String namespace = token.substring(pos + 1).trim(); entries.add(new NamespaceEntry(prefix, namespace)); } } if (entries.size() > 0) { this.namespaceTable.put( bundle.getBundleId(), entries.toArray(new NamespaceEntry[entries.size()])); } } }
@Override public Bundle apply(Bundle b) { if (printBundle) printBundleFunction.apply(b); Object imports = b.getHeaders().get("Import-Package"); Object exports = b.getHeaders().get("Export-Package"); FormatPackageElementFunction pf = new FormatPackageElementFunction(sb, brief); if (imports != null) { sb.append("Imports"); sb.append(StringConstants.CRLF); Applier.map(imports.toString().split(","), pf); } if (exports != null) { sb.append("Exports"); sb.append(StringConstants.CRLF); Applier.map(exports.toString().split(","), pf); } if (printBundle) sb.append(StringConstants.CRLF); return b; }
protected void findBundlesWithFramentsToRefresh(Set<Bundle> toRefresh) { for (Bundle b : toRefresh) { if (b.getState() != Bundle.UNINSTALLED) { String hostHeader = (String) b.getHeaders().get(Constants.FRAGMENT_HOST); if (hostHeader != null) { Clause[] clauses = Parser.parseHeader(hostHeader); if (clauses != null && clauses.length > 0) { Clause path = clauses[0]; for (Bundle hostBundle : bundleContext.getBundles()) { if (hostBundle.getSymbolicName().equals(path.getName())) { String ver = path.getAttribute(Constants.BUNDLE_VERSION_ATTRIBUTE); if (ver != null) { VersionRange v = VersionRange.parseVersionRange(ver); if (v.contains(hostBundle.getVersion())) { toRefresh.add(hostBundle); } } else { toRefresh.add(hostBundle); } } } } } } } }
@SuppressWarnings("deprecation") public void testAllResolved() { assertNotNull("Expected a Bundle Context", context); StringBuilder sb = new StringBuilder(); for (Bundle b : context.getBundles()) { if (b.getState() == Bundle.INSTALLED && b.getHeaders().get(aQute.bnd.osgi.Constants.FRAGMENT_HOST) == null) { try { b.start(); } catch (BundleException e) { sb.append(b.getBundleId()) .append(" ") .append(b.getSymbolicName()) .append(";") .append(b.getVersion()) .append("\n"); sb.append(" ").append(e.getMessage()).append("\n\n"); System.err.println(e.getMessage()); } } } Matcher matcher = IP_P.matcher(sb); String out = matcher.replaceAll( "\n\n " + aQute.bnd.osgi.Constants.IMPORT_PACKAGE + ": $1;version=[$2,$3)\n"); assertTrue("Unresolved bundles\n" + out, sb.length() == 0); }
private String printBundleState(Bundle bundle) { String result; switch (bundle.getState()) { case Bundle.UNINSTALLED: result = "UNINSTALLED"; break; case Bundle.INSTALLED: result = "INSTALLED"; break; case Bundle.RESOLVED: result = "RESOLVED"; break; case Bundle.STARTING: result = "STARTING"; if ("lazy".equals(bundle.getHeaders().get("Bundle-ActivationPolicy"))) result += "/LAZY"; break; case Bundle.ACTIVE: result = "ACTIVE"; break; case Bundle.STOPPING: result = "STOPPING"; break; default: result = "<<UNKNOWN>>"; break; } return result; }
@Override public boolean uninstall(OTEStatusCallback<ConfigurationStatus> statusCallback) { boolean result = true; for (Bundle bundle : installedBundles) { try { bundle.uninstall(); } catch (BundleException ex) { result = false; statusCallback.error("Failed to uninstall " + bundle.getSymbolicName(), ex); } } installedBundles.clear(); for (Bundle bundle : runningBundles) { try { String entry = bundle.getHeaders().get("Fragment-Host"); if (entry == null) { bundle.stop(); } bundle.uninstall(); } catch (BundleException ex) { result = false; statusCallback.error("Failed to stop and uninstall " + bundle.getSymbolicName(), ex); } } runningBundles.clear(); return result; }
@Override public boolean start(OTEStatusCallback<ConfigurationStatus> statusCallback) { boolean pass = true; sortBundles(installedBundles); Iterator<Bundle> iter = installedBundles.iterator(); while (iter.hasNext()) { Bundle bundle = iter.next(); try { String entry = bundle.getHeaders().get("Fragment-Host"); if (entry == null) { int bundleState = bundle.getState(); if (bundleState != Bundle.ACTIVE) { bundle.start(); } } // We got here because bundle.start did not exception runningBundles.add(bundle); iter.remove(); statusCallback.log("started " + bundle.getSymbolicName()); } catch (BundleException ex) { pass = false; statusCallback.error("Failed to start " + bundle.getSymbolicName(), ex); } finally { statusCallback.incrememtUnitsWorked(1); } } return pass; }
public void testSupplementerRegistryWithWildcards() throws Exception { Hashtable headers = new Hashtable(); headers = new Hashtable(); headers.put("Eclipse-SupplementBundle", "symbolic-name-supplementedBundle*"); EasyMock.expect(supplementerBundle1.getHeaders()).andStubReturn(headers); headers = new Hashtable(); headers.put("Eclipse-SupplementBundle", "symbolic-name-supplemented*"); EasyMock.expect(supplementerBundle2.getHeaders()).andStubReturn(headers); EasyMock.expect(context.getBundles()) .andStubReturn(new Bundle[] {supplementerBundle1, supplementerBundle2}); headers = new Hashtable(); EasyMock.expect(supplementedBundle1.getHeaders()).andStubReturn(headers); headers = new Hashtable(); EasyMock.expect(supplementedBundle2.getHeaders()).andStubReturn(headers); headers = new Hashtable(); EasyMock.expect(supplementedBundle3.getHeaders()).andStubReturn(headers); EasyMock.replay(mocks); registry.addBundle(supplementerBundle1); registry.addBundle(supplementerBundle2); registry.addBundle(supplementedBundle1); registry.addBundle(supplementedBundle2); registry.addBundle(supplementedBundle3); Supplementer[] supplementers = registry.getSupplementers(supplementedBundle1); assertEquals(2, supplementers.length); assertTrue(containsSupplementer(supplementers, supplementerBundle1)); assertTrue(containsSupplementer(supplementers, supplementerBundle2)); supplementers = registry.getSupplementers(supplementedBundle2); assertEquals(2, supplementers.length); assertTrue(containsSupplementer(supplementers, supplementerBundle1)); assertTrue(containsSupplementer(supplementers, supplementerBundle2)); supplementers = registry.getSupplementers(supplementedBundle3); assertEquals(0, supplementers.length); assertFalse(containsSupplementer(supplementers, supplementerBundle1)); assertFalse(containsSupplementer(supplementers, supplementerBundle2)); EasyMock.verify(mocks); }
private StringBuffer printBundleHeaderLine(Bundle bundle, StringBuffer buffer) { buffer.append(Long.toString(bundle.getBundleId())).append(','); buffer.append(bundle.getHeaders().get(Constants.BUNDLE_SYMBOLICNAME)).append(','); buffer.append(bundle.getLocation()).append(','); buffer.append(printBundleState(bundle)); return buffer; }
/** * @param bundle * @param artifact */ public InstalledBundle(Bundle bundle, ArtifactFS artifact) { super(); this.bundle = bundle; this.artifact = artifact; isWebBundle = (bundle.getHeaders().get(Constains.BUNDLE_WEB_CONTEXTPATH_KEY) != null); this.bundleState = WEB_BUNDLE_STOPPED; }
private static String getRemoteServicesDir(Bundle b) { Dictionary<?, ?> headers = b.getHeaders(); Object header = null; if (headers != null) { header = headers.get(REMOTE_SERVICES_HEADER_NAME); } return (header == null) ? REMOTE_SERVICES_DIRECTORY : header.toString(); }
/** * Here is the order in which jars and osgi artifacts are scanned for discoverable annotations. * * <ol> * <li>The container jars are scanned. * <li>The WEB-INF/classes are scanned * <li>The osgi fragment to the web bundle are parsed. * <li>The WEB-INF/lib are scanned * <li>The required bundles are parsed * </ol> */ @Override public void parseWebInfLib( WebAppContext context, org.eclipse.jetty.annotations.AnnotationParser parser) throws Exception { AnnotationParser oparser = (AnnotationParser) parser; Bundle webbundle = (Bundle) context.getAttribute(OSGiWebappConstants.JETTY_OSGI_BUNDLE); Set<Bundle> fragAndRequiredBundles = (Set<Bundle>) context.getAttribute(OSGiWebInfConfiguration.FRAGMENT_AND_REQUIRED_BUNDLES); if (fragAndRequiredBundles != null) { // index and scan fragments for (Bundle bundle : fragAndRequiredBundles) { // skip bundles that have been uninstalled since we discovered them if (bundle.getState() == Bundle.UNINSTALLED) continue; Resource bundleRes = oparser.indexBundle(bundle); if (!context.getMetaData().getWebInfJars().contains(bundleRes)) { context.getMetaData().addWebInfJar(bundleRes); } if (bundle.getHeaders().get(Constants.FRAGMENT_HOST) != null) { // a fragment indeed: parseFragmentBundle(context, oparser, webbundle, bundle); } } } // scan ourselves oparser.indexBundle(webbundle); parseWebBundle(context, oparser, webbundle); // scan the WEB-INF/lib super.parseWebInfLib(context, parser); if (fragAndRequiredBundles != null) { // scan the required bundles for (Bundle requiredBundle : fragAndRequiredBundles) { // skip bundles that have been uninstalled since we discovered them if (requiredBundle.getState() == Bundle.UNINSTALLED) continue; if (requiredBundle.getHeaders().get(Constants.FRAGMENT_HOST) == null) { // a bundle indeed: parseRequiredBundle(context, oparser, webbundle, requiredBundle); } } } }
// TODO use jgit API methods as soon as they are available private void writeGitPatch(StringBuilder sb, DiffFormatter diffFmt) throws IOException { final SimpleDateFormat dtfmt; dtfmt = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z", Locale.US); // $NON-NLS-1$ dtfmt.setTimeZone(commit.getAuthorIdent().getTimeZone()); sb.append(UIText.GitHistoryPage_From) .append(" ") // $NON-NLS-1$ .append(commit.getId().getName()) .append(" ") // $NON-NLS-1$ .append(dtfmt.format(Long.valueOf(System.currentTimeMillis()))) .append("\n"); // $NON-NLS-1$ sb.append(UIText.GitHistoryPage_From) .append(": ") // $NON-NLS-1$ .append(commit.getAuthorIdent().getName()) .append(" <") .append(commit.getAuthorIdent().getEmailAddress()) // $NON-NLS-1$ .append(">\n"); // $NON-NLS-1$ sb.append(UIText.GitHistoryPage_Date) .append(": ") // $NON-NLS-1$ .append(dtfmt.format(commit.getAuthorIdent().getWhen())) .append("\n"); // $NON-NLS-1$ sb.append(UIText.GitHistoryPage_Subject) .append(": [PATCH] ") // $NON-NLS-1$ .append(commit.getShortMessage()); String message = commit.getFullMessage().substring(commit.getShortMessage().length()); sb.append(message).append("\n\n"); // $NON-NLS-1$ FileDiff[] diffs = FileDiff.compute(walker, commit); for (FileDiff diff : diffs) { sb.append("diff --git a") .append(IPath.SEPARATOR) // $NON-NLS-1$ .append(diff.path) .append(" b") .append(IPath.SEPARATOR) // $NON-NLS-1$ .append(diff.path) .append("\n"); // $NON-NLS-1$ diff.outputDiff(sb, db, diffFmt, false, false); } sb.append("\n--\n"); // $NON-NLS-1$ Bundle bundle = Activator.getDefault().getBundle(); String name = (String) bundle.getHeaders().get(org.osgi.framework.Constants.BUNDLE_NAME); String version = (String) bundle.getHeaders().get(org.osgi.framework.Constants.BUNDLE_VERSION); sb.append(name).append(" ").append(version); // $NON-NLS-1$ }
public Resource createResource(final Bundle bundle) { final Dictionary dict = bundle.getHeaders(); return createResource( new Headers() { public String getHeader(String name) { return (String) dict.get(name); } }); }
public static List<ExportedPackage> getExportedPackages(Bundle bundle) { final List<ExportedPackage> result = new ArrayList<ExportedPackage>(); final BundleManifest manifest = BundleManifestFactory.createBundleManifest(bundle.getHeaders(), new DummyParserLogger()); for (ExportedPackage exportedPackage : manifest.getExportPackage().getExportedPackages()) { result.add(exportedPackage); } return result; }
/** * test the supplementer registry with a supplemented bundle * * @throws Exception */ public void testSupplementerRegistryWithSupplementedBundle() throws Exception { final Hashtable headers = new Hashtable(); headers.put("Eclipse-SupplementBundle", "symbolic-name-supplementedBundle1"); EasyMock.expect(bundle.getHeaders()).andStubReturn(headers); EasyMock.expect(context.getBundles()).andReturn(new Bundle[] {bundle}); EasyMock.expect(supplementedBundle1.getHeaders()).andStubReturn(new Hashtable()); EasyMock.replay(mocks); registry.addBundle(bundle); registry.addBundle(supplementedBundle1); final Supplementer[] supplementers = registry.getSupplementers(supplementedBundle1); assertSame(bundle, supplementers[0].getSupplementerBundle()); EasyMock.verify(mocks); }
@Before public void mockIt() { when(contextModelMock.getContextName()).thenReturn(KNOWN_CONTEXT_NAME); when(contextModelMock.getHttpContext()).thenReturn(httpContextMock); when(contextModelMock.getBundle()).thenReturn(bundleMock); when(bundleMock.getHeaders()).thenReturn(new Hashtable<String, String>()); when(bundleMock.getSymbolicName()).thenReturn(BUNDLE_SYMBOLIC_NAME); when(bundleMock.getBundleContext()).thenReturn(bundleContextMock); }
/** * @param b * @param sb */ public static void getBundleVersion(Bundle b, StringBuilder sb) { String version = (String) b.getHeaders().get("Bundle-Version"); if (version == null) { version = ""; } sb.append(version); }
@JsonProperty public List<String> getBundleVersions() { Bundle[] bundles = ServiceUtility.getContext().getBundles(); List<String> versions = new ArrayList<>(); for (Bundle bundle : bundles) { String version = bundle.getHeaders().get("Bundle-Version"); String implVersion = bundle.getHeaders().get("Implementation-Version"); if (version != null && implVersion != null) { versions.add(String.format("%s_%s_%s", bundle.getSymbolicName(), version, implVersion)); } else if (version != null) { versions.add(String.format("%s_%s", bundle.getSymbolicName(), version)); } else { versions.add(String.format("%s", bundle.getSymbolicName())); } } Collections.sort(versions); return versions; }
/** Checks if an arbitrary bundle is a DeepaMehta plugin. */ private boolean isDeepaMehtaPlugin(Bundle bundle) { String packages = (String) bundle.getHeaders().get("Import-Package"); // Note 1: 3rd party bundles might not import any package. So, "packages" might be null. // Note 2: all DeepaMehta plugin bundles depend on de.deepamehta.core.osgi.PluginActivator so we // can // use that package for detection. The core bundle on the other hand does not import that // package. return packages != null && packages.contains("de.deepamehta.core.osgi"); }
public static List<ImportedPackage> getImportedPackages(Bundle bundle, Resolution resolution) { final List<ImportedPackage> result = new ArrayList<ImportedPackage>(); final BundleManifest manifest = BundleManifestFactory.createBundleManifest(bundle.getHeaders(), new DummyParserLogger()); for (ImportedPackage importedPackage : manifest.getImportPackage().getImportedPackages()) { if (resolution == null || resolution.equals(importedPackage.getResolution())) { result.add(importedPackage); } } return result; }