Example usage for org.apache.maven.classrealm ClassRealmManager getCoreRealm

List of usage examples for org.apache.maven.classrealm ClassRealmManager getCoreRealm

Introduction

In this page you can find the example usage for org.apache.maven.classrealm ClassRealmManager getCoreRealm.

Prototype

ClassRealm getCoreRealm();

Source Link

Document

Gets the class realm hosting the Maven core.

Usage

From source file:org.jboss.shrinkwrap.resolver.plugin.DependencyTreeMojo.java

License:Apache License

private ClassLoader getCombinedClassLoader(ClassRealmManager manager) {

    List<URL> urlList = new ArrayList<URL>();

    // add thread classpath
    ClassLoader threadCL = SecurityActions.getThreadContextClassLoader();
    if (threadCL instanceof URLClassLoader) {
        urlList.addAll(Arrays.asList(((URLClassLoader) threadCL).getURLs()));
    }//from w  ww .j a  v  a  2s  .  com

    // add maven core libraries
    ClassRealm core = manager.getCoreRealm();
    if (core != null) {
        urlList.addAll(Arrays.asList(core.getURLs()));
    }

    ClassRealm mavenApi = manager.getMavenApiRealm();
    if (mavenApi != null) {
        urlList.addAll(Arrays.asList(mavenApi.getURLs()));
    }

    // we need to keep threadCL as parent, otherwise we'll get ClassCastException in runtime
    URLClassLoader cl = new URLClassLoader(urlList.toArray(new URL[0]), threadCL);

    // for (URL u : cl.getURLs()) {
    // System.out.println("CLR: " + u);
    // }

    return cl;
}