killbill-aplcache

osgi: rely on naming convention to find the JRuby bundle The

2/21/2013 2:03:33 AM

Details

diff --git a/osgi/src/main/java/com/ning/billing/osgi/DefaultOSGIService.java b/osgi/src/main/java/com/ning/billing/osgi/DefaultOSGIService.java
index abe221f..15516d0 100644
--- a/osgi/src/main/java/com/ning/billing/osgi/DefaultOSGIService.java
+++ b/osgi/src/main/java/com/ning/billing/osgi/DefaultOSGIService.java
@@ -167,15 +167,30 @@ public class DefaultOSGIService implements OSGIService {
     }
 
     private void installAllJRubyPluginBundles(final BundleContext context, final List<Bundle> installedBundles) throws PluginConfigException, BundleException {
+        final String jrubyBundlePath = findJrubyBundlePath();
+        if (jrubyBundlePath == null) {
+            return;
+        }
+
         final List<PluginRubyConfig> pluginRubyConfigs = pluginFinder.getLatestRubyPlugins();
         for (final PluginRubyConfig cur : pluginRubyConfigs) {
             logger.info("Installing JRuby bundle for plugin {} in {}", cur.getPluginName(), cur.getRubyLoadDir());
-            final Bundle bundle = context.installBundle(osgiConfig.getJrubyBundlePath());
+            final Bundle bundle = context.installBundle("file:" + jrubyBundlePath);
             ((DefaultPluginConfigServiceApi) pluginConfigServiceApi).registerBundle(bundle.getBundleId(), cur);
             installedBundles.add(bundle);
         }
     }
 
+    private String findJrubyBundlePath() {
+        final String expectedPath = osgiBundleFinder.getPlatformOSGIBundlesRootDir() + "jruby.jar";
+        if (new File(expectedPath).isFile()) {
+            return expectedPath;
+        } else {
+            logger.warn("Unable to find the JRuby bundle for ruby plugins. If you want to install ruby plugins, copy the jar to " + expectedPath);
+            return null;
+        }
+    }
+
     private Framework createAndInitFramework() throws BundleException {
         final Map<String, String> config = new HashMap<String, String>();
         config.put("org.osgi.framework.system.packages.extra", osgiConfig.getSystemBundleExportPackages());
diff --git a/osgi/src/main/java/com/ning/billing/osgi/PureOSGIBundleFinder.java b/osgi/src/main/java/com/ning/billing/osgi/PureOSGIBundleFinder.java
index 0eebfd1..12a41ed 100644
--- a/osgi/src/main/java/com/ning/billing/osgi/PureOSGIBundleFinder.java
+++ b/osgi/src/main/java/com/ning/billing/osgi/PureOSGIBundleFinder.java
@@ -44,7 +44,7 @@ public class PureOSGIBundleFinder {
     }
 
     public List<String> getLatestBundles() throws PluginConfigException {
-        final String rootDirPath = osgiConfig.getRootInstallationDir() + "/platform/";
+        final String rootDirPath = getPlatformOSGIBundlesRootDir();
         final File rootDir = new File(rootDirPath);
         if (!rootDir.exists() || !rootDir.isDirectory()) {
             logger.warn("Configuration root dir {} is not a valid directory", rootDirPath);
@@ -65,4 +65,8 @@ public class PureOSGIBundleFinder {
 
         return bundles;
     }
+
+    public String getPlatformOSGIBundlesRootDir() {
+        return osgiConfig.getRootInstallationDir() + "/platform/";
+    }
 }
diff --git a/util/src/main/java/com/ning/billing/util/config/OSGIConfig.java b/util/src/main/java/com/ning/billing/util/config/OSGIConfig.java
index 2e18f38..44b44c2 100644
--- a/util/src/main/java/com/ning/billing/util/config/OSGIConfig.java
+++ b/util/src/main/java/com/ning/billing/util/config/OSGIConfig.java
@@ -73,10 +73,4 @@ public interface OSGIConfig extends KillbillConfig {
              // Let the world know the System bundle exposes the requirement (&(osgi.wiring.package=org.slf4j)(version>=1.7.0)(!(version>=2.0.0)))
              "org.slf4j;version=1.7.2")
     public String getSystemBundleExportPackages();
-
-    // TODO FIXME OSGI
-    @Config("killbill.osgi.jruby.bundle.path")
-    @Default("file:/var/tmp/killbill-osgi-bundles-jruby.jar")
-    public String getJrubyBundlePath();
-
 }