incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1603850 - in /sling/trunk/contrib/crankstart/sling-extensions: pom.xml src/main/java/org/apache/sling/crankstart/extensions/sling/CrankstartInventoryPrinter.java
Date Thu, 19 Jun 2014 12:09:59 GMT
Author: bdelacretaz
Date: Thu Jun 19 12:09:58 2014
New Revision: 1603850

URL: http://svn.apache.org/r1603850
Log:
Add configs to the crankstart dump

Modified:
    sling/trunk/contrib/crankstart/sling-extensions/pom.xml
    sling/trunk/contrib/crankstart/sling-extensions/src/main/java/org/apache/sling/crankstart/extensions/sling/CrankstartInventoryPrinter.java

Modified: sling/trunk/contrib/crankstart/sling-extensions/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/crankstart/sling-extensions/pom.xml?rev=1603850&r1=1603849&r2=1603850&view=diff
==============================================================================
--- sling/trunk/contrib/crankstart/sling-extensions/pom.xml (original)
+++ sling/trunk/contrib/crankstart/sling-extensions/pom.xml Thu Jun 19 12:09:58 2014
@@ -33,6 +33,9 @@
                             org.apache.commons.io.*;resolution:=optional,
                             *
                         </Import-Package>
+                        <Embed-Dependency>
+                            org.apache.felix.configadmin;inline="org/apache/felix/cm/file/ConfigurationHandler.*"
+                        </Embed-Dependency>
                     </instructions>
                 </configuration>
             </plugin>
@@ -57,6 +60,12 @@
             <artifactId>org.apache.felix.scr.annotations</artifactId>
         </dependency>
         <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.configadmin</artifactId>
+            <version>1.2.8</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.crankstart.api</artifactId>
             <version>${project.version}</version>

Modified: sling/trunk/contrib/crankstart/sling-extensions/src/main/java/org/apache/sling/crankstart/extensions/sling/CrankstartInventoryPrinter.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/crankstart/sling-extensions/src/main/java/org/apache/sling/crankstart/extensions/sling/CrankstartInventoryPrinter.java?rev=1603850&r1=1603849&r2=1603850&view=diff
==============================================================================
--- sling/trunk/contrib/crankstart/sling-extensions/src/main/java/org/apache/sling/crankstart/extensions/sling/CrankstartInventoryPrinter.java
(original)
+++ sling/trunk/contrib/crankstart/sling-extensions/src/main/java/org/apache/sling/crankstart/extensions/sling/CrankstartInventoryPrinter.java
Thu Jun 19 12:09:58 2014
@@ -16,9 +16,12 @@
  */
 package org.apache.sling.crankstart.extensions.sling;
 
+import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.PrintWriter;
+import java.io.StringReader;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -27,8 +30,10 @@ import java.util.Enumeration;
 import java.util.List;
 import java.util.Set;
 import java.util.TreeSet;
+import java.util.UUID;
 
 import org.apache.commons.io.IOUtils;
+import org.apache.felix.cm.file.ConfigurationHandler;
 import org.apache.felix.inventory.Format;
 import org.apache.felix.inventory.InventoryPrinter;
 import org.apache.felix.scr.annotations.Activate;
@@ -55,6 +60,13 @@ import org.osgi.service.component.Compon
 public class CrankstartInventoryPrinter implements InventoryPrinter {
 
     private BundleContext bundleContext;
+    private static final String INDENT = "  ";
+    
+    // Properties to ignore when dumping configs
+    private static final String [] PROPS_TO_IGNORE = {
+        Constants.SERVICE_PID,
+        "service.factoryPid"
+    };
     
     @Activate
     public void activate(ComponentContext ctx) {
@@ -75,19 +87,21 @@ public class CrankstartInventoryPrinter 
     }
     
     private void configs(PrintWriter out) throws IOException {
-        out.println("# TODO - dump OSGi configurations with FORMAT:felix.config");
-        
         final ServiceReference ref = bundleContext.getServiceReference(ConfigurationAdmin.class.getName());
         if(ref == null) {
             out.println("WARN - ConfigurationAdmin service not available");
             return;
         }
         
+        out.println("# The CRANKSTART_CONFIG_ID property that we add to configs is meant
to detect which factory configs have already been created");
+        
         final ConfigurationAdmin ca = (ConfigurationAdmin)bundleContext.getService(ref);
         try {
             final Configuration [] allCfg = ca.listConfigurations(null);
+            int count = 0;
             if(allCfg != null) {
                 for(Configuration cfg : allCfg) {
+                    count++;
                     if(cfg.getFactoryPid() != null && cfg.getFactoryPid().length()
> 0) {
                         out.print("config.factory ");
                         out.print(cfg.getFactoryPid());
@@ -96,10 +110,34 @@ public class CrankstartInventoryPrinter 
                         out.print(cfg.getPid());
                     }
                     out.println(" FORMAT:felix.config");
-                    out.print(" TODO - output values using org/apache/felix/cm/file/ConfigurationHandler");
+                    
+                    out.print(INDENT);
+                    out.print("CRANKSTART_CONFIG_ID=\"");
+                    out.print(UUID.randomUUID());
+                    out.println("\"");
+                    
+                    // Need to indent the config properties 
+                    final ByteArrayOutputStream bos = new ByteArrayOutputStream();
+                    ConfigurationHandler.write(bos, cfg.getProperties());
+                    final BufferedReader r = new BufferedReader(new StringReader(new String(bos.toString())));
+                    String line = null;
+                    
+                    readingLines:
+                    while((line = r.readLine()) != null) {
+                        for(String p : PROPS_TO_IGNORE) {
+                            if(line.startsWith(p)) {
+                                continue readingLines;
+                            }
+                        }
+                        out.print(INDENT);
+                        out.println(line);
+                    }
                     out.println();
                 }
             }
+            out.print("# ");
+            out.print(count);
+            out.println(" configurations processed");
         } catch(InvalidSyntaxException ise) {
             throw new RuntimeException("Unexpected InvalidSyntaxException", ise);
         } finally {
@@ -233,7 +271,5 @@ public class CrankstartInventoryPrinter 
         } finally {
             resource.close();
         }
-    }
-    
-    
-}
+    }    
+}
\ No newline at end of file



Mime
View raw message