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