killbill-memoizeit

Introduce OSGIConfigProperties as an an osgi service to allow

4/23/2014 12:53:43 AM

Details

diff --git a/api/src/main/java/org/killbill/billing/osgi/api/OSGIConfigProperties.java b/api/src/main/java/org/killbill/billing/osgi/api/OSGIConfigProperties.java
new file mode 100644
index 0000000..2f4ba9f
--- /dev/null
+++ b/api/src/main/java/org/killbill/billing/osgi/api/OSGIConfigProperties.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2014 Groupon, Inc
+ *
+ * Groupon licenses this file to you under the Apache License, version 2.0
+ * (the "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at:
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.killbill.billing.osgi.api;
+
+import java.util.Properties;
+
+/**
+ * OSGI bundles should read their (system) properties using that service interface instead of using
+ * the {@codeSystem.getProperties()} as there is no guarantees that standard java mechanism would work.
+ */
+public interface OSGIConfigProperties {
+
+    /**
+     *
+     * @param propertyName the system property name
+     * @return the value of the property
+     */
+    public String getString(final String propertyName);
+
+    /**
+     *
+     * @return all knows system properties (for the JVM)
+     */
+    public Properties getProperties();
+}
diff --git a/beatrix/src/test/java/org/killbill/billing/beatrix/integration/BeatrixIntegrationModule.java b/beatrix/src/test/java/org/killbill/billing/beatrix/integration/BeatrixIntegrationModule.java
index eea3f8c..312c639 100644
--- a/beatrix/src/test/java/org/killbill/billing/beatrix/integration/BeatrixIntegrationModule.java
+++ b/beatrix/src/test/java/org/killbill/billing/beatrix/integration/BeatrixIntegrationModule.java
@@ -56,6 +56,7 @@ import org.killbill.billing.subscription.glue.DefaultSubscriptionModule;
 import org.killbill.billing.tenant.glue.TenantModule;
 import org.killbill.billing.usage.glue.TestUsageModule;
 import org.killbill.billing.usage.glue.UsageModule;
+import org.killbill.billing.util.config.KillbillConfigSource;
 import org.killbill.billing.util.config.PaymentConfig;
 import org.killbill.billing.util.email.EmailModule;
 import org.killbill.billing.util.email.templates.TemplateModule;
@@ -86,9 +87,9 @@ public class BeatrixIntegrationModule extends AbstractModule {
     // Same name the osgi-payment-test plugin uses to register its service
     public static final String OSGI_PLUGIN_NAME = "osgi-payment-plugin";
 
-    private final ConfigSource configSource;
+    private final KillbillConfigSource configSource;
 
-    public BeatrixIntegrationModule(final ConfigSource configSource) {
+    public BeatrixIntegrationModule(final KillbillConfigSource configSource) {
         this.configSource = configSource;
     }
 
diff --git a/osgi/src/main/java/org/killbill/billing/osgi/glue/DefaultOSGIModule.java b/osgi/src/main/java/org/killbill/billing/osgi/glue/DefaultOSGIModule.java
index 0d9267f..bb9a25a 100644
--- a/osgi/src/main/java/org/killbill/billing/osgi/glue/DefaultOSGIModule.java
+++ b/osgi/src/main/java/org/killbill/billing/osgi/glue/DefaultOSGIModule.java
@@ -20,6 +20,8 @@ import javax.servlet.Servlet;
 import javax.servlet.http.HttpServlet;
 import javax.sql.DataSource;
 
+import org.killbill.billing.osgi.api.OSGIConfigProperties;
+import org.killbill.billing.util.config.KillbillConfigSource;
 import org.osgi.service.http.HttpService;
 import org.skife.config.ConfigSource;
 import org.skife.config.ConfigurationObjectFactory;
@@ -50,15 +52,16 @@ public class DefaultOSGIModule extends AbstractModule {
 
     public static final String OSGI_NAMED = "osgi";
 
-    protected final ConfigSource configSource;
+    protected final KillbillConfigSource configSource;
 
-    public DefaultOSGIModule(final ConfigSource configSource) {
+    public DefaultOSGIModule(final KillbillConfigSource configSource) {
         this.configSource = configSource;
     }
 
     protected void installConfig() {
         final OSGIConfig config = new ConfigurationObjectFactory(configSource).build(OSGIConfig.class);
         bind(OSGIConfig.class).toInstance(config);
+        bind(OSGIConfigProperties.class).toInstance(configSource);
 
         final OSGIDataSourceConfig osgiDataSourceConfig = new ConfigurationObjectFactory(configSource).build(OSGIDataSourceConfig.class);
         bind(OSGIDataSourceConfig.class).toInstance(osgiDataSourceConfig);
diff --git a/osgi/src/main/java/org/killbill/billing/osgi/KillbillActivator.java b/osgi/src/main/java/org/killbill/billing/osgi/KillbillActivator.java
index 9a6da80..98385d7 100644
--- a/osgi/src/main/java/org/killbill/billing/osgi/KillbillActivator.java
+++ b/osgi/src/main/java/org/killbill/billing/osgi/KillbillActivator.java
@@ -28,6 +28,7 @@ import javax.inject.Named;
 import javax.servlet.Servlet;
 import javax.sql.DataSource;
 
+import org.killbill.billing.osgi.api.OSGIConfigProperties;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceEvent;
@@ -60,6 +61,7 @@ public class KillbillActivator implements BundleActivator, ServiceListener {
     private final DataSource dataSource;
     private final KillbillEventObservable observable;
     private final OSGIKillbillRegistrar registrar;
+    private final OSGIConfigProperties configProperties;
 
     private final List<OSGIServiceRegistration> allRegistrationHandlers;
 
@@ -71,6 +73,7 @@ public class KillbillActivator implements BundleActivator, ServiceListener {
                              final OSGIKillbill osgiKillbill,
                              final HttpService defaultHttpService,
                              final KillbillEventObservable observable,
+                             final OSGIConfigProperties configProperties,
                              final OSGIServiceRegistration<Servlet> servletRouter,
                              final OSGIServiceRegistration<PaymentPluginApi> paymentProviderPluginRegistry,
                              final OSGIServiceRegistration<CurrencyPluginApi> currencyProviderPluginRegistry) {
@@ -78,6 +81,7 @@ public class KillbillActivator implements BundleActivator, ServiceListener {
         this.defaultHttpService = defaultHttpService;
         this.dataSource = dataSource;
         this.observable = observable;
+        this.configProperties = configProperties;
         this.registrar = new OSGIKillbillRegistrar();
         this.allRegistrationHandlers = ImmutableList.<OSGIServiceRegistration>of(servletRouter, paymentProviderPluginRegistry, currencyProviderPluginRegistry);
     }
@@ -95,6 +99,7 @@ public class KillbillActivator implements BundleActivator, ServiceListener {
         registrar.registerService(context, HttpService.class, defaultHttpService, props);
         registrar.registerService(context, Observable.class, observable, props);
         registrar.registerService(context, DataSource.class, dataSource, props);
+        registrar.registerService(context, OSGIConfigProperties.class, configProperties, props);
 
         context.addServiceListener(this);
     }
diff --git a/osgi-bundles/bundles/jruby/pom.xml b/osgi-bundles/bundles/jruby/pom.xml
index b56b94b..5280ebe 100644
--- a/osgi-bundles/bundles/jruby/pom.xml
+++ b/osgi-bundles/bundles/jruby/pom.xml
@@ -154,11 +154,11 @@
                             org.killbill.billing.subscription.api.user;
                             org.killbill.billing.junction.api;
                             org.killbill.billing;
+                            org.killbill.billing.osgi.api;
                             org.killbill.billing.overdue;
                             org.killbill.billing.tenant.api;
                             org.killbill.billing.usage.api;
                             org.killbill.billing.util.audit;
-                            org.killbill.billing.util.config;
                             org.killbill.billing.util.customfield;
                             org.killbill.billing.notification.plugin;
                             org.killbill.billing.util.email;
@@ -166,15 +166,6 @@
                             org.killbill.billing.util.template;
                             org.killbill.billing.util.template.translation;resolution:=optional,
                             org.joda.time.format;resolution:=optional,
-                            org.skife.config;
-                            org.skife.config.cglib.asm;
-                            org.skife.config.cglib.beans;
-                            org.skife.config.cglib.core;
-                            org.skife.config.cglib.proxy;
-                            org.skife.config.cglib.reflect;
-                            org.skife.config.cglib.transform;
-                            org.skife.config.cglib.transform.impl;
-                            org.skife.config.cglib.util;
                             sun.misc;
                             sun.misc.*;
                             sun.misc.unsafe;
diff --git a/osgi-bundles/libs/killbill/src/main/java/org/killbill/killbill/osgi/libs/killbill/KillbillActivatorBase.java b/osgi-bundles/libs/killbill/src/main/java/org/killbill/killbill/osgi/libs/killbill/KillbillActivatorBase.java
index 7075883..fd68a05 100644
--- a/osgi-bundles/libs/killbill/src/main/java/org/killbill/killbill/osgi/libs/killbill/KillbillActivatorBase.java
+++ b/osgi-bundles/libs/killbill/src/main/java/org/killbill/killbill/osgi/libs/killbill/KillbillActivatorBase.java
@@ -16,22 +16,19 @@
 
 package org.killbill.killbill.osgi.libs.killbill;
 
-import org.killbill.billing.util.config.KillbillConfigSource;
+import org.killbill.billing.osgi.api.OSGIConfigProperties;
+import org.killbill.killbill.osgi.libs.killbill.OSGIKillbillEventDispatcher.OSGIKillbillEventHandler;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
 
-import org.killbill.killbill.osgi.libs.killbill.OSGIKillbillEventDispatcher.OSGIKillbillEventHandler;
-import org.skife.config.ConfigSource;
-
 public abstract class KillbillActivatorBase implements BundleActivator {
 
-
     protected OSGIKillbillAPI killbillAPI;
     protected OSGIKillbillLogService logService;
     protected OSGIKillbillRegistrar registrar;
     protected OSGIKillbillDataSource dataSource;
     protected OSGIKillbillEventDispatcher dispatcher;
-    protected ConfigSource configSource;
+    protected OSGIConfigProperties configProperties;
 
     @Override
     public void start(final BundleContext context) throws Exception {
@@ -41,7 +38,7 @@ public abstract class KillbillActivatorBase implements BundleActivator {
         logService = new OSGIKillbillLogService(context);
         dataSource = new OSGIKillbillDataSource(context);
         dispatcher = new OSGIKillbillEventDispatcher(context);
-        configSource = new KillbillConfigSource();
+        configProperties = new OSGIConfigPropertiesService(context);
 
         // Registrar for bundle
         registrar = new OSGIKillbillRegistrar();
diff --git a/osgi-bundles/libs/killbill/src/main/java/org/killbill/killbill/osgi/libs/killbill/OSGIConfigPropertiesService.java b/osgi-bundles/libs/killbill/src/main/java/org/killbill/killbill/osgi/libs/killbill/OSGIConfigPropertiesService.java
new file mode 100644
index 0000000..d45d144
--- /dev/null
+++ b/osgi-bundles/libs/killbill/src/main/java/org/killbill/killbill/osgi/libs/killbill/OSGIConfigPropertiesService.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2014 Groupon, Inc
+ *
+ * Groupon licenses this file to you under the Apache License, version 2.0
+ * (the "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at:
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.killbill.killbill.osgi.libs.killbill;
+
+import java.util.Properties;
+
+import org.killbill.billing.osgi.api.OSGIConfigProperties;
+import org.osgi.framework.BundleContext;
+import org.osgi.util.tracker.ServiceTracker;
+
+public class OSGIConfigPropertiesService extends OSGIKillbillLibraryBase implements OSGIConfigProperties {
+
+    private final ServiceTracker killbillTracker;
+
+    public OSGIConfigPropertiesService(final BundleContext context) {
+        killbillTracker = new ServiceTracker(context, OSGIConfigProperties.class.getName(), null);
+        killbillTracker.open();
+    }
+
+    public void close() {
+        if (killbillTracker != null) {
+            killbillTracker.close();
+        }
+    }
+
+    @Override
+    public String getString(final String propertyName) {
+        return withServiceTracker(killbillTracker, new APICallback<String, OSGIConfigProperties>(OSGIConfigProperties.class.getName()) {
+            @Override
+            public String executeWithService(final OSGIConfigProperties service) {
+                return service.getString(propertyName);
+            }
+        });
+    }
+
+    @Override
+    public Properties getProperties() {
+        return withServiceTracker(killbillTracker, new APICallback<Properties, OSGIConfigProperties>(OSGIConfigProperties.class.getName()) {
+            @Override
+            public Properties executeWithService(final OSGIConfigProperties service) {
+                return service.getProperties();
+            }
+        });
+    }
+}
diff --git a/osgi-bundles/tests/beatrix/pom.xml b/osgi-bundles/tests/beatrix/pom.xml
index 99d9206..b721656 100644
--- a/osgi-bundles/tests/beatrix/pom.xml
+++ b/osgi-bundles/tests/beatrix/pom.xml
@@ -67,11 +67,6 @@
             <groupId>org.slf4j</groupId>
             <artifactId>osgi-over-slf4j</artifactId>
         </dependency>
-        <dependency>
-            <groupId>org.testng</groupId>
-            <artifactId>testng</artifactId>
-            <scope>test</scope>
-        </dependency>
     </dependencies>
     <build>
         <plugins>
@@ -90,7 +85,7 @@
                 <configuration>
                     <instructions>
                         <Bundle-Activator>org.killbill.billing.osgi.bundles.test.TestActivator</Bundle-Activator>
-                        <Import-Package>*;resolution:=optional</Import-Package>
+                        <Import-Package>*;resolution:=optional,org.killbill.billing.osgi.api;</Import-Package>
                     </instructions>
                 </configuration>
             </plugin>
@@ -138,6 +133,13 @@
                 </executions>
             </plugin>
             <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <configuration>
+                    <skipTests>true</skipTests>
+                </configuration>
+            </plugin>
+            <plugin>
                 <groupId>org.codehaus.mojo</groupId>
                 <artifactId>build-helper-maven-plugin</artifactId>
                 <version>1.5</version>
diff --git a/server/src/main/java/org/killbill/billing/server/listeners/KillbillGuiceListener.java b/server/src/main/java/org/killbill/billing/server/listeners/KillbillGuiceListener.java
index 58f3ca2..8b941cd 100644
--- a/server/src/main/java/org/killbill/billing/server/listeners/KillbillGuiceListener.java
+++ b/server/src/main/java/org/killbill/billing/server/listeners/KillbillGuiceListener.java
@@ -65,7 +65,7 @@ public class KillbillGuiceListener extends GuiceServletContextListener {
     public static final ImmutableList<String> METRICS_SERVLETS_PATHS = ImmutableList.<String>of("/1.0/healthcheck", "/1.0/metrics", "/1.0/ping", "/1.0/threads");
 
     private KillbillServerConfig config;
-    private ConfigSource configSource;
+    private KillbillConfigSource configSource;
     private Injector injector;
     private DefaultLifecycle killbillLifecycle;
     private BusService killbillBusService;
diff --git a/server/src/main/java/org/killbill/billing/server/modules/KillbillServerModule.java b/server/src/main/java/org/killbill/billing/server/modules/KillbillServerModule.java
index 7f4e5ed..397f508 100644
--- a/server/src/main/java/org/killbill/billing/server/modules/KillbillServerModule.java
+++ b/server/src/main/java/org/killbill/billing/server/modules/KillbillServerModule.java
@@ -53,6 +53,7 @@ import org.killbill.billing.server.notifications.PushNotificationListener;
 import org.killbill.billing.subscription.glue.DefaultSubscriptionModule;
 import org.killbill.billing.tenant.glue.TenantModule;
 import org.killbill.billing.usage.glue.UsageModule;
+import org.killbill.billing.util.config.KillbillConfigSource;
 import org.killbill.billing.util.email.EmailModule;
 import org.killbill.billing.util.email.templates.TemplateModule;
 import org.killbill.billing.util.glue.AuditModule;
@@ -84,9 +85,9 @@ public class KillbillServerModule extends AbstractModule {
     protected final ServletContext servletContext;
 
     private final KillbillServerConfig serverConfig;
-    private final ConfigSource configSource;
+    private final KillbillConfigSource configSource;
 
-    public KillbillServerModule(final ServletContext servletContext, final KillbillServerConfig serverConfig, final ConfigSource configSource) {
+    public KillbillServerModule(final ServletContext servletContext, final KillbillServerConfig serverConfig, final KillbillConfigSource configSource) {
         this.servletContext = servletContext;
         this.serverConfig = serverConfig;
         this.configSource = configSource;
diff --git a/server/src/test/java/org/killbill/billing/jaxrs/TestJaxrsBase.java b/server/src/test/java/org/killbill/billing/jaxrs/TestJaxrsBase.java
index ec7feca..34e445b 100644
--- a/server/src/test/java/org/killbill/billing/jaxrs/TestJaxrsBase.java
+++ b/server/src/test/java/org/killbill/billing/jaxrs/TestJaxrsBase.java
@@ -126,9 +126,9 @@ public class TestJaxrsBase extends KillbillClient {
     public class TestKillbillGuiceListener extends KillbillGuiceListener {
 
         private final KillbillServerConfig serverConfig;
-        private final ConfigSource configSource;
+        private final KillbillConfigSource configSource;
 
-        public TestKillbillGuiceListener(final KillbillServerConfig serverConfig, final ConfigSource configSource) {
+        public TestKillbillGuiceListener(final KillbillServerConfig serverConfig, final KillbillConfigSource configSource) {
             super();
             this.serverConfig = serverConfig;
             this.configSource = configSource;
@@ -155,7 +155,7 @@ public class TestJaxrsBase extends KillbillClient {
 
     public class TestKillbillServerModule extends KillbillServerModule {
 
-        public TestKillbillServerModule(final ServletContext servletContext, final KillbillServerConfig serverConfig, final ConfigSource configSource) {
+        public TestKillbillServerModule(final ServletContext servletContext, final KillbillServerConfig serverConfig, final KillbillConfigSource configSource) {
             super(servletContext, serverConfig, configSource);
         }
 
diff --git a/util/src/main/java/org/killbill/billing/util/config/KillbillConfigSource.java b/util/src/main/java/org/killbill/billing/util/config/KillbillConfigSource.java
index f88a09b..dc990b6 100644
--- a/util/src/main/java/org/killbill/billing/util/config/KillbillConfigSource.java
+++ b/util/src/main/java/org/killbill/billing/util/config/KillbillConfigSource.java
@@ -20,6 +20,7 @@ import java.io.IOException;
 import java.net.URISyntaxException;
 import java.util.Properties;
 
+import org.killbill.billing.osgi.api.OSGIConfigProperties;
 import org.killbill.billing.util.config.catalog.UriAccessor;
 import org.skife.config.ConfigSource;
 import org.slf4j.Logger;
@@ -27,7 +28,7 @@ import org.slf4j.LoggerFactory;
 
 import com.google.common.annotations.VisibleForTesting;
 
-public class KillbillConfigSource implements ConfigSource {
+public class KillbillConfigSource implements ConfigSource, OSGIConfigProperties {
 
     private static final Logger logger = LoggerFactory.getLogger(KillbillConfigSource.class);
     private static final String PROPERTIES_FILE = "org.killbill.server.properties";
@@ -51,6 +52,11 @@ public class KillbillConfigSource implements ConfigSource {
         return properties.getProperty(propertyName);
     }
 
+    @Override
+    public Properties getProperties() {
+        return properties;
+    }
+
     private Properties loadPropertiesFromFileOrSystemProperties() {
         // Chicken-egg problem. It would be nice to have the property in e.g. KillbillServerConfig,
         // but we need to build the ConfigSource first...
diff --git a/util/src/main/java/org/killbill/billing/util/config/OSGIConfig.java b/util/src/main/java/org/killbill/billing/util/config/OSGIConfig.java
index 37ffbd5..f3d2738 100644
--- a/util/src/main/java/org/killbill/billing/util/config/OSGIConfig.java
+++ b/util/src/main/java/org/killbill/billing/util/config/OSGIConfig.java
@@ -54,6 +54,7 @@ public interface OSGIConfig extends KillbillConfig {
              "org.killbill.billing," +
              "org.killbill.billing.notification.api," +
              "org.killbill.billing.notification.plugin.api," +
+             "org.killbill.billing.notification.plugin," +
              "org.killbill.billing.osgi.api," +
              "org.killbill.billing.osgi.api.config," +
              "org.killbill.billing.overdue," +
@@ -61,19 +62,17 @@ public interface OSGIConfig extends KillbillConfig {
              "org.killbill.billing.payment.plugin.api," +
              "org.killbill.billing.tenant.api," +
              "org.killbill.billing.usage.api," +
-             "org.killbill.billing.util.config," +
              "org.killbill.billing.util.api," +
              "org.killbill.billing.util.audit," +
              "org.killbill.billing.util.callcontext," +
              "org.killbill.billing.util.customfield," +
-             "org.killbill.billing.notification.plugin," +
-             "org.killbill.billing.currency.plugin.api," +
-             "org.killbill.billing.currency.api," +
              "org.killbill.billing.util.email," +
              "org.killbill.billing.util.entity," +
              "org.killbill.billing.util.tag," +
              "org.killbill.billing.util.template," +
              "org.killbill.billing.util.template.translation," +
+             "org.killbill.billing.currency.plugin.api," +
+             "org.killbill.billing.currency.api," +
 
              // Add export for all the com.sun.xml.internal.ws required to have apache-cxf working properly within a plugin environment.
              "com.sun.xml.internal.ws," +
@@ -177,8 +176,6 @@ public interface OSGIConfig extends KillbillConfig {
 
              // Since we are using joda in our APIs we need to export it
              "org.joda.time;org.joda.time.format;version=2.3," +
-             // KillbillConfigSource is exported and implements ConfigSource so that needs to be exported
-             "org.skife.config;org.skife.config.cglib.asm;org.skife.config.cglib.beans;org.skife.config.cglib.core;org.skife.config.cglib.proxy;org.skife.config.cglib.reflect;org.skife.config.cglib.transform;org.skife.config.cglib.transform.impl;org.skife.config.cglib.util," +
              "org.osgi.service.log;version=1.3," +
              // Let the world know the System bundle exposes (via org.osgi.compendium) the requirement (osgi.wiring.package=org.osgi.service.http)
              "org.osgi.service.http;version=1.2.0," +