public MavenExecutionRequest createRequest(
      File file, List<String> activeProfiles, List<String> inactiveProfiles, List<String> goals)
      throws RemoteException {
    // Properties executionProperties = myMavenSettings.getProperties();
    // if (executionProperties == null) {
    //  executionProperties = new Properties();
    // }

    MavenExecutionRequest result = new DefaultMavenExecutionRequest();

    try {
      getComponent(MavenExecutionRequestPopulator.class)
          .populateFromSettings(result, myMavenSettings);

      result.setGoals(goals);

      result.setPom(file);

      getComponent(MavenExecutionRequestPopulator.class).populateDefaults(result);

      result.setSystemProperties(mySystemProperties);

      result.setActiveProfiles(activeProfiles);
      result.setInactiveProfiles(inactiveProfiles);

      return result;
    } catch (MavenExecutionRequestPopulationException e) {
      throw new RuntimeException(e);
    }
  }
Example #2
0
  /**
   * @param goals
   * @param serverProperties
   * @param module
   * @param monitor
   * @return
   * @throws CoreException
   */
  public static boolean runBuild(
      List<String> goals, Properties serverProperties, IModule module, IProgressMonitor monitor)
      throws CoreException {
    IMaven maven = MavenPlugin.getMaven();
    IMavenExecutionContext executionContext = maven.createExecutionContext();
    MavenExecutionRequest executionRequest = executionContext.getExecutionRequest();
    executionRequest.setPom(getModelFile(module));
    if (serverProperties != null && serverProperties.isEmpty() == false) {
      Server fabric8Server = new Server();
      fabric8Server.setId(serverProperties.getProperty(SERVER_ID));
      fabric8Server.setUsername(serverProperties.getProperty(SERVER_USER));
      fabric8Server.setPassword(serverProperties.getProperty(SERVER_PASSWORD));
      executionRequest.addServer(fabric8Server);
    }
    executionRequest.setGoals(goals);

    MavenExecutionResult result = maven.execute(executionRequest, monitor);
    for (Throwable t : result.getExceptions()) {
      Activator.getLogger().error(t);
    }
    return !result.hasExceptions();
  }
Example #3
0
  private MavenExecutionRequest populateRequest(CliRequest cliRequest) {
    MavenExecutionRequest request = cliRequest.request;
    CommandLine commandLine = cliRequest.commandLine;
    String workingDirectory = cliRequest.workingDirectory;
    boolean quiet = cliRequest.quiet;
    boolean showErrors = cliRequest.showErrors;

    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.");
      }
    }

    // ----------------------------------------------------------------------
    // 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 (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.commandLine.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();
    executionListener = eventSpyDispatcher.chainListener(executionListener);

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

    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
        .setExecutionListener(executionListener)
        .setTransferListener(
            transferListener) // default: batch mode which goes along with interactive
        .setUpdateSnapshots(updateSnapshots) // default: false
        .setNoSnapshotUpdates(noSnapshotUpdates) // default: false
        .setGlobalChecksumPolicy(globalChecksumPolicy) // default: warn
    ;

    if (alternatePomFile != null) {
      File pom = resolveFile(new File(alternatePomFile), workingDirectory);
      if (pom.isDirectory()) {
        pom = new File(pom, "pom.xml");
      }

      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[] 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(
                    MavenCli
                        .THREADS_DEPRECATED); // TODO: Remove this setting. Note that the int-tests
                                              // use it

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

    //
    // Allow the builder to be overriden by the user if requested. The builders are now pluggable.
    //
    if (commandLine.hasOption(CLIManager.BUILDER)) {
      request.setBuilderId(commandLine.getOptionValue(CLIManager.BUILDER));
    }

    return request;
  }
Example #4
0
    private void configureRequest(final MavenExecutionRequest request) throws Exception {
      assert request != null;
      assert config != null;

      File dir = new File(config.getBaseDirectory(), "").getAbsoluteFile();
      request.setBaseDirectory(dir);

      // HACK: Some bits need user.dir to be set, or use un-rooted File's :-(
      System.setProperty("user.dir", dir.getAbsolutePath());

      // Configure profiles
      for (String profile : config.getProfiles()) {
        profile = profile.trim();

        if (profile.startsWith("-") || profile.startsWith("!")) {
          request.addInactiveProfile(profile.substring(1));
        } else if (profile.startsWith("+")) {
          request.addActiveProfile(profile.substring(1));
        } else {
          request.addActiveProfile(profile);
        }
      }

      // Configure user toolchains
      File userToolchainsFile = request.getUserToolchainsFile();
      if (userToolchainsFile != null) {
        userToolchainsFile = resolveFile(userToolchainsFile, config.getBaseDirectory());
      } else {
        userToolchainsFile = DEFAULT_USER_TOOLCHAINS_FILE;
      }
      request.setUserToolchainsFile(userToolchainsFile);

      // Configure the pom
      File alternatePomFile = config.getPomFile();
      if (alternatePomFile != null) {
        request.setPom(resolveFile(alternatePomFile, config.getBaseDirectory()));
      } else if (request.getPom() != null && !request.getPom().isAbsolute()) {
        request.setPom(request.getPom().getAbsoluteFile());
      }

      if ((request.getPom() != null) && (request.getPom().getParentFile() != null)) {
        request.setBaseDirectory(request.getPom().getParentFile());
      } else if (request.getPom() == null && request.getBaseDirectory() != null) {
        ModelProcessor modelProcessor = container.lookup(ModelProcessor.class);
        try {
          File pom = modelProcessor.locatePom(new File(request.getBaseDirectory()));
          request.setPom(pom);
        } finally {
          container.release(modelProcessor);
        }
      } else if (request.getBaseDirectory() == null) {
        request.setBaseDirectory(config.getBaseDirectory());
      }

      // Configure the local repo path
      String localRepoPath = request.getUserProperties().getProperty(LOCAL_REPO);
      if (localRepoPath == null) {
        localRepoPath = request.getSystemProperties().getProperty(LOCAL_REPO);
      }
      if (localRepoPath != null) {
        request.setLocalRepositoryPath(localRepoPath);
      }

      // Setup the xfr listener
      ArtifactTransferListener transferListener;
      if (request.isInteractiveMode()) {
        transferListener = new ConsoleMavenTransferListener(config.getStreams().out);
      } else {
        transferListener = new BatchModeMavenTransferListener(config.getStreams().out);
      }
      transferListener.setShowChecksumEvents(false);
      request.setTransferListener(transferListener);

      // Configure request logging
      request.setLoggingLevel(logger.getThreshold());
      request.setExecutionListener(new ExecutionEventLogger(terminal.get(), logger));
    }
  public void execute() throws MojoExecutionException, MojoFailureException {
    // set up derived paths
    forgeDir = new File(outputDir, "forge");
    jarsDir = new File(forgeDir, "mcp/jars");

    // check whether the artifact is already installed
    if (reinstall) {
      getLog().info("reinstall flag set; skipping availability check");
    } else {
      getLog().info("attempting to resolve Forge artifacts");

      if (null != resolveApiArtifact() && null != resolveToolsArtifact()) {
        getLog().info("artifacts are available; skipping installation");
        return;
      } else {
        getLog().info("artifacts not available; continuing installation");
      }
    }

    if (!noExtract) downloadAndExtract();

    if (!forgeDir.isDirectory())
      throw new MojoFailureException("distribution did not extract to the excpected directory");

    // run the install script
    if (!noInstall) {
      getLog().info("running install script");
      try {
        final PythonLauncher launcher = new PythonLauncher(getLog(), forgeDir);

        final int result = launcher.execute(new File(forgeDir, "install.py"));

        if (0 != result) {
          throw new MojoFailureException("install script returned " + result);
        }
      } catch (IOException caught) {
        throw new MojoFailureException("error calling install script", caught);
      }
    }

    // load Minecraft's POM
    final Model minecraft = loadModelFromResouce("minecraft.pom");
    minecraft.setVersion(getMinecraftVersion());

    // figure out Minecraft's dependencies
    {
      getLog().info("detecting Minecraft dependencies");
      final Artifact lwjgl =
          locator.findVersion(new File(jarsDir, "bin/lwjgl.jar"), "org.lwjgl.lwjgl", "lwjgl");

      final Artifact lwjgl_util =
          new DefaultArtifact("org.lwjgl.lwjgl", "lwjgl_util", "jar", lwjgl.getVersion());

      // don't include jinput.jar
      // it's a transitive dependency from LWJGL

      getLog().info("resolving Minecraft dependencies");
      for (Artifact target : new Artifact[] {lwjgl, lwjgl_util}) {
        getLog().info("    " + target);

        final Artifact resolved = resolveRemoteArtifact(target);
        if (null == resolved)
          throw new MojoFailureException("unable to resolve artifact " + target);

        minecraft.addDependency(artifactToDependency(resolved));
      }
    }

    // install Minecraft JAR
    installJar(minecraft, new File(jarsDir, "bin/minecraft.jar"));

    // figure out Forge's dependencies
    // using a Map of coordinates => artifact for deduplication
    // can't use a Set, Artifact#equals() doesn't behave
    final Map<String, Dependency> forgeDeps = new HashMap<String, Dependency>();
    for (File file : (new File(forgeDir, "mcp/lib")).listFiles()) {
      final Artifact artifact = locator.locate(file);
      if (null == artifact)
        throw new MojoFailureException("no artifact found for dependency " + file.getName());

      forgeDeps.put(artifact.toString(), artifactToDependency(artifact));
    }

    // add Minecraft client to Forge dependencies
    {
      final Artifact artifact =
          new DefaultArtifact("net.minecraft", "minecraft", "jar", getMinecraftVersion());
      forgeDeps.put(artifact.toString(), artifactToDependency(artifact));
    }

    // extract the Forge POM
    final File pom = new File(forgeDir, "pom.xml");
    {
      final Model model = loadModelFromResouce("mcforge.pom");
      model.setVersion(getApiDependency().getVersion());
      model.setDependencies(new ArrayList<Dependency>(forgeDeps.values()));
      writeModelToFile(model, pom);
    }

    // execute a build from the Forge POM
    getLog().info("executing POM to package and install artifacts");
    try {
      final MavenExecutionRequest request = new DefaultMavenExecutionRequest();
      requestPopulator.populateDefaults(request);

      request.setPom(pom);
      request.setGoals(Collections.singletonList("install"));

      final MavenExecutionResult result = maven.execute(request);

      // check for startup exceptions
      if (result.hasExceptions())
        throw new MojoFailureException(
            "failed to package and install artifacts", result.getExceptions().get(0));

      // check for build failure
      final BuildSummary summary = result.getBuildSummary(result.getProject());
      if (summary instanceof BuildFailure) {
        throw new MojoFailureException(
            "failed to package and install artifacts", ((BuildFailure) summary).getCause());
      }
    } catch (MojoFailureException caught) {
      throw caught;
    } catch (Exception caught) {
      throw new MojoFailureException("failed to package and install artifacts", caught);
    }
  }
Example #6
0
  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.");
      }
    }

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