Search in sources :

Example 1 with TransferListener

use of org.eclipse.aether.transfer.TransferListener in project kie-wb-common by kiegroup.

the class AFMavenCli method populateRequest.

// ----------------------------------------------------------------------
// System properties handling
// ----------------------------------------------------------------------
protected MavenExecutionRequest populateRequest(AFCliRequest cliRequest, MavenExecutionRequest request) {
    CommandLine commandLine = cliRequest.getCommandLine();
    String workingDirectory = cliRequest.getWorkingDirectory();
    boolean quiet = cliRequest.isQuiet();
    boolean showErrors = cliRequest.isShowErrors();
    String[] deprecatedOptions = { "up", "npu", "cpu", "npr" };
    for (String deprecatedOption : deprecatedOptions) {
        if (commandLine.hasOption(deprecatedOption)) {
            slf4jLogger.warn("Command line option -" + deprecatedOption + " is deprecated and will be removed in future Maven versions.");
        }
    }
    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 (String profileOptionValue : profileOptionValues) {
                StringTokenizer profileTokens = new StringTokenizer(profileOptionValue, ",");
                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() && !cliRequest.getCommandLine().hasOption(CLIManager.LOG_FILE)) {
        // 
        // If we're logging to a file then we don't want the console transfer listener as it will spew
        // download progress all over the place
        // 
        transferListener = getConsoleTransferListener();
    } else {
        transferListener = getBatchTransferListener();
    }
    ExecutionListener executionListener = new ExecutionEventLogger();
    if (eventSpyDispatcher != null) {
        executionListener = eventSpyDispatcher.chainListener(executionListener);
    }
    String alternatePomFile = null;
    if (commandLine.hasOption(CLIManager.ALTERNATE_POM_FILE)) {
        alternatePomFile = commandLine.getOptionValue(CLIManager.ALTERNATE_POM_FILE);
    }
    request.setBaseDirectory(baseDirectory).setGoals(goals).setSystemProperties(cliRequest.getSystemProperties()).setUserProperties(cliRequest.getUserProperties()).setReactorFailureBehavior(// default: fail fast
    reactorFailureBehaviour).setRecursive(// default: true
    recursive).setShowErrors(// default: false
    showErrors).addActiveProfiles(// optional
    activeProfiles).addInactiveProfiles(// optional
    inactiveProfiles).setExecutionListener(executionListener).setTransferListener(// default: batch mode which goes along with interactive
    transferListener).setUpdateSnapshots(// default: false
    updateSnapshots).setNoSnapshotUpdates(// default: false
    noSnapshotUpdates).setGlobalChecksumPolicy(// default: warn
    globalChecksumPolicy).setMultiModuleProjectDirectory(new File(cliRequest.getMultiModuleProjectDirectory()));
    if (alternatePomFile != null) {
        File pom = resolveFile(new File(alternatePomFile.trim()), workingDirectory);
        if (pom.isDirectory()) {
            pom = new File(pom, "pom.xml");
        }
        request.setPom(pom);
    } else if (modelProcessor != null) {
        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[] projectOptionValues = commandLine.getOptionValues(CLIManager.PROJECT_LIST);
        List<String> inclProjects = new ArrayList<String>();
        List<String> exclProjects = new ArrayList<String>();
        if (projectOptionValues != null) {
            for (String projectOptionValue : projectOptionValues) {
                StringTokenizer projectTokens = new StringTokenizer(projectOptionValue, ",");
                while (projectTokens.hasMoreTokens()) {
                    String projectAction = projectTokens.nextToken().trim();
                    if (projectAction.startsWith("-") || projectAction.startsWith("!")) {
                        exclProjects.add(projectAction.substring(1));
                    } else if (projectAction.startsWith("+")) {
                        inclProjects.add(projectAction.substring(1));
                    } else {
                        inclProjects.add(projectAction);
                    }
                }
            }
        }
        request.setSelectedProjects(inclProjects);
        request.setExcludedProjects(exclProjects);
    }
    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);
    }
    request.setCacheNotFound(true);
    request.setCacheTransferError(false);
    // 
    // Builder, concurrency and parallelism
    // 
    // We preserve the existing methods for builder selection which is to look for various inputs in the threading
    // configuration. We don't have an easy way to allow a pluggable builder to provide its own configuration
    // parameters but this is sufficient for now. Ultimately we want components like Builders to provide a way to
    // extend the command line to accept its own configuration parameters.
    // 
    final String threadConfiguration = commandLine.hasOption(CLIManager.THREADS) ? commandLine.getOptionValue(CLIManager.THREADS) : request.getSystemProperties().getProperty(// TODO: Remove this setting. Note that the int-tests use it
    MavenCli.THREADS_DEPRECATED);
    if (threadConfiguration != null) {
        // 
        // Default to the standard multithreaded builder
        // 
        request.setBuilderId("multithreaded");
        if (threadConfiguration.contains("C")) {
            request.setDegreeOfConcurrency(calculateDegreeOfConcurrencyWithCoreMultiplier(threadConfiguration));
        } else {
            request.setDegreeOfConcurrency(Integer.valueOf(threadConfiguration));
        }
    }
    // 
    if (commandLine.hasOption(CLIManager.BUILDER)) {
        request.setBuilderId(commandLine.getOptionValue(CLIManager.BUILDER));
    }
    return request;
}
Also used : ConsoleMavenTransferListener(org.apache.maven.cli.transfer.ConsoleMavenTransferListener) QuietMavenTransferListener(org.apache.maven.cli.transfer.QuietMavenTransferListener) TransferListener(org.eclipse.aether.transfer.TransferListener) Slf4jMavenTransferListener(org.apache.maven.cli.transfer.Slf4jMavenTransferListener) ArrayList(java.util.ArrayList) ExecutionListener(org.apache.maven.execution.ExecutionListener) ExecutionEventLogger(org.apache.maven.cli.event.ExecutionEventLogger) CommandLine(org.apache.commons.cli.CommandLine) StringTokenizer(java.util.StringTokenizer) File(java.io.File) QuietMavenTransferListener(org.apache.maven.cli.transfer.QuietMavenTransferListener)

Aggregations

File (java.io.File)1 ArrayList (java.util.ArrayList)1 StringTokenizer (java.util.StringTokenizer)1 CommandLine (org.apache.commons.cli.CommandLine)1 ExecutionEventLogger (org.apache.maven.cli.event.ExecutionEventLogger)1 ConsoleMavenTransferListener (org.apache.maven.cli.transfer.ConsoleMavenTransferListener)1 QuietMavenTransferListener (org.apache.maven.cli.transfer.QuietMavenTransferListener)1 Slf4jMavenTransferListener (org.apache.maven.cli.transfer.Slf4jMavenTransferListener)1 ExecutionListener (org.apache.maven.execution.ExecutionListener)1 TransferListener (org.eclipse.aether.transfer.TransferListener)1