Search in sources :

Example 1 with CoreExtensionEntry

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;
}
Also used : ClassRealm(org.codehaus.plexus.classworlds.realm.ClassRealm) CoreExtensionEntry(org.apache.maven.extension.internal.CoreExtensionEntry) File(java.io.File)

Example 2 with CoreExtensionEntry

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;
}
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 3 with CoreExtensionEntry

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;
}
Also used : ClassRealm(org.codehaus.plexus.classworlds.realm.ClassRealm) CoreExtensionEntry(org.apache.maven.extension.internal.CoreExtensionEntry) File(java.io.File)

Example 4 with CoreExtensionEntry

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;
}
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 5 with CoreExtensionEntry

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

CoreExtensionEntry (org.apache.maven.extension.internal.CoreExtensionEntry)7 ClassRealm (org.codehaus.plexus.classworlds.realm.ClassRealm)7 File (java.io.File)6 AbstractModule (com.google.inject.AbstractModule)4 CoreExports (org.apache.maven.extension.internal.CoreExports)4 ContainerConfiguration (org.codehaus.plexus.ContainerConfiguration)4 DefaultContainerConfiguration (org.codehaus.plexus.DefaultContainerConfiguration)4 DefaultPlexusContainer (org.codehaus.plexus.DefaultPlexusContainer)4 HashSet (java.util.HashSet)3 Maven (org.apache.maven.Maven)3 DefaultEventSpyContext (org.apache.maven.cli.event.DefaultEventSpyContext)3 EventSpyDispatcher (org.apache.maven.eventspy.internal.EventSpyDispatcher)3 MavenExecutionRequestPopulator (org.apache.maven.execution.MavenExecutionRequestPopulator)3 ToolchainsBuilder (org.apache.maven.toolchain.building.ToolchainsBuilder)3 Module (com.google.inject.Module)1 PlexusContainerException (org.codehaus.plexus.PlexusContainerException)1 ClassWorld (org.codehaus.plexus.classworlds.ClassWorld)1 NoSuchRealmException (org.codehaus.plexus.classworlds.realm.NoSuchRealmException)1 ILoggerFactory (org.slf4j.ILoggerFactory)1