コード例 #1
0
  private MavenProject buildProjectStub(final Artifact depArtifact) {
    final Model model = new Model();
    model.setGroupId(depArtifact.getGroupId());
    model.setArtifactId(depArtifact.getArtifactId());
    model.setVersion(depArtifact.getBaseVersion());
    model.setPackaging(depArtifact.getType());

    model.setDescription("Stub for " + depArtifact.getId());

    final MavenProject project = new MavenProject(model);
    project.setArtifact(depArtifact);

    return project;
  }
コード例 #2
0
  protected void setAttributes(Model model) {
    if (this.getGroupId() != null) {
      model.setGroupId(this.getGroupId());
    }
    if (this.getArtifactId() != null) {
      model.setArtifactId(this.getArtifactId());
    }
    if (this.getVersion() != null) {
      model.setVersion(this.getVersion());
    }
    if (this.getPackaging() != null) {
      model.setPackaging(this.getPackaging());
    }
    if (this.getName() != null) {
      model.setName(this.getName());
    }

    if (this.getDesc() != null) {
      model.setDescription(this.getDesc());
    }
  }
コード例 #3
0
  /**
   * Write the POM file corresponding to a given maven file
   *
   * @param mvnFile the maven file
   * @param file the pom file to be written to
   * @throws MojoExecutionException when any issue occurs
   */
  private void writePomFile(MavenFile mvnFile, File file) throws MojoExecutionException {
    Model model = mvnFile.getModel();

    model.setDescription(
        "POM file generated by maven-mavenizer-plugin for "
            + mvnFile.getFile().getName()
            + " from archive "
            + getArchiveFile().getName());
    if (getArchiveURL() != null) {
      model.setUrl(getArchiveURL().toString());
    }

    Writer writer = null;
    try {
      writer = WriterFactory.newXmlWriter(file);
      new MavenXpp3Writer().write(writer, model);
    } catch (IOException e) {
      throw new MojoExecutionException(
          "Error writing " + file.getAbsolutePath() + " : " + e.getMessage(), e);
    } finally {
      IOUtil.close(writer);
    }
  }
コード例 #4
0
ファイル: Project.java プロジェクト: sveryovka/polyglot-maven
  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;
  }