use of org.codehaus.plexus.classworlds.ClassWorld in project intellij-plugins by JetBrains.
the class GeneratorServer method createPlexusContainer.
private static DefaultPlexusContainer createPlexusContainer() throws PlexusContainerException, ComponentLookupException {
ContainerConfiguration containerConfiguration = new DefaultContainerConfiguration().setClassPathScanning(PlexusConstants.SCANNING_INDEX).setAutoWiring(true).setClassWorld(new ClassWorld("plexus.core", Thread.currentThread().getContextClassLoader())).setName("maven");
final DefaultPlexusContainer container = new DefaultPlexusContainer(containerConfiguration);
final List<LocalRepositoryManagerFactory> factoryList = Collections.singletonList(container.lookup(LocalRepositoryManagerFactory.class, "simple"));
final String mavenVersion = container.lookup(RuntimeInformation.class).getMavenVersion();
// tracked impl is not suitable for us (our list of remote repo may be not equals - we don't want think about it)
if (mavenVersion.length() >= 5 && mavenVersion.charAt(2) == '0' && mavenVersion.charAt(4) < '4') {
final DefaultRepositorySystem repositorySystem = (DefaultRepositorySystem) container.lookup(RepositorySystem.class);
try {
repositorySystem.getClass().getMethod("setLocalRepositoryManagerFactories", List.class).invoke(repositorySystem, factoryList);
} catch (Exception e) {
container.getLoggerManager().getLoggerForComponent(null).warn("", e);
}
} else {
((DefaultLocalRepositoryProvider) container.lookup(LocalRepositoryProvider.class)).setLocalRepositoryManagerFactories(factoryList);
}
return container;
}
use of org.codehaus.plexus.classworlds.ClassWorld in project gradle by gradle.
the class MavenProjectsCreator method createNow.
private Set<MavenProject> createNow(Settings settings, File pomFile) throws PlexusContainerException, PlexusConfigurationException, ComponentLookupException, MavenExecutionRequestPopulationException, ProjectBuildingException {
ContainerConfiguration containerConfiguration = new DefaultContainerConfiguration().setClassWorld(new ClassWorld("plexus.core", ClassWorld.class.getClassLoader())).setName("mavenCore");
DefaultPlexusContainer container = new DefaultPlexusContainer(containerConfiguration);
ProjectBuilder builder = container.lookup(ProjectBuilder.class);
MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest();
final Properties properties = new Properties();
properties.putAll(SystemProperties.getInstance().asMap());
executionRequest.setSystemProperties(properties);
MavenExecutionRequestPopulator populator = container.lookup(MavenExecutionRequestPopulator.class);
populator.populateFromSettings(executionRequest, settings);
populator.populateDefaults(executionRequest);
ProjectBuildingRequest buildingRequest = executionRequest.getProjectBuildingRequest();
buildingRequest.setProcessPlugins(false);
MavenProject mavenProject = builder.build(pomFile, buildingRequest).getProject();
Set<MavenProject> reactorProjects = new LinkedHashSet<MavenProject>();
// TODO adding the parent project first because the converter needs it this way ATM. This is oversimplified.
// the converter should not depend on the order of reactor projects.
// we should add coverage for nested multi-project builds with multiple parents.
reactorProjects.add(mavenProject);
List<ProjectBuildingResult> allProjects = builder.build(ImmutableList.of(pomFile), true, buildingRequest);
CollectionUtils.collect(allProjects, reactorProjects, new Transformer<MavenProject, ProjectBuildingResult>() {
public MavenProject transform(ProjectBuildingResult original) {
return original.getProject();
}
});
MavenExecutionResult result = new DefaultMavenExecutionResult();
result.setProject(mavenProject);
RepositorySystemSession repoSession = new DefaultRepositorySystemSession();
MavenSession session = new MavenSession(container, repoSession, executionRequest, result);
session.setCurrentProject(mavenProject);
return reactorProjects;
}
use of org.codehaus.plexus.classworlds.ClassWorld in project kie-wb-common by kiegroup.
the class BaseMavenCompiler method compileSync.
@Override
public T compileSync(CompilationRequest req) {
if (logger.isDebugEnabled()) {
logger.debug("KieCompilationRequest:{}", req);
}
if (!req.getInfo().getEnhancedMainPomFile().isPresent()) {
ProcessedPoms processedPoms = enabler.process(req);
if (!processedPoms.getResult()) {
return buildDefaultCompilationResponse(Boolean.FALSE, "Processing poms failed", Collections.emptyList());
}
}
req.getKieCliRequest().getRequest().setLocalRepositoryPath(req.getMavenRepo());
/**
* The classworld is now Created in the NioMavenCompiler and in the DefaultMaven compielr 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) buildDefaultCompilationResponse(Boolean.TRUE);
} else {
return (T) buildDefaultCompilationResponse(Boolean.FALSE);
}
}
use of org.codehaus.plexus.classworlds.ClassWorld in project archiva by apache.
the class PlexusSisuBridge method initialize.
@PostConstruct
public void initialize() throws PlexusSisuBridgeException {
DefaultContainerConfiguration conf = new DefaultContainerConfiguration();
conf.setAutoWiring(containerAutoWiring);
conf.setClassPathScanning(containerClassPathScanning);
conf.setComponentVisibility(containerComponentVisibility);
conf.setContainerConfigurationURL(overridingComponentsXml);
ClassWorld classWorld = new ClassWorld();
ClassLoader tccl = Thread.currentThread().getContextClassLoader();
containerRealm = new ClassRealm(classWorld, "maven", tccl);
if (tccl instanceof URLClassLoader) {
URL[] urls = ((URLClassLoader) tccl).getURLs();
for (URL url : urls) {
containerRealm.addURL(url);
}
}
conf.setRealm(containerRealm);
// conf.setClassWorld( classWorld );
ClassLoader ori = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(containerRealm);
plexusContainer = new DefaultPlexusContainer(conf);
} catch (PlexusContainerException e) {
throw new PlexusSisuBridgeException(e.getMessage(), e);
} finally {
Thread.currentThread().setContextClassLoader(ori);
}
}
use of org.codehaus.plexus.classworlds.ClassWorld in project scala-maven-plugin by davidB.
the class ScalaScriptMojo method createScriptClassloader.
private URLClassLoader createScriptClassloader(File scriptDir, Set<String> classpath) throws Exception {
ClassWorld w = new ClassWorld("zero", null);
w.newRealm("mojo", getClass().getClassLoader());
Strategy s = new SelfFirstStrategy(w.newRealm("scalaScript", null));
ClassRealm rScript = s.getRealm();
rScript.setParentClassLoader(getClass().getClassLoader());
// rScript.importFrom("mojo", MavenProject.class.getPackage().getName());
// rScript.importFrom("mojo", MavenSession.class.getPackage().getName());
// rScript.importFrom("mojo", Log.class.getPackage().getName());
rScript.importFrom("mojo", "org.apache.maven");
// add the script directory to the classpath
rScript.addURL(scriptDir.toURI().toURL());
for (String string : classpath) {
rScript.addURL(new File(string).toURI().toURL());
}
return rScript;
}
Aggregations