コード例 #1
0
  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());
    }
  }
コード例 #2
0
 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;
 }
コード例 #3
0
 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;
 }
コード例 #4
0
 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;
 }
コード例 #5
0
  @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);
  }