Author: cschneider Date: Wed Jul 4 13:10:10 2012 New Revision: 1357236 URL: http://svn.apache.org/viewvc?rev=1357236&view=rev Log: KARAF-1607 Moving the dev:framework and dev:system-property to system and removing the dev modules
Added: karaf/trunk/system/command/src/main/java/org/apache/karaf/system/commands/AbstractSystemAction.java karaf/trunk/system/command/src/main/java/org/apache/karaf/system/commands/FrameworkOptions.java - copied, changed from r1356761, karaf/trunk/dev/command/src/main/java/org/apache/karaf/dev/command/FrameworkOptions.java karaf/trunk/system/command/src/main/java/org/apache/karaf/system/commands/SystemProperty.java - copied, changed from r1356761, karaf/trunk/dev/command/src/main/java/org/apache/karaf/dev/command/SystemProperty.java karaf/trunk/system/core/src/main/java/org/apache/karaf/system/FrameworkType.java - copied, changed from r1356743, karaf/trunk/dev/core/src/main/java/org/apache/karaf/dev/core/FrameworkType.java Removed: karaf/trunk/dev/ Modified: karaf/trunk/assemblies/features/standard/pom.xml karaf/trunk/assemblies/features/standard/src/main/feature/feature.xml karaf/trunk/pom.xml karaf/trunk/system/command/src/main/java/org/apache/karaf/system/commands/Name.java karaf/trunk/system/command/src/main/java/org/apache/karaf/system/commands/Shutdown.java karaf/trunk/system/command/src/main/resources/OSGI-INF/blueprint/system-commands.xml karaf/trunk/system/core/src/main/java/org/apache/karaf/system/SystemService.java karaf/trunk/system/core/src/main/java/org/apache/karaf/system/internal/SystemServiceImpl.java karaf/trunk/system/core/src/main/java/org/apache/karaf/system/management/SystemMBean.java karaf/trunk/system/core/src/main/java/org/apache/karaf/system/management/internal/System.java Modified: karaf/trunk/assemblies/features/standard/pom.xml URL: http://svn.apache.org/viewvc/karaf/trunk/assemblies/features/standard/pom.xml?rev=1357236&r1=1357235&r2=1357236&view=diff ============================================================================== --- karaf/trunk/assemblies/features/standard/pom.xml (original) +++ karaf/trunk/assemblies/features/standard/pom.xml Wed Jul 4 13:10:10 2012 @@ -125,18 +125,6 @@ <version>${project.version}</version> <scope>provided</scope> </dependency> - <dependency> - <groupId>org.apache.karaf.dev</groupId> - <artifactId>org.apache.karaf.dev.core</artifactId> - <version>${project.version}</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.apache.karaf.dev</groupId> - <artifactId>org.apache.karaf.dev.command</artifactId> - <version>${project.version}</version> - <scope>provided</scope> - </dependency> <!-- aries-annotation deps --> <dependency> Modified: karaf/trunk/assemblies/features/standard/src/main/feature/feature.xml URL: http://svn.apache.org/viewvc/karaf/trunk/assemblies/features/standard/src/main/feature/feature.xml?rev=1357236&r1=1357235&r2=1357236&view=diff ============================================================================== --- karaf/trunk/assemblies/features/standard/src/main/feature/feature.xml (original) +++ karaf/trunk/assemblies/features/standard/src/main/feature/feature.xml Wed Jul 4 13:10:10 2012 @@ -33,8 +33,6 @@ <bundle start-level="30">mvn:org.apache.karaf.log/org.apache.karaf.log.command/${project.version}</bundle> <bundle start-level="30">mvn:org.apache.karaf.service/org.apache.karaf.service.core/${project.version}</bundle> <bundle start-level="30">mvn:org.apache.karaf.service/org.apache.karaf.service.command/${project.version}</bundle> - <bundle start-level="30">mvn:org.apache.karaf.dev/org.apache.karaf.dev.core/${project.version}</bundle> - <bundle start-level="30">mvn:org.apache.karaf.dev/org.apache.karaf.dev.command/${project.version}</bundle> </feature> <feature name="aries-annotation" description="Aries Annotations" version="${project.version}"> Modified: karaf/trunk/pom.xml URL: http://svn.apache.org/viewvc/karaf/trunk/pom.xml?rev=1357236&r1=1357235&r2=1357236&view=diff ============================================================================== --- karaf/trunk/pom.xml (original) +++ karaf/trunk/pom.xml Wed Jul 4 13:10:10 2012 @@ -53,7 +53,6 @@ <module>jaas</module> <module>client</module> <module>management</module> - <module>dev</module> <module>system</module> <module>web</module> <module>wrapper</module> @@ -394,17 +393,6 @@ </dependency> <dependency> - <groupId>org.apache.karaf.dev</groupId> - <artifactId>org.apache.karaf.dev.core</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.karaf.dev</groupId> - <artifactId>org.apache.karaf.dev.command</artifactId> - <version>${project.version}</version> - </dependency> - - <dependency> <groupId>org.apache.karaf.log</groupId> <artifactId>org.apache.karaf.log.core</artifactId> <version>${project.version}</version> Added: karaf/trunk/system/command/src/main/java/org/apache/karaf/system/commands/AbstractSystemAction.java URL: http://svn.apache.org/viewvc/karaf/trunk/system/command/src/main/java/org/apache/karaf/system/commands/AbstractSystemAction.java?rev=1357236&view=auto ============================================================================== --- karaf/trunk/system/command/src/main/java/org/apache/karaf/system/commands/AbstractSystemAction.java (added) +++ karaf/trunk/system/command/src/main/java/org/apache/karaf/system/commands/AbstractSystemAction.java Wed Jul 4 13:10:10 2012 @@ -0,0 +1,12 @@ +package org.apache.karaf.system.commands; + +import org.apache.karaf.shell.console.AbstractAction; +import org.apache.karaf.system.SystemService; + +public abstract class AbstractSystemAction extends AbstractAction { + protected SystemService systemService; + + public void setSystemService(SystemService systemService) { + this.systemService = systemService; + } +} Copied: karaf/trunk/system/command/src/main/java/org/apache/karaf/system/commands/FrameworkOptions.java (from r1356761, karaf/trunk/dev/command/src/main/java/org/apache/karaf/dev/command/FrameworkOptions.java) URL: http://svn.apache.org/viewvc/karaf/trunk/system/command/src/main/java/org/apache/karaf/system/commands/FrameworkOptions.java?p2=karaf/trunk/system/command/src/main/java/org/apache/karaf/system/commands/FrameworkOptions.java&p1=karaf/trunk/dev/command/src/main/java/org/apache/karaf/dev/command/FrameworkOptions.java&r1=1356761&r2=1357236&rev=1357236&view=diff ============================================================================== --- karaf/trunk/dev/command/src/main/java/org/apache/karaf/dev/command/FrameworkOptions.java (original) +++ karaf/trunk/system/command/src/main/java/org/apache/karaf/system/commands/FrameworkOptions.java Wed Jul 4 13:10:10 2012 @@ -14,18 +14,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.karaf.dev.command; +package org.apache.karaf.system.commands; -import org.apache.karaf.dev.core.FrameworkType; import org.apache.karaf.shell.commands.Argument; import org.apache.karaf.shell.commands.Command; import org.apache.karaf.shell.commands.Option; +import org.apache.karaf.system.FrameworkType; /** * Command for enabling/disabling debug logging on the OSGi framework */ -@Command(scope = "dev", name = "framework", description = "OSGi Framework options.") -public class FrameworkOptions extends DevCommandSupport { +@Command(scope = "system", name = "framework", description = "OSGi Framework options.") +public class FrameworkOptions extends AbstractSystemAction { @Option(name = "-debug", aliases={"--enable-debug"}, description="Enable debug for the OSGi framework", required = false, multiValued = false) boolean debug; @@ -40,23 +40,23 @@ public class FrameworkOptions extends De protected Object doExecute() throws Exception { if (!debug^nodebug && framework == null) { - System.out.printf("Current OSGi framework is %s%n", devService.getFramework().name()); + System.out.printf("Current OSGi framework is %s%n", systemService.getFramework().name()); return null; } if (framework != null) { FrameworkType frameworkType = FrameworkType.valueOf(framework); - devService.setFramework(frameworkType); + systemService.setFramework(frameworkType); System.out.println("Changed OSGi framework to " + frameworkType.toString().toLowerCase() + ". Karaf needs to be restarted to make the change effective"); } if (debug) { - FrameworkType frameworkType = devService.getFramework(); + FrameworkType frameworkType = systemService.getFramework(); System.out.printf("Enabling debug for OSGi framework (%s)%n", frameworkType.name()); - devService.setFrameworkDebug(true); + systemService.setFrameworkDebug(true); } if (nodebug) { - FrameworkType frameworkType = devService.getFramework(); + FrameworkType frameworkType = systemService.getFramework(); System.out.printf("Disabling debug for OSGi framework (%s)%n", frameworkType.name()); - devService.setFrameworkDebug(false); + systemService.setFrameworkDebug(false); } return null; Modified: karaf/trunk/system/command/src/main/java/org/apache/karaf/system/commands/Name.java URL: http://svn.apache.org/viewvc/karaf/trunk/system/command/src/main/java/org/apache/karaf/system/commands/Name.java?rev=1357236&r1=1357235&r2=1357236&view=diff ============================================================================== --- karaf/trunk/system/command/src/main/java/org/apache/karaf/system/commands/Name.java (original) +++ karaf/trunk/system/command/src/main/java/org/apache/karaf/system/commands/Name.java Wed Jul 4 13:10:10 2012 @@ -18,24 +18,16 @@ package org.apache.karaf.system.commands import org.apache.karaf.shell.commands.Argument; import org.apache.karaf.shell.commands.Command; -import org.apache.karaf.shell.console.OsgiCommandSupport; -import org.apache.karaf.system.SystemService; /** * Command to shut down Karaf container. */ @Command(scope = "system", name = "name", description = "Show or change Karaf instance name.") -public class Name extends OsgiCommandSupport { +public class Name extends AbstractSystemAction { @Argument(name = "name", index = 0, description = "New name for the instance", required = false, multiValued = false) String name; - private SystemService systemService; - - public void setSystemService(SystemService systemService) { - this.systemService = systemService; - } - protected Object doExecute() throws Exception { if (name == null) { System.out.println(systemService.getName()); Modified: karaf/trunk/system/command/src/main/java/org/apache/karaf/system/commands/Shutdown.java URL: http://svn.apache.org/viewvc/karaf/trunk/system/command/src/main/java/org/apache/karaf/system/commands/Shutdown.java?rev=1357236&r1=1357235&r2=1357236&view=diff ============================================================================== --- karaf/trunk/system/command/src/main/java/org/apache/karaf/system/commands/Shutdown.java (original) +++ karaf/trunk/system/command/src/main/java/org/apache/karaf/system/commands/Shutdown.java Wed Jul 4 13:10:10 2012 @@ -19,14 +19,12 @@ package org.apache.karaf.system.commands import org.apache.karaf.shell.commands.Argument; import org.apache.karaf.shell.commands.Command; import org.apache.karaf.shell.commands.Option; -import org.apache.karaf.shell.console.OsgiCommandSupport; -import org.apache.karaf.system.SystemService; /** * Command to shut down Karaf container. */ @Command(scope = "system", name = "shutdown", description = "Shutdown Karaf.") -public class Shutdown extends OsgiCommandSupport { +public class Shutdown extends AbstractSystemAction { @Option(name = "-f", aliases = "--force", description = "Force the shutdown without confirmation message.", required = false, multiValued = false) boolean force = false; @@ -46,12 +44,6 @@ public class Shutdown extends OsgiComman " to wait. The word now is an alias for +0.", required = false, multiValued = false) String time; - private SystemService systemService; - - public void setSystemService(SystemService systemService) { - this.systemService = systemService; - } - protected Object doExecute() throws Exception { if (force) { Copied: karaf/trunk/system/command/src/main/java/org/apache/karaf/system/commands/SystemProperty.java (from r1356761, karaf/trunk/dev/command/src/main/java/org/apache/karaf/dev/command/SystemProperty.java) URL: http://svn.apache.org/viewvc/karaf/trunk/system/command/src/main/java/org/apache/karaf/system/commands/SystemProperty.java?p2=karaf/trunk/system/command/src/main/java/org/apache/karaf/system/commands/SystemProperty.java&p1=karaf/trunk/dev/command/src/main/java/org/apache/karaf/dev/command/SystemProperty.java&r1=1356761&r2=1357236&rev=1357236&view=diff ============================================================================== --- karaf/trunk/dev/command/src/main/java/org/apache/karaf/dev/command/SystemProperty.java (original) +++ karaf/trunk/system/command/src/main/java/org/apache/karaf/system/commands/SystemProperty.java Wed Jul 4 13:10:10 2012 @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.karaf.dev.command; +package org.apache.karaf.system.commands; import org.apache.karaf.shell.commands.Argument; import org.apache.karaf.shell.commands.Command; @@ -23,8 +23,8 @@ import org.apache.karaf.shell.commands.O /** * Command that allow access to system properties easily. */ -@Command(scope = "dev", name = "system-property", description = "Get or set a system property.") -public class SystemProperty extends DevCommandSupport { +@Command(scope = "systen", name = "property", description = "Get or set a system property.") +public class SystemProperty extends AbstractSystemAction { @Option(name = "-p", aliases = { "--persistent" }, description = "Persist the new value to the etc/system.properties file") boolean persistent; @@ -38,7 +38,7 @@ public class SystemProperty extends DevC @Override protected Object doExecute() throws Exception { if (value != null) { - return devService.setSystemProperty(key, value, persistent); + return systemService.setSystemProperty(key, value, persistent); } else { return System.getProperty(key); } Modified: karaf/trunk/system/command/src/main/resources/OSGI-INF/blueprint/system-commands.xml URL: http://svn.apache.org/viewvc/karaf/trunk/system/command/src/main/resources/OSGI-INF/blueprint/system-commands.xml?rev=1357236&r1=1357235&r2=1357236&view=diff ============================================================================== --- karaf/trunk/system/command/src/main/resources/OSGI-INF/blueprint/system-commands.xml (original) +++ karaf/trunk/system/command/src/main/resources/OSGI-INF/blueprint/system-commands.xml Wed Jul 4 13:10:10 2012 @@ -35,6 +35,16 @@ <property name="systemService" ref="systemService"/> </action> </command> + <command> + <action class="org.apache.karaf.system.commands.FrameworkOptions" > + <property name="systemService" ref="systemService"/> + </action> + </command> + <command> + <action class="org.apache.karaf.system.commands.SystemProperty" > + <property name="systemService" ref="systemService"/> + </action> + </command> </command-bundle> <reference id="systemService" interface="org.apache.karaf.system.SystemService"/> Copied: karaf/trunk/system/core/src/main/java/org/apache/karaf/system/FrameworkType.java (from r1356743, karaf/trunk/dev/core/src/main/java/org/apache/karaf/dev/core/FrameworkType.java) URL: http://svn.apache.org/viewvc/karaf/trunk/system/core/src/main/java/org/apache/karaf/system/FrameworkType.java?p2=karaf/trunk/system/core/src/main/java/org/apache/karaf/system/FrameworkType.java&p1=karaf/trunk/dev/core/src/main/java/org/apache/karaf/dev/core/FrameworkType.java&r1=1356743&r2=1357236&rev=1357236&view=diff ============================================================================== --- karaf/trunk/dev/core/src/main/java/org/apache/karaf/dev/core/FrameworkType.java (original) +++ karaf/trunk/system/core/src/main/java/org/apache/karaf/system/FrameworkType.java Wed Jul 4 13:10:10 2012 @@ -11,7 +11,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.karaf.dev.core; +package org.apache.karaf.system; public enum FrameworkType { felix, Modified: karaf/trunk/system/core/src/main/java/org/apache/karaf/system/SystemService.java URL: http://svn.apache.org/viewvc/karaf/trunk/system/core/src/main/java/org/apache/karaf/system/SystemService.java?rev=1357236&r1=1357235&r2=1357236&view=diff ============================================================================== --- karaf/trunk/system/core/src/main/java/org/apache/karaf/system/SystemService.java (original) +++ karaf/trunk/system/core/src/main/java/org/apache/karaf/system/SystemService.java Wed Jul 4 13:10:10 2012 @@ -79,4 +79,31 @@ public interface SystemService { * @param name new instance name */ void setName(String name); + + /** + * Get the current OSGi framework in use. + * + * @return the name of the OSGi framework in use. + * @throws Exception + */ + FrameworkType getFramework(); + + /** + * change OSGi framework + * + * @param framework to use. + */ + void setFramework(FrameworkType framework); + + /** + * Enable or diable debgging + * @param debug enable if true + */ + void setFrameworkDebug(boolean debug); + + /** + * Set a system property and persist to etc/system.properties + * @param key + */ + String setSystemProperty(String key, String value, boolean persist); } Modified: karaf/trunk/system/core/src/main/java/org/apache/karaf/system/internal/SystemServiceImpl.java URL: http://svn.apache.org/viewvc/karaf/trunk/system/core/src/main/java/org/apache/karaf/system/internal/SystemServiceImpl.java?rev=1357236&r1=1357235&r2=1357236&view=diff ============================================================================== --- karaf/trunk/system/core/src/main/java/org/apache/karaf/system/internal/SystemServiceImpl.java (original) +++ karaf/trunk/system/core/src/main/java/org/apache/karaf/system/internal/SystemServiceImpl.java Wed Jul 4 13:10:10 2012 @@ -19,12 +19,13 @@ package org.apache.karaf.system.internal import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; +import java.io.IOException; import java.util.Calendar; import java.util.GregorianCalendar; import org.apache.felix.utils.properties.Properties; +import org.apache.karaf.system.FrameworkType; import org.apache.karaf.system.SystemService; -import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.framework.startlevel.FrameworkStartLevel; import org.slf4j.Logger; @@ -67,13 +68,8 @@ public class SystemServiceImpl implement new Thread() { public void run() { try { - if (sleep > 0) { - LOGGER.info("Shutdown in " + sleep / 1000 / 60 + " minute(s)"); - System.err.println("Shutdown in " + sleep / 1000 / 60 + " minutes(s)"); - } - Thread.sleep(sleep); - Bundle bundle = getBundleContext().getBundle(0); - bundle.stop(); + sleepWithMsg(sleep, "Shutdown in " + sleep / 1000 / 60 + " minute(s)"); + getBundleContext().getBundle(0).stop(); } catch (Exception e) { LOGGER.error("Halt error", e); } @@ -85,11 +81,7 @@ public class SystemServiceImpl implement new Thread() { public void run() { try { - if (sleep > 0) { - LOGGER.info("Reboot in " + sleep / 1000 / 60 + " minute(s)"); - System.err.println("Reboot in " + sleep / 1000 / 60 + " minute(s)"); - } - Thread.sleep(sleep); + sleepWithMsg(sleep, "Reboot in " + sleep / 1000 / 60 + " minute(s)"); System.setProperty("karaf.restart", "true"); System.setProperty("karaf.restart.clean", Boolean.toString(clean)); bundleContext.getBundle(0).stop(); @@ -99,6 +91,15 @@ public class SystemServiceImpl implement } }.start(); } + + private void sleepWithMsg(final long sleep, String msg) + throws InterruptedException { + if (sleep > 0) { + LOGGER.info(msg); + System.err.println(msg); + } + Thread.sleep(sleep); + } public void setStartLevel(int startLevel) throws Exception { getBundleContext().getBundle(0).adapt(FrameworkStartLevel.class).setStartLevel(startLevel); @@ -167,5 +168,62 @@ public class SystemServiceImpl implement throw new RuntimeException(e.getMessage(), e); } } + + public FrameworkType getFramework() { + if (bundleContext.getBundle(0).getSymbolicName().contains("felix")) { + return FrameworkType.felix; + } else { + return FrameworkType.equinox; + } + } + + private Properties loadProps() throws IOException { + return new Properties(new File(System.getProperty("karaf.base"), "etc/config.properties")); + } + + public void setFramework(FrameworkType framework) { + if (framework == null) { + return; + } + try { + Properties properties = loadProps(); + properties.put("karaf.framework", framework.name()); + properties.save(); + } catch (IOException e) { + throw new RuntimeException("Error settting framework: " + e.getMessage(), e); + } + } + + public void setFrameworkDebug(boolean debug) { + try { + Properties properties = loadProps(); + if (debug) { + properties.put("felix.log.level", "4"); + properties.put("osgi.debug", "etc/equinox-debug.properties"); + } else { + properties.remove("felix.log.level"); + properties.remove("osgi.debug"); + } + // TODO populate the equinox-debug.properties file with the one provided in shell/dev module + properties.save(); + } catch (IOException e) { + throw new RuntimeException("Error settting framework debugging: " + e.getMessage(), e); + } + } + + @Override + public String setSystemProperty(String key, String value, boolean persist) { + if (persist) { + try { + String base = System.getProperty("karaf.base"); + Properties props = new Properties(new File(base, "etc/system.properties")); + props.put(key, value); + props.save(); + } catch (IOException e) { + throw new RuntimeException("Error persisting system property", e); + } + } + return System.setProperty(key, value); + } } Modified: karaf/trunk/system/core/src/main/java/org/apache/karaf/system/management/SystemMBean.java URL: http://svn.apache.org/viewvc/karaf/trunk/system/core/src/main/java/org/apache/karaf/system/management/SystemMBean.java?rev=1357236&r1=1357235&r2=1357236&view=diff ============================================================================== --- karaf/trunk/system/core/src/main/java/org/apache/karaf/system/management/SystemMBean.java (original) +++ karaf/trunk/system/core/src/main/java/org/apache/karaf/system/management/SystemMBean.java Wed Jul 4 13:10:10 2012 @@ -29,4 +29,25 @@ public interface SystemMBean { void setStartLevel(int startLevel) throws Exception; int getStartLevel() throws Exception; + /** + * Get the current OSGi framework in use. + * + * @return the name of the OSGi framework in use. + * @throws Exception + */ + String getFramework(); + + /** + * change OSGi framework + * + * @param framework to use. + */ + void setFramework(String framework); + + /** + * Enable or diable debgging + * @param debug enable if true + */ + void setFrameworkDebug(boolean debug); + } Modified: karaf/trunk/system/core/src/main/java/org/apache/karaf/system/management/internal/System.java URL: http://svn.apache.org/viewvc/karaf/trunk/system/core/src/main/java/org/apache/karaf/system/management/internal/System.java?rev=1357236&r1=1357235&r2=1357236&view=diff ============================================================================== --- karaf/trunk/system/core/src/main/java/org/apache/karaf/system/management/internal/System.java (original) +++ karaf/trunk/system/core/src/main/java/org/apache/karaf/system/management/internal/System.java Wed Jul 4 13:10:10 2012 @@ -16,6 +16,7 @@ */ package org.apache.karaf.system.management.internal; +import org.apache.karaf.system.FrameworkType; import org.apache.karaf.system.SystemService; import org.apache.karaf.system.management.SystemMBean; @@ -65,4 +66,19 @@ public class System extends StandardMBea return systemService.getStartLevel(); } + @Override + public String getFramework() { + return this.systemService.getFramework().toString(); + } + + @Override + public void setFramework(String framework) { + this.systemService.setFramework(FrameworkType.valueOf(framework.toLowerCase())); + } + + @Override + public void setFrameworkDebug(boolean debug) { + this.systemService.setFrameworkDebug(debug); + } + }