Stop using parallel stream

The Atomos maven plugin was using parallel streams in several places.
Unfortunately many of the consumers called in the parallel streams are
not thread safe.  This can lead to unpredictable behavior.  For example,
randomly the plugin would omit a few bundles to include in the
processing.

This change also sorts the atomos index file to be in bundle symbolic
name order.  This allows for a consistent install order for images that
use the Atomos index.
diff --git a/atomos.examples/atomos.examples.jaxrs/pom.xml b/atomos.examples/atomos.examples.jaxrs/pom.xml
index 9284f77..f14e51e 100644
--- a/atomos.examples/atomos.examples.jaxrs/pom.xml
+++ b/atomos.examples/atomos.examples.jaxrs/pom.xml
@@ -157,7 +157,6 @@
                             <additionalInitializeAtBuildTime>org.apache.cxf.bus.managers.DestinationFactoryManagerImpl</additionalInitializeAtBuildTime>
                             <additionalInitializeAtBuildTime>org.apache.cxf.bus.managers.ConduitInitiatorManagerImpl</additionalInitializeAtBuildTime>
                             <additionalInitializeAtBuildTime>org.apache.cxf.bus.managers.BindingFactoryManagerImpl</additionalInitializeAtBuildTime>
-                            <!-- <additionalInitializeAtBuildTime>org.apache.felix.atomos.impl.runtime.base</additionalInitializeAtBuildTime> -->
                         </additionalInitializeAtBuildTime>
                         <resourceConfigurationFiles>
                             <resourceConfigurationFile>additionalResourceConfig.json</resourceConfigurationFile>
@@ -175,7 +174,6 @@
                             <reflectionConfigurationFile>reflectConfig_jetty.json</reflectionConfigurationFile>
                             <reflectionConfigurationFile>reflectAgentConfig.json</reflectionConfigurationFile>
                         </reflectionConfigurationFiles>
-                        <!-- <mainClass>org.apache.felix.atomos.launch.AtomosLauncher</mainClass> -->
                     </nativeImage>
                 </configuration>
                 <executions>
diff --git a/atomos.maven/src/main/java/org/apache/felix/atomos/maven/LauncherBuilderUtil.java b/atomos.maven/src/main/java/org/apache/felix/atomos/maven/LauncherBuilderUtil.java
index c7ceb68..e1fa0c0 100644
--- a/atomos.maven/src/main/java/org/apache/felix/atomos/maven/LauncherBuilderUtil.java
+++ b/atomos.maven/src/main/java/org/apache/felix/atomos/maven/LauncherBuilderUtil.java
@@ -109,6 +109,7 @@
                     .anyMatch(s -> a.getArtifactId().matches(s));
             })//
             .map(a -> a.getFile().toPath())//
+            .sorted()//
             .collect(Collectors.toList());
 
         PathCollectorPluginConfig dc = new PathCollectorPluginConfig()
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 70699d8..f21e784 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
@@ -32,6 +32,7 @@
 import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
@@ -675,7 +676,7 @@
 
         protected final Set<AtomosContentBase> findAtomosContents()
         {
-            Set<AtomosContentBase> bootBundles = new HashSet<>();
+            Set<AtomosContentBase> bootBundles = new LinkedHashSet<>();
 
             // first get the modules from the boot ModuleLayer (Java 9+ JPMS)
             findBootModuleLayerAtomosContents(bootBundles);
diff --git a/atomos.utils/atomos.utils.core/src/main/java/org/apache/felix/atomos/utils/core/ContextImpl.java b/atomos.utils/atomos.utils.core/src/main/java/org/apache/felix/atomos/utils/core/ContextImpl.java
index 961981f..48d33cc 100644
--- a/atomos.utils/atomos.utils.core/src/main/java/org/apache/felix/atomos/utils/core/ContextImpl.java
+++ b/atomos.utils/atomos.utils.core/src/main/java/org/apache/felix/atomos/utils/core/ContextImpl.java
@@ -198,7 +198,7 @@
     @Override
     public Stream<Path> getFiles(FileType... fileType)
     {
-        return paths.entrySet().parallelStream().filter(
+        return paths.entrySet().stream().filter(
             e -> List.of(fileType).stream().filter(Objects::nonNull).anyMatch(
                 t -> t.equals(e.getValue()))).map(Entry::getKey);
     }
diff --git a/atomos.utils/atomos.utils.core/src/main/java/org/apache/felix/atomos/utils/core/LauncherImpl.java b/atomos.utils/atomos.utils.core/src/main/java/org/apache/felix/atomos/utils/core/LauncherImpl.java
index 7a595e1..ad2b2d7 100644
--- a/atomos.utils/atomos.utils.core/src/main/java/org/apache/felix/atomos/utils/core/LauncherImpl.java
+++ b/atomos.utils/atomos.utils.core/src/main/java/org/apache/felix/atomos/utils/core/LauncherImpl.java
@@ -133,7 +133,7 @@
             //      }
         }
 
-        List<ComponentDescription> cds = list.parallelStream().map(cmd -> {
+        List<ComponentDescription> cds = list.stream().map(cmd -> {
             cmd.validate();
             return new ComponentDescriptionImpl(cmd);
 
@@ -345,7 +345,7 @@
 
     private <T extends SubstratePlugin<?>> Stream<T> orderdPluginsBy(Class<T> clazz)
     {
-        return plugins.parallelStream()//
+        return plugins.stream()//
             .filter(clazz::isInstance)//
             .map(clazz::cast)//
             .sorted((p1, p2) -> p1.ranking(clazz) - p2.ranking(clazz));
diff --git a/atomos.utils/atomos.utils.core/src/main/java/org/apache/felix/atomos/utils/core/plugins/collector/PathCollectorPlugin.java b/atomos.utils/atomos.utils.core/src/main/java/org/apache/felix/atomos/utils/core/plugins/collector/PathCollectorPlugin.java
index 8768b47..4856773 100644
--- a/atomos.utils/atomos.utils.core/src/main/java/org/apache/felix/atomos/utils/core/plugins/collector/PathCollectorPlugin.java
+++ b/atomos.utils/atomos.utils.core/src/main/java/org/apache/felix/atomos/utils/core/plugins/collector/PathCollectorPlugin.java
@@ -62,7 +62,7 @@
             }
 
         };
-        config.paths().parallelStream().forEach(p -> {
+        config.paths().forEach(p -> {
             try
             {
                 Files.walkFileTree(p, v);
diff --git a/atomos.utils/atomos.utils.core/src/main/java/org/apache/felix/atomos/utils/core/plugins/finaliser/shade/ShadePreHolder.java b/atomos.utils/atomos.utils.core/src/main/java/org/apache/felix/atomos/utils/core/plugins/finaliser/shade/ShadePreHolder.java
index b57cbb7..02b8ad4 100644
--- a/atomos.utils/atomos.utils.core/src/main/java/org/apache/felix/atomos/utils/core/plugins/finaliser/shade/ShadePreHolder.java
+++ b/atomos.utils/atomos.utils.core/src/main/java/org/apache/felix/atomos/utils/core/plugins/finaliser/shade/ShadePreHolder.java
@@ -65,7 +65,7 @@
 
     List<JarFile> all()
     {
-        return source.entrySet().parallelStream().flatMap(
+        return source.entrySet().stream().flatMap(
             c -> c.getValue().stream()).collect(Collectors.toList());
     }
 
@@ -76,7 +76,7 @@
 
     JarFile any()
     {
-        return source.entrySet().parallelStream().map(
+        return source.entrySet().stream().map(
             c -> c.getValue().stream().findAny()).findAny().get().get();
     }
 
@@ -92,7 +92,7 @@
 
     long size()
     {
-        return source.entrySet().parallelStream().flatMap(
+        return source.entrySet().stream().flatMap(
             c -> c.getValue().stream()).count();
     }
 
diff --git a/atomos.utils/atomos.utils.core/src/main/java/org/apache/felix/atomos/utils/core/plugins/index/IndexPlugin.java b/atomos.utils/atomos.utils.core/src/main/java/org/apache/felix/atomos/utils/core/plugins/index/IndexPlugin.java
index 2b4d1eb..2311486 100644
--- a/atomos.utils/atomos.utils.core/src/main/java/org/apache/felix/atomos/utils/core/plugins/index/IndexPlugin.java
+++ b/atomos.utils/atomos.utils.core/src/main/java/org/apache/felix/atomos/utils/core/plugins/index/IndexPlugin.java
@@ -79,7 +79,7 @@
 
     JarOutputStream jos;
 
-    private ArrayList<IndexInfo> sis;
+    private ArrayList<IndexInfo> indexInfos;
     private Map<String, Boolean> uniquePaths;
 
     private Path substrateJar;
@@ -178,7 +178,7 @@
         }).map(JarEntry::getName).collect(Collectors.toList());
 
         info.setFiles(files);
-        sis.add(info);
+        indexInfos.add(info);
     }
 
     @Override
@@ -203,21 +203,23 @@
 
             final List<String> bundleIndexLines = new ArrayList<>();
             final Collection<String> resources = new LinkedHashSet<>();
-            sis.forEach(s -> {
-                if (s.getBundleSymbolicName() != null)
-                {
+            indexInfos.stream() //
+                .filter((i) -> i.getBundleSymbolicName() != null) //
+                .sorted((i1, i2) -> i1.getBundleSymbolicName().compareTo(
+                    i2.getBundleSymbolicName())) //
+                .forEach((i) -> {
                     bundleIndexLines.add(ATOMOS_BUNDLE_SEPARATOR);
-                    bundleIndexLines.add(s.getId());
-                    bundleIndexLines.add(s.getBundleSymbolicName());
-                    bundleIndexLines.add(s.getVersion());
-                    s.getFiles().forEach(f -> {
+                    bundleIndexLines.add(i.getId());
+                    bundleIndexLines.add(i.getBundleSymbolicName());
+                    bundleIndexLines.add(i.getVersion());
+                    i.getFiles().forEach(f -> {
                         bundleIndexLines.add(f);
                         if (!isClass(f))
                         {
                             if (Boolean.FALSE == uniquePaths.get(f))
                             {
                                 resources.add(
-                                    ATOMOS_BUNDLES_BASE_PATH + s.getId() + "/" + f);
+                                    ATOMOS_BUNDLES_BASE_PATH + i.getId() + "/" + f);
                             }
                             if (!f.endsWith("/") && !"META-INF/MANIFEST.MF".equals(f))
                             {
@@ -225,8 +227,8 @@
                             }
                         }
                     });
-                }
-            });
+                });
+
             ByteArrayOutputStream indexBytes;
             try (final ByteArrayOutputStream out = new ByteArrayOutputStream();
                 BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out)))
@@ -319,7 +321,7 @@
             }
         }
         counter = new AtomicLong(0);
-        sis = new ArrayList<>();
+        indexInfos = new ArrayList<>();
         uniquePaths = new HashMap<>();
     }