コード例 #1
0
ファイル: MavenCli.java プロジェクト: sonatype/maven-demo
  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("");
    }
  }
コード例 #2
0
ファイル: MavenSystemImpl.java プロジェクト: sammyt/mvnsh
    private void configureSettings(final MavenExecutionRequest request) throws Exception {
      assert request != null;
      assert config != null;

      File userSettingsFile = config.getSettingsFile();
      if (userSettingsFile != null) {
        userSettingsFile = resolveFile(userSettingsFile, config.getBaseDirectory());
        if (!userSettingsFile.isFile()) {
          throw new FileNotFoundException(
              "The specified user settings file does not exist: " + userSettingsFile); // TODO: i18n
        }
      } else {
        userSettingsFile = DEFAULT_USER_SETTINGS_FILE;
      }

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

      File globalSettingsFile = config.getGlobalSettingsFile();
      if (globalSettingsFile != null) {
        globalSettingsFile = resolveFile(globalSettingsFile, config.getBaseDirectory());
        if (!globalSettingsFile.isFile()) {
          throw new FileNotFoundException(
              "The specified global settings file does not exist: "
                  + globalSettingsFile); // TODO: i18n
        }
      } else {
        globalSettingsFile = DEFAULT_GLOBAL_SETTINGS_FILE;
      }

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

      configureProperties(request);

      SettingsBuildingRequest settingsRequest =
          new DefaultSettingsBuildingRequest()
              .setGlobalSettingsFile(globalSettingsFile)
              .setUserSettingsFile(userSettingsFile)
              .setSystemProperties(request.getSystemProperties())
              .setUserProperties(request.getUserProperties());

      SettingsBuildingResult settingsResult;
      SettingsBuilder settingsBuilder = container.lookup(SettingsBuilder.class);
      try {
        settingsResult = settingsBuilder.build(settingsRequest);
      } finally {
        container.release(settingsBuilder);
      }

      // NOTE: This will nuke some details from the request; profiles, online, etc... :-(
      MavenExecutionRequestPopulator populator =
          container.lookup(MavenExecutionRequestPopulator.class);
      try {
        populator.populateFromSettings(request, settingsResult.getEffectiveSettings());
      } finally {
        container.release(populator);
      }

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

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

        logger.warn("");
      }
    }