Search in sources :

Example 1 with ClassWorld

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;
}
Also used : DefaultLocalRepositoryProvider(org.eclipse.aether.internal.impl.DefaultLocalRepositoryProvider) DefaultRepositorySystem(org.eclipse.aether.internal.impl.DefaultRepositorySystem) ClassWorld(org.codehaus.plexus.classworlds.ClassWorld) SettingsBuildingException(org.apache.maven.settings.building.SettingsBuildingException) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) InvalidRepositoryException(org.apache.maven.artifact.InvalidRepositoryException) IOException(java.io.IOException) DefaultRepositorySystem(org.eclipse.aether.internal.impl.DefaultRepositorySystem) RepositorySystem(org.apache.maven.repository.RepositorySystem) LocalRepositoryManagerFactory(org.eclipse.aether.spi.localrepo.LocalRepositoryManagerFactory) DefaultLocalRepositoryProvider(org.eclipse.aether.internal.impl.DefaultLocalRepositoryProvider) LocalRepositoryProvider(org.eclipse.aether.impl.LocalRepositoryProvider) RuntimeInformation(org.apache.maven.rtinfo.RuntimeInformation)

Example 2 with ClassWorld

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) RepositorySystemSession(org.sonatype.aether.RepositorySystemSession) DefaultRepositorySystemSession(org.sonatype.aether.util.DefaultRepositorySystemSession) ClassWorld(org.codehaus.plexus.classworlds.ClassWorld) Properties(java.util.Properties) SystemProperties(org.gradle.internal.SystemProperties) DefaultContainerConfiguration(org.codehaus.plexus.DefaultContainerConfiguration) ContainerConfiguration(org.codehaus.plexus.ContainerConfiguration) DefaultContainerConfiguration(org.codehaus.plexus.DefaultContainerConfiguration) DefaultPlexusContainer(org.codehaus.plexus.DefaultPlexusContainer) DefaultRepositorySystemSession(org.sonatype.aether.util.DefaultRepositorySystemSession)

Example 3 with ClassWorld

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);
    }
}
Also used : ProcessedPoms(org.kie.workbench.common.services.backend.compiler.impl.ProcessedPoms) ClassWorld(org.codehaus.plexus.classworlds.ClassWorld)

Example 4 with ClassWorld

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);
    }
}
Also used : PlexusContainerException(org.codehaus.plexus.PlexusContainerException) ClassRealm(org.codehaus.plexus.classworlds.realm.ClassRealm) DefaultContainerConfiguration(org.codehaus.plexus.DefaultContainerConfiguration) DefaultPlexusContainer(org.codehaus.plexus.DefaultPlexusContainer) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) ClassWorld(org.codehaus.plexus.classworlds.ClassWorld) URL(java.net.URL) PostConstruct(javax.annotation.PostConstruct)

Example 5 with ClassWorld

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;
}
Also used : ClassRealm(org.codehaus.plexus.classworlds.realm.ClassRealm) SelfFirstStrategy(org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy) SelfFirstStrategy(org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy) Strategy(org.codehaus.plexus.classworlds.strategy.Strategy) 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