private Dependency toDependency(String id, String version, String type) throws ResolveException {
    Matcher matcher = PARSER_ID.matcher(id);
    if (!matcher.matches()) {
      throw new ResolveException(
          "Bad id " + id + ", expected format is <groupId>:<artifactId>[:<classifier>]");
    }

    Dependency dependency = new Dependency();

    dependency.setGroupId(matcher.group(1));
    dependency.setArtifactId(matcher.group(2));
    if (matcher.group(4) != null) {
      dependency.setClassifier(StringUtils.defaultString(matcher.group(4), ""));
    }

    if (version != null) {
      dependency.setVersion(version);
    }

    if (type != null) {
      dependency.setType(type);
    }

    return dependency;
  }
  protected Dependency createDependency() {
    Dependency d = new Dependency();
    d.setGroupId(dependencyGroupId);
    d.setArtifactId(dependencyArtifactId);
    d.setVersion(dependencyVersion);
    d.setType(dependencyType);
    d.setClassifier(dependencyClassifier);

    return d;
  }
  public List<Dependency> getDependencyMgtList(ArtifactItem item) {
    Dependency dep = new Dependency();
    dep.setArtifactId(item.getArtifactId());
    dep.setClassifier(item.getClassifier());
    dep.setGroupId(item.getGroupId());
    dep.setType(item.getType());
    dep.setVersion("3.0-SNAPSHOT");

    Dependency dep2 = new Dependency();
    dep2.setArtifactId(item.getArtifactId());
    dep2.setClassifier("classifier");
    dep2.setGroupId(item.getGroupId());
    dep2.setType(item.getType());
    dep2.setVersion("3.1");

    List<Dependency> list = new ArrayList<Dependency>(2);
    list.add(dep2);
    list.add(dep);

    return list;
  }
Exemplo n.º 4
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;
  }