private Yaml prepareLoader(ClassLoader classLoader) {
    final Constructor constructor = new MyConstructor(Holder.class, classLoader);
    final TypeDescription typeDescription = new TypeDescription(Holder.class);
    typeDescription.putListPropertyType("prototypes", DefaultEntityPrototype.class);
    constructor.addTypeDescription(typeDescription);

    final Loader loader = new Loader(constructor);
    final Yaml yaml = new Yaml(loader);
    return yaml;
  }
Example #2
0
  public static XmlSuite parse(String filePath, InputStream is) throws FileNotFoundException {
    Constructor constructor = new TestNGConstructor(XmlSuite.class);
    {
      TypeDescription suiteDescription = new TypeDescription(XmlSuite.class);
      suiteDescription.putListPropertyType("packages", XmlPackage.class);
      suiteDescription.putListPropertyType("listeners", String.class);
      suiteDescription.putListPropertyType("tests", XmlTest.class);
      suiteDescription.putListPropertyType("method-selectors", XmlMethodSelector.class);
      constructor.addTypeDescription(suiteDescription);
    }

    {
      TypeDescription testDescription = new TypeDescription(XmlTest.class);
      testDescription.putListPropertyType("classes", XmlClass.class);
      testDescription.putMapPropertyType("metaGroups", String.class, List.class);
      testDescription.putListPropertyType("method-selectors", XmlMethodSelector.class);
      constructor.addTypeDescription(testDescription);
    }

    org.yaml.snakeyaml.Yaml y = new org.yaml.snakeyaml.Yaml(constructor);
    if (is == null) is = new FileInputStream(new File(filePath));
    XmlSuite result = (XmlSuite) y.load(is);

    result.setFileName(filePath);
    // DEBUG
    //    System.out.println("[Yaml] " + result.toXml());

    // Adjust XmlTest parents and indices
    for (XmlTest t : result.getTests()) {
      t.setSuite(result);
      int index = 0;
      for (XmlClass c : t.getClasses()) {
        c.setIndex(index++);
      }
    }

    return result;
  }
  public ModelConstructor() {
    super(Model.class);

    yamlConstructors.put(Tags.MAP, new ConstructXpp3Dom());

    TypeDescription desc;

    desc = new TypeDescription(Model.class);
    desc.putListPropertyType("licenses", License.class);
    desc.putListPropertyType("mailingLists", MailingList.class);
    desc.putListPropertyType("dependencies", Dependency.class);
    desc.putListPropertyType("modules", String.class);
    desc.putListPropertyType("profiles", Profile.class);
    desc.putListPropertyType("repositories", Repository.class);
    desc.putListPropertyType("pluginRepositories", Repository.class);
    desc.putListPropertyType("developers", Developer.class);
    desc.putListPropertyType("contributors", Contributor.class);
    addTypeDescription(desc);

    desc = new TypeDescription(Dependency.class);
    desc.putListPropertyType("exclusions", Exclusion.class);
    addTypeDescription(desc);

    desc = new TypeDescription(DependencyManagement.class);
    desc.putListPropertyType("dependencies", Dependency.class);
    addTypeDescription(desc);

    desc = new TypeDescription(Build.class);
    desc.putListPropertyType("extensions", Extension.class);
    desc.putListPropertyType("resources", Resource.class);
    desc.putListPropertyType("testResources", Resource.class);
    desc.putListPropertyType("filters", String.class);
    desc.putListPropertyType("plugins", Plugin.class);
    addTypeDescription(desc);

    desc = new TypeDescription(BuildBase.class);
    desc.putListPropertyType("resources", Resource.class);
    desc.putListPropertyType("testResources", Resource.class);
    desc.putListPropertyType("filters", String.class);
    desc.putListPropertyType("plugins", Plugin.class);
    addTypeDescription(desc);

    desc = new TypeDescription(PluginManagement.class);
    desc.putListPropertyType("plugins", Plugin.class);
    addTypeDescription(desc);

    desc = new TypeDescription(Plugin.class);
    desc.putListPropertyType("executions", PluginExecution.class);
    addTypeDescription(desc);

    desc = new TypeDescription(PluginExecution.class);
    desc.putListPropertyType("goals", String.class);
    addTypeDescription(desc);

    desc = new TypeDescription(Reporting.class);
    desc.putListPropertyType("plugins", ReportPlugin.class);
    addTypeDescription(desc);

    desc = new TypeDescription(ReportPlugin.class);
    desc.putListPropertyType("reportSets", ReportSet.class);
    addTypeDescription(desc);

    desc = new TypeDescription(ReportSet.class);
    desc.putListPropertyType("reports", String.class);
    addTypeDescription(desc);

    desc = new TypeDescription(CiManagement.class);
    desc.putListPropertyType("notifiers", Notifier.class);
    addTypeDescription(desc);

    desc = new TypeDescription(Developer.class);
    desc.putListPropertyType("roles", String.class);
    addTypeDescription(desc);

    desc = new TypeDescription(Contributor.class);
    desc.putListPropertyType("roles", String.class);
    addTypeDescription(desc);

    desc = new TypeDescription(MailingList.class);
    desc.putListPropertyType("otherArchives", String.class);
    addTypeDescription(desc);

    // Simple types
    addTypeDescription(new TypeDescription(DistributionManagement.class));
    addTypeDescription(new TypeDescription(Scm.class));
    addTypeDescription(new TypeDescription(IssueManagement.class));
    addTypeDescription(new TypeDescription(Parent.class));
    addTypeDescription(new TypeDescription(Organization.class));
  }