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

Go to download

This is a Maven plugin for running an embedded PostgreSQL server, mostly for integration tests.

The newest version!
package com.github.slavaz.maven.plugin.postgresql.embedded.classloader;

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

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() {
    	// a static util class
    }

    public static ClassLoader buildClassLoader(List artifacts) {
        Validate.notEmpty(artifacts);
        URL[] urls = artifacts.stream()
            .map(artifact -> artifact.getFile())
            .map(file -> file.toURI())
            .map(uri -> uriToURL(uri))
            .toArray(size -> new URL[size]);
        return new URLClassLoader(urls);
    }

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




© 2015 - 2025 Weber Informatics LLC | Privacy Policy