felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fili...@apache.org
Subject svn commit: r815951 - in /felix/trunk/shell/src/main/java/org/apache/felix/shell/impl: Activator.java SystemPropertiesCommandImpl.java
Date Wed, 16 Sep 2009 20:21:25 GMT
Author: filippo
Date: Wed Sep 16 20:21:25 2009
New Revision: 815951

URL: http://svn.apache.org/viewvc?rev=815951&view=rev
Log:
FELIX-1561 added a sysprop command to manage system properties

Added:
    felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/SystemPropertiesCommandImpl.java
Modified:
    felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/Activator.java

Modified: felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/Activator.java
URL: http://svn.apache.org/viewvc/felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/Activator.java?rev=815951&r1=815950&r2=815951&view=diff
==============================================================================
--- felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/Activator.java (original)
+++ felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/Activator.java Wed Sep 16
20:21:25 2009
@@ -156,6 +156,11 @@
         context.registerService(
             org.apache.felix.shell.Command.class.getName(),
             new StopCommandImpl(m_context), null);
+        
+        // Register "sysprop" command service.
+        context.registerService(
+            org.apache.felix.shell.Command.class.getName(),
+            new SystemPropertiesCommandImpl(), null);
 
         // Register "uninstall" command service.
         context.registerService(

Added: felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/SystemPropertiesCommandImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/SystemPropertiesCommandImpl.java?rev=815951&view=auto
==============================================================================
--- felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/SystemPropertiesCommandImpl.java
(added)
+++ felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/SystemPropertiesCommandImpl.java
Wed Sep 16 20:21:25 2009
@@ -0,0 +1,95 @@
+/*
+ * 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.felix.shell.impl;
+
+
+import java.io.PrintStream;
+import java.util.Iterator;
+import java.util.StringTokenizer;
+
+import org.apache.felix.shell.Command;
+
+
+/**
+ * Command to display, set and modify system properties
+ * Usage:
+ * sysprop                 -> displays all the system properties
+ * sysprop [key]           -> displays the [key] property 
+ * sysprop [key] [value]   -> set the property [key] to [value]
+ */
+public class SystemPropertiesCommandImpl implements Command
+{
+
+    public void execute( String line, PrintStream out, PrintStream err )
+    {
+        StringTokenizer st = new StringTokenizer( line );
+        int tokens = st.countTokens();
+
+        if ( tokens == 1 )
+        {
+            printAll( out );
+        }
+        else
+        {
+            st.nextToken();
+            String propertyKey = st.nextToken();
+
+            if ( tokens == 2 )
+            {
+                out.println( propertyKey + "=" + System.getProperty( propertyKey ) );
+            }
+            else
+            {
+                String value = st.nextToken();
+                System.setProperty( propertyKey, value );
+                out.println( "Set " + propertyKey + "=" + value );
+            }
+        }
+    }
+
+
+    private void printAll( PrintStream out )
+    {
+        out.println( "-------System properties------" );
+        for ( Iterator keyIterator = System.getProperties().keySet().iterator(); keyIterator.hasNext();
)
+        {
+            Object key = keyIterator.next();
+            out.println( key.toString() + "=" + System.getProperty( key.toString() ) );
+        }
+    }
+
+
+    public String getName()
+    {
+        return "sysprop";
+    }
+
+
+    public String getShortDescription()
+    {
+        return "Display, set and modify system properties";
+    }
+
+
+    public String getUsage()
+    {
+        return "sysprop [<key>] [<value>]";
+    }
+
+}



Mime
View raw message