Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make PackageUtils compliant with JPMS #2817

Merged
merged 1 commit into from Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.txt
@@ -1,4 +1,5 @@
Current
Fixed: GITHUB-2308: StringIndexOutOfBoundsException in findClassesInPackage - Surefire/Maven - JDK 11 fails (Krishnan Mahadevan)
Fixed: GITHUB:2788: TestResult.isSuccess() is TRUE when test fails due to expectedExceptions (Krishnan Mahadevan)
Fixed: GITHUB-2800: Running Test Classes with Inherited @Factory and @DataProvider Annotated Non-Static Methods Fail (Krishnan Mahadevan)
New: Ability to provide custom error message for assertThrows\expectThrows methods (Anatolii Yuzhakov)
Expand Down
@@ -1,8 +1,9 @@
package org.testng.internal;

import static java.nio.charset.StandardCharsets.UTF_8;

import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Method;
import java.net.JarURLConnection;
import java.net.URL;
Expand All @@ -25,7 +26,6 @@
* @author <a href="mailto:cedric@beust.com">Cedric Beust</a>
*/
public class PackageUtils {
private static final String UTF_8 = "UTF-8";
private static final String PACKAGE_UTILS = PackageUtils.class.getSimpleName();
private static String[] testClassPaths;

Expand All @@ -36,11 +36,6 @@ private PackageUtils() {
// Utility class. Defeat instantiation.
}

/** Add a class loader to the searchable loaders. */
public static void addClassLoader(final ClassLoader loader) {
classLoaders.add(loader);
}

/**
* @param packageName - The package name
* @param included - The inclusion list.
Expand Down Expand Up @@ -96,6 +91,9 @@ public static String[] findClassesInPackage(
while (entries.hasMoreElements()) {
JarEntry entry = entries.nextElement();
String name = entry.getName();
if (name.startsWith("module-info") || name.startsWith("META-INF")) {
continue;
}
if (name.charAt(0) == '/') {
name = name.substring(1);
}
Expand Down Expand Up @@ -183,11 +181,7 @@ private static boolean matchTestClasspath(URL url, String lastFragment, boolean
}

String fileName = "";
try {
fileName = URLDecoder.decode(url.getFile(), UTF_8);
} catch (UnsupportedEncodingException ueex) {
// ignore. should never happen
}
fileName = URLDecoder.decode(url.getFile(), UTF_8);

for (String classpathFrag : classpathFragments) {
String path = classpathFrag + lastFragment;
Expand Down