[Git][java-team/felix-gogo-shell][upstream] 3 commits: New upstream version 1.1.0

Emmanuel Bourg (@ebourg) gitlab at salsa.debian.org
Fri Nov 20 08:24:53 GMT 2026



Emmanuel Bourg pushed to branch upstream at Debian Java Maintainers / felix-gogo-shell


Commits:
91787912 by Emmanuel Bourg at 2026-11-19T18:13:45+01:00
New upstream version 1.1.0
- - - - -
9db7f56e by Emmanuel Bourg at 2026-11-19T18:13:45+01:00
New upstream version 1.1.2
- - - - -
b2c3adc2 by Emmanuel Bourg at 2026-11-19T18:13:46+01:00
New upstream version 1.1.4
- - - - -


15 changed files:

- doc/changelog.txt
- pom.xml
- src/main/java/org/apache/felix/gogo/options/Option.java
- src/main/java/org/apache/felix/gogo/options/Options.java
- src/main/java/org/apache/felix/gogo/shell/Activator.java
- src/main/java/org/apache/felix/gogo/shell/Builtin.java
- src/main/java/org/apache/felix/gogo/shell/Console.java
- src/main/java/org/apache/felix/gogo/shell/Converters.java
- src/main/java/org/apache/felix/gogo/shell/History.java
- src/main/java/org/apache/felix/gogo/shell/Posix.java
- src/main/java/org/apache/felix/gogo/shell/Procedural.java
- src/main/java/org/apache/felix/gogo/shell/Shell.java
- src/main/java/org/apache/felix/gogo/shell/Telnet.java
- + src/main/java/org/apache/felix/gogo/shell/package-info.java
- src/main/resources/gosh_profile


Changes:

=====================================
doc/changelog.txt
=====================================
@@ -1,12 +1,49 @@
+Changes from 1.1.2 to 1.1.4
+----------------------------
+Improvement
+    [FELIX-6038] - pull Java 7 support back in for gogo runtime,shell and console
+
+Bug
+    [FELIX-6046] - fix gogo shell thread interrupt.
+
+Changes from 1.1.0 to 1.1.2
+----------------------------
+Improvement
+    [FELIX-5970] - Add requirement & capabilities model so gogo can be resolved
+    [FELIX-5999] - cleanup compiler warnings
+    [FELIX-6000] - cleanup compiler warnings
+    [FELIX-6003] - Add some resolver checks to make sure @RequireGogo annotation works for both jline and shell
+    [FELIX-6007] - create a gogo bom
+
+Changes from 1.0.0 to 1.1.0
+----------------------------
+New Feature
+    [FELIX-5835] - Upgrade to JDK 8
+    [FELIX-5836] - Upgrade to OSGi r6
+
+Improvement
+    [FELIX-5857] - Provide a context classloader on the session to help with class loading
+
+Changes from 0.12.0 to 1.0.0
+----------------------------
+New Feature
+    [FELIX-5272] - New gogo features
+
+Improvement
+    [FELIX-2536] - Gogo Shell should export org.apache.felix.gogo.options package
+
+Task
+    [FELIX-5378] - [gogo] Upgrade packages and bundle to 1.0.0
+
 Changes from 0.10.0 to 0.12.0
 -----------------------------
-** Improvement 
+** Improvement
     * FELIX-5021 [GOGO] Use system bundle to find bundles
     * FELIX-4529 [Gogo] Let gosh be configured by files contributed by a bundle fragment
     * FELIX-3341 Simple csh-like Command History
     * FELIX-3340 Allow the prompt to be a Function
 
-** Bug 
+** Bug
     * FELIX-4425 Short command in Gogo Shell not working with Java 8
     * FELIX-3706 gogo shell startup failure in busy system
     * FELIX-3703 Race condition in gogo runtime activator


=====================================
pom.xml
=====================================
@@ -1,3 +1,4 @@
+<?xml version="1.0"?>
 <!--
  Licensed to the Apache Software Foundation (ASF) under one
  or more contributor license agreements.  See the NOTICE file
@@ -17,34 +18,49 @@
  under the License.
 -->
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+
     <parent>
         <groupId>org.apache.felix</groupId>
         <artifactId>gogo-parent</artifactId>
-        <version>0.6.0</version>
+        <version>6</version>
         <relativePath>../gogo-parent/pom.xml</relativePath>
     </parent>
-    <modelVersion>4.0.0</modelVersion>
+
     <packaging>bundle</packaging>
     <name>Apache Felix Gogo Shell</name>
     <artifactId>org.apache.felix.gogo.shell</artifactId>
-    <version>0.12.0</version>
+    <version>1.1.4</version>
+    <url>http://felix.apache.org/</url>
+    <scm>
+        <connection>scm:git:https://github.com/apache/felix-dev.git</connection>
+        <developerConnection>scm:git:https://github.com/apache/felix-dev.git</developerConnection>
+        <url>https://gitbox.apache.org/repos/asf?p=felix-dev.git</url>
+      <tag>org.apache.felix.gogo.shell-1.1.4</tag>
+  </scm>
+
     <dependencies>
         <dependency>
             <groupId>org.osgi</groupId>
-            <artifactId>org.osgi.core</artifactId>
-            <version>4.2.0</version>
-            <scope>provided</scope>
+            <artifactId>osgi.annotation</artifactId>
         </dependency>
         <dependency>
             <groupId>org.osgi</groupId>
-            <artifactId>org.osgi.compendium</artifactId>
-            <version>4.0.0</version>
-            <scope>provided</scope>
+            <artifactId>osgi.core</artifactId>
         </dependency>
         <dependency>
             <groupId>org.apache.felix</groupId>
             <artifactId>org.apache.felix.gogo.runtime</artifactId>
-            <version>0.10.0</version>
+            <version>1.1.4</version>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-core</artifactId>
         </dependency>
     </dependencies>
     <build>
@@ -52,31 +68,15 @@
             <plugin>
                 <groupId>org.apache.felix</groupId>
                 <artifactId>maven-bundle-plugin</artifactId>
-                <extensions>true</extensions>
                 <configuration>
                     <instructions>
-                        <Export-Package>
-                        </Export-Package>
-                        <Import-Package>
-                            org.apache.felix.service.command; status="provisional",
-                            *
-                        </Import-Package>
-                        <Private-Package>
-			    org.apache.felix.gogo.shell,
-			    org.apache.felix.gogo.options
-			</Private-Package>
-                        <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
-                        <Bundle-Vendor>The Apache Software Foundation</Bundle-Vendor>
-                        <Bundle-Activator>org.apache.felix.gogo.shell.Activator</Bundle-Activator>
-                        <Include-Resource>{maven-resources},META-INF/LICENSE=LICENSE,META-INF/NOTICE=NOTICE,META-INF/DEPENDENCIES=DEPENDENCIES</Include-Resource>
-                        <_versionpolicy>[$(version;==;$(@)),$(version;+;$(@)))</_versionpolicy>
-                        <_removeheaders>Private-Package,Ignore-Package,Include-Resource</_removeheaders>
+                        <Export-Package />
                     </instructions>
                 </configuration>
             </plugin>
             <plugin>
-                <groupId>org.codehaus.mojo</groupId>
-                <artifactId>rat-maven-plugin</artifactId>
+                <groupId>org.apache.rat</groupId>
+                <artifactId>apache-rat-plugin</artifactId>
                 <configuration>
                     <excludeSubProjects>false</excludeSubProjects>
                     <useEclipseDefaultExcludes>true</useEclipseDefaultExcludes>
@@ -86,22 +86,10 @@
                         <param>maven-eclipse.xml</param>
                         <param>.checkstyle</param>
                         <param>.externalToolBuilders/*</param>
+                        <param>src/main/resources/motd</param>
                     </excludes>
                 </configuration>
             </plugin>
-            <plugin>
-                <artifactId>maven-compiler-plugin</artifactId>
-                <configuration>
-                    <source>1.5</source>
-                    <target>1.5</target>
-                </configuration>
-            </plugin>
         </plugins>
     </build>
-
-  <scm>
-    <connection>scm:svn:https://svn.apache.org/repos/asf/felix/releases/org.apache.felix.gogo.shell-0.12.0</connection>
-    <developerConnection>scm:svn:https://svn.apache.org/repos/asf/felix/releases/org.apache.felix.gogo.shell-0.12.0</developerConnection>
-    <url>scm:svn:https://svn.apache.org/repos/asf/felix/releases/org.apache.felix.gogo.shell-0.12.0</url>
-  </scm>
 </project>


=====================================
src/main/java/org/apache/felix/gogo/options/Option.java
=====================================
@@ -24,67 +24,76 @@ public interface Option {
     /**
      * stop parsing on the first unknown option. This allows one parser to get its own options and
      * then pass the remaining options to another parser.
-     * 
-     * @param stopOnBadOption
+     *
+     * @param stopOnBadOption stopOnBadOption
+     * @return Option
      */
     Option setStopOnBadOption(boolean stopOnBadOption);
 
     /**
      * require options to precede args. Default is false, so options can appear between or after
      * args.
-     * 
-     * @param optionsFirst
+     *
+     * @param optionsFirst optionsFirst
+     * @return Option
      */
     Option setOptionsFirst(boolean optionsFirst);
 
     /**
      * parse arguments. If skipArgv0 is true, then parsing begins at arg1. This allows for commands
      * where argv0 is the command name rather than a real argument.
-     * 
-     * @param argv
-     * @param skipArg0
-     * @return
+     *
+     * @param argv argv
+     * @param skipArg0 skipArg0
+     * @return Option
      */
-    Option parse(List<? extends Object> argv, boolean skipArg0);
+    Option parse(List<?> argv, boolean skipArg0);
 
     /**
      * parse arguments.
-     * 
-     * @see {@link #parse(List, boolean)
-
+     *
+     * See {@link #parse(List, boolean)}
+     *
+     * @param argv the arg
+     * @return Option
      */
-    Option parse(List<? extends Object> argv);
+    Option parse(List<?> argv);
 
     /**
      * parse arguments.
-     * 
-     * @see {@link #parse(List, boolean)
-
+     *
+     * See {@link #parse(List, boolean)}
+     *
+     * @param argv the arg
+     * @param skipArg0 skipArg0
+     * @return Option
      */
     Option parse(Object[] argv, boolean skipArg0);
 
     /**
      * parse arguments.
-     * 
-     * @see {@link #parse(List, boolean)
-
+     *
+     * See {@link #parse(List, boolean)}
+     *
+     * @param argv argv
+     * @return Option
      */
     Option parse(Object[] argv);
 
     /**
      * test whether specified option has been explicitly set.
-     * 
-     * @param name
-     * @return
+     *
+     * @param name name
+     * @return boolean
      */
     boolean isSet(String name);
 
     /**
      * get value of named option. If multiple options given, this method returns the last one. Use
      * {@link #getList(String)} to get all values.
-     * 
-     * @param name
-     * @return
+     *
+     * @param name the name
+     * @return String
      * @throws IllegalArgumentException
      *             if value is not a String.
      */
@@ -92,8 +101,8 @@ public interface Option {
 
     /**
      * get list of all values for named option.
-     * 
-     * @param name
+     *
+     * @param name the name
      * @return empty list if option not given and no default specified.
      * @throws IllegalArgumentException
      *             if all values are not Strings.
@@ -103,25 +112,25 @@ public interface Option {
     /**
      * get value of named option as an Object. If multiple options given, this method returns the
      * last one. Use {@link #getObjectList(String)} to get all values.
-     * 
-     * @param name
-     * @return
+     *
+     * @param name the name
+     * @return Object
      */
     Object getObject(String name);
 
     /**
      * get list of all Object values for named option.
-     * 
-     * @param name
-     * @return
+     *
+     * @param name the name
+     * @return List<Object>
      */
     List<Object> getObjectList(String name);
 
     /**
      * get value of named option as a Number.
-     * 
-     * @param name
-     * @return
+     *
+     * @param name the name
+     * @return int
      * @throws IllegalArgumentException
      *             if argument is not a Number.
      */
@@ -129,8 +138,8 @@ public interface Option {
 
     /**
      * get remaining non-options args as Strings.
-     * 
-     * @return
+     *
+     * @return List<String>
      * @throws IllegalArgumentException
      *             if args are not Strings.
      */
@@ -138,8 +147,8 @@ public interface Option {
 
     /**
      * get remaining non-options args as Objects.
-     * 
-     * @return
+     *
+     * @return List<Object>
      */
     List<Object> argObjects();
 
@@ -151,8 +160,8 @@ public interface Option {
     /**
      * print specified usage error to System.err. You should explicitly throw the returned
      * exception.
-     * 
-     * @param error
+     *
+     * @param error the error
      * @return IllegalArgumentException
      */
     IllegalArgumentException usageError(String error);


=====================================
src/main/java/org/apache/felix/gogo/options/Options.java
=====================================
@@ -32,41 +32,47 @@ import java.util.regex.Pattern;
 /**
  * Yet another GNU long options parser. This one is configured by parsing its Usage string.
  */
-public class Options implements Option {
-    public static void main(String[] args) {
+public class Options implements Option
+{
+    public static void main(String[] args)
+    {
         final String[] usage = {
-            "test - test Options usage",
-            "  text before Usage: is displayed when usage() is called and no error has occurred.",
-            "  so can be used as a simple help message.",
-            "",
-            "Usage: testOptions [OPTION]... PATTERN [FILES]...",
-            "  Output control: arbitary non-option text can be included.",
-            "  -? --help                show help",
-            "  -c --count=COUNT           show COUNT lines",
-            "  -h --no-filename         suppress the prefixing filename on output",
-            "  -q --quiet, --silent     suppress all normal output",
-            "     --binary-files=TYPE   assume that binary files are TYPE",
-            "                           TYPE is 'binary', 'text', or 'without-match'",
-            "  -I                       equivalent to --binary-files=without-match",
-            "  -d --directories=ACTION  how to handle directories (default=skip)",
-            "                           ACTION is 'read', 'recurse', or 'skip'",
-            "  -D --devices=ACTION      how to handle devices, FIFOs and sockets",
-            "                           ACTION is 'read' or 'skip'",
-            "  -R, -r --recursive       equivalent to --directories=recurse" };
+                "test - test Options usage",
+                "  text before Usage: is displayed when usage() is called and no error has occurred.",
+                "  so can be used as a simple help message.",
+                "",
+                "Usage: testOptions [OPTION]... PATTERN [FILES]...",
+                "  Output control: arbitary non-option text can be included.",
+                "  -? --help                show help",
+                "  -c --count=COUNT         show COUNT lines",
+                "  -h --no-filename         suppress the prefixing filename on output",
+                "  -q --quiet, --silent     suppress all normal output",
+                "     --binary-files=TYPE   assume that binary files are TYPE",
+                "                           TYPE is 'binary', 'text', or 'without-match'",
+                "  -I                       equivalent to --binary-files=without-match",
+                "  -d --directories=ACTION  how to handle directories (default=skip)",
+                "                           ACTION is 'read', 'recurse', or 'skip'",
+                "  -D --devices=ACTION      how to handle devices, FIFOs and sockets",
+                "                           ACTION is 'read' or 'skip'",
+                "  -R, -r --recursive       equivalent to --directories=recurse" };
 
         Option opt = Options.compile(usage).parse(args);
 
-        if (opt.isSet("help")) {
+        if (opt.isSet("help"))
+        {
             opt.usage(); // includes text before Usage:
             return;
         }
 
-        if (opt.args().size() == 0)
+        if (opt.args().isEmpty())
+        {
             throw opt.usageError("PATTERN not specified");
-
+        }
         System.out.println(opt);
         if (opt.isSet("count"))
+        {
             System.out.println("count = " + opt.getNumber("count"));
+        }
         System.out.println("--directories specified: " + opt.isSet("directories"));
         System.out.println("directories=" + opt.get("directories"));
     }
@@ -75,10 +81,10 @@ public class Options implements Option {
 
     // Note: need to double \ within ""
     private static final String regex = "(?x)\\s*" + "(?:-([^-]))?" + // 1: short-opt-1
-            "(?:,?\\s*-(\\w))?" + // 2: short-opt-2
-            "(?:,?\\s*--(\\w[\\w-]*)(=\\w+)?)?" + // 3: long-opt-1 and 4:arg-1
-            "(?:,?\\s*--(\\w[\\w-]*))?" + // 5: long-opt-2
-            ".*?(?:\\(default=(.*)\\))?\\s*"; // 6: default
+        "(?:,?\\s*-(\\w))?" + // 2: short-opt-2
+        "(?:,?\\s*--(\\w[\\w-]*)(=\\w+)?)?" + // 3: long-opt-1 and 4:arg-1
+        "(?:,?\\s*--(\\w[\\w-]*))?" + // 5: long-opt-2
+        ".*?(?:\\(default=(.*)\\))?\\s*"; // 6: default
 
     private static final int GROUP_SHORT_OPT_1 = 1;
     private static final int GROUP_SHORT_OPT_2 = 2;
@@ -92,12 +98,12 @@ public class Options implements Option {
 
     private final Map<String, Boolean> unmodifiableOptSet;
     private final Map<String, Object> unmodifiableOptArg;
-    private final Map<String, Boolean> optSet = new HashMap<String, Boolean>();
-    private final Map<String, Object> optArg = new HashMap<String, Object>();
+    private final Map<String, Boolean> optSet = new HashMap<>();
+    private final Map<String, Object> optArg = new HashMap<>();
 
-    private final Map<String, String> optName = new HashMap<String, String>();
-    private final Map<String, String> optAlias = new HashMap<String, String>();
-    private final List<Object> xargs = new ArrayList<Object>();
+    private final Map<String, String> optName = new HashMap<>();
+    private final Map<String, String> optAlias = new HashMap<>();
+    private final List<Object> xargs = new ArrayList<>();
     private List<String> args = null;
 
     private static final String UNKNOWN = "unknown";
@@ -114,75 +120,96 @@ public class Options implements Option {
     private boolean optionsFirst = false;
     private boolean stopOnBadOption = false;
 
-    public static Option compile(String[] optSpec) {
+    public static Option compile(String[] optSpec)
+    {
         return new Options(optSpec, null, null);
     }
 
-    public static Option compile(String optSpec) {
+    public static Option compile(String optSpec)
+    {
         return compile(optSpec.split("\\n"));
     }
 
-    public static Option compile(String[] optSpec, Option gopt) {
+    public static Option compile(String[] optSpec, Option gopt)
+    {
         return new Options(optSpec, null, gopt);
     }
 
-    public static Option compile(String[] optSpec, String[] gspec) {
+    public static Option compile(String[] optSpec, String[] gspec)
+    {
         return new Options(optSpec, gspec, null);
     }
 
-    public Option setStopOnBadOption(boolean stopOnBadOption) {
+    public Option setStopOnBadOption(boolean stopOnBadOption)
+    {
         this.stopOnBadOption = stopOnBadOption;
         return this;
     }
 
-    public Option setOptionsFirst(boolean optionsFirst) {
+    public Option setOptionsFirst(boolean optionsFirst)
+    {
         this.optionsFirst = optionsFirst;
         return this;
     }
 
-    public boolean isSet(String name) {
+    public boolean isSet(String name)
+    {
         if (!optSet.containsKey(name))
+        {
             throw new IllegalArgumentException("option not defined in spec: " + name);
-
+        }
         return optSet.get(name);
     }
 
-    public Object getObject(String name) {
+    public Object getObject(String name)
+    {
         if (!optArg.containsKey(name))
+        {
             throw new IllegalArgumentException("option not defined with argument: " + name);
-
+        }
         List<Object> list = getObjectList(name);
 
         return list.isEmpty() ? "" : list.get(list.size() - 1);
     }
 
     @SuppressWarnings("unchecked")
-    public List<Object> getObjectList(String name) {
+    public List<Object> getObjectList(String name)
+    {
         List<Object> list;
         Object arg = optArg.get(name);
 
-        if ( arg == null ) {
+        if (arg == null)
+        {
             throw new IllegalArgumentException("option not defined with argument: " + name);
         }
-        
-        if (arg instanceof String) { // default value
-            list = new ArrayList<Object>();
+
+        if (arg instanceof String)
+        { // default value
+            list = new ArrayList<>();
             if (!"".equals(arg))
+            {
                 list.add(arg);
+            }
         }
-        else {
+        else
+        {
             list = (List<Object>) arg;
         }
 
         return list;
     }
 
-    public List<String> getList(String name) {
-        ArrayList<String> list = new ArrayList<String>();
-        for (Object o : getObjectList(name)) {
-            try {
+    public List<String> getList(String name)
+    {
+        ArrayList<String> list = new ArrayList<>();
+        for (Object o : getObjectList(name))
+        {
+            try
+            {
                 list.add((String) o);
-            } catch (ClassCastException e) {
+            }
+            catch (ClassCastException e)
+            {
                 throw new IllegalArgumentException("option not String: " + name);
             }
         }
@@ -190,72 +217,93 @@ public class Options implements Option {
     }
 
     @SuppressWarnings("unchecked")
-    private void addArg(String name, Object value) {
+    private void addArg(String name, Object value)
+    {
         List<Object> list;
         Object arg = optArg.get(name);
 
-        if (arg instanceof String) { // default value
-            list = new ArrayList<Object>();
+        if (arg instanceof String)
+        { // default value
+            list = new ArrayList<>();
             optArg.put(name, list);
         }
-        else {
+        else
+        {
             list = (List<Object>) arg;
         }
 
         list.add(value);
     }
 
-    public String get(String name) {
-        try {
+    public String get(String name)
+    {
+        try
+        {
             return (String) getObject(name);
-        } catch (ClassCastException e) {
+        }
+        catch (ClassCastException e)
+        {
             throw new IllegalArgumentException("option not String: " + name);
         }
     }
 
-    public int getNumber(String name) {
+    public int getNumber(String name)
+    {
         String number = get(name);
-        try {
+        try
+        {
             if (number != null)
+            {
                 return Integer.parseInt(number);
+            }
             return 0;
-        } catch (NumberFormatException e) {
+        }
+        catch (NumberFormatException e)
+        {
             throw new IllegalArgumentException("option '" + name + "' not Number: " + number);
         }
     }
 
-    public List<Object> argObjects() {
+    public List<Object> argObjects()
+    {
         return xargs;
     }
 
-    public List<String> args() {
-        if (args == null) {
-            args = new ArrayList<String>();
-            for (Object arg : xargs) {
+    public List<String> args()
+    {
+        if (args == null)
+        {
+            args = new ArrayList<>();
+            for (Object arg : xargs)
+            {
                 args.add(arg == null ? "null" : arg.toString());
             }
         }
         return args;
     }
 
-    public void usage() {
+    public void usage()
+    {
         StringBuilder buf = new StringBuilder();
         int index = 0;
 
-        if (error != null) {
+        if (error != null)
+        {
             buf.append(error);
             buf.append(NL);
             index = usageIndex;
         }
 
-        for (int i = index; i < spec.length; ++i) {
+        for (int i = index; i < spec.length; ++i)
+        {
             buf.append(spec[i]);
             buf.append(NL);
         }
 
         String msg = buf.toString();
 
-        if (errStream != null) {
+        if (errStream != null)
+        {
             errStream.print(msg);
         }
     }
@@ -263,41 +311,52 @@ public class Options implements Option {
     /**
      * prints usage message and returns IllegalArgumentException, for you to throw.
      */
-    public IllegalArgumentException usageError(String s) {
+    public IllegalArgumentException usageError(String s)
+    {
         error = usageName + ": " + s;
         usage();
         return new IllegalArgumentException(error);
     }
 
     // internal constructor
-    private Options(String[] spec, String[] gspec, Option opt) {
+    private Options(String[] spec, String[] gspec, Option opt)
+    {
         this.gspec = gspec;
         Options gopt = (Options) opt;
 
-        if (gspec == null && gopt == null) {
+        if (gspec == null && gopt == null)
+        {
             this.spec = spec;
         }
-        else {
-            ArrayList<String> list = new ArrayList<String>();
+        else
+        {
+            ArrayList<String> list = new ArrayList<>();
             list.addAll(Arrays.asList(spec));
             list.addAll(Arrays.asList(gspec != null ? gspec : gopt.gspec));
             this.spec = list.toArray(new String[0]);
         }
 
-        Map<String, Boolean> myOptSet = new HashMap<String, Boolean>();
-        Map<String, Object> myOptArg = new HashMap<String, Object>();
+        Map<String, Boolean> myOptSet = new HashMap<>();
+        Map<String, Object> myOptArg = new HashMap<>();
 
         parseSpec(myOptSet, myOptArg);
 
-        if (gopt != null) {
-            for (Entry<String, Boolean> e : gopt.optSet.entrySet()) {
+        if (gopt != null)
+        {
+            for (Entry<String, Boolean> e : gopt.optSet.entrySet())
+            {
                 if (e.getValue())
+                {
                     myOptSet.put(e.getKey(), true);
+                }
             }
 
-            for (Entry<String, Object> e : gopt.optArg.entrySet()) {
-                if (!e.getValue().equals(""))
+            for (Entry<String, Object> e : gopt.optArg.entrySet())
+            {
+                if (!"".equals(e.getValue()))
+                {
                     myOptArg.put(e.getKey(), e.getValue());
+                }
             }
 
             gopt.reset();
@@ -313,18 +372,24 @@ public class Options implements Option {
     /**
      * parse option spec.
      */
-    private void parseSpec(Map<String, Boolean> myOptSet, Map<String, Object> myOptArg) {
+    private void parseSpec(Map<String, Boolean> myOptSet, Map<String, Object> myOptArg)
+    {
         int index = 0;
-        for (String line : spec) {
+        for (String line : spec)
+        {
             Matcher m = parser.matcher(line);
 
-            if (m.matches()) {
+            if (m.matches())
+            {
                 final String opt = m.group(GROUP_LONG_OPT_1);
                 final String name = (opt != null) ? opt : m.group(GROUP_SHORT_OPT_1);
 
-                if (name != null) {
+                if (name != null)
+                {
                     if (myOptSet.containsKey(name))
+                    {
                         throw new IllegalArgumentException("duplicate option in spec: --" + name);
+                    }
                     myOptSet.put(name, false);
                 }
 
@@ -333,26 +398,35 @@ public class Options implements Option {
                     myOptArg.put(opt, dflt);
 
                 String opt2 = m.group(GROUP_LONG_OPT_2);
-                if (opt2 != null) {
+                if (opt2 != null)
+                {
                     optAlias.put(opt2, opt);
                     myOptSet.put(opt2, false);
                     if (m.group(GROUP_ARG_1) != null)
+                    {
                         myOptArg.put(opt2, "");
+                    }
                 }
 
-                for (int i = 0; i < 2; ++i) {
+                for (int i = 0; i < 2; ++i)
+                {
                     String sopt = m.group(i == 0 ? GROUP_SHORT_OPT_1 : GROUP_SHORT_OPT_2);
-                    if (sopt != null) {
+                    if (sopt != null)
+                    {
                         if (optName.containsKey(sopt))
+                        {
                             throw new IllegalArgumentException("duplicate option in spec: -" + sopt);
+                        }
                         optName.put(sopt, name);
                     }
                 }
             }
 
-            if (usageName == UNKNOWN) {
+            if (usageName == UNKNOWN)
+            {
                 Matcher u = uname.matcher(line);
-                if (u.find()) {
+                if (u.find())
+                {
                     usageName = u.group(1);
                     usageIndex = index;
                 }
@@ -362,7 +436,8 @@ public class Options implements Option {
         }
     }
 
-    private void reset() {
+    private void reset()
+    {
         optSet.clear();
         optSet.putAll(unmodifiableOptSet);
         optArg.clear();
@@ -372,32 +447,38 @@ public class Options implements Option {
         error = null;
     }
 
-    public Option parse(Object[] argv) {
+    public Option parse(Object[] argv)
+    {
         return parse(argv, false);
     }
 
-    public Option parse(List<? extends Object> argv) {
+    public Option parse(List<?> argv)
+    {
         return parse(argv, false);
     }
 
-    public Option parse(Object[] argv, boolean skipArg0) {
+    public Option parse(Object[] argv, boolean skipArg0)
+    {
         if (null == argv)
+        {
             throw new IllegalArgumentException("argv is null");
-        
+        }
         return parse(Arrays.asList(argv), skipArg0);
     }
 
-    public Option parse(List<? extends Object> argv, boolean skipArg0) {
+    public Option parse(List<?> argv, boolean skipArg0)
+    {
         reset();
-        List<Object> args = new ArrayList<Object>();
-        args.addAll(Arrays.asList(defArgs));
-
-        for (Object arg : argv) {
-            if (skipArg0) {
+        List<Object> args = new ArrayList<Object>(Arrays.asList(defArgs));
+        for (Object arg : argv)
+        {
+            if (skipArg0)
+            {
                 skipArg0 = false;
                 usageName = arg.toString();
             }
-            else {
+            else
+            {
                 args.add(arg);
             }
         }
@@ -406,89 +487,114 @@ public class Options implements Option {
         String needOpt = null;
         boolean endOpt = false;
 
-        for (Object oarg : args) {
+        for (Object oarg : args)
+        {
             String arg = oarg == null ? "null" : oarg.toString();
 
-            if (endOpt) {
+            if (endOpt)
+            {
                 xargs.add(oarg);
             }
-            else if (needArg != null) {
+            else if (needArg != null)
+            {
                 addArg(needArg, oarg);
                 needArg = null;
                 needOpt = null;
             }
-            else if (!arg.startsWith("-") || "-".equals(oarg)) {
+            else if (!arg.startsWith("-") || "-".equals(oarg))
+            {
                 if (optionsFirst)
+                {
                     endOpt = true;
+                }
                 xargs.add(oarg);
             }
-            else {
+            else
+            {
                 if (arg.equals("--"))
+                {
                     endOpt = true;
-                else if (arg.startsWith("--")) {
+                }
+                else if (arg.startsWith("--"))
+                {
                     int eq = arg.indexOf("=");
                     String value = (eq == -1) ? null : arg.substring(eq + 1);
                     String name = arg.substring(2, ((eq == -1) ? arg.length() : eq));
-                    List<String> names = new ArrayList<String>();
+                    List<String> names = new ArrayList<>();
 
-                    if (optSet.containsKey(name)) {
+                    if (optSet.containsKey(name))
+                    {
                         names.add(name);
                     }
-                    else {
-                        for (String k : optSet.keySet()) {
+                    else
+                    {
+                        for (String k : optSet.keySet())
+                        {
                             if (k.startsWith(name))
                                 names.add(k);
                         }
                     }
 
-                    switch (names.size()) {
-                    case 1:
-                        name = names.get(0);
-                        optSet.put(name, true);
-                        if (optArg.containsKey(name)) {
-                            if (value != null)
-                                addArg(name, value);
-                            else
-                                needArg = name;
-                        }
-                        else if (value != null) {
-                            throw usageError("option '--" + name + "' doesn't allow an argument");
-                        }
-                        break;
-
-                    case 0:
-                        if (stopOnBadOption) {
-                            endOpt = true;
-                            xargs.add(oarg);
+                    switch (names.size())
+                    {
+                        case 1:
+                            name = names.get(0);
+                            optSet.put(name, true);
+                            if (optArg.containsKey(name))
+                            {
+                                if (value != null)
+                                    addArg(name, value);
+                                else
+                                    needArg = name;
+                            }
+                            else if (value != null)
+                            {
+                                throw usageError("option '--" + name + "' doesn't allow an argument");
+                            }
                             break;
-                        }
-                        else
-                            throw usageError("invalid option '--" + name + "'");
 
-                    default:
-                        throw usageError("option '--" + name + "' is ambiguous: " + names);
+                        case 0:
+                            if (stopOnBadOption)
+                            {
+                                endOpt = true;
+                                xargs.add(oarg);
+                                break;
+                            }
+                            else
+                                throw usageError("invalid option '--" + name + "'");
+
+                        default:
+                            throw usageError("option '--" + name + "' is ambiguous: " + names);
                     }
                 }
-                else {
-                    for (int i = 1; i < arg.length(); i++) {
+                else
+                {
+                    for (int i = 1; i < arg.length(); i++)
+                    {
                         String c = String.valueOf(arg.charAt(i));
-                        if (optName.containsKey(c)) {
+                        if (optName.containsKey(c))
+                        {
                             String name = optName.get(c);
                             optSet.put(name, true);
-                            if (optArg.containsKey(name)) {
+                            if (optArg.containsKey(name))
+                            {
                                 int k = i + 1;
-                                if (k < arg.length()) {
+                                if (k < arg.length())
+                                {
                                     addArg(name, arg.substring(k));
                                 }
-                                else {
+                                else
+                                {
                                     needOpt = c;
                                     needArg = name;
                                 }
                                 break;
                             }
                         }
-                        else {
-                            if (stopOnBadOption) {
+                        else
+                        {
+                            if (stopOnBadOption)
+                            {
                                 xargs.add("-" + c);
                                 endOpt = true;
                             }
@@ -500,14 +606,17 @@ public class Options implements Option {
             }
         }
 
-        if (needArg != null) {
+        if (needArg != null)
+        {
             String name = (needOpt != null) ? needOpt : "--" + needArg;
             throw usageError("option '" + name + "' requires an argument");
         }
 
         // remove long option aliases
-        for (Entry<String, String> alias : optAlias.entrySet()) {
-            if (optSet.get(alias.getKey())) {
+        for (Entry<String, String> alias : optAlias.entrySet())
+        {
+            if (optSet.get(alias.getKey()))
+            {
                 optSet.put(alias.getValue(), true);
                 if (optArg.containsKey(alias.getKey()))
                     optArg.put(alias.getValue(), optArg.get(alias.getKey()));
@@ -520,7 +629,8 @@ public class Options implements Option {
     }
 
     @Override
-    public String toString() {
+    public String toString()
+    {
         return "isSet" + optSet + "\nArg" + optArg + "\nargs" + xargs;
     }
 


=====================================
src/main/java/org/apache/felix/gogo/shell/Activator.java
=====================================
@@ -18,10 +18,14 @@
  */
 package org.apache.felix.gogo.shell;
 
+import java.io.FileDescriptor;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.util.Arrays;
 import java.util.Dictionary;
 import java.util.HashSet;
 import java.util.Hashtable;
-import java.util.Iterator;
+import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
@@ -31,61 +35,67 @@ import java.util.concurrent.TimeUnit;
 import org.apache.felix.service.command.CommandProcessor;
 import org.apache.felix.service.command.CommandSession;
 import org.apache.felix.service.command.Converter;
+import org.osgi.annotation.bundle.Header;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceReference;
 import org.osgi.framework.ServiceRegistration;
 import org.osgi.util.tracker.ServiceTracker;
 
+ at Header(name = Constants.BUNDLE_ACTIVATOR, value = "${@class}")
 public class Activator implements BundleActivator
 {
     private BundleContext context;
-    private ServiceTracker commandProcessorTracker;
-    private Set<ServiceRegistration> regs;
+    private ServiceTracker<?,?> commandProcessorTracker;
+    private Set<ServiceRegistration<?>> regs;
 
-    private ExecutorService executor;
+    private volatile ExecutorService executor;
+    private volatile StartShellJob shellJob;
 
     public Activator()
     {
-        regs = new HashSet<ServiceRegistration>();
+        regs = new HashSet<>();
     }
 
-    public void start(BundleContext context) throws Exception
-    {
+    public void start(BundleContext context) {
         this.context = context;
         this.commandProcessorTracker = createCommandProcessorTracker();
         this.commandProcessorTracker.open();
     }
 
-    public void stop(BundleContext context) throws Exception
-    {
-        Iterator<ServiceRegistration> iterator = regs.iterator();
-        while (iterator.hasNext())
+    public void stop(BundleContext context) {
+        Set<ServiceRegistration<?>> currentRegs;
+        synchronized (regs)
         {
-            ServiceRegistration reg = iterator.next();
-            reg.unregister();
-            iterator.remove();
+            currentRegs = new HashSet<>(regs);
+            regs.clear();
         }
 
-        stopShell();
+        for (ServiceRegistration<?> reg : currentRegs)
+        {
+            reg.unregister();
+        }
 
         this.commandProcessorTracker.close();
+
+        stopShell();
     }
 
-    private ServiceTracker createCommandProcessorTracker()
+    private ServiceTracker<CommandProcessor, CommandProcessor> createCommandProcessorTracker()
     {
-        return new ServiceTracker(context, CommandProcessor.class.getName(), null)
+        return new ServiceTracker<CommandProcessor, CommandProcessor>(context, CommandProcessor.class, null)
         {
             @Override
-            public Object addingService(ServiceReference reference)
+            public CommandProcessor addingService(ServiceReference<CommandProcessor> reference)
             {
-                CommandProcessor processor = (CommandProcessor) super.addingService(reference);
+                CommandProcessor processor = super.addingService(reference);
                 startShell(context, processor);
                 return processor;
             }
 
             @Override
-            public void removedService(ServiceReference reference, Object service)
+            public void removedService(ServiceReference<CommandProcessor> reference, CommandProcessor service)
             {
                 stopShell();
                 super.removedService(reference, service);
@@ -95,52 +105,70 @@ public class Activator implements BundleActivator
 
     private void startShell(BundleContext context, CommandProcessor processor)
     {
-        Dictionary<String, Object> dict = new Hashtable<String, Object>();
+        Dictionary<String, Object> dict = new Hashtable<>();
         dict.put(CommandProcessor.COMMAND_SCOPE, "gogo");
 
+        Set<ServiceRegistration<?>> currentRegs = new HashSet<>();
+
         // register converters
-        regs.add(context.registerService(Converter.class.getName(), new Converters(context.getBundle(0).getBundleContext()), null));
+        currentRegs.add(context.registerService(Converter.class.getName(), new Converters(context.getBundle(0).getBundleContext()), null));
 
         // register commands
 
         dict.put(CommandProcessor.COMMAND_FUNCTION, Builtin.functions);
-        regs.add(context.registerService(Builtin.class.getName(), new Builtin(), dict));
+        currentRegs.add(context.registerService(Builtin.class.getName(), new Builtin(), dict));
 
         dict.put(CommandProcessor.COMMAND_FUNCTION, Procedural.functions);
-        regs.add(context.registerService(Procedural.class.getName(), new Procedural(), dict));
+        currentRegs.add(context.registerService(Procedural.class.getName(), new Procedural(), dict));
 
         dict.put(CommandProcessor.COMMAND_FUNCTION, Posix.functions);
-        regs.add(context.registerService(Posix.class.getName(), new Posix(), dict));
+        currentRegs.add(context.registerService(Posix.class.getName(), new Posix(), dict));
 
         dict.put(CommandProcessor.COMMAND_FUNCTION, Telnet.functions);
-        regs.add(context.registerService(Telnet.class.getName(), new Telnet(processor), dict));
+        currentRegs.add(context.registerService(Telnet.class.getName(), new Telnet(processor), dict));
 
         Shell shell = new Shell(context, processor);
         dict.put(CommandProcessor.COMMAND_FUNCTION, Shell.functions);
-        regs.add(context.registerService(Shell.class.getName(), shell, dict));
+        currentRegs.add(context.registerService(Shell.class.getName(), shell, dict));
 
-        // start shell on a separate thread...
-        executor = Executors.newSingleThreadExecutor(new ThreadFactory()
+        synchronized (regs)
         {
-            public Thread newThread(Runnable runnable)
-            {
+            regs.addAll(currentRegs);
+            currentRegs.clear();
+        }
+
+        // start shell on a separate thread...
+        executor = Executors.newSingleThreadExecutor(new ThreadFactory() {
+            @Override
+            public Thread newThread(Runnable runnable) {
                 return new Thread(runnable, "Gogo shell");
             }
         });
-        executor.submit(new StartShellJob(context, processor));
+        shellJob = new StartShellJob(context, processor);
+        executor.submit(shellJob);
     }
 
     private void stopShell()
     {
         if (executor != null && !(executor.isShutdown() || executor.isTerminated()))
         {
-            executor.shutdownNow();
+            if (shellJob != null)
+            {
+                shellJob.terminate();
+            }
+            executor.shutdown();
 
             try
             {
                 if (!executor.awaitTermination(5, TimeUnit.SECONDS))
                 {
                     System.err.println("!!! FAILED TO STOP EXECUTOR !!!");
+                    Map<Thread, StackTraceElement[]> allStackTraces = Thread.getAllStackTraces();
+                    for (Map.Entry<Thread, StackTraceElement[]> entry : allStackTraces.entrySet())
+                    {
+                        Thread t = entry.getKey();
+                        System.err.printf("Thread: %s (%s): %s\n", t.getName(), t.getState(), Arrays.toString(entry.getValue()));
+                    }
                 }
             }
             catch (InterruptedException e)
@@ -156,6 +184,9 @@ public class Activator implements BundleActivator
     {
         private final BundleContext context;
         private final CommandProcessor processor;
+        private volatile CommandSession session;
+        private volatile Thread shellThread;
+
 
         public StartShellJob(BundleContext context, CommandProcessor processor)
         {
@@ -165,7 +196,11 @@ public class Activator implements BundleActivator
 
         public void run()
         {
-            CommandSession session = processor.createSession(System.in, System.out, System.err);
+
+            shellThread = Thread.currentThread();
+            session = processor.createSession(new FileInputStream(FileDescriptor.in),
+                                              new FileOutputStream(FileDescriptor.out),
+                                              new FileOutputStream(FileDescriptor.err));
             try
             {
                 // wait for gosh command to be registered
@@ -178,6 +213,11 @@ public class Activator implements BundleActivator
                 args = (args == null) ? "" : args;
                 session.execute("gosh --login " + args);
             }
+            catch (InterruptedException e)
+            {
+                // Ok, back off...
+                Thread.currentThread().interrupt();
+            }
             catch (Exception e)
             {
                 Object loc = session.get(".location");
@@ -190,8 +230,20 @@ public class Activator implements BundleActivator
                 e.printStackTrace();
             }
             finally
+            {
+                terminate();
+            }
+        }
+
+        public void terminate()
+        {
+            if (session != null)
             {
                 session.close();
+                session = null;
+            }
+            if (shellThread != null) {
+                shellThread.interrupt();
             }
         }
     }


=====================================
src/main/java/org/apache/felix/gogo/shell/Builtin.java
=====================================
@@ -60,7 +60,7 @@ public class Builtin
     {
         return format(session, session.get("_"));    // last result
     }
-    
+
     public CharSequence format(CommandSession session, Object arg)
     {
         CharSequence result = session.format(arg, Converter.INSPECT);
@@ -70,6 +70,9 @@ public class Builtin
 
     /**
      * script access to Options.
+     * @param spec the spec
+     * @param args the args
+     * @return Option
      */
     public Option getopt(List<Object> spec, Object[] args)
     {
@@ -83,7 +86,7 @@ public class Builtin
 
     // FIXME: the "new" command should be provided by runtime,
     // so it can leverage same argument coercion mechanism, used to invoke methods.
-    public Object _new(Object name, Object[] argv) throws Exception
+    public Object _new(CommandSession session, Object name, Object[] argv) throws Exception
     {
         Class<?> clazz = null;
 
@@ -93,7 +96,7 @@ public class Builtin
         }
         else
         {
-            clazz = loadClass(name.toString());
+            clazz = loadClass(session, name.toString());
         }
 
         for (Constructor<?> c : clazz.getConstructors())
@@ -143,7 +146,7 @@ public class Builtin
             + " to any of " + Arrays.asList(clazz.getConstructors()));
     }
 
-    private Class<?> loadClass(String name) throws ClassNotFoundException
+    private Class<?> loadClass(CommandSession session, String name) throws ClassNotFoundException
     {
         if (!name.contains("."))
         {
@@ -152,18 +155,17 @@ public class Builtin
                 String pkg = p + "." + name;
                 try
                 {
-                    return Class.forName(pkg);
+                    return Class.forName(pkg, true, session.classLoader());
                 }
                 catch (ClassNotFoundException e)
                 {
                 }
             }
         }
-        return Class.forName(name);
+        return Class.forName(name, true, session.classLoader());
     }
 
-    public void set(CommandSession session, String[] argv) throws Exception
-    {
+    public void set(CommandSession session, String[] argv) {
         final String[] usage = {
                 "set - show session variables",
                 "Usage: set [OPTIONS] [PREFIX]",
@@ -195,7 +197,7 @@ public class Builtin
         else
         {
             boolean all = opt.isSet("all");
-            for (String key : new TreeSet<String>(Shell.getVariables(session)))
+            for (String key : new TreeSet<>(Shell.getVariables(session)))
             {
                 if (!key.startsWith(prefix))
                     continue;
@@ -209,7 +211,7 @@ public class Builtin
 
                 if (target != null)
                 {
-                    Class<? extends Object> clazz = target.getClass();
+                    Class<?> clazz = target.getClass();
                     type = clazz.getSimpleName();
                     value = target.toString();
                 }
@@ -254,7 +256,7 @@ public class Builtin
 
         if (opt.isSet("list"))
         {
-            list = new ArrayList<String>();
+            list = new ArrayList<>();
         }
 
         boolean first = true;
@@ -311,7 +313,7 @@ public class Builtin
             opt.usage();
             return true;
         }
-        
+
         boolean all = opt.isSet("all");
 
         String optScope = null;
@@ -331,7 +333,7 @@ public class Builtin
 
         if (optScope != null || (args.isEmpty() && all))
         {
-            Set<String> snames = new TreeSet<String>();
+            Set<String> snames = new TreeSet<>();
 
             for (String sname : (getCommands(session)))
             {
@@ -351,7 +353,7 @@ public class Builtin
 
         if (args.size() == 0)
         {
-            Map<String, Integer> scopes = new TreeMap<String, Integer>();
+            Map<String, Integer> scopes = new TreeMap<>();
 
             for (String sname : getCommands(session))
             {
@@ -379,7 +381,7 @@ public class Builtin
         final String MAIN = "_main"; // FIXME: must match Reflective.java
 
         StringBuilder buf = new StringBuilder();
-        Set<String> cmds = new LinkedHashSet<String>();
+        Set<String> cmds = new LinkedHashSet<>();
 
         // get all commands
         if ((colon != -1) || (session.get(name) != null))
@@ -564,7 +566,7 @@ public class Builtin
             target = method.invoke(target, (Object[])null);
         }
 
-        ArrayList<Method> list = new ArrayList<Method>();
+        ArrayList<Method> list = new ArrayList<>();
         Class<?> tc = (target instanceof Class<?>) ? (Class<?>) target
             : target.getClass();
         Method[] methods = tc.getMethods();
@@ -583,14 +585,14 @@ public class Builtin
         return list;
     }
 
-    private final static Set<String> KEYWORDS = new HashSet<String>(
-        Arrays.asList(new String[] { "abstract", "continue", "for", "new", "switch",
-                "assert", "default", "goto", "package", "synchronized", "boolean", "do",
-                "if", "private", "this", "break", "double", "implements", "protected",
-                "throw", "byte", "else", "import", "public", "throws", "case", "enum",
-                "instanceof", "return", "transient", "catch", "extends", "int", "short",
-                "try", "char", "final", "interface", "static", "void", "class",
-                "finally", "long", "strictfp", "volatile", "const", "float", "native",
-                "super", "while" }));
+    private final static Set<String> KEYWORDS = new HashSet<>(
+            Arrays.asList("abstract", "continue", "for", "new", "switch",
+                    "assert", "default", "goto", "package", "synchronized", "boolean", "do",
+                    "if", "private", "this", "break", "double", "implements", "protected",
+                    "throw", "byte", "else", "import", "public", "throws", "case", "enum",
+                    "instanceof", "return", "transient", "catch", "extends", "int", "short",
+                    "try", "char", "final", "interface", "static", "void", "class",
+                    "finally", "long", "strictfp", "volatile", "const", "float", "native",
+                    "super", "while"));
 
 }


=====================================
src/main/java/org/apache/felix/gogo/shell/Console.java
=====================================
@@ -32,7 +32,7 @@ public class Console implements Runnable
     private final InputStream in;
     private final PrintStream out;
     private final History history;
-    private boolean quit;
+    private volatile boolean quit;
 
     public Console(CommandSession session, History history)
     {
@@ -46,7 +46,7 @@ public class Console implements Runnable
     {
         try
         {
-            while (!quit)
+            while (!Thread.currentThread().isInterrupted() && !quit)
             {
                 CharSequence line = getLine(getPrompt());
 
@@ -95,8 +95,7 @@ public class Console implements Runnable
                             loc = "gogo";
                         }
 
-                        out.println(loc + ": " + e.getClass().getSimpleName() + ": "
-                            + e.getMessage());
+                        out.println(loc + ": " + e.getClass().getSimpleName() + ": " + e.getMessage());
                     }
                 }
                 finally
@@ -146,7 +145,20 @@ public class Console implements Runnable
         while (!quit)
         {
             out.flush();
-            int c = in.read();
+
+            int c = 0;
+            try
+            {
+                c = in.read();
+            }
+            catch (IOException e)
+            {
+                if ("Stream closed".equals(e.getMessage())) {
+                    quit = true;
+                } else {
+                    throw e;
+                }
+            }
 
             switch (c)
             {


=====================================
src/main/java/org/apache/felix/gogo/shell/Converters.java
=====================================
@@ -24,19 +24,19 @@ import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
 import java.util.Arrays;
-import java.util.Formatter;
 
+import org.apache.felix.service.command.Converter;
+import org.apache.felix.service.command.Function;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceReference;
-import org.apache.felix.service.command.Converter;
-import org.apache.felix.service.command.Function;
-import org.osgi.service.startlevel.StartLevel;
+import org.osgi.framework.startlevel.BundleStartLevel;
 
 public class Converters implements Converter
 {
     private final BundleContext context;
+
     public Converters(BundleContext context)
     {
         this.context = context;
@@ -45,31 +45,14 @@ public class Converters implements Converter
     private CharSequence print(Bundle bundle)
     {
         // [ ID ] [STATE      ] [ SL ] symname
-        StartLevel sl = null;
-        ServiceReference ref = context.getServiceReference(StartLevel.class.getName());
-        if (ref != null)
-        {
-            sl = (StartLevel) context.getService(ref);
-        }
-
-        if (sl == null)
-        {
-            return String.format("%5d|%-11s|%s (%s)", bundle.getBundleId(),
-                getState(bundle), bundle.getSymbolicName(), bundle.getVersion());
-        }
-
-        int level = sl.getBundleStartLevel(bundle);
-        context.ungetService(ref);
+        int level = bundle.adapt(BundleStartLevel.class).getStartLevel();
 
         return String.format("%5d|%-11s|%5d|%s (%s)", bundle.getBundleId(),
             getState(bundle), level, bundle.getSymbolicName(), bundle.getVersion());
     }
 
-    private CharSequence print(ServiceReference ref)
+    private CharSequence print(ServiceReference<?> ref)
     {
-        StringBuilder sb = new StringBuilder();
-        Formatter f = new Formatter(sb);
-
         String spid = "";
         Object pid = ref.getProperty("service.pid");
         if (pid != null)
@@ -77,10 +60,9 @@ public class Converters implements Converter
             spid = pid.toString();
         }
 
-        f.format("%06d %3s %-40s %s", ref.getProperty("service.id"),
+        return String.format("%06d %3s %-40s %s", ref.getProperty("service.id"),
             ref.getBundle().getBundleId(),
             getShortNames((String[]) ref.getProperty("objectclass")), spid);
-        return sb;
     }
 
     private CharSequence getShortNames(String[] list)
@@ -89,7 +71,7 @@ public class Converters implements Converter
         String del = "";
         for (String s : list)
         {
-            sb.append(del + getShortName(s));
+            sb.append(del).append(getShortName(s));
             del = " | ";
         }
         return sb;
@@ -192,7 +174,7 @@ public class Converters implements Converter
         String s = in.toString();
         if (s.startsWith("(") && s.endsWith(")"))
         {
-            ServiceReference refs[] = context.getServiceReferences(null, String.format(
+            ServiceReference<?> refs[] = context.getServiceReferences((String) null, String.format(
                 "(|(service.id=%s)(service.pid=%s))", in, in));
             if (refs != null && refs.length > 0)
             {
@@ -200,7 +182,7 @@ public class Converters implements Converter
             }
         }
 
-        ServiceReference refs[] = context.getServiceReferences(null, String.format(
+        ServiceReference<?> refs[] = context.getServiceReferences((String) null, String.format(
             "(|(service.id=%s)(service.pid=%s))", in, in));
         if (refs != null && refs.length > 0)
         {
@@ -252,7 +234,7 @@ public class Converters implements Converter
         }
         if (level == LINE && target instanceof ServiceReference)
         {
-            return print((ServiceReference) target);
+            return print((ServiceReference<?>) target);
         }
         if (level == PART && target instanceof Bundle)
         {
@@ -260,7 +242,7 @@ public class Converters implements Converter
         }
         if (level == PART && target instanceof ServiceReference)
         {
-            return getShortNames((String[]) ((ServiceReference) target).getProperty("objectclass"));
+            return getShortNames((String[]) ((ServiceReference<?>) target).getProperty("objectclass"));
         }
         return null;
     }


=====================================
src/main/java/org/apache/felix/gogo/shell/History.java
=====================================
@@ -36,7 +36,7 @@ public class History {
 
     public History() {
         this.limit = SIZE_DEFAULT;
-        this.commands = new LinkedList<String>();
+        this.commands = new LinkedList<>();
     }
 
     CharSequence evaluate(final CharSequence commandLine) {


=====================================
src/main/java/org/apache/felix/gogo/shell/Posix.java
=====================================
@@ -34,8 +34,8 @@ import org.apache.felix.service.command.CommandSession;
 
 /**
  * Posix-like utilities.
- * 
- * @see http://www.opengroup.org/onlinepubs/009695399/utilities/contents.html
+ *
+ * See http://www.opengroup.org/onlinepubs/009695399/utilities/contents.html
  */
 public class Posix
 {
@@ -50,7 +50,7 @@ public class Posix
         }
 
         URI cwd = Shell.cwd(session);
-        
+
         for (String arg : args)
         {
             copy(cwd.resolve(arg), System.out);
@@ -141,7 +141,7 @@ public class Posix
             {
                 URI cwd = Shell.cwd(session);
                 in = (arg == null) ? System.in : cwd.resolve(arg).toURL().openStream();
-                
+
                 BufferedReader rdr = new BufferedReader(new InputStreamReader(in));
                 int line = 0;
                 String s;
@@ -149,7 +149,7 @@ public class Posix
                 {
                     line++;
                     Matcher matcher = pattern.matcher(s);
-                    if (!(matcher.find() ^ !opt.isSet("invert-match")))
+                    if (matcher.find() == !opt.isSet("invert-match"))
                     {
                         match = true;
                         if (opt.isSet("quiet"))
@@ -180,21 +180,21 @@ public class Posix
 
         return match && status;
     }
-    
-    public static void copy(URI source, OutputStream out) throws IOException {
-        InputStream in = source.toURL().openStream();
-        try {
+
+    public static void copy(URI source, OutputStream out) throws IOException
+    {
+        try (InputStream in = source.toURL().openStream())
+        {
             copy(in, out);
-        } finally {
-            in.close();
         }
     }
 
-
-    public static void copy(InputStream in, OutputStream out) throws IOException {
+    public static void copy(InputStream in, OutputStream out) throws IOException
+    {
         byte buf[] = new byte[10240];
         int len;
-        while ((len = in.read(buf)) > 0) {
+        while ((len = in.read(buf)) > 0)
+        {
             out.write(buf, 0, len);
         }
         out.flush();


=====================================
src/main/java/org/apache/felix/gogo/shell/Procedural.java
=====================================
@@ -32,8 +32,8 @@ public class Procedural
     public List<Object> each(CommandSession session, Collection<Object> list,
         Function closure) throws Exception
     {
-        List<Object> args = new ArrayList<Object>();
-        List<Object> results = new ArrayList<Object>();
+        List<Object> args = new ArrayList<>();
+        List<Object> results = new ArrayList<>();
         args.add(null);
 
         for (Object x : list)
@@ -97,8 +97,7 @@ public class Procedural
             throw new IllegalArgumentException("exception not set or not Throwable.");
     }
 
-    public Object _try(CommandSession session, Function func) throws Exception
-    {
+    public Object _try(CommandSession session, Function func) {
         try
         {
             return func.execute(session, null);
@@ -150,7 +149,7 @@ public class Procedural
             return false;
 
         if (result instanceof Boolean)
-            return ((Boolean) result).booleanValue();
+            return (Boolean) result;
 
         if (result instanceof Number)
         {
@@ -161,10 +160,7 @@ public class Procedural
         if ("".equals(result))
             return false;
 
-        if ("0".equals(result))
-            return false;
-
-        return true;
+        return !"0".equals(result);
     }
     
     private void checkInterrupt() throws InterruptedException


=====================================
src/main/java/org/apache/felix/gogo/shell/Shell.java
=====================================
@@ -19,9 +19,8 @@
 package org.apache.felix.gogo.shell;
 
 import java.io.File;
-import java.io.InputStream;
 import java.io.InputStreamReader;
-import java.io.Reader;
+import java.net.HttpURLConnection;
 import java.net.URI;
 import java.net.URL;
 import java.net.URLConnection;
@@ -35,6 +34,7 @@ import org.apache.felix.gogo.options.Option;
 import org.apache.felix.gogo.options.Options;
 import org.apache.felix.service.command.CommandProcessor;
 import org.apache.felix.service.command.CommandSession;
+import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleException;
 
@@ -49,6 +49,8 @@ public class Shell
     private final CommandProcessor processor;
     private final History history;
 
+    private volatile Bundle systemBundle;
+
     public Shell(BundleContext context, CommandProcessor processor)
     {
         this.context = context;
@@ -69,6 +71,7 @@ public class Shell
                 "     --nointeractive       don't start interactive session",
                 "     --login               login shell (same session, reads etc/gosh_profile)",
                 "  -s --noshutdown          don't shutdown framework when script completes",
+                "  -q --quiet               don't display message-of-the-day",
                 "  -x --xtrace              echo commands before execution",
                 "  -? --help                show help",
                 "If no script-file, an interactive shell is started, type $D to exit." };
@@ -79,6 +82,9 @@ public class Shell
         boolean login = opt.isSet("login");
         boolean interactive = !opt.isSet("nointeractive");
 
+        // We grab this bundle as early as possible to avoid having to deal with invalid bundleContexts of this bundle during shutdowns...
+        systemBundle = context.getBundle(0);
+
         if (opt.isSet("help"))
         {
             opt.usage();
@@ -94,8 +100,11 @@ public class Shell
             throw opt.usageError("option --command requires argument(s)");
         }
 
-        CommandSession newSession = (login ? session : processor.createSession(
-            session.getKeyboard(), session.getConsole(), System.err));
+        CommandSession newSession = (login ? session : processor.createSession(session.getKeyboard(), session.getConsole(), System.err));
+        // Make some of the given arguments available to the shell itself...
+        newSession.put(".gosh_login", login);
+        newSession.put(".gosh_interactive", interactive);
+        newSession.put(".gosh_quiet", opt.isSet("quiet"));
 
         if (opt.isSet("xtrace"))
         {
@@ -108,7 +117,8 @@ public class Shell
             if (!new File(uri).exists())
             {
                 URL url = getClass().getResource("/ext/gosh_profile");
-                if (url == null) {
+                if (url == null)
+                {
                     url = getClass().getResource("/gosh_profile");
                 }
                 uri = (url == null) ? null : url.toURI();
@@ -173,10 +183,17 @@ public class Shell
             result = newSession.execute(program);
         }
 
-        if (login && interactive && !opt.isSet("noshutdown"))
+        if (login && interactive)
         {
-            System.out.println("gosh: stopping framework");
-            shutdown();
+            if (opt.isSet("noshutdown"))
+            {
+                System.out.println("gosh: stopping shell");
+            }
+            else
+            {
+                System.out.println("gosh: stopping shell and framework");
+                shutdown();
+            }
         }
 
         return result;
@@ -189,7 +206,11 @@ public class Shell
 
     private void shutdown() throws BundleException
     {
-        context.getBundle(0).stop();
+        if (systemBundle != null)
+        {
+            systemBundle.stop();
+            systemBundle = null;
+        }
     }
 
     public Object source(CommandSession session, String script) throws Exception
@@ -215,23 +236,29 @@ public class Shell
 
     private CharSequence readScript(URI script) throws Exception
     {
+        CharBuffer buf = CharBuffer.allocate(4096);
+        StringBuilder sb = new StringBuilder();
+
         URLConnection conn = script.toURL().openConnection();
-        int length = conn.getContentLength();
 
-        if (length == -1)
+        try (InputStreamReader in = new InputStreamReader(conn.getInputStream()))
         {
-            System.err.println("eek! unknown Contentlength for: " + script);
-            length = 10240;
+            while (in.read(buf) > 0)
+            {
+                buf.flip();
+                sb.append(buf);
+                buf.clear();
+            }
+        }
+        finally
+        {
+            if (conn instanceof HttpURLConnection)
+            {
+                ((HttpURLConnection) conn).disconnect();
+            }
         }
 
-        InputStream in = conn.getInputStream();
-        CharBuffer cbuf = CharBuffer.allocate(length);
-        Reader reader = new InputStreamReader(in);
-        reader.read(cbuf);
-        in.close();
-        cbuf.rewind();
-
-        return cbuf;
+        return sb;
     }
 
     @SuppressWarnings("unchecked")
@@ -258,10 +285,12 @@ public class Shell
         }
     }
 
-    public String[] history() {
+    public String[] history()
+    {
         Iterator<String> history = this.history.getHistory();
-        List<String> lines = new ArrayList<String>();
-        for (int i = 1; history.hasNext(); i++) {
+        List<String> lines = new ArrayList<>();
+        for (int i = 1; history.hasNext(); i++)
+        {
             lines.add(String.format("%5d  %s", i, history.next()));
         }
         return lines.toArray(new String[lines.size()]);


=====================================
src/main/java/org/apache/felix/gogo/shell/Telnet.java
=====================================
@@ -74,8 +74,7 @@ public class Telnet implements Runnable
         {
             if (server != null)
             {
-                throw new IllegalStateException("telnetd is already running on port "
-                    + port);
+                throw new IllegalStateException("telnetd is already running on port " + port);
             }
             ip = opt.get("ip");
             port = opt.getNumber("port");
@@ -115,8 +114,9 @@ public class Telnet implements Runnable
     private void start() throws IOException
     {
         quit = false;
-        server = new ServerSocket(port, 0, InetAddress.getByName(ip));
-        thread = new Thread(this, "gogo telnet");
+        InetAddress addr = "".equals(ip) ? null : InetAddress.getByName(ip);
+        server = new ServerSocket(port, 0, addr);
+        thread = new Thread(this, "Gogo telnet");
         thread.start();
     }
 
@@ -138,11 +138,9 @@ public class Telnet implements Runnable
                 PrintStream out = new PrintStream(socket.getOutputStream());
                 final CommandSession session = processor.createSession(
                     socket.getInputStream(), out, out);
-
-                Thread handler = new Thread()
-                {
-                    public void run()
-                    {
+                Thread handler = new Thread(new Runnable() {
+                    @Override
+                    public void run() {
                         try
                         {
                             session.execute("gosh --login --noshutdown");
@@ -163,7 +161,7 @@ public class Telnet implements Runnable
                             }
                         }
                     }
-                };
+                });
                 handler.start();
             }
         }


=====================================
src/main/java/org/apache/felix/gogo/shell/package-info.java
=====================================
@@ -0,0 +1,34 @@
+/*
+ * 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.
+ */
+
+ at org.osgi.annotation.bundle.Capability(
+    attribute = "implementation.name=gogo.shell",
+    namespace = "org.apache.felix.gogo",
+    name = "shell.implementation",
+    version = "1.0.0"
+)
+ at Requirement(
+    effective = "active",
+    namespace = "org.apache.felix.gogo",
+    name = "command.implementation",
+    version = "1.0.0"
+)
+package org.apache.felix.gogo.shell;
+
+import org.osgi.annotation.bundle.Requirement;


=====================================
src/main/resources/gosh_profile
=====================================
@@ -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.
+#
 # default gosh_profile
 # only read if etc/gosh_profile doesn't exist relative to the System property
 # gosh.home or failing that the current directory.
@@ -6,7 +24,7 @@
 try {
 
   # ensure gogo commands are found first
-  SCOPE = gogo:*
+  SCOPE = 'gogo:*'
 
   # add methods on BundleContext object as commands
   #addcommand context ${.context} (${.context} class)
@@ -30,8 +48,8 @@ try {
   # set prompt
   prompt = 'g! '
 
-  # print welcome message
-  cat ($0 resolve motd)
+  # print welcome message, unless we're explicitly told not to...
+  if { $.gosh_quiet } { } { cat ($0 resolve motd) }
 } {
     echo "$0: ERROR: $exception"
 }



View it on GitLab: https://salsa.debian.org/java-team/felix-gogo-shell/-/compare/2c85f588799e29ea7acaf684bfdfcbf12a648dc9...b2c3adc2a21c2ea70bb35cdb3d9ceaaa6e6a9d74

-- 
View it on GitLab: https://salsa.debian.org/java-team/felix-gogo-shell/-/compare/2c85f588799e29ea7acaf684bfdfcbf12a648dc9...b2c3adc2a21c2ea70bb35cdb3d9ceaaa6e6a9d74
You're receiving this email because of your account on salsa.debian.org. Manage all notifications: https://salsa.debian.org/-/profile/notifications | Help: https://salsa.debian.org/help


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-java-commits/attachments/20261120/ab4acad0/attachment.htm>


More information about the pkg-java-commits mailing list