JBoss-OSGI SVN: r99996 - in projects/jboss-osgi: projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/bundle and 2 other directories.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2010-01-27 08:47:50 -0500 (Wed, 27 Jan 2010)
New Revision: 99996
Modified:
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/bundle/BundleContextUnitTestCase.java
projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/client/ServiceLoaderClientActivator.java
projects/jboss-osgi/trunk/testsuite/example/src/test/resources/serviceloader/example-serviceloader-client.bnd
Log:
Improve serviceloader example
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java 2010-01-27 12:35:09 UTC (rev 99995)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java 2010-01-27 13:47:50 UTC (rev 99996)
@@ -115,8 +115,8 @@
private static String OSGi_FRAMEWORK_PROCESSOR;
/** The framework vendor */
private static String OSGi_FRAMEWORK_VENDOR = "jboss.org";
- /** The framework version */
- private static String OSGi_FRAMEWORK_VERSION = "r4v42";
+ /** The framework version. This is the version of the org.osgi.framework package in r4v42 */
+ private static String OSGi_FRAMEWORK_VERSION = "1.5";
/** The bundles by id */
private List<AbstractBundleState> allBundles = new CopyOnWriteArrayList<AbstractBundleState>();
/** The kernel */
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/bundle/BundleContextUnitTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/bundle/BundleContextUnitTestCase.java 2010-01-27 12:35:09 UTC (rev 99995)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/bundle/BundleContextUnitTestCase.java 2010-01-27 13:47:50 UTC (rev 99996)
@@ -184,7 +184,7 @@
bundle.start();
BundleContext bundleContext = bundle.getBundleContext();
assertNotNull(bundleContext);
- assertEquals("r4v42", bundleContext.getProperty(Constants.FRAMEWORK_VERSION));
+ assertEquals("1.5", bundleContext.getProperty(Constants.FRAMEWORK_VERSION));
assertEquals("jboss.org", bundleContext.getProperty(Constants.FRAMEWORK_VENDOR));
assertEquals(Locale.getDefault().getISO3Language(), bundleContext.getProperty(Constants.FRAMEWORK_LANGUAGE));
assertSystemProperty(bundleContext, "os.name", Constants.FRAMEWORK_OS_NAME);
Modified: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/client/ServiceLoaderClientActivator.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/client/ServiceLoaderClientActivator.java 2010-01-27 12:35:09 UTC (rev 99995)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/client/ServiceLoaderClientActivator.java 2010-01-27 13:47:50 UTC (rev 99996)
@@ -27,8 +27,12 @@
import org.jboss.test.osgi.example.serviceloader.service.AccountService;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Filter;
+import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
+import org.osgi.util.tracker.ServiceTracker;
/**
* A Service Activator
@@ -38,17 +42,30 @@
*/
public class ServiceLoaderClientActivator implements BundleActivator
{
+ private AccountService service;
+
+ // Note, the example-serviceloader-impl does NOT register the service itself.
+ // Instead, jboss-osgi-serviceloader generically registeres all services in META-INF/services
public void start(BundleContext context)
{
// Use the traditional ServiceLoader API to get the service
- AccountService service = ServiceLoader.loadService(AccountService.class);
+ service = ServiceLoader.loadService(AccountService.class);
if (service != null)
throw new IllegalStateException("Traditional ServiceLoader API, expected to fail");
-
- // Get the registered service.
- // Note, the example-serviceloader-impl does NOT register the service itself.
- // Instead, jboss-osgi-serviceloader generically registeres all services in META-INF/services
-
+
+ checkStaticServiceAccess(context);
+
+ checkDynamicServiceAccess(context);
+ }
+
+ public void stop(BundleContext context)
+ {
+ if (service == null)
+ throw new IllegalStateException("ServiceTracker could not obtain the service");
+ }
+
+ private void checkStaticServiceAccess(BundleContext context)
+ {
ServiceReference[] srefs = null;
try
{
@@ -61,11 +78,31 @@
}
if (srefs == null || srefs.length != 1)
throw new IllegalStateException("Cannot obtain service");
-
- service = (AccountService)context.getService(srefs[0]);
}
- public void stop(BundleContext context)
+ private void checkDynamicServiceAccess(BundleContext context)
{
+ Filter filter = null;
+ try
+ {
+ String filterstr = "(&(" + Constants.OBJECTCLASS + "=" + AccountService.class.getName() + ")(version=1.0.0))";
+ filter = FrameworkUtil.createFilter(filterstr);
+ }
+ catch (InvalidSyntaxException ex)
+ {
+ throw new IllegalStateException(ex);
+ }
+
+ // Track the service
+ ServiceTracker tracker = new ServiceTracker(context, filter, null)
+ {
+ public Object addingService(ServiceReference reference)
+ {
+ service = (AccountService)super.addingService(reference);
+ return service;
+ }
+ };
+ tracker.open();
}
+
}
\ No newline at end of file
Modified: projects/jboss-osgi/trunk/testsuite/example/src/test/resources/serviceloader/example-serviceloader-client.bnd
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/resources/serviceloader/example-serviceloader-client.bnd 2010-01-27 12:35:09 UTC (rev 99995)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/resources/serviceloader/example-serviceloader-client.bnd 2010-01-27 13:47:50 UTC (rev 99996)
@@ -2,6 +2,6 @@
Bundle-SymbolicName: example-serviceloader-client
Bundle-Activator: org.jboss.test.osgi.example.serviceloader.client.ServiceLoaderClientActivator
-Import-Package: org.osgi.framework, org.jboss.osgi.spi.util, org.jboss.test.osgi.example.serviceloader.service
+Import-Package: org.osgi.framework, org.osgi.util.tracker, org.jboss.osgi.spi.util, org.jboss.test.osgi.example.serviceloader.service
Private-Package: org.jboss.test.osgi.example.serviceloader.client
16 years, 4 months
JBoss-OSGI SVN: r99988 - in projects/jboss-osgi/trunk/testsuite/example/src/test: java/org/jboss/test/osgi/example/serviceloader/client and 1 other directories.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2010-01-27 06:09:26 -0500 (Wed, 27 Jan 2010)
New Revision: 99988
Modified:
projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/ServiceLoaderTestCase.java
projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/client/ServiceLoaderClientActivator.java
projects/jboss-osgi/trunk/testsuite/example/src/test/resources/serviceloader/example-serviceloader-api.bnd
projects/jboss-osgi/trunk/testsuite/example/src/test/resources/serviceloader/example-serviceloader-impl.bnd
Log:
Use version attribute in service lookup
Modified: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/ServiceLoaderTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/ServiceLoaderTestCase.java 2010-01-27 11:08:44 UTC (rev 99987)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/ServiceLoaderTestCase.java 2010-01-27 11:09:26 UTC (rev 99988)
@@ -87,8 +87,9 @@
OSGiBundle clientBundle = runtime.installBundle("example-serviceloader-client.jar");
clientBundle.start();
- OSGiServiceReference sref = runtime.getServiceReference(AccountService.class.getName());
- assertNotNull("AccountService available", sref);
+ OSGiServiceReference[] srefs = runtime.getServiceReferences(AccountService.class.getName(), "(version=1.0.0)");
+ assertNotNull("AccountService available", srefs);
+ assertEquals("One AccountService available", 1, srefs.length);
assertBundleState(Bundle.ACTIVE, implBundle.getState());
assertBundleState(Bundle.ACTIVE, clientBundle.getState());
Modified: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/client/ServiceLoaderClientActivator.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/client/ServiceLoaderClientActivator.java 2010-01-27 11:08:44 UTC (rev 99987)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/client/ServiceLoaderClientActivator.java 2010-01-27 11:09:26 UTC (rev 99988)
@@ -27,6 +27,7 @@
import org.jboss.test.osgi.example.serviceloader.service.AccountService;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
/**
@@ -46,9 +47,22 @@
// Get the registered service.
// Note, the example-serviceloader-impl does NOT register the service itself.
- // Instead, jboss-osgi-serviceloader generically registeres all services in META-INF/services
- ServiceReference sref = context.getServiceReference(AccountService.class.getName());
- service = (AccountService)context.getService(sref);
+ // Instead, jboss-osgi-serviceloader generically registeres all services in META-INF/services
+
+ ServiceReference[] srefs = null;
+ try
+ {
+ String filter = "(version=1.0.0)";
+ srefs = context.getServiceReferences(AccountService.class.getName(), filter);
+ }
+ catch (InvalidSyntaxException ex)
+ {
+ // ignore
+ }
+ if (srefs == null || srefs.length != 1)
+ throw new IllegalStateException("Cannot obtain service");
+
+ service = (AccountService)context.getService(srefs[0]);
}
public void stop(BundleContext context)
Modified: projects/jboss-osgi/trunk/testsuite/example/src/test/resources/serviceloader/example-serviceloader-api.bnd
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/resources/serviceloader/example-serviceloader-api.bnd 2010-01-27 11:08:44 UTC (rev 99987)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/resources/serviceloader/example-serviceloader-api.bnd 2010-01-27 11:09:26 UTC (rev 99988)
@@ -2,5 +2,5 @@
Bundle-SymbolicName: example-serviceloader-api
-Export-Package: org.jboss.test.osgi.example.serviceloader.service
+Export-Package: org.jboss.test.osgi.example.serviceloader.service;version="1.0.0"
Modified: projects/jboss-osgi/trunk/testsuite/example/src/test/resources/serviceloader/example-serviceloader-impl.bnd
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/resources/serviceloader/example-serviceloader-impl.bnd 2010-01-27 11:08:44 UTC (rev 99987)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/resources/serviceloader/example-serviceloader-impl.bnd 2010-01-27 11:09:26 UTC (rev 99988)
@@ -1,8 +1,8 @@
# bnd build -classpath target/test-classes -output target/test-libs/example-serviceloader-impl.jar src/test/resources/example/serviceloader/example-serviceloader-impl.bnd
Bundle-SymbolicName: example-serviceloader-impl
-
-Import-Package: org.jboss.test.osgi.example.serviceloader.service
+Bundle-Version: 1.0.0
+Import-Package: org.jboss.test.osgi.example.serviceloader.service;version="[1.0,2.0)"
Private-Package: org.jboss.test.osgi.example.serviceloader.service.internal
Include-Resource: META-INF/services/org.jboss.test.osgi.example.serviceloader.service.AccountService=../META-INF/services/org.jboss.test.osgi.example.serviceloader.service.AccountService
16 years, 4 months
JBoss-OSGI SVN: r99987 - projects/jboss-osgi/projects/bundles/serviceloader/trunk/src/main/java/org/jboss/osgi/serviceloader/internal.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2010-01-27 06:08:44 -0500 (Wed, 27 Jan 2010)
New Revision: 99987
Modified:
projects/jboss-osgi/projects/bundles/serviceloader/trunk/src/main/java/org/jboss/osgi/serviceloader/internal/ServiceLoaderInterceptor.java
Log:
Add a version attribute for registered services
Modified: projects/jboss-osgi/projects/bundles/serviceloader/trunk/src/main/java/org/jboss/osgi/serviceloader/internal/ServiceLoaderInterceptor.java
===================================================================
--- projects/jboss-osgi/projects/bundles/serviceloader/trunk/src/main/java/org/jboss/osgi/serviceloader/internal/ServiceLoaderInterceptor.java 2010-01-27 11:05:46 UTC (rev 99986)
+++ projects/jboss-osgi/projects/bundles/serviceloader/trunk/src/main/java/org/jboss/osgi/serviceloader/internal/ServiceLoaderInterceptor.java 2010-01-27 11:08:44 UTC (rev 99987)
@@ -27,6 +27,7 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Enumeration;
+import java.util.Hashtable;
import org.jboss.osgi.deployment.interceptor.AbstractLifecycleInterceptor;
import org.jboss.osgi.deployment.interceptor.InvocationContext;
@@ -36,6 +37,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import aQute.lib.osgi.Constants;
+
/**
* An interceptor that registeres service defained in META-INF/services.
*
@@ -102,7 +105,9 @@
// Register the service instance
Object serviceInstance = implClass.newInstance();
BundleContext bundleContext = bundle.getBundleContext();
- bundleContext.registerService(serviceName, serviceInstance, null);
+ Hashtable<String, String> props = new Hashtable<String, String>();
+ props.put(Constants.VERSION_ATTRIBUTE, bundle.getVersion().toString());
+ bundleContext.registerService(serviceName, serviceInstance, props);
}
implClassName = br.readLine();
16 years, 4 months
JBoss-OSGI SVN: r99985 - projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/webapp.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2010-01-27 05:49:00 -0500 (Wed, 27 Jan 2010)
New Revision: 99985
Modified:
projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/webapp/WebAppExtenderTestCase.java
Log:
[JBOSGI-283] WebApp extender not installed by default
Modified: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/webapp/WebAppExtenderTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/webapp/WebAppExtenderTestCase.java 2010-01-27 10:19:20 UTC (rev 99984)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/webapp/WebAppExtenderTestCase.java 2010-01-27 10:49:00 UTC (rev 99985)
@@ -53,6 +53,7 @@
runtime = osgiTestHelper.getDefaultRuntime();
runtime.addCapability(new HttpServiceCapability());
+ runtime.installBundle("bundles/pax-web-extender-war.jar").start();
runtime.installBundle("example-webapp.war").start();
}
16 years, 4 months
JBoss-OSGI SVN: r99984 - projects/jboss-osgi/trunk/distribution/installer/src/main/resources/installer.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2010-01-27 05:19:20 -0500 (Wed, 27 Jan 2010)
New Revision: 99984
Modified:
projects/jboss-osgi/trunk/distribution/installer/src/main/resources/installer/install-definition.xml
Log:
[JBOSGI-283] WebApp extender not installed by default
Modified: projects/jboss-osgi/trunk/distribution/installer/src/main/resources/installer/install-definition.xml
===================================================================
--- projects/jboss-osgi/trunk/distribution/installer/src/main/resources/installer/install-definition.xml 2010-01-27 10:18:45 UTC (rev 99983)
+++ projects/jboss-osgi/trunk/distribution/installer/src/main/resources/installer/install-definition.xml 2010-01-27 10:19:20 UTC (rev 99984)
@@ -427,6 +427,7 @@
<fileset condition="isFelix" dir="@{deploy.artifacts.dir}/lib" targetdir="${jbossInstallPath}/server/${jbossTargetServer}/deploy/osgi" override="true">
<include name="org.apache.felix.configadmin.jar" />
<include name="org.apache.felix.metatype.jar" />
+ <include name="pax-web-extender-war.jar" />
</fileset>
<fileset condition="isFelix" dir="@{deploy.artifacts.dir}/lib/org.osgi" targetdir="${jbossInstallPath}/server/${jbossTargetServer}/deploy/osgi"
override="true">
@@ -434,7 +435,6 @@
</fileset>
<fileset condition="isFelix" dir="@{deploy.artifacts.dir}/resources/jbossas" targetdir="${jbossInstallPath}/server/${jbossTargetServer}/deploy/osgi" override="true">
<include name="microcontainer-service-jboss-beans.xml" />
- <include name="pax-web-extender-war.jar" />
</fileset>
<!-- Equinox Integration -->
@@ -452,10 +452,10 @@
<include name="org.apache.felix.metatype.jar" />
<include name="org.eclipse.osgi.services.jar" />
<include name="org.eclipse.osgi.util.jar" />
+ <include name="pax-web-extender-war.jar" />
</fileset>
<fileset condition="isEquinox" dir="@{deploy.artifacts.dir}/resources/jbossas" targetdir="${jbossInstallPath}/server/${jbossTargetServer}/deploy/osgi" override="true">
<include name="microcontainer-service-jboss-beans.xml" />
- <include name="pax-web-extender-war.jar" />
</fileset>
<!-- JBossMC Integration -->
16 years, 4 months
JBoss-OSGI SVN: r99983 - projects/jboss-osgi/projects/runtime/deployers/trunk/src/main/java/org/jboss/osgi/deployer.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2010-01-27 05:18:45 -0500 (Wed, 27 Jan 2010)
New Revision: 99983
Modified:
projects/jboss-osgi/projects/runtime/deployers/trunk/src/main/java/org/jboss/osgi/deployer/BundleMetaData.java
projects/jboss-osgi/projects/runtime/deployers/trunk/src/main/java/org/jboss/osgi/deployer/BundleMetaDataDeployer.java
projects/jboss-osgi/projects/runtime/deployers/trunk/src/main/java/org/jboss/osgi/deployer/BundleRealDeployer.java
Log:
Fix duplicate bundle installation
Modified: projects/jboss-osgi/projects/runtime/deployers/trunk/src/main/java/org/jboss/osgi/deployer/BundleMetaData.java
===================================================================
--- projects/jboss-osgi/projects/runtime/deployers/trunk/src/main/java/org/jboss/osgi/deployer/BundleMetaData.java 2010-01-27 10:00:11 UTC (rev 99982)
+++ projects/jboss-osgi/projects/runtime/deployers/trunk/src/main/java/org/jboss/osgi/deployer/BundleMetaData.java 2010-01-27 10:18:45 UTC (rev 99983)
@@ -24,6 +24,7 @@
//$Id$
import org.jboss.deployers.vfs.spi.deployer.helpers.AbstractManifestMetaData;
+import org.osgi.framework.Version;
/**
* The Bundle metadata.
@@ -34,7 +35,8 @@
public class BundleMetaData extends AbstractManifestMetaData
{
private String symbolicName;
- private String bundleLocation;
+ private Version version;
+ private String location;
// exteralizable usage
public BundleMetaData()
@@ -51,18 +53,28 @@
return symbolicName;
}
- public String getBundleLocation()
+ public Version getVersion()
{
- return bundleLocation;
+ return version;
}
- public void setBundleLocation(String bundleLocation)
+ public void setVersion(Version version)
{
- this.bundleLocation = bundleLocation;
+ this.version = version;
}
+ public String getLocation()
+ {
+ return location;
+ }
+
+ public void setLocation(String location)
+ {
+ this.location = location;
+ }
+
public String toString()
{
- return "Bundle[name=" + symbolicName + "]";
+ return "Bundle[" + symbolicName + "-" + version + "]";
}
}
Modified: projects/jboss-osgi/projects/runtime/deployers/trunk/src/main/java/org/jboss/osgi/deployer/BundleMetaDataDeployer.java
===================================================================
--- projects/jboss-osgi/projects/runtime/deployers/trunk/src/main/java/org/jboss/osgi/deployer/BundleMetaDataDeployer.java 2010-01-27 10:00:11 UTC (rev 99982)
+++ projects/jboss-osgi/projects/runtime/deployers/trunk/src/main/java/org/jboss/osgi/deployer/BundleMetaDataDeployer.java 2010-01-27 10:18:45 UTC (rev 99983)
@@ -32,11 +32,12 @@
import org.jboss.osgi.spi.OSGiConstants;
import org.jboss.virtual.VirtualFile;
import org.osgi.framework.Constants;
+import org.osgi.framework.Version;
/**
* Create {@link BundleMetaData} from Manifest Headers.
*
- * If the manifest does not contain a header (named "Bundle-SymbolicName") this deployer does nothing.
+ * If the manifest does not contain a header Bundle-SymbolicName this deployer does nothing.
*
* @author Thomas.Diesler(a)jboss.org
* @since 03-Feb-2009
@@ -60,7 +61,7 @@
Deployment dep = unit.getAttachment(Deployment.class);
String location = (dep != null ? dep.getLocation() : unit.getName());
- metaData.setBundleLocation(location);
+ metaData.setLocation(location);
// Add a marker that this is an OSGi deployment
unit.addAttachment(OSGiConstants.KEY_BUNDLE_SYMBOLIC_NAME, symbolicName);
@@ -71,11 +72,16 @@
@Override
protected BundleMetaData createMetaData(Manifest manifest) throws Exception
{
+ BundleMetaData metaData = null;
Attributes attribs = manifest.getMainAttributes();
String symbolicName = attribs.getValue(Constants.BUNDLE_SYMBOLICNAME);
if (symbolicName != null)
- return new BundleMetaData(symbolicName);
+ {
+ metaData = new BundleMetaData(symbolicName);
+ String version = attribs.getValue(Constants.BUNDLE_VERSION);
+ metaData.setVersion(Version.parseVersion(version));
+ }
- return null;
+ return metaData;
}
}
Modified: projects/jboss-osgi/projects/runtime/deployers/trunk/src/main/java/org/jboss/osgi/deployer/BundleRealDeployer.java
===================================================================
--- projects/jboss-osgi/projects/runtime/deployers/trunk/src/main/java/org/jboss/osgi/deployer/BundleRealDeployer.java 2010-01-27 10:00:11 UTC (rev 99982)
+++ projects/jboss-osgi/projects/runtime/deployers/trunk/src/main/java/org/jboss/osgi/deployer/BundleRealDeployer.java 2010-01-27 10:18:45 UTC (rev 99983)
@@ -23,6 +23,7 @@
//$Id$
+import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
@@ -69,17 +70,31 @@
public void deploy(DeploymentUnit unit, BundleMetaData metadata) throws DeploymentException
{
- String location = metadata.getBundleLocation();
+ String location = metadata.getLocation();
if (location == null)
throw new IllegalStateException("Cannot obtain bundle location for: " + metadata);
+ // Normalize the bundle install path
+ String path = location;
try
{
+ URL url = new URL(location);
+ path = url.getPath();
+ if (path.endsWith("/"))
+ path = path.substring(0, path.length() - 1);
+ }
+ catch (MalformedURLException ex)
+ {
+ // ignore
+ }
+
+ try
+ {
boolean skipBundle = false;
for (URL skip : skipBundles)
{
String skipPath = skip.getPath();
- if (skipPath.equals(location))
+ if (skipPath.equals(path))
{
skipBundle = true;
break;
@@ -89,7 +104,6 @@
{
Bundle bundle = systemContext.installBundle(location);
unit.addAttachment(Bundle.class, bundle);
-
log.info("Installed: " + bundle);
}
}
16 years, 4 months
JBoss-OSGI SVN: r99981 - in projects/jboss-osgi/trunk: testsuite/example and 1 other directories.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2010-01-27 04:33:11 -0500 (Wed, 27 Jan 2010)
New Revision: 99981
Modified:
projects/jboss-osgi/trunk/distribution/installer/src/main/resources/installer/install-definition.xml
projects/jboss-osgi/trunk/testsuite/example/pom.xml
projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/webapp/WebAppExtenderTestCase.java
Log:
[JBOSGI-283] WebApp extender not installed by default
Modified: projects/jboss-osgi/trunk/distribution/installer/src/main/resources/installer/install-definition.xml
===================================================================
--- projects/jboss-osgi/trunk/distribution/installer/src/main/resources/installer/install-definition.xml 2010-01-27 06:37:36 UTC (rev 99980)
+++ projects/jboss-osgi/trunk/distribution/installer/src/main/resources/installer/install-definition.xml 2010-01-27 09:33:11 UTC (rev 99981)
@@ -270,6 +270,12 @@
<fileset condition="isFelix" dir="@{deploy.artifacts.dir}/lib/org.osgi" targetdir="$INSTALL_PATH/runtime/server/minimal/deploy" override="true">
<include name="org.osgi.compendium.jar" />
</fileset>
+ <fileset condition="isFelix" dir="@{deploy.artifacts.dir}/lib" targetdir="$INSTALL_PATH/runtime/server/web/deploy" override="true">
+ <include name="pax-web-extender-war.jar" />
+ </fileset>
+ <fileset condition="isFelix" dir="@{deploy.artifacts.dir}/lib" targetdir="$INSTALL_PATH/runtime/server/all/deploy" override="true">
+ <include name="pax-web-extender-war.jar" />
+ </fileset>
<!-- Equinox Integration -->
@@ -291,6 +297,12 @@
<include name="org.eclipse.osgi.services.jar" />
<include name="org.eclipse.osgi.util.jar" />
</fileset>
+ <fileset condition="isEquinox" dir="@{deploy.artifacts.dir}/lib" targetdir="$INSTALL_PATH/runtime/server/web/deploy" override="true">
+ <include name="pax-web-extender-war.jar" />
+ </fileset>
+ <fileset condition="isEquinox" dir="@{deploy.artifacts.dir}/lib" targetdir="$INSTALL_PATH/runtime/server/all/deploy" override="true">
+ <include name="pax-web-extender-war.jar" />
+ </fileset>
<!-- JBossMC Integration -->
@@ -422,6 +434,7 @@
</fileset>
<fileset condition="isFelix" dir="@{deploy.artifacts.dir}/resources/jbossas" targetdir="${jbossInstallPath}/server/${jbossTargetServer}/deploy/osgi" override="true">
<include name="microcontainer-service-jboss-beans.xml" />
+ <include name="pax-web-extender-war.jar" />
</fileset>
<!-- Equinox Integration -->
@@ -442,6 +455,7 @@
</fileset>
<fileset condition="isEquinox" dir="@{deploy.artifacts.dir}/resources/jbossas" targetdir="${jbossInstallPath}/server/${jbossTargetServer}/deploy/osgi" override="true">
<include name="microcontainer-service-jboss-beans.xml" />
+ <include name="pax-web-extender-war.jar" />
</fileset>
<!-- JBossMC Integration -->
Modified: projects/jboss-osgi/trunk/testsuite/example/pom.xml
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/pom.xml 2010-01-27 06:37:36 UTC (rev 99980)
+++ projects/jboss-osgi/trunk/testsuite/example/pom.xml 2010-01-27 09:33:11 UTC (rev 99981)
@@ -187,6 +187,7 @@
<!-- Functionality not supported in Equinox -->
<exclude>org/jboss/test/osgi/example/interceptor/**</exclude>
<exclude>org/jboss/test/osgi/example/microcontainer/**</exclude>
+ <exclude>org/jboss/test/osgi/example/serviceloader/**</exclude>
<exclude>org/jboss/test/osgi/example/webapp/WebAppNegativeTestCase.class</exclude>
<exclude>org/jboss/test/osgi/example/webapp/WebAppInterceptorTestCase.class</exclude>
</excludes>
@@ -241,6 +242,7 @@
<!-- Functionality not supported in Felix -->
<exclude>org/jboss/test/osgi/example/interceptor/**</exclude>
<exclude>org/jboss/test/osgi/example/microcontainer/**</exclude>
+ <exclude>org/jboss/test/osgi/example/serviceloader/**</exclude>
</excludes>
</configuration>
</plugin>
Modified: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/webapp/WebAppExtenderTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/webapp/WebAppExtenderTestCase.java 2010-01-27 06:37:36 UTC (rev 99980)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/webapp/WebAppExtenderTestCase.java 2010-01-27 09:33:11 UTC (rev 99981)
@@ -53,9 +53,6 @@
runtime = osgiTestHelper.getDefaultRuntime();
runtime.addCapability(new HttpServiceCapability());
-
- runtime.installBundle("bundles/pax-web-extender-war.jar").start();
-
runtime.installBundle("example-webapp.war").start();
}
16 years, 4 months
JBoss-OSGI SVN: r99951 - in projects/jboss-osgi/projects/runtime/framework/trunk: src/main/java/org/jboss/osgi/framework/classloading and 1 other directories.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2010-01-26 12:24:26 -0500 (Tue, 26 Jan 2010)
New Revision: 99951
Modified:
projects/jboss-osgi/projects/runtime/framework/trunk/pom.xml
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiClassLoaderPolicy.java
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/OSGiFragmentAttachmentDeployer.java
Log:
Remove fragment support in VFSClassLoaderPolicy
Promote VirtualFileInfo to top level
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/pom.xml
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/pom.xml 2010-01-26 17:12:25 UTC (rev 99950)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/pom.xml 2010-01-26 17:24:26 UTC (rev 99951)
@@ -47,7 +47,7 @@
<version.apache.felix.log>1.0.0</version.apache.felix.log>
<version.apache.felix.metatype>1.0.2</version.apache.felix.metatype>
<version.drools>5.0.1</version.drools>
- <version.jboss.classloading>2.0.9-SNAPSHOT</version.jboss.classloading>
+ <version.jboss.classloading>2.2.0-SNAPSHOT</version.jboss.classloading>
<version.jboss.deployers>2.2.0.Alpha1</version.jboss.deployers>
<version.jboss.kernel>2.2.0.Alpha2</version.jboss.kernel>
<version.jboss.osgi.apache.xerces>2.9.1.SP3</version.jboss.osgi.apache.xerces>
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiClassLoaderPolicy.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiClassLoaderPolicy.java 2010-01-26 17:12:25 UTC (rev 99950)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiClassLoaderPolicy.java 2010-01-26 17:24:26 UTC (rev 99951)
@@ -29,11 +29,14 @@
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Date;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
import org.jboss.classloader.spi.NativeLibraryProvider;
import org.jboss.classloading.spi.dependency.Module;
import org.jboss.classloading.spi.metadata.ClassLoadingMetaData;
import org.jboss.classloading.spi.vfs.policy.VFSClassLoaderPolicy;
+import org.jboss.classloading.spi.vfs.policy.VirtualFileInfo;
import org.jboss.deployers.structure.spi.DeploymentUnit;
import org.jboss.osgi.framework.bundle.AbstractBundleState;
import org.jboss.osgi.framework.bundle.AbstractDeployedBundleState;
@@ -53,6 +56,9 @@
*/
public class OSGiClassLoaderPolicy extends VFSClassLoaderPolicy
{
+ /** The fragment roots */
+ private List<VirtualFile> fragments;
+
public OSGiClassLoaderPolicy(AbstractBundleState absBundleState, VirtualFile[] roots)
{
super(roots);
@@ -127,6 +133,76 @@
}
/**
+ * Attach a new fragment root to the policy.
+ * @param fragRoot The fragment root file
+ */
+ public void attachFragment(VirtualFile fragRoot)
+ {
+ if (fragRoot == null)
+ throw new IllegalArgumentException("Null fragment file");
+
+ if (fragments == null)
+ fragments = new CopyOnWriteArrayList<VirtualFile>();
+
+ fragments.add(fragRoot);
+ }
+
+ /**
+ * Detach a fragment root from the policy.
+ * @param fragRoot The fragment root file
+ * @return true if the fragment could be detached
+ */
+ public boolean detachFragment(VirtualFile fragRoot)
+ {
+ if (fragRoot == null)
+ throw new IllegalArgumentException("Null fragment file");
+
+ if (fragments == null)
+ return false;
+
+ return fragments.remove(fragRoot);
+ }
+
+ /**
+ * Get the array of attached fragment root files.
+ * @return The array of attached fragment root files or null.
+ */
+ public VirtualFile[] getFragmentRoots()
+ {
+ if (fragments == null)
+ return null;
+
+ VirtualFile[] retarr = new VirtualFile[fragments.size()];
+ fragments.toArray(retarr);
+ return retarr;
+ }
+
+ @Override
+ protected VirtualFileInfo findVirtualFileInfo(String path)
+ {
+ VirtualFileInfo result = super.findVirtualFileInfo(path);
+ if (result == null && fragments != null)
+ {
+ for (VirtualFile root : fragments)
+ {
+ try
+ {
+ VirtualFile file = root.getChild(path);
+ if (file != null)
+ {
+ result = new VirtualFileInfo(file, root);
+ return result;
+ }
+ }
+ catch (Exception ignored)
+ {
+ }
+ }
+ }
+ return result;
+ }
+
+ /**
* An implementation of NativeLibraryProvider that provides the native library file
* location from the bundle that contains the library.
*/
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/OSGiFragmentAttachmentDeployer.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/OSGiFragmentAttachmentDeployer.java 2010-01-26 17:12:25 UTC (rev 99950)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/OSGiFragmentAttachmentDeployer.java 2010-01-26 17:24:26 UTC (rev 99951)
@@ -25,7 +25,6 @@
import org.jboss.classloader.spi.ClassLoaderPolicy;
import org.jboss.classloading.spi.metadata.ClassLoadingMetaData;
-import org.jboss.classloading.spi.vfs.policy.VFSClassLoaderPolicy;
import org.jboss.deployers.spi.DeploymentException;
import org.jboss.deployers.spi.deployer.DeploymentStages;
import org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer;
@@ -34,6 +33,7 @@
import org.jboss.osgi.framework.bundle.OSGiBundleManager;
import org.jboss.osgi.framework.bundle.OSGiBundleState;
import org.jboss.osgi.framework.bundle.OSGiFragmentState;
+import org.jboss.osgi.framework.classloading.OSGiClassLoaderPolicy;
import org.osgi.framework.Bundle;
/**
@@ -89,7 +89,7 @@
OSGiFragmentState fragState = (OSGiFragmentState)absBundleState;
OSGiBundleState hostState = fragState.getFragmentHost();
DeploymentUnit hostUnit = hostState.getDeploymentUnit();
- VFSClassLoaderPolicy hostPolicy = (VFSClassLoaderPolicy)hostUnit.getAttachment(ClassLoaderPolicy.class);
+ OSGiClassLoaderPolicy hostPolicy = (OSGiClassLoaderPolicy)hostUnit.getAttachment(ClassLoaderPolicy.class);
hostPolicy.attachFragment(fragState.getRoot());
}
}
16 years, 4 months
JBoss-OSGI SVN: r99944 - in projects/jboss-osgi/trunk: testsuite and 9 other directories.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2010-01-26 10:27:43 -0500 (Tue, 26 Jan 2010)
New Revision: 99944
Added:
projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/
projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/ServiceLoaderTestCase.java
projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/client/
projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/client/ServiceLoaderClientActivator.java
projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/service/
projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/service/AccountService.java
projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/service/internal/
projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/service/internal/AccountServiceImpl.java
projects/jboss-osgi/trunk/testsuite/example/src/test/resources/META-INF/services/org.jboss.test.osgi.example.serviceloader.service.AccountService
projects/jboss-osgi/trunk/testsuite/example/src/test/resources/serviceloader/
projects/jboss-osgi/trunk/testsuite/example/src/test/resources/serviceloader/example-serviceloader-api.bnd
projects/jboss-osgi/trunk/testsuite/example/src/test/resources/serviceloader/example-serviceloader-client.bnd
projects/jboss-osgi/trunk/testsuite/example/src/test/resources/serviceloader/example-serviceloader-impl.bnd
Modified:
projects/jboss-osgi/trunk/pom.xml
projects/jboss-osgi/trunk/testsuite/example/scripts/antrun-test-jars.xml
projects/jboss-osgi/trunk/testsuite/example/scripts/assembly-bundles.xml
projects/jboss-osgi/trunk/testsuite/pom.xml
Log:
Add serviceloader example
Modified: projects/jboss-osgi/trunk/pom.xml
===================================================================
--- projects/jboss-osgi/trunk/pom.xml 2010-01-26 15:26:29 UTC (rev 99943)
+++ projects/jboss-osgi/trunk/pom.xml 2010-01-26 15:27:43 UTC (rev 99944)
@@ -69,6 +69,7 @@
<version.jboss.osgi.runtime.equinox>3.5.1</version.jboss.osgi.runtime.equinox>
<version.jboss.osgi.runtime.felix>2.0.2</version.jboss.osgi.runtime.felix>
<version.jboss.osgi.runtime.jbossas>1.0.2</version.jboss.osgi.runtime.jbossas>
+ <version.jboss.osgi.serviceloader>1.0.0-SNAPSHOT</version.jboss.osgi.serviceloader>
<version.jboss.osgi.spi>1.0.4-SNAPSHOT</version.jboss.osgi.spi>
<version.jboss.osgi.webapp>0.7.2</version.jboss.osgi.webapp>
<version.jboss.osgi.webconsole>1.0.2</version.jboss.osgi.webconsole>
@@ -169,6 +170,11 @@
</dependency>
<dependency>
<groupId>org.jboss.osgi.bundles</groupId>
+ <artifactId>jboss-osgi-serviceloader</artifactId>
+ <version>${version.jboss.osgi.serviceloader}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.osgi.bundles</groupId>
<artifactId>jboss-osgi-webapp</artifactId>
<version>${version.jboss.osgi.webapp}</version>
</dependency>
Modified: projects/jboss-osgi/trunk/testsuite/example/scripts/antrun-test-jars.xml
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/scripts/antrun-test-jars.xml 2010-01-26 15:26:29 UTC (rev 99943)
+++ projects/jboss-osgi/trunk/testsuite/example/scripts/antrun-test-jars.xml 2010-01-26 15:27:43 UTC (rev 99944)
@@ -67,6 +67,11 @@
<!-- mcservice -->
<bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/example-mcservice-bundleA.jar" files="${tests.resources.dir}/mcservice/example-mcservice-bundleA.bnd" />
+ <!-- serviceloader -->
+ <bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/example-serviceloader-api.jar" files="${tests.resources.dir}/serviceloader/example-serviceloader-api.bnd" />
+ <bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/example-serviceloader-client.jar" files="${tests.resources.dir}/serviceloader/example-serviceloader-client.bnd" />
+ <bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/example-serviceloader-impl.jar" files="${tests.resources.dir}/serviceloader/example-serviceloader-impl.bnd" />
+
<!-- simple -->
<bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/example-simple.jar" files="${tests.resources.dir}/simple/example-simple.bnd" />
<bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/example-simple-husky.jar" files="${tests.resources.dir}/simple/example-simple-husky.bnd" />
Modified: projects/jboss-osgi/trunk/testsuite/example/scripts/assembly-bundles.xml
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/scripts/assembly-bundles.xml 2010-01-26 15:26:29 UTC (rev 99943)
+++ projects/jboss-osgi/trunk/testsuite/example/scripts/assembly-bundles.xml 2010-01-26 15:27:43 UTC (rev 99944)
@@ -25,6 +25,7 @@
<include>*:jboss-osgi-jndi:jar</include>
<include>*:jboss-osgi-jta:jar</include>
<include>*:jboss-osgi-reflect:jar</include>
+ <include>*:jboss-osgi-serviceloader:jar</include>
<include>*:jboss-osgi-webapp:jar</include>
<include>*:jboss-osgi-xml-binding:jar</include>
<include>*:org.apache.aries.blueprint:jar</include>
Added: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/ServiceLoaderTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/ServiceLoaderTestCase.java (rev 0)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/ServiceLoaderTestCase.java 2010-01-26 15:27:43 UTC (rev 99944)
@@ -0,0 +1,102 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.osgi.example.serviceloader;
+
+//$Id$
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import org.jboss.osgi.serviceloader.ServiceLoaderCapability;
+import org.jboss.osgi.spi.util.ServiceLoader;
+import org.jboss.osgi.testing.OSGiBundle;
+import org.jboss.osgi.testing.OSGiRuntime;
+import org.jboss.osgi.testing.OSGiServiceReference;
+import org.jboss.osgi.testing.OSGiTest;
+import org.jboss.test.osgi.example.serviceloader.service.AccountService;
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+
+/**
+ * A test that deployes a bundle and verifies its state
+ *
+ * @author thomas.diesler(a)jboss.com
+ * @since 26-Jan-2010
+ */
+public class ServiceLoaderTestCase extends OSGiTest
+{
+ @Test
+ public void testTraditionalServiceLoaderAPI() throws Exception
+ {
+ // Use the traditional ServiceLoader API to get the service
+ AccountService service = ServiceLoader.loadService(AccountService.class);
+ assertNotNull("AccountService loaded", service);
+
+ assertEquals(0, service.getBalance());
+ assertEquals(100, service.credit(100));
+ assertEquals(80, service.withdraw(20));
+
+ try
+ {
+ service.withdraw(100);
+ fail("Insuffient funds expected");
+ }
+ catch (RuntimeException e)
+ {
+ assertEquals(80, service.getBalance());
+ }
+ }
+
+ @Test
+ public void testOSGiServiceAPI() throws Exception
+ {
+ // Get the default runtime
+ OSGiRuntime runtime = getDefaultRuntime();
+ runtime.addCapability(new ServiceLoaderCapability());
+
+ try
+ {
+ // Install the API bundle
+ runtime.installBundle("example-serviceloader-api.jar");
+
+ // Install/Start the client bundle
+ OSGiBundle implBundle = runtime.installBundle("example-serviceloader-impl.jar");
+ implBundle.start();
+
+ // Install/Start the client bundle
+ OSGiBundle clientBundle = runtime.installBundle("example-serviceloader-client.jar");
+ clientBundle.start();
+
+ OSGiServiceReference sref = runtime.getServiceReference(AccountService.class.getName());
+ assertNotNull("AccountService available", sref);
+
+ assertBundleState(Bundle.ACTIVE, implBundle.getState());
+ assertBundleState(Bundle.ACTIVE, clientBundle.getState());
+ }
+ finally
+ {
+ // Shutdown the runtime
+ runtime.shutdown();
+ }
+ }
+}
\ No newline at end of file
Property changes on: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/ServiceLoaderTestCase.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/client/ServiceLoaderClientActivator.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/client/ServiceLoaderClientActivator.java (rev 0)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/client/ServiceLoaderClientActivator.java 2010-01-26 15:27:43 UTC (rev 99944)
@@ -0,0 +1,57 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.osgi.example.serviceloader.client;
+
+//$Id$
+
+import org.jboss.osgi.spi.util.ServiceLoader;
+import org.jboss.test.osgi.example.serviceloader.service.AccountService;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * A Service Activator
+ *
+ * @author thomas.diesler(a)jboss.com
+ * @since 26-Jan-2010
+ */
+public class ServiceLoaderClientActivator implements BundleActivator
+{
+ public void start(BundleContext context)
+ {
+ // Use the traditional ServiceLoader API to get the service
+ AccountService service = ServiceLoader.loadService(AccountService.class);
+ if (service != null)
+ throw new IllegalStateException("Traditional ServiceLoader API, expected to fail");
+
+ // Get the registered service.
+ // Note, the example-serviceloader-impl does NOT register the service itself.
+ // Instead, jboss-osgi-serviceloader generically registeres all services in META-INF/services
+ ServiceReference sref = context.getServiceReference(AccountService.class.getName());
+ service = (AccountService)context.getService(sref);
+ }
+
+ public void stop(BundleContext context)
+ {
+ }
+}
\ No newline at end of file
Property changes on: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/client/ServiceLoaderClientActivator.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/service/AccountService.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/service/AccountService.java (rev 0)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/service/AccountService.java 2010-01-26 15:27:43 UTC (rev 99944)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.osgi.example.serviceloader.service;
+
+//$Id$
+
+/**
+ * A simple bank account service
+ *
+ * @author thomas.diesler(a)jboss.com
+ * @since 26-Jan-2010
+ */
+public interface AccountService
+{
+ /** Get the current balance */
+ long getBalance();
+
+ /** Credit the given amount and return the current balance */
+ long credit(long amount);
+
+ /** Withdraw the given amount and return the current balance */
+ long withdraw(long amount);
+}
\ No newline at end of file
Property changes on: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/service/AccountService.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/service/internal/AccountServiceImpl.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/service/internal/AccountServiceImpl.java (rev 0)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/service/internal/AccountServiceImpl.java 2010-01-26 15:27:43 UTC (rev 99944)
@@ -0,0 +1,57 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.osgi.example.serviceloader.service.internal;
+
+import org.jboss.test.osgi.example.serviceloader.service.AccountService;
+
+//$Id$
+
+/**
+ * A simple bank account service
+ *
+ * @author thomas.diesler(a)jboss.com
+ * @since 26-Jan-2010
+ */
+public class AccountServiceImpl implements AccountService
+{
+ private long balance;
+
+ public long credit(long amount)
+ {
+ balance += amount;
+ return balance;
+ }
+
+ public long getBalance()
+ {
+ return balance;
+ }
+
+ public long withdraw(long amount)
+ {
+ if (balance - amount < 0)
+ throw new IllegalArgumentException("Insufficient funds: " + balance);
+
+ balance -= amount;
+ return balance;
+ }
+}
\ No newline at end of file
Property changes on: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/service/internal/AccountServiceImpl.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: projects/jboss-osgi/trunk/testsuite/example/src/test/resources/META-INF/services/org.jboss.test.osgi.example.serviceloader.service.AccountService
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/resources/META-INF/services/org.jboss.test.osgi.example.serviceloader.service.AccountService (rev 0)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/resources/META-INF/services/org.jboss.test.osgi.example.serviceloader.service.AccountService 2010-01-26 15:27:43 UTC (rev 99944)
@@ -0,0 +1 @@
+org.jboss.test.osgi.example.serviceloader.service.internal.AccountServiceImpl
\ No newline at end of file
Added: projects/jboss-osgi/trunk/testsuite/example/src/test/resources/serviceloader/example-serviceloader-api.bnd
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/resources/serviceloader/example-serviceloader-api.bnd (rev 0)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/resources/serviceloader/example-serviceloader-api.bnd 2010-01-26 15:27:43 UTC (rev 99944)
@@ -0,0 +1,6 @@
+# bnd build -classpath target/test-classes -output target/test-libs/example-serviceloader-api.jar src/test/resources/example/serviceloader/example-serviceloader-api.bnd
+
+Bundle-SymbolicName: example-serviceloader-api
+
+Export-Package: org.jboss.test.osgi.example.serviceloader.service
+
Added: projects/jboss-osgi/trunk/testsuite/example/src/test/resources/serviceloader/example-serviceloader-client.bnd
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/resources/serviceloader/example-serviceloader-client.bnd (rev 0)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/resources/serviceloader/example-serviceloader-client.bnd 2010-01-26 15:27:43 UTC (rev 99944)
@@ -0,0 +1,7 @@
+# bnd build -classpath target/test-classes -output target/test-libs/example-serviceloader-client.jar src/test/resources/example/serviceloader/example-serviceloader-client.bnd
+
+Bundle-SymbolicName: example-serviceloader-client
+Bundle-Activator: org.jboss.test.osgi.example.serviceloader.client.ServiceLoaderClientActivator
+Import-Package: org.osgi.framework, org.jboss.osgi.spi.util, org.jboss.test.osgi.example.serviceloader.service
+Private-Package: org.jboss.test.osgi.example.serviceloader.client
+
Added: projects/jboss-osgi/trunk/testsuite/example/src/test/resources/serviceloader/example-serviceloader-impl.bnd
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/resources/serviceloader/example-serviceloader-impl.bnd (rev 0)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/resources/serviceloader/example-serviceloader-impl.bnd 2010-01-26 15:27:43 UTC (rev 99944)
@@ -0,0 +1,10 @@
+# bnd build -classpath target/test-classes -output target/test-libs/example-serviceloader-impl.jar src/test/resources/example/serviceloader/example-serviceloader-impl.bnd
+
+Bundle-SymbolicName: example-serviceloader-impl
+
+Import-Package: org.jboss.test.osgi.example.serviceloader.service
+Private-Package: org.jboss.test.osgi.example.serviceloader.service.internal
+Include-Resource: META-INF/services/org.jboss.test.osgi.example.serviceloader.service.AccountService=../META-INF/services/org.jboss.test.osgi.example.serviceloader.service.AccountService
+
+-removeheaders: Include-Resource
+
Modified: projects/jboss-osgi/trunk/testsuite/pom.xml
===================================================================
--- projects/jboss-osgi/trunk/testsuite/pom.xml 2010-01-26 15:26:29 UTC (rev 99943)
+++ projects/jboss-osgi/trunk/testsuite/pom.xml 2010-01-26 15:27:43 UTC (rev 99944)
@@ -159,16 +159,21 @@
</dependency>
<dependency>
<groupId>org.jboss.osgi.bundles</groupId>
- <artifactId>jboss-osgi-webapp</artifactId>
+ <artifactId>jboss-osgi-reflect</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.osgi.bundles</groupId>
- <artifactId>jboss-osgi-reflect</artifactId>
+ <artifactId>jboss-osgi-serviceloader</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.osgi.bundles</groupId>
+ <artifactId>jboss-osgi-webapp</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.osgi.bundles</groupId>
<artifactId>jboss-osgi-xml-binding</artifactId>
<scope>provided</scope>
</dependency>
16 years, 4 months
JBoss-OSGI SVN: r99943 - projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/util.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2010-01-26 10:26:29 -0500 (Tue, 26 Jan 2010)
New Revision: 99943
Modified:
projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/util/ServiceLoader.java
Log:
Clarify ServiceLoader
Modified: projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/util/ServiceLoader.java
===================================================================
--- projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/util/ServiceLoader.java 2010-01-26 15:25:35 UTC (rev 99942)
+++ projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/util/ServiceLoader.java 2010-01-26 15:26:29 UTC (rev 99943)
@@ -41,49 +41,55 @@
{
// Provide logging
static final Logger log = LoggerFactory.getLogger(ServiceLoader.class);
-
+
/**
* Loads a list of service implementations defined in META-INF/services/${serviceClass}
+ *
+ * @param serviceClass The interface that is implemented by all loaded services
+ * @return The list of available service or an empty list
*/
@SuppressWarnings("unchecked")
public static <T> List<T> loadServices(Class<T> serviceClass)
{
List<T> services = new ArrayList<T>();
ClassLoader loader = serviceClass.getClassLoader();
-
+
// Use the Services API (as detailed in the JAR specification), if available, to determine the classname.
String filename = "META-INF/services/" + serviceClass.getName();
InputStream inStream = loader.getResourceAsStream(filename);
if (inStream == null)
- log.debug ("Cannot find resource: " + filename);
-
+ log.debug("Cannot find resource: " + filename);
+
if (inStream != null)
{
try
{
BufferedReader br = new BufferedReader(new InputStreamReader(inStream, "UTF-8"));
String implClassName = br.readLine();
- while(implClassName != null)
+ while (implClassName != null)
{
int hashIndex = implClassName.indexOf("#");
if (hashIndex > 0)
implClassName = implClassName.substring(0, hashIndex);
-
+
implClassName = implClassName.trim();
-
+
if (implClassName.length() > 0)
{
try
{
Class<T> implClass = (Class<T>)loader.loadClass(implClassName);
- services.add(implClass.newInstance());
+ if (serviceClass.isAssignableFrom(implClass))
+ services.add(implClass.newInstance());
+ else
+ log.warn("Not assignable: " + implClassName);
}
catch (Exception ex)
{
- log.debug ("Cannot load service: " + implClassName);
+ log.debug("Cannot load service: " + implClassName);
}
}
-
+
implClassName = br.readLine();
}
br.close();
@@ -93,16 +99,22 @@
throw new IllegalStateException("Failed to load services for: " + serviceClass.getName());
}
}
-
+
return services;
}
/**
* Loads the first of a list of service implementations defined in META-INF/services/${serviceClass}
+ *
+ * @param serviceClass The interface that is implemented by all loaded services
+ * @return The first available service or null
*/
public static <T> T loadService(Class<T> serviceClass)
{
List<T> services = loadServices(serviceClass);
- return services.get(0);
+ if (services.isEmpty())
+ return null;
+
+ return services.get(0);
}
}
16 years, 4 months