Search in sources :

Example 1 with EventSpyDispatcher

use of org.apache.maven.eventspy.internal.EventSpyDispatcher 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)

Aggregations

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