Skip to main content



      Home
Home » Eclipse Projects » Equinox » Snippet of code to install/update a bundle
Snippet of code to install/update a bundle [message #37272] Fri, 12 March 2004 09:39 Go to next message
Eclipse UserFriend
/*
* Created on Mar 8, 2004
*
* To change the template for this generated file go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
import java.util.ArrayList;
import java.util.List;
import org.osgi.framework.*;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.service.packageadmin.PackageAdmin;

/**
* @author prapicault
*
* To change the template for this generated type comment go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
public class Test {
BundleContext context;
String location; //The location of the bundle to install. Because osgi
systematically copy,
//in eclispe implementation of osgi we introduced the concept of reference
url, reference:<URL> that prevent the installed plugin to be copied


private void installBundle() {
List toRefresh = getUnresolvedBundles(); //Get all unresolved bundles
Bundle target;
try {
target = context.installBundle(location);
toRefresh.add(target); // any new bundle should be refreshed as well
refreshPackages((Bundle[]) toRefresh.toArray(new
Bundle[toRefresh.size()])); //refresh all the bundles specified and their
dependents.
//If the unresolved bundles are not part of the list then they would not
detect the presence of a new budle that could satisfy some of their
constraints.
} catch (BundleException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


}
private List getUnresolvedBundles() {
Bundle[] allBundles = context.getBundles();
List unresolved = new ArrayList();
for (int i = 0; i < allBundles.length; i++)
if (allBundles[i].getState() == Bundle.INSTALLED)
unresolved.add(allBundles[i]);
return unresolved;
}

private void refreshPackages(Bundle[] bundles) {
if (bundles.length == 0)
return;
ServiceReference packageAdminRef =
context.getServiceReference(PackageAdmin.class.getName());
PackageAdmin packageAdmin = null;
if (packageAdminRef != null) {
packageAdmin = (PackageAdmin) context.getService(packageAdminRef);
if (packageAdmin == null)
return;
}

final boolean[] flag = new boolean[] {false};
FrameworkListener listener = new FrameworkListener() {
public void frameworkEvent(FrameworkEvent event) {
if (event.getType() == FrameworkEvent.PACKAGES_REFRESHED)
synchronized (flag) {
flag[0] = true;
flag.notifyAll();
}
}
};
context.addFrameworkListener(listener);
packageAdmin.refreshPackages(bundles);
synchronized (flag) {
while (!flag[0]) {
try {
flag.wait();
} catch (InterruptedException e) {
}
}
}
context.removeFrameworkListener(listener);
context.ungetService(packageAdminRef);
}

}


  • Attachment: Test.java
    (Size: 2.79KB, Downloaded 313 times)
Re: Snippet of code to install/update a bundle [message #37341 is a reply to message #37272] Fri, 12 March 2004 09:53 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: alexsmr.sympatico.ca

Thanks for the snippet Pascal.
Re: Snippet of code to install/update a bundle [message #37375 is a reply to message #37272] Fri, 12 March 2004 10:12 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: alexsmr.sympatico.ca

> target = context.installBundle(location);

So the difference between installBundle("<URL>") and
installBundle("reference:<URL>") is that
in the last case bundle will not be copied to local cache directory, but I
still have to create
temporary JAR file from "bundle under development" project? Is that correct?
Re: Snippet of code to install/update a bundle [message #37408 is a reply to message #37375] Fri, 12 March 2004 14:16 Go to previous messageGo to next message
Eclipse UserFriend
If you specify reference:file:d:/workspace/myBundle/
it will be fine if there is a bin folder under myBundle.

PaScaL

"Alex Smirnoff" <alexsmr@sympatico.ca> wrote in message
news:c2sjd5$bdr$1@eclipse.org...
> > target = context.installBundle(location);
>
> So the difference between installBundle("<URL>") and
> installBundle("reference:<URL>") is that
> in the last case bundle will not be copied to local cache directory, but I
> still have to create
> temporary JAR file from "bundle under development" project? Is that
correct?
>
>
Re: Snippet of code to install/update a bundle [message #37441 is a reply to message #37408] Fri, 12 March 2004 14:35 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: alexsmr.sympatico.ca

> If you specify reference:file:d:/workspace/myBundle/
> it will be fine if there is a bin folder under myBundle.

Then how framework will know where to look for Manifest and
where load the binaries? Will it parse

d:/workspace/myBundle/.project [and]
d:/workspace/myBundle/.classpath [and]

will it look for Manifest in d:/workspace/myBundle/META-INF?
Where I can find more info on this?
Re: Snippet of code to install/update a bundle [message #37474 is a reply to message #37441] Sat, 13 March 2004 09:55 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: pascal.ibm.canada

Nothing fancy is done.
It simply looks for META-INF and look for bin in d:/workspace/myBundle/.
You can get more info in looking at the code ;-)
EclipseBundleData and EclipseClassLoader are two good starting points.

PaScaL

Alex Smirnoff wrote:
>>If you specify reference:file:d:/workspace/myBundle/
>>it will be fine if there is a bin folder under myBundle.
>
>
> Then how framework will know where to look for Manifest and
> where load the binaries? Will it parse
>
> d:/workspace/myBundle/.project [and]
> d:/workspace/myBundle/.classpath [and]
>
> will it look for Manifest in d:/workspace/myBundle/META-INF?
> Where I can find more info on this?
>
>
Re: Snippet of code to install/update a bundle [message #37573 is a reply to message #37441] Sun, 14 March 2004 17:08 Go to previous message
Eclipse UserFriend
Originally posted by: jeff_mcaffer.REMOVE.ca.ibm.com

Doc is coming. Basically jars and directories are just different forms of
the same thing. Point the runtime at either and it is happy. Just for fun
you can also use a regular (non reference:) URL and point to a dir. That
copies the content of the dir into some local stash and runs from there.

And, no, .project and .classpath are development time entities. The runtime
does not know about them.

Jeff

"Alex Smirnoff" <alexsmr@sympatico.ca> wrote in message
news:c2t2qg$u2g$1@eclipse.org...
> > If you specify reference:file:d:/workspace/myBundle/
> > it will be fine if there is a bin folder under myBundle.
>
> Then how framework will know where to look for Manifest and
> where load the binaries? Will it parse
>
> d:/workspace/myBundle/.project [and]
> d:/workspace/myBundle/.classpath [and]
>
> will it look for Manifest in d:/workspace/myBundle/META-INF?
> Where I can find more info on this?
>
>
Previous Topic:Bundle provisioning
Next Topic:headless execution shutdown?
Goto Forum:
  


Current Time: Thu Jul 17 02:13:00 EDT 2025

Powered by FUDForum. Page generated in 0.30691 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top