All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.slavaz.maven.plugin.postgresql.embedded.classloader.ClassLoaderUtils Maven / Gradle / Ivy

package com.github.slavaz.maven.plugin.postgresql.embedded.classloader;

import org.apache.commons.lang3.Validate;
import org.apache.maven.artifact.Artifact;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.List;

public class ClassLoaderUtils {

    private ClassLoaderUtils() {
    }

    public static ClassLoader buildClassLoader(List artifacts) {
        Validate.notEmpty(artifacts);
        return new URLClassLoader(artifacts.stream()
                .map(Artifact::getFile)
                .map(File::toURI)
                .map(ClassLoaderUtils::uriToURL)
                .toArray(URL[]::new));
    }

    private static URL uriToURL(URI uri) {
        try {
            return uri.toURL();
        } catch (MalformedURLException e) {
            throw new RuntimeException("Malformed URL: " + uri, e);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy