incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1600912 - in /sling/trunk/contrib/crankstart/sling-extensions: pom.xml src/main/java/org/apache/sling/crankstart/extensions/sling/CrankstartInventoryPrinter.java src/main/resources/ src/main/resources/crankstart-header.txt
Date Fri, 06 Jun 2014 15:19:28 GMT
Author: bdelacretaz
Date: Fri Jun  6 15:19:28 2014
New Revision: 1600912

URL: http://svn.apache.org/r1600912
Log:
CrankstartInventoryPrinter - meant to reproduce a Sling instance in a Crankstart launcher,
via /system/console/status-crankstart.txt (work in progress)

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

Modified: sling/trunk/contrib/crankstart/sling-extensions/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/crankstart/sling-extensions/pom.xml?rev=1600912&r1=1600911&r2=1600912&view=diff
==============================================================================
--- sling/trunk/contrib/crankstart/sling-extensions/pom.xml (original)
+++ sling/trunk/contrib/crankstart/sling-extensions/pom.xml Fri Jun  6 15:19:28 2014
@@ -28,6 +28,11 @@
                 <configuration>
                     <instructions>
                         <Private-Package>org.apache.sling.crankstart.extensions.*</Private-Package>
+                        <Import-Package>
+                            org.apache.felix.inventory.*;resolution:=optional,
+                            org.apache.commons.io.*;resolution:=optional,
+                            *
+                        </Import-Package>
                     </instructions>
                 </configuration>
             </plugin>
@@ -64,6 +69,18 @@
             <scope>provided</scope>
         </dependency>
         <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.inventory</artifactId>
+            <version>1.0.4</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>commons-io</groupId>
+            <artifactId>commons-io</artifactId>
+            <version>2.4</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-simple</artifactId>
             <scope>provided</scope>

Added: 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=1600912&view=auto
==============================================================================
--- sling/trunk/contrib/crankstart/sling-extensions/src/main/java/org/apache/sling/crankstart/extensions/sling/CrankstartInventoryPrinter.java
(added)
+++ sling/trunk/contrib/crankstart/sling-extensions/src/main/java/org/apache/sling/crankstart/extensions/sling/CrankstartInventoryPrinter.java
Fri Jun  6 15:19:28 2014
@@ -0,0 +1,150 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.apache.sling.crankstart.extensions.sling;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintWriter;
+import java.net.URL;
+import java.util.Enumeration;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.felix.inventory.Format;
+import org.apache.felix.inventory.InventoryPrinter;
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Properties;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Service;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.component.ComponentContext;
+
+@Component
+@Service
+@Properties({
+    @Property(name = "felix.inventory.printer.name", value = "crankstart"),
+    @Property(name = "felix.inventory.printer.title", value = "Sling Crankstart Exporter"),
+    @Property(name = "felix.inventory.printer.format", value = "TEXT")
+})
+public class CrankstartInventoryPrinter implements InventoryPrinter {
+
+    private BundleContext bundleContext;
+    
+    @Activate
+    public void activate(ComponentContext ctx) {
+        bundleContext = ctx.getBundleContext();
+    }
+    
+    public void print(PrintWriter out, Format fmt, boolean isZip) {
+        try {
+            includeResource(out, "/crankstart-header.txt");
+            header(out, "bundles");
+            bundles(out);
+            header(out, "configurations");
+            configs(out);
+            header(out, "end of " + getClass().getSimpleName() + " status dump");
+        } catch(Exception e) {
+            e.printStackTrace(out);
+        }
+    }
+    
+    private void configs(PrintWriter out) throws IOException {
+        out.println("# TODO - dump OSGi configurations with FORMAT:felix.config");
+    }
+    
+    private void bundles(PrintWriter out) throws IOException {
+        int ok = 0;
+        int errors = 0;
+        for(Bundle b : bundleContext.getBundles()) {
+            final String coords = mavenCoordinates(b);
+            if(coords.length() == 0) {
+                errors++;
+                out.print("# ERROR: Maven coordinates not found for bundle ");
+                out.print(b.getSymbolicName());
+                out.print(" version ");
+                out.print(b.getVersion());
+                out.println();
+            } else {
+                ok++;
+                out.print("bundle ");
+                out.println(coords);
+            }
+        }
+        
+        out.println("start.all.bundles");
+        
+        out.print("# ");
+        out.print(ok);
+        out.print(" bundles processed sucessfully, ");
+        out.print(errors);
+        out.println(" errors.");
+    }
+    
+    private String mavenCoordinates(Bundle b) throws IOException {
+        final StringBuilder sb = new StringBuilder();
+        
+        @SuppressWarnings("unchecked")
+        final Enumeration<URL> entries = b.findEntries("META-INF/maven", "pom.properties",
true);
+        
+        int count=0;
+        while(entries != null && entries.hasMoreElements()) {
+            final URL u = entries.nextElement();
+            java.util.Properties props = new java.util.Properties();
+            InputStream is = null;
+            try {
+                is = u.openStream();
+                props.load(u.openStream());
+                sb.append("mvn:")
+                .append(props.get("groupId"))
+                .append("/")
+                .append(props.get("artifactId"))
+                .append("/")
+                .append(props.get("version"));
+            } finally {
+                IOUtils.closeQuietly(is);
+            }
+            count++;
+        }
+        
+        if(count > 1) {
+            sb.append(" WARNING - multiple entries, how to handle that?");
+        }
+ 
+        return sb.toString();
+    }
+    
+    private void header(PrintWriter out, String title) {
+        out.println();
+        out.print("# ");
+        out.println(title);
+    }
+    
+    private void includeResource(PrintWriter out, String path) throws IOException {
+        final InputStream resource = getClass().getResourceAsStream(path);
+        if(resource == null) {
+            throw new IOException("Resource not found: " + path);
+        }
+        try {
+            IOUtils.copy(resource, out);
+        } finally {
+            resource.close();
+        }
+    }
+    
+    
+}

Added: sling/trunk/contrib/crankstart/sling-extensions/src/main/resources/crankstart-header.txt
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/crankstart/sling-extensions/src/main/resources/crankstart-header.txt?rev=1600912&view=auto
==============================================================================
--- sling/trunk/contrib/crankstart/sling-extensions/src/main/resources/crankstart-header.txt
(added)
+++ sling/trunk/contrib/crankstart/sling-extensions/src/main/resources/crankstart-header.txt
Fri Jun  6 15:19:28 2014
@@ -0,0 +1,34 @@
+# ----------------------------------------------------------------------------
+# Sling Crankstart startup file generated by the CrankstartInventoryPrinter
+#
+# This file is meant to recreate an existing Sling instance using the 
+# Sling Crankstart launcher.
+# ----------------------------------------------------------------------------
+
+# TODO adapt this: default values for our variables
+defaults http.port 4502
+defaults osgi.storage.path cq-crankstart
+defaults felix.http.jetty.version 2.2.0
+
+# TODO adapt this: Bootstrap classpath (variables are not supported here)
+classpath mvn:org.apache.felix/org.apache.felix.framework/4.3.0-R1558704
+classpath mvn:org.apache.sling/org.apache.sling.crankstart.core/0.0.1-SNAPSHOT
+classpath mvn:org.apache.sling/org.apache.sling.crankstart.api/0.0.1-SNAPSHOT
+classpath mvn:org.slf4j/slf4j-api/1.7.6
+
+# TODO adapt this: OSGi properties
+osgi.property org.osgi.service.http.port ${http.port}
+osgi.property org.osgi.framework.storage ${osgi.storage.path}
+osgi.property sling.home SLING-HOME
+osgi.property felix.startlevel.bundle 22
+osgi.property org.osgi.framework.startlevel.beginning 32
+
+# TODO adapt this: Logging
+osgi.property org.apache.sling.commons.log.level INFO
+osgi.property org.apache.sling.commons.log.file logs/error.log
+osgi.property org.apache.sling.commons.log.file.number 5
+osgi.property org.apache.sling.commons.log.file.size '.'yyyy-MM-dd
+
+# Start the framework
+start.framework
+



Mime
View raw message