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

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

Introduction

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

Prototype

ClassRealm getMavenApiRealm();

Source Link

Document

Gets the class realm exposing the Maven API.

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()));
    }/*www.  j  ava 2 s  . 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;
}