[ 
https://issues.apache.org/jira/browse/KARAF-334?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12973251#action_12973251
 ] 

Stephane Chomat commented on KARAF-334:
---------------------------------------

I see an another problem.
I test with startlevel one and two. But if i test with five and 10, the test 
doesn't work.

I propose this correction.
diff -r 715709e78bab src/main/java/org/apache/karaf/main/Main.java
--- a/src/main/java/org/apache/karaf/main/Main.java     Mon Dec 20 17:22:04 
2010 +0100
+++ b/src/main/java/org/apache/karaf/main/Main.java     Mon Dec 20 17:34:52 
2010 +0100
@@ -556,6 +556,7 @@
                                                                        + 
b.getSymbolicName() + ": " + ex);
                                                }
                                        }
+                                       sl.setStartLevel(startLevel);
                                }
             }
         }
Thanks.


I propose this test but you must extecute this test in two separated jvm. If I 
run the second test alone without correction, it doesn't work. But i I exexute 
the two test I see a trace "Error installing bundle  
mvn:org.osgi/org.osgi.compendium/4.2.0|unused: java.net.MalformedURLException: 
Unknown protocol: mvn" but the test passes.



/*
 * 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.karaf.main;

import java.io.File;
import java.util.Properties;

import junit.framework.Assert;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.osgi.framework.Bundle;
import org.osgi.framework.launch.Framework;

/**
 * Before running this test, you must delete all directory like 
target/test-karaf-home-*
 * @author Stephane Chomat
 *
 */
public class MainStartTest {
        Properties backup = null;
        
        @Before
        public void before() {
                backup = System.getProperties();
        }
        
        @After
        public void after() {
                System.setProperties(backup);
        }
        
        /** 
         * Start two bundles at level one and two.
         * At level one start mvn handler service and at level 2 use mvn 
handler service.
         * @throws Exception cannot start karaf.
         */
        @Test
    public void testAutoStart() throws Exception {
                File basedir = new 
File(getClass().getClassLoader().getResource("foo").getPath()).getParentFile();
        File home = new File(basedir, "test-karaf-home");
        File data = new File(home, "data");

        Utils.deleteDirectory(data);

                String[] args = new String[0];
                String fileMVNbundle = new File(home, 
"bundles/pax-url-mvn.jar").toURI().toURL().toExternalForm();
                String mvnUrl = "mvn:org.osgi/org.osgi.compendium/4.2.0";
                System.setProperty("karaf.home", home.toString());
                System.setProperty("karaf.data", data.toString());
                System.setProperty("karaf.auto.start.1", 
"\""+fileMVNbundle+"|unused\"");
                System.setProperty("karaf.auto.start.2", 
"\""+mvnUrl+"|unused\"");
                System.setProperty("karaf.maven.convert", "false");

                Main main = new Main(args);
                main.launch();
                Thread.sleep(1000);
                Framework framework = main.getFramework();
                Bundle[] bundles = framework.getBundleContext().getBundles();
                Assert.assertEquals(3, bundles.length);
                Assert.assertEquals(fileMVNbundle, bundles[1].getLocation());
                Assert.assertEquals(mvnUrl, bundles[2].getLocation());
                Assert.assertEquals(Bundle.ACTIVE, bundles[1].getState());
                Assert.assertEquals(Bundle.ACTIVE, bundles[2].getState());
                main.destroy(false);
        }
        
        /** 
         * Start two bundles at level 5 and 10.
         * At level 5 start mvn handler service and at level 10 use mvn handler 
service.
         * @throws Exception cannot start karaf.
         */
        @Test
    public void testAutoStart2() throws Exception {
                File basedir = new 
File(getClass().getClassLoader().getResource("foo").getPath()).getParentFile();
        File home = new File(basedir, "test-karaf-home");
        File data = new File(home, "data-2");

        Utils.deleteDirectory(data);

                String[] args = new String[0];
                String fileMVNbundle = new File(home, 
"bundles/pax-url-mvn.jar").toURI().toURL().toExternalForm();
                String mvnUrl = "mvn:org.osgi/org.osgi.compendium/4.2.0";
                System.setProperty("karaf.home", home.toString());
                System.setProperty("karaf.data", data.toString());
                System.setProperty("karaf.auto.start.5", 
"\""+fileMVNbundle+"|unused\"");
                System.setProperty("karaf.auto.start.10", 
"\""+mvnUrl+"|unused\"");
                System.setProperty("karaf.maven.convert", "false");

                Main main = new Main(args);
                main.launch();
                Thread.sleep(1000);
                Framework framework = main.getFramework();
                Bundle[] bundles = framework.getBundleContext().getBundles();
                Assert.assertEquals(3, bundles.length);
                Assert.assertEquals(fileMVNbundle, bundles[1].getLocation());
                Assert.assertEquals(mvnUrl, bundles[2].getLocation());
                Assert.assertEquals(Bundle.ACTIVE, bundles[1].getState());
                Assert.assertEquals(Bundle.ACTIVE, bundles[2].getState());
                main.destroy(false);
        }
}

> At startup, Karaf does not support urls like mvn:, obr:.
> --------------------------------------------------------
>
>                 Key: KARAF-334
>                 URL: https://issues.apache.org/jira/browse/KARAF-334
>             Project: Karaf
>          Issue Type: Improvement
>          Components: runtime
>    Affects Versions: 2.1.2
>            Reporter: Stephane Chomat
>            Assignee: Guillaume Nodet
>             Fix For: 2.1.3, 2.2.0
>
>         Attachments: test-karaf-home.zip
>
>   Original Estimate: 24h
>  Remaining Estimate: 24h
>
> At startup, Karafi does not support urls like mvn:, obr:.
> Imagine that at level 5 you install the bundle pax-url-mvn with 
> karaf.auto.start.5 = "file: pax-url-mvn.jar | pax-url-mvn" 
> and then at level 10 you install mvn:. ... With karaf.auto.start.10 = "mvn 
> :....| ...."
> At the level 6 the url handler 'mvn' is available and you can use it.
> This feature does not work with Karaf
> I propose this path :
> diff -r f0bb11c3d77c src/main/java/org/apache/karaf/main/Main.java
> --- a/src/main/java/org/apache/karaf/main/Main.java   Mon Dec 20 11:05:11 
> 2010 +0100
> +++ b/src/main/java/org/apache/karaf/main/Main.java   Mon Dec 20 11:46:29 
> 2010 +0100
> @@ -485,28 +485,20 @@
>          // the start level to which the bundles are assigned is specified by
>          // appending a ".n" to the auto-install property name, where "n" is
>          // the desired start level for the list of bundles.
> -        autoInstall(PROPERTY_AUTO_INSTALL, context, sl, convertToMavenUrls);
> +        autoInstall(PROPERTY_AUTO_INSTALL, context, sl, convertToMavenUrls, 
> false);
>  
>          // The auto-start property specifies a space-delimited list of
>          // bundle URLs to be automatically installed and started into each
>          // new profile; the start level to which the bundles are assigned
>          // is specified by appending a ".n" to the auto-start property name,
>          // where "n" is the desired start level for the list of bundles.
> -        // The following code starts bundles in two passes, first it installs
> -        // them, then it starts them.
> -            List<Bundle> bundlesToStart = autoInstall(PROPERTY_AUTO_START, 
> context, sl, convertToMavenUrls);
> -        // Now loop through and start the installed bundles.
> -        for (Bundle b : bundlesToStart) {
> -            try {
> -                b.start();
> -            }
> -            catch (Exception ex) {
> -                System.err.println("Auto-properties start: " + ex);
> -            }
> -        }
> +        // The following code starts bundles in one passes, it installs
> +        // and it starts them by level.
> +        autoInstall(PROPERTY_AUTO_START, context, sl, convertToMavenUrls, 
> true);
> +        
>      }
>  
> -    private List<Bundle> autoInstall(String propertyPrefix, BundleContext 
> context, StartLevel sl, boolean convertToMavenUrls) {
> +    private List<Bundle> autoInstall(String propertyPrefix, BundleContext 
> context, StartLevel sl, boolean convertToMavenUrls, boolean start) {
>          Map<Integer, String> autoStart = new TreeMap<Integer, String>();
>          List<Bundle> bundles = new ArrayList<Bundle>();
>          for (Iterator i = configProps.keySet().iterator(); i.hasNext();) {
> @@ -531,6 +523,7 @@
>          }
>          for (Integer startLevel : autoStart.keySet()) {
>              StringTokenizer st = new 
> StringTokenizer(autoStart.get(startLevel), "\" ", true);
> +            List<Bundle> bundlesLevel = new ArrayList<Bundle>();
>              if (st.countTokens() > 0) {
>                  String location = null;
>                  do {
> @@ -541,6 +534,7 @@
>                              Bundle b = context.installBundle(parts[0], new 
> URL(parts[1]).openStream());
>                              sl.setBundleStartLevel(b, startLevel);
>                              bundles.add(b);
> +                            bundlesLevel.add(b);
>                          }
>                          catch (Exception ex) {
>                              System.err.println("Auto-properties install:" + 
> ex);
> @@ -549,6 +543,15 @@
>                  }
>                  while (location != null);
>              }
> +         // Now loop through and start the installed bundles.
> +            for (Bundle b : bundlesLevel) {
> +                try {
> +                    b.start();
> +                }
> +                catch (Exception ex) {
> +                    System.err.println("Auto-properties start: " + ex);
> +                }
> +            }
>          }
>          return bundles;
>      }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to