Search in sources :

Example 1 with ToolchainsBuilder

use of org.apache.maven.toolchain.building.ToolchainsBuilder in project kie-wb-common by kiegroup.

the class AFMavenCli method container.

protected PlexusContainer container(AFCliRequest cliRequest, ClassWorld classWorld) throws Exception {
    if (cliRequest.getClassWorld() == null) {
        /**
         *             The classworld is now Created in the NioMavenCompiler and in the InternalNioDefaultMaven 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
         *             original version:
         *             cliRequest.setClassWorld(new ClassWorld("plexus.core",Thread.currentThread().getContextClassLoader()));
         */
        cliRequest.setClassWorld(classWorld);
    }
    ClassRealm coreRealm = cliRequest.getClassWorld().getClassRealm("plexus.core");
    if (coreRealm == null) {
        coreRealm = cliRequest.getClassWorld().getRealms().iterator().next();
    }
    List<File> extClassPath = parseExtClasspath(cliRequest);
    CoreExtensionEntry coreEntry = CoreExtensionEntry.discoverFrom(coreRealm);
    List<CoreExtensionEntry> extensions = loadCoreExtensions(cliRequest, coreRealm, coreEntry.getExportedArtifacts());
    ClassRealm containerRealm = setupContainerRealm(cliRequest.getClassWorld(), coreRealm, extClassPath, extensions);
    ContainerConfiguration cc = new DefaultContainerConfiguration().setClassWorld(cliRequest.getClassWorld()).setRealm(containerRealm).setClassPathScanning(PlexusConstants.SCANNING_INDEX).setAutoWiring(true).setName("maven");
    Set<String> exportedArtifacts = new HashSet<String>(coreEntry.getExportedArtifacts());
    Set<String> exportedPackages = new HashSet<String>(coreEntry.getExportedPackages());
    for (CoreExtensionEntry extension : extensions) {
        exportedArtifacts.addAll(extension.getExportedArtifacts());
        exportedPackages.addAll(extension.getExportedPackages());
    }
    final CoreExports exports = new CoreExports(containerRealm, exportedArtifacts, exportedPackages);
    DefaultPlexusContainer container = new DefaultPlexusContainer(cc, new AbstractModule() {

        @Override
        protected void configure() {
            bind(ILoggerFactory.class).toInstance(slf4jLoggerFactory);
            bind(CoreExports.class).toInstance(exports);
        }
    });
    // This is used to share informations at runtime between Maven plugins and our compiler
    container.addComponent(cliRequest.getMap(), HashMap.class, "kieMap");
    // NOTE: To avoid inconsistencies, we'll use the TCCL exclusively for lookups
    container.setLookupRealm(null);
    container.setLoggerManager(plexusLoggerManager);
    for (CoreExtensionEntry extension : extensions) {
        container.discoverComponents(extension.getClassRealm());
    }
    customizeContainer(container);
    container.getLoggerManager().setThresholds(cliRequest.getRequest().getLoggingLevel());
    Thread.currentThread().setContextClassLoader(container.getContainerRealm());
    eventSpyDispatcher = container.lookup(EventSpyDispatcher.class);
    DefaultEventSpyContext eventSpyContext = new DefaultEventSpyContext();
    Map<String, Object> data = eventSpyContext.getData();
    data.put("plexus", container);
    data.put("workingDirectory", cliRequest.getWorkingDirectory());
    data.put("systemProperties", cliRequest.getSystemProperties());
    data.put("userProperties", cliRequest.getUserProperties());
    data.put("versionProperties", AFCLIReportingUtils.getBuildProperties());
    eventSpyDispatcher.init(eventSpyContext);
    slf4jLogger = slf4jLoggerFactory.getLogger(this.getClass().getName());
    maven = container.lookup(Maven.class);
    executionRequestPopulator = container.lookup(MavenExecutionRequestPopulator.class);
    modelProcessor = createModelProcessor(container);
    configurationProcessors = container.lookupMap(AFConfigurationProcessor.class);
    toolchainsBuilder = container.lookup(ToolchainsBuilder.class);
    dispatcher = (DefaultSecDispatcher) container.lookup(SecDispatcher.class, "maven");
    return container;
}
Also used : EventSpyDispatcher(org.apache.maven.eventspy.internal.EventSpyDispatcher) Maven(org.apache.maven.Maven) CoreExtensionEntry(org.apache.maven.extension.internal.CoreExtensionEntry) ToolchainsBuilder(org.apache.maven.toolchain.building.ToolchainsBuilder) ContainerConfiguration(org.codehaus.plexus.ContainerConfiguration) DefaultContainerConfiguration(org.codehaus.plexus.DefaultContainerConfiguration) AbstractModule(com.google.inject.AbstractModule) ClassRealm(org.codehaus.plexus.classworlds.realm.ClassRealm) DefaultContainerConfiguration(org.codehaus.plexus.DefaultContainerConfiguration) CoreExports(org.apache.maven.extension.internal.CoreExports) DefaultPlexusContainer(org.codehaus.plexus.DefaultPlexusContainer) DefaultEventSpyContext(org.apache.maven.cli.event.DefaultEventSpyContext) File(java.io.File) HashSet(java.util.HashSet) MavenExecutionRequestPopulator(org.apache.maven.execution.MavenExecutionRequestPopulator)

Example 2 with ToolchainsBuilder

use of org.apache.maven.toolchain.building.ToolchainsBuilder in project kie-wb-common by kiegroup.

the class AFMavenCli method container.

protected PlexusContainer container(AFCliRequest cliRequest, ClassWorld classWorld) throws Exception {
    if (cliRequest.getClassWorld() == null) {
        /**
         *             The classworld is now Created in the NioMavenCompiler and in the InternalNioDefaultMaven 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
         *             original version:
         *             cliRequest.setClassWorld(new ClassWorld("plexus.core",Thread.currentThread().getContextClassLoader()));
         */
        cliRequest.setClassWorld(classWorld);
    }
    ClassRealm coreRealm = cliRequest.getClassWorld().getClassRealm("plexus.core");
    if (coreRealm == null) {
        coreRealm = cliRequest.getClassWorld().getRealms().iterator().next();
    }
    List<File> extClassPath = parseExtClasspath(cliRequest);
    CoreExtensionEntry coreEntry = CoreExtensionEntry.discoverFrom(coreRealm);
    List<CoreExtensionEntry> extensions = loadCoreExtensions(cliRequest, coreRealm, coreEntry.getExportedArtifacts());
    ClassRealm containerRealm = setupContainerRealm(cliRequest.getClassWorld(), coreRealm, extClassPath, extensions);
    ContainerConfiguration cc = new DefaultContainerConfiguration().setClassWorld(cliRequest.getClassWorld()).setRealm(containerRealm).setClassPathScanning(PlexusConstants.SCANNING_INDEX).setAutoWiring(true).setName("maven");
    Set<String> exportedArtifacts = new HashSet<String>(coreEntry.getExportedArtifacts());
    Set<String> exportedPackages = new HashSet<String>(coreEntry.getExportedPackages());
    for (CoreExtensionEntry extension : extensions) {
        exportedArtifacts.addAll(extension.getExportedArtifacts());
        exportedPackages.addAll(extension.getExportedPackages());
    }
    final CoreExports exports = new CoreExports(containerRealm, exportedArtifacts, exportedPackages);
    DefaultPlexusContainer container = new DefaultPlexusContainer(cc, new AbstractModule() {

        @Override
        protected void configure() {
            bind(ILoggerFactory.class).toInstance(slf4jLoggerFactory);
            bind(CoreExports.class).toInstance(exports);
        }
    });
    // This is used to share informations at runtime between Maven plugins and our compiler
    container.addComponent(cliRequest.getMap(), HashMap.class, "kieMap");
    // NOTE: To avoid inconsistencies, we'll use the TCCL exclusively for lookups
    container.setLookupRealm(null);
    container.setLoggerManager(plexusLoggerManager);
    for (CoreExtensionEntry extension : extensions) {
        container.discoverComponents(extension.getClassRealm());
    }
    customizeContainer(container);
    container.getLoggerManager().setThresholds(cliRequest.getRequest().getLoggingLevel());
    Thread.currentThread().setContextClassLoader(container.getContainerRealm());
    eventSpyDispatcher = container.lookup(EventSpyDispatcher.class);
    DefaultEventSpyContext eventSpyContext = new DefaultEventSpyContext();
    Map<String, Object> data = eventSpyContext.getData();
    data.put("plexus", container);
    data.put("workingDirectory", cliRequest.getWorkingDirectory());
    data.put("systemProperties", cliRequest.getSystemProperties());
    data.put("userProperties", cliRequest.getUserProperties());
    data.put("versionProperties", AFCLIReportingUtils.getBuildProperties());
    eventSpyDispatcher.init(eventSpyContext);
    slf4jLogger = slf4jLoggerFactory.getLogger(this.getClass().getName());
    maven = container.lookup(Maven.class);
    executionRequestPopulator = container.lookup(MavenExecutionRequestPopulator.class);
    modelProcessor = createModelProcessor(container);
    configurationProcessors = container.lookupMap(AFConfigurationProcessor.class);
    toolchainsBuilder = container.lookup(ToolchainsBuilder.class);
    dispatcher = (DefaultSecDispatcher) container.lookup(SecDispatcher.class, "maven");
    return container;
}
Also used : EventSpyDispatcher(org.apache.maven.eventspy.internal.EventSpyDispatcher) Maven(org.apache.maven.Maven) CoreExtensionEntry(org.apache.maven.extension.internal.CoreExtensionEntry) ToolchainsBuilder(org.apache.maven.toolchain.building.ToolchainsBuilder) ContainerConfiguration(org.codehaus.plexus.ContainerConfiguration) DefaultContainerConfiguration(org.codehaus.plexus.DefaultContainerConfiguration) AbstractModule(com.google.inject.AbstractModule) ClassRealm(org.codehaus.plexus.classworlds.realm.ClassRealm) DefaultContainerConfiguration(org.codehaus.plexus.DefaultContainerConfiguration) CoreExports(org.apache.maven.extension.internal.CoreExports) DefaultPlexusContainer(org.codehaus.plexus.DefaultPlexusContainer) DefaultEventSpyContext(org.apache.maven.cli.event.DefaultEventSpyContext) File(java.io.File) HashSet(java.util.HashSet) MavenExecutionRequestPopulator(org.apache.maven.execution.MavenExecutionRequestPopulator)

Aggregations

AbstractModule (com.google.inject.AbstractModule)2 File (java.io.File)2 HashSet (java.util.HashSet)2 Maven (org.apache.maven.Maven)2 DefaultEventSpyContext (org.apache.maven.cli.event.DefaultEventSpyContext)2 EventSpyDispatcher (org.apache.maven.eventspy.internal.EventSpyDispatcher)2 MavenExecutionRequestPopulator (org.apache.maven.execution.MavenExecutionRequestPopulator)2 CoreExports (org.apache.maven.extension.internal.CoreExports)2 CoreExtensionEntry (org.apache.maven.extension.internal.CoreExtensionEntry)2 ToolchainsBuilder (org.apache.maven.toolchain.building.ToolchainsBuilder)2 ContainerConfiguration (org.codehaus.plexus.ContainerConfiguration)2 DefaultContainerConfiguration (org.codehaus.plexus.DefaultContainerConfiguration)2 DefaultPlexusContainer (org.codehaus.plexus.DefaultPlexusContainer)2 ClassRealm (org.codehaus.plexus.classworlds.realm.ClassRealm)2