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 static void addActiveProfileRepositories(
     List<Profile> activeProfiles, List<RepositoryConfiguration> repositoryConfiguration) {
   for (Profile activeProfile : activeProfiles) {
     for (Repository repository : activeProfile.getRepositories()) {
       repositoryConfiguration.add(
           new RepositoryConfiguration(
               repository.getId(),
               URI.create(repository.getUrl()),
               repository.getSnapshots() != null ? repository.getSnapshots().isEnabled() : false));
     }
   }
 }
 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;
 }
  @Test
  public void autoDiscoverWithOneCompleteLocationFromSettingsProfileRepoWithConfirmation()
      throws NexusDiscoveryException {
    Settings settings = new Settings();

    String url = "http://nexus.somewhere.com/";
    String id = "some-mirror";
    String user = "******";
    String password = "******";

    testClientManager.testUrl = url;
    testClientManager.testUser = user;
    testClientManager.testPassword = password;

    Server server = new Server();
    server.setId(id);
    server.setUsername(user);
    server.setPassword(password);

    settings.addServer(server);

    org.apache.maven.settings.Repository repo = new org.apache.maven.settings.Repository();
    repo.setId(id);
    repo.setUrl(url);
    repo.setName("Profile Repository");

    org.apache.maven.settings.Profile profile = new org.apache.maven.settings.Profile();
    profile.addRepository(repo);

    settings.addProfile(profile);

    Model model = new Model();
    model.setModelVersion("4.0.0");
    model.setGroupId("group.id");
    model.setArtifactId("artifact-id");
    model.setVersion("1");

    MavenProject project = new MavenProject(model);

    prompter.addExpectation("Use this connection?", "y");
    discovery.discover(settings, project, "blah", false);
  }
  @Override
  public <T> List<T> getData(String key, Class<T> type, Object... params) {
    List<T> retval = null;

    if ("profileIds".equals(key)) {
      final List<T> profileIds = new ArrayList<T>();

      try {
        final List<Profile> profiles = MavenPlugin.getMaven().getSettings().getProfiles();

        for (final Profile profile : profiles) {
          if (profile.getActivation() != null) {
            if (profile.getActivation().isActiveByDefault()) {
              continue;
            }
          }

          profileIds.add(type.cast(profile.getId()));
        }

        if (params[0] != null && params[0] instanceof File) {
          final File locationDir = (File) params[0];

          File pomFile = new File(locationDir, IMavenConstants.POM_FILE_NAME);

          if (!pomFile.exists() && locationDir.getParentFile().exists()) {
            // try one level up for when user is adding new module
            pomFile = new File(locationDir.getParentFile(), IMavenConstants.POM_FILE_NAME);
          }

          if (pomFile.exists()) {
            final IMaven maven = MavenPlugin.getMaven();

            Model model = maven.readModel(pomFile);

            File parentDir = pomFile.getParentFile();

            while (model != null) {
              for (org.apache.maven.model.Profile p : model.getProfiles()) {
                profileIds.add(type.cast(p.getId()));
              }

              parentDir = parentDir.getParentFile();

              if (parentDir != null && parentDir.exists()) {
                try {
                  model = maven.readModel(new File(parentDir, IMavenConstants.POM_FILE_NAME));
                } catch (Exception e) {
                  model = null;
                }
              }
            }
          }
        }
      } catch (CoreException e) {
        LiferayMavenCore.logError(e);
      }

      retval = profileIds;
    } else if ("liferayVersions".equals(key)) {
      final List<T> possibleVersions = new ArrayList<T>();

      final RepositorySystem system = AetherUtil.newRepositorySystem();

      final RepositorySystemSession session = AetherUtil.newRepositorySystemSession(system);

      final String groupId = params[0].toString();
      final String artifactId = params[1].toString();

      final String coords = groupId + ":" + artifactId + ":[6,)";

      final Artifact artifact = new DefaultArtifact(coords);

      final VersionRangeRequest rangeRequest = new VersionRangeRequest();
      rangeRequest.setArtifact(artifact);
      rangeRequest.addRepository(AetherUtil.newCentralRepository());
      rangeRequest.addRepository(AetherUtil.newLiferayRepository());

      try {
        final VersionRangeResult rangeResult = system.resolveVersionRange(session, rangeRequest);

        final List<Version> versions = rangeResult.getVersions();

        for (Version version : versions) {
          final String val = version.toString();

          if (!"6.2.0".equals(val)) {
            possibleVersions.add(type.cast(val));
          }
        }

        retval = possibleVersions;
      } catch (VersionRangeResolutionException e) {
      }
    } else if ("parentVersion".equals(key)) {
      final List<T> version = new ArrayList<T>();

      final File locationDir = (File) params[0];

      final File parentPom = new File(locationDir, IMavenConstants.POM_FILE_NAME);

      if (parentPom.exists()) {
        try {
          final IMaven maven = MavenPlugin.getMaven();

          final Model model = maven.readModel(parentPom);

          version.add(type.cast(model.getVersion()));

          retval = version;
        } catch (CoreException e) {
          LiferayMavenCore.logError("unable to get parent version", e);
        }
      }
    } else if ("parentGroupId".equals(key)) {
      final List<T> groupId = new ArrayList<T>();

      final File locationDir = (File) params[0];

      final File parentPom = new File(locationDir, IMavenConstants.POM_FILE_NAME);

      if (parentPom.exists()) {
        try {
          final IMaven maven = MavenPlugin.getMaven();

          final Model model = maven.readModel(parentPom);

          groupId.add(type.cast(model.getGroupId()));

          retval = groupId;
        } catch (CoreException e) {
          LiferayMavenCore.logError("unable to get parent groupId", e);
        }
      }
    }

    return retval;
  }
  protected String getNewLiferayProfilesPluginVersion(
      String[] activeProfiles,
      List<NewLiferayProfile> newLiferayProfiles,
      String archetypeVersion) {
    org.osgi.framework.Version minVersion =
        new org.osgi.framework.Version(archetypeVersion.substring(0, 3));

    try {
      final List<Profile> profiles = MavenPlugin.getMaven().getSettings().getProfiles();

      org.osgi.framework.Version minNewVersion =
          new org.osgi.framework.Version(archetypeVersion.substring(0, 3));

      org.osgi.framework.Version minExistedVersion =
          new org.osgi.framework.Version(archetypeVersion.substring(0, 3));

      for (final String activeProfile : activeProfiles) {
        for (final NewLiferayProfile newProfile : newLiferayProfiles) {
          if (activeProfile.equals(newProfile.getId().content())) {
            final String liferayVersion = newProfile.getLiferayVersion().content();

            final org.osgi.framework.Version shortLiferayVersion =
                new org.osgi.framework.Version(liferayVersion.substring(0, 3));

            final org.osgi.framework.Version shortPluginVersion =
                new org.osgi.framework.Version(archetypeVersion.substring(0, 3));

            minNewVersion =
                shortLiferayVersion.compareTo(shortPluginVersion) < 0
                    ? shortLiferayVersion
                    : shortPluginVersion;
          }
        }

        minVersion = minVersion.compareTo(minNewVersion) < 0 ? minVersion : minNewVersion;

        for (final Profile existProfile : profiles) {
          if (activeProfile.equals(existProfile.getId())) {
            final Properties properties = existProfile.getProperties();
            final String liferayVersion = properties.getProperty("liferay.version");
            final String pluginVersion = properties.getProperty("liferay.maven.plugin.version");

            if (pluginVersion != null && liferayVersion != null) {
              final org.osgi.framework.Version shortLiferayVersion =
                  new org.osgi.framework.Version(liferayVersion.substring(0, 3));

              final org.osgi.framework.Version shortPluginVersion =
                  new org.osgi.framework.Version(pluginVersion.substring(0, 3));

              minExistedVersion =
                  shortLiferayVersion.compareTo(shortPluginVersion) < 0
                      ? shortLiferayVersion
                      : shortPluginVersion;
            }
          }
        }

        minVersion = minVersion.compareTo(minExistedVersion) < 0 ? minVersion : minExistedVersion;
      }
    } catch (Exception e) {
    }

    return minVersion.toString();
  }