@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);
  }
  @Test
  public void promptWithTwoPotentialLocationsFromMirrors() 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);

    Mirror mirror2 = new Mirror();
    mirror2.setId("some-other-mirror");
    mirror2.setName("Another Mirror");
    mirror2.setUrl("http://nexus.somewhere-else.com/");

    settings.addMirror(mirror2);

    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());
  }
  @Test
  public void autoDiscoverWithOneCompleteLocationFromSnapshotPOMDistMgmt()
      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);

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

    DistributionManagement dm = new DistributionManagement();

    DeploymentRepository repo = new DeploymentRepository();
    repo.setId(id);
    repo.setUrl(url);

    dm.setSnapshotRepository(repo);

    model.setDistributionManagement(dm);

    MavenProject project = new MavenProject(model);

    project.setArtifact(factory.create(project));

    discovery.discover(settings, project, "blah", true);
  }
  @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);
  }
  @Test
  public void autoDiscoverWithOneCompleteLocationFromPOMRepo() 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);

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

    Repository repo = new Repository();
    repo.setId(id);
    repo.setUrl(url);

    model.addRepository(repo);

    MavenProject project = new MavenProject(model);

    discovery.discover(settings, project, "blah", true);
  }
 /** According to setting, create Maven Model. */
 protected Model createModel() {
   Model model = new Model();
   model.setModelVersion(TalendMavenConstants.POM_VERSION);
   configModel(model);
   return model;
 }
示例#7
0
  public Model toMavenModel() {
    Model model = new Model();
    model.setBuild(new Build());
    model.setDescription(description);
    model.setUrl(url);
    model.setName(projectId.getArtifact());
    model.setGroupId(projectId.getGroup());
    model.setVersion(projectId.getVersion());
    model.setArtifactId(projectId.getArtifact());
    model.setModelVersion("4.0.0");

    // parent
    if (parent != null) {
      model.setParent(parent);
    }

    model.setPackaging(packaging);

    if (properties != null) {
      Properties modelProperties = new Properties();
      for (Property p : properties) {
        modelProperties.setProperty(p.getKey(), p.getValue());
      }
      model.setProperties(modelProperties);
    }

    // Add jar repository urls.
    if (null != repositories) {
      for (String repoUrl : repositories.getRepositories()) {
        Repository repository = new Repository();
        repository.setId(Integer.toString(repoUrl.hashCode()));
        repository.setUrl(repoUrl);
        model.addRepository(repository);
      }
    }

    // Add dependency management
    if (overrides != null) {
      DependencyManagement depMan = new DependencyManagement();
      for (Id dep : overrides) {
        Dependency dependency = new Dependency();
        dependency.setGroupId(dep.getGroup());
        dependency.setArtifactId(dep.getArtifact());
        dependency.setVersion(dep.getVersion());
        // JVZ: We need to parse these
        dependency.setType("jar");

        if (null != dep.getClassifier()) {
          dependency.setClassifier(dep.getClassifier());
        }
        depMan.addDependency(dependency);
      }
      model.setDependencyManagement(depMan);
    }

    // Add project dependencies.
    if (deps != null) {
      for (Id dep : deps) {
        Dependency dependency = new Dependency();
        dependency.setGroupId(dep.getGroup());
        dependency.setArtifactId(dep.getArtifact());
        dependency.setVersion(dep.getVersion());
        // JVZ: We need to parse these
        dependency.setType("jar");

        if (null != dep.getClassifier()) {
          dependency.setClassifier(dep.getClassifier());
        }
        model.addDependency(dependency);
      }
    }

    if (modules != null) {
      model.setModules(modules);
    }

    if (pluginOverrides != null) {
      PluginManagement management = new PluginManagement();
      management.setPlugins(pluginOverrides);
      model.getBuild().setPluginManagement(management);
    }

    if (plugins != null) {
      model.getBuild().setPlugins(plugins);
    }

    // Optional source dirs customization.
    if (dirs != null) {
      Build build = new Build();
      String srcDir = dirs.get("src");
      String testDir = dirs.get("test");

      if (null != srcDir) build.setSourceDirectory(srcDir);

      if (null != testDir) build.setTestSourceDirectory(testDir);

      model.setBuild(build);
    }

    if (null != scm) {
      Scm scm = new Scm();
      scm.setConnection(this.scm.getConnection());
      scm.setDeveloperConnection(this.scm.getDeveloperConnection());
      scm.setUrl(this.scm.getUrl());

      model.setScm(scm);
    }

    return model;
  }