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 Settings settingsWithJettyRepository() {
   Settings settings = new Settings();
   Profile defaultProfile = new Profile();
   defaultProfile.setId("default");
   Repository repo1 = new Repository();
   repo1.setId("repo1");
   repo1.setUrl("http://localhost:" + port + "/repository");
   defaultProfile.addRepository(repo1);
   settings.addProfile(defaultProfile);
   settings.addActiveProfile("default");
   return settings;
 }
 private Settings settingsForRepository(String id, String url) {
   Settings settings = new Settings();
   Profile profile = new Profile();
   profile.setId("test");
   Repository repo = new Repository();
   repo.setId(id);
   repo.setUrl(url);
   profile.addRepository(repo);
   settings.addProfile(profile);
   settings.addActiveProfile("test");
   return settings;
 }
 private Settings settingsWithUnresponsiveRepository() {
   Settings settings = new Settings();
   Profile defaultProfile = new Profile();
   defaultProfile.setId("default");
   Repository repo1 = new Repository();
   repo1.setId("repo1");
   // see:
   //  - https://tools.ietf.org/html/rfc5737
   //  - https://en.wikipedia.org/wiki/Reserved_IP_addresses
   repo1.setUrl("http://192.0.2.0/repository");
   defaultProfile.addRepository(repo1);
   settings.addProfile(defaultProfile);
   settings.addActiveProfile("default");
   return settings;
 }