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);
}
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());
}
}
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);
}
}
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);
}
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;
}
Aggregations