Search in sources :

Example 6 with PlexusContainer

use of org.codehaus.plexus.PlexusContainer in project maven-plugins by apache.

the class AbstractAnalyzeMojo method createProjectDependencyAnalyzer.

protected ProjectDependencyAnalyzer createProjectDependencyAnalyzer() throws MojoExecutionException {
    final String role = ProjectDependencyAnalyzer.ROLE;
    final String roleHint = analyzer;
    try {
        final PlexusContainer container = (PlexusContainer) context.get(PlexusConstants.PLEXUS_KEY);
        return (ProjectDependencyAnalyzer) container.lookup(role, roleHint);
    } catch (Exception exception) {
        throw new MojoExecutionException("Failed to instantiate ProjectDependencyAnalyser with role " + role + " / role-hint " + roleHint, exception);
    }
}
Also used : PlexusContainer(org.codehaus.plexus.PlexusContainer) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ProjectDependencyAnalyzer(org.apache.maven.shared.dependency.analyzer.ProjectDependencyAnalyzer) ProjectDependencyAnalyzerException(org.apache.maven.shared.dependency.analyzer.ProjectDependencyAnalyzerException) ContextException(org.codehaus.plexus.context.ContextException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Example 7 with PlexusContainer

use of org.codehaus.plexus.PlexusContainer in project kie-wb-common by kiegroup.

the class AFMavenCli method doMain.

public int doMain(AFCliRequest cliRequest, ClassWorld classWorld) {
    PlexusContainer localContainer = null;
    PrintStream originalOut = System.out;
    PrintStream originalErr = System.err;
    try {
        initialize(cliRequest);
        cli(cliRequest);
        logging(cliRequest);
        version(cliRequest);
        properties(cliRequest);
        localContainer = container(cliRequest, classWorld);
        commands(cliRequest);
        configure(cliRequest);
        toolchains(cliRequest);
        populateRequest(cliRequest);
        repository(cliRequest);
        return execute(cliRequest);
    } catch (ExitException e) {
        e.getStackTrace();
        return e.exitCode;
    } catch (UnrecognizedOptionException e) {
        e.getStackTrace();
        return 1;
    } catch (BuildAbort e) {
        e.getStackTrace();
        AFCLIReportingUtils.showError(slf4jLogger, "ABORTED", e, cliRequest.isShowErrors());
        return 2;
    } catch (Exception e) {
        e.getStackTrace();
        AFCLIReportingUtils.showError(slf4jLogger, "Error executing Maven.", e, cliRequest.isShowErrors());
        return 1;
    } finally {
        System.setOut(originalOut);
        System.setErr(originalErr);
        if (localContainer != null) {
            localContainer.dispose();
            localContainer = null;
        }
    }
}
Also used : PrintStream(java.io.PrintStream) DefaultPlexusContainer(org.codehaus.plexus.DefaultPlexusContainer) PlexusContainer(org.codehaus.plexus.PlexusContainer) BuildAbort(org.apache.maven.BuildAbort) UnrecognizedOptionException(org.apache.commons.cli.UnrecognizedOptionException) 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)

Example 8 with PlexusContainer

use of org.codehaus.plexus.PlexusContainer in project intellij-community by JetBrains.

the class Maven2ServerEmbedderImpl method create.

public static Maven2ServerEmbedderImpl create(MavenServerSettings facadeSettings) throws RemoteException {
    MavenEmbedderSettings settings = new MavenEmbedderSettings();
    List<String> commandLineOptions = new ArrayList<String>();
    String mavenEmbedderCliOptions = System.getProperty(MavenServerEmbedder.MAVEN_EMBEDDER_CLI_ADDITIONAL_ARGS);
    if (mavenEmbedderCliOptions != null) {
        commandLineOptions.addAll(StringUtil.splitHonorQuotes(mavenEmbedderCliOptions, ' '));
    }
    settings.setConfigurator(new PlexusComponentConfigurator() {

        public void configureComponents(@NotNull PlexusContainer c) {
            setupContainer(c);
        }
    });
    Maven2ServerConsoleWrapper consoleWrapper = new Maven2ServerConsoleWrapper();
    consoleWrapper.setThreshold(facadeSettings.getLoggingLevel());
    settings.setLogger(consoleWrapper);
    settings.setRecursive(false);
    settings.setWorkOffline(facadeSettings.isOffline());
    settings.setUsePluginRegistry(false);
    settings.setMavenHome(facadeSettings.getMavenHome());
    settings.setUserSettingsFile(facadeSettings.getUserSettingsFile());
    settings.setGlobalSettingsFile(facadeSettings.getGlobalSettingsFile());
    settings.setLocalRepository(facadeSettings.getLocalRepository());
    if (commandLineOptions.contains("-U") || commandLineOptions.contains("--update-snapshots")) {
        settings.setSnapshotUpdatePolicy(MavenEmbedderSettings.UpdatePolicy.ALWAYS_UPDATE);
    } else {
        settings.setSnapshotUpdatePolicy(convertUpdatePolicy(facadeSettings.getSnapshotUpdatePolicy()));
    }
    settings.setPluginUpdatePolicy(convertUpdatePolicy(facadeSettings.getPluginUpdatePolicy()));
    settings.setProperties(MavenServerUtil.collectSystemProperties());
    return new Maven2ServerEmbedderImpl(MavenEmbedder.create(settings), consoleWrapper);
}
Also used : PlexusContainer(org.codehaus.plexus.PlexusContainer) PlexusComponentConfigurator(org.jetbrains.maven.embedder.PlexusComponentConfigurator) MavenEmbedderSettings(org.jetbrains.maven.embedder.MavenEmbedderSettings)

Example 9 with PlexusContainer

use of org.codehaus.plexus.PlexusContainer in project maven-dependency-plugin by apache.

the class AbstractAnalyzeMojo method createProjectDependencyAnalyzer.

/**
 * @return {@link ProjectDependencyAnalyzer}
 * @throws MojoExecutionException in case of an error.
 */
protected ProjectDependencyAnalyzer createProjectDependencyAnalyzer() throws MojoExecutionException {
    final String role = ProjectDependencyAnalyzer.ROLE;
    final String roleHint = analyzer;
    try {
        final PlexusContainer container = (PlexusContainer) context.get(PlexusConstants.PLEXUS_KEY);
        return (ProjectDependencyAnalyzer) container.lookup(role, roleHint);
    } catch (Exception exception) {
        throw new MojoExecutionException("Failed to instantiate ProjectDependencyAnalyser with role " + role + " / role-hint " + roleHint, exception);
    }
}
Also used : PlexusContainer(org.codehaus.plexus.PlexusContainer) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ProjectDependencyAnalyzer(org.apache.maven.shared.dependency.analyzer.ProjectDependencyAnalyzer) ProjectDependencyAnalyzerException(org.apache.maven.shared.dependency.analyzer.ProjectDependencyAnalyzerException) ContextException(org.codehaus.plexus.context.ContextException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Example 10 with PlexusContainer

use of org.codehaus.plexus.PlexusContainer in project pom-manipulation-ext by release-engineering.

the class Cli method parseSettings.

private Settings parseSettings(File settings) throws PlexusContainerException, ComponentLookupException, SettingsBuildingException {
    PlexusContainer container = new DefaultPlexusContainer();
    DefaultSettingsBuildingRequest settingsRequest = new DefaultSettingsBuildingRequest();
    settingsRequest.setUserSettingsFile(settings);
    settingsRequest.setGlobalSettingsFile(DEFAULT_GLOBAL_SETTINGS_FILE);
    settingsRequest.setUserProperties(session.getUserProperties());
    settingsRequest.setSystemProperties(System.getProperties());
    SettingsBuilder settingsBuilder = container.lookup(SettingsBuilder.class);
    SettingsBuildingResult settingsResult = settingsBuilder.build(settingsRequest);
    Settings effectiveSettings = settingsResult.getEffectiveSettings();
    ProfileSelector profileSelector = container.lookup(ProfileSelector.class);
    ProfileActivationContext profileActivationContext = new DefaultProfileActivationContext().setActiveProfileIds(effectiveSettings.getActiveProfiles());
    List<org.apache.maven.model.Profile> modelProfiles = new ArrayList<>();
    for (Profile profile : effectiveSettings.getProfiles()) {
        modelProfiles.add(SettingsUtils.convertFromSettingsProfile(profile));
    }
    List<org.apache.maven.model.Profile> activeModelProfiles = profileSelector.getActiveProfiles(modelProfiles, profileActivationContext, new ModelProblemCollector() {

        @Override
        public void add(ModelProblem.Severity severity, String message, InputLocation location, Exception cause) {
        // do nothing
        }
    });
    List<String> activeProfiles = new ArrayList<>();
    for (org.apache.maven.model.Profile profile : activeModelProfiles) {
        activeProfiles.add(profile.getId());
    }
    effectiveSettings.setActiveProfiles(activeProfiles);
    return effectiveSettings;
}
Also used : InputLocation(org.apache.maven.model.InputLocation) DefaultPlexusContainer(org.codehaus.plexus.DefaultPlexusContainer) PlexusContainer(org.codehaus.plexus.PlexusContainer) SettingsBuildingResult(org.apache.maven.settings.building.SettingsBuildingResult) ArrayList(java.util.ArrayList) Profile(org.apache.maven.settings.Profile) SettingsBuilder(org.apache.maven.settings.building.SettingsBuilder) ModelProblem(org.apache.maven.model.building.ModelProblem) ProfileSelector(org.apache.maven.model.profile.ProfileSelector) Settings(org.apache.maven.settings.Settings) DefaultProfileActivationContext(org.apache.maven.model.profile.DefaultProfileActivationContext) ProfileActivationContext(org.apache.maven.model.profile.ProfileActivationContext) DefaultSettingsBuildingRequest(org.apache.maven.settings.building.DefaultSettingsBuildingRequest) PlexusContainerException(org.codehaus.plexus.PlexusContainerException) RestException(org.commonjava.maven.ext.io.rest.exception.RestException) ManipulationException(org.commonjava.maven.ext.common.ManipulationException) ParseException(org.apache.commons.cli.ParseException) SettingsBuildingException(org.apache.maven.settings.building.SettingsBuildingException) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) MavenExecutionRequestPopulationException(org.apache.maven.execution.MavenExecutionRequestPopulationException) ModelProblemCollector(org.apache.maven.model.building.ModelProblemCollector) DefaultPlexusContainer(org.codehaus.plexus.DefaultPlexusContainer) DefaultProfileActivationContext(org.apache.maven.model.profile.DefaultProfileActivationContext)

Aggregations

PlexusContainer (org.codehaus.plexus.PlexusContainer)14 DefaultPlexusContainer (org.codehaus.plexus.DefaultPlexusContainer)8 MavenSession (org.apache.maven.execution.MavenSession)6 MavenExecutionRequest (org.apache.maven.execution.MavenExecutionRequest)5 ComponentLookupException (org.codehaus.plexus.component.repository.exception.ComponentLookupException)5 IOException (java.io.IOException)4 MavenExecutionRequestPopulationException (org.apache.maven.execution.MavenExecutionRequestPopulationException)4 ParseException (org.apache.commons.cli.ParseException)3 DefaultMavenExecutionRequest (org.apache.maven.execution.DefaultMavenExecutionRequest)3 DefaultMavenExecutionResult (org.apache.maven.execution.DefaultMavenExecutionResult)3 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)3 FileNotFoundException (java.io.FileNotFoundException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Properties (java.util.Properties)2 UnrecognizedOptionException (org.apache.commons.cli.UnrecognizedOptionException)2 BuildAbort (org.apache.maven.BuildAbort)2 InternalErrorException (org.apache.maven.InternalErrorException)2 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)2 MavenArtifactRepository (org.apache.maven.artifact.repository.MavenArtifactRepository)2