@Override public URL getEntry(String name) { return file.getEntry(name); }
/** * Read symbolic name. * * @param bf the bf * @return the string */ protected String readSymbolicName(BundleFile bf) { Manifest manifest = bf.getManifest(); if (manifest == null) { return null; } Attributes attrs = manifest.getMainAttributes(); String name = attrs.getValue("Bundle-SymbolicName"); if (name == null) { return null; } String[] sp = name.split(";", 2); return sp[0]; }
public void visitNestedBundles(BundleFile bundleFile) throws IOException { if (bundleFile instanceof NestedJarBundleFile) { return; // do not allows more than one level of nesting } if (extractNestedJARs) { Collection<BundleFile> bundles; if (scanForNestedJARs) { bundles = bundleFile.findNestedBundles(tmpDir); } else { // use manifest to find nested jars bundles = bundleFile.getNestedBundles(tmpDir); } if (bundles == null || bundles.isEmpty()) { return; } for (BundleFile bundle : bundles) { if (bundle.getSymbolicName() != null) { visitBundle(bundle); } else { visitJar(bundle); } } } } }
public Collection<BundleFile> extractNestedJars(BundleFile bf, File nestedBundlesDir) throws IOException { Collection<BundleFile> bundles = null; if (scanForNestedJARs) { bundles = bf.findNestedBundles(nestedBundlesDir); } else { // use manifest to find nested jars bundles = bf.getNestedBundles(nestedBundlesDir); } if (bundles != null && bundles.isEmpty()) { bundles = null; } return bundles; }
public void store(File file) throws IOException { BufferedWriter writer = null; try { writer = new BufferedWriter(new FileWriter(file)); for (BundleFile bf : bundles) { writer.append(bf.getFile().getAbsolutePath()); writer.newLine(); } writer.append("#"); writer.newLine(); for (BundleFile bf : jars) { writer.append(bf.getFile().getAbsolutePath()); writer.newLine(); } writer.append("#"); writer.newLine(); for (BundleFile bf : nestedJars) { writer.append(bf.getFile().getAbsolutePath()); writer.newLine(); } } finally { if (writer != null) { writer.close(); } } }
public BundleImpl(OSGiAdapter osgi, BundleFile file, ClassLoader loader, boolean isSystemBundle) throws BundleException { this.osgi = osgi; this.loader = loader; this.file = file; this.location = file.getLocation(); Manifest mf = file.getManifest(); if (mf == null) { headers = null; symbolicName = null; id = -1; context = null; return; } try { headers = BundleManifestReader.getHeaders(mf); } catch (BundleException e) { throw new BundleException("Invalid OSGi Manifest in file " + file + " : " + e.getMessage(), e); } symbolicName = headers.get(Constants.BUNDLE_SYMBOLICNAME); allowHostOverride = Boolean.parseBoolean(headers.get(BundleManifestReader.ALLOW_HOST_OVERRIDE)); id = isSystemBundle ? 0 : osgi.getBundleId(symbolicName); context = createContext(); state = UNINSTALLED; }
if (bf.getSymbolicName() == null) { // a regular jar nestedJARsDir = callback.handleJar(bf); } else { // an osgi bundle
@Override public Enumeration<String> getEntryPaths(String path) { return file.getEntryPaths(path); }
@Override public void uninstall() throws BundleException { osgi.uninstall(this); try { file.close(); } catch (IOException e) { throw new BundleException("Cannot close underlying file resources " + symbolicName, e); } }
@Override public Enumeration<URL> findEntries(String path, String filePattern, boolean recurse) { Enumeration<URL> hostEntries = file.findEntries(path, filePattern, recurse); Bundle[] fragments = osgi.getRegistry().getFragments(symbolicName); if (fragments.length == 0) { return hostEntries; } CompoundEnumerationBuilder builder = new CompoundEnumerationBuilder(); if (!allowHostOverride) { builder.add(hostEntries); } for (Bundle fragment : fragments) { Enumeration<URL> fragmentEntries = fragment.findEntries(path, filePattern, recurse); builder.add(fragmentEntries); } if (allowHostOverride) { builder.add(hostEntries); } return builder.build(); }
public static void writeCache(File file, List<BundleFile> bundles, List<BundleFile> jars) throws IOException { // write loaded bundles to the cache BufferedWriter writer = null; try { writer = new BufferedWriter(new FileWriter(file)); for (BundleFile bf : bundles) { writer.append(bf.getFile().getAbsolutePath()); writer.newLine(); } writer.append("#"); writer.newLine(); for (BundleFile bf : jars) { writer.append(bf.getFile().getAbsolutePath()); writer.newLine(); } } finally { if (writer != null) { writer.close(); } } }
@Override public int visitFile(File file) { // first check if this is a possible bundle String fileName = file.getName(); if (patterns != null) { if (!acceptFile(fileName, patterns)) { return FileWalker.CONTINUE; } } // check if this is an OSGi bundle try (JarFile jarFile = new JarFile(file)) { if (jarFile.getManifest() == null) { return FileWalker.CONTINUE; } BundleFile bundleFile = new JarBundleFile(jarFile); if (bundleFile.getSymbolicName() != null) { // notify the callback about the new bundle callback.visitBundle(bundleFile); } else { // notify the callback about the new jar callback.visitJar(bundleFile); } } catch (IOException e) { // ignore } return FileWalker.CONTINUE; }
File jarFile = nxBundle.getBundleFile().getFile(); if (jarFile == null) { return binfo;
@Override public void deployContrib(String name, String contrib) throws Exception { RuntimeContext context = runtime.getContext(name); if (context == null) { context = runtime.getContext(); BundleFile file = lookupBundle(name); URL location = file.getEntry(contrib); if (location == null) { throw new AssertionError("Cannot locate " + contrib + " in " + name); } context.deploy(location); } else { context.deploy(contrib); } }