public void create() {
        checkFilesAccessibility(bundledPlugins, externalPlugins);
        reset();

        MessageDigest md5Digest = DigestUtils.getMd5Digest();
        try (ZipOutputStream zos = new ZipOutputStream(new DigestOutputStream(new BufferedOutputStream(new FileOutputStream(destZipFile)), md5Digest))) {
            for (GoPluginBundleDescriptor agentPlugins : agentPlugins()) {
                String zipEntryPrefix = "external/";

                if (agentPlugins.isBundledPlugin()) {
                    zipEntryPrefix = "bundled/";
                }

                zos.putNextEntry(new ZipEntry(zipEntryPrefix + new File(agentPlugins.bundleJARFileLocation()).getName()));
                Files.copy(new File(agentPlugins.bundleJARFileLocation()).toPath(), zos);
                zos.closeEntry();
            }
        } catch (Exception e) {
            LOG.error("Could not create zip of plugins for agent to download.", e);
        }

        md5DigestOfPlugins = Hex.encodeHexString(md5Digest.digest());
    }
@Test
    void shouldCreateAZipWithOneCopyOfEachJar_ForAPluginBundleWithMultiplePluginsInIt() throws IOException {
        File bundledPluginJarLocation = createPluginFile(bundledPluginsDir, "bundled-multi-plugin-1.jar", "Bundled1");
        File externalPluginJarLocation = createPluginFile(externalPluginsDir, "external-multi-plugin-1.jar", "External1");

        bundledTaskPlugin = new GoPluginBundleDescriptor(
                getPluginDescriptor("bundled-plugin-1", bundledPluginJarLocation, true),
                getPluginDescriptor("bundled-plugin-2", bundledPluginJarLocation, true)
        );

        externalTaskPlugin = new GoPluginBundleDescriptor(
                getPluginDescriptor("external-plugin-1", externalPluginJarLocation, false),
                getPluginDescriptor("external-plugin-2", externalPluginJarLocation, false)
        );

        when(pluginManager.plugins()).thenReturn(List.of(
                bundledTaskPlugin.descriptors().get(0),
                bundledTaskPlugin.descriptors().get(1),

                externalTaskPlugin.descriptors().get(0),
                externalTaskPlugin.descriptors().get(1)
        ));

        when(pluginManager.isPluginOfType("task", "bundled-plugin-1")).thenReturn(true);
        when(pluginManager.isPluginOfType("scm", "bundled-plugin-2")).thenReturn(true);
        when(pluginManager.isPluginOfType("task", "external-plugin-1")).thenReturn(true);
        when(pluginManager.isPluginOfType("artifact", "external-plugin-2")).thenReturn(true);


        pluginsZip = spy(new PluginsZip(systemEnvironment, pluginManager));
        pluginsZip.create();

        try (ZipFile zipFile = new ZipFile(expectedZipPath)) {
            assertThat(new File(expectedZipPath).exists()).as(expectedZipPath + " should exist").isTrue();
            assertThat(EnumerationUtils.toList(zipFile.entries()).size()).isEqualTo(2);
            assertThat(zipFile.getEntry("bundled/bundled-multi-plugin-1.jar")).isNotNull();
            assertThat(zipFile.getEntry("external/external-multi-plugin-1.jar")).isNotNull();
        }
    }