public void doFinal()

in atomos.utils/atomos.utils.core/src/main/java/org/apache/felix/atomos/utils/core/plugins/finaliser/shade/ShaderPlugin.java [60:169]


    public void doFinal(Context context)
    {
        Path shadesJar = config.shadeOutputDirectory().resolve("shaded.jar");
        Manifest manifest = new Manifest();
        manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
        manifest.getMainAttributes().put(new Attributes.Name("Created-By"),
            "atomos-maven-plugin");
        manifest.getMainAttributes().put(Attributes.Name.MAIN_CLASS, "foooBar");

        try (JarOutputStream jarOutputStream = new JarOutputStream(
            new FileOutputStream(shadesJar.toFile()), manifest))
        {

            List<Path> classpath = context.getFiles(FileType.ARTIFACT,
                FileType.INDEX_JAR).collect(Collectors.toList());
            classpath.forEach(p -> {
                try
                {
                    JarFile jar = new JarFile(p.toFile());
                    map.put(jar, p);
                    jar.stream()//
                        .filter(Predicate.not(JarEntry::isDirectory))//
                        .forEach(je -> {
                            compute(je.getName()).add(jar);
                        });
                }
                catch (IOException e)
                {
                    throw new UncheckedIOException(e);
                }
            });
            candidates.forEach(c -> {
                try
                {
                    if ("module-info.class".equals(c.getName()))
                    {
                        return;
                    }
                    if ("META-INF/MANIFEST.MF".equals(c.getName()))
                    {
                        return;
                    }
                    JarEntry jarEntry = new JarEntry(c.getName());
                    jarOutputStream.putNextEntry(jarEntry);
                    if (c.getName().startsWith("services"))
                    {
                        AtomicBoolean ab = new AtomicBoolean();
                        StringBuilder sb = new StringBuilder();
                        for (JarFile jar : c.all())
                        {
                            if (ab.getAndSet(true))
                            {
                                sb.append("\n");
                            }
                            JarEntry e = jar.getJarEntry(c.getName());
                            InputStream is = jar.getInputStream(e);
                            sb.append(is);
                        }
                        jarOutputStream.write(sb.toString().getBytes());
                    }
                    else
                    {
                        if (!c.allSameChecksum())
                        {
                            System.out.println(c.getName());
                            c.getSource().forEach((k, v) -> {

                                System.out.println("- Checksum: " + k);
                                System.out.println("-- List of Jars:");

                                v.stream().map(map::get)//
                                    .map(Path::toAbsolutePath)//
                                    .map(p -> "-- " + p.toString())//
                                    .forEach(System.out::println);

                            });
                        }
                        JarFile j = c.any();
                        JarEntry e = j.getJarEntry(c.getName());
                        InputStream is = j.getInputStream(e);
                        jarOutputStream.write(is.readAllBytes());
                    }
                }
                catch (IOException e)
                {
                    throw new UncheckedIOException(e);
                }

            });

        }
        catch (

        Exception e)
        {
            e.printStackTrace();
        }
        finally
        {
            map.forEach((j, p) -> {
                try
                {
                    j.close();
                }
                catch (IOException e)
                {
                }
            });
        }
    }