-1 see dev thread. Please revert. On Fri, May 25, 2012 at 4:40 PM, <[email protected]> wrote: > Author: cschneider > Date: Fri May 25 14:40:34 2012 > New Revision: 1342652 > > URL: http://svn.apache.org/viewvc?rev=1342652&view=rev > Log: > KARAF-1296 Adding startup feature loading to main > > Added: > karaf/trunk/main/src/main/java/org/apache/karaf/main/FeatureReader.java > karaf/trunk/main/src/test/java/org/apache/karaf/main/FeatureReaderTest.java > Modified: > karaf/trunk/main/src/main/java/org/apache/karaf/main/BundleInfo.java > karaf/trunk/main/src/main/java/org/apache/karaf/main/ConfigProperties.java > karaf/trunk/main/src/main/java/org/apache/karaf/main/Main.java > karaf/trunk/main/src/test/resources/test-karaf-home/etc/config.properties > karaf/trunk/main/src/test/resources/test-karaf-home/etc/startup.properties > > Modified: karaf/trunk/main/src/main/java/org/apache/karaf/main/BundleInfo.java > URL: > http://svn.apache.org/viewvc/karaf/trunk/main/src/main/java/org/apache/karaf/main/BundleInfo.java?rev=1342652&r1=1342651&r2=1342652&view=diff > ============================================================================== > --- karaf/trunk/main/src/main/java/org/apache/karaf/main/BundleInfo.java > (original) > +++ karaf/trunk/main/src/main/java/org/apache/karaf/main/BundleInfo.java Fri > May 25 14:40:34 2012 > @@ -1,3 +1,21 @@ > +/* > + * 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.net.URI; > > Modified: > karaf/trunk/main/src/main/java/org/apache/karaf/main/ConfigProperties.java > URL: > http://svn.apache.org/viewvc/karaf/trunk/main/src/main/java/org/apache/karaf/main/ConfigProperties.java?rev=1342652&r1=1342651&r2=1342652&view=diff > ============================================================================== > --- > karaf/trunk/main/src/main/java/org/apache/karaf/main/ConfigProperties.java > (original) > +++ > karaf/trunk/main/src/main/java/org/apache/karaf/main/ConfigProperties.java > Fri May 25 14:40:34 2012 > @@ -95,6 +95,10 @@ public class ConfigProperties { > private static final String KARAF_SHUTDOWN_COMMAND = > "karaf.shutdown.command"; > > private static final String KARAF_SHUTDOWN_PID_FILE = > "karaf.shutdown.pid.file"; > + > + static final String KARAF_STARTUP_FEATURE_URI = > "karaf.startup.feature.uri"; > + > + private static final String KARAF_STARTUP_FEATURE_NAME = > "karaf.startup.feature.name"; > > private static final String DEFAULT_SHUTDOWN_COMMAND = "SHUTDOWN"; > > @@ -133,6 +137,8 @@ public class ConfigProperties { > String includes; > String optionals; > File etcFolder; > + URI startupFeatureUri; > + String startupFeatureName; > > public ConfigProperties() throws Exception { > this.karafHome = Utils.getKarafHome(ConfigProperties.class, > PROP_KARAF_HOME, ENV_KARAF_HOME); > @@ -183,6 +189,10 @@ public class ConfigProperties { > this.shutdownHost = props.getProperty(KARAF_SHUTDOWN_HOST, > "localhost"); > this.portFile = props.getProperty(KARAF_SHUTDOWN_PORT_FILE); > this.shutdownCommand = props.getProperty(KARAF_SHUTDOWN_COMMAND, > DEFAULT_SHUTDOWN_COMMAND); > + if (props.getProperty(KARAF_STARTUP_FEATURE_URI) != null) { > + this.startupFeatureUri = new > URI(props.getProperty(KARAF_STARTUP_FEATURE_URI)); > + } > + this.startupFeatureName = > props.getProperty(KARAF_STARTUP_FEATURE_NAME, "framework"); > } > > private String getProperyOrFail(String propertyName) { > > Added: karaf/trunk/main/src/main/java/org/apache/karaf/main/FeatureReader.java > URL: > http://svn.apache.org/viewvc/karaf/trunk/main/src/main/java/org/apache/karaf/main/FeatureReader.java?rev=1342652&view=auto > ============================================================================== > --- karaf/trunk/main/src/main/java/org/apache/karaf/main/FeatureReader.java > (added) > +++ karaf/trunk/main/src/main/java/org/apache/karaf/main/FeatureReader.java > Fri May 25 14:40:34 2012 > @@ -0,0 +1,68 @@ > +/* > + * 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.InputStream; > +import java.net.URI; > +import java.net.URISyntaxException; > +import java.util.ArrayList; > +import java.util.List; > + > +import javax.xml.parsers.DocumentBuilder; > +import javax.xml.parsers.DocumentBuilderFactory; > + > +import org.w3c.dom.Document; > +import org.w3c.dom.Element; > +import org.w3c.dom.NodeList; > + > +class FeatureReader { > + List<BundleInfo> readBundles(URI featureUri, String featureName) throws > Exception { > + InputStream is = featureUri.toURL().openStream(); > + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); > + DocumentBuilder db = dbf.newDocumentBuilder(); > + Document doc = db.parse(is); > + is.close(); > + NodeList features = doc.getElementsByTagName("feature"); > + for (int c=0; c<features.getLength(); c++) { > + Element feature = (Element) features.item(c); > + String name = feature.getAttribute("name"); > + if (featureName.equals(name)) { > + NodeList bundleNodes = > feature.getElementsByTagName("bundle"); > + return getBundles(bundleNodes); > + } > + } > + return new ArrayList<BundleInfo>(); > + } > + > + private List<BundleInfo> getBundles(NodeList bundleNodes) throws > URISyntaxException { > + ArrayList<BundleInfo> bundles = new ArrayList<BundleInfo>(); > + for (int c=0; c<bundleNodes.getLength(); c++) { > + Element bundleNode = (Element)bundleNodes.item(c); > + String startLevel = bundleNode.getAttribute("start-level"); > + String uri = bundleNode.getFirstChild().getNodeValue(); > + BundleInfo bi = new BundleInfo(); > + if (startLevel != null) { > + bi.startLevel = new Integer(startLevel); > + } > + bi.uri = new URI(uri); > + bundles.add(bi); > + } > + return bundles; > + } > +} > > Modified: karaf/trunk/main/src/main/java/org/apache/karaf/main/Main.java > URL: > http://svn.apache.org/viewvc/karaf/trunk/main/src/main/java/org/apache/karaf/main/Main.java?rev=1342652&r1=1342651&r2=1342652&view=diff > ============================================================================== > --- karaf/trunk/main/src/main/java/org/apache/karaf/main/Main.java (original) > +++ karaf/trunk/main/src/main/java/org/apache/karaf/main/Main.java Fri May 25 > 14:40:34 2012 > @@ -20,12 +20,9 @@ package org.apache.karaf.main; > > import java.io.BufferedReader; > import java.io.File; > -import java.io.IOException; > import java.io.InputStream; > import java.io.InputStreamReader; > -import java.net.MalformedURLException; > import java.net.URI; > -import java.net.URISyntaxException; > import java.net.URL; > import java.net.URLClassLoader; > import java.security.Provider; > @@ -241,9 +238,23 @@ public class Main { > > LOG.info("Installing and starting initial bundles"); > File startupPropsFile = new File(config.etcFolder, > STARTUP_PROPERTIES_FILE_NAME); > - List<BundleInfo> bundles = > readBundlesFromStartupProperties(startupPropsFile); > - installAndStartBundles(resolver, framework.getBundleContext(), > bundles); > - LOG.info("All initial bundles installed and set to start"); > + if (startupPropsFile.exists()) { > + LOG.info("Installing and starting bundles from " + > startupPropsFile); > + List<BundleInfo> bundles = > readBundlesFromStartupProperties(startupPropsFile); > + installAndStartBundles(resolver, > framework.getBundleContext(), bundles); > + } > + > + if (config.startupFeatureUri != null) { > + LOG.info("Installing and starting bundles from startup > feature uri " + config.startupFeatureUri + ", name " + > config.startupFeatureName); > + URI resolvedStartupFeatureUri = > resolver.resolve(config.startupFeatureUri); > + List<BundleInfo> bundles = new > FeatureReader().readBundles(resolvedStartupFeatureUri, > config.startupFeatureName); > + installAndStartBundles(resolver, > framework.getBundleContext(), bundles); > + } > + int numBundles = > framework.getBundleContext().getBundles().length -1; > + if (numBundles == 0) { > + throw new RuntimeException("No bundles loaded. You either > need a etc/startup.properties or set " + > ConfigProperties.KARAF_STARTUP_FEATURE_URI + " in config.properties"); > + } > + LOG.info(numBundles + " initial bundles installed and set to > start"); > } > > ServerInfo serverInfo = new ServerInfoImpl(args, config); > > Added: > karaf/trunk/main/src/test/java/org/apache/karaf/main/FeatureReaderTest.java > URL: > http://svn.apache.org/viewvc/karaf/trunk/main/src/test/java/org/apache/karaf/main/FeatureReaderTest.java?rev=1342652&view=auto > ============================================================================== > --- > karaf/trunk/main/src/test/java/org/apache/karaf/main/FeatureReaderTest.java > (added) > +++ > karaf/trunk/main/src/test/java/org/apache/karaf/main/FeatureReaderTest.java > Fri May 25 14:40:34 2012 > @@ -0,0 +1,39 @@ > +/* > + * 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.net.URI; > +import java.net.URISyntaxException; > +import java.net.URL; > +import java.util.List; > + > +import org.junit.Assert; > +import org.junit.Test; > + > +public class FeatureReaderTest { > + > + @Test > + public void testReadBundlesFromFeature() throws URISyntaxException, > Exception { > + URL res = > this.getClass().getClassLoader().getResource("test-karaf-home/system/org/apache/karaf/features/framework/1.0.0/framework-1.0.0-features.xml"); > + List<BundleInfo> bundles = new > FeatureReader().readBundles(res.toURI(), "framework"); > + Assert.assertEquals(1, bundles.size()); > + Assert.assertEquals(10, bundles.get(0).startLevel.intValue()); > + Assert.assertEquals(new > URI("mvn:org.apache.aries.blueprint/org.apache.aries.blueprint.api/0.3.1"), > bundles.get(0).uri); > + } > +} > > Modified: > karaf/trunk/main/src/test/resources/test-karaf-home/etc/config.properties > URL: > http://svn.apache.org/viewvc/karaf/trunk/main/src/test/resources/test-karaf-home/etc/config.properties?rev=1342652&r1=1342651&r2=1342652&view=diff > ============================================================================== > --- karaf/trunk/main/src/test/resources/test-karaf-home/etc/config.properties > (original) > +++ karaf/trunk/main/src/test/resources/test-karaf-home/etc/config.properties > Fri May 25 14:40:34 2012 > @@ -39,3 +39,4 @@ org.osgi.framework.startlevel.beginning= > karaf.startlevel.bundle=60 > karaf.name=root > karaf.default.repository=system > +karaf.startup.feature.uri=mvn:org.apache.karaf.features/framework/1.0.0/xml/features > > Modified: > karaf/trunk/main/src/test/resources/test-karaf-home/etc/startup.properties > URL: > http://svn.apache.org/viewvc/karaf/trunk/main/src/test/resources/test-karaf-home/etc/startup.properties?rev=1342652&r1=1342651&r2=1342652&view=diff > ============================================================================== > --- > karaf/trunk/main/src/test/resources/test-karaf-home/etc/startup.properties > (original) > +++ > karaf/trunk/main/src/test/resources/test-karaf-home/etc/startup.properties > Fri May 25 14:40:34 2012 > @@ -23,6 +23,4 @@ > # > # Startup core services like logging > # > -mvn\:org.apache.aries.blueprint/org.apache.aries.blueprint.api/0.3.1=10 > pax-url-mvn.jar=10 > -#mvn\:org.apache.felix/org.apache.felix.configadmin/1.2.8=10 > >
-- ------------------------ Guillaume Nodet ------------------------ Blog: http://gnodet.blogspot.com/ ------------------------ FuseSource, Integration everywhere http://fusesource.com
