incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1599226 - in /sling/trunk/contrib/crankstart: ./ launcher/src/test/java/org/apache/sling/crankstart/launcher/ launcher/src/test/resources/ sling-extensions/ sling-extensions/src/ sling-extensions/src/main/ sling-extensions/src/main/java/ s...
Date Mon, 02 Jun 2014 14:33:42 GMT
Author: bdelacretaz
Date: Mon Jun  2 14:33:42 2014
New Revision: 1599226

URL: http://svn.apache.org/r1599226
Log:
Register resources with the Sling installer via a crankstart extension command

Added:
    sling/trunk/contrib/crankstart/sling-extensions/   (with props)
    sling/trunk/contrib/crankstart/sling-extensions/pom.xml
    sling/trunk/contrib/crankstart/sling-extensions/src/
    sling/trunk/contrib/crankstart/sling-extensions/src/main/
    sling/trunk/contrib/crankstart/sling-extensions/src/main/java/
    sling/trunk/contrib/crankstart/sling-extensions/src/main/java/org/
    sling/trunk/contrib/crankstart/sling-extensions/src/main/java/org/apache/
    sling/trunk/contrib/crankstart/sling-extensions/src/main/java/org/apache/sling/
    sling/trunk/contrib/crankstart/sling-extensions/src/main/java/org/apache/sling/crankstart/
    sling/trunk/contrib/crankstart/sling-extensions/src/main/java/org/apache/sling/crankstart/extensions/
    sling/trunk/contrib/crankstart/sling-extensions/src/main/java/org/apache/sling/crankstart/extensions/sling/
    sling/trunk/contrib/crankstart/sling-extensions/src/main/java/org/apache/sling/crankstart/extensions/sling/InstallerResourceCommand.java
Modified:
    sling/trunk/contrib/crankstart/launcher/src/test/java/org/apache/sling/crankstart/launcher/CrankstartBootstrapTest.java
    sling/trunk/contrib/crankstart/launcher/src/test/resources/launcher-test.crank.txt
    sling/trunk/contrib/crankstart/pom.xml
    sling/trunk/contrib/crankstart/test-services/pom.xml

Modified: sling/trunk/contrib/crankstart/launcher/src/test/java/org/apache/sling/crankstart/launcher/CrankstartBootstrapTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/crankstart/launcher/src/test/java/org/apache/sling/crankstart/launcher/CrankstartBootstrapTest.java?rev=1599226&r1=1599225&r2=1599226&view=diff
==============================================================================
--- sling/trunk/contrib/crankstart/launcher/src/test/java/org/apache/sling/crankstart/launcher/CrankstartBootstrapTest.java
(original)
+++ sling/trunk/contrib/crankstart/launcher/src/test/java/org/apache/sling/crankstart/launcher/CrankstartBootstrapTest.java
Mon Jun  2 14:33:42 2014
@@ -135,6 +135,15 @@ public class CrankstartBootstrapTest {
         assertEquals("was set by test-services bundle", System.getProperty(TEST_SYSTEM_PROPERTY));
     }
     
+    @Test
+    @Retry(timeoutMsec=10000, intervalMsec=250)
+    public void testJUnitServlet() throws Exception {
+        final String path = "/system/sling/junit";
+        final GetMethod get = new GetMethod(baseUrl + path);
+        client.executeMethod(get);
+        assertEquals("Expecting JUnit servlet to be installed via sling extension command,
at " + get.getURI(), 200, get.getStatusCode());
+    }
+    
     private static String getOsgiStoragePath() {
         final File tmpRoot = new File(System.getProperty("java.io.tmpdir"));
         final Random random = new Random();

Modified: sling/trunk/contrib/crankstart/launcher/src/test/resources/launcher-test.crank.txt
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/crankstart/launcher/src/test/resources/launcher-test.crank.txt?rev=1599226&r1=1599225&r2=1599226&view=diff
==============================================================================
--- sling/trunk/contrib/crankstart/launcher/src/test/resources/launcher-test.crank.txt (original)
+++ sling/trunk/contrib/crankstart/launcher/src/test/resources/launcher-test.crank.txt Mon
Jun  2 14:33:42 2014
@@ -26,6 +26,7 @@ bundle mvn:org.apache.felix/org.apache.f
 bundle mvn:org.apache.sling/org.apache.sling.commons.osgi/2.2.1-SNAPSHOT
 bundle mvn:org.apache.sling/org.apache.sling.commons.log/2.1.2
 bundle mvn:org.apache.felix/org.apache.felix.configadmin/1.6.0
+bundle mvn:org.apache.felix/org.apache.felix.webconsole/3.1.6
 
 # The crankstart.api.fragment bundle makes the crankstart.api package available
 # to bundles, required for bundles to provide crankstart extension commands like
@@ -33,6 +34,13 @@ bundle mvn:org.apache.felix/org.apache.f
 bundle mvn:org.apache.sling/org.apache.sling.crankstart.api.fragment/0.0.1-SNAPSHOT
 bundle mvn:org.apache.sling/org.apache.sling.crankstart.test.services/0.0.1-SNAPSHOT
 
+# Test our Sling extension commands, that add a bundle via the Sling installer
+# (which requires commons.json and jcr-wrapper)
+bundle mvn:org.apache.sling/org.apache.sling.installer.core/3.5.0
+bundle mvn:org.apache.sling/org.apache.sling.commons.json/2.0.6
+bundle mvn:org.apache.sling/org.apache.sling.jcr.jcr-wrapper/2.0.0
+bundle mvn:org.apache.sling/org.apache.sling.crankstart.sling.extensions/0.0.1-SNAPSHOT
+
 # Now start our bundles
 start.all.bundles
 
@@ -52,5 +60,8 @@ config.factory org.apache.sling.cranksta
 # Test an extension command provided by our test-services bundle
 test.system.property the.test.system.property was set by test-services bundle
   
+# Add the JUnit core via the Sling installer and our sling.extensions
+sling.installer.resource mvn:org.apache.sling/org.apache.sling.junit.core/1.0.8
+  
 # Informative log  
 log felix http service should come up at http://localhost:${http.port}
\ No newline at end of file

Modified: sling/trunk/contrib/crankstart/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/crankstart/pom.xml?rev=1599226&r1=1599225&r2=1599226&view=diff
==============================================================================
--- sling/trunk/contrib/crankstart/pom.xml (original)
+++ sling/trunk/contrib/crankstart/pom.xml Mon Jun  2 14:33:42 2014
@@ -47,5 +47,6 @@
       <module>core</module>
       <module>launcher</module>
       <module>test-services</module>
+      <module>sling-extensions</module>
     </modules>
 </project>

Propchange: sling/trunk/contrib/crankstart/sling-extensions/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Jun  2 14:33:42 2014
@@ -0,0 +1,15 @@
+target
+bin
+*.iml
+*.ipr
+*.iws
+.settings
+.project
+.classpath
+.externalToolBuilders
+maven-eclipse.xml
+felix-cache
+sling-crankstart
+derby.log
+
+

Added: sling/trunk/contrib/crankstart/sling-extensions/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/crankstart/sling-extensions/pom.xml?rev=1599226&view=auto
==============================================================================
--- sling/trunk/contrib/crankstart/sling-extensions/pom.xml (added)
+++ sling/trunk/contrib/crankstart/sling-extensions/pom.xml Mon Jun  2 14:33:42 2014
@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.sling</groupId>
+        <artifactId>sling</artifactId>
+        <version>19</version>
+        <relativePath />
+    </parent>
+    
+    <groupId>org.apache.sling</groupId>
+    <artifactId>org.apache.sling.crankstart.sling.extensions</artifactId>
+    <version>0.0.1-SNAPSHOT</version>
+    <packaging>bundle</packaging>
+    <name>Apache Sling Crankstart Sling Extensions</name>
+    <description>Sling-specific extension commands for the Crankstart launcher</description>
+    
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-scr-plugin</artifactId>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <extensions>true</extensions>
+                <configuration>
+                    <instructions>
+                        <Private-Package>org.apache.sling.crankstart.extensions.*</Private-Package>
+                    </instructions>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+    
+    <dependencies>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.core</artifactId>
+            <version>4.2.0</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.compendium</artifactId>
+            <version>4.2.0</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.scr.annotations</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.crankstart.api</artifactId>
+            <version>${project.version}</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.installer.core</artifactId>
+            <version>3.5.0</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-simple</artifactId>
+            <scope>provided</scope>
+        </dependency>
+    </dependencies>
+</project>

Added: sling/trunk/contrib/crankstart/sling-extensions/src/main/java/org/apache/sling/crankstart/extensions/sling/InstallerResourceCommand.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/crankstart/sling-extensions/src/main/java/org/apache/sling/crankstart/extensions/sling/InstallerResourceCommand.java?rev=1599226&view=auto
==============================================================================
--- sling/trunk/contrib/crankstart/sling-extensions/src/main/java/org/apache/sling/crankstart/extensions/sling/InstallerResourceCommand.java
(added)
+++ sling/trunk/contrib/crankstart/sling-extensions/src/main/java/org/apache/sling/crankstart/extensions/sling/InstallerResourceCommand.java
Mon Jun  2 14:33:42 2014
@@ -0,0 +1,75 @@
+/*
+ * 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.InputStream;
+import java.net.URL;
+
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.sling.crankstart.api.CrankstartCommand;
+import org.apache.sling.crankstart.api.CrankstartCommandLine;
+import org.apache.sling.crankstart.api.CrankstartContext;
+import org.apache.sling.crankstart.api.CrankstartException;
+import org.apache.sling.installer.api.InstallableResource;
+import org.apache.sling.installer.api.OsgiInstaller;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** CrankstartCommand that registers a resource with the Sling installer */
+@Component
+@Service
+public class InstallerResourceCommand implements CrankstartCommand {
+    
+    public static final String I_INSTALLER_RESOURCE = "sling.installer.resource";
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    public boolean appliesTo(CrankstartCommandLine commandLine) {
+        return I_INSTALLER_RESOURCE.equals(commandLine.getVerb());
+    }
+    
+    public String getDescription() {
+        return I_INSTALLER_RESOURCE + ": register a resource with the Sling installer";
+    }
+
+    public void execute(CrankstartContext crankstartContext, CrankstartCommandLine commandLine)
throws Exception {
+        final String resourceRef = commandLine.getQualifier();
+        final URL url = new URL(resourceRef);
+        final BundleContext ctx = crankstartContext.getOsgiFramework().getBundleContext();
+        final String serviceClass = OsgiInstaller.class.getName();
+        final ServiceReference ref = ctx.getServiceReference(serviceClass);
+        if(ref == null) {
+            throw new CrankstartException("Installer service not available, cannot register
resource (" + serviceClass + ")");
+        }
+        InputStream stream = null;
+        final OsgiInstaller installer = (OsgiInstaller)ctx.getService(ref);
+        try {
+            stream = url.openStream();
+            final String digest = resourceRef;
+            final InstallableResource r = new InstallableResource(resourceRef, stream, null,
digest, "file", 100);
+            installer.registerResources("crankstart", new InstallableResource[] { r });
+            log.info("Resource registered with Sling installer: {}", resourceRef);
+        } finally {
+            ctx.ungetService(ref);
+            if(stream != null) {
+                stream.close();
+            }
+        }
+    }
+}

Modified: sling/trunk/contrib/crankstart/test-services/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/crankstart/test-services/pom.xml?rev=1599226&r1=1599225&r2=1599226&view=diff
==============================================================================
--- sling/trunk/contrib/crankstart/test-services/pom.xml (original)
+++ sling/trunk/contrib/crankstart/test-services/pom.xml Mon Jun  2 14:33:42 2014
@@ -27,11 +27,7 @@
                 <extensions>true</extensions>
                 <configuration>
                     <instructions>
-                        <Private-Package>org.apache.sling.crankstart.*</Private-Package>
-                        <Import-Package>
-                            org.apache.sling.crankstart.api,
-                            *
-                        </Import-Package>
+                        <Private-Package>org.apache.sling.crankstart.testservices.*</Private-Package>
                     </instructions>
                 </configuration>
             </plugin>



Mime
View raw message