Example usage for org.apache.maven.execution MavenExecutionRequest LOGGING_LEVEL_DEBUG

List of usage examples for org.apache.maven.execution MavenExecutionRequest LOGGING_LEVEL_DEBUG

Introduction

In this page you can find the example usage for org.apache.maven.execution MavenExecutionRequest LOGGING_LEVEL_DEBUG.

Prototype

int LOGGING_LEVEL_DEBUG

To view the source code for org.apache.maven.execution MavenExecutionRequest LOGGING_LEVEL_DEBUG.

Click Source Link

Usage

From source file:com.ccoe.build.profiler.lifecycle.MavenLifecycleProfiler.java

License:Apache License

@Override
public void onEvent(Object event) throws Exception {

    if (event instanceof SettingsBuildingRequest) {
        SettingsBuildingRequest settingBuildingRequest = (SettingsBuildingRequest) event;
        userSettingFile = settingBuildingRequest.getUserSettingsFile();
        globalSettingFile = settingBuildingRequest.getGlobalSettingsFile();
    }/*from   w  w w. j a va2s  .c  o m*/

    if (event instanceof MavenExecutionRequest) {
        MavenExecutionRequest mer = (MavenExecutionRequest) event;
        debug = (mer.getLoggingLevel() == MavenExecutionRequest.LOGGING_LEVEL_DEBUG);
        context.getData().put("baseAdd", mer.getBaseDirectory());
    }

    if (event instanceof ExecutionEvent) {

        ExecutionEvent executionEvent = (ExecutionEvent) event;

        if (executionEvent.getType() == ExecutionEvent.Type.ProjectDiscoveryStarted) {
            discoveryProfile = new DiscoveryProfile(context, executionEvent, userSettingFile, globalSettingFile,
                    debug);

        } else if (executionEvent.getType() == ExecutionEvent.Type.SessionStarted) {
            sessionProfile = new SessionProfile(context, executionEvent, debug);
        } else if (executionEvent.getType() == ExecutionEvent.Type.SessionEnded) {
            projectProfile.addPhaseProfile(phaseProfile);

            //if can accelerate,we will not generate the dependency file

            sessionProfile.stop();
            discoveryProfile.stop();
            OutputRenderer renderer = new OutputRenderer(sessionProfile, discoveryProfile);
            renderer.renderToScreen();
            // renderer.renderToJSON();
        } else if (executionEvent.getType() == ExecutionEvent.Type.ProjectStarted) {
            projectProfile = new ProjectProfile(context, executionEvent.getProject(), executionEvent);
        } else if (executionEvent.getType() == ExecutionEvent.Type.ProjectSucceeded
                || executionEvent.getType() == ExecutionEvent.Type.ProjectFailed) {

            if (phaseProfile != null)
                phaseProfile.stop();
            projectProfile.stop();
            sessionProfile.addProjectProfile(projectProfile);
        } else if (executionEvent.getType() == ExecutionEvent.Type.MojoStarted) {
            String phase = executionEvent.getMojoExecution().getLifecyclePhase();
            if (phaseProfile == null) {
                phaseProfile = new PhaseProfile(context, phase, executionEvent);
            } else if (phase == null) {
                phaseProfile.stop();
                projectProfile.addPhaseProfile(phaseProfile);
                phaseProfile = new PhaseProfile(context, "default", executionEvent);
            } else if (!phase.equals(phaseProfile.getPhase())) {
                phaseProfile.stop();
                projectProfile.addPhaseProfile(phaseProfile);
                phaseProfile = new PhaseProfile(context, phase, executionEvent);
            }
            mojoProfile = new MojoProfile(context, executionEvent.getMojoExecution(), executionEvent);
        } else if (executionEvent.getType() == ExecutionEvent.Type.MojoSucceeded
                || executionEvent.getType() == ExecutionEvent.Type.MojoFailed) {
            mojoProfile.stop();
            phaseProfile.addMojoProfile(mojoProfile);
        }
    }
}

From source file:org.commonjava.emb.boot.main.EMBMain.java

License:Apache License

protected EMBExecutionRequest populateRequest(final CliRequest cliRequest) throws EMBEmbeddingException {
    // cliRequest.builder.build();

    final EMBExecutionRequest request = cliRequest.request;
    final CommandLine commandLine = cliRequest.commandLine;
    final String workingDirectory = cliRequest.workingDirectory;
    final boolean debug = cliRequest.builder.shouldShowDebug();
    final boolean quiet = cliRequest.builder.shouldBeQuiet();
    final boolean showErrors = cliRequest.builder.shouldShowErrors();

    // ----------------------------------------------------------------------
    // Now that we have everything that we need we will fire up plexus and
    // bring the maven component to life for use.
    // ----------------------------------------------------------------------

    if (commandLine.hasOption(CLIManager.BATCH_MODE)) {
        request.setInteractiveMode(false);
        cliRequest.builder.embConfiguration().nonInteractive();
    }/*from  w  w  w .  ja  v  a2 s. co m*/

    boolean noSnapshotUpdates = false;
    if (commandLine.hasOption(CLIManager.SUPRESS_SNAPSHOT_UPDATES)) {
        noSnapshotUpdates = true;
    }

    // ----------------------------------------------------------------------
    //
    // ----------------------------------------------------------------------

    @SuppressWarnings("unchecked")
    final List<String> goals = commandLine.getArgList();

    boolean recursive = true;

    // this is the default behavior.
    String reactorFailureBehaviour = MavenExecutionRequest.REACTOR_FAIL_FAST;

    if (commandLine.hasOption(CLIManager.NON_RECURSIVE)) {
        recursive = false;
    }

    if (commandLine.hasOption(CLIManager.FAIL_FAST)) {
        reactorFailureBehaviour = MavenExecutionRequest.REACTOR_FAIL_FAST;
    } else if (commandLine.hasOption(CLIManager.FAIL_AT_END)) {
        reactorFailureBehaviour = MavenExecutionRequest.REACTOR_FAIL_AT_END;
    } else if (commandLine.hasOption(CLIManager.FAIL_NEVER)) {
        reactorFailureBehaviour = MavenExecutionRequest.REACTOR_FAIL_NEVER;
    }

    if (commandLine.hasOption(CLIManager.OFFLINE)) {
        request.setOffline(true);
    }

    boolean updateSnapshots = false;

    if (commandLine.hasOption(CLIManager.UPDATE_SNAPSHOTS)) {
        updateSnapshots = true;
    }

    String globalChecksumPolicy = null;

    if (commandLine.hasOption(CLIManager.CHECKSUM_FAILURE_POLICY)) {
        globalChecksumPolicy = MavenExecutionRequest.CHECKSUM_POLICY_FAIL;
    } else if (commandLine.hasOption(CLIManager.CHECKSUM_WARNING_POLICY)) {
        globalChecksumPolicy = MavenExecutionRequest.CHECKSUM_POLICY_WARN;
    }

    final File baseDirectory = new File(workingDirectory, "").getAbsoluteFile();

    // ----------------------------------------------------------------------
    // Profile Activation
    // ----------------------------------------------------------------------

    final List<String> activeProfiles = new ArrayList<String>();

    final List<String> inactiveProfiles = new ArrayList<String>();

    if (commandLine.hasOption(CLIManager.ACTIVATE_PROFILES)) {
        final String[] profileOptionValues = commandLine.getOptionValues(CLIManager.ACTIVATE_PROFILES);
        if (profileOptionValues != null) {
            for (int i = 0; i < profileOptionValues.length; ++i) {
                final StringTokenizer profileTokens = new StringTokenizer(profileOptionValues[i], ",");

                while (profileTokens.hasMoreTokens()) {
                    final String profileAction = profileTokens.nextToken().trim();

                    if (profileAction.startsWith("-") || profileAction.startsWith("!")) {
                        inactiveProfiles.add(profileAction.substring(1));
                    } else if (profileAction.startsWith("+")) {
                        activeProfiles.add(profileAction.substring(1));
                    } else {
                        activeProfiles.add(profileAction);
                    }
                }
            }
        }
    }

    ArtifactTransferListener transferListener;

    if (request.isInteractiveMode()) {
        transferListener = new InteractiveTransferListener(cliRequest.builder.standardOut());
    } else {
        transferListener = new BatchTransferListener(cliRequest.builder.standardOut());
    }

    transferListener.setShowChecksumEvents(false);

    String alternatePomFile = null;
    if (commandLine.hasOption(CLIManager.ALTERNATE_POM_FILE)) {
        alternatePomFile = commandLine.getOptionValue(CLIManager.ALTERNATE_POM_FILE);
    }

    int loggingLevel;

    if (debug) {
        loggingLevel = MavenExecutionRequest.LOGGING_LEVEL_DEBUG;
    } else if (quiet) {
        // TODO: we need to do some more work here. Some plugins use sys out or log errors at info level.
        // Ideally, we could use Warn across the board
        loggingLevel = MavenExecutionRequest.LOGGING_LEVEL_ERROR;
        // TODO:Additionally, we can't change the mojo level because the component key includes the version and it
        // isn't known ahead of time. This seems worth changing.
    } else {
        loggingLevel = MavenExecutionRequest.LOGGING_LEVEL_INFO;
    }

    File userToolchainsFile;
    if (commandLine.hasOption(CLIManager.ALTERNATE_USER_TOOLCHAINS)) {
        userToolchainsFile = new File(commandLine.getOptionValue(CLIManager.ALTERNATE_USER_TOOLCHAINS));
        userToolchainsFile = resolveFile(userToolchainsFile, workingDirectory);
    } else {
        userToolchainsFile = EMBMain.DEFAULT_USER_TOOLCHAINS_FILE;
    }

    request.setBaseDirectory(baseDirectory).setGoals(goals).setSystemProperties(cliRequest.systemProperties)
            .setUserProperties(cliRequest.userProperties).setReactorFailureBehavior(reactorFailureBehaviour)
            // default: fail fast
            .setRecursive(recursive)
            // default: true
            .setShowErrors(showErrors).addActiveProfiles(activeProfiles)
            // optional
            .addInactiveProfiles(inactiveProfiles)
            // optional
            .setLoggingLevel(loggingLevel)
            // default: batch mode which goes along with interactive
            .setUpdateSnapshots(updateSnapshots)
            // default: false
            .setNoSnapshotUpdates(noSnapshotUpdates)
            // default: false
            .setGlobalChecksumPolicy(globalChecksumPolicy)
            // default: warn
            .setUserToolchainsFile(userToolchainsFile);

    if (alternatePomFile != null) {
        final File pom = resolveFile(new File(alternatePomFile), workingDirectory);

        request.setPom(pom);
    } else {
        final File pom = cliRequest.builder.modelProcessor().locatePom(baseDirectory);
        cliRequest.builder.resetContainer();

        if (pom.isFile()) {
            request.setPom(pom);
        }
    }

    if ((request.getPom() != null) && (request.getPom().getParentFile() != null)) {
        request.setBaseDirectory(request.getPom().getParentFile());
    }

    if (commandLine.hasOption(CLIManager.RESUME_FROM)) {
        request.setResumeFrom(commandLine.getOptionValue(CLIManager.RESUME_FROM));
    }

    if (commandLine.hasOption(CLIManager.PROJECT_LIST)) {
        final String projectList = commandLine.getOptionValue(CLIManager.PROJECT_LIST);
        final String[] projects = StringUtils.split(projectList, ",");
        request.setSelectedProjects(Arrays.asList(projects));
    }

    if (commandLine.hasOption(CLIManager.ALSO_MAKE)
            && !commandLine.hasOption(CLIManager.ALSO_MAKE_DEPENDENTS)) {
        request.setMakeBehavior(MavenExecutionRequest.REACTOR_MAKE_UPSTREAM);
    } else if (!commandLine.hasOption(CLIManager.ALSO_MAKE)
            && commandLine.hasOption(CLIManager.ALSO_MAKE_DEPENDENTS)) {
        request.setMakeBehavior(MavenExecutionRequest.REACTOR_MAKE_DOWNSTREAM);
    } else if (commandLine.hasOption(CLIManager.ALSO_MAKE)
            && commandLine.hasOption(CLIManager.ALSO_MAKE_DEPENDENTS)) {
        request.setMakeBehavior(MavenExecutionRequest.REACTOR_MAKE_BOTH);
    }

    String localRepoProperty = request.getUserProperties().getProperty(EMBMain.LOCAL_REPO_PROPERTY);

    if (localRepoProperty == null) {
        localRepoProperty = request.getSystemProperties().getProperty(EMBMain.LOCAL_REPO_PROPERTY);
    }

    if (localRepoProperty != null) {
        request.setLocalRepositoryPath(localRepoProperty);
    }

    final String threadConfiguration = commandLine.hasOption(CLIManager.THREADS)
            ? commandLine.getOptionValue(CLIManager.THREADS)
            : request.getSystemProperties().getProperty(EMBMain.THREADS_DEPRECATED); // TODO: Remove
                                                                                                                                                                                                                   // this setting.
                                                                                                                                                                                                                   // Note that the
                                                                                                                                                                                                                   // int-tests use
                                                                                                                                                                                                                   // it

    if (threadConfiguration != null) {
        request.setPerCoreThreadCount(threadConfiguration.contains("C"));
        if (threadConfiguration.contains("W")) {
            LifecycleWeaveBuilder.setWeaveMode(request.getUserProperties());
        }
        request.setThreadCount(threadConfiguration.replace("C", "").replace("W", "").replace("auto", ""));
    }

    return request;
}

From source file:org.jvnet.hudson.plugins.mavendepsupdate.MavenUpdateChecker.java

License:Apache License

ProjectBuildingRequest getProjectBuildingRequest(Properties userProperties, PlexusContainer plexusContainer)
        throws ComponentLookupException, SettingsBuildingException, MavenExecutionRequestPopulationException,
        InvalidRepositoryException {//from  w w w  .  j ava2s.  c  o m

    MavenExecutionRequest request = new DefaultMavenExecutionRequest();

    request.setLoggingLevel(MavenExecutionRequest.LOGGING_LEVEL_DEBUG);

    request.setWorkspaceReader(new ReactorReader(new HashMap<String, MavenProject>(0)));

    SettingsBuilder settingsBuilder = plexusContainer.lookup(SettingsBuilder.class);

    RepositorySystem repositorySystem = plexusContainer.lookup(RepositorySystem.class);

    org.sonatype.aether.RepositorySystem repoSystem = plexusContainer
            .lookup(org.sonatype.aether.RepositorySystem.class);

    SettingsBuildingRequest settingsRequest = new DefaultSettingsBuildingRequest();

    if (globalSettings != null) {
        mavenUpdateCheckerResult.addDebugLine("globalSettings " + globalSettings.getRemote());
        settingsRequest.setGlobalSettingsFile(new File(globalSettings.getRemote()));
    } else {
        File globalSettings = new File(mavenHome, "conf/settings.xml");
        if (globalSettings.exists()) {
            settingsRequest.setGlobalSettingsFile(globalSettings);
        }
    }
    if (alternateSettings != null) {
        mavenUpdateCheckerResult.addDebugLine("alternateSettings " + alternateSettings.getRemote());
        settingsRequest.setUserSettingsFile(new File(alternateSettings.getRemote()));
        request.setUserSettingsFile(new File(alternateSettings.getRemote()));
    } else {
        File defaultUserSettings = new File(new File(System.getProperty("user.home"), ".m2"), "settings.xml");
        settingsRequest.setUserSettingsFile(defaultUserSettings);
        request.setUserSettingsFile(defaultUserSettings);
    }
    settingsRequest.setSystemProperties(System.getProperties());
    settingsRequest.setUserProperties(userProperties);

    SettingsBuildingResult settingsBuildingResult = settingsBuilder.build(settingsRequest);

    MavenExecutionRequestPopulator executionRequestPopulator = plexusContainer
            .lookup(MavenExecutionRequestPopulator.class);

    executionRequestPopulator.populateFromSettings(request, settingsBuildingResult.getEffectiveSettings());

    executionRequestPopulator.populateDefaults(request);

    MavenRepositorySystemSession session = new MavenRepositorySystemSession();

    session.setUpdatePolicy(RepositoryPolicy.UPDATE_POLICY_ALWAYS);

    SnapshotTransfertListener snapshotTransfertListener = new SnapshotTransfertListener(this.lastBuildTime);
    session.setTransferListener(snapshotTransfertListener);

    LocalRepository localRepo = getLocalRepo(settingsBuildingResult);

    session.setLocalRepositoryManager(repoSystem.newLocalRepositoryManager(localRepo));

    ArtifactRepository localArtifactRepository = getLocalArtifactRepo(settingsBuildingResult, repositorySystem);

    request.setLocalRepository(localArtifactRepository);

    if (this.activeProfiles != null && !this.activeProfiles.isEmpty()) {
        for (String id : this.activeProfiles) {
            Profile p = new Profile();
            p.setId(id);
            p.setSource("cli");
            request.addProfile(p);
            request.addActiveProfile(id);
        }
    }

    ProjectBuildingRequest projectBuildingRequest = request.getProjectBuildingRequest();
    return projectBuildingRequest.setRepositorySession(session);
}

From source file:org.kie.workbench.common.services.backend.compiler.external339.AFMavenCli.java

License:Apache License

protected void logging(AFCliRequest cliRequest) {
    cliRequest.setDebug(cliRequest.getCommandLine().hasOption(CLIManager.DEBUG));
    cliRequest.setQuiet(!cliRequest.isDebug() && cliRequest.getCommandLine().hasOption(CLIManager.QUIET));
    cliRequest.setShowErrors(cliRequest.isDebug() || cliRequest.getCommandLine().hasOption(CLIManager.ERRORS));

    slf4jLoggerFactory = LoggerFactory.getILoggerFactory();
    Slf4jConfiguration slf4jConfiguration = Slf4jConfigurationFactory.getConfiguration(slf4jLoggerFactory);

    if (cliRequest.isDebug()) {
        cliRequest.getRequest().setLoggingLevel(MavenExecutionRequest.LOGGING_LEVEL_DEBUG);
        slf4jConfiguration.setRootLoggerLevel(Slf4jConfiguration.Level.DEBUG);
    } else if (cliRequest.isQuiet()) {
        cliRequest.getRequest().setLoggingLevel(MavenExecutionRequest.LOGGING_LEVEL_ERROR);
        slf4jConfiguration.setRootLoggerLevel(Slf4jConfiguration.Level.ERROR);
    }//from  ww w. j a va 2 s . c  o m

    if (cliRequest.getCommandLine().hasOption(CLIManager.LOG_FILE)) {
        File logFile = new File(cliRequest.getCommandLine().getOptionValue(CLIManager.LOG_FILE).trim());
        logFile = resolveFile(logFile, cliRequest.getWorkingDirectory()); //@MAX

        try {
            PrintStream ps = new PrintStream(new FileOutputStream(logFile));
            System.setOut(ps);
            System.setErr(ps);
        } catch (FileNotFoundException e) {
            logger.error(e.getMessage());
        }
    }

    slf4jConfiguration.activate();

    plexusLoggerManager = new Slf4jLoggerManager();
    slf4jLogger = slf4jLoggerFactory.getLogger(this.getClass().getName());
}

From source file:org.kie.workbench.common.services.backend.compiler.impl.external339.AFMavenCli.java

License:Apache License

protected void logging(AFCliRequest cliRequest) {
    cliRequest.setDebug(cliRequest.getCommandLine().hasOption(CLIManager.DEBUG));
    cliRequest.setQuiet(!cliRequest.isDebug() && cliRequest.getCommandLine().hasOption(CLIManager.QUIET));
    cliRequest.setShowErrors(cliRequest.isDebug() || cliRequest.getCommandLine().hasOption(CLIManager.ERRORS));

    slf4jLoggerFactory = LoggerFactory.getILoggerFactory();
    Slf4jConfiguration slf4jConfiguration = Slf4jConfigurationFactory.getConfiguration(slf4jLoggerFactory);
    if (cliRequest.isDebug()) {
        cliRequest.getRequest().setLoggingLevel(MavenExecutionRequest.LOGGING_LEVEL_DEBUG);
        slf4jConfiguration.setRootLoggerLevel(Slf4jConfiguration.Level.DEBUG);
    } else if (cliRequest.isQuiet()) {
        cliRequest.getRequest().setLoggingLevel(MavenExecutionRequest.LOGGING_LEVEL_ERROR);
        slf4jConfiguration.setRootLoggerLevel(Slf4jConfiguration.Level.ERROR);
    }/*  w w w . j  av  a 2 s. c  o m*/

    if (cliRequest.getCommandLine().hasOption(CLIManager.LOG_FILE)) {
        File logFile = new File(cliRequest.getCommandLine().getOptionValue(CLIManager.LOG_FILE).trim());
        logFile = resolveFile(logFile, cliRequest.getWorkingDirectory());

        try {
            PrintStream ps = new PrintStream(new FileOutputStream(logFile));
            System.setOut(ps);
            System.setErr(ps);
        } catch (FileNotFoundException e) {
            logger.error(e.getMessage());
        }
    }

    slf4jConfiguration.activate();

    plexusLoggerManager = new Slf4jLoggerManager();
    slf4jLogger = slf4jLoggerFactory.getLogger(this.getClass().getName());
}

From source file:org.kie.workbench.common.services.backend.compiler.impl.external339.ReusableAFMavenCli.java

License:Apache License

protected void logging(AFCliRequest cliRequest) {
    cliRequest.setDebug(cliRequest.getCommandLine().hasOption(CLIManager.DEBUG));
    cliRequest.setQuiet(!cliRequest.isDebug() && cliRequest.getCommandLine().hasOption(CLIManager.QUIET));
    cliRequest.setShowErrors(cliRequest.isDebug() || cliRequest.getCommandLine().hasOption(CLIManager.ERRORS));

    slf4jLoggerFactory = LoggerFactory.getILoggerFactory();
    Slf4jConfiguration slf4jConfiguration = Slf4jConfigurationFactory.getConfiguration(slf4jLoggerFactory);
    if (cliRequest.isDebug()) {
        cliRequest.getRequest().setLoggingLevel(MavenExecutionRequest.LOGGING_LEVEL_DEBUG);
        slf4jConfiguration.setRootLoggerLevel(Slf4jConfiguration.Level.DEBUG);
    } else if (cliRequest.isQuiet()) {
        cliRequest.getRequest().setLoggingLevel(MavenExecutionRequest.LOGGING_LEVEL_ERROR);
        slf4jConfiguration.setRootLoggerLevel(Slf4jConfiguration.Level.ERROR);
    }/*from  w  ww. j  a v  a2s .c  o m*/

    if (cliRequest.getCommandLine().hasOption(CLIManager.LOG_FILE)) {
        File logFile = new File(cliRequest.getCommandLine().getOptionValue(CLIManager.LOG_FILE).trim());
        logFile = resolveFile(logFile, cliRequest.getWorkingDirectory());

        try {
            PrintStream ps = new PrintStream(new FileOutputStream(logFile));
            System.setOut(ps);
            System.setErr(ps);
        } catch (FileNotFoundException e) {
            logger.error(e.getMessage());
        }
    }

    slf4jConfiguration.activate();

    plexusLoggerManager = new Slf4jLoggerManager();
    reusableSlf4jLogger = slf4jLoggerFactory.getLogger(this.getClass().getName());
}

From source file:org.maven.ide.eclipse.embedder.EmbedderFactory.java

License:Apache License

public static MavenExecutionRequest createMavenExecutionRequest(MavenEmbedder embedder, boolean offline,
        boolean debug) {
    DefaultMavenExecutionRequest request = new DefaultMavenExecutionRequest();

    request.setOffline(offline);//from w ww .  j a v  a  2s.  co m
    request.setUseReactor(false);
    request.setRecursive(true);

    if (debug) {
        request.setShowErrors(true);
        request.setLoggingLevel(MavenExecutionRequest.LOGGING_LEVEL_DEBUG);
    } else {
        request.setShowErrors(false);
        request.setLoggingLevel(MavenExecutionRequest.LOGGING_LEVEL_INFO);
    }

    return request;
}

From source file:org.topdesk.maven.tracker.MavenCli.java

License:Apache License

private void logging(CliRequest cliRequest) {
    cliRequest.debug = cliRequest.commandLine.hasOption(CLIManager.DEBUG);
    cliRequest.quiet = !cliRequest.debug && cliRequest.commandLine.hasOption(CLIManager.QUIET);
    cliRequest.showErrors = cliRequest.debug || cliRequest.commandLine.hasOption(CLIManager.ERRORS);

    if (cliRequest.debug) {
        cliRequest.request.setLoggingLevel(MavenExecutionRequest.LOGGING_LEVEL_DEBUG);
    } else if (cliRequest.quiet) {
        // TODO: we need to do some more work here. Some plugins use sys out or log errors at info level.
        // Ideally, we could use Warn across the board
        cliRequest.request.setLoggingLevel(MavenExecutionRequest.LOGGING_LEVEL_ERROR);
        // TODO:Additionally, we can't change the mojo level because the component key includes the version and
        // it isn't known ahead of time. This seems worth changing.
    } else {/*from  ww  w  .  j a  v  a2s. co m*/
        cliRequest.request.setLoggingLevel(MavenExecutionRequest.LOGGING_LEVEL_INFO);
    }

    logger.setThreshold(cliRequest.request.getLoggingLevel());

    if (cliRequest.commandLine.hasOption(CLIManager.LOG_FILE)) {
        File logFile = new File(cliRequest.commandLine.getOptionValue(CLIManager.LOG_FILE));
        logFile = resolveFile(logFile, cliRequest.workingDirectory);

        try {
            cliRequest.fileStream = new PrintStream(logFile);
            logger.setStream(cliRequest.fileStream);
        } catch (FileNotFoundException e) {
            cliRequest.stderr.println(e);
            logger.setStream(cliRequest.stdout);
        }
    } else {
        logger.setStream(cliRequest.stdout);
    }

    ExecutionListener loggerListener = new ExecutionEventLogger(logger);
    ExecutionListener timerListener = new TrackingExecutionListener();

    cliRequest.request.setExecutionListener(new DelegatingExecutionListener(loggerListener, timerListener));
}

From source file:org.topdesk.maven.tracker.MavenCli.java

License:Apache License

private MavenExecutionRequest populateRequest(CliRequest cliRequest) {
    MavenExecutionRequest request = cliRequest.request;
    CommandLine commandLine = cliRequest.commandLine;
    String workingDirectory = cliRequest.workingDirectory;
    boolean debug = cliRequest.debug;
    boolean quiet = cliRequest.quiet;
    boolean showErrors = cliRequest.showErrors;

    String[] deprecatedOptions = { "up", "npu", "cpu", "npr" };
    for (String deprecatedOption : deprecatedOptions) {
        if (commandLine.hasOption(deprecatedOption)) {
            cliRequest.stdout.println("[WARNING] Command line option -" + deprecatedOption
                    + " is deprecated and will be removed in future Maven versions.");
        }/*w  w w .  j  a va2 s  . c  om*/
    }

    // ----------------------------------------------------------------------
    // Now that we have everything that we need we will fire up plexus and
    // bring the maven component to life for use.
    // ----------------------------------------------------------------------

    if (commandLine.hasOption(CLIManager.BATCH_MODE)) {
        request.setInteractiveMode(false);
    }

    boolean noSnapshotUpdates = false;
    if (commandLine.hasOption(CLIManager.SUPRESS_SNAPSHOT_UPDATES)) {
        noSnapshotUpdates = true;
    }

    // ----------------------------------------------------------------------
    //
    // ----------------------------------------------------------------------

    @SuppressWarnings("unchecked")
    List<String> goals = commandLine.getArgList();

    boolean recursive = true;

    // this is the default behavior.
    String reactorFailureBehaviour = MavenExecutionRequest.REACTOR_FAIL_FAST;

    if (commandLine.hasOption(CLIManager.NON_RECURSIVE)) {
        recursive = false;
    }

    if (commandLine.hasOption(CLIManager.FAIL_FAST)) {
        reactorFailureBehaviour = MavenExecutionRequest.REACTOR_FAIL_FAST;
    } else if (commandLine.hasOption(CLIManager.FAIL_AT_END)) {
        reactorFailureBehaviour = MavenExecutionRequest.REACTOR_FAIL_AT_END;
    } else if (commandLine.hasOption(CLIManager.FAIL_NEVER)) {
        reactorFailureBehaviour = MavenExecutionRequest.REACTOR_FAIL_NEVER;
    }

    if (commandLine.hasOption(CLIManager.OFFLINE)) {
        request.setOffline(true);
    }

    boolean updateSnapshots = false;

    if (commandLine.hasOption(CLIManager.UPDATE_SNAPSHOTS)) {
        updateSnapshots = true;
    }

    String globalChecksumPolicy = null;

    if (commandLine.hasOption(CLIManager.CHECKSUM_FAILURE_POLICY)) {
        globalChecksumPolicy = MavenExecutionRequest.CHECKSUM_POLICY_FAIL;
    } else if (commandLine.hasOption(CLIManager.CHECKSUM_WARNING_POLICY)) {
        globalChecksumPolicy = MavenExecutionRequest.CHECKSUM_POLICY_WARN;
    }

    File baseDirectory = new File(workingDirectory, "").getAbsoluteFile();

    // ----------------------------------------------------------------------
    // Profile Activation
    // ----------------------------------------------------------------------

    List<String> activeProfiles = new ArrayList<String>();

    List<String> inactiveProfiles = new ArrayList<String>();

    if (commandLine.hasOption(CLIManager.ACTIVATE_PROFILES)) {
        String[] profileOptionValues = commandLine.getOptionValues(CLIManager.ACTIVATE_PROFILES);
        if (profileOptionValues != null) {
            for (int i = 0; i < profileOptionValues.length; ++i) {
                StringTokenizer profileTokens = new StringTokenizer(profileOptionValues[i], ",");

                while (profileTokens.hasMoreTokens()) {
                    String profileAction = profileTokens.nextToken().trim();

                    if (profileAction.startsWith("-") || profileAction.startsWith("!")) {
                        inactiveProfiles.add(profileAction.substring(1));
                    } else if (profileAction.startsWith("+")) {
                        activeProfiles.add(profileAction.substring(1));
                    } else {
                        activeProfiles.add(profileAction);
                    }
                }
            }
        }
    }

    TransferListener transferListener;

    if (quiet) {
        transferListener = new QuietMavenTransferListener();
    } else if (request.isInteractiveMode()) {
        transferListener = new ConsoleMavenTransferListener(cliRequest.stdout);
    } else {
        transferListener = new BatchModeMavenTransferListener(cliRequest.stdout);
    }

    String alternatePomFile = null;
    if (commandLine.hasOption(CLIManager.ALTERNATE_POM_FILE)) {
        alternatePomFile = commandLine.getOptionValue(CLIManager.ALTERNATE_POM_FILE);
    }

    int loggingLevel;

    if (debug) {
        loggingLevel = MavenExecutionRequest.LOGGING_LEVEL_DEBUG;
    } else if (quiet) {
        // TODO: we need to do some more work here. Some plugins use sys out or log errors at info level.
        // Ideally, we could use Warn across the board
        loggingLevel = MavenExecutionRequest.LOGGING_LEVEL_ERROR;
        // TODO:Additionally, we can't change the mojo level because the component key includes the version and
        // it isn't known ahead of time. This seems worth changing.
    } else {
        loggingLevel = MavenExecutionRequest.LOGGING_LEVEL_INFO;
    }

    File userToolchainsFile;
    if (commandLine.hasOption(CLIManager.ALTERNATE_USER_TOOLCHAINS)) {
        userToolchainsFile = new File(commandLine.getOptionValue(CLIManager.ALTERNATE_USER_TOOLCHAINS));
        userToolchainsFile = resolveFile(userToolchainsFile, workingDirectory);
    } else {
        userToolchainsFile = MavenCli.DEFAULT_USER_TOOLCHAINS_FILE;
    }

    request.setBaseDirectory(baseDirectory).setGoals(goals).setSystemProperties(cliRequest.systemProperties)
            .setUserProperties(cliRequest.userProperties).setReactorFailureBehavior(reactorFailureBehaviour) // default: fail fast
            .setRecursive(recursive) // default: true
            .setShowErrors(showErrors) // default: false
            .addActiveProfiles(activeProfiles) // optional
            .addInactiveProfiles(inactiveProfiles) // optional
            .setLoggingLevel(loggingLevel) // default: info
            .setTransferListener(transferListener) // default: batch mode which goes along with interactive
            .setUpdateSnapshots(updateSnapshots) // default: false
            .setNoSnapshotUpdates(noSnapshotUpdates) // default: false
            .setGlobalChecksumPolicy(globalChecksumPolicy) // default: warn
            .setUserToolchainsFile(userToolchainsFile);

    if (alternatePomFile != null) {
        File pom = resolveFile(new File(alternatePomFile), workingDirectory);

        request.setPom(pom);
    } else {
        File pom = modelProcessor.locatePom(baseDirectory);

        if (pom.isFile()) {
            request.setPom(pom);
        }
    }

    if ((request.getPom() != null) && (request.getPom().getParentFile() != null)) {
        request.setBaseDirectory(request.getPom().getParentFile());
    }

    if (commandLine.hasOption(CLIManager.RESUME_FROM)) {
        request.setResumeFrom(commandLine.getOptionValue(CLIManager.RESUME_FROM));
    }

    if (commandLine.hasOption(CLIManager.PROJECT_LIST)) {
        String projectList = commandLine.getOptionValue(CLIManager.PROJECT_LIST);
        String[] projects = StringUtils.split(projectList, ",");
        request.setSelectedProjects(Arrays.asList(projects));
    }

    if (commandLine.hasOption(CLIManager.ALSO_MAKE)
            && !commandLine.hasOption(CLIManager.ALSO_MAKE_DEPENDENTS)) {
        request.setMakeBehavior(MavenExecutionRequest.REACTOR_MAKE_UPSTREAM);
    } else if (!commandLine.hasOption(CLIManager.ALSO_MAKE)
            && commandLine.hasOption(CLIManager.ALSO_MAKE_DEPENDENTS)) {
        request.setMakeBehavior(MavenExecutionRequest.REACTOR_MAKE_DOWNSTREAM);
    } else if (commandLine.hasOption(CLIManager.ALSO_MAKE)
            && commandLine.hasOption(CLIManager.ALSO_MAKE_DEPENDENTS)) {
        request.setMakeBehavior(MavenExecutionRequest.REACTOR_MAKE_BOTH);
    }

    String localRepoProperty = request.getUserProperties().getProperty(MavenCli.LOCAL_REPO_PROPERTY);

    if (localRepoProperty == null) {
        localRepoProperty = request.getSystemProperties().getProperty(MavenCli.LOCAL_REPO_PROPERTY);
    }

    if (localRepoProperty != null) {
        request.setLocalRepositoryPath(localRepoProperty);
    }

    final String threadConfiguration = commandLine.hasOption(CLIManager.THREADS)
            ? commandLine.getOptionValue(CLIManager.THREADS)
            : request.getSystemProperties().getProperty(MavenCli.THREADS_DEPRECATED); // TODO: Remove this setting. Note that the int-tests use it

    if (threadConfiguration != null) {
        request.setPerCoreThreadCount(threadConfiguration.contains("C"));
        if (threadConfiguration.contains("W")) {
            LifecycleWeaveBuilder.setWeaveMode(request.getUserProperties());
        }
        request.setThreadCount(threadConfiguration.replace("C", "").replace("W", "").replace("auto", ""));
    }

    request.setCacheNotFound(true);
    request.setCacheTransferError(false);

    return request;
}

From source file:org.universaal.tools.packaging.tool.preferences.EclipsePreferencesConfigurator.java

License:Apache License

public int getMavenLogLevel(String message) {

    Map<String, Integer> enumeration = new HashMap<String, Integer>();
    enumeration.put("DEBUG", MavenExecutionRequest.LOGGING_LEVEL_DEBUG);
    enumeration.put("INFO", MavenExecutionRequest.LOGGING_LEVEL_INFO);
    enumeration.put("WARN", MavenExecutionRequest.LOGGING_LEVEL_WARN);
    enumeration.put("ERROR", MavenExecutionRequest.LOGGING_LEVEL_ERROR);
    enumeration.put("FATAL", MavenExecutionRequest.LOGGING_LEVEL_FATAL);
    enumeration.put("DISABLED", MavenExecutionRequest.LOGGING_LEVEL_DISABLED);

    for (String key : enumeration.keySet()) {
        if (message.contains(key))
            return enumeration.get(key);
    }//from   w w w  .  j av  a  2  s.com
    return 4;
}