Refine search
/** * Lookup resource by given name. If OSGi runtime is detected and the originClass parameter is not null, * an attempt will be made to get the resource input stream via OSGi API from the bundle where originClass is included. * Otherwise (non OSGi environment) or if OSGi fails to provide the input stream, the return value * will be taken from the provided loader getResourceAsStream method. * * @param loader class loader where to lookup the resource in non-OSGi environment or if OSGi means fail. * @param originClass if not null, and OSGi environment is detected, the resource will be taken from the bundle including * the originClass type. * @param name filename of the desired resource. * @return an input stream corresponding to the required resource or null if the resource could not be found. */ public static InputStream getResourceAsStream(final ClassLoader loader, final Class<?> originClass, final String name) { try { if (bundleReferenceClass != null && originClass != null && bundleReferenceClass.isInstance(ReflectionHelper.class.getClassLoader())) { final Bundle bundle = FrameworkUtil.getBundle(originClass); final URL resourceUrl = (bundle != null) ? bundle.getEntry(name) : null; if (resourceUrl != null) { return resourceUrl.openStream(); } } } catch (final IOException ex) { // ignore } return loader.getResourceAsStream(name); }
private Filter getFilter() { if (appliedFilter == null) { try { appliedFilter = FrameworkUtil.createFilter(filter); } catch (InvalidSyntaxException e) { // we will return null } } return appliedFilter; } }
Bundle matchBundle = bundle != null ? bundle : other.bundle; String matchPattern = bundle != null ? other.pattern : pattern; Map<X509Certificate, List<X509Certificate>> signers = matchBundle.getSignerCertificates(Bundle.SIGNERS_TRUSTED); for (List<X509Certificate> signerCerts : signers.values()) { List<String> dnChain = new ArrayList<String>(signerCerts.size()); for (X509Certificate signerCert : signerCerts) { dnChain.add(signerCert.getSubjectDN().getName()); if (FrameworkUtil.matchDistinguishedNameChain(matchPattern, dnChain)) { return true;
BundleContext bundleContext = FrameworkUtil.getBundle(getClass()).getBundleContext(); Bundle bundle = bundleContext.getBundle(id); if (bundle != null) { String title = ShellUtil.getBundleName(bundle); ps.println("\n" + title); ps.println(ShellUtil.getUnderlineString(title)); URL bundleInfo = bundle.getEntry("OSGI-INF/bundle.info"); if (bundleInfo != null) { try (BufferedReader reader = new BufferedReader(new InputStreamReader(bundleInfo.openStream()))) { int maxSize = 80; Terminal terminal = session.getTerminal();
private static String getMavenCoordinates(long bundleId) { Bundle m_bundle = FrameworkUtil.getBundle(Logs.class).getBundleContext().getBundle(bundleId); if (m_bundle == null) { // Not sure why can't we find the bundleId? return null; } String id = Long.toString(m_bundle.getBundleId()) + ":" + Long.toString(m_bundle.getLastModified()); String maven = MAVEN_COORDINATES.get(id); if (maven == null) { try { Enumeration<URL> e = m_bundle.findEntries("META-INF/maven/", "pom.properties", true); StringBuilder buf = new StringBuilder(); while (e != null && e.hasMoreElements()) { URL url = e.nextElement(); MavenCoordinates.appendMavenCoordinateFromPomProperties(url.openStream(), buf); } maven = buf.toString(); } catch (Throwable t) { // Ignore maven = ""; } MAVEN_COORDINATES.put(id, maven); } return maven; }
/** * Since the docker-compose file is a resource in the bundle and docker-compose needs it. * in the file system, we copy it over - ugly but necessary. * @param yamlFileName File name * @return A File object for the newly created temporary yaml file. */ private File createTempDockerComposeFile(String yamlFileName) { Bundle bundle = FrameworkUtil.getBundle(this.getClass()); Assert.assertNotNull("DockerOvs: bundle is null", bundle); URL url = bundle.getResource(envDockerComposeFile); Assert.assertNotNull("DockerOvs: URL is null", url); File tmpFile = null; try { tmpFile = File.createTempFile("ovsdb-it-tmp-", null); try (Reader in = new InputStreamReader(url.openStream()); FileWriter out = new FileWriter(tmpFile)) { char[] buf = new char[1024]; int read; while (-1 != (read = in.read(buf))) { out.write(buf, 0, read); } } } catch (IOException e) { Assert.fail(e.toString()); } return tmpFile; }
private List<String> loadWhitelistExtension() { Enumeration<URL> entries = FrameworkUtil.getBundle(this.getClass()).findEntries("res", "whitelist.txt", false); if (entries != null && entries.hasMoreElements()) { URL url = entries.nextElement(); try (InputStream is = url.openStream()) { return readWhitelistEntries(is); } catch (IOException e) { logger.warn("Error reading REST extension whitelist from {}", url, e); return null; } } else { return null; } }
public Optional<File> resolveFile(final String filename) { final Bundle bundle = FrameworkUtil.getBundle(this.clazz); final File dataFile; URL jreArgumentEntry = bundle.getEntry(filename); if (jreArgumentEntry == null) { return Optional.empty(); dataFile = bundle.getDataFile(filename); if(dataFile.exists()) { dataFile.delete(); try (InputStream input = jreArgumentEntry.openStream()){ Files.copy(input, dataFile.toPath()); } catch(Exception exc) {
static Xnio doGetOsgiService() { Bundle bundle = FrameworkUtil.getBundle(Xnio.class); BundleContext context = bundle.getBundleContext(); if (context == null) { throw new IllegalStateException("Bundle not started"); } ServiceReference<Xnio> sr = context.getServiceReference(Xnio.class); if (sr == null) { return null; } return context.getService(sr); }
public Set<String> findResourceNames(String location, URL locationUrl) throws IOException { Set<String> resourceNames = new TreeSet<String>(); Bundle bundle = FrameworkUtil.getBundle(getClass()); @SuppressWarnings({"unchecked"}) Enumeration<URL> entries = bundle.findEntries(locationUrl.getPath(), "*", true); if (entries != null) { while (entries.hasMoreElements()) { URL entry = entries.nextElement(); String resourceName = getPathWithoutLeadingSlash(entry); resourceNames.add(resourceName); } } return resourceNames; }
public EventRegistryServiceImpl() { // Register this service with karaf BundleContext context = FrameworkUtil.getBundle(this.getClass()).getBundleContext(); nicEventServiceRegistration = context.registerService(EventRegistryService.class, this, null); }
@SuppressWarnings("unchecked") protected void init() { Bundle bundle = FrameworkUtil.getBundle(process.getClass()); LinkedList<String> classNames = new LinkedList<>(); // TODO iterate and parse .... like DefaultProcesLoader String start = process.getClass().getPackage().getName().replace('.', '/'); Enumeration<URL> enu = bundle.findEntries(start, "*.class", true); while (enu.hasMoreElements()) { URL url = enu.nextElement(); String name = url.getPath(); if (name.endsWith(".class") && name.indexOf('$') < 0) { if (name.startsWith("/")) name = name.substring(1); classNames.add(MString.beforeLastIndex(name,'.').replace('/', '.')); } } // load class and test if it's Element for (String name : classNames) { try { Class<?> clazz = bundle.loadClass(name); if (AElement.class.isAssignableFrom(clazz)) elementClasses.add((Class<? extends AElement<?>>) clazz); } catch (Throwable t) { log().w(name,t); } } }
public static Map<String,Boolean> getResources( Pattern pattern ) { Bundle bundle = FrameworkUtil.getBundle(ResourceMap.class); String base = bundle.getResource("META-INF/MANIFEST.MF").toExternalForm(); int prefix = base.indexOf("META-INF/MANIFEST.MF"); Map<String, Boolean> map = new HashMap<String, Boolean>(); for (Enumeration e = bundle.findEntries("", "*", true); e.hasMoreElements();) { String url = ((URL) e.nextElement()).toExternalForm(); url = url.substring(prefix); if (pattern.matcher(url).matches()) { map.put(url, true); } } return map; }
Bundle portletBundle = FrameworkUtil.getBundle(ConfigurationResourceProviderBase.class); BundleWiring bundleWiring = portletBundle.adapt(BundleWiring.class); Collection<String> resourceFilePaths = bundleWiring.listResources("META-INF/", resourceFilePattern, BundleWiring.LISTRESOURCES_RECURSE); resourceURLs = portletBundle.getResources(resourceFilePath); URI resourceURI = resourceURL.toURI(); resourceURIs.add(resourceURI);
@Override public String call() throws Exception { BundleContext context = FrameworkUtil.getBundle(getClass()).getBundleContext(); Bundle sysBundle = context.getBundle(0); return sysBundle.getSymbolicName() + "-" + sysBundle.getVersion(); } };
@Override public Framework getFramework(String felixCacheDir, boolean clean) { final Bundle bundle = FrameworkUtil.getBundle(Osgis.class); return (Framework) bundle.getBundleContext().getBundle(0); }
public String apply(Long value) { Bundle bundle = FrameworkUtil.getBundle(getClass()); Bundle target = bundle.getBundleContext().getBundle(value); return BundleState.fromState(target.getState()).name(); } }
private static <T> Iterable<T> lookupAllInOsgi(Class<T> clazz) { final List<T> result = new ArrayList<>(); final Bundle bundle = FrameworkUtil.getBundle(FrameworkLookup.class); if (bundle != null) { LOG.trace("Looking up all " + clazz.getSimpleName() + " in OSGI"); BundleContext ctx = bundle.getBundleContext(); for (ServiceReference<T> reference: getServiceReferences(clazz, ctx)) { result.add(ctx.getService(reference)); } } return result; }
/** * Get all bundle list of APP-C * @return Array of Bundle */ Bundle[] getBundleList() { BundleContext myBundleContext = FrameworkUtil.getBundle(this.getClass()).getBundleContext(); if (myBundleContext != null) { return myBundleContext.getBundles(); } return null; }
private String getProperty(String var, String def) { Bundle b = FrameworkUtil.getBundle(BgpManager.class); if (b == null) { return def; } BundleContext context = b.getBundleContext(); if (context == null) { return def; } String s = context.getProperty(var); return (s == null ? def : s); }