Move ReflectionScanningHelper -> ClasspathAccess

This commit is contained in:
JeremyStar™ 2024-07-16 14:52:19 +02:00
parent 97dcc5263b
commit 050befbb73
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D

View file

@ -17,10 +17,12 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.staropensource.sosengine.base.internal.reflection;
package de.staropensource.sosengine.base.reflection;
import de.staropensource.sosengine.base.logging.Logger;
import de.staropensource.sosengine.base.types.CodePart;
import de.staropensource.sosengine.base.types.logging.LogIssuer;
import org.jetbrains.annotations.NotNull;
import org.reflections.Reflections;
import java.io.File;
import java.net.URL;
@ -30,7 +32,7 @@ import java.util.LinkedHashMap;
import java.util.Map;
/**
* Helps in scanning the class path.
* Allows getting the classpath as {@link URL}s.
* <p>
* This entire class has been stolen from
* <a href="https://github.com/ronmamo/reflections">the Reflections library</a>.
@ -39,9 +41,9 @@ import java.util.Map;
* @since v1-alpha2
*/
@SuppressWarnings({ "unused" })
public class ReflectionScanningHelper {
public final class ClasspathAccess {
/**
* Returns the classpath as URLs.
* Returns the classpath as a collection of {@link URL}s.
*
* @return collection of classpath urls
* @since v1-alpha2
@ -50,17 +52,15 @@ public class ReflectionScanningHelper {
public static Collection<URL> getClasspathURLs() {
Collection<URL> urls = new ArrayList<>();
String javaClassPath = System.getProperty("java.class.path");
if (javaClassPath != null) {
for (String path : javaClassPath.split(File.pathSeparator)) {
if (javaClassPath != null)
for (String path : javaClassPath.split(File.pathSeparator))
try {
urls.add(new File(path).toURI().toURL());
} catch (Exception e) {
if (Reflections.log != null) {
Reflections.log.warn("Could not get URL", e);
}
}
}
} catch (Exception exception) {
Logger.crash(new LogIssuer(ClasspathAccess.class, CodePart.ENGINE), "Failed converting classpath to URL", exception);
}
return fixURLs(urls);
}
@ -74,7 +74,7 @@ public class ReflectionScanningHelper {
* @since v1-alpha2
*/
@NotNull
public static Collection<URL> fixURLs(@NotNull Collection<URL> urls) {
private static Collection<URL> fixURLs(@NotNull Collection<URL> urls) {
Map<String, URL> distinct = new LinkedHashMap<>(urls.size());
for (URL url : urls) {
distinct.put(url.toExternalForm(), url);