public void update(Settings settings, File settingsFile) throws ManipulationException {
    try {
      Settings defaultSettings = new Settings();

      if (settingsFile.exists()) {
        DefaultSettingsBuildingRequest settingsRequest = new DefaultSettingsBuildingRequest();
        settingsRequest.setGlobalSettingsFile(settingsFile);
        defaultSettings = settingsBuilder.build(settingsRequest).getEffectiveSettings();
      }

      for (Profile profile : settings.getProfiles()) {
        Iterator<Profile> i = defaultSettings.getProfiles().iterator();
        while (i.hasNext()) {
          if (i.next().getId().equals(profile.getId())) {
            i.remove();
          }
        }
        defaultSettings.addProfile(profile);
      }
      for (String activeProfile : settings.getActiveProfiles()) {
        Iterator<String> i = defaultSettings.getActiveProfiles().iterator();
        while (i.hasNext()) {
          if (i.next().equals(activeProfile)) {
            i.remove();
          }
        }
        defaultSettings.addActiveProfile(activeProfile);
      }
      for (Mirror mirror : settings.getMirrors()) {
        defaultSettings.addMirror(mirror);
      }
      for (Proxy proxy : settings.getProxies()) {
        defaultSettings.addProxy(proxy);
      }
      for (Server server : settings.getServers()) {
        defaultSettings.addServer(server);
      }
      for (String pluginGroup : settings.getPluginGroups()) {
        defaultSettings.addPluginGroup(pluginGroup);
      }
      if (settings.getLocalRepository() != null) {
        defaultSettings.setLocalRepository(settings.getLocalRepository());
      }

      write(defaultSettings, settingsFile);
    } catch (SettingsBuildingException e) {
      throw new ManipulationException(
          "Failed to build existing settings.xml for repo removal backup.",
          e,
          settingsFile,
          e.getMessage());
    }
  }
  private MirrorSelector getMirrorSelector(Settings settings) {
    DefaultMirrorSelector selector = new DefaultMirrorSelector();
    for (Mirror mirror : settings.getMirrors()) {
      selector.add(
          String.valueOf(mirror.getId()),
          mirror.getUrl(),
          mirror.getLayout(),
          false,
          mirror.getMirrorOf(),
          mirror.getMirrorOfLayouts());
    }

    return selector;
  }
Exemplo n.º 3
0
  /**
   * Gets mirror selector
   *
   * @return the selector
   */
  public MirrorSelector mirrorSelector() {

    DefaultMirrorSelector dms = new DefaultMirrorSelector();

    // fill in mirrors
    for (Mirror mirror : settings.getMirrors()) {
      // Repository manager flag is set to false
      // Maven does not support specifying it in the settings.xml
      dms.add(
          mirror.getId(),
          mirror.getUrl(),
          mirror.getLayout(),
          false,
          mirror.getMirrorOf(),
          mirror.getMirrorOfLayouts());
    }

    return dms;
  }
  private MirrorSelector getMirrorSelector() {
    DefaultMirrorSelector selector = new DefaultMirrorSelector();

    for (Mirror mirror : mirrors) {
      selector.add(
          mirror.getId(), mirror.getUrl(), mirror.getType(), false, mirror.getMirrorOf(), null);
    }

    Settings settings = getSettings();
    for (org.apache.maven.settings.Mirror mirror : settings.getMirrors()) {
      selector.add(
          String.valueOf(mirror.getId()),
          mirror.getUrl(),
          mirror.getLayout(),
          false,
          mirror.getMirrorOf(),
          mirror.getMirrorOfLayouts());
    }

    return selector;
  }