Search in sources :

Example 6 with ClassWorld

use of org.codehaus.plexus.classworlds.ClassWorld in project drools by kiegroup.

the class MavenEmbedderUtils method buildPlexusContainer.

public static PlexusContainer buildPlexusContainer(File mavenHome, MavenRequest mavenRequest) throws MavenEmbedderException {
    ClassWorld world = new ClassWorld("plexus.core", Thread.currentThread().getContextClassLoader());
    ClassRealm classRealm = MavenEmbedderUtils.buildClassRealm(mavenHome, world, Thread.currentThread().getContextClassLoader());
    DefaultContainerConfiguration conf = new DefaultContainerConfiguration();
    conf.setContainerConfigurationURL(mavenRequest.getOverridingComponentsXml()).setRealm(classRealm).setClassWorld(world).setClassPathScanning(mavenRequest.getContainerClassPathScanning()).setComponentVisibility(mavenRequest.getContainerComponentVisibility());
    return buildPlexusContainer(mavenRequest, conf);
}
Also used : ClassRealm(org.codehaus.plexus.classworlds.realm.ClassRealm) DefaultContainerConfiguration(org.codehaus.plexus.DefaultContainerConfiguration) ClassWorld(org.codehaus.plexus.classworlds.ClassWorld)

Example 7 with ClassWorld

use of org.codehaus.plexus.classworlds.ClassWorld in project kie-wb-common by kiegroup.

the class BaseMavenCompiler method compile.

@Override
public T compile(CompilationRequest req) {
    if (!skipLog) {
        MDC.clear();
        MDC.put(MavenConfig.COMPILATION_ID, req.getRequestUUID());
        Thread.currentThread().setName(req.getRequestUUID());
        if (logger.isDebugEnabled()) {
            logger.debug("KieCompilationRequest:{}", req);
        }
    }
    if (!changedPoms) {
        enabler.process(req);
        changedPoms = true;
    }
    req.getKieCliRequest().getRequest().setLocalRepositoryPath(req.getMavenRepo());
    /**
     *         The classworld is now Created in the DefaultMaven compiler for this reasons:
     *         problem: https://stackoverflow.com/questions/22410706/error-when-execute-mavencli-in-the-loop-maven-embedder
     *         problem:https://stackoverflow.com/questions/40587683/invocation-of-mavencli-fails-within-a-maven-plugin
     *         solution:https://dev.eclipse.org/mhonarc/lists/sisu-users/msg00063.html
     */
    ClassLoader original = Thread.currentThread().getContextClassLoader();
    ClassWorld kieClassWorld = new ClassWorld("plexus.core", getClass().getClassLoader());
    int exitCode = cli.doMain(req.getKieCliRequest(), kieClassWorld);
    Thread.currentThread().setContextClassLoader(original);
    if (exitCode == 0) {
        return (T) new DefaultKieCompilationResponse(Boolean.TRUE, req.getRequestUUID());
    } else {
        return (T) new DefaultKieCompilationResponse(Boolean.FALSE, req.getRequestUUID());
    }
}
Also used : ClassWorld(org.codehaus.plexus.classworlds.ClassWorld)

Example 8 with ClassWorld

use of org.codehaus.plexus.classworlds.ClassWorld in project gradle by gradle.

the class AbstractMavenPublishAction method newPlexusContainer.

private PlexusContainer newPlexusContainer(List<File> wagonJars) {
    try {
        ClassWorld world = new ClassWorld("plexus.core", ClassWorld.class.getClassLoader());
        ClassRealm classRealm = new ClassRealm(world, "plexus.core", ClassWorld.class.getClassLoader());
        if (wagonJars != null) {
            for (File jar : wagonJars) {
                classRealm.addURL(jar.toURI().toURL());
            }
        }
        return new DefaultPlexusContainer(new DefaultContainerConfiguration().setRealm(classRealm));
    } catch (PlexusContainerException e) {
        throw UncheckedException.throwAsUncheckedException(e);
    } catch (MalformedURLException e) {
        throw UncheckedException.throwAsUncheckedException(e);
    }
}
Also used : PlexusContainerException(org.codehaus.plexus.PlexusContainerException) ClassRealm(org.codehaus.plexus.classworlds.realm.ClassRealm) MalformedURLException(java.net.MalformedURLException) DefaultPlexusContainer(org.codehaus.plexus.DefaultPlexusContainer) DefaultContainerConfiguration(org.codehaus.plexus.DefaultContainerConfiguration) ClassWorld(org.codehaus.plexus.classworlds.ClassWorld) File(java.io.File)

Example 9 with ClassWorld

use of org.codehaus.plexus.classworlds.ClassWorld in project drools by kiegroup.

the class MavenEmbedderUtils method buildPlexusContainer.

public static PlexusContainer buildPlexusContainer(ClassLoader mavenClassLoader, ClassLoader parent, MavenRequest mavenRequest) throws MavenEmbedderException {
    DefaultContainerConfiguration conf = new DefaultContainerConfiguration();
    conf.setAutoWiring(mavenRequest.isContainerAutoWiring()).setClassPathScanning(mavenRequest.getContainerClassPathScanning()).setComponentVisibility(mavenRequest.getContainerComponentVisibility()).setContainerConfigurationURL(mavenRequest.getOverridingComponentsXml());
    ClassWorld classWorld = new ClassWorld();
    ClassRealm parentRealm = createParentRealm(classWorld, parent, MavenExecutionRequestPopulator.class, RepositorySystem.class, PlexusCipher.class);
    ClassRealm classRealm = createClassRealm(classWorld, "maven", mavenClassLoader);
    classRealm.setParentRealm(parentRealm);
    conf.setRealm(classRealm);
    conf.setClassWorld(classWorld);
    return buildPlexusContainer(mavenRequest, conf);
}
Also used : ClassRealm(org.codehaus.plexus.classworlds.realm.ClassRealm) DefaultContainerConfiguration(org.codehaus.plexus.DefaultContainerConfiguration) ClassWorld(org.codehaus.plexus.classworlds.ClassWorld)

Example 10 with ClassWorld

use of org.codehaus.plexus.classworlds.ClassWorld in project drools by kiegroup.

the class MavenEmbedderUtils method buildClassRealm.

public static ClassRealm buildClassRealm(File mavenHome, ClassWorld world, ClassLoader parentClassLoader) throws MavenEmbedderException {
    if (mavenHome == null) {
        throw new IllegalArgumentException("mavenHome cannot be null");
    }
    if (!mavenHome.exists()) {
        throw new IllegalArgumentException("mavenHome '" + mavenHome.getPath() + "' doesn't seem to exist on this node (or you don't have sufficient rights to access it)");
    }
    File libDirectory = new File(mavenHome, "lib");
    if (!libDirectory.exists()) {
        throw new IllegalArgumentException(mavenHome.getPath() + " doesn't have a 'lib' subdirectory - thus cannot be a valid maven installation!");
    }
    File[] jarFiles = libDirectory.listFiles(new FilenameFilter() {

        public boolean accept(File dir, String name) {
            return name.endsWith(".jar");
        }
    });
    AntClassLoader antClassLoader = new AntClassLoader(Thread.currentThread().getContextClassLoader(), false);
    for (File jarFile : jarFiles) {
        antClassLoader.addPathComponent(jarFile);
    }
    if (world == null) {
        world = new ClassWorld();
    }
    ClassRealm classRealm = createClassRealm(world, "plexus.core", parentClassLoader == null ? antClassLoader : parentClassLoader);
    for (File jarFile : jarFiles) {
        try {
            classRealm.addURL(jarFile.toURI().toURL());
        } catch (MalformedURLException e) {
            throw new MavenEmbedderException(e.getMessage(), e);
        }
    }
    return classRealm;
}
Also used : FilenameFilter(java.io.FilenameFilter) ClassRealm(org.codehaus.plexus.classworlds.realm.ClassRealm) MalformedURLException(java.net.MalformedURLException) AntClassLoader(org.apache.tools.ant.AntClassLoader) ClassWorld(org.codehaus.plexus.classworlds.ClassWorld) File(java.io.File)

Aggregations

ClassWorld (org.codehaus.plexus.classworlds.ClassWorld)15 ClassRealm (org.codehaus.plexus.classworlds.realm.ClassRealm)9 DefaultContainerConfiguration (org.codehaus.plexus.DefaultContainerConfiguration)8 DefaultPlexusContainer (org.codehaus.plexus.DefaultPlexusContainer)6 File (java.io.File)5 ContainerConfiguration (org.codehaus.plexus.ContainerConfiguration)4 PlexusContainerException (org.codehaus.plexus.PlexusContainerException)3 IOException (java.io.IOException)2 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 LinkedHashSet (java.util.LinkedHashSet)2 Properties (java.util.Properties)2 ProjectBuilder (org.apache.maven.project.ProjectBuilder)2 SelfFirstStrategy (org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy)2 Strategy (org.codehaus.plexus.classworlds.strategy.Strategy)2 AbstractModule (com.google.inject.AbstractModule)1 Module (com.google.inject.Module)1 FilenameFilter (java.io.FilenameFilter)1 URLClassLoader (java.net.URLClassLoader)1 ArrayList (java.util.ArrayList)1