// Find files in the bundle without triggering resolve of it. private Enumeration<URL> findEntries( String baseDir, String fileNamePrefix, String fileNameSuffix) { Enumeration<URL> res; if (bundle.getState() == Bundle.INSTALLED) { final Enumeration<String> p = bundle.getEntryPaths(baseDir); if (p != null) { final Vector<URL> tmp = new Vector<URL>(); while (p.hasMoreElements()) { final String path = p.nextElement(); final int lastSlash = path.lastIndexOf('/'); if (lastSlash > 0) { final String name = path.substring(lastSlash) + 1; if (name.startsWith(fileNamePrefix) && name.endsWith(fileNameSuffix)) { tmp.addElement(bundle.getEntry(path)); } } } res = tmp.elements(); } else { res = null; } } else { res = bundle.findEntries(locBaseDir, fileNamePrefix + "*" + fileNameSuffix, false); } return res; }
/** * Populates the entries list with recursively found class entries. * * @param bundle The bundle to get class entries for. * @param entries The list to add the class entries to. * @param startPath The start path to look for entries. */ protected void collectClassEntries(Bundle bundle, List<Class> entries, String startPath) { Enumeration<String> entryPathEnumeration = bundle.getEntryPaths(startPath); while (entryPathEnumeration.hasMoreElements()) { String entryPath = entryPathEnumeration.nextElement(); if (entryPath.endsWith("/")) { collectClassEntries(bundle, entries, entryPath); } else if (entryPath.endsWith(".class")) { try { String classQName = entryPath.substring(0, entryPath.length() - 6).replace(File.separatorChar, '.'); if (classQName.startsWith("WEB-INF.classes.")) { classQName = classQName.substring(16); } Class entryClass = bundle.loadClass(classQName); // If not activatorMode is true then there will be classes in this list already on the // first // call to this method. Therefore we skip duplicates. if (!entries.contains(entryClass)) { entries.add(entryClass); } } catch (ClassNotFoundException cnfe) { this.activatorLogger.warn("Failed to load bundle class!", cnfe); } catch (NoClassDefFoundError ncdfe) { this.activatorLogger.warn("Failed to load bundle class!", ncdfe); } } } }
@Override public ResourceKeys findFolders(final ApplicationKey applicationKey, final String path) { ResourceKeys resourceKeys = null; final Application application = getActiveApplication(applicationKey); if (application != null) { Bundle bundle = application.getBundle(); final Enumeration<String> entryPaths = bundle.getEntryPaths(path); if (entryPaths != null) { final List<ResourceKey> resourceKeyList = Collections.list(entryPaths) .stream() .filter(entryPath -> entryPath.endsWith("/")) .map(entryPath -> ResourceKey.from(applicationKey, entryPath)) .collect(Collectors.toList()); resourceKeys = ResourceKeys.from(resourceKeyList); } } if (resourceKeys == null) { resourceKeys = ResourceKeys.empty(); } return resourceKeys; }
protected void registerLanguages(Bundle bundle, List<BaseService> resolvers) { if (checkCompat(bundle, Language.class)) { Map<String, String> languages = new HashMap<String, String>(); for (Enumeration e = bundle.getEntryPaths(META_INF_LANGUAGE); e != null && e.hasMoreElements(); ) { String path = (String) e.nextElement(); LOG.debug("Found entry: {} in bundle {}", path, bundle.getSymbolicName()); String name = path.substring(path.lastIndexOf("/") + 1); languages.put(name, path); } if (!languages.isEmpty()) { resolvers.add(new BundleLanguageResolver(bundle, languages)); } for (Enumeration e = bundle.getEntryPaths(META_INF_LANGUAGE_RESOLVER); e != null && e.hasMoreElements(); ) { String path = (String) e.nextElement(); LOG.debug("Found entry: {} in bundle {}", path, bundle.getSymbolicName()); String name = path.substring(path.lastIndexOf("/") + 1); resolvers.add(new BundleMetaLanguageResolver(bundle, name, path)); } } }
protected void registerDataFormats(Bundle bundle, List<BaseService> resolvers) { if (checkCompat(bundle, DataFormat.class)) { Map<String, String> dataformats = new HashMap<String, String>(); for (Enumeration e = bundle.getEntryPaths(META_INF_DATAFORMAT); e != null && e.hasMoreElements(); ) { String path = (String) e.nextElement(); LOG.debug("Found entry: {} in bundle {}", path, bundle.getSymbolicName()); String name = path.substring(path.lastIndexOf("/") + 1); dataformats.put(name, path); } if (!dataformats.isEmpty()) { resolvers.add(new BundleDataFormatResolver(bundle, dataformats)); } } }
@Override public List<String> getEntryPaths(long bundleId, String directory) { Bundle bundle = context.getBundle(bundleId); if (bundle == null) throw new IllegalStateException("bundle not found: " + bundleId); List<String> paths = new ArrayList<String>(); Enumeration<String> e = bundle.getEntryPaths(directory); if (e == null) { return paths; } while (e.hasMoreElements()) { paths.add(e.nextElement()); } return paths; }
/** * Imports resources from <code>bundleSourcePath</code> inside <code>bundle</code> into <code> * importTarget</code>. * * @param importTarget the parent container * @param bundle the bundle * @param bundleSourcePath the path to a folder containing resources * @throws CoreException import failed * @throws IOException import failed */ public static void importResources( IContainer importTarget, Bundle bundle, String bundleSourcePath) throws CoreException, IOException { Enumeration entryPaths = bundle.getEntryPaths(bundleSourcePath); while (entryPaths.hasMoreElements()) { String path = (String) entryPaths.nextElement(); IPath name = new Path(path.substring(bundleSourcePath.length())); if (path.endsWith("/")) { IFolder folder = importTarget.getFolder(name); folder.create(false, true, null); importResources(folder, bundle, path); } else { URL url = bundle.getEntry(path); IFile file = importTarget.getFile(name); file.create(url.openStream(), true, null); } } }
/** DOC ycbai Comment method "initializeSystemLibs". */ public void initializeSystemLibs() { if (!initialized) { ILibraryManagerService libManagerService = null; if (GlobalServiceRegister.getDefault().isServiceRegistered(ILibraryManagerService.class)) { libManagerService = (ILibraryManagerService) GlobalServiceRegister.getDefault().getService(ILibraryManagerService.class); } for (IConfigurationElement current : configurationElements) { String bundleName = current.getContributor().getName(); Bundle bundle = Platform.getBundle(bundleName); Enumeration entryPaths = bundle.getEntryPaths(LIB_FOLDER); if (entryPaths == null) { continue; } while (entryPaths.hasMoreElements()) { Object entryPath = entryPaths.nextElement(); if (entryPath != null && entryPath instanceof String) { String path = (String) entryPath; if (path.endsWith(FileExtensions.JAR_FILE_SUFFIX)) { URL entry = bundle.getEntry(path); if (entry != null && libManagerService != null) { try { URL fileUrl = FileLocator.toFileURL(entry); libManagerService.deploy(fileUrl.toURI()); } catch (Exception e) { log.warn("Cannot deploy: " + bundleName + path); continue; } } } } } } initialized = true; } }
/** * @param bundle * @param templateLocation */ @SuppressWarnings({"nls", "boxing", "unchecked"}) public void initializeFrom(Bundle bundle, String templateLocation) { Enumeration<String> list = bundle.getEntryPaths(templateLocation); if (list == null) { return; } // got some elements, look for "template.properties" int count = 0; while (list.hasMoreElements()) { String nextRoot = list.nextElement(); if (nextRoot.endsWith(BUNDLE_DIRECTORY) == false) { continue; } String nextEntry = nextRoot + TEMPLATE_PROPERTIES; // found another template URL nextURL = bundle.getEntry(nextEntry); if (nextURL == null) { // no such thing continue; } // looks like we have properties count += 1; Properties props = new Properties(); InputStream is = null; try { is = nextURL.openStream(); props.load(is); } catch (IOException e) { BPELUIPlugin.log(e); // skip to the next entry continue; } finally { try { is.close(); } catch (Throwable t) { } } String name = props.getProperty(PROPERTY_NAME); // No name, no game. if (name == null) { continue; } String enc = props.getProperty(PROPERTY_ENCODING, DEFAULT_ENCODING); String desc = props.getProperty(PROPERTY_DESCRIPTION, EMPTY); // add any namespaces we are supplying ... mNamespaceNames.addAll(findProperties(props, "namespace.{0}")); Template template = new Template(); template.mName = name; template.mDescription = desc; template.mProperties = (Map) props; mTemplateByName.put(name, template); String id = props.getProperty(PROPERTY_KEY); if (id != null) { // https://bugs.eclipse.org/bugs/show_bug.cgi?id=330813 // https://jira.jboss.org/browse/JBIDE-7165 template.mKey = id; mTemplateByKey.put(id, template); } int hole = 3; for (int i = 0; hole >= 0; i++) { String key = MessageFormat.format("resource.{0}", i); String resourceName = props.getProperty(key); if (resourceName == null) { hole--; continue; } hole = 3; key = MessageFormat.format("resource.{0}.name", i); String nameTemplate = props.getProperty(key); String entryLoc = nextRoot + resourceName; TemplateResource resource = new TemplateResource(); resource.mName = resourceName; resource.mContent = slurpContent(bundle.getEntry(entryLoc), enc); resource.mNameTemplate = nameTemplate; // add the resource which makes up this "template" template.add(resource); } } }