felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickh...@apache.org
Subject svn commit: r699539 - in /felix/trunk/shell/src/main/java/org/apache/felix/shell/impl: StartCommandImpl.java StopCommandImpl.java
Date Sat, 27 Sep 2008 02:00:21 GMT
Author: rickhall
Date: Fri Sep 26 19:00:18 2008
New Revision: 699539

URL: http://svn.apache.org/viewvc?rev=699539&view=rev
Log:
Added support for transiently starting/stopping bundles. (FELIX-741)

Modified:
    felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/StartCommandImpl.java
    felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/StopCommandImpl.java

Modified: felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/StartCommandImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/StartCommandImpl.java?rev=699539&r1=699538&r2=699539&view=diff
==============================================================================
--- felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/StartCommandImpl.java (original)
+++ felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/StartCommandImpl.java Fri
Sep 26 19:00:18 2008
@@ -19,6 +19,8 @@
 package org.apache.felix.shell.impl;
 
 import java.io.PrintStream;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.StringTokenizer;
 
 import org.apache.felix.shell.Command;
@@ -26,6 +28,8 @@
 
 public class StartCommandImpl extends InstallCommandImpl implements Command
 {
+    private static final String TRANSIENT_SWITCH = "-t";
+
     private BundleContext m_context = null;
 
     public StartCommandImpl(BundleContext context)
@@ -41,7 +45,7 @@
 
     public String getUsage()
     {
-        return "start <id> [<id> <URL> ...]";
+        return "start [-t] <id> [<id> <URL> ...]";
     }
 
     public String getShortDescription()
@@ -56,14 +60,33 @@
         // Ignore the command name.
         st.nextToken();
 
+        // Put the remaining tokens into a list.
+        List tokens = new ArrayList();
+        for (int i = 0; st.hasMoreTokens(); i++)
+        {
+            tokens.add(st.nextToken());
+        }
+
+        // Default switch value.
+        boolean isTransient = false;
+
+        // Check for "transient" switch.
+        if (tokens.contains(TRANSIENT_SWITCH))
+        {
+            // Remove the switch and set boolean flag.
+            tokens.remove(TRANSIENT_SWITCH);
+            isTransient = true;
+        }
+
         // There should be at least one bundle id.
-        if (st.countTokens() >= 1)
+        if (tokens.size() >= 1)
         {
-            while (st.hasMoreTokens())
+            while (tokens.size() > 0)
             {
-                String id = st.nextToken().trim();
+                String id = ((String) tokens.remove(0)).trim();
 
-                try {
+                try
+                {
                     Bundle bundle = null;
 
                     // The id may be a number or a URL, so check.
@@ -79,15 +102,19 @@
 
                     if (bundle != null)
                     {
-                        bundle.start();
+                        bundle.start(isTransient ? Bundle.START_TRANSIENT : 0);
                     }
                     else
                     {
                         err.println("Bundle ID " + id + " is invalid.");
                     }
-                } catch (NumberFormatException ex) {
+                }
+                catch (NumberFormatException ex)
+                {
                     err.println("Unable to parse id '" + id + "'.");
-                } catch (BundleException ex) {
+                }
+                catch (BundleException ex)
+                {
                     if (ex.getNestedException() != null)
                     {
                         ex.printStackTrace();
@@ -97,7 +124,9 @@
                     {
                         err.println(ex.toString());
                     }
-                } catch (Exception ex) {
+                }
+                catch (Exception ex)
+                {
                     err.println(ex.toString());
                 }
             }

Modified: felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/StopCommandImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/StopCommandImpl.java?rev=699539&r1=699538&r2=699539&view=diff
==============================================================================
--- felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/StopCommandImpl.java (original)
+++ felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/StopCommandImpl.java Fri Sep
26 19:00:18 2008
@@ -19,6 +19,8 @@
 package org.apache.felix.shell.impl;
 
 import java.io.PrintStream;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.StringTokenizer;
 
 import org.apache.felix.shell.Command;
@@ -26,6 +28,8 @@
 
 public class StopCommandImpl implements Command
 {
+    private static final String TRANSIENT_SWITCH = "-t";
+
     private BundleContext m_context = null;
 
     public StopCommandImpl(BundleContext context)
@@ -40,7 +44,7 @@
 
     public String getUsage()
     {
-        return "stop <id> [<id> ...]";
+        return "stop [-t] <id> [<id> ...]";
     }
 
     public String getShortDescription()
@@ -55,32 +59,61 @@
         // Ignore the command name.
         st.nextToken();
 
+        // Put the remaining tokens into a list.
+        List tokens = new ArrayList();
+        for (int i = 0; st.hasMoreTokens(); i++)
+        {
+            tokens.add(st.nextToken());
+        }
+
+        // Default switch value.
+        boolean isTransient = false;
+
+        // Check for "transient" switch.
+        if (tokens.contains(TRANSIENT_SWITCH))
+        {
+            // Remove the switch and set boolean flag.
+            tokens.remove(TRANSIENT_SWITCH);
+            isTransient = true;
+        }
+
         // There should be at least one bundle id.
-        if (st.countTokens() >= 1)
+        if (tokens.size() >= 1)
         {
-            while (st.hasMoreTokens())
+            while (tokens.size() > 0)
             {
-                String id = st.nextToken().trim();
+                String id = ((String) tokens.remove(0)).trim();
 
-                try {
+                try
+                {
                     long l = Long.parseLong(id);
                     Bundle bundle = m_context.getBundle(l);
                     if (bundle != null)
                     {
-                        bundle.stop();
+                        bundle.stop(isTransient ? Bundle.STOP_TRANSIENT : 0);
                     }
                     else
                     {
                         err.println("Bundle ID " + id + " is invalid.");
                     }
-                } catch (NumberFormatException ex) {
+                }
+                catch (NumberFormatException ex)
+                {
                     err.println("Unable to parse id '" + id + "'.");
-                } catch (BundleException ex) {
+                }
+                catch (BundleException ex)
+                {
                     if (ex.getNestedException() != null)
+                    {
                         err.println(ex.getNestedException().toString());
+                    }
                     else
+                    {
                         err.println(ex.toString());
-                } catch (Exception ex) {
+                    }
+                }
+                catch (Exception ex)
+                {
                     err.println(ex.toString());
                 }
             }



Mime
View raw message