This is an automated email from the ASF dual-hosted git repository.

gharris pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/kafka.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 4550550c7cb MINOR: Cleanup TestPlugins and normalize TestPlugin enum 
(#13333)
4550550c7cb is described below

commit 4550550c7cbb2f00934a09296ad1b03ceb643730
Author: Greg Harris <greg.har...@aiven.io>
AuthorDate: Wed Jul 3 09:44:09 2024 -0700

    MINOR: Cleanup TestPlugins and normalize TestPlugin enum (#13333)
    
    Signed-off-by: Greg Harris <greg.har...@aiven.io>
    Reviewers: Chris Egerton <chr...@aiven.io>
---
 .../runtime/isolation/PluginScannerTest.java       |   7 -
 .../connect/runtime/isolation/TestPlugins.java     | 267 ++++++++++++---------
 .../apache/kafka/tools/ConnectPluginPathTest.java  |   8 -
 3 files changed, 154 insertions(+), 128 deletions(-)

diff --git 
a/connect/runtime/src/test/java/org/apache/kafka/connect/runtime/isolation/PluginScannerTest.java
 
b/connect/runtime/src/test/java/org/apache/kafka/connect/runtime/isolation/PluginScannerTest.java
index d1e9f55953b..268efdc8c02 100644
--- 
a/connect/runtime/src/test/java/org/apache/kafka/connect/runtime/isolation/PluginScannerTest.java
+++ 
b/connect/runtime/src/test/java/org/apache/kafka/connect/runtime/isolation/PluginScannerTest.java
@@ -17,7 +17,6 @@
 
 package org.apache.kafka.connect.runtime.isolation;
 
-import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.io.TempDir;
 import org.junit.jupiter.params.ParameterizedTest;
 import org.junit.jupiter.params.provider.MethodSource;
@@ -49,12 +48,6 @@ public class PluginScannerTest {
         return Stream.of(new ReflectionScanner(), new ServiceLoaderScanner());
     }
 
-    @BeforeAll
-    public static void setUp() {
-        // Work around a circular-dependency in TestPlugins.
-        TestPlugins.pluginPath();
-    }
-
     @ParameterizedTest
     @MethodSource("parameters")
     public void testScanningEmptyPluginPath(PluginScanner scanner) {
diff --git 
a/connect/runtime/src/test/java/org/apache/kafka/connect/runtime/isolation/TestPlugins.java
 
b/connect/runtime/src/test/java/org/apache/kafka/connect/runtime/isolation/TestPlugins.java
index 2c6c460c0ea..47c6f8b4ee6 100644
--- 
a/connect/runtime/src/test/java/org/apache/kafka/connect/runtime/isolation/TestPlugins.java
+++ 
b/connect/runtime/src/test/java/org/apache/kafka/connect/runtime/isolation/TestPlugins.java
@@ -34,7 +34,7 @@ import java.nio.file.Paths;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.Comparator;
-import java.util.HashMap;
+import java.util.EnumMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
@@ -45,6 +45,7 @@ import java.util.jar.JarEntry;
 import java.util.jar.JarOutputStream;
 import java.util.jar.Manifest;
 import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 import javax.tools.JavaCompiler;
 import javax.tools.StandardJavaFileManager;
@@ -66,166 +67,200 @@ import javax.tools.ToolProvider;
  * and reference the names of the different plugins directly via the {@link 
TestPlugin} enum.
  */
 public class TestPlugins {
-    private static final Predicate<String> REMOVE_CLASS_FILTER = s -> 
s.contains("NonExistentInterface");
+
+    /**
+     * Unit of compilation and distribution, containing zero or more plugin 
classes.
+     */
+    public enum TestPackage {
+        ALIASED_STATIC_FIELD("aliased-static-field"),
+        ALWAYS_THROW_EXCEPTION("always-throw-exception"),
+        BAD_PACKAGING("bad-packaging", s -> 
s.contains("NonExistentInterface")),
+        MULTIPLE_PLUGINS_IN_JAR("multiple-plugins-in-jar"),
+        NON_MIGRATED("non-migrated"),
+        READ_VERSION_FROM_RESOURCE_V1("read-version-from-resource-v1"),
+        READ_VERSION_FROM_RESOURCE_V2("read-version-from-resource-v2"),
+        SAMPLING_CONFIGURABLE("sampling-configurable"),
+        SAMPLING_CONFIG_PROVIDER("sampling-config-provider"),
+        SAMPLING_CONNECTOR("sampling-connector"),
+        SAMPLING_CONVERTER("sampling-converter"),
+        SAMPLING_HEADER_CONVERTER("sampling-header-converter"),
+        SERVICE_LOADER("service-loader"),
+        SUBCLASS_OF_CLASSPATH("subclass-of-classpath");
+
+        private final String resourceDir;
+        private final Predicate<String> removeRuntimeClasses;
+
+        TestPackage(String resourceDir) {
+            this(resourceDir, ignored -> false);
+        }
+
+        TestPackage(String resourceDir, Predicate<String> 
removeRuntimeClasses) {
+            this.resourceDir = resourceDir;
+            this.removeRuntimeClasses = removeRuntimeClasses;
+        }
+
+        public String resourceDir() {
+            return resourceDir;
+        }
+
+        public Predicate<String> removeRuntimeClasses() {
+            return removeRuntimeClasses;
+        }
+    }
+
     public enum TestPlugin {
         /**
-         * A plugin which will always throw an exception during loading
+         * A plugin which samples information about its initialization.
          */
-        ALWAYS_THROW_EXCEPTION("always-throw-exception", 
"test.plugins.AlwaysThrowException", false),
+        ALIASED_STATIC_FIELD(TestPackage.ALIASED_STATIC_FIELD, 
"test.plugins.AliasedStaticField"),
         /**
-         * A plugin which samples information about its initialization.
+         * A plugin which will always throw an exception during loading
          */
-        ALIASED_STATIC_FIELD("aliased-static-field", 
"test.plugins.AliasedStaticField"),
+        ALWAYS_THROW_EXCEPTION(TestPackage.ALWAYS_THROW_EXCEPTION, 
"test.plugins.AlwaysThrowException", false),
         /**
-         * A {@link org.apache.kafka.connect.storage.Converter}
-         * which samples information about its method calls.
+         * A plugin which is packaged with other incorrectly packaged plugins, 
but itself has no issues loading.
          */
-        SAMPLING_CONVERTER("sampling-converter", 
"test.plugins.SamplingConverter"),
+        BAD_PACKAGING_CO_LOCATED(TestPackage.BAD_PACKAGING, 
"test.plugins.CoLocatedPlugin", true),
         /**
-         * A {@link org.apache.kafka.common.Configurable}
-         * which samples information about its method calls.
+         * A plugin which is incorrectly packaged, which has a private default 
constructor.
          */
-        SAMPLING_CONFIGURABLE("sampling-configurable", 
"test.plugins.SamplingConfigurable"),
+        
BAD_PACKAGING_DEFAULT_CONSTRUCTOR_PRIVATE_CONNECTOR(TestPackage.BAD_PACKAGING, 
"test.plugins.DefaultConstructorPrivateConnector", false),
         /**
-         * A {@link org.apache.kafka.connect.storage.HeaderConverter}
-         * which samples information about its method calls.
+         * A plugin which is incorrectly packaged, which throws an exception 
from default constructor.
          */
-        SAMPLING_HEADER_CONVERTER("sampling-header-converter", 
"test.plugins.SamplingHeaderConverter"),
+        
BAD_PACKAGING_DEFAULT_CONSTRUCTOR_THROWS_CONNECTOR(TestPackage.BAD_PACKAGING, 
"test.plugins.DefaultConstructorThrowsConnector", false),
         /**
-         * A {@link org.apache.kafka.common.config.provider.ConfigProvider}
-         * which samples information about its method calls.
+         * A plugin which is incorrectly packaged, which throws an exception 
from the {@link Versioned#version()} method.
          */
-        SAMPLING_CONFIG_PROVIDER("sampling-config-provider", 
"test.plugins.SamplingConfigProvider"),
+        BAD_PACKAGING_INNER_CLASS_CONNECTOR(TestPackage.BAD_PACKAGING, 
"test.plugins.OuterClass$InnerClass", false),
         /**
-         * A {@link org.apache.kafka.connect.sink.SinkConnector}
-         * which samples information about its method calls.
+         * A plugin which is incorrectly packaged, and is missing a superclass 
definition.
          */
-        SAMPLING_CONNECTOR("sampling-connector", 
"test.plugins.SamplingConnector"),
+        BAD_PACKAGING_MISSING_SUPERCLASS(TestPackage.BAD_PACKAGING, 
"test.plugins.MissingSuperclassConverter", false),
         /**
-         * A plugin which uses a {@link java.util.ServiceLoader}
-         * to load internal classes, and samples information about their 
initialization.
+         * A plugin which is incorrectly packaged, which has a private default 
constructor.
          */
-        SERVICE_LOADER("service-loader", "test.plugins.ServiceLoaderPlugin"),
+        
BAD_PACKAGING_NO_DEFAULT_CONSTRUCTOR_CONNECTOR(TestPackage.BAD_PACKAGING, 
"test.plugins.NoDefaultConstructorConnector", false),
         /**
-         * A plugin which reads a version string from a resource and packages 
the version string 1.0.0.
+         * A plugin which is incorrectly packaged, which has a constructor 
which takes arguments.
          */
-        READ_VERSION_FROM_RESOURCE_V1("read-version-from-resource-v1", 
"test.plugins.ReadVersionFromResource"),
+        
BAD_PACKAGING_NO_DEFAULT_CONSTRUCTOR_CONVERTER(TestPackage.BAD_PACKAGING, 
"test.plugins.NoDefaultConstructorConverter", false),
         /**
-         * A plugin which reads a version string from a resource and packages 
the version string 2.0.0.
-         * This plugin is not included in {@link TestPlugins#pluginPath()} and 
must be included explicitly
+         * A plugin which is incorrectly packaged, which has a constructor 
which takes arguments.
          */
-        READ_VERSION_FROM_RESOURCE_V2("read-version-from-resource-v2", 
"test.plugins.ReadVersionFromResource", false),
+        
BAD_PACKAGING_NO_DEFAULT_CONSTRUCTOR_OVERRIDE_POLICY(TestPackage.BAD_PACKAGING, 
"test.plugins.NoDefaultConstructorOverridePolicy", false),
         /**
-         * A plugin which shares a jar file with {@link 
TestPlugin#MULTIPLE_PLUGINS_IN_JAR_THING_TWO}
+         * A connector which is incorrectly packaged, and throws during static 
initialization.
          */
-        MULTIPLE_PLUGINS_IN_JAR_THING_ONE("multiple-plugins-in-jar", 
"test.plugins.ThingOne"),
+        
BAD_PACKAGING_STATIC_INITIALIZER_THROWS_CONNECTOR(TestPackage.BAD_PACKAGING, 
"test.plugins.StaticInitializerThrowsConnector", false),
         /**
-         * A plugin which shares a jar file with {@link 
TestPlugin#MULTIPLE_PLUGINS_IN_JAR_THING_ONE}
+         * A plugin which is incorrectly packaged, which throws an exception 
from the {@link Versioned#version()} method.
          */
-        MULTIPLE_PLUGINS_IN_JAR_THING_TWO("multiple-plugins-in-jar", 
"test.plugins.ThingTwo"),
+        
BAD_PACKAGING_STATIC_INITIALIZER_THROWS_REST_EXTENSION(TestPackage.BAD_PACKAGING,
 "test.plugins.StaticInitializerThrowsRestExtension", false),
         /**
-         * A plugin which is incorrectly packaged, and is missing a superclass 
definition.
+         * A plugin which is incorrectly packaged, which throws an exception 
from the {@link Versioned#version()} method.
          */
-        BAD_PACKAGING_MISSING_SUPERCLASS("bad-packaging", 
"test.plugins.MissingSuperclassConverter", false, REMOVE_CLASS_FILTER),
+        
BAD_PACKAGING_VERSION_METHOD_THROWS_CONNECTOR(TestPackage.BAD_PACKAGING, 
"test.plugins.VersionMethodThrowsConnector", true),
         /**
-         * A plugin which is packaged with other incorrectly packaged plugins, 
but itself has no issues loading.
+         * A plugin which shares a jar file with {@link 
TestPlugin#MULTIPLE_PLUGINS_IN_JAR_THING_TWO}
          */
-        BAD_PACKAGING_CO_LOCATED("bad-packaging", 
"test.plugins.CoLocatedPlugin", true, REMOVE_CLASS_FILTER),
+        MULTIPLE_PLUGINS_IN_JAR_THING_ONE(TestPackage.MULTIPLE_PLUGINS_IN_JAR, 
"test.plugins.ThingOne"),
         /**
-         * A connector which is incorrectly packaged, and throws during static 
initialization.
+         * A plugin which shares a jar file with {@link 
TestPlugin#MULTIPLE_PLUGINS_IN_JAR_THING_ONE}
          */
-        BAD_PACKAGING_STATIC_INITIALIZER_THROWS_CONNECTOR("bad-packaging", 
"test.plugins.StaticInitializerThrowsConnector", false, REMOVE_CLASS_FILTER),
+        MULTIPLE_PLUGINS_IN_JAR_THING_TWO(TestPackage.MULTIPLE_PLUGINS_IN_JAR, 
"test.plugins.ThingTwo"),
         /**
-         * A plugin which is incorrectly packaged, which throws an exception 
from the {@link Versioned#version()} method.
+         * A converter which does not have a corresponding ServiceLoader 
manifest
          */
-        BAD_PACKAGING_VERSION_METHOD_THROWS_CONNECTOR("bad-packaging", 
"test.plugins.VersionMethodThrowsConnector", true, REMOVE_CLASS_FILTER),
+        NON_MIGRATED_CONVERTER(TestPackage.NON_MIGRATED, 
"test.plugins.NonMigratedConverter", false),
         /**
-         * A plugin which is incorrectly packaged, which throws an exception 
from default constructor.
+         * A header converter which does not have a corresponding 
ServiceLoader manifest
          */
-        BAD_PACKAGING_DEFAULT_CONSTRUCTOR_THROWS_CONNECTOR("bad-packaging", 
"test.plugins.DefaultConstructorThrowsConnector", false, REMOVE_CLASS_FILTER),
+        NON_MIGRATED_HEADER_CONVERTER(TestPackage.NON_MIGRATED, 
"test.plugins.NonMigratedHeaderConverter", false),
         /**
-         * A plugin which is incorrectly packaged, which has a private default 
constructor.
+         * A plugin which implements multiple interfaces, and has 
ServiceLoader manifests for some interfaces and not others.
          */
-        BAD_PACKAGING_DEFAULT_CONSTRUCTOR_PRIVATE_CONNECTOR("bad-packaging", 
"test.plugins.DefaultConstructorPrivateConnector", false, REMOVE_CLASS_FILTER),
+        NON_MIGRATED_MULTI_PLUGIN(TestPackage.NON_MIGRATED, 
"test.plugins.NonMigratedMultiPlugin", false),
         /**
-         * A plugin which is incorrectly packaged, which has a constructor 
which takes arguments.
+         * A predicate which does not have a corresponding ServiceLoader 
manifest
          */
-        BAD_PACKAGING_NO_DEFAULT_CONSTRUCTOR_CONNECTOR("bad-packaging", 
"test.plugins.NoDefaultConstructorConnector", false, REMOVE_CLASS_FILTER),
+        NON_MIGRATED_PREDICATE(TestPackage.NON_MIGRATED, 
"test.plugins.NonMigratedPredicate", false),
         /**
-         * A plugin which is incorrectly packaged, which has a constructor 
which takes arguments.
+         * A sink connector which does not have a corresponding ServiceLoader 
manifest
          */
-        BAD_PACKAGING_NO_DEFAULT_CONSTRUCTOR_CONVERTER("bad-packaging", 
"test.plugins.NoDefaultConstructorConverter", false, REMOVE_CLASS_FILTER),
+        NON_MIGRATED_SINK_CONNECTOR(TestPackage.NON_MIGRATED, 
"test.plugins.NonMigratedSinkConnector", false),
         /**
-         * A plugin which is incorrectly packaged, which has a constructor 
which takes arguments.
+         * A source connector which does not have a corresponding 
ServiceLoader manifest
          */
-        BAD_PACKAGING_NO_DEFAULT_CONSTRUCTOR_OVERRIDE_POLICY("bad-packaging", 
"test.plugins.NoDefaultConstructorOverridePolicy", false, REMOVE_CLASS_FILTER),
+        NON_MIGRATED_SOURCE_CONNECTOR(TestPackage.NON_MIGRATED, 
"test.plugins.NonMigratedSourceConnector", false),
         /**
-         * A plugin which is incorrectly packaged, which throws an exception 
from the {@link Versioned#version()} method.
+         * A transformation which does not have a corresponding ServiceLoader 
manifest
          */
-        BAD_PACKAGING_INNER_CLASS_CONNECTOR("bad-packaging", 
"test.plugins.OuterClass$InnerClass", false, REMOVE_CLASS_FILTER),
+        NON_MIGRATED_TRANSFORMATION(TestPackage.NON_MIGRATED, 
"test.plugins.NonMigratedTransformation", false),
         /**
-         * A plugin which is incorrectly packaged, which throws an exception 
from the {@link Versioned#version()} method.
+         * A plugin which reads a version string from a resource and packages 
the version string 1.0.0.
          */
-        
BAD_PACKAGING_STATIC_INITIALIZER_THROWS_REST_EXTENSION("bad-packaging", 
"test.plugins.StaticInitializerThrowsRestExtension", false, 
REMOVE_CLASS_FILTER),
+        
READ_VERSION_FROM_RESOURCE_V1(TestPackage.READ_VERSION_FROM_RESOURCE_V1, 
"test.plugins.ReadVersionFromResource"),
         /**
-         * A reflectively discovered plugin which subclasses another plugin 
which is present on the classpath
+         * A plugin which reads a version string from a resource and packages 
the version string 2.0.0.
+         * This plugin is not included in {@link TestPlugins#pluginPath()} and 
must be included explicitly
          */
-        SUBCLASS_OF_CLASSPATH_CONVERTER("subclass-of-classpath", 
"test.plugins.SubclassOfClasspathConverter"),
+        
READ_VERSION_FROM_RESOURCE_V2(TestPackage.READ_VERSION_FROM_RESOURCE_V2, 
"test.plugins.ReadVersionFromResource", false),
         /**
-         * A ServiceLoader discovered plugin which subclasses another plugin 
which is present on the classpath
+         * A {@link org.apache.kafka.common.Configurable}
+         * which samples information about its method calls.
          */
-        SUBCLASS_OF_CLASSPATH_OVERRIDE_POLICY("subclass-of-classpath", 
"test.plugins.SubclassOfClasspathOverridePolicy"),
+        SAMPLING_CONFIGURABLE(TestPackage.SAMPLING_CONFIGURABLE, 
"test.plugins.SamplingConfigurable"),
         /**
-         * A converter which does not have a corresponding ServiceLoader 
manifest
+         * A {@link org.apache.kafka.common.config.provider.ConfigProvider}
+         * which samples information about its method calls.
          */
-        NON_MIGRATED_CONVERTER("non-migrated", 
"test.plugins.NonMigratedConverter", false),
+        SAMPLING_CONFIG_PROVIDER(TestPackage.SAMPLING_CONFIG_PROVIDER, 
"test.plugins.SamplingConfigProvider"),
         /**
-         * A header converter which does not have a corresponding 
ServiceLoader manifest
+         * A {@link org.apache.kafka.connect.sink.SinkConnector}
+         * which samples information about its method calls.
          */
-        NON_MIGRATED_HEADER_CONVERTER("non-migrated", 
"test.plugins.NonMigratedHeaderConverter", false),
+        SAMPLING_CONNECTOR(TestPackage.SAMPLING_CONNECTOR, 
"test.plugins.SamplingConnector"),
         /**
-         * A plugin which implements multiple interfaces, and has 
ServiceLoader manifests for some interfaces and not others.
+         * A {@link org.apache.kafka.connect.storage.Converter}
+         * which samples information about its method calls.
          */
-        NON_MIGRATED_MULTI_PLUGIN("non-migrated", 
"test.plugins.NonMigratedMultiPlugin", false),
+        SAMPLING_CONVERTER(TestPackage.SAMPLING_CONVERTER, 
"test.plugins.SamplingConverter"),
         /**
-         * A predicate which does not have a corresponding ServiceLoader 
manifest
+         * A {@link org.apache.kafka.connect.storage.HeaderConverter}
+         * which samples information about its method calls.
          */
-        NON_MIGRATED_PREDICATE("non-migrated", 
"test.plugins.NonMigratedPredicate", false),
+        SAMPLING_HEADER_CONVERTER(TestPackage.SAMPLING_HEADER_CONVERTER, 
"test.plugins.SamplingHeaderConverter"),
         /**
-         * A sink connector which does not have a corresponding ServiceLoader 
manifest
+         * A plugin which uses a {@link java.util.ServiceLoader}
+         * to load internal classes, and samples information about their 
initialization.
          */
-        NON_MIGRATED_SINK_CONNECTOR("non-migrated", 
"test.plugins.NonMigratedSinkConnector", false),
+        SERVICE_LOADER(TestPackage.SERVICE_LOADER, 
"test.plugins.ServiceLoaderPlugin"),
         /**
-         * A source connector which does not have a corresponding 
ServiceLoader manifest
+         * A reflectively discovered plugin which subclasses another plugin 
which is present on the classpath
          */
-        NON_MIGRATED_SOURCE_CONNECTOR("non-migrated", 
"test.plugins.NonMigratedSourceConnector", false),
+        SUBCLASS_OF_CLASSPATH_CONVERTER(TestPackage.SUBCLASS_OF_CLASSPATH, 
"test.plugins.SubclassOfClasspathConverter"),
         /**
-         * A transformation which does not have a corresponding ServiceLoader 
manifest
+         * A ServiceLoader discovered plugin which subclasses another plugin 
which is present on the classpath
          */
-        NON_MIGRATED_TRANSFORMATION("non-migrated", 
"test.plugins.NonMigratedTransformation", false);
+        
SUBCLASS_OF_CLASSPATH_OVERRIDE_POLICY(TestPackage.SUBCLASS_OF_CLASSPATH, 
"test.plugins.SubclassOfClasspathOverridePolicy");
 
-        private final String resourceDir;
+        private final TestPackage testPackage;
         private final String className;
         private final boolean includeByDefault;
-        private final Predicate<String> removeRuntimeClasses;
-
-        TestPlugin(String resourceDir, String className) {
-            this(resourceDir, className, true);
-        }
 
-        TestPlugin(String resourceDir, String className, boolean 
includeByDefault) {
-            this(resourceDir, className, includeByDefault, ignored -> false);
+        TestPlugin(TestPackage testPackage, String className) {
+            this(testPackage, className, true);
         }
 
-        TestPlugin(String resourceDir, String className, boolean 
includeByDefault, Predicate<String> removeRuntimeClasses) {
-            this.resourceDir = resourceDir;
+        TestPlugin(TestPackage testPackage, String className, boolean 
includeByDefault) {
+            this.testPackage = testPackage;
             this.className = className;
             this.includeByDefault = includeByDefault;
-            this.removeRuntimeClasses = removeRuntimeClasses;
         }
 
-        public String resourceDir() {
-            return resourceDir;
+        public TestPackage testPackage() {
+            return testPackage;
         }
 
         public String className() {
@@ -235,25 +270,21 @@ public class TestPlugins {
         public boolean includeByDefault() {
             return includeByDefault;
         }
-
-        public Predicate<String> removeRuntimeClasses() {
-            return removeRuntimeClasses;
-        }
     }
 
     private static final Logger log = 
LoggerFactory.getLogger(TestPlugins.class);
-    private static final Map<String, Path> PLUGIN_JARS;
+    private static final Map<TestPackage, Path> PLUGIN_JARS;
     private static final Throwable INITIALIZATION_EXCEPTION;
 
     static {
         Throwable err = null;
-        Map<String, Path> pluginJars = new HashMap<>();
+        Map<TestPackage, Path> pluginJars = new EnumMap<>(TestPackage.class);
         try {
-            for (TestPlugin testPlugin : TestPlugin.values()) {
-                if (pluginJars.containsKey(testPlugin.resourceDir())) {
-                    log.debug("Skipping recompilation of " + 
testPlugin.resourceDir());
+            for (TestPackage testPackage : TestPackage.values()) {
+                if (pluginJars.containsKey(testPackage)) {
+                    log.debug("Skipping recompilation of " + 
testPackage.resourceDir());
                 }
-                pluginJars.put(testPlugin.resourceDir(), 
createPluginJar(testPlugin.resourceDir(), testPlugin.removeRuntimeClasses()));
+                pluginJars.put(testPackage, 
createPluginJar(testPackage.resourceDir(), testPackage.removeRuntimeClasses()));
             }
         } catch (Throwable e) {
             log.error("Could not set up plugin test jars", e);
@@ -296,7 +327,7 @@ public class TestPlugins {
         assertAvailable();
         return Arrays.stream(plugins)
                 .filter(Objects::nonNull)
-                .map(TestPlugin::resourceDir)
+                .map(TestPlugin::testPackage)
                 .distinct()
                 .map(PLUGIN_JARS::get)
                 .collect(Collectors.toSet());
@@ -374,11 +405,15 @@ public class TestPlugins {
     }
 
     private static void removeDirectory(Path binDir) throws IOException {
-        List<Path> classFiles = Files.walk(binDir)
-            .sorted(Comparator.reverseOrder())
-            .collect(Collectors.toList());
-        for (Path classFile : classFiles) {
-            if (!Files.deleteIfExists(classFile)) {
+        List<File> classFiles;
+        try (Stream<Path> stream = Files.walk(binDir)) {
+            classFiles = stream
+                    .sorted(Comparator.reverseOrder())
+                    .map(Path::toFile)
+                    .collect(Collectors.toList());
+        }
+        for (File classFile : classFiles) {
+            if (!classFile.delete()) {
                 throw new IOException("Could not delete: " + classFile);
             }
         }
@@ -390,18 +425,21 @@ public class TestPlugins {
      *
      * <p>Dependencies between source files in this directory are resolved 
against one another
      * and the classes present in the test environment.
-     * See https://stackoverflow.com/questions/1563909/ for more information.
+     * See <a href="https://stackoverflow.com/questions/1563909/"/> for more 
information.
      * Additional dependencies in your plugins should be added as test scope 
to :connect:runtime.
      * @param sourceDir Directory containing java source files
      * @throws IOException if the files cannot be compiled
      */
     private static void compileJavaSources(Path sourceDir, Path binDir) throws 
IOException {
         JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
-        List<File> sourceFiles = Files.walk(sourceDir)
-            .filter(Files::isRegularFile)
-            .filter(path -> path.toFile().getName().endsWith(".java"))
-            .map(Path::toFile)
-            .collect(Collectors.toList());
+        List<File> sourceFiles;
+        try (Stream<Path> stream = Files.walk(sourceDir)) {
+            sourceFiles = stream
+                    .filter(Files::isRegularFile)
+                    .map(Path::toFile)
+                    .filter(file -> file.getName().endsWith(".java"))
+                    .collect(Collectors.toList());
+        }
         StringWriter writer = new StringWriter();
         List<String> options = Arrays.asList(
             "-d", binDir.toString() // Write class output to a different 
directory.
@@ -423,11 +461,14 @@ public class TestPlugins {
     }
 
     private static void writeJar(JarOutputStream jar, Path inputDir, 
Predicate<String> removeRuntimeClasses) throws IOException {
-        List<Path> paths = Files.walk(inputDir)
-            .filter(Files::isRegularFile)
-            .filter(path -> !path.toFile().getName().endsWith(".java"))
-            .filter(path -> 
!removeRuntimeClasses.test(path.toFile().getName()))
-            .collect(Collectors.toList());
+        List<Path> paths;
+        try (Stream<Path> stream = Files.walk(inputDir)) {
+            paths = stream
+                    .filter(Files::isRegularFile)
+                    .filter(path -> !path.toFile().getName().endsWith(".java"))
+                    .filter(path -> 
!removeRuntimeClasses.test(path.toFile().getName()))
+                    .collect(Collectors.toList());
+        }
         for (Path path : paths) {
             try (InputStream in = new 
BufferedInputStream(Files.newInputStream(path))) {
                 jar.putNextEntry(new JarEntry(
diff --git 
a/tools/src/test/java/org/apache/kafka/tools/ConnectPluginPathTest.java 
b/tools/src/test/java/org/apache/kafka/tools/ConnectPluginPathTest.java
index 2317bb9e91a..e1696a3c334 100644
--- a/tools/src/test/java/org/apache/kafka/tools/ConnectPluginPathTest.java
+++ b/tools/src/test/java/org/apache/kafka/tools/ConnectPluginPathTest.java
@@ -26,7 +26,6 @@ import 
org.apache.kafka.connect.runtime.isolation.ReflectionScanner;
 import org.apache.kafka.connect.runtime.isolation.ServiceLoaderScanner;
 import org.apache.kafka.connect.runtime.isolation.TestPlugins;
 
-import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.io.TempDir;
 import org.junit.jupiter.params.ParameterizedTest;
@@ -82,13 +81,6 @@ public class ConnectPluginPathTest {
     @TempDir
     public Path workspace;
 
-    @BeforeAll
-    public static void setUp() {
-        // Work around a circular-dependency in TestPlugins.
-        TestPlugins.pluginPath();
-    }
-
-
     @Test
     public void testNoArguments() {
         CommandResult res = runCommand();

Reply via email to