public void setUnits(final List<Unit> units) {
    removeChild(dom, "units");
    final Xpp3Dom unitsDom = new Xpp3Dom("units");

    for (final Unit unit : units) {
      unitsDom.addChild(unit.getDom());
    }
    unitsDom.setAttribute("size", Integer.toString(units.size()));

    dom.addChild(unitsDom);
  }
示例#2
0
 /**
  * Recursively convert PLEXUS config to Xpp3Dom.
  *
  * @param config The config to convert
  * @return The Xpp3Dom document
  * @see #execute(String,String,Properties)
  */
 private Xpp3Dom toXppDom(final PlexusConfiguration config) {
   final Xpp3Dom result = new Xpp3Dom(config.getName());
   result.setValue(config.getValue(null));
   for (final String name : config.getAttributeNames()) {
     try {
       result.setAttribute(name, config.getAttribute(name));
     } catch (final PlexusConfigurationException ex) {
       throw new IllegalArgumentException(ex);
     }
   }
   for (final PlexusConfiguration child : config.getChildren()) {
     result.addChild(this.toXppDom(child));
   }
   return result;
 }
 public void setVersion(String version) {
   dom.setAttribute("version", version);
 }
示例#4
0
  public void verifyWriter() throws IOException, DocumentException {
    String expectedXml = FileUtils.fileRead(getTestFile("src/test/verifiers/dom4j/expected.xml"));
    expectedXml = expectedXml.replaceAll("(\r\n)|(\r)", "\n");

    // ----------------------------------------------------------------------
    // Build the model thats going to be written.
    // ----------------------------------------------------------------------

    Model expected = new Model();

    expected.setExtend("/foo/bar");

    expected.setName("Maven");

    expected.setModelVersion("4.0.0");

    MailingList mailingList = new MailingList();

    mailingList.setName("Mailing list");

    mailingList.setSubscribe("Super Subscribe");

    mailingList.setUnsubscribe("Duper Unsubscribe");

    mailingList.setArchive("?ber Archive");

    expected.addMailingList(mailingList);

    Scm scm = new Scm();

    String connection = "connection";

    String developerConnection = "developerConnection";

    String url = "url";

    scm.setConnection(connection);

    scm.setDeveloperConnection(developerConnection);

    scm.setUrl(url);

    expected.setScm(scm);

    Build build = new Build();

    build.setSourceDirectory("src/main/java");

    build.setUnitTestSourceDirectory("src/test/java");

    SourceModification sourceModification = new SourceModification();

    sourceModification.setClassName("excludeEclipsePlugin");

    sourceModification.setDirectory("foo");

    sourceModification.addExclude("de/abstrakt/tools/codegeneration/eclipse/*.java");

    build.addSourceModification(sourceModification);

    expected.setBuild(build);

    Component component = new Component();

    component.setName("component1");

    expected.addComponent(component);

    component = new Component();

    component.setName("component2");

    component.setComment("comment2");

    expected.addComponent(component);

    Component c2 = new Component();

    c2.setName("sub");

    c2.setComment("subcomment");

    component.getComponents().add(c2);

    component = new Component();

    component.setName("component3");

    Xpp3Dom xpp3Dom = new Xpp3Dom("custom");
    Xpp3Dom child = new Xpp3Dom("foo");
    child.setValue("bar");
    xpp3Dom.addChild(child);
    child = new Xpp3Dom("bar");
    child.setAttribute("att1", "value");
    child.setValue("baz");
    xpp3Dom.addChild(child);
    child = new Xpp3Dom("el1");
    xpp3Dom.addChild(child);
    Xpp3Dom el1 = child;
    child = new Xpp3Dom("el2");
    child.setValue("text");
    el1.addChild(child);

    component.setCustom(xpp3Dom);

    expected.addComponent(component);

    component = new Component();
    component.setName("component4");
    expected.addComponent(component);

    Properties properties = new Properties();
    properties.setProperty("name", "value");
    component.setFlatProperties(properties);

    properties = new Properties();
    properties.setProperty("key", "theValue");
    component.setProperties(properties);

    Repository repository = new Repository();
    repository.setId("foo");
    expected.addRepository(repository);

    // ----------------------------------------------------------------------
    // Write out the model
    // ----------------------------------------------------------------------

    MavenDom4jWriter writer = new MavenDom4jWriter();

    StringWriter buffer = new StringWriter();

    writer.write(buffer, expected);

    String actualXml = buffer.toString();
    actualXml = actualXml.replaceAll("(\r\n)|(\r)", "\n");

    //        System.out.println( expectedXml );
    //
    //        System.err.println( actualXml );

    Assert.assertEquals(expectedXml.trim(), actualXml.trim());

    MavenDom4jReader reader = new MavenDom4jReader();

    Model actual = reader.read(new StringReader(actualXml));

    Assert.assertNotNull("Actual", actual);

    assertModel(expected, actual);

    buffer = new StringWriter();

    writer.write(buffer, actual);

    Assert.assertEquals(
        expectedXml.trim(), buffer.toString().trim().replaceAll("(\r\n)|(\r)", "\n"));
  }