Ejemplo n.º 1
0
 public void setUp() throws Exception {
   mojo = new CopyModulesMojo();
   model = new Model();
   project = new MavenProject(model);
   properties = new Properties();
   model.setProperties(properties);
   model.setPackaging("war");
 }
 @SuppressWarnings("nls")
 protected void addProperties(Model model) {
   // set the properties
   Properties p = model.getProperties();
   if (p == null) {
     p = new Properties();
     model.setProperties(p);
   }
 }
Ejemplo n.º 3
0
 @Test
 public void testModelWriter() throws Exception {
   StringWriter sw = new StringWriter();
   ModelWriter writer = new YamlModelWriter();
   Model model = getModel();
   Properties p = new Properties();
   p.setProperty("FOO", "BAR");
   model.setProperties(p);
   writer.write(sw, null, model);
   // System.out.println(sw.toString());
 }
Ejemplo n.º 4
0
  private void initialize() {
    if (isStale() || currentModel == null) {
      try (InputStream stream = getResourceInputStream()) {
        MavenXpp3Reader reader = new MavenXpp3Reader();
        currentModel = reader.read(stream);
        currentModel.setPomFile(getUnderlyingResourceObject());

        // FORGE-2273: Making properties sortable
        SortedProperties sortedProps = new SortedProperties();
        sortedProps.putAll(currentModel.getProperties());
        currentModel.setProperties(sortedProps);
      } catch (Exception e) {
        throw new RuntimeException(e);
      } finally {
        refresh();
      }
    }
  }
Ejemplo n.º 5
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;
  }