Search in sources :

Example 1 with BootstrapCoreExtensionManager

use of org.apache.maven.cli.internal.BootstrapCoreExtensionManager in project kie-wb-common by kiegroup.

the class AFMavenCli method loadCoreExtensions.

protected List<CoreExtensionEntry> loadCoreExtensions(AFCliRequest cliRequest, ClassRealm containerRealm, Set<String> providedArtifacts) {
    if (cliRequest.getMultiModuleProjectDirectory() == null) {
        return Collections.emptyList();
    }
    Path extensionsFile = Paths.get(cliRequest.getMultiModuleProjectDirectory().toString(), EXTENSIONS_FILENAME);
    if (!java.nio.file.Files.isRegularFile(extensionsFile)) {
        return Collections.emptyList();
    }
    try {
        List<CoreExtension> extensions = readCoreExtensionsDescriptor(extensionsFile);
        if (extensions.isEmpty()) {
            return Collections.emptyList();
        }
        ContainerConfiguration cc = // 
        new DefaultContainerConfiguration().setClassWorld(// 
        cliRequest.getClassWorld()).setRealm(// 
        containerRealm).setClassPathScanning(// 
        PlexusConstants.SCANNING_INDEX).setAutoWiring(// 
        true).setName("maven");
        DefaultPlexusContainer container = new DefaultPlexusContainer(cc, new AbstractModule() {

            @Override
            protected void configure() {
                bind(ILoggerFactory.class).toInstance(slf4jLoggerFactory);
            }
        });
        try {
            container.setLookupRealm(null);
            container.setLoggerManager(plexusLoggerManager);
            container.getLoggerManager().setThresholds(cliRequest.getRequest().getLoggingLevel());
            Thread.currentThread().setContextClassLoader(container.getContainerRealm());
            executionRequestPopulator = container.lookup(MavenExecutionRequestPopulator.class);
            configurationProcessors = container.lookupMap(AFConfigurationProcessor.class);
            configure(cliRequest);
            MavenExecutionRequest request = DefaultMavenExecutionRequest.copy(cliRequest.getRequest());
            request = populateRequest(cliRequest, request);
            request = executionRequestPopulator.populateDefaults(request);
            BootstrapCoreExtensionManager resolver = container.lookup(BootstrapCoreExtensionManager.class);
            return resolver.loadCoreExtensions(request, providedArtifacts, extensions);
        } finally {
            executionRequestPopulator = null;
            container.dispose();
        }
    } catch (RuntimeException e) {
        // runtime exceptions are most likely bugs in maven, let them bubble up to the user
        throw e;
    } catch (Exception e) {
        slf4jLogger.warn("Failed to read extensions descriptor " + extensionsFile + ": " + e.getMessage());
    }
    return Collections.emptyList();
}
Also used : Path(java.nio.file.Path) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) ContainerConfiguration(org.codehaus.plexus.ContainerConfiguration) DefaultContainerConfiguration(org.codehaus.plexus.DefaultContainerConfiguration) LifecycleExecutionException(org.apache.maven.lifecycle.LifecycleExecutionException) InternalErrorException(org.apache.maven.InternalErrorException) UnrecognizedOptionException(org.apache.commons.cli.UnrecognizedOptionException) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) FileNotFoundException(java.io.FileNotFoundException) ParseException(org.apache.commons.cli.ParseException) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) IOException(java.io.IOException) MavenExecutionRequestPopulationException(org.apache.maven.execution.MavenExecutionRequestPopulationException) AbstractModule(com.google.inject.AbstractModule) CoreExtension(org.apache.maven.cli.internal.extension.model.CoreExtension) DefaultContainerConfiguration(org.codehaus.plexus.DefaultContainerConfiguration) DefaultPlexusContainer(org.codehaus.plexus.DefaultPlexusContainer) BootstrapCoreExtensionManager(org.apache.maven.cli.internal.BootstrapCoreExtensionManager) MavenExecutionRequestPopulator(org.apache.maven.execution.MavenExecutionRequestPopulator)

Example 2 with BootstrapCoreExtensionManager

use of org.apache.maven.cli.internal.BootstrapCoreExtensionManager in project kie-wb-common by kiegroup.

the class AFMavenCli method loadCoreExtensions.

protected List<CoreExtensionEntry> loadCoreExtensions(AFCliRequest cliRequest, ClassRealm containerRealm, Set<String> providedArtifacts) {
    if (cliRequest.getMultiModuleProjectDirectory() == null) {
        return Collections.emptyList();
    }
    Path extensionsFile = Paths.get(cliRequest.getMultiModuleProjectDirectory().toString(), EXTENSIONS_FILENAME);
    if (!java.nio.file.Files.isRegularFile(extensionsFile)) {
        return Collections.emptyList();
    }
    try {
        List<CoreExtension> extensions = readCoreExtensionsDescriptor(extensionsFile);
        if (extensions.isEmpty()) {
            return Collections.emptyList();
        }
        ContainerConfiguration cc = // 
        new DefaultContainerConfiguration().setClassWorld(// 
        cliRequest.getClassWorld()).setRealm(// 
        containerRealm).setClassPathScanning(// 
        PlexusConstants.SCANNING_INDEX).setAutoWiring(// 
        true).setName("maven");
        DefaultPlexusContainer container = new DefaultPlexusContainer(cc, new AbstractModule() {

            @Override
            protected void configure() {
                bind(ILoggerFactory.class).toInstance(slf4jLoggerFactory);
            }
        });
        try {
            container.setLookupRealm(null);
            container.setLoggerManager(plexusLoggerManager);
            container.getLoggerManager().setThresholds(cliRequest.getRequest().getLoggingLevel());
            Thread.currentThread().setContextClassLoader(container.getContainerRealm());
            executionRequestPopulator = container.lookup(MavenExecutionRequestPopulator.class);
            configurationProcessors = container.lookupMap(AFConfigurationProcessor.class);
            configure(cliRequest);
            MavenExecutionRequest request = DefaultMavenExecutionRequest.copy(cliRequest.getRequest());
            request = populateRequest(cliRequest, request);
            request = executionRequestPopulator.populateDefaults(request);
            BootstrapCoreExtensionManager resolver = container.lookup(BootstrapCoreExtensionManager.class);
            return resolver.loadCoreExtensions(request, providedArtifacts, extensions);
        } finally {
            executionRequestPopulator = null;
            container.dispose();
        }
    } catch (RuntimeException e) {
        // runtime exceptions are most likely bugs in maven, let them bubble up to the user
        throw e;
    } catch (Exception e) {
        slf4jLogger.warn("Failed to read extensions descriptor " + extensionsFile + ": " + e.getMessage());
    }
    return Collections.emptyList();
}
Also used : Path(java.nio.file.Path) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) ContainerConfiguration(org.codehaus.plexus.ContainerConfiguration) DefaultContainerConfiguration(org.codehaus.plexus.DefaultContainerConfiguration) LifecycleExecutionException(org.apache.maven.lifecycle.LifecycleExecutionException) InternalErrorException(org.apache.maven.InternalErrorException) UnrecognizedOptionException(org.apache.commons.cli.UnrecognizedOptionException) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) FileNotFoundException(java.io.FileNotFoundException) ParseException(org.apache.commons.cli.ParseException) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) IOException(java.io.IOException) MavenExecutionRequestPopulationException(org.apache.maven.execution.MavenExecutionRequestPopulationException) AbstractModule(com.google.inject.AbstractModule) CoreExtension(org.apache.maven.cli.internal.extension.model.CoreExtension) DefaultContainerConfiguration(org.codehaus.plexus.DefaultContainerConfiguration) DefaultPlexusContainer(org.codehaus.plexus.DefaultPlexusContainer) BootstrapCoreExtensionManager(org.apache.maven.cli.internal.BootstrapCoreExtensionManager) MavenExecutionRequestPopulator(org.apache.maven.execution.MavenExecutionRequestPopulator)

Example 3 with BootstrapCoreExtensionManager

use of org.apache.maven.cli.internal.BootstrapCoreExtensionManager in project kie-wb-common by kiegroup.

the class ReusableAFMavenCli method loadCoreExtensions.

protected List<CoreExtensionEntry> loadCoreExtensions(AFCliRequest cliRequest, ClassRealm containerRealm, Set<String> providedArtifacts) {
    if (cliRequest.getMultiModuleProjectDirectory() == null) {
        return Collections.emptyList();
    }
    Path extensionsFile = Paths.get(cliRequest.getMultiModuleProjectDirectory().toString(), EXTENSIONS_FILENAME);
    if (!java.nio.file.Files.isRegularFile(extensionsFile)) {
        return Collections.emptyList();
    }
    try {
        List<CoreExtension> extensions = readCoreExtensionsDescriptor(extensionsFile);
        if (extensions.isEmpty()) {
            return Collections.emptyList();
        }
        ContainerConfiguration cc = // 
        new DefaultContainerConfiguration().setClassWorld(// 
        cliRequest.getClassWorld()).setRealm(// 
        containerRealm).setClassPathScanning(// 
        PlexusConstants.SCANNING_INDEX).setAutoWiring(// 
        true).setName("maven");
        if (reusableContainerCoreExtensions == null) {
            reusableContainerCoreExtensions = new DefaultPlexusContainer(cc, new AbstractModule() {

                @Override
                protected void configure() {
                    bind(ILoggerFactory.class).toInstance(slf4jLoggerFactory);
                }
            });
        }
        try {
            reusableContainerCoreExtensions.setLookupRealm(null);
            ((DefaultPlexusContainer) reusableContainerCoreExtensions).setLoggerManager(plexusLoggerManager);
            ((DefaultPlexusContainer) reusableContainerCoreExtensions).getLoggerManager().setThresholds(cliRequest.getRequest().getLoggingLevel());
            Thread.currentThread().setContextClassLoader(reusableContainerCoreExtensions.getContainerRealm());
            reusableExecutionRequestPopulator = reusableContainerCoreExtensions.lookup(MavenExecutionRequestPopulator.class);
            reusableConfigurationProcessors = reusableContainerCoreExtensions.lookupMap(AFConfigurationProcessor.class);
            configure(cliRequest);
            MavenExecutionRequest request = DefaultMavenExecutionRequest.copy(cliRequest.getRequest());
            request = populateRequest(cliRequest, request);
            request = reusableExecutionRequestPopulator.populateDefaults(request);
            BootstrapCoreExtensionManager resolver = reusableContainerCoreExtensions.lookup(BootstrapCoreExtensionManager.class);
            reusableExtensions = resolver.loadCoreExtensions(request, providedArtifacts, extensions);
            return reusableExtensions;
        } finally {
            reusableExecutionRequestPopulator = null;
        }
    } catch (RuntimeException e) {
        // runtime exceptions are most likely bugs in maven, let them bubble up to the user
        throw e;
    } catch (Exception e) {
        reusableSlf4jLogger.warn("Failed to read extensions descriptor " + extensionsFile + ": " + e.getMessage());
    }
    return Collections.emptyList();
}
Also used : Path(java.nio.file.Path) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) ContainerConfiguration(org.codehaus.plexus.ContainerConfiguration) DefaultContainerConfiguration(org.codehaus.plexus.DefaultContainerConfiguration) LifecycleExecutionException(org.apache.maven.lifecycle.LifecycleExecutionException) InternalErrorException(org.apache.maven.InternalErrorException) UnrecognizedOptionException(org.apache.commons.cli.UnrecognizedOptionException) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) FileNotFoundException(java.io.FileNotFoundException) ParseException(org.apache.commons.cli.ParseException) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) IOException(java.io.IOException) MavenExecutionRequestPopulationException(org.apache.maven.execution.MavenExecutionRequestPopulationException) AbstractModule(com.google.inject.AbstractModule) CoreExtension(org.apache.maven.cli.internal.extension.model.CoreExtension) DefaultContainerConfiguration(org.codehaus.plexus.DefaultContainerConfiguration) DefaultPlexusContainer(org.codehaus.plexus.DefaultPlexusContainer) ILoggerFactory(org.slf4j.ILoggerFactory) BootstrapCoreExtensionManager(org.apache.maven.cli.internal.BootstrapCoreExtensionManager) MavenExecutionRequestPopulator(org.apache.maven.execution.MavenExecutionRequestPopulator)

Aggregations

AbstractModule (com.google.inject.AbstractModule)3 FileNotFoundException (java.io.FileNotFoundException)3 IOException (java.io.IOException)3 Path (java.nio.file.Path)3 ParseException (org.apache.commons.cli.ParseException)3 UnrecognizedOptionException (org.apache.commons.cli.UnrecognizedOptionException)3 InternalErrorException (org.apache.maven.InternalErrorException)3 BootstrapCoreExtensionManager (org.apache.maven.cli.internal.BootstrapCoreExtensionManager)3 CoreExtension (org.apache.maven.cli.internal.extension.model.CoreExtension)3 DefaultMavenExecutionRequest (org.apache.maven.execution.DefaultMavenExecutionRequest)3 MavenExecutionRequest (org.apache.maven.execution.MavenExecutionRequest)3 MavenExecutionRequestPopulationException (org.apache.maven.execution.MavenExecutionRequestPopulationException)3 MavenExecutionRequestPopulator (org.apache.maven.execution.MavenExecutionRequestPopulator)3 LifecycleExecutionException (org.apache.maven.lifecycle.LifecycleExecutionException)3 ContainerConfiguration (org.codehaus.plexus.ContainerConfiguration)3 DefaultContainerConfiguration (org.codehaus.plexus.DefaultContainerConfiguration)3 DefaultPlexusContainer (org.codehaus.plexus.DefaultPlexusContainer)3 ComponentLookupException (org.codehaus.plexus.component.repository.exception.ComponentLookupException)3 XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)3 ILoggerFactory (org.slf4j.ILoggerFactory)1