@Test
  public void autoDiscoverWithOneCompleteLocationFromMirrorWithEncryptedPassword()
      throws NexusDiscoveryException {
    Settings settings = new Settings();

    String url = "http://nexus.somewhere.com/";

    testClientManager.testUrl = url;
    testClientManager.testUser = "******";
    testClientManager.testPassword = "******";

    Mirror mirror = new Mirror();
    mirror.setId("some-mirror");
    mirror.setName("A Mirror");
    mirror.setUrl(url);

    settings.addMirror(mirror);

    Server server = new Server();
    server.setId("some-mirror");
    server.setUsername("user");
    server.setPassword(encryptedPassword);

    settings.addServer(server);

    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);

    discovery.discover(settings, project, "blah", true);
  }
Пример #2
0
 private Mirror getMirror(RepositorySystemSession session, ArtifactRepository repository) {
   if (session != null) {
     org.eclipse.aether.repository.MirrorSelector selector = session.getMirrorSelector();
     if (selector != null) {
       RemoteRepository repo = selector.getMirror(RepositoryUtils.toRepo(repository));
       if (repo != null) {
         Mirror mirror = new Mirror();
         mirror.setId(repo.getId());
         mirror.setUrl(repo.getUrl());
         mirror.setLayout(repo.getContentType());
         return mirror;
       }
     }
   }
   return null;
 }
Пример #3
0
  public static Mirror getMirror(ArtifactRepository repository, List<Mirror> mirrors) {
    String repoId = repository.getId();

    if (repoId != null && mirrors != null) {
      for (Mirror mirror : mirrors) {
        if (repoId.equals(mirror.getMirrorOf()) && matchesLayout(repository, mirror)) {
          return mirror;
        }
      }

      for (Mirror mirror : mirrors) {
        if (matchPattern(repository, mirror.getMirrorOf()) && matchesLayout(repository, mirror)) {
          return mirror;
        }
      }
    }

    return null;
  }
Пример #4
0
  private void injectMirror(ArtifactRepository repository, Mirror mirror) {
    if (mirror != null) {
      ArtifactRepository original =
          createArtifactRepository(
              repository.getId(),
              repository.getUrl(),
              repository.getLayout(),
              repository.getSnapshots(),
              repository.getReleases());

      repository.setMirroredRepositories(Collections.singletonList(original));

      repository.setId(mirror.getId());
      repository.setUrl(mirror.getUrl());

      if (StringUtils.isNotEmpty(mirror.getLayout())) {
        repository.setLayout(getLayout(mirror.getLayout()));
      }
    }
  }
  private URI getMirror(TargetDefinition.Repository location, List<Mirror> mirrors)
      throws URISyntaxException {
    URI p2RepositoryLocation = location.getLocation();
    String id = location.getId();
    if (id == null) {
      id = p2RepositoryLocation.toString();
    }

    ArtifactRepository repository =
        repositorySystem.createArtifactRepository(
            id,
            p2RepositoryLocation.toString(),
            p2layout,
            P2_REPOSITORY_POLICY,
            P2_REPOSITORY_POLICY);

    Mirror mirror = repositorySystem.getMirror(repository, mirrors);

    return mirror != null ? new URI(mirror.getUrl()) : p2RepositoryLocation;
  }
  @Test
  public void promptWithOnePotentialLocationFromMirrors() throws NexusDiscoveryException {
    Settings settings = new Settings();

    String url = "http://nexus.somewhere.com/";
    String user = "******";
    String password = "******";

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

    Mirror mirror = new Mirror();
    mirror.setId("some-mirror");
    mirror.setName("A Mirror");
    mirror.setUrl(url);

    settings.addMirror(mirror);

    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("1", "http://nexus.somewhere.com/", "Selection:");
    prompter.addExpectation("Enter Username", user);
    prompter.addExpectation("Enter Password", password);

    NexusConnectionInfo info = discovery.discover(settings, project, "blah", false);
    assertNotNull(info);
    assertEquals(url, info.getNexusUrl());
    assertEquals(user, info.getUser());
    assertEquals(password, info.getPassword());
  }
  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;
  }
Пример #8
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;
  }
Пример #10
0
 static boolean matchesLayout(ArtifactRepository repository, Mirror mirror) {
   return matchesLayout(RepositoryUtils.getLayout(repository), mirror.getMirrorOfLayouts());
 }