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 shouldZipTaskPluginsIntoOneZipEveryTime() throws Exception {
        pluginsZip.create();

        assertThat(new File(expectedZipPath).exists()).as(expectedZipPath + " should exist").isTrue();
        try (ZipFile zipFile = new ZipFile(expectedZipPath)) {
            assertThat(zipFile.getEntry("bundled/bundled-task-1.jar")).isNotNull();
            assertThat(zipFile.getEntry("bundled/bundled-scm-3.jar")).isNotNull();
            assertThat(zipFile.getEntry("bundled/bundled-package-material-4.jar")).isNotNull();
            assertThat(zipFile.getEntry("external/external-task-1.jar")).isNotNull();
            assertThat(zipFile.getEntry("external/external-scm-3.jar")).isNotNull();
            assertThat(zipFile.getEntry("external/external-package-material-4.jar")).isNotNull();

            assertThat(zipFile.getEntry("bundled/bundled-auth-2.jar")).isNull();
            assertThat(zipFile.getEntry("external/external-elastic-agent-2.jar")).isNull();
        }
    }