Set system packages correctly when modules from boot layer are loaded

The launcher needs to set the system packages to empty any time the boot
modules from the JVM are loaded as atomos content.  Otherwise the system
bundle will export duplicate packages that are exported by boot module
connect bundles.  This was not happening correctly for the case where
the old classpath mode was used on Java 11 because
org.apache.felix.atomos.runtime.AtomosLayer.isAddLayerSupported() was
returning false in this case.

The fix is to set the system packages to the empty string anytime the
AtomosRuntimeModules is used.
diff --git a/atomos.runtime/src/main/java/org/apache/felix/atomos/impl/runtime/base/AtomosRuntimeBase.java b/atomos.runtime/src/main/java/org/apache/felix/atomos/impl/runtime/base/AtomosRuntimeBase.java
index f21e784..df79a5e 100644
--- a/atomos.runtime/src/main/java/org/apache/felix/atomos/impl/runtime/base/AtomosRuntimeBase.java
+++ b/atomos.runtime/src/main/java/org/apache/felix/atomos/impl/runtime/base/AtomosRuntimeBase.java
@@ -1696,4 +1696,9 @@
     {
         throw (E) e;
     }
+
+    public void populateConfig(Map<String, String> frameworkConfig)
+    {
+        // do nothing by default
+    }
 }
diff --git a/atomos.runtime/src/main/java/org/apache/felix/atomos/impl/runtime/modules/AtomosRuntimeModules.java b/atomos.runtime/src/main/java/org/apache/felix/atomos/impl/runtime/modules/AtomosRuntimeModules.java
index 080c197..55eb229 100644
--- a/atomos.runtime/src/main/java/org/apache/felix/atomos/impl/runtime/modules/AtomosRuntimeModules.java
+++ b/atomos.runtime/src/main/java/org/apache/felix/atomos/impl/runtime/modules/AtomosRuntimeModules.java
@@ -599,4 +599,16 @@
         }
         return bc.getBundle(location);
     }
+
+    @Override
+    public void populateConfig(Map<String, String> config)
+    {
+        super.populateConfig(config);
+        if (config.get(Constants.FRAMEWORK_SYSTEMPACKAGES) == null)
+        {
+            // this is to prevent the framework from exporting all the packages provided
+            // by the module path.
+            config.put(Constants.FRAMEWORK_SYSTEMPACKAGES, "");
+        }
+    }
 }
diff --git a/atomos.runtime/src/main/java/org/apache/felix/atomos/launch/AtomosLauncher.java b/atomos.runtime/src/main/java/org/apache/felix/atomos/launch/AtomosLauncher.java
index e3f3204..2fa5b1d 100644
--- a/atomos.runtime/src/main/java/org/apache/felix/atomos/launch/AtomosLauncher.java
+++ b/atomos.runtime/src/main/java/org/apache/felix/atomos/launch/AtomosLauncher.java
@@ -23,7 +23,6 @@
 import org.apache.felix.atomos.runtime.AtomosLayer;
 import org.apache.felix.atomos.runtime.AtomosRuntime;
 import org.osgi.framework.BundleException;
-import org.osgi.framework.Constants;
 import org.osgi.framework.connect.ConnectFrameworkFactory;
 import org.osgi.framework.launch.Framework;
 
@@ -144,13 +143,7 @@
         frameworkConfig = frameworkConfig == null ? new HashMap<>()
             : new HashMap<>(frameworkConfig);
 
-        if (atomosRuntime.getBootLayer().isAddLayerSupported()
-            && frameworkConfig.get(Constants.FRAMEWORK_SYSTEMPACKAGES) == null)
-        {
-            // this is to prevent the framework from exporting all the packages provided
-            // by the module path.
-            frameworkConfig.put(Constants.FRAMEWORK_SYSTEMPACKAGES, "");
-        }
+        ((AtomosRuntimeBase) atomosRuntime).populateConfig(frameworkConfig);
 
         // Always allow the console to work
         frameworkConfig.putIfAbsent("osgi.console", "");
diff --git a/atomos.tests/atomos.tests.classpath.service/src/test/java/org/apache/felix/atomos/tests/classpath/service/test/ClasspathLaunchTest.java b/atomos.tests/atomos.tests.classpath.service/src/test/java/org/apache/felix/atomos/tests/classpath/service/test/ClasspathLaunchTest.java
index eed1558..998e48d 100644
--- a/atomos.tests/atomos.tests.classpath.service/src/test/java/org/apache/felix/atomos/tests/classpath/service/test/ClasspathLaunchTest.java
+++ b/atomos.tests/atomos.tests.classpath.service/src/test/java/org/apache/felix/atomos/tests/classpath/service/test/ClasspathLaunchTest.java
@@ -26,6 +26,7 @@
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Map;
 import java.util.Optional;
 
 import org.apache.felix.atomos.impl.runtime.base.AtomosCommands;
@@ -46,6 +47,12 @@
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceReference;
 import org.osgi.framework.launch.Framework;
+import org.osgi.framework.namespace.PackageNamespace;
+import org.osgi.framework.wiring.BundleCapability;
+import org.osgi.framework.wiring.FrameworkWiring;
+import org.osgi.resource.Namespace;
+import org.osgi.resource.Requirement;
+import org.osgi.resource.Resource;
 
 public class ClasspathLaunchTest
 {
@@ -257,4 +264,45 @@
             assertEquals(expected, b.getState(), "Wrong bundle state for bundle: " + msg);
         }
     }
+
+    @Test
+    void testSystemPackages(@TempDir Path storage) throws BundleException
+    {
+        testFramework = AtomosLauncher.launch(Collections.singletonMap(
+            Constants.FRAMEWORK_STORAGE, storage.toFile().getAbsolutePath()));
+        // this test assumes it is running on Java 11+
+        Collection<BundleCapability> javaLangPackages = testFramework.adapt(
+            FrameworkWiring.class).findProviders(new Requirement()
+            {
+
+                @Override
+                public Resource getResource()
+                {
+                    return null;
+                }
+
+                @Override
+                public String getNamespace()
+                {
+                    return PackageNamespace.PACKAGE_NAMESPACE;
+                }
+
+                @Override
+                public Map<String, String> getDirectives()
+                {
+                    return Map.of(Namespace.REQUIREMENT_FILTER_DIRECTIVE,
+                        "(" + PackageNamespace.PACKAGE_NAMESPACE + "=java.lang)");
+                }
+
+                @Override
+                public Map<String, Object> getAttributes()
+                {
+                    return Collections.emptyMap();
+                }
+            });
+        assertEquals(1, javaLangPackages.size(), "Wrong number of java.lang packages.");
+        assertEquals(Object.class.getModule().getName(),
+            javaLangPackages.iterator().next().getRevision().getSymbolicName(),
+            "Wrong provider of java.lang package.");
+    }
 }