use of org.apache.maven.extension.internal.CoreExtensionEntry in project kie-wb-common by kiegroup.
the class AFMavenCli method setupContainerRealm.
protected ClassRealm setupContainerRealm(ClassWorld classWorld, ClassRealm coreRealm, List<File> extClassPath, List<CoreExtensionEntry> extensions) throws Exception {
if (!extClassPath.isEmpty() || !extensions.isEmpty()) {
ClassRealm extRealm = classWorld.newRealm("maven.ext", null);
extRealm.setParentRealm(coreRealm);
slf4jLogger.debug("Populating class realm " + extRealm.getId());
for (File file : extClassPath) {
slf4jLogger.debug(" Included " + file);
extRealm.addURL(file.toURI().toURL());
}
for (CoreExtensionEntry entry : reverse(extensions)) {
Set<String> exportedPackages = entry.getExportedPackages();
ClassRealm realm = entry.getClassRealm();
for (String exportedPackage : exportedPackages) {
extRealm.importFrom(realm, exportedPackage);
}
if (exportedPackages.isEmpty()) {
// sisu uses realm imports to establish component visibility
extRealm.importFrom(realm, realm.getId());
}
}
return extRealm;
}
return coreRealm;
}
use of org.apache.maven.extension.internal.CoreExtensionEntry 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;
}
use of org.apache.maven.extension.internal.CoreExtensionEntry in project kie-wb-common by kiegroup.
the class ReusableAFMavenCli method setupContainerRealm.
protected ClassRealm setupContainerRealm(ClassWorld classWorld, ClassRealm coreRealm, List<File> extClassPath, List<CoreExtensionEntry> extensions) throws Exception {
if (!extClassPath.isEmpty() || !extensions.isEmpty()) {
ClassRealm extRealm = classWorld.newRealm("maven.ext", null);
extRealm.setParentRealm(coreRealm);
reusableSlf4jLogger.debug("Populating class realm " + extRealm.getId());
for (File file : extClassPath) {
reusableSlf4jLogger.debug(" Included " + file);
extRealm.addURL(file.toURI().toURL());
}
for (CoreExtensionEntry entry : reverse(extensions)) {
Set<String> exportedPackages = entry.getExportedPackages();
ClassRealm realm = entry.getClassRealm();
for (String exportedPackage : exportedPackages) {
extRealm.importFrom(realm, exportedPackage);
}
if (exportedPackages.isEmpty()) {
// sisu uses realm imports to establish component visibility
extRealm.importFrom(realm, realm.getId());
}
}
return extRealm;
}
return coreRealm;
}
use of org.apache.maven.extension.internal.CoreExtensionEntry in project kie-wb-common by kiegroup.
the class ReusableAFMavenCli method createNewPlexusContainer.
private DefaultPlexusContainer createNewPlexusContainer(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);
reusableEventSpyDispatcher = container.lookup(EventSpyDispatcher.class);
reusableEventSpyContext = new DefaultEventSpyContext();
setEventSpyContextData(reusableEventSpyContext, container, cliRequest);
reusableEventSpyDispatcher.init(reusableEventSpyContext);
reusableSlf4jLogger = slf4jLoggerFactory.getLogger(this.getClass().getName());
reusableMaven = container.lookup(Maven.class);
reusableExecutionRequestPopulator = container.lookup(MavenExecutionRequestPopulator.class);
reusableModelProcessor = createModelProcessor(container);
reusableConfigurationProcessors = container.lookupMap(AFConfigurationProcessor.class);
reusableToolchainsBuilder = container.lookup(ToolchainsBuilder.class);
reusableDispatcher = (DefaultSecDispatcher) container.lookup(SecDispatcher.class, "maven");
return container;
}
use of org.apache.maven.extension.internal.CoreExtensionEntry 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;
}
Aggregations