@Test public void testNullSymbolicName() throws Exception { final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "null-symbolic-name"); archive.setManifest( new Asset() { public InputStream openStream() { OSGiManifestBuilder builder = OSGiManifestBuilder.newInstance(); builder.addBundleName(archive.getName()); return builder.openStream(); } }); Bundle bundle = installBundle(archive); try { assertBundleState(Bundle.INSTALLED, bundle.getState()); assertNull("Null symbolic name", bundle.getSymbolicName()); assertEquals("null-symbolic-name:0.0.0", bundle.toString()); bundle.start(); assertBundleState(Bundle.ACTIVE, bundle.getState()); } finally { bundle.uninstall(); assertBundleState(Bundle.UNINSTALLED, bundle.getState()); } }
/** * Go through the p-units in a given bundle and assign the ones that do not have a provider, or * have a provider specified as this one. * * @param b the bundle to look for p-units in */ public void tryAssigningPersistenceUnitsInBundle(Bundle b) { debug("Extender.tryAssigningPersistenceUnitsInBundle: ", b); // If we have already assigned it then bail if (isAssigned(b)) { warning("Attempted to assign a bundle that was already assigned: ", b.toString()); return; } // Look for all of the persistence descriptor files in the bundle List<PersistenceDescriptorInfo> descriptorInfos = bundleUtil.persistenceDescriptorInfos(b); if (descriptorInfos.isEmpty()) { // There were no descriptors specified in the manifest - check if there is any config from // config admin PersistenceUnitConfiguration config = mgr.getConfigAdminListener().configForBundle(b.getSymbolicName()); if (config != null) { // There is a config to go with this bundle. // Create a special descriptorInfo with the descriptor string right inside it debug("No persistence descriptors, but found a config for bundle ", b); descriptorInfos.add(new InlinedDescriptorInfo(config)); } else { // We can't assign it just yet. Add to the limbo list warning("No persistence descriptors found in persistence bundle ", b.getSymbolicName()); debug("Putting bundle ", b, " in limbo"); inLimbo.put(b.getSymbolicName(), b); // The bundle will be removed from being in limbo by the config admin listener when // a config comes along that contains the bsn of this bundle. It will then be refreshed. return; } } // Do a partial parse of the descriptors Set<PUnitInfo> pUnitInfos = bundleUtil.persistenceUnitInfoFromXmlFiles(descriptorInfos); // Cycle through each p-unit info and see if a provider was specified for (PUnitInfo info : pUnitInfos) { if ((info.getProvider() == null) || (EclipseLinkProvider.ECLIPSELINK_PROVIDER_CLASS_NAME.equals(info.getProvider()))) { // We can be the provider; claim the p-unit and add it to our list info.setBundle(b); info.setAssignedProvider(mgr.getProvider()); debug("Assigning punit ", info.getUnitName(), " to this provider"); addToBundleUnits(unitsByBundle, b, info); } } // If we found any that were for us then move on to do the preResolve work List<PUnitInfo> unitsFound = unitsByBundle.get(b); if ((unitsFound != null) && (unitsFound.size() != 0)) { mgr.preResolve(b, unitsByBundle.get(b)); } }
private String getNestedJarOrDir(Bundle bundle, String cp) { // try embeded entries first URL url = bundle.getEntry(cp); if (url != null) { try { return FileLocator.toFileURL(url).getFile(); } catch (IOException ex) { log.warn("Could not get entry {} for bundle {}", new Object[] {cp, bundle.toString(), ex}); } } // in development mode entries can be absolute paths outside of bundle basedir if (DevClassPathHelper.inDevelopmentMode()) { File file = new File(cp); if (file.exists() && file.isAbsolute()) { return file.getAbsolutePath(); } } log.debug("Bundle {} does not have entry {}", bundle.toString(), cp); return null; }
private String[] parseBundleClasspath(Bundle bundle) { String[] result = new String[] {"."}; String header = (String) bundle.getHeaders().get(Constants.BUNDLE_CLASSPATH); ManifestElement[] classpathEntries = null; try { classpathEntries = ManifestElement.parseHeader(Constants.BUNDLE_CLASSPATH, header); } catch (BundleException ex) { log.warn("Could not parse bundle classpath of {}", bundle.toString(), ex); } if (classpathEntries != null) { result = new String[classpathEntries.length]; for (int i = 0; i < classpathEntries.length; i++) { result[i] = classpathEntries[i].getValue(); } } return result; }
private void addBundleClasspathEntries(Set<String> entries, Bundle bundle) { log.debug("addBundleClasspathEntries(Bundle={})", bundle.toString()); Set<String> cp = new LinkedHashSet<String>(); if (DevClassPathHelper.inDevelopmentMode()) { cp.addAll(Arrays.asList(DevClassPathHelper.getDevClassPath(bundle.getSymbolicName()))); } cp.addAll(Arrays.asList(parseBundleClasspath(bundle))); for (String cpe : cp) { String entry; if (".".equals(cpe)) { entry = getNestedJarOrDir(bundle, "/"); } else { entry = getNestedJarOrDir(bundle, cpe); } if (entry != null) { log.debug("\tEntry:{}", entry); entries.add(entry); } } }