Ejemplo n.º 1
0
 /**
  * Undeploys a contribution from a given bundle.
  *
  * <p>The path will be relative to the bundle root. Example: <code>
  * undeployContrib("org.nuxeo.ecm.core", "OSGI-INF/CoreExtensions.xml")
  * </code>
  *
  * @param name the bundle
  * @param contrib the contribution
  */
 @Override
 public void undeployContrib(String name, String contrib) throws Exception {
   RuntimeContext context = runtime.getContext(name);
   if (context == null) {
     context = runtime.getContext();
   }
   context.undeploy(contrib);
 }
Ejemplo n.º 2
0
 protected URL getUrlFromPath(String path, RuntimeContext extensionContext) {
   if (path == null) {
     return null;
   }
   URL url = null;
   try {
     url = new URL(path);
   } catch (MalformedURLException e) {
     url = extensionContext.getLocalResource(path);
     if (url == null) {
       url = extensionContext.getResource(path);
     }
   }
   return url;
 }
Ejemplo n.º 3
0
 /**
  * Deploys a contribution from a given bundle.
  *
  * <p>The path will be relative to the bundle root. Example: <code>
  * deployContrib("org.nuxeo.ecm.core", "OSGI-INF/CoreExtensions.xml")
  * </code>
  *
  * <p>For compatibility reasons the name of the bundle may be a jar name, but this use is
  * discouraged and deprecated.
  *
  * @param name the name of the bundle to peek the contrib in
  * @param contrib the path to contrib in the bundle.
  */
 @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);
     return;
   }
   context.deploy(contrib);
 }
 protected void loadComponents(Bundle bundle, RuntimeContext ctx) throws Exception {
   String list = getComponentsList(bundle);
   String name = bundle.getSymbolicName();
   log.debug("Bundle: " + name + " components: " + list);
   if (list == null) {
     return;
   }
   StringTokenizer tok = new StringTokenizer(list, ", \t\n\r\f");
   while (tok.hasMoreTokens()) {
     String path = tok.nextToken();
     URL url = bundle.getEntry(path);
     log.debug("Loading component for: " + name + " path: " + path + " url: " + url);
     if (url != null) {
       try {
         ctx.deploy(url);
       } catch (Exception e) {
         // just log error to know where is the cause of the
         // exception
         log.error("Error deploying resource: " + url);
         Framework.handleDevError(e);
         throw e;
       }
     } else {
       String message = "Unknown component '" + path + "' referenced by bundle '" + name + "'";
       log.error(message + ". Check the MANIFEST.MF");
       Framework.handleDevError(null);
       warnings.add(message);
     }
   }
 }
 public Script getScript() throws Exception {
   if (rc != null) {
     URL url = rc.getBundle().getEntry(script);
     if (url == null) {
       // if not found using bundle entries try using classloader
       // in a test environment bundle entries may not work
       url = rc.getResource(script);
       if (url == null) {
         throw new Exception("Script Not found: " + script);
       }
     }
     return Script.newScript(url);
   } else {
     return Script.newScript(script);
   }
 }
 public Bundle findHostBundle(Bundle bundle) {
   String hostId = (String) bundle.getHeaders().get(Constants.FRAGMENT_HOST);
   log.debug("Looking for host bundle: " + bundle.getSymbolicName() + " host id: " + hostId);
   if (hostId != null) {
     int p = hostId.indexOf(';');
     if (p > -1) { // remove version or other extra information if any
       hostId = hostId.substring(0, p);
     }
     RuntimeContext ctx = contexts.get(hostId);
     if (ctx != null) {
       log.debug("Context was found for host id: " + hostId);
       return ctx.getBundle();
     } else {
       log.warn("No context found for host id: " + hostId);
     }
   }
   return null;
 }
 @Override
 public boolean uninstallContribution(Contribution contrib) {
   boolean ret = isInstalled(contrib);
   try {
     ctx.undeploy(contrib);
   } catch (IOException e) {
     throw new RuntimeServiceException(e);
   }
   return ret;
 }
 @Override
 public synchronized boolean installContribution(Contribution contrib) {
   RegistrationInfo ri;
   try {
     ri = ctx.deploy(contrib);
   } catch (IOException e) {
     throw new RuntimeServiceException(e);
   }
   if (ri == null) {
     return false;
   }
   ri.setPersistent(true);
   return true;
 }
 public synchronized void destroyContext(Bundle bundle) {
   RuntimeContext ctx = contexts.remove(bundle.getSymbolicName());
   if (ctx != null) {
     ctx.destroy();
   }
 }
 @Override
 public boolean isInstalled(Contribution contrib) {
   return ctx.isDeployed(contrib);
 }
Ejemplo n.º 11
0
 protected void deploy(String path) throws Exception {
   URL location = TestService.class.getResource("/".concat(path));
   rc.deploy(location);
 }
Ejemplo n.º 12
0
 @After
 public void undeploy() {
   rc.destroy();
   rc = null;
 }