Changeset 29876
- Timestamp:
- 02/02/08 18:15:30 (10 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
org.nuxeo.runtime/trunk/nuxeo-runtime-test/src/main/java/org/nuxeo/runtime/test/NXRuntimeTestCase.java
r28358 r29876 23 23 import java.net.URL; 24 24 import java.net.URLClassLoader; 25 import java.util.HashMap; 26 import java.util.HashSet; 27 import java.util.Set; 28 import java.util.jar.Attributes; 29 import java.util.jar.Manifest; 25 30 26 31 import org.apache.commons.logging.Log; … … 67 72 private StandaloneBundleLoader bundleLoader; 68 73 74 private Set<URL> readUrls; 75 76 private HashMap<String, BundleFile> bundles; 77 69 78 @Override 70 79 protected void setUp() throws Exception { … … 85 94 FileUtils.deleteTree(workingDir); 86 95 } 96 readUrls = null; 97 bundles = null; 87 98 super.tearDown(); 88 99 } … … 111 122 bundleLoader.setExtractNestedJARs(false); 112 123 113 BundleFile bundleFile = lookupBundle(" nuxeo-runtime");124 BundleFile bundleFile = lookupBundle("org.nuxeo.runtime"); 114 125 Bundle bundle = new RootRuntimeBundle(osgi, bundleFile, 115 126 bundleLoader.getClass().getClassLoader(), true); … … 149 160 } 150 161 log.debug(sb.toString()); 162 readUrls = new HashSet<URL>(); 163 bundles = new HashMap<String, BundleFile>(); 151 164 } 152 165 … … 194 207 /** 195 208 * Deploys a contribution file by looking for it in the class loader. 196 * 209 * <p>The first contribution file found by the class loader will be used. 210 * You have no guarantee in case of name collisions</p> 211 * 212 * @deprecated use the less ambiguous {@method deployContrib(bundleName, contrib)} 197 213 * @param contrib the relative path to the contribution file 198 214 */ 215 @Deprecated 199 216 public void deployContrib(String contrib) { 200 217 URL url = getResource(contrib); … … 289 306 /** 290 307 * Deploy a whole OSGI bundle. 291 * 292 * @param bundle the name of the bundle. 308 * <p>The lookup is first done on symbolic name, as set in <code>MANIFEST.MF</code> 309 * and then falls back to the bundle url (e.g., <code>nuxeo-platform-search-api</code>) 310 * for backwards compatibility. 311 * 312 * @param bundle the symbolic name 293 313 * @throws Exception 294 314 */ … … 299 319 } 300 320 301 protected BundleFile lookupBundle(String bundle) throws Exception { 321 protected String readSymbolicName(BundleFile bf) { 322 Manifest manifest = bf.getManifest(); 323 if (manifest == null) { 324 return null; 325 } 326 Attributes attrs = manifest.getMainAttributes(); 327 String name = (String) attrs.getValue("Bundle-SymbolicName"); 328 if (name == null) { 329 return null; 330 } 331 String[] sp = name.split(";", 2); 332 return sp[0]; 333 } 334 335 protected BundleFile lookupBundle(String bundleName) throws Exception { 336 BundleFile bundleFile = bundles.get(bundleName); 337 if (bundleFile != null) { 338 return bundleFile; 339 } 340 for (URL url: urls) { 341 if (readUrls.contains(url)) { 342 continue; 343 } 344 File file = new File(url.toURI()); 345 readUrls.add(url); 346 try { 347 if (file.isDirectory()) { 348 bundleFile = new DirectoryBundleFile(file); 349 } else { 350 bundleFile = new JarBundleFile(file); 351 } 352 } catch (IOException e) { 353 // no manifest => not a bundle 354 continue; 355 } 356 String symbolicName = readSymbolicName(bundleFile); 357 if (symbolicName != null) { 358 log.info(String.format("Bundle '%s' has URL %s", symbolicName, url)); 359 bundles.put(symbolicName, bundleFile); 360 } 361 if (bundleName.equals(symbolicName)) { 362 return bundleFile; 363 } 364 } 365 log.warn(String.format("No bundle with symbolic name '%s'; Falling back to deprecated url lookup scheme", bundleName)); 366 return oldLookupBundle(bundleName); 367 } 368 369 @Deprecated 370 protected BundleFile oldLookupBundle(String bundle) throws Exception { 302 371 URL url = lookupBundleUrl(bundle); 303 372 File file = new File(url.toURI()); 373 BundleFile bundleFile; 304 374 if (file.isDirectory()) { 305 returnnew DirectoryBundleFile(file);375 bundleFile = new DirectoryBundleFile(file); 306 376 } else { 307 return new JarBundleFile(file); 308 } 309 } 377 bundleFile = new JarBundleFile(file); 378 } 379 log.warn(String.format( 380 "URL-based bundle lookup is deprecated. Please use the symbolic name from MANIFEST (%s) instead", 381 readSymbolicName(bundleFile)) 382 ); 383 return bundleFile; 384 } 385 310 386 311 387 }
