private static Settings buildSettings(
      SettingsBuilder builder,
      MavenServerSettings settings,
      Properties systemProperties,
      Properties userProperties)
      throws RemoteException {
    SettingsBuildingRequest settingsRequest = new DefaultSettingsBuildingRequest();
    settingsRequest.setGlobalSettingsFile(settings.getGlobalSettingsFile());
    settingsRequest.setUserSettingsFile(settings.getUserSettingsFile());
    settingsRequest.setSystemProperties(systemProperties);
    settingsRequest.setUserProperties(userProperties);

    Settings result = new Settings();
    try {
      result = builder.build(settingsRequest).getEffectiveSettings();
    } catch (SettingsBuildingException e) {
      Maven3ServerGlobals.getLogger().info(e);
    }

    if (settings.getLocalRepository() != null) {
      result.setLocalRepository(settings.getLocalRepository().getPath());
    }

    if (result.getLocalRepository() == null) {
      result.setLocalRepository(
          new File(SystemProperties.getUserHome(), ".m2/repository").getPath());
    }

    return result;
  }
Exemple #2
0
  private void settings(CliRequest cliRequest) throws Exception {
    File userSettingsFile;

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

      if (!userSettingsFile.isFile()) {
        throw new FileNotFoundException(
            "The specified user settings file does not exist: " + userSettingsFile);
      }
    } else {
      userSettingsFile = DEFAULT_USER_SETTINGS_FILE;
    }

    logger.debug("Reading user settings from " + userSettingsFile);

    File globalSettingsFile;

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

      if (!globalSettingsFile.isFile()) {
        throw new FileNotFoundException(
            "The specified global settings file does not exist: " + globalSettingsFile);
      }
    } else {
      globalSettingsFile = DEFAULT_GLOBAL_SETTINGS_FILE;
    }

    logger.debug("Reading global settings from " + globalSettingsFile);

    cliRequest.request.setGlobalSettingsFile(globalSettingsFile);
    cliRequest.request.setUserSettingsFile(userSettingsFile);

    SettingsBuildingRequest settingsRequest = new DefaultSettingsBuildingRequest();
    settingsRequest.setGlobalSettingsFile(globalSettingsFile);
    settingsRequest.setUserSettingsFile(userSettingsFile);
    settingsRequest.setSystemProperties(cliRequest.systemProperties);
    settingsRequest.setUserProperties(cliRequest.userProperties);

    SettingsBuildingResult settingsResult = settingsBuilder.build(settingsRequest);

    executionRequestPopulator.populateFromSettings(
        cliRequest.request, settingsResult.getEffectiveSettings());

    if (!settingsResult.getProblems().isEmpty() && logger.isWarnEnabled()) {
      logger.warn("");
      logger.warn("Some problems were encountered while building the effective settings");

      for (SettingsProblem problem : settingsResult.getProblems()) {
        logger.warn(problem.getMessage() + " @ " + problem.getLocation());
      }

      logger.warn("");
    }
  }
  /**
   * Loads default Maven settings from standard location or from a location specified by a property
   *
   * @return
   */
  public Settings buildDefaultSettings() {
    SettingsBuildingRequest request =
        new DefaultSettingsBuildingRequest().setSystemProperties(SecurityActions.getProperties());

    String altUserSettings = SecurityActions.getProperty(ALT_USER_SETTINGS_XML_LOCATION);
    String altGlobalSettings = SecurityActions.getProperty(ALT_GLOBAL_SETTINGS_XML_LOCATION);

    request.setUserSettingsFile(new File(DEFAULT_USER_SETTINGS_PATH));
    // set alternate files
    if (altUserSettings != null && altUserSettings.length() > 0) {
      request.setUserSettingsFile(new File(altUserSettings));
    }

    if (altGlobalSettings != null && altGlobalSettings.length() > 0) {
      request.setGlobalSettingsFile(new File(altGlobalSettings));
    }

    return buildSettings(request);
  }