You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2013/02/08 12:57:13 UTC

svn commit: r1443965 - in /camel/branches/camel-2.10.x: ./ components/camel-test-blueprint/ components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/ components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ co...

Author: davsclaus
Date: Fri Feb  8 11:57:12 2013
New Revision: 1443965

URL: http://svn.apache.org/r1443965
Log:
CAMEL-6053: Allow to load .cfg config admin properties file from camel-test-blueprint.

Added:
    camel/branches/camel-2.10.x/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminLoadConfigurationFileTest.java
      - copied unchanged from r1443964, camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminLoadConfigurationFileTest.java
    camel/branches/camel-2.10.x/components/camel-test-blueprint/src/test/resources/etc/
      - copied from r1443964, camel/trunk/components/camel-test-blueprint/src/test/resources/etc/
    camel/branches/camel-2.10.x/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/configadmin-loadfile.xml
      - copied unchanged from r1443964, camel/trunk/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/configadmin-loadfile.xml
Modified:
    camel/branches/camel-2.10.x/   (props changed)
    camel/branches/camel-2.10.x/components/camel-test-blueprint/pom.xml
    camel/branches/camel-2.10.x/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java
    camel/branches/camel-2.10.x/parent/pom.xml

Propchange: camel/branches/camel-2.10.x/
------------------------------------------------------------------------------
  Merged /camel/trunk:r1443964

Propchange: camel/branches/camel-2.10.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: camel/branches/camel-2.10.x/components/camel-test-blueprint/pom.xml
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/components/camel-test-blueprint/pom.xml?rev=1443965&r1=1443964&r2=1443965&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/components/camel-test-blueprint/pom.xml (original)
+++ camel/branches/camel-2.10.x/components/camel-test-blueprint/pom.xml Fri Feb  8 11:57:12 2013
@@ -121,6 +121,27 @@
                     </exclusion>
                 </exclusions>
         </dependency>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.fileinstall</artifactId>
+            <version>${felix-fileinstall-version}</version>
+                <!-- exclude the following dependency which otherwise would pop up a lot of compilation
+                     errors both by this and the camel-maven-plugin modules under eclipse. -->
+                <exclusions>
+                    <exclusion>
+                        <groupId>org.apache.felix</groupId>
+                        <artifactId>org.osgi.foundation</artifactId>
+                    </exclusion>
+                    <exclusion>
+                        <groupId>org.apache.felix</groupId>
+                        <artifactId>org.osgi.core</artifactId>
+                    </exclusion>
+                    <exclusion>
+                        <groupId>org.apache.felix</groupId>
+                        <artifactId>org.osgi.compendium</artifactId>
+                    </exclusion>
+                </exclusions>
+        </dependency>
 
         <!-- optional dependencies for running tests -->
         <dependency>

Modified: camel/branches/camel-2.10.x/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java?rev=1443965&r1=1443964&r2=1443965&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java (original)
+++ camel/branches/camel-2.10.x/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java Fri Feb  8 11:57:12 2013
@@ -16,9 +16,12 @@
  */
 package org.apache.camel.test.blueprint;
 
+import java.io.File;
 import java.util.Dictionary;
+import java.util.Map;
 import java.util.Properties;
 
+import org.apache.aries.blueprint.compendium.cm.CmPropertyPlaceholder;
 import org.apache.camel.CamelContext;
 import org.apache.camel.component.properties.PropertiesComponent;
 import org.apache.camel.model.ModelCamelContext;
@@ -50,7 +53,31 @@ public abstract class CamelBlueprintTest
             bundleContext.registerService(PropertiesComponent.OVERRIDE_PROPERTIES, extra, null);
         }
 
-        // allow end users to override config admin service with extra properties
+        // load configuration file
+        String[] file = loadConfigAdminConfigurationFile();
+        if (file != null && file.length != 2) {
+            throw new IllegalArgumentException("The returned String[] from loadConfigAdminConfigurationFile must be of length 2, was " + file.length);
+        }
+        if (file != null && file[0] != null) {
+            Dictionary props = new Properties();
+
+            File load = new File(file[0]);
+            log.debug("Loading properties from OSGi config admin file: {}", load);
+            org.apache.felix.utils.properties.Properties cfg = new org.apache.felix.utils.properties.Properties(load);
+            for (Map.Entry entry : cfg.entrySet()) {
+                props.put(entry.getKey(), entry.getValue());
+            }
+
+            ConfigurationAdmin configAdmin = getOsgiService(ConfigurationAdmin.class);
+            if (configAdmin != null) {
+                // ensure we update
+                Configuration config = configAdmin.getConfiguration(file[1]);
+                log.info("Updating ConfigAdmin {} by overriding properties {}", config, props);
+                config.update(props);
+            }
+        }
+
+        // allow end user to override properties
         Dictionary props = new Properties();
         String pid = useOverridePropertiesWithConfigAdmin(props);
         if (pid != null) {
@@ -76,7 +103,17 @@ public abstract class CamelBlueprintTest
      * @param props properties where you add the properties to override
      * @return the PID of the OSGi {@link ConfigurationAdmin} which are defined in the Blueprint XML file.
      */
-    protected String useOverridePropertiesWithConfigAdmin(Dictionary props) {
+    protected String useOverridePropertiesWithConfigAdmin(Dictionary props) throws Exception {
+        return null;
+    }
+
+    /**
+     * Override this method and provide the name of the .cfg configuration file to use for
+     * Blueprint ConfigAdmin service.
+     *
+     * @return the name of the path for the .cfg file to load, and the persistence-id of the property placeholder.
+     */
+    protected String[] loadConfigAdminConfigurationFile() {
         return null;
     }
 

Modified: camel/branches/camel-2.10.x/parent/pom.xml
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/parent/pom.xml?rev=1443965&r1=1443964&r2=1443965&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/parent/pom.xml (original)
+++ camel/branches/camel-2.10.x/parent/pom.xml Fri Feb  8 11:57:12 2013
@@ -79,6 +79,7 @@
     <easymock-version>3.0</easymock-version>
     <ehcache-bundle-version>2.5.2_1</ehcache-bundle-version>
     <exec-maven-plugin-version>1.2.1</exec-maven-plugin-version>
+    <felix-fileinstall-version>3.2.6</felix-fileinstall-version>
     <flatpack-version>3.2.0_2</flatpack-version>
     <fop-version>1.0</fop-version>
     <ftpserver-version>1.0.6</ftpserver-version>