sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1684661 - in /sling/whiteboard/bdelacretaz/crankstart3/launcher/src: main/java/org/apache/sling/crankstart/launcher/ test/java/org/apache/sling/crankstart/launcher/
Date Wed, 10 Jun 2015 12:41:24 GMT
Author: bdelacretaz
Date: Wed Jun 10 12:41:24 2015
New Revision: 1684661

URL: http://svn.apache.org/r1684661
Log:
SLING-4728 - cleanup

Removed:
    sling/whiteboard/bdelacretaz/crankstart3/launcher/src/main/java/org/apache/sling/crankstart/launcher/CrankstartBootstrap.java
    sling/whiteboard/bdelacretaz/crankstart3/launcher/src/main/java/org/apache/sling/crankstart/launcher/CrankstartModelHelper.java
Modified:
    sling/whiteboard/bdelacretaz/crankstart3/launcher/src/main/java/org/apache/sling/crankstart/launcher/Launcher.java
    sling/whiteboard/bdelacretaz/crankstart3/launcher/src/test/java/org/apache/sling/crankstart/launcher/CrankstartBootstrapTest.java

Modified: sling/whiteboard/bdelacretaz/crankstart3/launcher/src/main/java/org/apache/sling/crankstart/launcher/Launcher.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/crankstart3/launcher/src/main/java/org/apache/sling/crankstart/launcher/Launcher.java?rev=1684661&r1=1684660&r2=1684661&view=diff
==============================================================================
--- sling/whiteboard/bdelacretaz/crankstart3/launcher/src/main/java/org/apache/sling/crankstart/launcher/Launcher.java
(original)
+++ sling/whiteboard/bdelacretaz/crankstart3/launcher/src/main/java/org/apache/sling/crankstart/launcher/Launcher.java
Wed Jun 10 12:41:24 2015
@@ -16,7 +16,11 @@
  */
 package org.apache.sling.crankstart.launcher;
 
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
 import java.io.IOException;
+import java.io.Reader;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.net.MalformedURLException;
@@ -26,6 +30,8 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.SortedSet;
+import java.util.TreeSet;
 
 import org.apache.sling.provisioning.model.Artifact;
 import org.apache.sling.provisioning.model.ArtifactGroup;
@@ -33,6 +39,7 @@ import org.apache.sling.provisioning.mod
 import org.apache.sling.provisioning.model.Model;
 import org.apache.sling.provisioning.model.ModelUtility;
 import org.apache.sling.provisioning.model.RunMode;
+import org.apache.sling.provisioning.model.io.ModelReader;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.launch.Framework;
 import org.osgi.framework.launch.FrameworkFactory;
@@ -41,13 +48,45 @@ import org.slf4j.LoggerFactory;
 
 /** Launch an OSGi app instance using the Sling provisioning model */
 public class Launcher {
-    private Model model;
+    private final Model model = new Model();
     private final Logger log = LoggerFactory.getLogger(getClass());
     
-    public Launcher(String [] args) throws IOException {
-        final CrankstartModelHelper mr = new CrankstartModelHelper();
-        mr.read(args);
-        model = ModelUtility.getEffectiveModel(mr.getModel(), null);
+    public Launcher(String ... args) throws IOException {
+        // Find all files to read and sort the list, to be deterministic
+        final SortedSet<File> toRead = new TreeSet<File>();
+        
+        for(String name : args) {
+            final File f = new File(name);
+            if(f.isDirectory()) {
+                final String [] list = f.list();
+                for(String s : list) {
+                    toRead.add(new File(f, s));
+                }
+            } else {
+                toRead.add(f);
+            }
+        }
+        
+        for(File f : toRead) {
+            mergeModel(f);
+        }
+    }
+    
+    /** Can be called before launch() to read and merge additional models.
+     *  @param r provisioning model to read, closed by this method after reading */ 
+    public void mergeModel(Reader r, String sourceInfo) throws IOException {
+        try {
+            log.info("Merging provisioning model {}", sourceInfo);
+            final Model m = ModelReader.read(r, sourceInfo);
+            ModelUtility.merge(model, ModelUtility.getEffectiveModel(m, null) );
+        } finally {
+            r.close();
+        }
+    }
+    
+    /** Can be called before launch() to read and merge additional models */
+    public void mergeModel(File f) throws IOException {
+        mergeModel(new BufferedReader(new FileReader(f)), f.getAbsolutePath());
     }
     
     public void launch() throws Exception {

Modified: sling/whiteboard/bdelacretaz/crankstart3/launcher/src/test/java/org/apache/sling/crankstart/launcher/CrankstartBootstrapTest.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/crankstart3/launcher/src/test/java/org/apache/sling/crankstart/launcher/CrankstartBootstrapTest.java?rev=1684661&r1=1684660&r2=1684661&view=diff
==============================================================================
--- sling/whiteboard/bdelacretaz/crankstart3/launcher/src/test/java/org/apache/sling/crankstart/launcher/CrankstartBootstrapTest.java
(original)
+++ sling/whiteboard/bdelacretaz/crankstart3/launcher/src/test/java/org/apache/sling/crankstart/launcher/CrankstartBootstrapTest.java
Wed Jun 10 12:41:24 2015
@@ -2,7 +2,6 @@ package org.apache.sling.crankstart.laun
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
@@ -41,7 +40,9 @@ public class CrankstartBootstrapTest {
     private static DefaultHttpClient client;
     private static Thread crankstartThread;
     private static String baseUrl = "http://localhost:" + port;
-    public static final String TEST_RESOURCE = "/launcher-test.crank.txt";
+    public static final String TEST_RESOURCE = "/crankstart-model.txt";
+    public static final int LONG_TIMEOUT = 1; // TODO increase once these tests should pass!
+    public static final int STD_INTERVAL = 250;
             
     @Rule
     public final RetryRule retryRule = new RetryRule();
@@ -77,7 +78,7 @@ public class CrankstartBootstrapTest {
     }
     
     @BeforeClass
-    public static void setup() {
+    public static void setup() throws IOException {
         client = new DefaultHttpClient(); 
         final HttpUriRequest get = new HttpGet(baseUrl);
         System.setProperty("http.port", String.valueOf(port));
@@ -93,10 +94,13 @@ public class CrankstartBootstrapTest {
         } catch(IOException expected) {
         }
         
+        final Launcher launcher = new Launcher();
+        launcher.mergeModel(input, TEST_RESOURCE);
+        
         crankstartThread = new Thread() {
             public void run() {
                 try {
-                    new CrankstartBootstrap(input).start();
+                    launcher.launch();
                 } catch(Exception e) {
                     e.printStackTrace();
                     fail("CrankstartBootstrap exception:" + e);
@@ -125,7 +129,7 @@ public class CrankstartBootstrapTest {
     }
     
     @Test
-    @Retry(timeoutMsec=10000, intervalMsec=250)
+    @Retry(timeoutMsec=CrankstartBootstrapTest.LONG_TIMEOUT, intervalMsec=CrankstartBootstrapTest.STD_INTERVAL)
     public void testHttpRoot() throws Exception {
         final HttpUriRequest get = new HttpGet(baseUrl);
         HttpResponse response = null;
@@ -138,7 +142,7 @@ public class CrankstartBootstrapTest {
     }
     
     @Test
-    @Retry(timeoutMsec=10000, intervalMsec=250)
+    @Retry(timeoutMsec=CrankstartBootstrapTest.LONG_TIMEOUT, intervalMsec=CrankstartBootstrapTest.STD_INTERVAL)
     public void testSingleConfigServlet() throws Exception {
         final HttpUriRequest get = new HttpGet(baseUrl + "/single");
         HttpResponse response = null;
@@ -151,7 +155,7 @@ public class CrankstartBootstrapTest {
     }
     
     @Test
-    @Retry(timeoutMsec=10000, intervalMsec=250)
+    @Retry(timeoutMsec=CrankstartBootstrapTest.LONG_TIMEOUT, intervalMsec=CrankstartBootstrapTest.STD_INTERVAL)
     public void testConfigFactoryServlet() throws Exception {
         final String [] paths = { "/foo", "/bar/test" };
         for(String path : paths) {
@@ -167,7 +171,7 @@ public class CrankstartBootstrapTest {
     }
     
     @Test
-    @Retry(timeoutMsec=10000, intervalMsec=250)
+    @Retry(timeoutMsec=CrankstartBootstrapTest.LONG_TIMEOUT, intervalMsec=CrankstartBootstrapTest.STD_INTERVAL)
     public void testJUnitServlet() throws Exception {
         final String path = "/system/sling/junit";
         final HttpUriRequest get = new HttpGet(baseUrl + path);
@@ -181,7 +185,7 @@ public class CrankstartBootstrapTest {
     }
     
     @Test
-    @Retry(timeoutMsec=10000, intervalMsec=250)
+    @Retry(timeoutMsec=CrankstartBootstrapTest.LONG_TIMEOUT, intervalMsec=CrankstartBootstrapTest.STD_INTERVAL)
     public void testAdditionalBundles() throws Exception {
         setAdminCredentials();
         final String basePath = "/system/console/bundles/";
@@ -204,7 +208,7 @@ public class CrankstartBootstrapTest {
     }
     
     @Test
-    @Retry(timeoutMsec=10000, intervalMsec=250)
+    @Retry(timeoutMsec=CrankstartBootstrapTest.LONG_TIMEOUT, intervalMsec=CrankstartBootstrapTest.STD_INTERVAL)
     public void testSpecificStartLevel() throws Exception {
         // Verify that this bundle is only installed, as it's set to start level 99
         setAdminCredentials();
@@ -241,7 +245,7 @@ public class CrankstartBootstrapTest {
     }
     
     @Test
-    @Retry(timeoutMsec=10000, intervalMsec=250)
+    @Retry(timeoutMsec=CrankstartBootstrapTest.LONG_TIMEOUT, intervalMsec=CrankstartBootstrapTest.STD_INTERVAL)
     public void testEmptyConfig() throws Exception {
         setAdminCredentials();
         assertHttpGet(
@@ -250,7 +254,7 @@ public class CrankstartBootstrapTest {
     }
         
     @Test
-    @Retry(timeoutMsec=10000, intervalMsec=250)
+    @Retry(timeoutMsec=CrankstartBootstrapTest.LONG_TIMEOUT, intervalMsec=CrankstartBootstrapTest.STD_INTERVAL)
     public void testFelixFormatConfig() throws Exception {
         setAdminCredentials();
         assertHttpGet(



Mime
View raw message